var oAjax=new Object();

	oAjax.controller=function(url,params,onload,onerror){		this.request=null;
		this.onload=onload;
		this.isBusy=false;
		this.onerror=(onerror='') ? onerror : this.defaultError;
		this.initAjax(url,params);
	}

    oAjax.controller.prototype.initAjax=function(url,params){  		if (window.XMLHttpRequest){
			this.request=new XMLHttpRequest();
  		} else if (window.ActiveXObject){
			this.request=new ActiveXObject("Microsoft.XMLHTTP");
  		}

  		if (this.request){
      		try{
          		var loader=this;
      	  		this.request.onreadystatechange=function(){
      	      		oAjax.controller.onReadyState.call(loader);
      	  		}
      	  		if(this.isBusy){      	  			this.request.abort();
      	  		}
				this.request.open('GET',url,true);

      	  		this.isBusy=true;
           		this.request.send(null);
      		}catch (err){
          		this.onerror.call(this);
      		}
		}
  	}

	oAjax.controller.onReadyState=function(){
        if(this.request.readyState!=4) return;
        this.isBusy=false;
  		if (this.request.readyState==4){
    	if (this.request.status==200 || this.request.status==0){
      		this.onload.call(this);
    	}else{
      		this.onerror.call(this);
    	}
  		}

	}

	oAjax.controller.prototype.defaultError=function(){
  		alert("error fetching data!"
    	+"\n\nreadyState:"+this.request.readyState
    	+"\nstatus: "+this.request.status
    	+"\nheaders: "+this.request.getAllResponseHeaders());
	}

