<!--
//  this is a class to simplify AJAX calls greatly
function AJAX(method)
{
//  a couple of member variables
	this.method = method;
	this.url = "";
	this.params = new Array();
	this.result = "*";
	this.id = "";
	this.oneReplacement = true;
	this.history = new Array();
	this.xmlRequest;


	//  define the member object xmlRequest
	if(window.XMLHttpRequest)	//  most sane browsers (Firefox, IE7, Opera, et al)
	{
		try {  this.xmlRequest = new XMLHttpRequest();  }
		catch(e) {  this.xmlRequest = null;  }
	}
	else if(window.ActiveXObject)	//  IE < 7
	{
		try {  this.xmlRequest = new ActiveXObject("Msxml2.XMLHTTP");  }
		catch(e)
		{
			try {  this.xmlRequest = new ActiveXObject("Microsoft.XMLHTTP");  }
			catch(e) {  this.xmlRequest = null;  }
		}
	}
	else if(window.createRequest)	//  i hear that a browser called IceBrowser uses this method
	{
		try {  this.xmlRequest = window.createRequest();  }
		catch(e) {  this.xmlRequest = null;  }
	}
	else return;


//  write the result to the current page
	this.writeResult = function()
	{
	//  react based on whether we have the names of one or two divs
		var ids = new Array();
		ids = this.id.split(",");

		if(ids.length == 1 && document.getElementById(this.id)) document.getElementById(this.id).innerHTML = this.xmlRequest.responseText;
		else
		{
			var contents = new Array();
			contents = this.xmlRequest.responseText.split("_");

		//  write
			if(document.getElementById(ids[0])) document.getElementById(ids[0]).innerHTML = contents[0];
			if(document.getElementById(ids[0])) document.getElementById(ids[1]).innerHTML = contents[1];
		}

	//  change the cursor so that the user knows we're done loading
		document.body.style.cursor = "default";
	}


//  This is the function that actually makes the request and returns the result.
//  NOTE:  Parameters to the ajax request are passed as the 3rd, 4th, 5th, ... , nth parameters to ajaxRequest.  The function will deal with them appropriately.
	this.ajaxRequest = function(id, url)
	{
		this.history.push(this.url);
		this.url = escape("../" + url);
		this.id = id;
		this.params = new Array();

	//  change the cursor so that the user knows we're loading
		document.body.style.cursor = "wait";
        with (document.getElementById("loading"))
        {
            style.visibility = "visible";
            if (navigator.appName == "Microsoft Internet Explorer")
            {
                style.posLeft = document.body.clientWidth - 75;
                style.posTop = 0;
            }
            else
            {
                style.left = (window.innerWidth - 75) + "px";
                style.top = "0px";
            }
                
        }

	//  store the parameters that go to the php script
		for(var i=2; i<arguments.length; i++)
		{
		//  if it's an invalid name=value pair, ignore it
			if(arguments[i].indexOf("=") == -1 || arguments[i].indexOf("=") != arguments[i].lastIndexOf("=")) continue;
		//  split, url encode, and rejoin the name=value pair
			var tmpStr = new Array();
			tmpStr = arguments[i].split("=");
			tmpStr[0] = escape(tmpStr[0]);
			tmpStr[1] = escape(tmpStr[1]);
			this.params.push(tmpStr.join("="));
		}

	//  if this is a "GET" ajax object, append the parameters to the url, open the request, and send it with a null parameter string
		if(this.method == "GET")
		{
			if(this.params.length > 0) this.url += "?" + this.params.join("&");
			this.xmlRequest.open(this.method, this.url, true);

		//  define the onreadystatechange function
			var obj = this;
			this.xmlRequest.onreadystatechange = function()
			{
				if(obj.xmlRequest.readyState == 4) 
                {
                    obj.writeResult();
                    document.getElementById("loading").style.visibility = "hidden";
                }
			}

			this.xmlRequest.send(null);
		}

	//  if this is a "POST" ajax object, open the request first, then send the request with the parameter string
		else if(this.method == "POST")
		{
		//  open the request
			this.xmlRequest.open(this.method, this.url, true);
			this.xmlRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

		//  define the onreadystatechange function
			var obj = this;
			this.xmlRequest.onreadystatechange = function()
			{
				if(obj.xmlRequest.readyState == 4) obj.writeResult();
			}

		//  set up the parameter string
			var paramString = "";
			if(this.params.length > 0) paramString = this.params.join("&");

		//  send the parameters if they exist
			if(paramString.length > 0)
			{
				this.xmlRequest.setRequestHeader("Content-length", paramString.length);
				this.xmlRequest.setRequestHeader("Connection", "close");
				this.xmlRequest.send(paramString);
			}
			else this.xmlRequest.send(null);
		}

		return this.result;
	}
}
//-->
