/*
	page		url of page to access
	callback	function handle to call when complete
*/
function AjaxRequest(instructions)
{
	var that = this;
	var page = instructions.page;
	this.callback = instructions.callback;
	var result = '';
	var active = false;

	this.getResult = function()
	{
		return result;
	}
	this.update = function()
	{	
		if (active)
			return false;
		active = true;

		var req = null;
		if (window.XMLHttpRequest)
			req = new XMLHttpRequest();
		else if (window.ActiveXObject)
			req = new ActiveXObject('Microsoft.XMLHTTP');
		
		req.onreadystatechange = function()
		{
			if (req.readyState == 4)
			{
				result = req.responseText;
				if (that.callback)
					that.callback(result);
					
				reg = null;
				delete req;
				active = false;				
			}
		}

		var timestamp = new Date();		
		var tStamp = (page.indexOf('?')!=-1?'&':'?')+'tamp='+(timestamp*1);
			
		req.open('GET',page+tStamp,true);
		req.send(null);
	}

	this.update();
}

function AjaxServer()
{
	this.ajaxRequests = Array();
}
AjaxServer.prototype.request = function(id,url,fn)
{
	this.ajaxRequests[id] = new AjaxRequest({page:url,callback:fn});
}
AjaxServer.prototype.update = function(id)
{
	this.ajaxRequests[id].update();
}

AjaxServer.prototype.getResult = function(id)
{
	return this.ajaxRequests[id].getResult();
}