Ajax.Request.prototype._jshr_setOptions = Ajax.Request.prototype.setOptions;
Ajax.Request.prototype.setOptions = function(options) {
    // Support for whole form & form element sending.
    var parameters = options.parameters;
    options.parameters = {};
    this.transport._jshr_send = this.transport.send;
    this.transport.send = function(body) {return this._jshr_send(body || parameters);}
    this._jshr_setOptions(options);
}
Ajax.getTransport = function() {return new j2httpRequest_js();}
//Ajax.Request.prototype.evalResponse = Prototype.emptyFunction;
Ajax.Request.prototype.evalResponse = function() {
    try {
         var js = this.transport.responseJS;
         if (typeof js == 'object') { js = $H(js).toArray().join(''); }
         return js.evalScripts.bind(js).defer();
    } catch (e) {
         this.dispatchException(e);
    }
}

Ajax.ReqUpdater = Class.create(Ajax.Request, {
  initialize: function($super, url, options) {
	options.method = options.method || 'get';
    options = Object.clone(options);
    var onComplete = options.onComplete;
    options.onComplete = (function(response, json) {
      this.updateContent(response.transport.responseJS);
      if (Object.isFunction(onComplete)) onComplete(response.transport.responseJS, json);
    }).bind(this);
    $super(url, options);
  },

  updateContent: function(response) {
	for (id in response)
	{
		try
		{
			var elem = $(id);
			if (this.options.evalScripts)
			{
				response[id].extractScripts().each(function(script)
				{
					if (window.execScript)
						window.execScript(script,'javascript');
					else
						window.eval(script);
				});
			}
			if (Object.isElement(elem)) elem.update(response[id].stripScripts());
		} catch(er){};
	}
  }
});

Ajax.ReqPeriodicalUpdater = Class.create(Ajax.Base, {
 initialize: function($super, url, options) {
 $super(options);
 this.onComplete = this.options.onComplete;
 this.frequency = (this.options.frequency || 2);
 this.decay = (this.options.decay || 1);
 this.updater = { };
 this.url = url;
 this.start();
 },

 start: function() {
 this.options.onComplete = this.updateComplete.bind(this);
 this.onTimerEvent();
 },

 stop: function() {
 this.updater.options.onComplete = undefined;
 clearTimeout(this.timer);
 (this.onComplete || Prototype.emptyFunction).apply(this, arguments);
 },

 updateComplete: function(response) {
 if (this.options.decay) {
  this.decay = (response == this.lastText ?
  this.decay * this.options.decay : 1);
  this.lastText = responseText;
 }
 this.timer = this.onTimerEvent.bind(this).delay(this.decay * this.frequency);
 },

 onTimerEvent: function() {
 this.updater = new Ajax.ReqUpdater(this.url, this.options);
 }
});
