// JavaScript Document

function validateThis2(formObj)
   {

   //alert("test"); 
    var errorMessage = "";
	 		  
	//Email
    if(formObj.elements.email.value=="" || !etest(formObj.elements.email.value))
     errorMessage += "Please enter a valid Email\n"; 
	 
 
    if(errorMessage!="")
     alert(errorMessage); 
    else
    {
     formObj.action = "codes/forms/email.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
    }
