var arrReq = new Array();

//[Main]
function ajax_obj(url, data, callback, context)
{	
	var objXml = ajax_obj_request(context);	
	var async = typeof(callback) == "function";
	
	if (async) objXml.obj.onreadystatechange = function()
	{
		if (objXml.obj.readyState == 4)				
			callback(new ajax_obj_response(objXml));
	}
	
	objXml.obj.open("GET", url + "?" + data, async);
	objXml.obj.send(data);	
	
	if (!async)
		return new ajax_obj_response(objXml);
}


function ajax_obj_request(context)
{
	for (var i=0; i<arrReq.length; i++)
		if (arrReq[i].obj.readyState == 4)
		{
			arrReq[i].obj.abort();
			arrReq[i].context = context;
			return arrReq[i];
		}
	
	//New array entry	
	var j = arrReq.length;
	arrReq[j] = Object();
	arrReq[j].obj = new XMLHttpRequest();
	arrReq[j].context = context;
	
	return arrReq[j];
}


function ajax_obj_response(request)
{
	this.request = request.obj;
	this.error = null;
	this.value = null;
	this.context = request.context;
		
	if (request.obj.status == 200)
	{
		try
		{
			this.value = request.obj.responseText;			
			
			if (this.value && this.value.error)
			{
				this.error = this.value.error;
				this.value = null;
			}
		}
		catch(e)
		{
		}
	}
	
	return this;
}


//Define the XmlHttp function
if(typeof(XMLHttpRequest) == 'undefined')
var XMLHttpRequest = function()	
{
	var obj = null;
		
	try	
	{
		obj = new ActiveXObject('Msxml2.XMLHTTP');
	}
	catch(e)
	{
		try
		{
			obj = new ActiveXObject('Microsoft.XMLHTTP');			
		}
		catch(ee)					
		{
		}
	}
		
	return obj;
}