function IwAjax() {
  this.window=window;
  this.debugReqNotReady=false;
  this.debugReqError=false;
  this.debugReqOk=false;
}
IwAjax.prototype.newRequest = function() {
	var req = null;
  // branch for native XMLHttpRequest object
  if (this.window.XMLHttpRequest) {
    try {
      req = new XMLHttpRequest();
    } catch(e) {
      req = null;
    }
  // branch for IE/Windows ActiveX version
  } else if (this.window.ActiveXObject) {
    try {
      req = new ActiveXObject("Msxml2.XMLHTTP");
    } catch(e) {
      try {
        req = new ActiveXObject("Microsoft.XMLHTTP");
      } catch(e) {
        req = null;
      }
    }
  }
  return req;
}
IwAjax.prototype.loadXmlDoc = function(url,listener) {
  var ajax=this;
  var req=this.newRequest()
  if (req!=null) {
    if (listener!=null) {
      req.onreadystatechange = function() {
        listener.processReqChange(req);
      }
    } else {
      req.onreadystatechange = function() {
        ajax.processReqChange(req);
      }
    }
    req.open("GET", url, true);
		req.send("");
  }
}
IwAjax.prototype.processReqChange = function(req) {
  if (req.readyState==4) {
    if (req.status==200) {
      this.processReqOk(req);
    } else {
      this.processReqError(req);
    }
  } else {
    this.processReqNotReady(req);
  }
}
IwAjax.prototype.processReqNotReady = function(req) {
  if (this.debugReqNotReady) {
    alert("req.readyState="+req.readyState);
  }
}
IwAjax.prototype.processReqError = function(req) {
  if (this.debugReqError) {
    var s="";
    s+="req.readyState="+req.readyState+"\n";
    s+="req.status="+req.status+"\n";
    s+="req.statusText="+req.statusText+"\n";
    alert(s);
  }
}
IwAjax.prototype.processReqOk = function(req) {
  if (this.debugReqOk) {
    var s="";
    s+="req.readyState="+req.readyState+"\n";
    s+="req.status="+req.status+"\n";
    s+="req.statusText="+req.statusText+"\n";
    s+="req.responseXML="+req.responseXML+"\n";
    s+="req.responseText="+req.responseText+"\n";
    alert(s);
  }
}
IwAjax.prototype.newReqListener = function(reqOk,reqError,reqNotReady) {
  return new IwAjaxReqListener(this,reqOk,reqError,reqNotReady);
}
// listener
function IwAjaxReqListener(ajax,reqOk,reqError,reqNotReady) {
  this.ajax=ajax;
  this.processReqOk=reqOk;
  this.processReqError=reqError;
  this.processReqNotReady=reqNotReady;
}
IwAjaxReqListener.prototype.processReqChange = function(req) {
  if (req.readyState==4) {
    if (req.status==200) {
      if (this.processReqOk!=null) {
        this.processReqOk(req,this);
      } else {
        this.ajax.processReqOk(req);
      }
    } else {
      if (this.processReqError!=null) {
        this.processReqError(req,this);
      } else {
        this.ajax.processReqError(req);
      }
    }
  } else {
    if (this.processReqNotReady!=null) {
      this.processReqNotReady(req,this);
    } else {
      this.ajax.processReqNotReady(req);
    }
  }
}
