if (typeof XMLHttpRequest == 'undefined') {
 XMLHttpRequest = function () {
   var msxmls = ['MSXML3', 'MSXML2', 'Microsoft'];
   for (var i=0; i < msxmls.length; i++) {
	 try {
	   return new ActiveXObject(msxmls[i]+'.XMLHTTP');
	 } catch (e) { }
   }
   throw new Error("No XML component installed");
 }
}


/* ------------------------------ JavaScript AJAX Class  ------------------------------ */


// Constructor
function AjaxExecutor( pSourceURL, pCompletionFunction )
{
     if ( arguments.length > 0 )
     {
         // Initialize the object with its base properties
         this.init( pSourceURL, pCompletionFunction );
         // Go get the data from the web
         this.loadData();
     }
}


AjaxExecutor.prototype.init = function( pSourceURL, pCompletionFunction )
{
     this.sourceURL = pSourceURL;
     this.completionFunction = pCompletionFunction;
     this.req = null;
}


AjaxExecutor.prototype.toString = function()
{ return this.sourceURL + ", " + this.completionFunction; }


// Goes and gets the data at the other end of the source URL
AjaxExecutor.prototype.loadData = function()
{
    if ( this.sourceURL != "" )
     {
         this.req = new XMLHttpRequest();
         var owner = this;
         this.req.onreadystatechange = function() { owner.processReqChange(); };
         this.req.open("GET", this.sourceURL, true);
         this.req.send( null );
     }
}


// Handle the onReadyStateChange event of req object
AjaxExecutor.prototype.processReqChange = function()
{
     // only if req shows "loaded"
     if ( this.req.readyState == 4 )
     {
         // only if "OK"
         if ( this.req.status == 200 )
         { this.completionFunction( this.req.responseText ); }
         else
         { 
		 	// alert( "There was a problem retrieving the XML data: " +  this.req.statusText ); 
		}
     }
}
