  var usaArray =  new Array("('Select State','',true,true)",
      "('Alabama')",
      "('Alaska')",
      "('Arizona')",
      "('Arkansas')",
      "('California')",
      "('Colorado')",
      "('Connecticut')",
      "('Delaware')",
      "('Dst of Columbia')",
      "('Florida')",
      "('Georgia')",
      "('Hawaii')",
      "('Idaho')",
      "('Illinois')",
      "('Indiana')",
      "('Iowa')",
      "('Kansas')",
      "('Kentucky')",
      "('Louisiana')",
      "('Maine')",
      "('Maryland')",
      "('Massachusetts')",
      "('Michigan')",
      "('Minnesota')",
      "('Mississippi')",
      "('Missouri')",
      "('Montana')",
      "('Nebraska')",
      "('Nevada')",
      "('New Hampshire')",
      "('New Jersey')",
      "('New Mexico')",
      "('New York')",
      "('North Carolina')",
      "('North Dakota')",
      "('Ohio')",
      "('Oklahoma')",
      "('Oregon')",
      "('Pennsylvania')",
      "('Rhode Island')",
      "('South Carolina')",
      "('South Dakota')",
      "('Tennessee')",
      "('Texas')",
      "('Utah')",
      "('Vermont')",
      "('Virginia')",
      "('Washington')",
      "('West Virginia')",
      "('Wisconsin')",
      "('Wyoming')");

   var canadaArray =  new Array("('Select Province','',true,true)",
      "('Alberta')",
      "('British Columbia')",
      "('Manitoba')",
      "('New Brunswick')",
      "('Newfoundland')",
      "('Northwest Territory')",
      "('Nova Scotia')",
      "('Nunavut')",
      "('Ontario')",
      "('Prince Edward Island')",
      "('Quebec')",
      "('Saskatchewan')",
      "('Yukon Territory')");

   function populateCountry(inForm,selected) {
      if (selected == 'other') {   
         newCountry = "";
         while (newCountry == ""){
            newCountry=prompt ("Please enter the name of your country.", "");
         }
         if (newCountry != null) {
            inForm.country.options[(inForm.country.options.length-1)]=new Option(newCountry,newCountry,true,true);
            inForm.country.options[inForm.country.options.length]=new Option('Foreign','other');
         }
         return;
      }
      
      var selectedArray = eval(selected + "Array");
      while (selectedArray.length < inForm.state.options.length) {
         inForm.state.options[(inForm.state.options.length - 1)] = null;
      }
      for (var i=0; i < selectedArray.length; i++) {
         eval("inForm.state.options[i]=" + "new Option" + selectedArray[i]);
      }
      if (inForm.country.options[0].value == '') {
         inForm.country.options[0]= null;
         if ( navigator.appName == 'Netscape') {
            if (parseInt(navigator.appVersion) < 4) {
               window.history.go(0);
            }
         else {   	
               if (navigator.platform == 'Win32' || navigator.platform == 'Win16') {
                     window.history.go(0);
               }
            }
         }
      }
   }
      
   function valField(nField) {
      var fValue = nField.value;
      var temp;
      for (i=0;i<fValue.length;i++) {
         temp = fValue.substring(i, i+1);
	      if (temp != " ") {
	          return true;
	      }
      }
      return false;
   }
   
   function valForm() {
        var cErrMsg = "";

        if (document.forms[0].f_name.value == "" || (!valField(document.forms[0].f_name))) {
            cErrMsg = cErrMsg + "\tFirst Name\n";
        }
        if (document.forms[0].l_name.value == "" || (!valField(document.forms[0].l_name))) {
            cErrMsg = cErrMsg + "\tLast Name\n";
        }
        if (document.forms[0].Func_Area == "" || (!valField(document.forms[0].Func_Area))) {
            cErrMsg = cErrMsg + "\tFunctional Area of Responsibility\n";
        }
        
        if (document.forms[0].c_name.value == "" || (!valField(document.forms[0].c_name))) {
            cErrMsg = cErrMsg + "\tCompany Name\n";
        }
        if (document.forms[0].address_1.value == "" || (!valField(document.forms[0].address_1))) {
            cErrMsg = cErrMsg + "\tAddress\n";
        }
        if (document.forms[0].city.value == ""|| (!valField(document.forms[0].city))) {
            cErrMsg = cErrMsg + "\tCity\n";
        }
        if (document.forms[0].state.options[document.forms[0].state.selectedIndex].text.substring(0,6)== "Select") {
            cErrMsg = cErrMsg + "\tState\n";
        }
        if (document.forms[0].postal.value == "") {
            cErrMsg = cErrMsg + "\tZip/Postal\n";
        }
        else
        if (document.forms[0].country.value == "usa" && document.forms[0].postal.value.length != 5) {
            cErrMsg = cErrMsg + "\tPlease, enter your 5 digits zip code\n";
        }
        else
        if (document.forms[0].country.value == "canada" && document.forms[0].postal.value.length != 6) {
            cErrMsg = cErrMsg + "\tPlease, enter your 6 characters zip code\n";
        }
        else
        if (document.forms[0].country.value == "usa" && document.forms[0].postal.value.length == 5) {
            var valid = "0123456789-";
            var hyphencount = 0;
            var field = document.forms[0].postal.value;

            for (var i=0; i < field.length; i++) {
	            temp = "" + field.substring(i, i+1);
	            if (temp == "-") hyphencount++;
	            if (valid.indexOf(temp) == "-1") {
	               cErrMsg = cErrMsg + "\tInvalid characters in your zip code.  Please try again.\n";
	               break;
	            }
	            if ((hyphencount > 1) || ((field.length==10) && "" + field.charAt(5)!="-")) {
	               cErrMsg = cErrMsg + "\tThe hyphen character should be used with a properly formatted 5 digit+four zip code, like '12345-6789'.   Please try again./n";
	               break;
	            }
	         }
	     }
        
        if (document.forms[0].phone.value == "") {
            cErrMsg = cErrMsg + "\tPhone\n";
        }
        else
        if (document.forms[0].phone.value.length != 14) {
            cErrMsg = cErrMsg + "\tWrong Phone Format\n";
        }
        else
        if (document.forms[0].phone.value.length == 14) {
            if (!checkUSPhone(document.forms[0].phone))
               return false;
        }
        
        if (document.forms[0].extns.value != "" &&
            (valField(document.forms[0].extns))) {
                var eValid = "0123456789";
                var eField = document.forms[0].extns.value;
                var ttemp;

                for (var i=0; i < eField.length; i++) {
                   ttemp = eField.substring(i, i+1);
	                if (eValid.indexOf(ttemp) == "-1") {
	                   cErrMsg = cErrMsg + "\tPhone Ext should be numeric.\n";
                      break;
	                }
                }
            
        }

        if (document.forms[0].email.value == "") {
            cErrMsg = cErrMsg + "\tEmail Address\n";
        }
        
        document.forms[0].password_1.value=document.forms[0].password_1.value.toLowerCase();
        if (document.forms[0].password_1.value == "" || 
            (!valField(document.forms[0].password_1))) {
            cErrMsg = cErrMsg + "\tPassword\n";
        }
        if (document.forms[0].password_1.value == "welcome") {
            cErrMsg = cErrMsg + "\tPassword, can not use Welcome for password\n";
        }
        
        if (document.forms[0].password_1.value.length < 4 ||
            document.forms[0].password_1.value.length > 20) {
            cErrMsg = cErrMsg + "\tPassword length should be more then 4 and less then 20 characters long\n";
        }
        if (document.forms[0].marketcat.value == "") {
            cErrMsg = cErrMsg + "\tCategory\n";
        }

        document.forms[0].password_2.value=document.forms[0].password_2.value.toLowerCase();
        //if (document.forms[0].password_2.value == "") {
        //    cErrMsg = cErrMsg + "\tConfirm\n";
        //}
        //if (document.forms[0].password_2.value == "welcome") {
        //    cErrMsg = cErrMsg + "\tConfirm, can not use Welcome for Confirm\n";
        //}

        if (document.forms[0].password_1.value != document.forms[0].password_2.value) {
            cErrMsg = cErrMsg + "\n\n______________________________________________\nPasswords do not match.\n";
        }
        
        //If an error was found
        if (cErrMsg != "") {
           cErrMsg = "The following field(s) are required and were not filled in.\n" +
                     "______________________________________________\n\n" +
                     cErrMsg;
            alert(cErrMsg);
            return false;
        }
        else {
            return emailCheck(document.forms[0].email.value.toLowerCase());
           //return true;
        }
    }
   
   function emailCheck (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 email address's domain contains invalid characters.");
            return false;
         }
      }

      if (user.match(userPat)==null) {
         alert("The email address 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("Email destination IP address 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 email address's domain name 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 two letter " + "country.");
            return false;
      }

      if (len<2) {
         alert("This email address is missing a hostname!");
         return false;
      }

      return true;
   }
   
   function emailvalidate(submitfunc,crowid,cgotorowid) 
   {
   	
      if (document.forms[0].outputformat.value == "") 
      {
         alert("You must select a format...");
         return;
      }

      for (i=0,n=document.main.elements.length;i<n;i++) 
      {
         if (document.main.elements[i].name.indexOf('OPT_30') !=-1 ||
            document.main.elements[i].name.indexOf('OPT_31') !=-1) 
         {

            if (!valemail())
               return;
         }
      }
      document.main.hSubmitFctn.value=submitfunc;
      document.main.hRowId.value=crowid;
      document.main.hGoToRowId.value=cgotorowid;
      document.main.submit();
   }
   
   function lowerCase()
   { 
      document.forms[0].email.value=document.forms[0].email.value.toLowerCase();
   }

   function popState() {
         for (var i=0; i < document.main.state.options.length; i++) {
            if (document.main.state.options[i].text==document.main.b_bstate.value) {
                 document.main.state.options[i].selected=true;
                 return;
            }
         }
   }
   
   //  End -->
