
function initXMLhttp() {
	//Based on code courtesy of Jim Ley (Jibbering.com)
	//http://jibbering.com/2002/4/httprequest.html

	var xmlhttp = false;

	//for IE
	/*@cc_on @*/	//This is MS JScript's "Conditional Compilation" that lets us test for a version of JScript and whether or 
					//not we're permitted to initialize an XMLHTTP object, which may be blocked by end-user security settings.
					//  (It's commented out to block it from other browsers.}
					//  see: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/js56jsconconditionalcompilation.asp

	/*@if (@_jscript_version >= 5)
		try {
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (E) {
				xmlhttp = false;
			}
		}
	@else
		xmlhttp = false;
	@end @*/

	//for Mozilla/Safari
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') { //'undefined' is in quotes to avoid the "undefined is undefined" error message in IE5/Mac
		xmlhttp = new XMLHttpRequest();
	}
	
	return xmlhttp;	
}


function xmlParse(text) {
	//http://www.w3schools.com/xml/xml_parser.asp
	// code for IE
	if (window.ActiveXObject)
	  {
	  var doc=new ActiveXObject("Microsoft.XMLDOM");
	  doc.async="false";
	  doc.loadXML(text);
	  }
	// code for Mozilla, Firefox, Opera, etc.
	else
	  {
	  var parser=new DOMParser();
	  var doc=parser.parseFromString(text,"text/xml");
	  }

	// documentElement always represents the root node
	//return doc.documentElement;
	return doc;
}


function sendXMLhttp(url,data,mode) {
	xmlhttp = initXMLhttp(); //initialize an XMLHttpRequest object (returns false if not supported)
	switch (mode) {
		case 'GET':
			xmlhttp.open("GET", url+'?'+data, false); //3rd param ('false') is whether or not to continue before getting a response
			xmlhttp.send(null);
			break;
		case 'POST':
		default:
			xmlhttp.open("POST", url, false); //3rd param ('false') is whether or not to continue before getting a response
			xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			xmlhttp.send(data);
			break;
	}
	var response = new Array;
	if (xmlhttp.status=='200') {
		var responseNode = xmlParse(xmlhttp.responseText).getElementsByTagName('results')[0];
		response[0] = responseNode.getAttribute('status');
		if (first_child(responseNode)) response[1] = first_child(responseNode).nodeValue;
		if (responseNode.childNodes) response[2] = responseNode.childNodes;
	} else {
		response[0] = xmlhttp.status;
		response[1] = 'Server error: '+xmlhttp.statusText;
	}
	return response;
}