function makeRequest(theurl, elmID, showLoad, clickmenu, pageReload, loadingObj) {
	var http_request = "";
	theurl = theurl+'&request='+Math.random()+'&ajax=1';
	
	if(loadingObj) {
		document.getElementById(loadingObj).style.display = "";
		document.getElementById(elmID).style.filter = "alpha(opacity=20)"
	}
	
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/xml');
		}
	} else if (window.ActiveXObject) { // IE
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}

	if (!http_request) {
		alert('Giving up :( Cannot create an XMLHTTP instance');
		return false;
	}
	http_request.onreadystatechange = function() { alertContents(http_request, elmID, showLoad, clickmenu, pageReload, loadingObj); };
	http_request.open('GET', theurl, true);
	
	http_request.send(null);
}
function alertContents(http_request, elmID, showLoad, clickMenu, pageReload, loadingObj) {

	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
			if(http_request.responseText != "") {
				if(elmID != "") {
				document.getElementById(elmID).innerHTML = http_request.responseText;
				if(loadingObj) {
					document.getElementById(elmID).style.filter = "alpha(opacity=100)"
				}
				}
				if(pageReload == 1) {
					document.location.reload();	
				}
			}
		} else {
			document.getElementById(elmID).innerHTML = 'There was a problem with the request. Status: '+http_request.status;
		}
	} else {
		if(showLoad == 1) {
			document.getElementById(elmID).innerHTML = 'Loading...';
		}
	}

}


function updateGeoData(curValue,FormHandler,FieldHandler,areaID) {

	FieldHandler.options[0] = new Option("...loading...");
	
	
	request = createRequest();
	var url = "/index.php?action=xmldata&get=country&country="+curValue;

	request.onreadystatechange = function() {
		if (request.readyState == 4 && request.status == 200) {
			
			PullDataSelect(request.responseXML,FieldHandler);	

			if(FieldHandler.options.length > 0) {
				document.getElementById(areaID).style.display = "";
				document.getElementById(areaID+'2').style.display = "";
			} else {
				document.getElementById(areaID).style.display = "none";
				document.getElementById(areaID+'2').style.display = "none";
			}
		}//if
    }//function
	request.open("GET", url, true);
	request.send(null);
}
function getSelectValue(FieldHandler) {
	return FieldHandler.options[FieldHandler.selectedIndex].value;
}
function createRequest() {
	try {
		request = new XMLHttpRequest();
	} catch (tryMS) {
		try {
			request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (otherMS) {
			try {
				request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (failed) {
				request = null;
			}
		}
	}
	return request;
}

function PullDataSelect(XMLData,FieldHandler){

	for(var k = FieldHandler.options.length-1; k>=0; k--){
		FieldHandler.options[k] = null;
	}//for
	
   	var root_node = XMLData.getElementsByTagName('geo').item(0);


	for (i = 0; i < root_node.getElementsByTagName('option').length; i++) {

		var root_data = root_node.getElementsByTagName('option').item(i);
		var data_value = root_data.getElementsByTagName('id').item(0);
		var data_text = root_data.getElementsByTagName('name').item(0);	

		newOption = document.createElement("option");
		newOption.value = data_value.firstChild.data;  // assumes option string and value are the same
		newOption.text = data_text.firstChild.data;
		// add the new option
		try {
			FieldHandler.add(newOption);  // this will fail in DOM browsers but is needed for IE
		}
		catch (e) {
			FieldHandler.appendChild(newOption);

		}
		
	}
}//PullData
