// BASIC DATA VALIDATION FUNCTIONS:
//
// isEmail(s [,eok])                   True if string s is a valid
//					 email address.
//
// 18 Feb 97 created Eric Krock
//
// (c) 1997 Netscape Communications Corporation
// 1998 Supplemented by Dawn Bushong


// isEmail(STRING s [, BOOLEAN emptyOK])
// 
// Email address must be of form a@b.c -- in other words:
// * there must be at least one character before the @
// * there must be at least one character before and after the .
// * the characters @ and . are both required
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function isEmail(s) {
  if (isEmpty(s)) return emptyReturn(isEmail.arguments);
   
  // is s whitespace?
  if (isWhitespace(s)) return false;
    
  // there must be >= 1 character before @, so we
  // start looking at character position 1 
  // (i.e. second character)
  var i = 1;
  var sLength = s.length;

  // look for @
  while ((i < sLength) && (s.charAt(i) != "@")) {
    i++
  }

  if ((i >= sLength) || (s.charAt(i) != "@")) return false;
  else i += 2;

  // look for .
  while ((i < sLength) && (s.charAt(i) != ".")) {
    i++
  }

  // there must be at least one character after the .
  if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
  else return true;
}

