//--------------------------- for delete a meeting
function delete_meeting(thisurl, itemname){
	fun_status(1);
	thisid='response';
	if (confirm('آیا مطمئن هستید!؟')){
		ajax_del_meeting(thisurl, thisid, itemname);
	}else{
		fun_status(0);
	}
	return false;
}
function ajax_del_meeting(thisurl, thisid, itemname){
	var xmlhttp=false;
	document.getElementById(thisid).innerHTML = 'thisurl: '+thisurl+"<br />";
 /*@cc_on @*/
/*@if (@_jscript_version >= 5)
try {
xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');
} catch (e) {
try { xmlhttp = new ActiveXObject('Microsoft.XMLHTTP'); }
catch (E)
{ xmlhttp = false; }
}
@end @*/
	if(!xmlhttp) { xmlhttp=new XMLHttpRequest(); }
	xmlhttp.open('GET',thisurl, true);
	xmlhttp.onreadystatechange = function() {
		if(xmlhttp.readyState==4) {
			if(xmlhttp.status == 200) {
				if(!xmlhttp.responseText){
					document.getElementById(thisid).innerHTML += 'مطلب مورد نظر حذف نشد!';
				}else{
					eval(xmlhttp.responseText);
					if(del) document.getElementById(itemname).style.display='none';
					document.getElementById(thisid).innerHTML += xmlhttp.responseText;
					setTimeout("emptyIt('"+thisid+"')",5000);
				}
			}else
				alert("status is  " + xmlhttp.status);
		}
		fun_status(0);
	}
	xmlhttp.send(null);
}
//----------------------- END of delete a meeting -----------------------------
//--------------------------- for add a user in a jalase
function add_user_part(thisurl, itemobj){
	fun_status(1);
	ajax_add_user_part(thisurl, itemobj);
	return false;
}
function ajax_add_user_part(thisurl, itemobj){
	var xmlhttp=false;
 /*@cc_on @*/
/*@if (@_jscript_version >= 5)
try {
xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');
} catch (e) {
try { xmlhttp = new ActiveXObject('Microsoft.XMLHTTP'); }
catch (E)
{ xmlhttp = false; }
}
@end @*/
	if(!xmlhttp) { xmlhttp=new XMLHttpRequest(); }
	xmlhttp.open('GET',thisurl, true);
	xmlhttp.onreadystatechange = function() {
		if(xmlhttp.readyState==4) {
			if(xmlhttp.status == 200) {
				if(!xmlhttp.responseText){
					alert('کاربر مورد نظر افزوده نشد!');
				}else{
					eval(xmlhttp.responseText);
					if(uadd){
						itemobj.style.display='none';
					}
				}
			}else
				alert("status is  " + xmlhttp.status);
		}
		fun_status(0);
	}
	xmlhttp.send(null);
}
//----------------------- END of add a user in a jalase -----------------------------

//--------------------------- for delete a user
function delete_user(thisurl, itemname){
	fun_status(1);
	thisid='response';
	if (confirm('در صورت حذف این کاربر تمام اطلاعات پژوهشی او نیز حذف می گردد \nو غیر قابل بازگشت می باشد.آیا مطمئن هستید!؟')){
		ajax_del_user(thisurl, thisid, itemname);
	}else{
		fun_status(0);
	}
	return false;
}
function ajax_del_user(thisurl, thisid, itemname){
	var xmlhttp=false;
	document.getElementById(thisid).innerHTML = 'thisurl: '+thisurl+"<br />";
 /*@cc_on @*/
/*@if (@_jscript_version >= 5)
try {
xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');
} catch (e) {
try { xmlhttp = new ActiveXObject('Microsoft.XMLHTTP'); }
catch (E)
{ xmlhttp = false; }
}
@end @*/
	if(!xmlhttp) { xmlhttp=new XMLHttpRequest(); }
	xmlhttp.open('GET',thisurl, true);
	xmlhttp.onreadystatechange = function() {
		if(xmlhttp.readyState==4) {
			if(xmlhttp.status == 200) {
				if(!xmlhttp.responseText){
					document.getElementById(thisid).innerHTML += 'کاربر مورد نظر حذف نشد!';
				}else{
					eval(xmlhttp.responseText);
					if(del){
						document.getElementById(itemname).style.display='none';
					}
					document.getElementById(thisid).innerHTML += xmlhttp.responseText;
					setTimeout("emptyIt('"+thisid+"')",5000);
				}
			}else
				alert("status is  " + xmlhttp.status);
		}
		fun_status(0);
	}
	xmlhttp.send(null);
}
//----------------------- END of delete a user -----------------------------
//--------------------------- for delete an item(jalase title)
function delete_object(thisurl, itemname){
	fun_status(1);
	thisid='response';
	if (confirm('آیا مطمئن هستید!؟')){
		ajax_del(thisurl, thisid, itemname);
	}else{
		fun_status(0);
	}
	return false;
}
function ajax_del(thisurl, thisid, itemname){
	var xmlhttp=false;
	document.getElementById(thisid).innerHTML = 'thisurl: '+thisurl+"<br />";
 /*@cc_on @*/
/*@if (@_jscript_version >= 5)
try {
xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');
} catch (e) {
try { xmlhttp = new ActiveXObject('Microsoft.XMLHTTP'); }
catch (E)
{ xmlhttp = false; }
}
@end @*/
	if(!xmlhttp) { xmlhttp=new XMLHttpRequest(); }
	xmlhttp.open('GET',thisurl, true);
	xmlhttp.onreadystatechange = function() {
		if(xmlhttp.readyState==4) {
			if(xmlhttp.status == 200) {
				if(!xmlhttp.responseText){
					document.getElementById(thisid).innerHTML += 'مطلب مورد نظر حذف نشد!';
				}else{
					eval(xmlhttp.responseText);
					if(del) itemname.remove();
					document.getElementById(thisid).innerHTML += xmlhttp.responseText;
					setTimeout("emptyIt('"+thisid+"')",5000);
				}
			}else
				alert("status is  " + xmlhttp.status);
		}
		fun_status(0);
	}
	xmlhttp.send(null);
}
//----------------------- END of delete an item -----------------------------

//----------------------- for edit an item(jalase title)
img_edit = new Image();
img_endedit = new Image();
img_edit.src='templates/blue/images/item_edit.gif';
img_endedit.src='templates/blue/images/item_endedit.gif';
function edit_object(thisurl, itemname){
text = '<input id="'+itemname.id+'-input" type="text" name="title" value="'+itemname.text+'" class="part-edit-input">';
document.getElementById(itemname.id + "-anchor").innerHTML = text;
document.getElementById(itemname.id + "-edit").src = img_endedit.src;
col = document.getElementById(itemname.id);
col.innerHTML = col.innerHTML.replace(/edit_object/,'edit_object_final');
	return false;
}
function edit_object_final(thisurl, itemname){
	fun_status(1);
	thisid='response';
	jtitle = document.getElementById(itemname.id+'-input').value;
	thisurl += '&jtitle=' + encodeURIComponent(jtitle);
	document.getElementById(thisid).innerHTML=thisurl+"<br />";
	ajax_edit(thisurl, thisid, itemname);
	return false;
}
function edit_after(responsetext, itemname){
	eval(responsetext);
	document.getElementById(itemname.id + "-anchor").innerHTML = jtitle;
	itemname.text = jtitle;
	document.getElementById(itemname.id + "-edit").src = img_edit.src;
	col = document.getElementById(itemname.id);
	col.innerHTML = col.innerHTML.replace(/edit_object_final/,'edit_object');
	fun_status(0);
	return false;
}
function ajax_edit(thisurl, thisid, itemname){
	var xmlhttp=false;
	//document.getElementById(itemname).style.display
 /*@cc_on @*/
/*@if (@_jscript_version >= 5)
try {
xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');
} catch (e) {
try { xmlhttp = new ActiveXObject('Microsoft.XMLHTTP'); }
catch (E)
{ xmlhttp = false; }
}
@end @*/
	if(!xmlhttp) { xmlhttp=new XMLHttpRequest(); }
	xmlhttp.open('GET',thisurl, true);
	xmlhttp.onreadystatechange = function() {
		if(xmlhttp.readyState==4) {
			if(xmlhttp.status == 200) {
				if(!xmlhttp.responseText){
					document.getElementById(thisid).innerHTML += 'مطلب مورد نظر ویرایش نشد!';
				
				}else{
					
					document.getElementById(thisid).innerHTML += xmlhttp.responseText;
					edit_after(xmlhttp.responseText, itemname);
					setTimeout("emptyIt('"+thisid+"')",50000);
				}
			}else
				alert("status is  " + xmlhttp.status);
		}
	}
	xmlhttp.send(null);
}
//------------------- end of edit an item (jalase title)-----------------------------

//------------------- for add an item(jalase title)
function add_object_final(thisurl, itemname){
	thisid='response';
	row=document.getElementById(itemname);
	inpt=row.getElementsByTagName("input");
	mfolder=inpt[0].value;
	msubfolder=inpt[1].value;
	thisurl += '&f=' + encodeURIComponent(mfolder) + '&subf=' + encodeURIComponent(msubfolder);
	document.getElementById(thisid).innerHTML=thisurl+"<br />"+itemname+"<br />";
	ajax_add(thisurl, thisid, itemname);
	return false;
}
function add_after(responsetext, itemname){
	eval(responsetext);
	row=document.getElementById(itemname);
	col=row.getElementsByTagName("input");
	for(i=0;i<2;i++){
		col[i].value='';
	}
	document.getElementById(list-part).innerHTML += '';
	return false;
}
function ajax_add(thisurl, thisid, itemname){
	var xmlhttp=false;
	//document.getElementById(itemname).style.display
 /*@cc_on @*/
/*@if (@_jscript_version >= 5)
try {
xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');
} catch (e) {
try { xmlhttp = new ActiveXObject('Microsoft.XMLHTTP'); }
catch (E)
{ xmlhttp = false; }
}
@end @*/
	if(!xmlhttp) { xmlhttp=new XMLHttpRequest(); }
	xmlhttp.open('GET',thisurl, true);
	xmlhttp.onreadystatechange = function() {
		if(xmlhttp.readyState==4) {
			if(xmlhttp.status == 200) {
				if(!xmlhttp.responseText){
					document.getElementById(thisid).innerHTML += 'مطلب مورد نظر اضافه نشد!';
				
				}else{
					
					document.getElementById(thisid).innerHTML += xmlhttp.responseText;
					add_after(xmlhttp.responseText, itemname);
					setTimeout("emptyIt('"+thisid+"')",50000);
				}
			}else
				alert("status is  " + xmlhttp.status);
		}
	}
	xmlhttp.send(null);
}
//------------------- end of add an item(jalase title) -----------------------------

//-------------show waiting image
img_go = new Image();
img_stop = new Image();
img_go.src='templates/blue/images/going.gif';
img_stop.src='templates/blue/images/stop.gif';

function fun_status_auto()
{
	if(document.getElementById('img_status').src==img_stop.src)
		document.getElementById('img_status').src=img_go.src;
	else 
		document.getElementById('img_status').src=img_stop.src;
}
function fun_status(p)
{
	if(p==1)
		document.getElementById('img_status').src=img_go.src;
	else 
		document.getElementById('img_status').src=img_stop.src;
}
//--------END of show waiting image -----------------------------

//-------- for open and close a row in a table or a div tag
function closeIt(idname){
	par = document.getElementById(idname);
	i=eval(par.height);
//	document.getElementById('ali').innerHTML = par.height;
	if(i >= 30){
		par.height = i - 5;
		if(i > 30)
			setTimeout("closeIt('"+idname+"')",10);
	}
}
function openIt(idname){
	par = document.getElementById(idname);
	i=eval(par.height);
//	document.getElementById('ali').innerHTML = par.height;
	if(i <= 50){
		par.height = i + 1;
		if(i < 50)
			setTimeout("openIt('"+idname+"')",10);
	}
}
function open_close(idname){
	par = document.getElementById(idname);
	if(par.height == "") par.height=20;
	i=eval(par.height);
	if(i <= 50)
		openIt(idname);
	else
		closeIt(idname);
}
//------------------ end of open and close -----------------------------

function hide_show(idname){
	par = document.getElementById(idname);
	if(par.style.display == "") par.style.display = "none"; else par.style.display = "";
}
function emptyIt(thisid){
	document.getElementById(thisid).innerHTML = '';
}
function checkname(thisidshow){
	find_name = encodeURIComponent(document.getElementById("name").value);
	ajax_del('part.php?mod=ajax&name='+find_name , thisidshow);
}
