/*

  ajaxutils.js

  This file contains useful javascript functions used by AJAX such as the Ajax class

*/

//----------------------------------------
//        CreateXMLHttpRequest
//----------------------------------------
function CreateXMLHttpRequest()
/*
  This function creates an XMLHttpRequest object
*/
{
  //This is for almost all browsers expect IE
  if(window.XMLHttpRequest)
  {
    return new XMLHttpRequest();
  }
  //This is for IE
  else if(window.ActiveXObject)
  {
    var msxmls = new Array(
      'Msxml2.XMLHTTP.5.0',
      'Msxml2.XMLHTTP.4.0',
      'Msxml2.XMLHTTP.3.0',
      'Msxml2.XMLHTTP',
      'Microsoft.XMLHTTP');

    //try creating xmlhttprequest objects, start with newest version and work backwards
    for(var i=0;i<msxmls.length;i++)
    {
      try
      {
        return new ActiveXObject(msxmls[i]);
      }
      catch(e)
      {
      }
    }
  }
  throw new Error("Could not instantiate XMLHttpRequest");
}

//----------------------------------------
//               Ajax Class
//----------------------------------------

/*
  This class is used to make Ajax requests
*/

//constructor
function Ajax()
{
  this._xmlhttp = new CreateXMLHttpRequest();
}

//make a call for data
function Ajax_Call(url)
{
  var instance = this;
  this._xmlhttp.open('GET',url,true);
  this._xmlhttp.onreadystatechange=function()
  {
    switch(instance._xmlhttp.readyState)
    {
      case 1:instance.Loading();break;
      case 2:instance.Loaded();break;
      case 3:instance.Interactive();break;
      case 4:
      {
        instance.Complete(instance._xmlhttp.status,instance._xmlhttp.statusText,instance._xmlhttp.responseText,instance._xmlhttp.responseXML);
        break;
      }
    }
  }

  this._xmlhttp.send(null);
}

//loading function
function Ajax_Loading()
{
}

//loaded function
function Ajax_Loaded()
{
}

//interactive function
function Ajax_Interactive()
{
}

//complete function
function Ajax_Complete(status,statusText,responseText,responseHTML)
{
}

Ajax.prototype.Loading=Ajax_Loading;
Ajax.prototype.Loaded=Ajax_Loaded;
Ajax.prototype.Interactive=Ajax_Interactive;
Ajax.prototype.Complete=Ajax_Complete;

Ajax.prototype.Call=Ajax_Call;