//------------------------------------------------------------------------
// Browser detect
//------------------------------------------------------------------------

var agt = navigator.userAgent.toLowerCase();
var is_ie = (agt.indexOf("msie") != -1);
var is_ie5 = (agt.indexOf("msie 5") != -1);
var is_opera = (agt.indexOf("opera") != -1);
var is_mac = (agt.indexOf("mac") != -1);
var is_gecko = (agt.indexOf("gecko") != -1);
var is_safari = (agt.indexOf("safari") != -1);

//------------------------------------------------------------------------
// Communication with server
//------------------------------------------------------------------------

function CreateXmlHttpReq(handler) {

	var xmlhttp = null;
	if (is_ie) {
		// Guaranteed to be ie5 or ie6
		var control = (is_ie5) ? "Microsoft.XMLHTTP" : "Msxml2.XMLHTTP";

		try {
			xmlhttp = new ActiveXObject(control);
			xmlhttp.onreadystatechange = handler;
		} catch (ex) {
			// TODO: better help message
			alert("You need to enable active scripting and activeX controls");
		}

	} else {

		// Mozilla
		xmlhttp = new XMLHttpRequest();
		xmlhttp.onload = handler;
		xmlhttp.onerror = handler;

	}
	return xmlhttp;
}

// XMLHttp send POST request
function XmlHttpPOST(xmlhttp, url, data) {
	try {
		xmlhttp.open("POST", url, true);
		xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		xmlhttp.send(data);
	} catch (ex) {
		// do nothing
	}
}

// XMLHttp send GEt request
function XmlHttpGET(xmlhttp, url) {
	try {
		rnd=Math.round((Math.random()*10000000));
		xmlhttp.open("GET", url+'?rnd='+rnd, true);
		xmlhttp.send(null);
	} catch (ex) {
		window.alert(ex);
		// do nothing
	}
}

function XmlHttpHandler(){

}

