var xmlHttp

function GetXmlHttpObject(){ 
	var objXMLHttp=null
	if (window.XMLHttpRequest){
		objXMLHttp=new XMLHttpRequest()
	} else if (window.ActiveXObject){
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
	return objXMLHttp
}

function populateMenu2() { 
	menu1=document.getElementById('league_id1');
	
	var workingDiv=document.getElementById('workingDiv');
	workingDiv.innerHTML="<img src=\"images/working.gif\" />";
	
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
		alert ("Browser does not support HTTP Request");
		return;
	} 
	var url="register_ajax_xml.php";
	url=url+"?league_id="+menu1.value;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged_populateMenu2;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	
}

function stateChanged_populateMenu2(){ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
		if (xmlHttp.status == 200) {
			xmlDoc=xmlHttp.responseXML;
			var workingDiv=document.getElementById('workingDiv');
			var menuOptions = xmlDoc.getElementsByTagName("menuOption");
			var labels = xmlDoc.getElementsByTagName("label");
			var values = xmlDoc.getElementsByTagName("value");
					
			menu2=document.getElementById('league_id2');
			menu2.length = menuOptions.length;
			if(menu2.length > 2){
				for (o=0; o < menu2.length; o++){
					menu2[o].text = labels[o].childNodes[0].nodeValue.substring(1);
					menu2[o].value = values[o].childNodes[0].nodeValue.substring(1);
				}
				document.getElementById('area').style.display='block';
			} else {
				document.getElementById('area').style.display='none';	
			}
			//set selected option according to postback
			var areadropdown = document.getElementById('league_id2');
			for (var intI = 0; intI < areadropdown.options.length -1; intI++) {
				if (areadropdown.options[intI].value == league_id2) {
					areadropdown.options[intI].selected = true;
				}
			}
			workingDiv.innerHTML="";
		}
	}
} 