<!--
// Copyright 2008 info@poweredsites.ca

// Declare constructor
function AL( url, input, callback )
{
  // How about some member variables
  this.mUrl = url;
  this.mInput = input;
  this.mCallback = callback;
  this.mXmlHttpReq = null;
  this.mOutput = null;

  // Define the function prototypes
  //this.prototype.getXmlHttpReq();
  //this.prototype.callback();
  //this.prototype.load();
  //this.prototype.asyncHandler();
}

// Need this before declaring prototypes (for backwards compatability)
var tmpAl = new AL();

// Some class constants
AL.READY_STATE_UNINITIALIZED = 0;
AL.READY_STATE_LOADING = 1;
AL.READY_STATE_LOADED = 2;
AL.READY_STATE_INTERACTIVE = 3;
AL.READY_STATE_COMPLETE = 4;

AL.HTTP_STATUS_OK = 200;

// comment
AL.prototype.getXmlHttpReq = function()
{
    // IE only

    /*@cc_on
    @if( @_jscript_version >= 5 )
    {
      try
      {
        this.mXmlHttpReq = new ActiveXObject( "Msxml2.XMLHTTP" );
      }
      catch( e )
      {
        try
        {
          this.mXmlHttpReq = new ActiveXObject( "Microsoft.XMLHTTP" );
        }
        catch( e )
        {
          this.mXmlHttpReq = false;
        }
      }
    } // if
    @else
    {
      //xmlhttp = httpObj;
    }
    @end @*/

    // Mozilla

    if( ! this.mXmlHttpReq && typeof XMLHttpRequest != 'undefined' )
    {
      try
      {
        this.mXmlHttpReq = new XMLHttpRequest();
      }
      catch( e )
      {
        this.mXmlHttpReq = false;
      }
    }
}

AL.prototype.load = function()
{
  this.getXmlHttpReq();

  if( ! this.mXmlHttpReq )
  {
    //alert( "No XMLHttp request!" );
    return;
  }

//  this.mXmlHttpReq.onreadystatechange = this.asyncHandler;
  var myself = this;

  //:TRICKY
  this.mXmlHttpReq.onreadystatechange = function()
  {
    myself.asyncHandler.call( myself );
  }

  this.mXmlHttpReq.open( 'GET', this.mUrl + '/' + this.mInput, true );
  this.mXmlHttpReq.send( null );
}

AL.prototype.asyncHandler = function()
{
  var readyState = this.mXmlHttpReq.readyState;

  if( readyState == AL.READY_STATE_COMPLETE )
  {
    var status = this.mXmlHttpReq.status;

    if( status == AL.HTTP_STATUS_OK )
    {
      //var xmlDoc = this.mXmlHttpReq.responseXML;
      var xmlDoc = this.mXmlHttpReq.responseText;

      this.mOutput = xmlDoc;
      this.mCallback.call(this);

    }
  }
}
//-->

