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("Please input a valid number!");
	e.focus()
	return false;
}
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 checktitle(id)
{
	var e = document.getElementById(id);
	e.value = trim(e.value);
	if(e.value.length==0)
	{
		e.focus();
		alert('this field can not be empty');
		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('this field can not be empty');
		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 checkfullname(id)
{
	var e = document.getElementById(id);
	e.value = trim(e.value);
	if(e.value.length<2)
	{
		e.focus();
		e.select();
		alert('name is too short, put at least 2 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 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('false email syntax');
		return false;
	}
	if(firstpositionofat<2)
	{
		e.focus();
		e.select();
		alert('false email syntax');
		return false;
	}
	if(lastpositionofat != firstpositionofat)
	{
		e.focus();
		e.select();
		alert('false email syntax');
		return false;
	}
	if(lastpositionofdot < firstpositionofat + 2)
	{
		e.focus();
		e.select();
		alert('false email syntax');
		return false;
	}
	if((length > lastpositionofdot + 3) || (length < lastpositionofdot + 2))
	{
		e.focus();
		e.select();
		alert('false email syntax');
		return false;
	}
	return true;
}
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 trim(str)
{
	return rtrim(ltrim(str));
}
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 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 validatesignup()
{
	if(!checkemail('emailsignup')) return false;
	if(!checkpassword('password_signup')) return false;
	if(!checkconfirmpassword('password_signup', 'confirmpasswordsignup')) return false;
	if(!checkfullname('name_signup')) return false;
	return true;
}
function validateforgotyourpassword()
{
	if(!checkemail('emailforgotyourpassword')) return false;
	return true;
}
function validatecontactus()
{
	if(!checkfullname('fullname_')) return false;
	if(!checkemail('from_')) return false;
	if(!checktitle('requestsubject_')) return false;
	if(!checktitle('requestdetails_')) return false;
	return true;
}
function validatelogin()
{
	if(!checkemail('email_')) return false;
	if(!checkpassword('password')) return false;
	return true;
}