/*
	code by Dinu Florin
*/
//-------------------------------------------------------
function AjaxQuery()
{
	var xmlHTTP = ajax_GetXmlHttpObject();
	if(!xmlHTTP) throw("Could not initialise the AJAX framework");
	//-----------------------------
	var onOpenEvents = new Array();
	var onRecievingEvents = new Array();
	var onLoadedEvents = new Array();
	//-----------------------------
	this.load = function(remote_file, async, method, data)
	{
		if(async == undefined) async = true;
		if(data == undefined) data = null;
		if(method == undefined) method = "GET";
		xmlHTTP.open(method, remote_file, async);
		xmlHTTP.send(data);
	}
	this.post = function(remote_file, data)
	{
		if(data == undefined) data = null;
		xmlHTTP.open("POST", remote_file, true);
		xmlHTTP.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		xmlHTTP.send(data);
	}
	//-----------------------------
	this.addEvent = function(type, handler)
	{
		switch(type)
		{
			case "open":
				onOpenEvents.push(handler);
				break;
			case "reciving":
				onRecievingEvents.push(handler);
				break;
			case "loaded":
				onLoadedEvents.push(handler);
				break;
		}
	}
	//-----------------------------
	xmlHTTP.onreadystatechange = function() 
	{
		switch(xmlHTTP.readyState)
		{
			case 1:
				for(i in onOpenEvents) {onOpenEvents[i]();}
				break;
			case 3:
				for(i in onRecievingEvents) {onRecievingEvents[i]();}
				break;
			case 4:
				for(i in onLoadedEvents) {onLoadedEvents[i](xmlHTTP.responseText);}
				break;
		}
	}
}
//-------------------------------------------------------
function ajax_checkAJAX()
{
	if(obj = ajax_GetXmlHttpObject()!=null)
	{
		delete obj;
		return true;
	}
	else return false;
}
function ajax_GetXmlHttpObject(handler)
{ 
	var XMLHttp=null;
	try
	{
		XMLHttp=new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
 		{
 			XMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
 		}
		catch(e)	
		{
			try
			{
				XMLHttp=new XMLHttpRequest();
			}
			catch(e) {}
		}
	}
	return XMLHttp;
}
//----------------------------------------------
