/*
  GENERAL HTTP REQUEST HANDLING
*/


var Http = {

  httpHandler: false,

  initialize: function() {
    this.httpHandler=this.getHTTPObject();
  },

  getHTTPObject: function() {
    if (typeof XMLHttpRequest != 'undefined') {
      return new XMLHttpRequest();
    }
    try {
      return new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
          return new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {}
    }
    return false;
  },
  
  getPage: function(url, handler) {
     this.httpHandler.open("GET", url, true);
     this.httpHandler.onreadystatechange = this.useHttpResponse.bind(this);
     this.httpHandler.send(null);
     this.handler = handler;
  },
  
  useHttpResponse: function () {
    if (this.httpHandler.readyState == 4) {
      var textout = this.httpHandler.responseText;
      textout = this.strip(textout);
      this.handler(textout);
    }
  },
  
  strip: function(text) {
    var xpos=text.indexOf('<body')
    xpos = xpos + text.substring(xpos).indexOf('>') + 1;
    var ypos = text.indexOf('</body>')
    ypos = ypos ? ypos : text.length;
    if (xpos>5) {
      text=text.substring(ypos, xpos);
    }
    return text;
  }
}
