var Sliding={options:{form:"quotationForm",section:".quotation_section",header:".quotation_section_title",content:".quotation_section_content",footer:".quotation_section_footer",handler:".quotationModifyLink",elements:$A(("input,select,textarea").split(",")),err_div:"error_",nextbutton:"nextButton",disableButton:"disableNextButton",activeButton:"activeNextButton",opened:"opened",closed:"quotation_section_close",active:"quotation_section_active",hide:"hidden",timer:500,effectDuration:500,stopEventClass:"js_ajaxAction",noFxClass:"js_nofx",noToggleClass:"js_noToggle",methodForward:"evaluation",closeLastSection:true,onSubmit:undefined,onSectionOpen:Class.empty,onSectionClose:Class.empty},init:function(b,a){b=$(b||document.body);Sliding.options=$merge(Sliding.options,a);this.nextButton=b.getElement("#"+Sliding.options.nextbutton);this.form=$(Sliding.options.form);$ES(Sliding.options.section,b).each(function(d,c,e){if(c==0){this._first=d}this.buildSection(d,c)},this);this.nextButton.form=this.form;this.nextButton.addEvent("click",this.forward.bind(this));this.loaded=true;this.makeValidationThread();return this},makeValidationThread:function(){if(!this.loaded){return}$clear(this.timer);if(Sliding.options.timer){new Element("input",{type:"hidden",id:"_sliding_check","class":"hidden hide"}).injectBefore(this.nextButton);this.timer=this.enableNextButton.periodical(Sliding.options.timer,this)}},check:function(){if($("_sliding_check")&&$("_sliding_check").getParent()){return true}return false},buildSection:function(e,c){e.header=e.getElement(Sliding.options.header);e.content=e.getElement(Sliding.options.content);e.footer=e.getElement(Sliding.options.footer);e.handler=e.getElement(Sliding.options.handler);e._nextbutton=this.nextButton;e._form=this.form;if(!e.header||!e.content||!e.footer||!e.handler){return null}if(!e.fx){if(e.hasClass(Sliding.options.noFxClass)){e.fx={slideIn:function(){return{chain:function(){}}},slideOut:function(){}}}else{e.fx=new Fx.Slide(e.content,{duration:Sliding.options.effectDuration,transition:Fx.Transitions.Quart.easeOut,wait:false})}if(window.ie8){e.fx.vertical=function(){this.margin="margin-top";this.layout="height";if(!$defined(this.offset)){this.offset=this.element.offsetHeight}}}}var a=0;$ES("*",e).each(function(h,g,f){if(!Sliding.options.elements.contains(h.getTag())){return}this.buildElement(e,h,a++)},this);var b=this.find(this,c);var d=(b)?b.next:null;e.prev=b;if(b){b.next=e}e.next=d;if(d){d.prev=e}e._validation=this.validateSection.bind(e);e.isErrorMessagePresent=this.isErrorMessagePresent.bind(e);e.open=this.open.bind(e);e.selectElement=this.selectElement.bind(e);e.close=this.close.bind(e);e.clearErrors=this.clearErrors.bind(e);e.resize=this.resize.bind(e);e.setCSSClasses=this.setCSSClasses.bind(e);e.handler.addEvent("click",e.open.bind(e,[]));return e},buildElement:function(f,d,c){if(c==undefined||c==null){c=1000}d.section=f;d._validation=this.validateElement.bind(d);d.clearError=this.clearError.bind(d);d.clip=this.clip.bind(d);var b="";if(window.ie){_elementId=d.name.replace(new RegExp("\\.","gi"),"_").replace(new RegExp("\\[","gi"),"_").replace(new RegExp("\\]","gi"),"");_elementId=_elementId.replace(new RegExp("\\(","gi"),"_");_elementId=_elementId.replace(new RegExp("\\)","gi"),"")}else{_elementId=d.name.replace(".","_","g").replace("[","_","g").replace("]","","g");_elementId=_elementId.replace("(","_","g");_elementId=_elementId.replace(")","","g")}d._error=$(Sliding.options.err_div+_elementId);if(d.getTag()=="input"&&d.getProperty("type")=="radio"){d.addEvent("click",this.onLostfocus.bind(d))}else{if(d.getTag()=="input"){d.addEvent("blur",this.onLostfocus.bind(d))}else{if(d.getTag()=="select"){d.addEvent("change",this.onLostfocus.bind(d))}else{if(d.getTag=="textarea"){}}}}var e=this.find(f,c);var a=(e)?e.next:null;d.prev=e;if(e){e.next=d}d.next=a;if(a){a.prev=d}if(!d.prev){f._first=d}d._index=this.find(f,d);return d},find:function(d,a){if($type(a)=="number"){if(a<0){return null}var b=d._first;while(b&&a>0){if(!b.next){break}b=b.next;a--}return b}else{if($type(a)=="element"){var b=d._first;var c=0;while(b){if(b===a){return c}b=b.next;c++}return -1}}},closeAll:function(a){var b=this._first;while(b){if(!a.contains(b)){b.close.apply(b,[false])}else{b.setCSSClasses()}b=b.next}return this},enableNextButton:function(){if(!this.check()){if(this.timer){return $clear(this.timer)}}this.errors=0;var b=this._first;while(b){var a=b._validation(false,true);if(a&&b.hasClass(Sliding.options.closed)){b.handler.removeClass(Sliding.options.hide)}this.errors=a?this.errors:this.errors+1;b=b.next}if(this.errors==0){this.nextButton.removeClass(Sliding.options.disableButton);this.nextButton.addClass(Sliding.options.activeButton)}else{this.nextButton.removeClass(Sliding.options.activeButton);this.nextButton.addClass(Sliding.options.disableButton)}},forward:function(){if(this.nextButton.hasClass(Sliding.options.disableButton)){return false}$clear(this.timer);this.submitForm()},submitForm:function(){if(this.nextButton.hasClass(Sliding.options.disableButton)){return false}if($type(this.options.onSubmit)=="function"){return this.options.onSubmit.apply(this,[])}this.form.action=this.form.action.replace(/(\#.*)?$/,"?method="+Sliding.options.methodForward+"$1");myCursor.show();this.form.submit()},clearError:function(){if(this._error){this._error.addClass(Sliding.options.hide);this.section.resize()}return this},validateElement:function(c,b){if(!this.form){return true}var a=false;if(this.getProperty("type")=="radio"){var e=this.form.elements[this.name];for(var d=0;d<e.length;d++){if(e[d].checked){a=true;break}}}else{if(this.value==""){a=false}else{if(this.value!=""&&this.hasClass("hasDefaultText")){a=false}else{a=true}}}if($type(this.validation)=="function"){a=this.validation(a,!!b)}if(c&&this._error){if(a){this._error.addClass(Sliding.options.hide)}else{this._error.removeClass(Sliding.options.hide)}this.section.resize()}return a},onLostfocus:function(){if(this.hasClass(Sliding.options.stopEventClass)){return}if(!this.section.hasClass(Sliding.options.opened)){return}return this.clip()},clip:function(){var b=false;var a=this._validation(true);if(a){b=this.section._validation(false)}if(b){if(this.section.next){var d=this.section,c;while(d&&d._validation()){d=d.next}if(d){d.open(true,true)}this.section.close(true)}else{this.section.close(true)}}else{this.section.resize()}return this},clearErrors:function(){var a=this._first;while(a){a.clearError();a=a.next}return this},validateSection:function(b,a){this.errors=0;var d=this._first;while(d){if(!d._validation(b,!!a)){this.errors++}d=d.next}var c=(this.errors==0);if($type(this.onValidation)=="function"){c=this.onValidation(c,!!a)}return c},isErrorMessagePresent:function(){var b=0;var a=this._first;while(a){if(a._error){b=a._error.hasClass(Sliding.options.hide)?b:b+1}a=a.next}return(b>0)},selectElement:function(a){try{a=a||this._first;a.focus()}catch(b){}},open:function(a,b){if($type(this.onOpen)=="function"){if(!this.onOpen.apply(this,[])){return}}Sliding.options.onSectionOpen.apply(this,[]);this.fx.slideIn().chain((function(){if(this.hasClass(Sliding.options.opened)&&this.fx.element){if(this.fx.element.offsetHeight!=this.fx.wrapper.offsetHeight){this.fx.wrapper.setStyle("height",this.fx.element.offsetHeight)}}}).bind(this));if(!b){var c=Sliding._first;while(c){if(c!==this&&!c.hasClass(Sliding.options.closed)){c.close(true)}c=c.next}}if(this.hasClass(Sliding.options.noToggleClass)){return this}this.setCSSClasses();return this},setCSSClasses:function(){this.addClass(Sliding.options.opened);this.removeClass(Sliding.options.closed);this.handler.addClass(Sliding.options.hide);this.header.removeClass(Sliding.options.closed);this.header.addClass(Sliding.options.active);this.footer.removeClass(Sliding.options.hide)},resize:function(){this.fx.slideIn()},close:function(b){if($type(this.onClose)=="function"){if(!this.onClose.apply(this,[])){return}}Sliding.options.onSectionClose.apply(this,[]);if(b){if(!this._validation(true)){return this}}if((this._validation()&&!this.next)&&!Sliding.options.closeLastSection){this.addClass(Sliding.options.noToggleClass)}if(this.hasClass(Sliding.options.noToggleClass)){return this}(function a(){if(window.ie8){var c=this.content.offsetHeight;this.fx.slideOut().chain((function(){this.fx.offset=c}).bind(this))}else{this.fx.slideOut()}this.removeClass(Sliding.options.opened);this.addClass(Sliding.options.closed);this.header.removeClass(Sliding.options.active);this.header.addClass(Sliding.options.closed);this.footer.addClass(Sliding.options.hide);return this}).delay(1,this);return this}};