if(!window.Form){window.Form={}}(function(){Form.Request=new Class({Binds:["onSubmit","onFormValidate"],Implements:[Options,Events,Class.Occlude],options:{requestOptions:{evalScripts:true,useSpinner:true,emulation:false,link:"ignore"},sendButtonClicked:true,extraData:{},resetForm:true},property:"form.request",initialize:function(form,target,options){this.element=document.id(form);if(this.occlude()){return this.occluded}this.setOptions(options).setTarget(target).attach()},setTarget:function(target){this.target=document.id(target);if(!this.request){this.makeRequest()}else{this.request.setOptions({update:this.target})}return this},toElement:function(){return this.element},makeRequest:function(){var self=this;this.request=new Request.HTML(Object.merge({update:this.target,emulation:false,spinnerTarget:this.element,method:this.element.get("method")||"post"},this.options.requestOptions)).addEvents({success:function(tree,elements,html,javascript){["complete","success"].each(function(evt){self.fireEvent(evt,[self.target,tree,elements,html,javascript])})},failure:function(){self.fireEvent("complete",arguments).fireEvent("failure",arguments)},exception:function(){self.fireEvent("failure",arguments)}});return this.attachReset()},attachReset:function(){if(!this.options.resetForm){return this}this.request.addEvent("success",function(){Function.attempt(function(){this.element.reset()}.bind(this));if(window.OverText){OverText.update()}}.bind(this));return this},attach:function(attach){var method=(attach!=false)?"addEvent":"removeEvent";this.element[method]("click:relay(button, input[type=submit])",this.saveClickedButton.bind(this));var fv=this.element.retrieve("validator");if(fv){fv[method]("onFormValidate",this.onFormValidate)}else{this.element[method]("submit",this.onSubmit)}return this},detach:function(){return this.attach(false)},enable:function(){return this.attach()},disable:function(){return this.detach()},onFormValidate:function(valid,form,event){if(!event){return}var fv=this.element.retrieve("validator");if(valid||(fv&&!fv.options.stopOnFailure)){event.stop();this.send()}},onSubmit:function(event){var fv=this.element.retrieve("validator");if(fv){this.element.removeEvent("submit",this.onSubmit);fv.addEvent("onFormValidate",this.onFormValidate);this.element.validate();return}if(event){event.stop()}this.send()},saveClickedButton:function(event,target){var targetName=target.get("name");if(!targetName||!this.options.sendButtonClicked){return}this.options.extraData[targetName]=target.get("value")||true;this.clickedCleaner=function(){delete this.options.extraData[targetName];this.clickedCleaner=function(){}}.bind(this)},clickedCleaner:function(){},send:function(){var str=this.element.toQueryString().trim(),data=Object.toQueryString(this.options.extraData);if(str){str+="&"+data}else{str=data}this.fireEvent("send",[this.element,str.parseQueryString()]);this.request.send({data:str,url:this.options.requestOptions.url||this.element.get("action")});this.clickedCleaner();return this}});Element.implement("formUpdate",function(update,options){var fq=this.retrieve("form.request");if(!fq){fq=new Form.Request(this,update,options)}else{if(update){fq.setTarget(update)}if(options){fq.setOptions(options).makeRequest()}}fq.send();return this})})();