// validate an email address
/* the algorithm briefly is as follows
1.  check for an @ sign
1.1  if exists, continue to check to be sure no more @ signs
1.2  if doesn't exist return false
2.  check for a dot (.) after the @ sign
2.1  if exists, continue
2.2 if doesn't exist return false
3   check to be sure that there are at least 2 characters after the dot
3.1  if exists, done and return true
3.2  if not, return false
*/

function validateEmail (aVal)
{
   //window.alert ("validateEmail: inside");   
   /*
   1.  check for an @ sign
   1.1  if exists, continue to check to be sure no more @signs exist
   1.2  if doesn't exist return false
   */
   var posAt = aVal.indexOf("@", 0); // need the index of the at sign
   if (posAt == -1)  // not ok - no @ sign 
   {
     return false; 
   }
   else
   {
     var anotherPosAt = aVal.indexOf("@", posAt+1);
     if (anotherPosAt != -1)// hopefully we do not have another one
     {
         return false;
     }
   }  // here we know we have only 1 at sign
     
   /*
   2.  check for a dot (.) after the @ sign
   2.1  if exists, continue
   2.2 if doesn't exist return false
   */
   var posDot = aVal.indexOf(".", posAt + 1); // need the index of the dot
   if (posDot == -1)  // not ok - no dot 
   {
     return false; 
   }  // here we know we have an @ and a dot
      
   /*
   3   check to be sure that there are at least 2 characters after the dot
   3.1  if exists, done
   3.2  if not, return false
   */ 
   
   var lastIndex = aVal.length - 1; // the number of characters in  aVal minus 1
   
   if ( lastIndex - posDot < 2 )  
   {
       return false;
   }
   
    return true;
}


//check the phone format
function chkphone(str)
{
	var pattern3 = /\d{3}\-\d{3}\-\d{4}/;
	if(pattern3.test(str))
	{
		return true;
	}
	else
	{				
			return false;			
	}
	
}

