//TeachArabia 2005
// Ashraf Morad
function ShowGroup(X)
{
	for(i=0;i<4;i++)
	{
		if(X.value !== i) document.all("datas_[to_][" + i + "]").style.display = "none";
	}
	if(X.value >= 0) 
	{
		document.all("datas_[to_][" + X.value + "]").style.display = "";
	}
}
function controlmenu(tableid)
{
	if(document.all("men_" + tableid).style.display == "none")
	{
		document.all("men_" + tableid).style.display = "";
		document.all("arr_" + tableid).src = "../../images/menu/arrow_down.gif";		
		var expdate = new Date (); // pre-set to the current time and date
		expdate.setTime(expdate.getTime() + 1000 * 60 * 60 * 24 * 365); // add one year to it 
		setCookie("men_" + tableid,"false",expdate);		
	}
	else
	{
		document.all("men_" + tableid).style.display = "none";	
		document.all("arr_" + tableid).src = "../../images/menu/arrow_up.gif";				
		var expdate = new Date (); // pre-set to the current time and date
		expdate.setTime(expdate.getTime() + 1000 * 60 * 60 * 24 * 365); // add one year to it 
		setCookie("men_" + tableid,"true",expdate);				
	}
}
function changestate(THIS)
{
	for (var i=0;i<document.data_.elements.length;i++)
	{
		var e = document.data_.elements[i];
		if ((e.name != 'allc') && (e.type=='checkbox'))
		{
			e.checked = THIS.checked;
		}
	}
}
function moveto(xf_,xto_)
{
	var f_=document.data_[xf_];  
	var to_=document.data_[xto_];
	for ( x=0; x < f_.options.length ; x++)
	{
		if (f_.options[x].selected == true)
		{
			var newob = document.createElement("OPTION");
			newob.text = f_.options[x].text ;
			newob.value = f_.options[x].value;
			tmp1=checkifav(newob.value, xto_ )	;
				if ( ! tmp1 )
					to_.options.add(newob);
		}
	}
}

function moveall(xf_,xto_)
{
	var f_=document.data_[xf_];  
	var to_=document.data_[xto_];
	for ( x=0; x < f_.options.length ; x++)
	{
		var newob = document.createElement("OPTION");
		newob.text = f_.options[x].text ;
		newob.value = f_.options[x].value;
		tmp1=checkifav(newob.value, xto_ )	;
			if ( ! tmp1 )
				to_.options.add(newob);
	}
}
///////////////////////////////////////////////////////////////////////////////////
function removefrom(xf_)
{
	f_=document.data_[xf_];
	for (var n=f_.options.length-1;n>=0;n--)
		{
			if (f_.options[n].selected == true) 
				f_.options.remove(n);
		}
}
function removeall(xf_)
{
	f_=document.data_[xf_];
	for (var n=f_.options.length-1;n>=0;n--)
		{
				f_.options.remove(n);
		}	
}
/////////////////////////////////////////////////////////////////////////////////
function checkifav(idd , xf_)
{
	f_=document.data_[xf_];
	for (var n=0;n<f_.options.length;n++)
		if (f_.options[n].value == idd) 
			return true;
	return false;
}		
//////////////////////////////////////////////////////////////////////////////////////
function checkdata()
	{
		mes="";
		if ( data_["data_[label]"].value=="" )
			mes="الرجاء اختيار عنوان الرسالة";
	if (mes=="")
	{		
		return checkfinal();
	}
	alert(mes);
	return false;
	}
//////////////////////////////////////////////////////
function selectAllList(f_)
{
	for (var n=0;n<f_.options.length;n++)
		f_.options[n].selected=true;
}	
//////////////////////////
function setCookie(name, value, expires)
{
        if (!expires) expires = new Date(); 
	document.cookie = name + "=" + escape(value) + "; expires=" + expires.toGMTString() + "; path=/";
}
/////////////
function getCookie(name)
{
	var cookies = document.cookie;
	if (cookies.indexOf(name) != -1)
	{
		var startpos = cookies.indexOf(name)+name.length+1;
		var endpos = cookies.indexOf(";",startpos)-1;
		if (endpos == -2) endpos = cookies.length;
		return unescape(cookies.substring(startpos,endpos));
	}
	else
	{
		return false;
	}
}
/////////////
function checkfinal()
{
	var obj = document.forms[0];
	var j=0;
	for(i=0;i<obj.elements.length;i++)
	{
		if(obj.elements[i].type=="checkbox" && obj.elements[i].checked)
		{
			j++;
		}
	}
	
	if(j == 0)
	{
		alert("الرجاء اختيار مستلم واحد على الأقل للرسالة");
		return false;
	}
}

////////////
function checkallcheckboxes(prefix,formname)
{
	n = document.all[formname].elements.length;
	members = document.all[formname].elements;
	for(i=0;i<n;i++)
	{
		if(members[i].type == "checkbox")
		{
			Oname = members[i].name;
			if(Oname.substring(0,prefix.length+1) == prefix+"["){
				members[i].checked = true;
			}
		}
	}
}