// Ajax request class
function AjaxRequest(requestfile)
{
	this.phpfile = requestfile;
}

AjaxRequest.prototype.phpfile;

/*
	Sends ajax request to the server using GET http request with a callback function
*/
AjaxRequest.prototype.requestGET=function(areaId, parameters, callback)
{
	var xmlHttp = this.getAjax();
	if (xmlHttp != null)
	{
		// Prepare the request URL
		var file = this.phpfile;
		if (parameters.length > 0)
		{
			file += "?";
			for (i = 0; i < parameters.length; i++)
			{
				file += parameters[i];
				if (i < parameters.length-1)
				{
					file += "&";
				}
			}
		}
		
		// Set the response handler
		var xmlhttpObject = xmlHttp;
		xmlHttp.onreadystatechange=function()
		{
			if (xmlhttpObject.readyState == 4)
			{
				if (typeof(areaId) == 'function')
				{
					areaId(xmlhttpObject.responseText);
					eval(callback);
				}
				else if (areaId != null && areaId != '')
				{
					var docElement = document.getElementById(areaId);
					if (docElement)
					{
						docElement.innerHTML = xmlhttpObject.responseText;
					}
					eval(callback);
				}
			}
		}
		
		// Send the actual request
		xmlHttp.open("GET", file, true);
		xmlHttp.send(null);
	}
}


/*
	The basic function to get the XML HTTP object for AJAX operations
*/
AjaxRequest.prototype.getAjax=function()
{
	var xmlHttp;
	try
	{
		xmlHttp = new XMLHttpRequest();
	}
	catch(e)
	{
		try
		{
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e)
		{
			try
			{
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e)
			{
				alert("Browser does not support AJAX. Get to the 90's man!!");
			}
		}
	}
	return xmlHttp;
}

