function validateAdd()
{
	if(fnfname()&&fnlname()&&fncompany()&&fnaddress()&&fncity()&&fnzip()&&fnphone()&&fnemail())
		{
			//alert ("hi");
			
			document.form1.action="contactussubmit.php";
			document.form1.submit();
			return true;
		}
		return false;
}


 function fnfname()
 {
   var fname;
   fname = document.form1.fname.value;
   
   if(fname=="") 
   {
    alert("First name Cannot Be Empty");
    document.form1.fname.focus();
    document.form1.fname.select();
    return false;      
   }
    return true;
 }
 
  
 function fnlname()
 {
   var lname;
   lname = document.form1.lname.value;
   
   if(lname=="") 
   {
    alert("Last Name Cannot Be Empty");
    document.form1.lname.focus();
    document.form1.lname.select();
    return false;      
   }
    return true;
 }
 
  function fncompany()
 {
   var company;
   company = document.form1.company.value;
   
   if(company=="") 
   {
    alert("company Name Cannot Be Empty");
    document.form1.company.focus();
    document.form1.company.select();
    return false;      
   }
    return true;
 }
 function fnaddress()
 {
   var address;
   address = document.form1.address.value;
   
   if(address=="") 
   {
    alert("address Cannot Be Empty");
    document.form1.address.focus();
    document.form1.address.select();
    return false;      
   }
    return true;
 }
 
 function fncity()
 {
   var city;
   city = document.form1.city.value;
   
   if(city=="") 
   {
    alert("city Cannot Be Empty");
    document.form1.city.focus();
    document.form1.city.select();
    return false;      
   }
    return true;
 }
 
/* function fnstate()
  {
    var state;
	state= document.form1.Item.selectedIndex==0
   	{
    alert("Please select state.");
    document.form1.state.focus();
    document.form1.state.select();
	return false;
    }
    return true;
    }	*/
 function fnzip()
 {
   var zip;
   zip = document.form1.zip.value;
   
   if(zip=="") 
   {
    alert("zip Cannot Be Empty");
    document.form1.zip.focus();
    document.form1.zip.select();
    return false;      
   }
    return true;
 }
 
 function fnphone()
 {
   var phone;
   phone = document.form1.phone.value;
   
   if(phone=="") 
   {
    alert("phone no Cannot Be Empty");
    document.form1.phone.focus();
    document.form1.phone.select();
    return false;      
   }
    return true;
 }

/*function fnzip(){
zip = document.form1.zip.value;
zipCodeRegex = /\d{5}(-\d{4})?/;
if( !zip.match( zipCodeRegex ) ) {
  alert( "Please enter a valid zip number" );
  document.form1.zip.focus();
    document.form1.zip.select();
  return false;
}
return true;
}*/
//function to check the Email
function fnemail()
{
  
  var email;
  email = document.form1.email.value;
	
	//TO FIND A SINGLE QUOTE IN A VALUE
	var SnglQuote=email.indexOf("'");

    if (SnglQuote == "-1")
    {}
    else
    {
        alert("Please Enter a valid Email Address ");
		document.form1.email.focus();
		return false;
    }
    
		atPos = email.indexOf("@",0);
		pPos1 = email.indexOf(".",0);
		periodPos = email.indexOf(".",atPos);

	// Are there consecutive periods?
		pos1 = pPos1;
		pos2 = 0;
		
		 while (pos2 > -1) 
		  {
			pos2 = email.indexOf(".",pos1+1);
			if (pos2 == pos1+1) 
			{
			    alert("Please Enter a valid Email Address ");
				document.form1.email.focus();
				return false;
			} 
			else 
			{
				pos1 = pos2;
			}
		}

	// Is there an @ symbol in the address?

		if (atPos == -1) 
		{
		  
			alert("Please Enter a valid Email Address ");
			document.form1.email.focus();
			return false;
		}

	// Is the @ symbol in the first position?

		if (atPos == 0) 
		{
		    
			alert("Please Enter a valid Email Address ");
			document.form1.email.focus();
			return false;
		}

	// Is there a period in the first position?

		if (pPos1 == 0) 
		{
		    
			alert("Please Enter a valid Email Address ");
			document.form1.email.focus();
			return false;
		}

	// Is there more than one @ symbol in the address?

		if(email.indexOf("@",atPos+1) > -1) 
		{
		    
			alert("Please Enter a valid Email Address ");
			document.form1.email.focus();
			return false;
		}

	// Is there a period after the @ symbol?

		if (periodPos == -1) 
		{
		    
			alert("Please Enter a valid Email Address ");
			document.form1.email.focus();
			return false;
		}

	// Is the period imediately after the @ symbol?

		if (atPos+1 == periodPos) 
		{
		    
			alert("Please Enter a valid Email Address ");
			document.form1.email.focus();
			return false;
		}

	// Are there at least 2 characters after the period?

		if (periodPos+3 > email.length) 
		{
		   
			alert("Please Enter a valid Email Address");
			document.form1.email.focus();
			return false;
		}
	      	return true;
	 
  
}
/*function fnphone(){
phone = document.form1.phone.value;
phoneRegex = /^[2-9]\d{2}-\d{3}-\d{4}$/;
if( !phone.match( phoneRegex ) ) {
  alert( "Please enter a valid phone number" );
   document.form1.phone.focus();
   document.form1.phone.select();
  return false;
}
return true;
}*/

