/*
 * This is code to extend the functionality provided by prototype 1.3.1.
 * Include http://prototype.conio.net/dist/prototype-1.3.1.js before this
 *
 * author: bgraham
/*--------------------------------------------------------------------------*/

// The CnetUpdater overrides the determination of a successful response to
// check for a success token in a 2xx response.
Ajax.CnetUpdater = Class.create();
Ajax.CnetUpdater.prototype.extend(Ajax.Updater.prototype).extend({

  responseIsSuccess: function() {
    //if the response code is not in the 200s, it's not a success
    if(this.transport.status != undefined &&
       (this.transport.status < 200 || this.transport.status >= 300)) {
        return false;
    }

    if(this.transport.responseText.indexOf("COMPONENT_RESPONSE_CODE=200") > 0)
        return true;

    return false
  },

  responseIsFailure: function() {
    return !this.responseIsSuccess();
  }

});

// Wrapper around the CNetUpdater that's easier to use. This can be used to pass
// an error handler that knows how to check for an unauthorized component response
// (COMPONENT_RESPONSE_CODE=401) in the body and take action
function getHTML(divId, url, params, errorHandler)  {
    var myAjax = new Ajax.CnetUpdater({success: divId}, url,
                            {method: 'get', parameters: params, onFailure: errorHandler, evalScripts:true});
}
