//State selection box for mailForm - no matter division
function getStates(){
	lst=document.forms["mailForm"].custState;
	lst.options[0]=new Option("Alabama", "AL");
	lst.options[1]=new Option("Alaska", "AK");
	lst.options[2]=new Option("Arizona", "AZ");
	lst.options[3]=new Option("Arkansas", "AR");
	lst.options[4]=new Option("California", "CA");
	lst.options[5]=new Option("Colorado", "CO");
	lst.options[6]=new Option("Connecticut", "CT");
	lst.options[7]=new Option("Deleware", "DE");
	lst.options[8]=new Option("District of Columbia", "DC");
	lst.options[9]=new Option("Florida", "FL");
	lst.options[10]=new Option("Georgia", "GA");
	lst.options[11]=new Option("Hawaii", "HI");
	lst.options[12]=new Option("Idaho", "ID");
	lst.options[13]=new Option("Illinois", "IL");
	lst.options[14]=new Option("Indiana", "IN");
	lst.options[15]=new Option("Iowa", "IA");
	lst.options[16]=new Option("Kansas", "KS");
	lst.options[17]=new Option("Kentucky", "KY");
	lst.options[18]=new Option("Louisiana", "LA");
	lst.options[19]=new Option("Maine", "ME");
	lst.options[20]=new Option("Maryland", "MD");
	lst.options[21]=new Option("Massechusetts", "MA");
	lst.options[22]=new Option("Michigan", "MI");
	lst.options[23]=new Option("Minnesota", "MN");
	lst.options[24]=new Option("Mississippi", "MS");
	lst.options[25]=new Option("Missouri", "MO");
	lst.options[26]=new Option("Montana", "MT");
	lst.options[27]=new Option("Nebraska", "NE");
	lst.options[28]=new Option("Nevada", "NV");
	lst.options[29]=new Option("New Hampshire", "NH");
	lst.options[30]=new Option("New Jersey", "NJ");
	lst.options[31]=new Option("New Mexico", "NM");
	lst.options[32]=new Option("New York", "NY");
	lst.options[33]=new Option("North Carolina", "NC");
	lst.options[34]=new Option("North Dakota", "ND");
	lst.options[35]=new Option("Ohio", "OH");
	lst.options[36]=new Option("Oklahoma", "OK");
	lst.options[37]=new Option("Oregon", "OR");
	lst.options[38]=new Option("Pennsylvania", "PA");
	lst.options[39]=new Option("Rhode Island", "RI");
	lst.options[40]=new Option("South Carolina", "SC");
	lst.options[41]=new Option("South Dakota", "SD");
	lst.options[42]=new Option("Tennessee", "TN");
	lst.options[43]=new Option("Texas", "TX");
	lst.options[44]=new Option("Utah", "UT");
	lst.options[45]=new Option("Vermont", "VT");
	lst.options[46]=new Option("Virginia", "VA");
	lst.options[47]=new Option("Washington", "WA");
	lst.options[48]=new Option("West Virginia", "WV");
	lst.options[49]=new Option("Wisconsin", "WI");
	lst.options[50]=new Option("Wyoming", "WY");
	lst.options[15].selected=true;
}
//Check customer type and action based on type
function checkType(type){
	switch (type){
		case "company":
			document.getElementById("company").innerHTML="<font color=\"#ff0000\">*</font> Company Name";
			document.forms["mailForm"].custName.value="";
			document.forms["mailForm"].custName.disabled=false;
			break;
		case "individual":
			document.getElementById("company").innerHTML="Company Name";
			document.forms["mailForm"].custName.value="Not Applicable";
			document.forms["mailForm"].custName.disabled=true;
			break;	
	}
}
//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["mailForm"].custEmail.value="";
			document.forms["mailForm"].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. */
		alert("Email address seems incorrect (check @ and .'s)")
		document.mailForm.custEmail.focus()
		return false
	}
	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.mailForm.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.mailForm.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.mailForm.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.mailForm.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.mailForm.custEmail.focus()
		return false
	}

	// If we've gotten this far, everything's valid!
	return true;
}
//Validate form entries
function validate(){
	var err=0;
	//company name only if company checked
	if (document.forms["mailForm"].custType[0].checked){
		if (document.forms["mailForm"].custName.value==""){
			document.getElementById("company").style.color="#ff0000";
			err=1;
		}
	}
	//contact name
	if (document.forms["mailForm"].custContact.value==""){
		document.getElementById("contact").style.color="#ff0000";
		err=1;
	}
	//address
	if (document.forms["mailForm"].custAddress.value==""){
		document.getElementById("address").style.color="#ff0000";
		err=1;
	}
	//city
	if (document.forms["mailForm"].custCity.value==""){
		document.getElementById("city").style.color="#ff0000";
		err=1;
	}
	//state- may not need as blank is not an option
	/*
	if (document.forms["mailForm"].custState.value==""){
		document.getElementById("state").style.color="#ff0000";
		err=1;
	}
	*/
	//zip code
	if (document.forms["mailForm"].custZipCode.value==""){
		document.getElementById("zipcode").style.color="#ff0000";
		err=1;
	}
	//phone number
	if (document.forms["mailForm"].custPhone.value==""){
		document.getElementById("phone").style.color="#ff0000";
		err=1;
	}
	//email address
	if (document.forms["mailForm"].custEmail.value==""){
		document.getElementById("email").style.color="#ff0000";
		err=1;
	}
	//service - may not need as blank is not an option
	/*
	if (document.forms["mailForm"].services.value==""){
		document.getElementById("service").style.color="#ff0000";
		err=1;
	}
	*/
	//explanation
	if (document.forms["mailForm"].description.value==""){
		document.getElementById("desc").style.color="#ff0000";
		err=1;
	}
	if (err==0){
		return true;	
	}
	else {
		alert ("Missing Information");
		return false;
		
	}
}