// JavaScript Document
function validateThis(formObj)
   {

   //alert("test"); 
    var errorMessage = "";

	//First Name
    if(formObj.elements.firstname.value=="")
     errorMessage += "Please enter your First Name \n"
	  
	//Last Name
    if(formObj.elements.lastname.value=="")
     errorMessage += "Please enter your Last Name \n"
	  	 	 	 
	//Phone
    if(formObj.elements.phone.value=="")
     errorMessage += "Please enter your Phone \n"
	 
	//Email
    if(formObj.elements.email.value=="" || !etest(formObj.elements.email.value))
     errorMessage += "Please enter a valid Email Address\n"; 
    
	 
    if(errorMessage!="")
     alert(errorMessage); 
    else
    {
     formObj.action = "php/formmail.php";
     formObj.method = "post";
     formObj.submit();
    }     
     
     
   }
   
   //---------------------------------------------------
   //tests id email string has a @ and a . in this order
   //parameter
   //   str - string that need to be validated 
   //returns true for valid/ false for invalid
   //---------------------------------------------------
    function etest(str)
    {
    var i=0;//increment
    var n=0;//increment
    var m=0;//increment
    var j=0;//increment
    var dotPos=0;//holds the position of the dot in the string
    var k=str.length//holds the lenght of the string
    var instPosition=0;//used for the position of the current tested element 
    for(i=1;i<=k;i++)//looks for the @ sign
    {
    if(str.charCodeAt(i)==32) return false
    if(str.charCodeAt(i)==64)//if it finds it
     {      
     j++;//counts how many times it finds it
     instPosition=i;//locates the first position
     }  
    }
     
    if((j==1)&&(instPosition!=0)&&(instPosition!=(k-1))&&(str.charCodeAt(0)!=46)&&(str.charCodeAt(k-1)!=46))//if it finds @ once and it is neither first nor last character
    {
     for(n=0;n<=k;n++)//looks for dot 
     {
     if(str.charCodeAt(n)==46)//if it finds one 
     {
      dotPos=n;//determines its position
     if((instPosition==dotPos-1)||(instPosition==dotPos+1))//if the dot is right by the @ sign returns false
     return false
        
     if(dotPos>instPosition)//the dot is after @
     return true
     } 
     }   
     return false
    }
    else
    return false
    }