(function(){function a(c,f){function b(l){var j=l.name,k=l.getTag(),m=l.getProperty("type");if(k=="input"&&m=="radio"){while(true){if(l){var h=l.name,g=l.getTag(),i=l.getProperty("type");if(k!=k||m!=i||j!=h){return l}}else{return null}l=l.next}}else{return l.next}}var d=c;if((d=b(c))){c.section.selectElement(d)}else{if(f){var e=c.section.next;while(e&&e._validation(false)){e=e.next}if(e){e.selectElement()}else{}}}}window.Sliding={options:{form:"quotationForm",section:".quotation_section",radioButtonSection:"radioButtonSection",header:".quotation_section_title",content:".quotation_section_content",footer:".quotation_section_footer",handler:".quotationModifyLink",elements:$A(("input,select,textarea").split(",")),err_div:"error_",containerId:"",nextbutton:"nextButton",savebutton:"newSaveButton",disableButton:"disabledButton",activeButton:"activeButton",disableSaveButton:"disabledButton",activeSaveButton:"activeButton",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",methodSave:"",closeLastSection:true,onSubmit:undefined,onSectionOpen:Class.empty,onSectionClose:Class.empty,defaultValues:["JJ/MM/AAAA","MM/AAAA"],elementNotReset:"elementNotReset",isAjax:false,type:"navigationscript",displayAlwaysHandler:false,autonavigation:false,onDisableButton:null,onEnableButton:null,autoSliding:true},init:function(c,b){c=$(c||document.body);Sliding.options=$merge(Sliding.options,b);this.nextButton=c.getElement("#"+Sliding.options.nextbutton);this.saveButton=c.getElement("#"+Sliding.options.savebutton);this.containerId=Sliding.options.containerId||c.id;this.form=$(Sliding.options.form);$ES(Sliding.options.section,c).each(function(e,d,f){if(d==0){this._first=e}this.buildSection(e,d)},this);this.nextButton.form=this.form;this.nextButton.method=Sliding.options.methodForward;this.saveButton&&(this.saveButton.form=this.form);this.saveButton&&(this.saveButton.method=Sliding.options.methodSave);this.nextButton.removeEvents().addEvent("click",this.forward.bind(this));this.saveButton&&this.saveButton.removeEvents().addEvent("click",this.save.bind(this));this.loaded=true;this.makeValidationThread();return this},makeValidationThread:function(){if(!this.loaded){return}$clear(this.timer);if(Sliding.options.timer){$("_sliding_check")&&$("_sliding_check").remove();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.isRadioButtonSection=e.hasClass(Sliding.options.radioButtonSection);e._nextbutton=this.nextButton;e._savebutton=this.saveButton;e._form=this.form;if(!e.header||!e.content||!e.footer){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}}}}this.buildAllElement(e);var b=c>0?this.find(this,c):null;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.isErrorServerPresent=this.isErrorServerPresent.bind(e);e.open=this.open.bind(e);e.openRadioButtonSection=this.openRadioButtonSection.bind(e);e.resetSection=this.resetSection.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&&e.handler.removeEvents().addEvent("mousedown",this.manageModifier.bind(e,[]));return e},buildAllElement:function(c){var b=0;$ES("*",c).each(function(f,e,d){if(!Sliding.options.elements.contains(f.getTag())){return}if(this.find(c,f)==-1){this.buildElement(c,f,b++)}else{b++}},this)},buildElement:function(g,e,d){if(d==undefined||d==null){d=1000}e.section=g;e._validation=this.validateElement.bind(e);e.showError=this.showElementError.bind(e);e.clearError=this.clearError.bind(e);e.clip=this.clip.bind(e);var c="";_elementId=e.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"),"");e._error=$(Sliding.options.err_div+_elementId);e.selectNextElement=function(h){a(this,!!h);return this};if(e.getTag()=="input"&&e.getProperty("type")=="radio"){e.addEvent("click",this.onLostfocus.bind(e))}else{if(e.getTag()=="input"){e.addEvent("blur",this.onLostfocus.bind(e))}else{if(e.getTag()=="select"){e.addEvent("change",this.onLostfocus.bind(e))}else{if(e.getTag=="textarea"){}}}}var f=d>0?this.find(g,d):null;var b=(f)?f.next:null;e.prev=f;if(f){f.next=e}e.next=b;if(b){b.prev=e}if(!e.prev){g._first=e}e._index=this.find(g,e);return e},clear:function(c){var b=c._first;while(b){_elem=b;b=b.next;_elem.prev=null;_elem.next=null}c._first=null},find:function(e,b){if($type(b)=="number"){if(b<0){return null}var c=e._first;while(c&&b>0){if(!c.next){break}c=c.next;b--}return c}else{if($type(b)=="element"){var c=e._first;var d=0;while(c){if(c===b){return d}c=c.next;d++}return -1}}},closeAll:function(b){var c=this._first;while(c){if(!b.contains(c)){c.close.apply(c,[false])}else{c.setCSSClasses()}c=c.next}return this},enableNextButton:function(){if(!this.check()){if(this.timer){return $clear(this.timer)}}this.errors=0;var c=this._first;while(c){var b=c._validation(false,true);if(c.hasClass(Sliding.options.closed)&&(Sliding.options.displayAlwaysHandler||b)){c.handler&&c.handler.removeClass(Sliding.options.hide)}this.errors=b?this.errors:this.errors+1;c=c.next}if(this.errors==0){if(Sliding.options.onEnableButton&&Sliding.options.onEnableButton.apply){Sliding.options.onEnableButton()}else{this.nextButton.removeClass(Sliding.options.disableButton);this.nextButton.addClass(Sliding.options.activeButton);if(this.saveButton){this.saveButton.removeClass(Sliding.options.disableSaveButton);this.saveButton.addClass(Sliding.options.activeSaveButton)}}}else{if(Sliding.options.onDisableButton&&Sliding.options.onDisableButton.apply){Sliding.options.onDisableButton()}else{this.nextButton.removeClass(Sliding.options.activeButton);this.nextButton.addClass(Sliding.options.disableButton);if(this.saveButton){this.saveButton.removeClass(Sliding.options.activeSaveButton);this.saveButton.addClass(Sliding.options.disableSaveButton)}}}this.options.onEnableDisableButton&&this.options.onEnableDisableButton.apply&&this.options.onEnableDisableButton(this.errors==0)},forward:function(){if(this.nextButton.hasClass(Sliding.options.disableButton)){return false}$clear(this.timer);if(Sliding.options.isAjax){this.submitFormWithAjax(this.nextButton)}else{this.submitForm(this.nextButton)}},save:function(){if(this.saveButton.hasClass(Sliding.options.disableButton)){return false}$clear(this.timer);if(Sliding.options.isAjax){this.submitFormWithAjax(this.saveButton)}else{this.submitForm(this.saveButton)}},submitForm:function(b){if(b.hasClass(Sliding.options.disableButton)){return false}if($type(this.options.onSubmit)=="function"){return this.options.onSubmit.call(this)}this.form.action=b.form.action.replace(/(\#.*)?$/,"?method="+b.method+"$1");myCursor.show();this.form.submit()},submitFormWithAjax:function(b){if(b.hasClass(Sliding.options.disableButton)){return false}if($type(this.options.onSubmit)=="function"){return this.options.onSubmit.apply(this,[])}new Ajax(this.form.action,{onRequest:function(){myCursor.show()},onComplete:function(c){myCursor.hide()},evalScripts:true,update:this.containerId}).request(["method="+Sliding.options.methodForward,b.form.toQueryString()].join("&"))},clearError:function(){if(this._error){this._error.addClass(Sliding.options.hide)}return this},validateElement:function(d,c){if(!this.form){return true}var b=false;if(this.getProperty("type")=="radio"){var f=this.form.elements[this.name];for(var e=0;e<f.length;e++){if(f[e].checked){b=true;break}}}else{if(this.getProperty("type")=="checkbox"){b=this.checked}else{if(this.value==""){b=false}else{if(this.value!=""&&this.hasClass("hasDefaultText")){b=false}else{b=true}}}}if($type(this.validation)=="function"){b=this.validation(b,!!c)}if(d&&this._error){this.showError(b)}return b},showElementError:function(b){if(!this._error){return this}this._error[b?"addClass":"removeClass"](Sliding.options.hide);this.section.resize()},onLostfocus:function(){var b=this._validation(true);if(b){var d=false;d=this.hasClass(Sliding.options.stopEventClass)||!this.section.hasClass(Sliding.options.opened);var e=d?false:this.clip();var c=this.getProperty("type");if(Sliding.options.autonavigation&&(c!="text"&&c!="password")){this.selectNextElement(e)}}return b},clip:function(){var b=this.section._validation(false);if(b){if(this.section.next){var c=this.section.next;while(c&&c._validation()){c=c.next}if(c){if(c.isRadioButtonSection){c.openRadioButtonSection(true,true)}else{if(Sliding.options.autoSliding){c.open(true,true)}}}}if(Sliding.options.autoSliding){this.section.close(true)}}else{this.section.resize()}return b},clearErrors:function(){var b=this._first;while(b){b.clearError();b=b.next}return this},validateSection:function(c,b){this.errors=0;var e=this._first;while(e){if(!e._validation(c,!!b)){this.errors++}e=e.next}var d=(this.errors==0);if($type(this.onValidation)=="function"){d=this.onValidation(d,!!b)}return d},isErrorMessagePresent:function(){var c=0;var b=this._first;while(b){if(b._error){c=b._error.hasClass(Sliding.options.hide)?c:c+1}b=b.next}return(c>0)},isErrorServerPresent:function(){var b=0;$ES(".error_message",this).each(function(c){if(!c.hasClass(Sliding.options.hide)){if(c.innerHTML.trim().length>0){++b}}});return(b>0)},selectElement:function(b){try{b=b||this._first;b.focus()}catch(c){}},open:function(b,c){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)}if(this.fx.element.getBoundingClientRect().top!=this.fx.wrapper.getBoundingClientRect().top){var e=this.fx.wrapper.getBoundingClientRect().top-this.fx.element.getBoundingClientRect().top;this.fx.element.setStyle("margin-top",e)}}}).bind(this));if(!c){var d=Sliding._first;while(d){if(d!==this&&!d.hasClass(Sliding.options.closed)){d.close(true)}d=d.next}}if(this.hasClass(Sliding.options.noToggleClass)){return this}this.setCSSClasses();this.isOpen=true;return this},openRadioButtonSection:function(b,c){this.addClass(Sliding.options.opened);this.removeClass(Sliding.options.closed);this.handler&&this.handler.addClass(Sliding.options.hide);this.header.removeClass(Sliding.options.closed);this.header.addClass(Sliding.options.active)},manageModifier:function(c,d){if(Sliding.options.autoSliding){return this.open.apply(this,[])}else{if(this.isOpen){var b=this._validation(false,true);if(b){return this.close.delay(100,this)}}else{return this.open.apply(this,[])}}},setCSSClasses:function(){this.addClass(Sliding.options.opened);this.removeClass(Sliding.options.closed);if(Sliding.options.autoSliding){this.handler&&this.handler.addClass(Sliding.options.hide)}else{if(this.handler){this.handler.innerHTML="fermer"}}this.header.removeClass(Sliding.options.closed);this.header.addClass(Sliding.options.active);this.footer.removeClass(Sliding.options.hide)},resize:function(){if(this.hasClass(Sliding.options.opened)){this.fx.slideIn()}},close:function(c){if($type(this.onClose)=="function"){if(!this.onClose.apply(this,[])){return}}Sliding.options.onSectionClose.apply(this,[]);if(c){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 b(){if(window.ie8){var d=this.content.offsetHeight;this.fx.slideOut().chain((function(){this.fx.offset=d}).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);if(!Sliding.options.autoSliding){this.handler.innerHTML="modifier"}return this}).delay(1,this);this.isOpen=false;return this},resetSection:function(){$ES("input,select",this).each(function(b){if(!b.hasClass(Sliding.options.elementNotReset)){Sliding.resetElement(b)}})},resetElement:function(b){if(!Sliding.options.defaultValues.contains(b.value)){if(!b.disabled){if(b.tagName.toLowerCase()=="input"){if(b.type.toLowerCase()=="text"){b.value=""}if(b.type.toLowerCase()=="password"){b.value=""}if(b.type.toLowerCase()=="radio"||b.type.toLowerCase()=="checkbox"){b.checked=false}}if(b.tagName.toLowerCase()=="select"){b.selectedIndex=0}}}},getAllSectionsWithServerError:function(){var c=[];var b=Sliding._first;while(b){if(b.isErrorServerPresent()){c.push(b)}b=b.next}return c}}})();
