var xmlHttp;
// JavaScript Document
function createXMLHttpRequest() {
	if (window.ActiveXObject) {
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else if (window.XMLHttpRequest) {
		xmlHttp = new XMLHttpRequest();
	}
}

var curCounty;

function loadCounties(state, county) {
	curCounty = county;
	createXMLHttpRequest();
	url = "http://www.stormwatchalert.com/data/general.php?action=getcountylist&state="+state;
	xmlHttp.onreadystatechange = loadCountiesRequest;
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}

// This is a prototype of a fuction to handle the response initiated from the function above
function loadCountiesRequest() {
	if(xmlHttp.readyState == 4) {
		if(xmlHttp.status == 200) {
			outText = parseCounties();
			//alert("The server replied with: " + outText);
		}
	}
}

function parseCounties(){
	var xmlDoc = xmlHttp.responseXML;
	var nodes = xmlDoc.getElementsByTagName("name");
	
	wheretostop = nodes.length;
	
	document.getElementById("pickcounty").options.length = 0
	
	for(i=0;i<nodes.length;i++){
		//alert(nodes[i].childNodes[0].nodeValue);
		if(curCounty == nodes[i].childNodes[0].nodeValue){
			document.getElementById("pickcounty").options[i] = new Option(nodes[i].childNodes[0].nodeValue,nodes[i].childNodes[0].nodeValue,false,true);
		}
		else{
			document.getElementById("pickcounty").options[i] = new Option(nodes[i].childNodes[0].nodeValue,nodes[i].childNodes[0].nodeValue,false,false);
		}
	}
	//var responseNode = xmlDoc.getElementsByTagName("response")[0];
	return wheretostop;
}