function redirect(url)
{
	document.location.href = url;
}
function collapsepanel(obj)
{
	if((browser=='explorer') || (browser=='mozilla') || (browser=='opera')) obj.style.display='none';
	else if(browser=='firefox') obj.setAttribute('style', 'display:none');
}
function expandpanel(obj)
{
	if((browser=='explorer') || (browser=='mozilla') || (browser=='opera')) obj.style.display='inline';
	else if(browser=='firefox') obj.setAttribute('style', 'display:inline');
}
function changeclass(obj, className)
{
	if((browser=='explorer') || (browser=='mozilla') || (browser=='opera')) obj.className=className;
	else if(browser=='firefox') obj.setAttribute('class', className);
}
function messageWindow(url)
{ 
	//var width="" + screen.width - 50 + "";
		//var height="" + 3 * screen.height/4 + "" ;
		//var left = (screen.width/2) - width/2;
		//var top = (screen.height/2) - height/2;
		var width="" + screen.width + "";
		var height="" + screen.height + "" ;
		var left = 0;
		var top = 0;
	var styleStr = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+',top='+top+',screenX='+left+',screenY='+top;
	var msgWindow = window.open(url,"msgWindow", styleStr);
}
function byid(idname)
{
	return document.getElementById(idname);
}
function checkselectedIndex(id)
{
	var e = document.getElementById(id);
	if(e.selectedIndex == -1)
	{
		alert('select an item');
		e.focus();
		return false;
	}
	return true;
}
function checkdate(id)
{
	var e = document.getElementById(id);
	if(e.value.length==0)
	{
		alert('specify a date by clicking on the calendar icon');
		return false;
	}
	return true
}
function checktextarea(id)
{
	var e = document.getElementById(id);
	e.value = trim(e.value);
	if(e.value.length==0)
	{
		e.focus();
		alert('Ce champ ne peut pas être vide');
		return false;
	}
	return true;
}
function checktitle(id)
{
	var e = document.getElementById(id);
	e.value = trim(e.value);
	if(e.value.length==0)
	{
		e.focus();
		alert('Ce champ ne peut pas être vide');
		return false;
	}
	return true
}
function checknumber(id)
{
	var e = document.getElementById(id);
	e.value = trim(e.value);
	var anum=/(^\d+$)|(^\d+\.\d+$)/
	if (anum.test(e.value)) return true;
	alert("S'il vous plaît entrer un numéro valide!");
	e.focus()
	return false;
}
function checkfullname(id)
	{
		var e = document.getElementById(id);
		e.value = trim(e.value);
		if(e.value.length<5)
		{
			e.focus();
			e.select();
			alert('Username is too short');
			return false;
		}
		return true;
	}
	function checkpassword(id)
	{
		var e = document.getElementById(id);
		if(e.value.length<8)
		{
			e.focus();
			e.select();
			alert('Password is too short, put at least 8 characters');
			return false;
		}
		return true;
	}
	
	function checkconfirmpassword(id1, id2)
	{
		var e1 = document.getElementById(id1);
		var e2 = document.getElementById(id2);
		if(e1.value != e2.value)
		{
			e2.focus();
			e2.select();
			alert('password is not confirmed correctly');
			return false;
		}
		return true;
	}
function checkpercentage(id)
{
	var e = document.getElementById(id);
	e.value = trim(e.value);
	var anum=/(^\d+$)|(^\d+\.\d+$)/
	if (anum.test(e.value))
	{
		if(e.value <= 100) return true;
	}
	alert("Please input a valid percentage!");
	e.focus()
	return false;
}
function ltrim(str)
{
	str1 = str;
	var length = str1.length;
	while(str1.indexOf(" ")==0)
	{
		length = length - 1;
		str1 = str1.substr(1, length);
	}
	return str1;
}
function rtrim(str)
{
	str1 = str;
	var length = str1.length - 1;
	while(str1.lastIndexOf(" ")==length)
	{
		str1 = str1.substr(0, length);
		length = length - 1;
	}
	return str1;	
}
function checkemail(id)
{
	var e = document.getElementById(id);
	e.value = trim(e.value);
	var length = e.value.length;
	var lastpositionofdot = 1 + e.value.lastIndexOf(".");
	var lastpositionofat = 1 + e.value.lastIndexOf("@");
	var firstpositionofat = 1 + e.value.indexOf("@");
	if(length<6)
	{
		e.focus();
		e.select();
		alert('Faux format e-mail');
		return false;
	}
	if(firstpositionofat<2)
	{
		e.focus();
		e.select();
		alert('Faux format e-mail');
		return false;
	}
	if(lastpositionofat != firstpositionofat)
	{
		e.focus();
		e.select();
		alert('Faux format e-mail');
		return false;
	}
	if(lastpositionofdot < firstpositionofat + 2)
	{
		e.focus();
		e.select();
		alert('Faux format e-mail');
		return false;
	}
	if((length > lastpositionofdot + 3) || (length < lastpositionofdot + 2))
	{
		e.focus();
		e.select();
		alert('Faux format e-mail');
		return false;
	}
	return true;
}
function trim(str)
{
	return rtrim(ltrim(str));
}
