var XmlHttpObj;
function CreateXmlHttpObj(){
	try{
		XmlHttpObj = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e){
		try{
			XmlHttpObj = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch(oc){
			XmlHttpObj = null;
		}
	}
	if(!XmlHttpObj && typeof XMLHttpRequest != "undefined"){
		XmlHttpObj = new XMLHttpRequest();
	}
}
function ContinentListOnChange(){
    var continentList = document.getElementById("continentList");
    var selectedContinent = continentList.options[continentList.selectedIndex].value;
    var requestUrl;
    requestUrl = "inc/xml_data_provider.php" + "?filter=" + encodeURIComponent(selectedContinent);
	CreateXmlHttpObj();
	if(XmlHttpObj){
		XmlHttpObj.onreadystatechange = StateChangeHandler;
		XmlHttpObj.open("GET", requestUrl,  true);
		XmlHttpObj.send(null);		
	}
}
function StateChangeHandler(){
	if(XmlHttpObj.readyState == 4){
		if(XmlHttpObj.status == 200){			
			PopulateCountryList(XmlHttpObj.responseXML.documentElement);
		}else{
			alert("problem retrieving data from the server, status code: "  + XmlHttpObj.status);
		}
	}
}
function PopulateCountryList(countryNode){
    var ich_altdaire = document.getElementById("ich_altdaire");
	for (var count = ich_altdaire.options.length-1; count >-1; count--){
		ich_altdaire.options[count] = null;
	}
	var countryNodes = countryNode.getElementsByTagName('country');
	var idValue;
	var textValue; 
	var optionItem;
	for (var count = 0; count < countryNodes.length; count++){
   		textValue = GetInnerText(countryNodes[count]);
		idValue = GetInnerText(countryNodes[count]); 
		optionItem = new Option( textValue, idValue,  false, false);
		ich_altdaire.options[ich_altdaire.length] = optionItem;
	}
}
function GetInnerText (node){
	 return (node.textContent || node.innerText || node.text) ;
}
