var net = new Object();
net.READY_STATE_UNINITIALIZED = 0;
net.READY_STATE_LOADING = 1;
net.READY_STATE_LOADED = 2;
net.READY_STATE_INTERACTIVE = 3;
net.READY_STATE_COMPLETE = 4;
net.ContentLoader = function(url, onload, onerror) {
  this.url = url;
  this.request = null;
  this.onload = onload;
  this.onerror = (onerror) ? onerror : this.defaultError;
  this.loadXMLDoc(url);
}
net.ContentLoader.prototype = {
  loadXMLDoc:function(url) {
    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() {
          loader.onReadyState.call(loader);
        }
        this.request.open('GET', url, true);
        this.request.send(null);
      } catch (error) {
        this.onerror.call(this);
      }
    }
  },
  onReadyState:function() {
    var request = this.request;
    var ready = request.readyState;
    if (ready == net.READY_STATE_COMPLETE) {
      var httpStatus = request.status;
      if (httpStatus == 200 || httpStatus == 0) {
        this.onload.call(this);
      } else {
        this.onerror.call(this);
      }
    }
  },
  defaultError:function() {
    alert("Error fetching data!"
           + "\n\nreadyState: " + this.request.readyState
           + "\nstatus: " + this.request.status
           + "\nheaders:\n" + this.request.getAllResponseHeaders());
  }
}
