!function(e){var r="Validation",t=e.Core.newType("hafasModule"),i=function(e){if(null!=e&&null!=e.form){this.elements=e.form.elements,this.showInputFieldMessages=!0,void 0!==e.showInputFieldMessages&&(this.showInputFieldMessages=e.showInputFieldMessages),this.overrides={checkForm:null};var r=!0;e.hasOwnProperty("checkFormOnInit")&&!e.checkFormOnInit&&(r=!1),r&&this.checkForm()}};i.prototype={valid:!0,checkForm:function(){if(this.overrides.checkForm)return this.overrides.checkForm();this.resetFields();for(var e=0,r=this.elements.length;e<r;e++){var t=this.elements[e];if(t.getAttribute("required"))if(""===t.value)this.valid=!1,this.showError(t,"required");else if(t.getAttribute("pattern")){var i=new RegExp(t.getAttribute("pattern"),"g");t.value.match(i)||(this.valid=!1,this.showError(t,"pattern"))}if(t.getAttribute("pattern")){i=new RegExp(t.getAttribute("pattern"),"g");t.value.match(i)||(this.valid=!1,this.showError(t,"pattern"))}}},resetFields:function(){var r=e(".hfs_validation_error",!0);if(r.length>0)for(var t=0,i=r.length;t<i;t++){var a=r[t];a.parentNode.removeChild(a)}var o=e(".validation-error",!0);if(o.length>0)for(var n=0,s=o.length;n<s;n++){o[n].removeClassName("validation-error")}},setFocus:function(){this.showInputFieldMessages&&e(".validation-error",!0)[0].focus()},showError:function(e,r){var t=e.getAttribute("data-val-required"),i=e.getAttribute("data-val-pattern"),a=e.getAttribute("data-no-results"),o=this;function n(r){if(o.showInputFieldMessages){var t=document.createElement("span");t.className="hfs_validation_error",t.innerHTML=r,t.setAttribute("role","alert"),t.setAttribute("aria-live","assertive"),t.setAttribute("aria-atomic",!0),e.parentNode.appendChild(t),e.addClassName("validation-error")}}switch(r){case"required":if(!t)throw Error('No Errormessage in "data-val-required" defined.');n(t);break;case"pattern":if(!i)throw Error('No Pattern in "data-val-pattern" defined.');n(i);break;case"noResults":if(!a)throw Error('No Errormessage in "data-no-results" defined.');n(a)}this.setFocus()}};_checkIcon=function(r,t){var i={};return i[r]={},void 0===t?(i[r].ntf="undefined",i):validate.isEmpty(t)?(i[r].ntf="empty",i):validate.isEmpty(t)||e.Config.iconRes[t]&&e.Config.iconRes[t].icnClass?void 0:(i[r].ntf="not_found",i[r].ref=t,i)};e.Core.registerType(r,"hafasValidation",i),t.resetAllErrorFields=function(r){var t=e("#"+r+" .hfs_validation_error",!0);if(t.length>0)for(var i=0,a=t.length;i<a;i++){var o=t[i];o.parentNode.removeChild(o)}var n=e("#"+r+" .validation-error",!0);if(n.length>0)for(var s=0,d=n.length;s<d;s++){n[s].removeClassName("validation-error")}},t.resetErrorField=function(r){null!==e("#"+r,!1)&&e("#"+r,!1).removeClassName("validation-error");var t=e("#"+r+" + .hfs_validation_error",!1);t&&void 0!==t.parentNode&&t.parentNode.removeChild(e("#"+r+" + .hfs_validation_error",!1))},t.addRequirements=function(e){e.addModule("Render"),e.addModule("Loader"),e.addModule("i18n")},e.Core.registerModule(r,t)}(window.Hafas=window.Hafas||{});