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 checknumber(id)
{
	var e = document.getElementById(id);
	var anum=/(^\d+$)|(^\d+\.\d+$)/
	if (anum.test(e.value)) return true;
	alert("Please input a valid number!");
	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 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 checkemail(id)
{
	var e = document.getElementById(id);
	e.value = trim(e.value);
	if(e.value.length > 0)
	{
		if(e.value.indexOf("@") < 1)
		{
			e.focus();
			alert('false email syntax');
			return false;
		}
		return true;;
	}
	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 trim(str)
{
	return rtrim(ltrim(str));
}
function redirect(url)
{
	document.location.href=url;
}
