var stateList_us = new Array(
new state("AL", "Alabama"),
new state("AK", "Alaska"),
new state("AZ", "Arizona"),
new state("AR", "Arkansas"),
new state("CA", "California"),
new state("CO", "Colorado"),
new state("CT", "Connecticut"),
new state("DE", "Delaware"),
new state("DC", "District Of Columbia"),
new state("FL", "Florida"),
new state("GA", "Georgia"),
new state("HI", "Hawaii"),
new state("ID", "Idaho"),
new state("IL", "Illinois"),
new state("IN", "Indiana"),
new state("IA", "Iowa"),
new state("KS", "Kansas"),
new state("KY", "Kentucky"),
new state("LA", "Louisiana"),
new state("ME", "Maine"),
new state("MD", "Maryland"),
new state("MA", "Massachusetts"),
new state("MI", "Michigan"),
new state("MN", "Minnesota"),
new state("MS", "Mississippi"),
new state("MO", "Missouri"),
new state("MT", "Montana"),
new state("NE", "Nebraska"),
new state("NV", "Nevada"),
new state("NH", "New Hampshire"),
new state("NJ", "New Jersey"),
new state("NM", "New Mexico"),
new state("NY", "New York"),
new state("NC", "North Carolina"),
new state("ND", "North Dakota"),
new state("OH", "Ohio"),
new state("OK", "Oklahoma"),
new state("OR", "Oregon"),
new state("PA", "Pennsylvania"),
new state("RI", "Rhode Island"),
new state("SC", "South Carolina"),
new state("SD", "South Dakota"),
new state("TN", "Tennessee"),
new state("TX", "Texas"),
new state("UT", "Utah"),
new state("VT", "Vermont"),
new state("VA", "Virginia"),
new state("WA", "Washington"),
new state("WV", "West Virginia"),
new state("WI", "Wisconsin"),
new state("WY", "Wyoming"),
new state("PR", "Puerto Rico"),
new state("VI", "Virgin Island"),
new state("MP", "Northern Mariana Islands"),
new state("GU", "Guam"),
new state("AS", "American Samoa"),
new state("PW", "Palau"));

var stateList_canada = new Array(
new state("AB", "Alberta"),
new state("BC", "British Columbia"),
new state("MB", "Manitoba"),
new state("NB", "New Brunswick"),
new state("NL", "Newfoundland and Labrador"),
new state("NS", "Nova Scotia"),
new state("NU", "Nunavut"),
new state("NT", "N.W.T."),
new state("ON", "Ontario"),
new state("PE", "Prince Edward Island"),
new state("QC", "Quebec"),
new state("SK", "Saskatchewan"),
new state("YT", "Yukon"));


function buildStateList(fm, countryCode){
	var stateList;

	if (countryCode == 1){
		stateList = stateList_us;
	} else if (countryCode == 2){
		stateList = stateList_canada;
	} else {
		return;
	}

	var oState = fm.state;
	oState.length = stateList.length;
	oState.options[0].text = "- select -";
	oState.options[0].value = "default";
	for (i = 0; i < oState.length; i++){
		oState.options[i].text = stateList[i].text;
		oState.options[i].value = stateList[i].value;
	}
	oState.selectedIndex = 0;
}

function state(value,text){
	this.value = value;
	this.text = text;
}

function changeContactCountry(fm){
	countryCode = fm.country.options[fm.country.selectedIndex].value;
	oCountryOther = document.getElementById("country_other");
	oStateOther = document.getElementById("state_other");
	oState = document.getElementById("state");

	if (countryCode == 1 || countryCode == 2){
		buildStateList(fm, countryCode);
		oCountryOther.style.display="none";
		oState.style.display="block";
		oStateOther.style.display="none";
	} else {
		// manual input for the other country
		oCountryOther.style.display="inline";
		oState.style.display="none";
		oStateOther.style.display="block";
		fm.country_other.focus();
	}
}

function submitContactForm(fm){
		var isValid;
		var errorMsg;
				
		fdFName = new FormData(fm.fname, "notnull", "Please enter First Name");
		fdLName = new FormData(fm.lname, "notnull", "Please enter Last Name");
		fdEmail = new FormData(fm.email, "email", "Please enter a valid Email Address");
		fdCompany = new FormData(fm.companyName, "notnull", "Please enter a valid Company Name");
		fdJobTitle = new FormData(fm.jobtitle, "notnull", "Please enter a valid Title");
		fdStreet = new FormData(fm.street, "notnull", "Please enter a valid Street");
		fdCity = new FormData(fm.city, "notnull", "Please enter a valid City");
		fdZipcode = new FormData(fm.zipcode, "notnull", "Please enter a valid Zip / Postal Code");
		fdphone = new FormData(fm.phone, "notnull", "Please enter a valid Phone Number");
		fdindustry = new FormData(fm.industry, "notnull", "Please enter Industry");
		arrFormData = new Array(fdFName, fdLName, fdEmail, fdJobTitle, fdCompany, fdStreet, fdCity, fdZipcode, fdphone,fdindustry);

		errorMsg = validateFormDataArray(arrFormData);

		// check state
		countryCode = fm.country.options[fm.country.selectedIndex].value;
		if (countryCode==1 || countryCode==2){
			if(fm.state.selectedIndex == 0){
				isValid = false;
				errorMsg += "Please enter a valid State / Province\n";
			}
		} else {
			if (fm.state_other.value==""){
				isValid = false;
				errorMsg += "Please enter a valid State / Province\n";
			}
		}
		
		// check comments
		var fcomments = null;
		fcomments = fm.comments;
		if (fcomments !=null && fcomments.value.length >= 2000){
			errorMsg += "Please enter Comments 2000 characters or less ";
		}


		if (errorMsg == "")
			isValid = true;
		else
			isValid = false;

		if (isValid){
			fm.submit();
		} else {
			alert(errorMsg);
		}

		return false;
	}



