// Creates an XMLHttpRequest instance
function createXmlHttpRequestObject() {
	var xmlHttp;
	try {
		// This should work for all browsers except IE6 and older
		xmlHttp = new XMLHttpRequest();
	} catch (e) {
		var XmlHttpVersions = new Array(
			"MSXML2.XMLHTTP.7.0",
			"MSXML2.XMLHTTP.6.0",
			"MSXML2.XMLHTTP.5.0",
			"MSXML2.XMLHTTP.4.0",
			"MSXML2.XMLHTTP.3.0",
			"MSXML2.XMLHTTP",
			"Microsoft.XMLHTTP");
		
		// Try all Microsoft XML objects untill we find one
		for (var i=0; i<XmlHttpVersions.length && !xmlHttp; i++) {
			try {
				xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
			} catch(e) { }
		}
	}
	return xmlHttp;
}

// Request response from server using POST
function xmlHttpProcess(xmlHttp, func, requestUrl, parameters) {
	if (xmlHttp) {
		try {
			xmlHttp.open("POST", requestUrl, true);
			xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			xmlHttp.setRequestHeader("Content-length", parameters.length);
			xmlHttp.setRequestHeader("Connection", "close");
			xmlHttp.onreadystatechange = function() {
				if (xmlHttp.readyState == 4) {
					if (xmlHttp.status == 200) {
						try {
							// Process object response
							func(xmlHttp.responseText);
						} catch (e) {
							alert("Error reading the response: " + e.toString());
						}
					} else {
						alert("There was a problem retrieving the data:\n" + xmlHttp.statusText);
					}
				}
			}
			xmlHttp.send(parameters);
		} catch (e) {
			alert("Can't connect to server:\n" + e.toString());
		}
	}
}