var AjaxEngine=Class.create();AjaxEngine.prototype={initialize:function(){this.ajaxElements=new Hash();this.ajaxObjects=new Hash();this.requestURLS=new Hash();this.options={};},registerAjaxElement:function(ui,vi){if(!vi)vi=$(ui);this.ajaxElements.set(ui,vi);},unregisterAjaxElement:function(wi){this.ajaxElements.unset(wi);},registerAjaxObject:function(xi,yi){this.ajaxObjects.set(xi,yi);},unregisterAjaxObject:function(zi){this.ajaxObjects.unset(zi);},registerRequest:function(Ai,Bi){this.requestURLS.set(Ai,Bi);},unregisterRequest:function(Ci){this.requestURLS.unset(Ci);},sendRequest:function(Di,Ei){if(arguments.length>=2)if(typeof arguments[1]=='string')Ei={parameters:this._createQueryString(arguments,1)};this.sendRequestWithData(Di,null,Ei);},sendRequestWithData:function(Fi,Gi,Hi){var Ii=this.requestURLS.get(Fi);if(Ii==null)return;if(arguments.length>=3)if(typeof arguments[2]=='string')Hi.parameters=this._createQueryString(arguments,2);new Ajax.Request(Ii,this._requestOptions(Hi,Gi));},sendRequestAndUpdate:function(Ji,Ki,Li){if(arguments.length>=3)if(typeof arguments[2]=='string')Li.parameters=this._createQueryString(arguments,2);this.sendRequestWithDataAndUpdate(Ji,null,Ki,Li);},sendRequestWithDataAndUpdate:function(Mi,Ni,Oi,Pi){var Qi=this.requestURLS.get(Mi);if(Qi==null)return;if(arguments.length>=4)if(typeof arguments[3]=='string')Pi.parameters=this._createQueryString(arguments,3);var Ri=this._requestOptions(Pi,Ni);new Ajax.Updater(Oi,Qi,Ri);},_requestOptions:function(Si,Ti){var Ui=['X-Version','1.0'];var Vi='post';if(Ti==null)Vi='get';(!Si)?Si={}:'';if(!Si._RicoOptionsProcessed){if(Si.onComplete)Si.onRicoComplete=Si.onComplete;if(Si.overrideOnComplete)Si.onComplete=Si.overrideOnComplete;else Si.onComplete=this._onRequestComplete.bind(this);Si._RicoOptionsProcessed=true;}
Vi='post';this.options={requestHeaders:Ui,parameters:Si.parameters,postBody:Ti,method:Vi,onComplete:Si.onComplete,timeout:15000,onError:Si.onComplete};Object.extend(this.options,Si);return this.options;},_createQueryString:function(Wi,Xi){var Yi="";for(var i=Xi;i<Wi.length;i++){if(i!=Xi)Yi+="&";var Zi=Wi[i];if(Zi.name!=undefined&&Zi.value!=undefined){Yi+=Zi.name+"="+encodeURIComponent(Zi.value);}
else{var $i=Zi.indexOf('=');var aj=Zi.substring(0,$i);var bj=Zi.substring($i+1);Yi+=aj+"="+encodeURIComponent(bj);}}
return Yi;},_onRequestComplete:function(cj){if(!cj)return;if(cj.status!=200){var dj=this.options.onError;if(dj!=null)dj();return;}
var ej=cj.responseXML.getElementsByTagName("ajax-response");if(ej==null||ej.length!=1)return;this._processAjaxResponse(ej[0].childNodes);var fj=this.options.onRicoComplete;if(fj!=null)fj();},_processAjaxResponse:function(gj){for(var i=0;i<gj.length;i++){var hj=gj[i];if(hj.nodeType!=1)continue;var ij=hj.getAttribute("type");var jj=hj.getAttribute("id");if(ij=="object")this._processAjaxObjectUpdate(this.ajaxObjects.get(jj),hj);else if(ij=="element")this._processAjaxElementUpdate(this.ajaxElements.get(jj),hj);else alert('unrecognized AjaxResponse type : '+ij);}},_processAjaxObjectUpdate:function(kj,lj){kj.ajaxUpdate(lj);},_processAjaxElementUpdate:function(mj,nj){mj.innerHTML=RicoUtil.getContentAsString(nj);}};var ajaxEngine=new AjaxEngine();