var xmlHttp

function updateLocations(baseUrl) {

    //alert(baseUrl);



    var selectedCountryId = document.getElementById("countrySelect").options[document.getElementById("countrySelect").selectedIndex].value;

    if(document.getElementById("provinceSelect")) {
	var selectedProvinceId = document.getElementById("provinceSelect").options[document.getElementById("provinceSelect").selectedIndex].value;
    } else {
	var selectedProvinceId = "any";
    }

    if(document.getElementById("citySelect")) {
	var selectedCityId = document.getElementById("citySelect").options[document.getElementById("citySelect").selectedIndex].value;
    } else {
	var selectedCityId = "any";
    }

    //alert("hello 2");
    //var selectedSuburbId = document.getElementById("suburbSelect").options[document.getElementById("suburbSelect").selectedIndex].value;
    //alert("hello 3");

    //alert("selectedProvinceId = " + selectedProvinceId);

    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null)	{
	alert ("Your browser does not support AJAX!");
	return;
    } 


    var url=baseUrl+"?country="+selectedCountryId+"&province="+selectedProvinceId+"&city="+selectedCityId+"&rand="+Math.random();

    xmlHttp.onreadystatechange=function(){stateChanged(selectedProvinceId, selectedCityId);}
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
} 


function stateChanged(selectedProvinceId, selectedCityId) { 
    if (xmlHttp.readyState==4) { 
	document.getElementById("search-city").innerHTML=xmlHttp.responseText;
    } else {
	document.getElementById("suburbSelect").innerHTML="<option>loading ...&nbsp;</option>";
	if(selectedCityId == "any") {
	    document.getElementById("citySelect").innerHTML="<option>loading ...&nbsp;</option>";
	    if(selectedProvinceId == "any") {
		document.getElementById("provinceSelect").innerHTML="<option>loading ...&nbsp;</option>";
	    }
	}
    }
}

function GetXmlHttpObject() {
    var xmlHttp=null;
    try {
	// Firefox, Opera 8.0+, Safari
	xmlHttp=new XMLHttpRequest();
    } catch (e) {
	// Internet Explorer
	try {
	    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
	    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
    }
    return xmlHttp;
}



