// Namespace object.
if(!CSCC) var CSCC = new Object();

// /////////////////////////////////////////////////////////////////////////////////////////////////
// Ajax helper class
// /////////////////////////////////////////////////////////////////////////////////////////////////
CSCC.Ajax = function(Url, OnSuccess, OnError)
{
    var _request = null;
    var _this = null;
    
    // Default callback functions.
    this.OnSuccess = function() { };
    this.OnFailure = function() { };

    // Helpers used to retrieve the Ajax response and request object.
    this.GetResponseText = function()
    {
        return (_request) ? _request.responseText : null;
    }

    this.GetRequestObject = function()
    {
        return _request;
    }
    
    // Fire off the Ajax request.
    this.Send = function()
    {
        if (_request) _request.send(null);
    }



    // /////////////////////////////////////////////////////////////////////////
    // Constructor code.
    // /////////////////////////////////////////////////////////////////////////
    
    // Ready a new Ajax response
    _this = this;

    // Initialize our HTTP request object.
    try
    {
        _request = new XMLHttpRequest();
    }
    catch(e)
    {
        try
        {
            _request = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch(e)
        {
            try
            {
                _request = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch(e)
            {
                alert('Failed to create XmlHttp object!');
            }
        }
    }
   
    _request.open('GET', Url);
    
    // Set the readystate handler to call OnSuccess and OnError as appropriate.
    _request.onreadystatechange = function()
    {
        if (_request.readyState == 4)
        {
            if (_request.status == 200) _this.OnSuccess(_request);
            else                        _this.OnFailure(_request);
        }
    }

    // If we were passed specific callback functions then assign them now.        
    if (OnSuccess) this.OnSuccess = OnSuccess;
    if (OnError) this.OnError = OnError;
}

