function HTTPRequest(url,method,body){

	this.state=false;
	var hr=getXMLHTTPObject();

	if(typeof(hr)!="object"){
		this.state="failed to create object";
		return false;
	}

	this.url=url;
	this.method=method ? method.toUpperCase() : "GET";

	hr.open(this.method,this.url,0);

	body=body ? body : "";
	hr.send(body);
	return hr.responseText;

}


function HTTPRequestObject(){
	this.hr=getXMLHTTPObject();
	var i=0;
	while(eval("typeof(HTTPRequestObjHandle"+i+")")!="undefined") ++i;
	this.handle="HTTPRequestObjHandle"+i;
	eval(this.handle+"=this;");
	this.queue={};
	this.queuecount=-1;
	this.current=-1;
	this.busy=0;
}

HTTPRequestObject.prototype.readystatechange=function(){
	if(this.hr.readyState==4){
		var proc=this.queue[this.current];
		var response=this.hr.responseText;
		delete this.queue[this.current];
		this.busy=0;
		//start next request before callback on this one...
		this.next();
		if(proc.callback) proc.callback(response);
	}
};

HTTPRequestObject.prototype.process=function(url,method,body,callback){
	this.queue[++this.queuecount]={url:url,method:method ? method.toUpperCase() : "GET",body:body,callback:callback || null};
	this.next();
};

HTTPRequestObject.prototype.next=function(){
	if(this.busy) return;
	if(!this.queue[this.current+1]) return;
	this.busy=1;
	var proc=this.queue[++this.current];
	this.hr.open(proc.method,proc.url,1);
	this.hr.onreadystatechange=new Function(this.handle+".readystatechange();");
	this.hr.send(proc.body);
};


function getXMLHTTPObject(){

	var hr=false;
	if(window.ActiveXObject){
		try{
			hr=new window.ActiveXObject("msxml2.XMLHTTP");
		}
		catch(e){
			try{
				hr=new window.ActiveXObject("microsoft.XMLHTTP");
			}
			catch(e){
					alert("cannot instantiate XMLHTTP object"); return false;
			}
		}
	}
	else if(window.XMLHttpRequest){
		hr=new window.XMLHttpRequest();
	}

	return hr;

}
