var xmlHttp = null;
var xmlHttpTimeout = null;
var xmlHttpFunction = null;
var xmlHttpReloadOnTimeout = false;
var xmlHttpTimoutSecs = 8;

function getXmlHttpObject()
{
	var x = null;
	try
	{
		// Firefox, Opera 8.0+, Safari
		x = new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			x = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			x = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return x;
}

function xmlHttpRequest(url, fn)
{
	xmlHttp = getXmlHttpObject();
	if (xmlHttp == null)
		return false;
//	if (fn != null)
	xmlHttpFunction = fn;
	xmlHttp.onreadystatechange = xmlHttpStateChange;
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
	xmlHttpTimeout = setTimeout(ajaxTimeout, xmlHttpTimoutSecs * 1000);
	return true;
}

function xmlHttpStateChange()
{
	if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
		clearTimeout(xmlHttpTimeout);
	if (xmlHttpFunction != null)
		xmlHttpFunction();
}

function ajaxTimeout()
{
	xmlHttp.abort();
	if (xmlHttpReloadOnTimeout)
		window.location.reload();
}

function xmlHttpReloadIfNotEmpty()
{
	if (xmlHttp.readyState != 4)
		return;
	if (xmlHttp.responseText != '')
		window.location.reload();
}
