// JavaScript Document
/****************
Author:John
Email:enjoying8@gmail.com
*****************/

function oo(obj)
{
	return document.getElementById(obj);
}

function chk_name(obj)
{
	Namecheck = /^[A-Za-z]+$/
	var oValue = obj.value;
	var oE = oo(obj.name + "_error");
	if ( !oValue || oValue == "" || !Namecheck.test(oValue))
	{
		oE.style.display = "inline";
		return false;
	}
	oE.style.display = "none";
}

function chk_phone(obj)
{
	Phonecheck = /^\d{3}[- ]?\d{3}[- ]?\d{4}$/
	var oValue = obj.value;
	var oE = oo(obj.name + "_error");
	if ( !oValue || oValue == "" || !Phonecheck.test(oValue))
	{
		oE.style.display = "inline";
		return false;
	}
	oE.style.display = "none";
}

function chk_email(obj)
{
	Emailcheck = /^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@(([0-9a-zA-Z])+([-\w]*[0-9a-zA-Z])*\.)+[a-zA-Z]{2,9})$/
	var oValue = obj.value;
	var oE = oo(obj.name + "_error");
	if ( !oValue || oValue == "" || !Emailcheck.test(oValue))
	{
		oE.style.display = "inline";
		return false;
	}
	oE.style.display = "none";
}


function chk_zip(obj)
{
	Zipcheck = /^\d{5}$/
	var oValue = obj.value;
	var oE = oo(obj.name + "_error");
	if ( !oValue || oValue == "" || !Zipcheck.test(oValue))
	{
		oE.style.display = "inline";
		return false;
	}
	oE.style.display = "none";
}

function chk_address(obj)
{
	var oValue = obj.value;
	var oE = oo(obj.name + "_error");
	if ( !oValue || oValue == "")
	{
		oE.style.display = "inline";
		return false;
	}
	oE.style.display = "none";
}

function checkform()
{
	obj = oo("form1");
	var fn = chk_name(obj.firstname);
	var ln = chk_name(obj.lastname);
	var tel = chk_phone(obj.phone);
	var em = chk_email(obj.email);
	var zip = chk_zip(obj.zip);
	var ct = chk_name(obj.city);
	var st = chk_name(obj.state);
    
	var b = fn || ln || tel || em || zip || ct || st;

	if (b == false)
	{
		alert("Invalid value, please check again");
		return false;
	}
	//return true;
}

