// JavaScript Document
function frmvalidate(theForm){
	if (theForm.FName.value == "")
	{
	alert("First Name is a required field.");
	theForm.FName.focus();
	return (false);
	}
	if (theForm.LName.value == "")
	{
	alert("Last Name is a required field.");
	theForm.LName.focus();
	return (false);
	}
	if (theForm.Address1.value == "")
	{
	alert("Address1 is a required field.");
	theForm.Address1.focus();
	return (false);
	}
	if (theForm.City.value == "")
	{
	alert("City is a required field.");
	theForm.City.focus();
	return (false);
	}
	if (theForm.State1.value == "" && theForm.State2.value=="")
	{
	alert("State is a required field.");
	theForm.State1.focus();
	return (false);
	}
	if (theForm.Zip.value == "")
	{
	alert("ZipCode is a required field.");
	theForm.Zip.focus();
	return (false);
	}
	if (theForm.Country.value == "")
	{
	alert("Country is a required field.");
	theForm.Country.focus();
	return (false);
	}
	if(theForm.Email.value == "")
	{
	alert("Email is a required field.");
	theForm.Email.focus();
	return (false);
	}
	else if(echeck(theForm.Email.value)==false)
	{
	theForm.Email.focus();
	return (false);
	}
}
function echeck(str) {

	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   alert("Invalid E-mail address")
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   alert("Invalid E-mail address")
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		alert("Invalid E-mail address")
		return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
		alert("Invalid E-mail address")
		return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		alert("Invalid E-mail address")
		return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
		alert("Invalid E-mail address")
		return false
	 }
	
	 if (str.indexOf(" ")!=-1){
		alert("Invalid E-mail address")
		return false
	 }

	 return true					
}
function validate(theForm) {
	var retn = true;
	if (theForm.name.value == "")
	{
	alert("Name is a required field.");
	theForm.name.focus();
	retn = false;
	return false;
	}
	if(theForm.email.value.length > 0)
	{
		if(echeck(theForm.email.value)==false)
		{
		theForm.email.focus();
		retn = false;
		return false;
		}
	}
	if (theForm.comment.value.length <= 0)
	{
	alert("Please type a comment.");
	theForm.comment.focus();
	retn = false;
	return false;
	}
	return retn;
}
