buildQuery = function (query) {
	var data='';
	for (i in query) data+=(data==''?'?':'&')+escape(i)+"="+escape(query[i]);
	return data;
}

getXMLRequestObject = function () {
	if (typeof(XMLHttpRequest)!='undefined') return new XMLHttpRequest();
	var ax=['Msxml2.XMLHTTP.6.0', 'Msxml2.XMLHTTP.4.0',
					'Msxml2.XMLHTTP.3.0', 'Msxml2.XMLHTTP',
					'Microsoft.XMLHTTP'];
	for (var i=0; i<ax.length; i++)
					try { return new ActiveXObject(ax[i]); }
					catch (e) {}
	return null;
}

genericRequest = function (method,uri,content,callback,fallback,async) {
	var xmlhttp=getXMLRequestObject();
	if (async) 
		xmlhttp.onreadystatechange=function () {
			if (xmlhttp.readyState==4)
				if (xmlhttp.status==200)
					callback(xmlhttp);
				else
					fallback(xmlhttp);
		};
	if (method=="POST") {
		xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
		xmlhttp.setRequestHeader("Content-length",content.length);
		xmlhttp.setRequestHeader("Connection","close");
	} else content="";
	xmlhttp.open(method.toUpperCase(),uri,async);
	xmlhttp.send(content);
	return async?true:xmlhttp;
}

asyncRequest = function (method,uri,content,callback,fallback) {
	return genericRequest(method,uri,content,callback,fallback,true);
}
blockRequest = function (method,uri,content) {
	return genericRequest(method,uri,content,null,null,false);
}

GET = function (url, query, callback, fallback) {
	return asyncRequest(
		"GET",
		url+buildQuery(query),
		"",
		callback,
		fallback);
}

