function validateall()
{
	vChar = document.mainform.username.value;
	vPass = document.mainform.userpass.value;
	
	if ( !chekBlank(vChar) ) {
		if ( !checkinvalid(vChar) ) {
			if ( !chekBlank(vPass) ) {
				if ( !checkinvalid(vPass) ) {
					alert("OK");
				}
				else
				{
					alert("The password entered contains invalid characters.\nThe password must be composed of ONLY letters and/or numbers");
					document.mainform.userpass.focus();
				}
			}
			else
			{
				alert("Please enter your password")
				document.mainform.userpass.focus();
			}
		}
		else
		{
			alert("The username entered contains invalid characters.\nThe username must be composed of ONLY letters and/or numbers");
			document.mainform.username.focus();
		}
	}
	else
	{
		alert("Please enter your username")
		document.mainform.username.focus();
	}
					
	return false;
}	

function validateMainSearch(vChar)
{
	if ( chekBlank(vChar) )
	{
		alert("Please enter a search criteria");
		return false;
	}
	return true;
}

function chekBlank(vChar)
{
	len = vChar.length;
	count = 0;
	
	for (x=0; x<len; x++)
	{
		xChar = vChar.charAt(x);

		if (xChar == " ")
			count++;
	}

	if (count == len)
		return true;
	
	return false;
}

function checkinvalid(vChar)
{
	valid = "abcdefghijklmnopqrstuvwxyz0123456789";
	valid = valid.toUpperCase();
	vChar = vChar.toUpperCase();
	
	len = vChar.length;
	
	invalid = false;
	for (x=0; x<len; x++)
	{
		xChar = vChar.charAt(x);

		if (valid.indexOf(xChar) == -1)
			invalid = true;
	}
	
	return invalid; 
}

function validateEmail(email)
{
	expregular = /^(.+\@.+\..+)$/
	
	if ( !chekBlank(email) )
	{
		if(!expregular.test(email)) 
		{ 
		   alert("Please enter a valid email address");
		   return false;
		 }
	}
	return true;	
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function ss(w){window.status=w;return true;}
function cs(){window.status='';}

function goProductList(vChar, vChar1)
{
	document.mainform.warehousekey.value = vChar;
	if ( document.getElementById("condition") )
	{
		document.mainform.condition.value = vChar1;
	}
	if ( document.getElementById("start") )
	{
		document.mainform.start.value = 0;
	}
	
	document.mainform.action = 'productlist.php';
	document.mainform.submit();

}

