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=(url.indexOf('?')==-1?'?':'&')+'Rand='+Math.random();
	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){
		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);
			}
		}
		else{
			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);}
function echeck(str) {
		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length - 1;
		var ldot=str.indexOf(dot);
		if (str.indexOf(at)==-1){
		   return false;
		}
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false;
		}
		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false;
		}
		 if (str.indexOf(at,(lat+1))!=-1){
		    return false;
		 }
		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false;
		 }
		 if (str.indexOf(dot,(lat+2))==-1){
		    return false;
		 }
		 if (str.indexOf(" ")!=-1){
		    return false;
		 }
 		 return true;					
	}
function trim(str) {return str.replace(/^\s*|\s*$/g,"");}

