function XMLHTTP(server_url, readyStateFunction)
{
	this.server_url = server_url;
	this.async = true;
	this.method = 'POST';
	this.queue = new Array();
	this.in_process = 0;
	this.readyStateFunction = (readyStateFunction) ? readyStateFunction : this.responseHandler;
}

XMLHTTP.prototype.getXMLHTTP = function()
{
	//Mozila
	if (window.XMLHttpRequest) {
		this.req = new XMLHttpRequest();
	}
	// IE/Windows ActiveX
	else if (window.ActiveXObject){
		this.req = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		return false;
	}
	return this.req;
}

XMLHTTP.prototype.call = function(queryVars, userCallback, queue_request)
{
	var currentVars;
	var callback;
	this.fullUrl = '';

	if(this.throttle == 1 && queue_request != 'queue')
	{
		this.add2Queue(queryVars, userCallback);	
	}
	
	if(this.queue_in_process == 0)
	{
		if(!this.getXMLHTTP())
		{
			return false;
		}
		
		if(this.throttle == 1)
		{
			this.queue_in_process = 1;
			var currentCall = this.queue.shift();
			currentVars = currentCall.queryVars;
			callback = currentCall.userCallback;
		}
		else
		{
			currentVars = queryVars;
			callback = userCallback;
		}
		this.callBack = callback;
		
		

		this.req.onreadystatechange =  this.readyStateFunction;
	
		// if get is used, append the query variables to the url string 
		this.full_url = (this.method == "POST") ? this.server_url : this.server_url + '?'+ currentVars;
		
		// open connection
		this.req.open(this.method, this.full_url, this.async);
		
		// set any optional headers
		if(this.headers)
		{
			for(var i in this.headers)
			{
				if(i != '')
				{
					this.req.setRequestHeader( i, this.headers[i]);
				}
			}
		}
		
		// send request
		if(this.method == 'POST')
		{
			this.req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			this.request = currentVars;
			this.req.send(currentVars);
		}
		else
		{
			this.req.send(null);
		}
	}
	
}

XMLHTTP.prototype.responseHandler = function()
{
    if (ajaxObj.req.readyState == 4)
	{
        if (ajaxObj.req.status == 200)
		{
        }
		ajaxObj.queue_in_process = 0;
		if(ajaxObj.queue.length > 0)
		{
			ajaxObj.call('','','queue');
		}
    }
}

var ajaxObj = new XMLHTTP("/ajax");