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(b,c,a){this.element=document.id(b);if(this.occlude()){return this.occluded}this.setOptions(a).setTarget(c).attach()},setTarget:function(a){this.target=document.id(a);if(!this.request){this.makeRequest()}else{this.request.setOptions({update:this.target})}return this},toElement:function(){return this.element},makeRequest:function(){var a=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(c,e,d,b){["complete","success"].each(function(f){a.fireEvent(f,[a.target,c,e,d,b])})},failure:function(){a.fireEvent("complete",arguments).fireEvent("failure",arguments)},exception:function(){a.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(a){var c=(a!=false)?"addEvent":"removeEvent";this.element[c]("click:relay(button, input[type=submit])",this.saveClickedButton.bind(this));var b=this.element.retrieve("validator");if(b){b[c]("onFormValidate",this.onFormValidate)}else{this.element[c]("submit",this.onSubmit)}return this},detach:function(){return this.attach(false)},enable:function(){return this.attach()},disable:function(){return this.detach()},onFormValidate:function(c,b,a){if(!a){return}var d=this.element.retrieve("validator");if(c||(d&&!d.options.stopOnFailure)){a.stop();this.send()}},onSubmit:function(a){var b=this.element.retrieve("validator");if(b){this.element.removeEvent("submit",this.onSubmit);b.addEvent("onFormValidate",this.onFormValidate);this.element.validate();return}if(a){a.stop()}this.send()},saveClickedButton:function(b,c){var a=c.get("name");if(!a||!this.options.sendButtonClicked){return}this.options.extraData[a]=c.get("value")||true;this.clickedCleaner=function(){delete this.options.extraData[a];this.clickedCleaner=function(){}}.bind(this)},clickedCleaner:function(){},send:function(){var b=this.element.toQueryString().trim(),a=Object.toQueryString(this.options.extraData);if(b){b+="&"+a}else{b=a}this.fireEvent("send",[this.element,b.parseQueryString()]);this.request.send({data:b,url:this.options.requestOptions.url||this.element.get("action")});this.clickedCleaner();return this}});Element.implement("formUpdate",function(c,b){var a=this.retrieve("form.request");if(!a){a=new Form.Request(this,c,b)}else{if(c){a.setTarget(c)}if(b){a.setOptions(b).makeRequest()}}a.send();return this})})();