function checkForm() {
	if(document.forms.quicksearch.state.value == "") {
		alert(document.forms.quicksearch.state.options[0].text);
		return false;
	}
}

function stateDropdownOnChange() {
}

function countryDropdownOnChange() {
	fillStateList(document.forms.quicksearch.country.value);
}

function fillStateList(countryCode) {
	var stateList = document.forms.quicksearch.state;
	stateList.options[0] = new Option('Loading states...', '');

	http.open("get", "/location.php?cmd=getStateList&countryCode=" 
			+ document.forms.quicksearch.country.value);
	http.onreadystatechange = updateStateList;
	http.send(null);
}

function updateStateList() {
	if(http.readyState == 4) {
		var stateList = document.forms.quicksearch.state;

		var response = http.responseXML.documentElement;
		var country = response.getElementsByTagName('country')[0];
		var name = country.getElementsByTagName('name')[0].firstChild.data;
		var rd = country.getElementsByTagName('regionDesignator')[0].firstChild.data;
		var states = country.getElementsByTagName('region');
		
		stateList.options.length = 0;
		stateList.options[0] = new Option("Please Select a "+rd, "");
		stateList.selectedIndex = 0;

		for(var i=0; i<states.length; i++) {
			stateList.options[stateList.options.length] = 
				new Option(states[i].firstChild.data, states[i].getAttribute('code'));
		}
	}
}

function quicksearchSetup() {
	fillStateList(document.forms.quicksearch.country.value);
}

window.onload = quicksearchSetup;
