var xhrObj=false;
function showWait(){
	//if(divid)getEl(divid).innerHTML  = "<img src='images/status.gif'>"
	//status="waiting...";
}

/* XHR Processing functions */
var iRemoteProcedure=0;
var tRemoteProcedures={};
function RemoteProcedure(sUrl,fnOnLoad,fnOnPatience){
	this.req=null;
	this.fnOnLoad=null;
	this.id=++iRemoteProcedure;
	tRemoteProcedures[this.id]=this;
	this.timer=null;
	this.call(sUrl,fnOnLoad,fnOnPatience);
}
RemoteProcedure.prototype.call=function(url,fnOnLoad,fnOnPatience){
	if(xhrObj && xhrObj.readyState!=0){
		xhrObj.abort();
	}
	this.fnOnLoad=fnOnLoad;
	this.fnOnPatience=fnOnPatience;
	this.timer=window.setTimeout('tRemoteProcedures['+this.id+'].showPatience()',500);
	var sRand=Math.floor(Math.random()*11);
	if (window.XMLHttpRequest){
		this.req=new XMLHttpRequest();
		this.req.onreadystatechange=new Function('tRemoteProcedures['+this.id+'].processReqChange()');
		this.req.open("GET",url+sRand,true);
		this.req.send(null);
	} else if (window.ActiveXObject){

		try {
        	this.req = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	try {
          		this.req = new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
          		this.req = false;
        	}
		}
		//this.req=new ActiveXObject("Microsoft.XMLHTTP");
		if (this.req){
			this.req.onreadystatechange=new Function('tRemoteProcedures['+this.id+'].processReqChange()');
			
			this.req.open("GET",url+sRand,true);
			this.req.send();
		}
	}
}
RemoteProcedure.prototype.showPatience=function(){
	this.clearTimeout();
	if(this.fnOnPatience)
		this.fnOnPatience();
}
RemoteProcedure.prototype.clearTimeout=function(){
	if (this.timer!=null){
		window.clearTimeout(this.timer);
		this.timer=null;
	}
}
RemoteProcedure.prototype.processReqChange=function(){
	if (this.req.readyState==4){ // 4 means "loaded"
		this.clearTimeout();
		if (this.req.status==200 || this.req.status==0 ){ // 200 means "OK"
			if(this.fnOnLoad)
				this.fnOnLoad(this.req);//this.fnOnLoad(this.req.responseXML);
		}
		
			//alert("Error " + this.req.status + "\n" + this.req.statusText + "\n\n" + this.req.responseText.replace(/\r\n/g,''));
	}
}
/* DOM Processing functions */
function getEl(id){return document.getElementById(id)}