// JavaScript Document

function validate_form ()
{
    if ( document.frmContactus.Name.value == "" )
    {
        alert ( "Please fill in the Name" );
		  document.frmContactus.Name.focus()
        return false;
    }
	
	var lename=document.frmContactus.Name.value.length
	if(lename >= "80")
	{
		alert ( "Name Exceeds 80 Characters" );
		  document.frmContactus.Name.focus()
        return false;
		
	}
	
	 if ( document.frmContactus.Address.value == "" )
    {
        alert ( "Please fill in the Address" );
		 document.frmContactus.Address.focus()
        return false;
    }
	
	if ( document.frmContactus.City.value == "" )
    {
        alert ( "Please fill in the City" );
		 document.frmContactus.City.focus()
        return false;
    }
	if ( document.frmContactus.State.value == "" )
    {
        alert ( "Please fill in the State" );
		 document.frmContactus.State.focus()
        return false;
    }
	
	
	if ( document.frmContactus.ZipCode.value == "" )
    {
        alert ( "Please fill in the Zip Code" );
		 document.frmContactus.ZipCode.focus()
        return false;
    }
	
	if(IsNumeric(document.frmContactus.ZipCode.value)==false)
	
	{
		alert ( "Please fill in the Zip Code correctly" );
		 document.frmContactus.ZipCode.focus()
        return false;
	}
	var len= document.frmContactus.ZipCode.value.length;
    if ( len > "5" )
    {
        alert ( "Please enter 5 Digits" );
		 document.frmContactus.ZipCode.focus()
        return false;
    }
	
	
if(document.frmContactus.HomePhone.value=="" || isNaN(document.frmContactus.HomePhone.value))
{ alert("Enter Correct Phone Number!");
document.frmContactus.HomePhone.focus();
return false; } 

var homelen= document.frmContactus.HomePhone.value.length;
    if (homelen >= "80")
    {
	    alert ( "Phone Number Exceeds 80 characters" );
		 document.frmContactus.HomePhone.focus()
        return false;
    }

var emailID=document.frmContactus.Email
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email ID")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	
	var Emaillen= document.frmContactus.Email.value.length;
    if (Emaillen >= "80")
    {
	    alert ( "Email Exceeds 80 characters" );
		 document.frmContactus.Email.focus()
        return false;
    }
	var Helplen= document.frmContactus.Help.value.length;
    if (Helplen >= "1000")
    {
	    alert ( "How can we help you?  Exceeds 1000 characters" );
		 document.frmContactus.Help.focus()
        return false;
    }
	
	
  frmContactus.submit();
    return true;
}

function IsNumeric(sText)

{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }
   
   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 ID")
		   return false
		}

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

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

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

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

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

 		 return true					
	}
   



