function validateAdd()
{
	if(fnname()&&fncompany()&&fnemail()&&fnphone())
		{
			//alert ("hi");
			
			document.form1.action="gdform.php";
			document.form1.submit();
			return true;
		}
		return false;
}


 function fnname()
 {
   var name;
   name = document.form1.name.value;
   
   if(name=="") 
   {
    alert("name Cannot Be Empty");
    document.form1.name.focus();
    document.form1.name.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 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()
 {
   var phone;
   phone = document.form1.phone.value;
   
   if(phone=="") 
   {
    alert("phone  Cannot Be Empty");
    document.form1.phone.focus();
    document.form1.phone.select();
    return false;      
   }
    return true;
 }
 

