﻿var READY_STATE_UNINITIALIZED=0;
var READY_STATE_LOADING=1;
var READY_STATE_LOADED=2;
var READY_STATE_INTERACTIVE=3;
var READY_STATE_COMPLETE=4;

function createXMLHTTPRequest()
{
  var xRequest=null;
  if (window.XMLHttpRequest)
  {
    xRequest=new XMLHttpRequest();
  } 
  else if (typeof ActiveXObject != "undefined") //if (window.ActiveXObject)
  {
    var vr = ["Microsoft.XMLHTTP","Msxml2.XMLHTTP","Msxml2.XMLHTTP.6.0","Msxml2.XMLHTTP.5.0","Msxml2.XMLHTTP.4.0","Msxml2.XMLHTTP.3.0"];
    for(var i=0; i<6; i++)
    {
      try { xRequest = new ActiveXObject(vr[i]); } catch (ex) {};
      if(xRequest) break;
    }
  }
  return xRequest;
}

function sendRequest(url,callback,callbackparms,sendparams,HttpMethod)
{
  var req=createXMLHTTPRequest();
  if (req)
  {
    if (!HttpMethod)
    {
      HttpMethod="GET";
    }
    req.onreadystatechange = function()
    {
      var ready=req.readyState;
      if (ready==READY_STATE_COMPLETE)
      {
        var httpStatus=req.status;
        if (httpStatus==200 || httpStatus==0)
        {
            callback(req,callbackparms);
        }
      }
    }
    req.open(HttpMethod,url,true);
    req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    req.send(sendparams);
  }
}
