
/**
 * Send an HTML request to the given URL.
 * Asynchronously calls given callback (passing the given parameter).
 * 
 * @param url - URL to send request to  [string]
 * @param callback - callback to call   [function]
 * @param param - parameter to pass to callback [anything]
 */
function sendHtmlRequest(url, callback, param) {
	//alert("Requesting: URL: "+url);
	
	// get XML HTTP object
	var xmlHttp = false;
	if (typeof XMLHttpRequest != 'undefined') {
		// Mozilla, Opera, Safari and Internet Explorer 7
		xmlHttp = new XMLHttpRequest();
	}
	if (!xmlHttp) {
		// Internet Explorer 6 and older
		try {
			xmlHttp  = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try {
				xmlHttp  = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e) {
				xmlHttp  = false;
			}
		}
	}
	//alert("XML HTTP object: "+xmlHttp+", requested URL: "+url);
	
	// send request
	if (xmlHttp) {
		var async = false;
		xmlHttp.open('GET', url, async);
		if(async) {
			// register callback
			xmlHttp.onreadystatechange = function () {
				if (xmlHttp.readyState == 4) {
					//alert("Ready. status: "+xmlHttp.status);
					
					if(xmlHttp.status > 400) {
						alert("Response: status code = "+xmlHttp.status+", text = "+xmlHttp.responseText);
					} else {
						callback(xmlHttp.responseText, param);
					}
				} else {
					//alert("Ready state: "+xmlHttp.readyState+", response: "+xmlHttp.responseText);
				}
			};
			xmlHttp.send(null);
		} else {
			xmlHttp.send(null);
			if(xmlHttp.status > 400) {
				alert("Response: status code = "+xmlHttp.status+", text = "+xmlHttp.responseText);
			} else {
				callback(xmlHttp.responseText, param);
			}
		}
	} else {
		alert("XML HTTP object not supported.");
	}

}
