// Same function as job.js
//
// isValidEmail does not check if the address actually exists,
// it merely makes sure that the address has the correct syntax
// and could exist.
//
// The address should start with a bunch of alphanumerical
// (letters or numbers), underscores, dots or dashes. This is
// the user name.
//
// Followed by the @ sign.
//
// After that comes the domain name, which may include several
// sub-domains (mail.international.company). Therefore we now
// allow several series of alphanumerical characters and dashes,
// followed by a dot.
//
// Finally the top level domain, once again we check for
// alphanumerical characters, but now without the dash. Also,
// a top level domain name must be between 2 and 4 characters.
// Digits are included in the top level domain because IP
// addresses are also valid domains.
//
function isValidEmail(str)
{
  var eAddr = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/i;

  if (!(str))
  {
    alert("Please enter your email address.");
    return false;
  }

  if (!eAddr.test(str))
  {
    alert ("Invalid format for email address.");
    return false;
  }

  return true;
}

function checkEM(main)
{
  // If an email address is entered, check that is has the
  // correct format

  if (main.email1.value)
  {
    if (!isValidEmail(main.email1.value)) {
      main.email1.focus();
      return false; }
  }
}
