/* Original code from: http://www.designplanet.biz/tutorials-15.htm */

function XMLHTTPObject() {
  var xmlhttp;
  if (window.ActiveXObject) {

    if (_XML_ActiveX) xmlhttp = new ActiveXObject(_XML_ActiveX);
    else {
      var versions = ["MSXML2.XMLHTTP", "Microsoft.XMLHTTP", "Msxml2.XMLHTTP.7.0", "Msxml2.XMLHTTP.6.0",
                      "Msxml2.XMLHTTP.5.0", "Msxml2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0"];
      
      for (i=0; i<versions.length; i++) {
        try {
          if (xmlhttp = new ActiveXObject(versions[i])) {
            var _XML_ActiveX = versions[i];
            break;
          }
        }
        catch (e) { }
      }
    }
    
  }
  
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try { xmlhttp = new XMLHttpRequest(); }
    catch (e) { xmlhttp = false; }
  }
  return xmlhttp;
}

function sendHttpReq(is_post, url, data, handlerFunc) {
  xmlhttp = XMLHTTPObject();
  xmlhttp.onreadystatechange = function() { handlerFunc(xmlhttp); };
  xmlhttp.open(( (is_post) ? "POST" : "GET" ), url, true);
  if (is_post) xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  xmlhttp.send(data);
}