function changeState() {
	if (document.getElementById("country").selectedIndex != 0) {
		document.getElementById("state").selectedIndex = 1;
	} else {
		document.getElementById("state").selectedIndex = 0
	}
}

/* 
	This when the alert box popups for validation, this will toggle the state/province so it will ask
	for you to enter a state or province
*/
function stateORprovince() { 
	var type = "state";
	if (document.getElementById("country").selectedIndex == 36) { 
		type = "province";
	}
	return type;
}

/*
	This function will change the state drop down to either US states if United States is selected or
	It will change it to a list of canadian provinces. It also changes the text to the left of the drop 
	down
*/
function changeCountryState() {
	var USName = new Array();
	USName[1] = new Array("AL", "Alabama");
	USName[2] = new Array ("AK", "Alaska");
	USName[3] = new Array ("AZ", "Arizona");
	USName[4] = new Array ("AR", "Arkansas");
	USName[5] = new Array ("CA", "California");
	USName[6] = new Array ("CO", "Colorado");
	USName[7] = new Array ("CT", "Connecticut");
	USName[8] = new Array ("DE", "Delaware");
	USName[9] = new Array ("DC", "District of Columbia");
	USName[10] = new Array ("FL", "Florida");
	USName[11] = new Array ("GA", "Georgia");
	USName[12] = new Array ("HI", "Hawaii");
	USName[13] = new Array ("ID", "Idaho");
	USName[14] = new Array ("IL", "Illinois");
	USName[15] = new Array ("IN", "Indiana");
	USName[16] = new Array ("IA", "Iowa");
	USName[17] = new Array ("KS", "Kansas");
	USName[18] = new Array ("KY", "Kentucky");
	USName[19] = new Array ("LA", "Louisiana");
	USName[20] = new Array ("ME", "Maine");
	USName[21] = new Array ("MH", "Maryland");
	USName[22] = new Array ("MA", "Massachusetts");
	USName[23] = new Array ("MI", "Michigan");
	USName[24] = new Array ("MN", "Minnesota");
	USName[25] = new Array ("MS", "Mississippi");
	USName[26] = new Array ("MO", "Missouri");
	USName[27] = new Array ("MT", "Montana");
	USName[28] = new Array ("NE", "Nebraska");
	USName[29] = new Array ("NV", "Nevada");
	USName[30] = new Array ("NH", "New Hampshire");
	USName[31] = new Array ("NJ", "New Jersey");
	USName[32] = new Array ("NM", "New Mexico");
	USName[33] = new Array ("NY", "New York");
	USName[34] = new Array ("NC", "North Carolina");
	USName[35] = new Array ("ND", "North Dakota");
	USName[36] = new Array ("OH", "Ohio");
	USName[37] = new Array ("OK", "Oklahoma");
	USName[38] = new Array ("OR", "Oregon");
	USName[39] = new Array ("PA", "Pennsylvania");
	USName[40] = new Array ("PR", "Puerto Rico");
	USName[41] = new Array ("RI", "Rhode Island");
	USName[42] = new Array ("SC", "South Carolina");
	USName[43] = new Array ("SD", "South Dakota");
	USName[44] = new Array ("TN", "Tennessee");
	USName[45] = new Array ("TX", "Texas");
	USName[46] = new Array ("UT", "Utah");
	USName[47] = new Array ("VT", "Vermont");
	USName[48] = new Array ("VA", "Virginia");
	USName[49] = new Array ("WA", "Washington");
	USName[50] = new Array ("WV", "West Virginia");
	USName[51] = new Array ("WI", "Wisconsin");
	USName[52] = new Array ("WY", "Wyoming");

	var CAName = new Array();
	CAName[1] = new Array("AB", "Alberta");
	CAName[2] = new Array ("BC", "British Columbia");
	CAName[3] = new Array ("MB", "Manitoba");
	CAName[4] = new Array ("NB", "New Brunswick");
	CAName[5] = new Array ("NL", "Newfoundland/Labrador");
	CAName[6] = new Array ("NS", "Nova Scotia");
	CAName[7] = new Array ("ON", "Ontario");
	CAName[8] = new Array ("PE", "Prince Edward Island");
	CAName[9] = new Array ("QC", "Quebec");
	CAName[10] = new Array ("SK", "Saskatchewan");

	document.getElementById("state").options.length = 0;
	
	if(document.getElementById("country").value == "US") { 
		addOption("state", "<--- Select US State --->", "");
		for(i=1; i<53; i++) {
			addOption("state",USName[i][1],USName[i][0] )
		}
		document.getElementById("stateDescription").innerHTML = "State";
	}
	else if(document.getElementById("country").value == "CA") {
		addOption("state", "<--- Select Province --->", "");
		for(i=1; i<11; i++) {
			addOption("state",CAName[i][1],CAName[i][0] )
		}
		document.getElementById("stateDescription").innerHTML = "Province";
	}
	else { 
		addOption("state", "<--- Select State--->", "");
		addOption("state","Not Available","N/A" )
		document.getElementById("state").selectedIndex = 1;
		document.getElementById("stateDescription").innerHTML = "State";
	}
	
	function addOption(selectbox,text,value ) {
		var optn = document.createElement("OPTION");
		optn.text = text;
		optn.value = value;
		document.getElementById(selectbox).options.add(optn);
	}
}

function disableState() {
	if (document.getElementById("country").selectedIndex != 0) {
		document.getElementById('state').disabled = true;
	} else {
		document.getElementById('state').disabled = false;
	}
}

function checkState(fieldname, message) {
	if (document.getElementById(fieldname).disabled = true || document.getElementById(fieldname).selectedIndex != 0) {
		return true;
	} else {
		alert (message);
		document.getElementById(fieldname).focus();
		return false;
	}
}

function checkText(fieldname, message) {
	if (document.getElementById(fieldname).value == "")  {
		document.getElementById(fieldname).focus();
		alert (message);
		return false;
	} else {
		return true;
	}
}

function checkSelect(fieldname, message) {
	if (document.getElementById(fieldname).selectedIndex == 0)  {
		document.getElementById(fieldname).focus();
		alert (message);
		return false;
	} else {
		return true;
	}		
}	

function checkCheckBox(fieldname, message) {
	if (document.getElementById(fieldname).checked == false) {
		document.getElementById(fieldname).focus();
		alert (message);
		return false;
	} else {
		return true;
	}
}	

function checkRadio(fieldname) {
	if (document.getElementById(fieldname).checked == false) {
		return false;
	} else {
		return true;
	}
}

function checkEmail(fieldname, message) {
	if ((document.getElementById(fieldname).value != "") && (document.getElementById(fieldname).value.indexOf("@") != -1) && (document.getElementById(fieldname).value.indexOf(".") != -1) && (document.getElementById(fieldname).value.indexOf(" ") == -1 )){
		return true;
	} else {
		alert (message);
		document.getElementById(fieldname).focus();
		return false;
	}
}

function checkStateCountry(state, country) {
	if(document.getElementById(country).value == "US" && document.getElementById(state).value == "N/A") {
		alert("Please select a valid state for the United States");
		return false;
	}
	else {
		return true;
	}
}

/***********************************************
* Textarea Maxlength script- © Dynamic Drive (www.dynamicdrive.com)
* This notice must stay intact for legal use.
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/			
function ismaxlength(obj){
	var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
	if (obj.getAttribute && obj.value.length>mlength)
	obj.value=obj.value.substring(0,mlength)
}