function EmailCheck (emailStr)
{
  var emailPat=/^(.+)@(.+)$/
  var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
  var validChars="\[^\\s" + specialChars + "\]"
  var quotedUser="(\"[^\"]*\")"
  var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
  var atom=validChars + '+'
  var word="(" + atom + "|" + quotedUser + ")"
  var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
  var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
  var matchArray=emailStr.match(emailPat)
  if (matchArray==null) 
  {
     /* Too many/few @'s or something; basically, this address doesn't
     even fit the general mould of a valid e-mail address. */
    alert("Email address seems incorrect (check @ and .'s)");
    return (false);
  }

  var user=matchArray[1];
  var domain=matchArray[2];

  if (user.match(userPat)==null) 
  {
    // user is not valid
    alert("The username doesn't seem to be valid.");
    return (false);
  }

  var IPArray=domain.match(ipDomainPat)
  if (IPArray!=null) 
  {
    for (var i=1;i<=4;i++) 
    {
      if (IPArray[i]>255) 
      {
        alert("Destination IP address is invalid!");
        return (false);
      }
    }
    return (true);
  }

  var domainArray=domain.match(domainPat);
  if (domainArray==null) 
  {
    alert("The domain name doesn't seem to be valid.");
    return (false);
  }

  var atomPat=new RegExp(atom,"g");
  var domArr=domain.match(atomPat);
  var len=domArr.length;
  
  if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3) 
  {
    alert("The address must end in a three-letter domain, or two letter country.");
    return (false);
  }
  if (len<2) 
  {
    alert("This address is missing a hostname!");
    return (false);
  }
  return (true);
}

function Form1_Validator(theForm)
{
  now = new Date();
  month = Math.floor(now.getMonth() + 2);
  year  = now.getYear();
  if (year < 2000)
    { year += 1900 }

  if (theForm.name.value == "")
  {
    alert("Please enter a value for the 'Name' field.");
    theForm.name.focus();
    return (false);
  }
  if (!EmailCheck (theForm.email.value))
  {
    theForm.email.focus();
    return (false);
  }
  if (theForm.phone.value == "")
  {
    alert("Please enter a value for the 'Phone' field.");
    theForm.phone.focus();
    return (false);
  }
  if (theForm.address.value == "")
  {
    alert("Please enter a value for the 'Address' field.");
    theForm.address.focus();
    return (false);
  }
  
  var bd = document.forms[0].elements['bd[]'];
  var ed = document.forms[0].elements['ed[]'];
  var by = document.forms[0].elements['by[]'];
  var ey = document.forms[0].elements['ey[]'];
  var expert = document.forms[0].elements['expert[]'];

  for (i=0;i<=14;i++)
  {
    if ((bd[i].selectedIndex != 0 || ed[i].selectedIndex != 0 ||
        by[i].selectedIndex != 0 || ey[i].selectedIndex != 0) &&
        !expert[i].checked)
    {
      alert("Please enter a value for the 'Experience' field.");
      expert[i].focus();
      return (false);
    }
    if (expert[i].checked)
    {
      if (bd[i].selectedIndex == 0)
      {
      	alert("Please enter a value for the 'Begin Month' field.");
        bd[i].focus();
        return (false);
      }
      if (by[i].selectedIndex == 0)
      {
      	alert("Please enter a value for the 'Begin Year' field.");
        by[i].focus();
        return (false);
      }
      if (ed[i].selectedIndex == 0)
      {
      	alert("Please enter a value for the 'End Month' field.");
        ed[i].focus();
        return (false);
      }
      if (ey[i].selectedIndex == 0)
      {
      	alert("Please enter a value for the 'End Year' field.");
        ey[i].focus();
        return (false);
      }
    }
    if (by[i].selectedIndex > ey[i].selectedIndex)
    {
      alert("The 'End Year' may not be earlier than the 'Begin Year'.");
      ey[i].focus();
      return (false);
    }
    if (by[i].selectedIndex == ey[i].selectedIndex && bd[i].selectedIndex > ed[i].selectedIndex)
    {
      alert("The 'End Month' may not be earlier than the 'Begin Month'.");
      ed[i].focus();
      return (false);
    }
    if (ey[i].options[ey[i].selectedIndex].value == year &&
        ed[i].options[ed[i].selectedIndex].value > month)
    {
      alert("The 'End Date' may not be earlier than today.");
      ed[i].focus();
      return (false);
    }
  }
  return (true);
}
