//State selection box for signupForm - no matter division
function getStates(){
	var lst=document.forms["signupForm"].custState;
	lst.options[0]=new Option("Choose One", "");
	lst.options[1]=new Option("Alabama", "AL");
	lst.options[2]=new Option("Alaska", "AK");
	lst.options[3]=new Option("Arizona", "AZ");
	lst.options[4]=new Option("Arkansas", "AR");
	lst.options[5]=new Option("California", "CA");
	lst.options[6]=new Option("Colorado", "CO");
	lst.options[7]=new Option("Connecticut", "CT");
	lst.options[8]=new Option("Deleware", "DE");
	lst.options[9]=new Option("District of Columbia", "DC");
	lst.options[10]=new Option("Florida", "FL");
	lst.options[11]=new Option("Georgia", "GA");
	lst.options[12]=new Option("Hawaii", "HI");
	lst.options[13]=new Option("Idaho", "ID");
	lst.options[14]=new Option("Illinois", "IL");
	lst.options[15]=new Option("Indiana", "IN");
	lst.options[16]=new Option("Iowa", "IA");
	lst.options[17]=new Option("Kansas", "KS");
	lst.options[18]=new Option("Kentucky", "KY");
	lst.options[19]=new Option("Louisiana", "LA");
	lst.options[20]=new Option("Maine", "ME");
	lst.options[21]=new Option("Maryland", "MD");
	lst.options[22]=new Option("Massechusetts", "MA");
	lst.options[23]=new Option("Michigan", "MI");
	lst.options[24]=new Option("Minnesota", "MN");
	lst.options[25]=new Option("Mississippi", "MS");
	lst.options[26]=new Option("Missouri", "MO");
	lst.options[27]=new Option("Montana", "MT");
	lst.options[28]=new Option("Nebraska", "NE");
	lst.options[29]=new Option("Nevada", "NV");
	lst.options[30]=new Option("New Hampshire", "NH");
	lst.options[31]=new Option("New Jersey", "NJ");
	lst.options[32]=new Option("New Mexico", "NM");
	lst.options[33]=new Option("New York", "NY");
	lst.options[34]=new Option("North Carolina", "NC");
	lst.options[35]=new Option("North Dakota", "ND");
	lst.options[36]=new Option("Ohio", "OH");
	lst.options[37]=new Option("Oklahoma", "OK");
	lst.options[38]=new Option("Oregon", "OR");
	lst.options[39]=new Option("Pennsylvania", "PA");
	lst.options[40]=new Option("Rhode Island", "RI");
	lst.options[41]=new Option("South Carolina", "SC");
	lst.options[42]=new Option("South Dakota", "SD");
	lst.options[43]=new Option("Tennessee", "TN");
	lst.options[44]=new Option("Texas", "TX");
	lst.options[45]=new Option("Utah", "UT");
	lst.options[46]=new Option("Vermont", "VT");
	lst.options[47]=new Option("Virginia", "VA");
	lst.options[48]=new Option("Washington", "WA");
	lst.options[49]=new Option("West Virginia", "WV");
	lst.options[50]=new Option("Wisconsin", "WI");
	lst.options[51]=new Option("Wyoming", "WY");
	lst.options[0].selected=true;
}
/*
//Validate email address
function emailcheck(str){
	if(str.length>0){
		var cnt=0;
		var cntp=0;
		var p=0;
		var q=0;
		var s=str.length;
		for(var ii=0;ii<str.length;ii++){	
			if(str.charAt(ii)=="."){
				cnt++;
				p=ii;
			}
			if(str.charAt(ii)=="@"){
				cntp++;
				q=ii;
			}
		}
		if ( cntp!=1 || p<q || q==0 ||p-q<2 || p==s-1){
			alert("Please enter email address in proper format !")
			document.forms["signupForm"].custEmail.value="";
			document.forms["signupForm"].custEmail.focus();
		}		
	}
}
*/
//Check for valid email
function emailCheck (emailStr) {
	/* The following pattern is used to check if the entered e-mail address fits the user@domain format.  
	It also is used to separate the username from the domain. */
	var emailPat=/^(.+)@(.+)$/
	/* The following string represents the pattern for matching all special characters.  
	We don't want to allow special characters in the address. These characters include ( ) < > @ , ; : \ " . [ ]    */
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	/* The following string represents the range of characters allowed in a username or domainname.  
	It really states which chars aren't allowed. */
	var validChars="\[^\\s" + specialChars + "\]"
	/* The following pattern applies if the "user" is a quoted string (in which case, there are no rules 
	about which characters are allowed and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
   is a legal e-mail address. */
	var quotedUser="(\"[^\"]*\")"
	/* The following pattern applies for domains that are IP addresses, rather than symbolic names.  
	E.g. joe@[123.124.233.4] is a legal e-mail address. NOTE: The square brackets are required. */
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	/* The following string represents an atom (basically a series of non-special characters.) */
	var atom=validChars + '+'
	/* The following string represents one word in the typical username. For example, in 
	john.doe@somewhere.com, john and doe are words.  Basically, a word is either an atom or quoted string. */
	var word="(" + atom + "|" + quotedUser + ")"
	// The following pattern describes the structure of the user
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	/* The following pattern describes the structure of a normal symbolic domain, as opposed to ipDomainPat, shown above. */
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")

	/* Finally, let's start trying to figure out if the supplied address is
	valid. */

	/* Begin with the coarse pattern to simply break up user@domain into
	different pieces that are easy to analyze. */
	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. */
		var msg="Email address seems incorrect (check @ and .'s)";
		return msg;
	}
	var user=matchArray[1]
	var domain=matchArray[2]

	// See if "user" is valid 
	if (user.match(userPat)==null) {
		// user is not valid
		alert("The username doesn't seem to be valid.")
		document.signupForm.custEmail.focus()
		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!")
				document.signupForm.custEmail.focus()
				return false
		    }
	    }
		return true
	}

	// Domain is symbolic name
	var domainArray=domain.match(domainPat)
	if (domainArray==null) {
		alert("The domain name doesn't seem to be valid.")
		document.signupForm.custEmail.focus()
		return false
	}

	/* domain name seems valid, but now make sure that it ends in a
	three-letter word (like com, edu, gov) or a two-letter word,
	representing country (uk, nl), and that there's a hostname preceding 
	the domain or country. */

	/* Now we need to break up the domain to get a count of how many atoms
	it consists of. */
	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) {
		// the address must end in a two letter or three letter word.
		alert("The address must end in a three-letter domain, or two letter country.")
		document.signupForm.custEmail.focus()
		return false
	}

	// Make sure there's a host name preceding the domain.
	if (len<2) {
		var errStr="This address is missing a hostname!"
		alert(errStr)
		document.signupForm.custEmail.focus()
		return false
	}

	// If we've gotten this far, everything's valid!
	return true;
}
//Validate form entries
/*function validate(){
	var err=0;
	//make sure there is at least one local address
	var localtest=0;
	for (var a=1;a<=8;a++){
		var temp=eval("document.forms['signupForm'].local"+a);
		if (temp.value!=''){
			localtest=1;
		}
	}
	if (localtest==0){
		document.getElementById("local").style.color="#ff0000";
		alert ("At least one local email address is required");
		return false;
	}
	//current domain
	if (document.forms["signupForm"].domain[0].checked==true && document.forms['signupForm'].currentDomain.value==""){
		document.getElementById("current").style.color="#ff0000";
		document.forms['signupForm'].currentDomain.focus();
		alert ("This field is required");
		return false;
	}
	//new domain
	else if (document.forms["signupForm"].domain[1].checked==true){
		//make sure at least one domain is entered
		var domaintest=0;
		for (b=1;b<=3;b++){
			var temp=eval("document.forms['signupForm'].domainName"+b);
			if(temp.value!=''){
				domaintest=1;
			}
		}
		if(domaintest==0){
			document.getElementById("domainname").style.color="#ff0000";
			alert ("At least one domain name is required");
			return false;
		}
		//and .com or .org is indicated
		if(document.forms['signupForm'].top-level[0].checked==false && document.forms['signupForm'].top-level[1].checked==false){
			document.getElementById("toplevel").style.color="#ff0000";
			alert ("Top level option is required");
			return false;
		}
	}
	//either of the above
	else if (document.forms["signupForm"].domain[0].checked==false && document.forms["signupForm"].domain[1].checked==false){
		document.getElementById("domain").style.color="#ff0000";
		alert ("Domain name option is required");
		return false;
	}
	//company name 
	if (document.forms["signupForm"].custName.value==""){
		document.getElementById("company").style.color="#ff0000";
		alert ("This field is required");
		return false;
	}
	//contact name
	if (document.forms["signupForm"].custContact.value==""){
		document.getElementById("contact").style.color="#ff0000";
		document.forms['signupForm'].custContact.focus();
		alert ("This field is required");
		return false;
	}
	else {
		document.getElementById("contact").style.color="#000000";
	}
	//address
	if (document.forms["signupForm"].custAddress.value==""){
		document.getElementById("address").style.color="#ff0000";
		document.forms['signupForm'].custAddress.focus();
		alert ("This field is required");
		return false;
	}
	else {
		document.getElementById("address").style.color="#000000";
	}
	//city
	if (document.forms["signupForm"].custCity.value==""){
		document.getElementById("city").style.color="#ff0000";
		document.forms['signupForm'].custCity.focus();
		alert ("This field is required");
		return false;
	}
	else {
		document.getElementById("city").style.color="#000000";
	}
	//state
	if (document.forms["signupForm"].custState.value==""){
		document.getElementById("state").style.color="#ff0000";
		document.forms['signupForm'].custState.focus();
		alert ("This field is required");
		return false;
	}
	else {
		document.getElementById("state").style.color="#000000";
	}
	//zip code
	if (document.forms["signupForm"].custZipCode.value==""){
		document.getElementById("zip").style.color="#ff0000";
		document.forms['signupForm'].custZipCode.focus();
		alert ("This field is required");
		return false;
	}
	else {
		document.getElementById("zip").style.color="#000000";
	}
	//phone
	if (document.forms["signupForm"].custPhone.value==""){
		document.getElementById("phone").style.color="#ff0000";
		document.forms['signupForm'].custPhone.focus();
		alert ("This field is required");
		return false;
	}
	else {
		document.getElementById("phone").style.color="#000000";
	}
	//email address
	msg=emailCheck(document.forms["signupForm"].custEmail.value);
	if (msg!=true){
		document.getElementById("email").style.color="#ff0000";
		document.forms['signupForm'].custEmail.focus();
		alert(msg);
		return false;
	}
	else{
		document.getElementById("email").style.color="#000000";
	}
}*/
