/*
USAGE:
//------------------------------------------------------------------------------
html:
<div id='ajaxHttpDiv'></div>
//------------------------------------------------------------------------------
js:
// Ajax callback function (can be any name ==> is delivered below)
function HttpAjax_Callback()
{
  var httpResponseText=ajaxHttp.GetResponse();
  if (httpResponseText)
  {
    if (document.getElementById("ajaxHttpDiv")) document.getElementById("ajaxHttpDiv").innerHTML=httpResponseText;
  }
}
//------------------------------------------------------------------------------
js (at the end of the html-file, before </body>, where DIV exists already)
<script>
var ajaxHttp = new TAjaxHttp();
ajaxHttp.Callback = HttpAjax_Callback;
ajaxHttp.SetHttpPath("http://myhost/myscript.php"); ==> must be same DOMAIN as JavaScript runs!

ajaxHttp.SendRequest();
</script>
//------------------------------------------------------------------------------
*/

function TAjaxHttp()
{
  var activeX_HTTPObject=false;
  var httpPath;
  var xmlhttp;

  this.SetHttpPath = SetHttpPath;
  this.GetResponse = GetResponse;
  this.SendRequest = SendRequest;
  this.Callback = Callback;
  this.InitHTTPObject=InitHTTPObject;
  this.Abort=Abort;
  
  this.InitHTTPObject();
  
  function Callback() {}
  
  function SetHttpPath(path)
  {
  	this.httpPath=path;
  }
  
  function Abort()
  {
    if (!this.activeX_HTTPObject) return;
    
    this.activeX_HTTPObject.abort();
  }
  
  function SendRequest()
  {
    if (!this.httpPath) return;

    if (!this.activeX_HTTPObject)
    {
      alert("Not activeX object found!");
    }
//alert("Request");
//    this.InitHTTPObject();
    this.activeX_HTTPObject.abort();
    this.activeX_HTTPObject.onreadystatechange = this.Callback;

    this.activeX_HTTPObject.open("GET",this.httpPath, true);

    this.activeX_HTTPObject.send(null);
  }

  function GetResponse()
  {
    if (this.activeX_HTTPObject.readyState == 4) // 0..uninitialized, 1..loading, 2..loading, 3..interactive, 4..complete
    {
//alert("complete");
      if (this.activeX_HTTPObject.status == 200) // HTTP-Code: 200..OK, 404..not found, 500..internal server error etc.
      {
//alert("response OK");
        if (this.activeX_HTTPObject.responseText.length>0)
        {
//alert(this.activeX_HTTPObject.responseText);
          return this.activeX_HTTPObject.responseText;
        }
      }
//      else alert("TAjaxHttp::Callback_Ajax(): Response Error code: "+this.activeX_HTTPObject.status);
    }
    //else alert("TAjaxHttp::Callback_Ajax(): readyState not OK: "+this.activeX_HTTPObject.readyState);
  }


  function InitHTTPObject()
  {
    /*@cc_on
    @if (@_jscript_version >= 5)
    try
    {
      this.activeX_HTTPObject = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e)
    {
      try
      {
        this.activeX_HTTPObject = new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch (E)
      {
        this.activeX_HTTPObject = false;
      }
    }

    @else
    this.xmlhttp = false;
    @end @*/
//    if (!this.activeX_HTTPObject && typeof XMLHttpRequest != 'undefined')
//    if (typeof XMLHttpRequest != 'undefined')
    if (window.XMLHttpRequest)
    {
      try
      {
        this.activeX_HTTPObject = new XMLHttpRequest();
      }
      catch (e)
      {
        this.activeX_HTTPObject = false;
      }
    }
    else if (window.ActiveXObject)
    {
      this.activeX_HTTPObject = new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
}