/**
* Constructor
*
* @access public
*/
function MC_XmlHttp() {
  /**
  * XMLHTTPRequest object
  *
  * @access private
  * @var object
  */
  this.xmlhttp = null;
  
  // trying to set up XMLHTTP-object
  if (window.XMLHttpRequest) {
    // the common way
    this.xmlhttp = new XMLHttpRequest();
    
  } else if (window.ActiveXObject) {
    // internet explorer
    try {
      this.xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
    } catch (e) {
      try {
        this.xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');
      } catch (e) {}
    }
  }
  
  // did it work out?
  if (!this.xmlhttp) {
    // crud...
    this.error('Could not create XMLHTTP object');
  }
}

/**
* Initializes XMLHTTP object
*
* @access public
* @param string (may be GET|POST|PUT)
* @param string
* @param bool
* @return void
*/
MC_XmlHttp.prototype.open = function (method, target, async) {
  async = (arguments.length > 2) ? async : true;
  
  return this.xmlhttp.open(method, target, async);
}

/**
* Sends the XMLHTTP request
*
* @access public
* @param string (optional HTTP request content)
* @return void
*/
MC_XmlHttp.prototype.send = function (data) {
  data = (arguments.length > 0) ? data : null;
  
  return this.xmlhttp.send(data);
}

/**
* Error handler
*
* @access public
* @param string
* @return void
*/
MC_XmlHttp.prototype.error = function (text) {
  alert('XMLHTTP error: ' + text);
}

/**
* Sets the event handler for state changes
*
* @access public
* @param object (event handler function)
* @return void
*/
MC_XmlHttp.prototype.setReadyStateChangeHandler = function (handler) {
  this.xmlhttp.onreadystatechange = handler;
}

/**
* Returns the retrieved XML as text
*
* @access public
* @return string
*/
MC_XmlHttp.prototype.getResponseText = function () {
  return this.xmlhttp.responseText;
}

/**
* Returns the retrieved XML as document object
*
* @access public
* @return object (XML document object)
*/
MC_XmlHttp.prototype.getResponseXML = function () {
  return this.xmlhttp.responseXML;
}

/**
* Gets the state of the current request
*
* Meaning of the different states:
* 0 (uninitialized) object not initialized
* 1 (loading)       no request sent
* 2 (loaded)        response status and headers not yet available
* 3 (interactive)   data partially received
* 4 (complete)      all data received and available
*
* @access public
* @return int
*/
MC_XmlHttp.prototype.getReadyState = function () {
  return this.xmlhttp.readyState;
}

/**
* Gets the HTTP status code of the received HTTP response
*
* Common ones are 200 (OK) and 404 (Not Found)
*
* @access public
* @return int
*/
MC_XmlHttp.prototype.getStatus = function () {
  return this.xmlhttp.status;
}

/**
* Sets certain header of the HTTP request
*
* @access public
* @param string
* @param string
* @return void
*/
MC_XmlHttp.prototype.setRequestHeader = function (name, value) {
  return this.xmlhttp.setRequestHeader(name, value);
}

/**
* Gets certain header value of the HTTP response
*
* @access public
* @param string
* @return string
*/
MC_XmlHttp.prototype.getResponseHeader = function (name) {
  return this.xmlhttp.getResponseHeader(name);
}