function createRequest()
{
	try 
	{
		return new XMLHttpRequest();
	} 
	catch (trymicrosoft)
	{
		try 
		{
			return new ActiveXObject("Msxml2.XMLHTTP");
	    } 
		catch (othermicrosoft) 
		{
			try
			{
				return new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch (failed)
			{
				return null;
			}  
	    }
	}
}

function delegate(obj, method)
{
	return function() { return method.call(obj); }
}

function asyncRequest(url, responseHandler, responseHandlerArg)
{
	// Prevent browser caching
	var nocache = '__nocache=' + Math.random();
	if(url.indexOf('?') == -1)
		url += '?' + nocache
	else
		url += '&' + nocache

	// Create a new request and store it in a container object along with the handler details
	var request = createRequest();
	if(request == null)
		alert('Failed to initialise AJAX request');
	
	var requestContainer = new Object();
	requestContainer.request = request;
	requestContainer.responseHandler = responseHandler;
	requestContainer.responseHandlerArg = responseHandlerArg;

	// Make the async request
	request.open('GET', url, true);
	request.onreadystatechange = delegate(requestContainer, onReadyStateChange);
	request.send(null);
}

function onReadyStateChange()
{
	if (this.request.readyState != 4 || this.request.status != 200) return;
	this.responseHandler(this.request.responseText, this.responseHandlerArg);
}

function formToUrl(formName)
{
	var f = document.forms[formName];
	var url = '';
	var and = '';
	
	for(var i = 0; i < f.elements.length; i++)
	{
		if(f.elements[i].name == '') continue;
	
		var element = f.elements[i];
		var value;
		
		if(element.type == 'checkbox')
		{
			url += and + element.name + '=' + element.checked;
			and = '&';
		}
		else if(element.type == 'select-multiple')
		{
			for(var j = 0; j < element.options.length; j++)
			{
				if(element.options[j].selected)
				{
					url += and + element.name + '=' + escape(element.options[j].value);
					and = '&';
				}
			}
		}
		else
		{
			url += and + element.name + '=' + escape(element.value);
			and = '&';
		}
	}
	
	return url;
}