function AjaxRequest(method,script_name,func_name,args,callback,callback_object)
{
    function escapePlus(param){
        param = escape(param);
        return String(param).replace(/\+/g,'%2B');
    }

    this.query = script_name + "?ajax_call=1&func_name=" + escapePlus(func_name) +
        "&back=" + escapePlus(window.location)+"&data=" + escapePlus(Object.toJSON(args));

    this.method = method;
    this.callback = callback;
    this.callback_object = callback_object;

}

AjaxRequest.prototype.send = function () {
    return new Ajax.Request(this.query,
                            { method: this.method,
                              onSuccess: (function (transport) {
                                              var data = eval(transport.responseText);
	                                      var magic = data.shift();
	                                      if(magic != "AjaxResponse") return;
	                                      var result = data.shift();
                                              if(result == "OK") {
	                                          if(this.callback) {
		                                      this.callback.apply(this.callback_object?this.callback_object:window,data);
	                                          }
                                              }
                                              if(result == "Redirect") {
                                                  window.location = data;
                                              }
                                          }).bind(this)
                            });
};

var  ajax_requests = [];