//sbtLib ajax module

//If there's no exisiting sbt object, makeone
var SBT = {};

SBT.ajax = 
{
  //Method (GET/POST)
  method: 'GET',
  
  //Callback, no default
  callBack: function(){}, 
  
  //Init them early
  responseText: null,
  readyState: null,

  //Set the XMLHttp object up
  XMLHttp: null,
  initXMLHttp: function()
  {
    //Find and initialise the correct XMLHttp object
    if (window.XMLHttpRequest)
    {
      //Mozilla, WebKit etc
      this.XMLHttp = new XMLHttpRequest();
    }
    else
    {
      //Internet explorer
      //Stop JSLint bitching
      var ActiveXObject = ActiveXObject || null;
      this.XMLHttp = new ActiveXObject('Microsoft.XMLHTTP');
    }
    
    //Apply the onreadystate handler
    this.XMLHttp.onreadystatechange = function()
    {
      try
      {
        SBT.ajax.callBack(this.responseText, this.readyState);
      }
      catch(e)
      {
        //No-one cares about you, Internet Explorer
      }
    };
  },
  
  //Exec function
  exec: function(arg_url)
  {
    this.initXMLHttp();
    this.XMLHttp.open(this.method, arg_url, true);
    this.XMLHttp.send(null);
  },

  //The one-liner
  request: function(arg_url, arg_callback)
  {
    this.callBack = arg_callback;
    this.exec(arg_url);
  }
};
