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;


// *************** ContentLoader **************

// constructor
function ContentLoader(url, onload, userParam1, onerror) {
  this.url = url;
  this.req = null;
  this.onload = onload;
  this.onerror = (onerror) ? onerror: this.defaultError;
  this.err_found = false;
  this.addParam1 = userParam1;
  this.load();
}

ContentLoader.prototype.load = function() {
  var a = null;
  try {
    a = new ActiveXObject("Msxml2.XMLHTTP")
  } catch(b) {
    try {
      a = new ActiveXObject("Microsoft.XMLHTTP")
    } catch(c) {
      a = null
    }
  }
  if (!a && typeof XMLHttpRequest != "undefined")
    a = new XMLHttpRequest;
  this.req = a ; 
  if (this.req) {
    try {
      var loader = this;
      this.req.onreadystatechange = function() {
        loader.onReadyState();
      }
      this.req.open('GET', this.url, true);
      this.req.send();
    } catch (err) {
      if (! this.err_found) {
        this.err_found = true;
        this.onerror();
      }
    }
  }
}

ContentLoader.prototype.onReadyState = function() {
  if (this.req.readyState == net.READY_STATE_COMPLETE) {
    if (this.req.status == 200 || this.req.status == 0) {
      this.onload();
    } else {
      if (! this.err_found) {
        this.err_found = true;
        this.onerror();
      }
    }
  }
}


ContentLoader.prototype.defaultError = function() {
  alert("error fetching data!" + "\n\nurl: " + this.url + "\nheaders: " + this.req.getAllResponseHeaders());
}

// *************** /ContentLoader **************

function sleep(msecs) {
  var sDialogScript = 'window.setTimeout( function () { window.close(); }, ' + msecs + ');';
  window.showModalDialog('javascript:document.writeln("<script>' + sDialogScript + '<' + '/script>")');
}

