/*
Cameron's Ajax implementation, 27/10/2008
Very simple, nothing but basic functionality. Only using it because
I don't know how to use AjaxAnywhere and had to save a bit of time.

Include this JS file and call "sendAjax(url, updateFunction)" when you want to
retrieve data. The given updateFunction will be executed when the request
completes.

If, for any reason, you need to include parameters with the given update function,
pass them in in an array as the third argument (which is optional).
For example:

sendAjax("http://www.google.com/search?q=fish", parseResults, ["swordfish", "black fish"]);

function parseResults(fishType, excludeFishType)
{
 // ....
}

*/

var request = null;
var updateFunction = null;
var optionalArgument = null;
//Load the request object in static JavaScript.
try 
{
	request = new XMLHttpRequest();
} 
catch (trymicrosoft) 
{
	try 
	{
		request = new ActiveXObject("Msxml2.XMLHTTP");
	} 
	catch (othermicrosoft) 
	{
		try 
		{
			request = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch (failed) 
		{
			request = false;
		}  
	}
}
if (!request)
	alert("Error: Could not initialize XMLHttpRequest.\n\nMessage: You must either upgrade your Internet browser to a newer version or decrease your security settings before you can use this website.");

function sendAjax(url, theUpdateFunction)
{
	sendAjax(url, theUpdateFunction, null);
}

function sendAjax(url, theUpdateFunction, theOptionalArguments)
{
	try
	{
		request.open("GET", url, true);
		updateFunction = theUpdateFunction;
		optionalArguments = theOptionalArguments;
		request.onreadystatechange = ajaxUpdatePage;
		request.send(null);
	}
	catch(exception)
	{
		alert(exception);
	}
}

function ajaxUpdatePage()
{
	if(request.readyState == 4 && request.status == 200)
	{		
		var functionString = "updateFunction(";
		if(optionalArguments != null && optionalArguments.length > 0)
		{
			for(var i = 0; i < optionalArguments.length; i ++)
			{
				if(i > 0)
					functionString += ",";
				if(typeof optionalArguments[i] == 'string')
				{
					functionString += "\"" + optionalArguments[i] + "\""
				}
				else
				{
					functionString += optionalArguments[i];
				}
			}
		}
		functionString += ")";
		eval(functionString);
	}
}