function getXmlHttpLoader() {
	var xmlHttpLoader;
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	// JScript gives us Conditional compilation, we can cope with old IE versions.
	// and security blocked creation of the objects.
	try {
		xmlHttpLoader = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			xmlHttpLoader = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e) {
			xmlHttpLoader = false;
		}
	}
	@end @*/
	if (typeof XMLHttpRequest!='undefined') {
		if (typeof xmlHttpLoader != 'undefined') {
			alert (xmlHttpLoader.readyState);
		}
		xmlHttpLoader = new XMLHttpRequest();
	}
	// xmlHttpLoader.onreadystatechange = jsonLoadedEvent;
	return (xmlHttpLoader);
}

var jsonLoader = function(url, command, object, afterFunction) {
	var xmlHttpLoader = getXmlHttpLoader();
	var postdata = 'op='+command+'&';

	var h, i, j;

	for (i in object) {
		if (typeof object[i] == 'object') {
			postdata += "p["+i+"]=[";
			for (j in object[i]) {
				postdata += object[i][j] + ";";
			}
			postdata += "]&";
		} else {
			postdata += "p["+i+"]=" + object[i] + "&"; // Oh well, one "&" at the back won't hurt.
		}
	}
	/*
	h = 0;
	for (i in options) {
		if (i == 'wantedcolumns' && typeof options[i] == 'object') {
			postdata += "w["+h+"]=" + options[i][h] + "&";
			h++;
		}
		postdata += "o["+i+"]=" + options[i] + "&";
	}
	*/

	function decompress(header, data) {
		var newdata = {}, shortindex, longindex;
		for (shortindex in data) {
			longindex = header[shortindex] || shortindex;
			if (typeof data[shortindex] == 'object') {
				newdata[longindex] = decompress(header, data[shortindex])
			} else {
				newdata[longindex] = data[shortindex];
			}
		}
		return newdata;
	}

	xmlHttpLoader.onreadystatechange = function() {
		var response;
		if (xmlHttpLoader.readyState == 4) {
			// alert(xmlHttpLoader.responseText);
			try {
				debug("jsonLoader: response: " + xmlHttpLoader.responseText);
				debug("jsonLoader: response length: " + xmlHttpLoader.responseText.length);
				eval("response = " + xmlHttpLoader.responseText);
			} catch (err) {
				if (xmlHttpLoader.responseText) {
					debug('jsonLoader Error!\n\n' + xmlHttpLoader.responseText, 1);
				} else {
					debug('xmlHttpLoader.responseText not defined!', 1);
				}
			}
			if (response['header']) {
				response = decompress(response['header'], response['data']);
			}
			afterFunction.call(this, response);
		}
		delete(this);
	};
	debug('jsonloader: ' + url + '?' + postdata);
	xmlHttpLoader.open("POST", url, true);
	xmlHttpLoader.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttpLoader.send(postdata);
}
