
// isEmail (STRING email)
// 
// Email address must be of form a@b.c


function isEmail(email)
{
  validEmailString="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-_.@~";
  emailValid=true;
  
  //tests for invalid characters
  
  for (e=0; e < email.length; e++)
  {
    if (validEmailString.indexOf(email.charAt(e)) < 0)
    {
      emailValid=false;
      break;
    }
  }

  if (emailValid)
  {
    PosAt=email.indexOf("@");
    PosAtLast=email.lastIndexOf("@");
    
    // tests to make sure there is something before the @
    
    if (PosAt >0)
    {                       
      PosDotFirst=email.indexOf(".");
      PosDotLast=email.lastIndexOf(".");

      // tests to make sure the last dot is after the @
      // and that there is only one @
      
      if (PosDotLast < PosAt || PosAt != PosAtLast)
      { 
        emailValid=false;
      }                 
      
      // tests to make sure the dot is not the last character, 
      // or the first character, 
      // or the first character after the @

      if (PosDotLast == email.length-1 || PosDotFirst == 0 || email.charAt(PosAt+1) == ".")
      { 
        emailValid=false;
      }
    }else
    {
      emailValid=false;
    }
  }

  return(emailValid)
}


//
//  Checks for a string of semi-colon separated e-mail addresses
//
function isEmailList(emailList)
{
  emailValid=false;
  emailArray = emailList.split(";");
  for( var i=0 ; i<=emailArray.length ; i++ )
  {
    emailValid = isEmail( emailArray[i] );
    if ( !emailValid )
    {
      return emailValid
    }
  }
  return(emailValid)
}
