AjaxWrapper = function(dataUrl, callback, method, formBody, callbackParams)
  {
    this.READY_STATE_COMPLETE = 4;

    this.dataUrl  = dataUrl;
    this.callback = callback;

    this.xmlhttp  = null;

    this.method   = (method == null || method == 'GET') ? 'GET' : 'POST';
    this.formBody = (method == 'POST') ? formBody : null;

    this.callbackParams = callbackParams;

    this.getData(dataUrl);
  }

AjaxWrapper.prototype = {

    getData:function(dataUrl)
      {
        try { this.xmlhttp = new XMLHttpRequest(); }
        catch(e)
          {
            try { this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
            catch(e)
              {
                try { this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
                catch(err)
                  {
                    this.onError.call(this, 'An error occurred while initialising.');
                  }
              }
          }

        if(this.xmlhttp)
          {
            try
              {
                var loader = this;
                this.xmlhttp.onreadystatechange = function()
                  {
                    loader.onReadyState.call(loader);
                  }

                this.xmlhttp.open(this.method, dataUrl, true);
                this.xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
                this.xmlhttp.send(this.formBody);
              }
            catch(err)
              {
                this.onError.call(this, 'An error occurred while sending data.');
              }
          }
      },

    onReadyState:function()
      {
        var xmlhttp = this.xmlhttp;
        var ready = xmlhttp.readyState;
        if(ready == this.READY_STATE_COMPLETE)
          {
            var httpStatus = xmlhttp.status;
            if(httpStatus == 200 || httpStatus == 0)
              {
                if(this.callback != null)
                  {
                    if(this.callbackParams != null)
                        this.callback.call(this, this.callbackParams);
                    else
                        this.callback.call(this);
                  }
              }
            else
              {
                this.onError.call(this, 'An error occurred while receiving data - HTTP status ' + httpStatus);
              }
          }
      },

    onError:function(msg)
      {
        alert(msg);
      }
  }
