// Process a Form entered Email Address.
function emailAddress()
{
	var email;
	email = document.eMailFORM.email.value;
	if (!checkEmail(email))
	{
		return false;
	}
	//LaunchInCenter('./emailpopup.html?email=' + email, 'name', 450, 640, 'no');
}

// Launch a centered Window with relative name and size dimensions.
function LaunchInCenter(url, name, height, width, scroll)
{
	var str = "height=" + height + ",innerHeight=" + height;
	str += ",width=" + width + ",innerWidth=" + width;
	if (window.screen)
	{
		var ah = screen.availHeight - 30;
		var aw = screen.availWidth - 10;
		var xc = (aw - width) / 2;
		var yc = (ah - height) / 2;
		str += ",left=" + xc + ",screenX=" + xc;
		str += ",top=" + yc + ",screenY=" + yc;
		str +=",scrollbars=" + scroll
	}
	return window.open(url, name, str);
}

// A thorough check of an email address entry.
function checkEmail(emailStr)
{
  var checkTLD=1;
  var checkEXD=1;
  var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum|ca)$/;
  var excludeDomsPat=/^(gmail|earthlink|yahoo|msn|sbcglobal|hotmail|aol|comcast)$/;
  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)
  {
    alert("The Email Address entered appears to be incorrect (check the @ and/or . separators).");
    return false;
  }

  var user=matchArray[1];
  var domain=matchArray[2];
  for (i=0; i<user.length; i++)
  {
    if (user.charCodeAt(i)>127)
    {
      alert("The User Name you have entered contains invalid characters.");
      return false;
    }
  }
  if (user.match(userPat)==null)
  {
    alert("The User Name you have entered doesn't seem to be valid.");
    return false;
  }
  for (i=0; i<domain.length; i++)
  {
    if (domain.charCodeAt(i)>127)
    {
      alert("The Domain Name you have entered contains invalid characters.");
      return false;
    }
  }
  var IPArray=domain.match(ipDomainPat);
  if (IPArray!=null)
  {
    for (var i=1;i<=4;i++)
    {
      if (IPArray[i]>255)
      {
        alert("The Destination IP address entered is invalid!");
        return false;
      }
    }
    return true;
  }
  var atomPat=new RegExp("^" + atom + "$");
  var domArr=domain.split(".");
  var len=domArr.length;
  for (i=0;i<len;i++)
  {
    if (domArr[i].search(atomPat)==-1)
    {
      alert("The Domain Name you have entered does not seem to be valid.");
      return false;
    }
  }
  if (checkTLD && domArr[domArr.length-1].length!=2 && domArr[domArr.length-1].search(knownDomsPat)==-1)
  {
    alert("The Email Address must end in a well-known Domain or a two letter " + "Country Code.");
    return false;
  }
  if (checkEXD && domArr[0].search(excludeDomsPat)!=-1)
  {
    alert("You must use a Corporate Email address.");
    return false;
  }
  if (len<2)
  {
    alert("This Address is missing a hostname!");
    return false;
  }
  return true;
}


