// AjaxRequest - provides a wrapper around prototype's Ajax.Request call adding in standard error handling
var AjaxRequest = Class.create();
AjaxRequest.prototype = Object.extend(Ajax.Request.prototype, {
    initialize: function(url, options) {
        this.transport = Ajax.getTransport();
        this.setOptions(options);
        this.options.onFailure = showError; // Add in standard error handling
        this.request(url);
    }
});

// AjaxUpdater - provides a wrapper around prototype's Ajax.Updater call adding in standard error handling
var AjaxUpdater = Class.create();
AjaxUpdater.prototype = Object.extend(Ajax.Updater.prototype, {
    initialize: function(container, url, options) {
        this.containers = {
            success: container.success ? $(container.success) : $(container),
            failure: container.failure ? $(container.failure) : (container.success ? null : $(container))
        }
        this.transport = Ajax.getTransport();
        this.setOptions(options);
        var onComplete = this.options.onComplete || Prototype.emptyFunction;
        this.options.onComplete = (function(transport, object) {
            this.updateContent();
            onComplete(transport, object);
        }).bind(this);
        this.options.onFailure = showError; // Add in standard error handling
        this.request(url);
  }
});

// This is the function used to display the error/login page
function showError(request)
{
    document.write(request.responseText);
    document.close();
}

function logAjaxSupport()
{
    new AjaxRequest('/ajaxEnabled.servlet', {method: 'get'});
}
