/* The isEmail() function receives the name of the form field and then 
retrieves its value.  */

function isEmail(element)  {
	var message=""; 	
   var inputStr = element;

/* The validation process determines if the email is less than 9 characters. 
If so, then it sets the return variable to true indicating a failed validation. 
It also adds the appropriate message to the existing message string.  */

   if (inputStr.length <7)  { 
      message +="- - Email should be at least 9 characters \n"; return true; }
   
   /*  Next, we check for the existence of the @ character */
   var charA = inputStr.indexOf("@");
   if (charA == -1)  {
      message += "- - Email did not find the @ character \n";
      return true;
   }

/*  Once it has been determined that there is an @ character, the validation 
process checks to see if it is it more than two characters in from the left 
side of the string. */

   if (charA <1 )  { 
      message +="- - Email expected at least 2 characters before the @ character \n";
      return true; }
   
   /*  The check continues to determine if a . (period) exists. It begins the 
   search from    the right side of the string.  */
   
   var charP = inputStr.lastIndexOf(".");
      if (charP == -1)  {
         message += "- - Email expected to find the . character \n";
         return true;
      }

   /*  Now that we have a . (period), is it at the proper place at the 
   end of the string. */
	
   if (charP != inputStr.length - 3 && charP != inputStr.length - 4)  {
      message += "- - Email ending . character not in correct position \n";
      return true;
   }

/*  Okay, now that we have both the @ and . (period) characters, are they 
separated by at least two characters?  */

   if ((charP - charA)<2)
    	return true;
   /*  If none of the if statements detect a validation error, then the 
   'return' value of false is returned to the calling function which continues 
   with its script.  */
   
   return false;
}
