

// JavaScript File



var gHttpReq;
var ajaxTimeout = 10 * 1000;  // 10 seconds, in milliseconds
var ajaxTimeoutWatcher;

// -- Get a request object
function getHTTPObject()
{
	var xmlhttp;

	/*@cc_on
	@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 @*/

	if (!xmlhttp && typeof XMLHttpRequest != 'undefined')
	{
		try
		{
			xmlhttp = new XMLHttpRequest();
		}
		catch (e)
		{
			xmlhttp = false;
		}
	}

	return xmlhttp;
}

function GetAjaxContent(whereItsAt, thingToDo)
{
	var httpRequest;

	try
	{
		httpRequest = getHTTPObject();
	}
	catch (e)
	{
		return;
	}

	if (httpRequest == null)
		return;

	// -- Handle notifying some browsers of the permissions required for this operation
	try
	{
		netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
	}
	catch (e)
	{
		// -- Only for some browsers, tells them to prompt for permission instead of outright deny, I think...
	}

	// -- Make sure the browser is supporting the XMLhttpRequest object
	if (!httpRequest)
	{
		thingToDo("NOT_SUPPORTED");
	}

	// -- Avoid domain permissions errors when a www.* domain and one without www.* refer to the same page, by standardizing to match the window url
	if (window.location.href.indexOf("www.") != -1 && whereItsAt.indexOf("http://") != -1 && whereItsAt.indexOf("www.") == -1)    // url has www, and page address isn't relative so page address should too
	{
		whereItsAt = whereItsAt.replace("http://", "http://www.");
	}
	else if (window.location.href.indexOf("www.") == -1 && whereItsAt.indexOf("http://") != -1 && whereItsAt.indexOf("www.") != -1)    // url has no www, and page address isn't relative so page address shouldn't too
	{
		whereItsAt = whereItsAt.replace("http://www.", "http://");
	}

	whereItsAt = whereItsAt + "&random=" + Math.floor(Math.random() * 100000000);

	try
	{
		httpRequest.open('GET', whereItsAt, true);
		httpRequest.onreadystatechange = function() { updateLoadStatus(httpRequest, thingToDo); };
		httpRequest.send(null);
	}
	catch (e) { }
	
	gHttpReq = httpRequest;
	ajaxTimeoutWatcher = setTimeout("abortLastKnownConnection();", ajaxTimeout);
}

function updateLoadStatus(httpRequest, thingToDo)
{
    clearTimeout(ajaxTimeoutWatcher);

	// -- Set the status message
	switch (httpRequest.readyState)
	{
		case 1:
			break;
		case 2:
			break;
		case 3:
			break;
		case 4:
			if (httpRequest.status == 200)
				thingToDo(httpRequest.responseText);
			else
				;
			break;
		default:
			break;
	}
}

function abortLastKnownConnection()
{
    gHttpReq.abort();
    SetError();
    SetIdle();
}