function validEmail(emailStr) 
{
    var checkTLD=1;
    var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
    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("Email address seems incorrect (check @ and .'s)");
      return false;
    }
    
    var user=matchArray[1];
    var domain=matchArray[2];
    
    
    for (i=0; i<user.length; i++) {
      if (user.charCodeAt(i)>127) {
        alert("The email address contains invalid characters.");
        return false;
      }
    }
    for (i=0; i<domain.length; i++) {
      if (domain.charCodeAt(i)>127) {
        alert("The domain name contains invalid characters.");
        return false;
      }
    }
    
    // See if "user" is valid 
    
    if (user.match(userPat)==null) {
    
    // user is not valid
    
       alert("The email address doesn't seem to be valid.");
       return false;
    }
    
    /* if the e-mail address is at an IP address (as opposed to a symbolic
    host name) make sure the IP address is valid. */
    
    var IPArray=domain.match(ipDomainPat);
    if (IPArray!=null) {
    
    // this is an IP address
    
    for (var i=1;i<=4;i++) 
	{
        if (IPArray[i]>255) 
		{
           alert("Destination IP address is invalid!");
           return false;
    	}
    }
    }
    // Domain is symbolic name.  Check if it's valid.
     
    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 does not seem to be valid.");
    	   return false;
    	}
    }
    
    /* domain name seems valid, but now make sure that it ends in a
    known top-level domain (like com, edu, gov) or a two-letter word,
    representing country (uk, nl), and that there's a hostname preceding 
    the domain or country. */
    
    if (checkTLD && domArr[domArr.length-1].length!=2 && 
        domArr[domArr.length-1].search(knownDomsPat)==-1) 
	{
        alert("The address must end in a well-known domain or two letter " + "country.");
		return false;
	}
    
    // Make sure there's a host name preceding the domain.
    
    if (len<2) 
	{
        alert("This address is missing a hostname!");
		return false;
	}
    
    // If we've gotten this far, everything's valid!
    return true;
}
    
function compare_email(valEmail, conEmail)
{
       var cEmail = document.getElementById(conEmail);
       var vEmail = document.getElementById(valEmail);
       if (vEmail.value != cEmail.value)
       {
          alert('Please enter a correct and identical email address in both the Contact Email Address and the Contact Email Verification text boxes.');
    	  return false;
       }
       else
          return true;
}

function validateRequiredFieldsStep1()
{
   if (((document.InboundEmail.AreaCode.value!="") &&
       (document.InboundEmail.Prefix.value!="") &&
       (document.InboundEmail.Suffix.value!="")) &&
       (document.InboundEmail.LastName.value!="") &&
       (document.InboundEmail.ContactEmail.value!="") &&
       (document.InboundEmail.valEmail.value!=""))
   {
      if (!validEmail(document.InboundEmail.ContactEmail.value))
	  {
	     document.InboundEmail.ContactEmail.focus();  
         return false;
	  }
	  else if (!compare_email('valEmail', 'conEmail'))
	  {
	     document.InboundEmail.ContactEmail.focus();  
         return false;
	  }
	  else
	     return true;
   }
   else
      return false;
}

function validateRequiredFieldsStep2()
{ 
   var ISP = document.getElementById("ISPService");
   var Modem = document.getElementById("Modem");
   var ConnType = document.getElementById("ConnectionType");
   var OS = document.getElementById("OS");

   if (validateRequiredFieldsStep1() &&
       (ISP.options[ISP.selectedIndex].text!="--Please Specify--") &&
       (Modem.options[Modem.selectedIndex].text!="--Please Specify--") &&
       (ConnType.options[ConnType.selectedIndex].text!="--Please Specify--") &&
       (OS.options[OS.selectedIndex].text!="--Please Specify--"))
   {
      return true;
   }
   else
   {
      return false;
   }
}

function validateRequiredFieldsStep3()
{
   var CategoryMenu = document.getElementById("categoryMenu");
   var CategorySubMenu = document.getElementById("subMenu");
   
   if (validateRequiredFieldsStep2() &&
       (CategoryMenu.options[CategoryMenu.selectedIndex].text!="--Please select a Category--") &&
       (CategorySubMenu.options[CategorySubMenu.selectedIndex].text!="--Please select a sub-category--"))
   {
      return true;
   }
   else
   {
      return false;
   }
}