// XmlHttp.js


function XmlHttp() { 
  this.http_request = null;
  this.initialize();
}

XmlHttp.prototype.initialize = function() { 
  if (window.XMLHttpRequest) { // Mozilla, Safari,...
    this.http_request = new XMLHttpRequest();
    if(this.http_request.overrideMimeType) {
      this.http_request.overrideMimeType('text/xml');
    }
  } else if (window.ActiveXObject) { // IE
    try {
      this.http_request = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        this.http_request = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {}
    }
  }

  if (!this.http_request) {
    alert('Giving up :( Cannot create an XMLHTTP instance');
    return false;
  }
  return true;
}


XmlHttp.prototype.request = function(url,async,func) {
  async = (typeof(async)=="undefined" || !async) ? false : true;
  var xmlHttp = this.http_request;
  xmlHttp.open('GET', url, async);
  xmlHttp.send(null);

  if( async ) { 
    xmlHttp.onreadystatechange = function() {
      if(xmlHttp.readyState==4) {
        if( typeof(func)!="undefined" ) { 
          func(xmlHttp.responseText,xmlHttp.status);
        }
        return xmlHttp.responseText;
      }
    }
  } else {
    this.xml = xmlHttp.responseXML;
    if( typeof(func)!="undefined" ) { 
      func(xmlHttp.responseText,xmlHttp.status);
    }
    return xmlHttp.responseText;
  }
}


XmlHttp.prototype.parse = function(a) { 
  a = (!a) ? this.http_request.responseText : a;
  if(typeof ActiveXObject!="undefined"&&typeof GetObject!="undefined") {
    var b=new ActiveXObject("Microsoft.XMLDOM");
    b.loadXML(a);
    return b;
  }
  if(typeof DOMParser!="undefined") {
    var b = (new DOMParser).parseFromString(a,"text/xml");
    return b;
  }

  var doc = document.createElement("div");
  doc.innerHTML = a;
  return doc;
}

