// JavaScript Document
var http_request = null;
var callback = null;
function GetHTTPRequest(){
	if (window.XMLHttpRequest && !(window.ActiveXObject)) {
		try {
			http_request = new XMLHttpRequest();
        } catch (e) {
			http_request = false;
		}
	} else if (window.ActiveXObject) {
		try {
			http_request = new ActiveXObject("MSXML2.XMLHTTP.3.0");
		} 
		catch (e){
			try{
				http_request = new ActiveXObject("Msxml2.XMLHTTP");  /* some versions IE */
			} 
			catch (e){
				try{
					http_request = new ActiveXObject("Microsoft.XMLHTTP");  /* some versions IE */
				} 
				catch (e){
					http_request = null;
				}
			}
		}
	}
	return http_request;
}

function AjaxRequest(AjaxURL, AjaxCompleteNotify)
{
	var AjaxRequestParams = new String("");
	var AjaxMethod = new String("post");
	callback = AjaxCompleteNotify;
	http_request = GetHTTPRequest();

	try {
		if (http_request != null)
		{
			if (AjaxURL.indexOf("?") >= 0 && AjaxMethod.toLowerCase() == "post")
			{
				AjaxRequestParams = AjaxURL.substring(AjaxURL.indexOf("?") + 1, AjaxURL.length);
				AjaxURL = AjaxURL.substring(0, AjaxURL.indexOf("?"));
			}
	
			http_request.onreadystatechange = HttpRequestHandler;
			http_request.open(AjaxMethod, AjaxURL, true);
	
			// If the http method is set to "post", the parameters need to be passed to the send function.
			if (AjaxMethod.toLowerCase() == "post")
			{
				http_request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				http_request.send(AjaxRequestParams);
			}
			else
			{
				http_request.send();
			}
		}
		else {
			if (callback && "function" == typeof(callback))
			{
				callback("");
			}
		}
	}
	catch (e) {
		if (callback && "function" == typeof(callback))
		{
			callback("");
		}
	}
}

function HttpRequestHandler()
{
	if (http_request.readyState == 4)
	{
		if (callback && "function" == typeof(callback))
		{
			callback(http_request.responseText);
		}
	}
}
