const GenericTableFormUtils=function(){return this.runInit=function(n){var i=$("#blockId"+n),t=i.attr("data-dependentofformfield"),r=i.attr("data-dependentofformfieldvalue");t!=null&&t!=""&&this.dependencyDisplay(n,t,r)},this.copyTable=function(n,t){var e=parseInt($("#tablesCount"+n).html())+1,f,i;$("#tablesCount"+n).text(e);var o=$("#"+t+n),u=$(o).clone(),r=$("input",u);for(i=0;i<r.length;i++)r[i].type!=="hidden"&&(r[i].value="",r[i].name=r[i].name+"_"+e);for(f=$("a",u),i=0;i<f.length;i++)f[i].remove();u.appendTo("#"+t+"_elementer"+n)},this.dependencyDisplay=function(n,t,i){var r=$("input[name='"+t+"']");this.handleBlockDisplay(n,t,i);r.click({eID:n,elName:t,elValue:i},function(n){var t=n;window.GenericTableFormUtils.handleBlockDisplay(t.data.eID,t.data.elName,t.data.elValue)})},this.handleBlockDisplay=function(n,t,i){var r=$("input[name='"+t+"']");r.each(function(){$(this).is(":checked")&&window.GenericTableFormUtils.blockDisplay(n,$(this).val()==i)})},this.blockDisplay=function(n,t){t?$("#blockId"+n).removeClass("div-hide"):$("#blockId"+n).addClass("div-hide");this.tabbingEnable(n,t)},this.tabbingEnable=function(n,t){this.tabbingEnableElementsByType(n,t,"input");this.tabbingEnableElementsByType(n,t,"select")},this.tabbingEnableElementsByType=function(n,t,i){var r=$(i,$("#blockId"+n));r.each(function(){$(this).attr("tabindex")=="0"||$(this).attr("tabindex")=="-2"||(t?$(this).attr("tabindex",""):$(this).attr("tabindex","-1"))})},this},GenericTableContainerFormUtils=function(){return this.runInit=function(n){var i=$("#generic-formtable-container"+n),t=i.attr("data-dependentofformfield"),r=i.attr("data-dependentofformfieldvalue"),u=i.attr("data-dependentofformfieldmode"),f=i.attr("data-enablecopybody");window.GenericTableContainerFormUtils.setTable_id_onElements(n,f=="True");t!==""&&(u=="default"?window.GenericTableContainerFormUtils.dependencyDisplay(n,t,r):u=="hidden"?window.GenericTableContainerFormUtils.dependencyDisplayHidden(n,t,r):u=="evalgt"?window.GenericTableContainerFormUtils.dependencyDisplayEvalGT(n,t,r):u=="select"&&window.GenericTableContainerFormUtils.dependencyDisplaySelect(n,t,r))},this.get_table_id=function(n){var r=$("input[name='"+n+"']"),t=$("select[name='"+n+"']"),i="";return r.length>0?(i=r.attr("table_id"),t.length):t.length>0&&(i=t.attr("table_id")),i},this.setTable_id_onElements=function(n,t){var r=t?"body":"",i;r!==""&&(i=$("#generic-formtable-container"+n),this.table_id_onElementsAllTypes(n,i))},this.setTablesCount=function(n,t){$("#tablesCount"+n).text(t)},this.setTablesCountByElementReference=function(n,t){var i=null;i=$("input[name='"+t+"']").closest(".generic-formtable-container");i.length==0&&(i=$("select[name='"+t+"']").closest(".generic-formtable-container"));i.find(".tablesCount").text(n)},this.addContainerTable=function(n){var t=parseInt($("#tablesCount"+n).html())+1;this.setTablesCount(n,t)},this.copyContainerTable=function(n,t){var p=parseInt($("#tablesCount"+n).html()),d=$("#generic-formtable-container"+n),w=$("#"+t+n),o,g,e,u,s,h,f,r,i;for(this.table_id_onElementsAllTypes(n,w),o=d.find(".copy__body_border").not(".AP_Form__Table"),g=p-o.length,e=o.length+1;e<p+1;e++){for(u=$(w).clone(),u.attr("id",""),s=$("a",u),r=0;r<s.length;r++)s[r].remove();for(this.deleteValueSetNameOnElements("input",u,e),this.deleteValueSetNameOnElements("select",u,e),this.unselectElements("input",u,e),h=$("input",u),r=0;r<h.length;r++)i=$(h[r]),i.hasClass("hasDatepicker")&&$("input[name='"+i.attr("name")+"']",u).attr("id",i.attr("id")+i.attr("name").charAt(i.attr("name").length-2)+i.attr("name").charAt(i.attr("name").length-1));f=$("#"+t+"_elementer"+n);u.appendTo(f);var b=$("input",f),k,c="",l="",a="",v="",y="";for(r=0;r<b.length;r++)i=$(b[r]),i.hasClass("hasDatepicker")&&(k=i,c=i.attr("name")),i.hasClass("hasCPRValidation")&&(l=i.attr("name")),i.hasClass("has8CifreValidation")&&(a=i.attr("name")),i.hasClass("has4CifreValidation")&&(v=i.attr("name")),i.hasClass("has8CifreValidation")&&(y=i.attr("name"));if(c!==""&&(k.removeClass("hasDatepicker"),this.datepickerInitAndValidate(c,f)),l!=="")this.onChangevalidateCPR(l,f);if(a!=="")this.onChangevalidate8Cifre(a,f);if(v!=="")this.onChangevalidate4Cifre(v,f);if(y!=="")this.onChangevalidate8Cifre(y,f)}},this.copyContainerTableByElementReference=function(n,t){var e=null,s,nt,o,u,h,c,f,r,i;e=$("input[name='"+t+"']").closest(".generic-formtable-container");e.length==0&&(e=$("select[name='"+t+"']").closest(".generic-formtable-container"));var w=e.attr("id").replace("generic-formtable-container",""),b=parseInt(e.find(".tablesCount").html()),k=e.find(".copy__body_border");for(this.table_id_onElementsAllTypes(w,k),s=e.find(".copy__body_border").not(".AP_Form__Table"),nt=b-s.length,o=s.length+1;o<b+1;o++){for(u=$(k).clone(),u.attr("id",""),h=$("a",u),r=0;r<h.length;r++)h[r].remove();for(this.deleteValueSetNameOnElements("input",u,o),this.deleteValueSetNameOnElements("select",u,o),this.unselectElements("input",u,o),c=$("input",u),r=0;r<c.length;r++)i=$(c[r]),i.hasClass("hasDatepicker")&&$("input[name='"+i.attr("name")+"']",u).attr("id",i.attr("id")+i.attr("name").charAt(i.attr("name").length-2)+i.attr("name").charAt(i.attr("name").length-1));f=$("#"+n+"_elementer"+w);u.appendTo(f);var d=$("input",f),g,l="",a="",v="",y="",p="";for(r=0;r<d.length;r++)i=$(d[r]),i.hasClass("hasDatepicker")&&(g=i,l=i.attr("name")),i.hasClass("hasCPRValidation")&&(a=i.attr("name")),i.hasClass("has8CifreValidation")&&(v=i.attr("name")),i.hasClass("has4CifreValidation")&&(y=i.attr("name")),i.hasClass("has8CifreValidation")&&(p=i.attr("name"));if(l!==""&&(g.removeClass("hasDatepicker"),this.datepickerInitAndValidate(l,f)),a!=="")this.onChangevalidateCPR(a,f);if(v!=="")this.onChangevalidate8Cifre(v,f);if(y!=="")this.onChangevalidate4Cifre(y,f);if(p!=="")this.onChangevalidate8Cifre(p,f)}},this.deleteValueSetNameOnElements=function(n,t,i){for(var u=$(n,t),r=0;r<u.length;r++)u[r].type!=="hidden"&&(u[r].type!=="radio"&&u[r].type!=="checkbox"&&(u[r].value=""),u[r].name=u[r].name+"_"+i),n=="select"&&(u[r].id="")},this.unselectElements=function(n,t){for(var r=$(n,t),i=0;i<r.length;i++)r[i].type=="checkbox"&&(r[i].checked=!1)},this.table_id_onElementsAllTypes=function(n,t){this.table_id_onElements(n,"input",t);this.table_id_onElements(n,"select",t)},this.table_id_onElements=function(n,t,i){for(var f,u=$(t,i),r=0;r<u.length;r++)f=$(u[r]),f.attr("table_id",n)},this.dependencyDisplay=function(n,t,i){var r=$("input[name='"+t+"']");this.handleBlockDisplay(n,t,i);r.click({eID:n,elName:t,elValue:i},function(n){var t=n;window.GenericTableContainerFormUtils.handleBlockDisplay(t.data.eID,t.data.elName,t.data.elValue)});r.change({eID:n,elName:t,elValue:i},function(n){var t=n;window.GenericTableContainerFormUtils.handleBlockDisplay(t.data.eID,t.data.elName,t.data.elValue)})},this.dependencyDisplayHidden=function(n,t,i){var r=$("input[name='"+t+"']");this.handleBlockDisplayHidden(n,t,i);$("input[name='"+t+"']").change({eID:n,elNameHidden:t,elValue:i},function(n){var t=n;window.GenericTableContainerFormUtils.handleBlockDisplayHidden(t.data.eID,t.data.elNameHidden,t.data.elValue)});$("input[name='"+t+"']").click({eID:n,elNameHidden:t,elValue:i},function(n){var t=n;window.GenericTableContainerFormUtils.handleBlockDisplayHidden(t.data.eID,t.data.elNameHidden,t.data.elValue)})},this.handleBlockDisplayHidden=function(n,t,i){var r=$("input[name='"+t+"']");r.each(function(){i!=null&&i.length>0?window.GenericTableContainerFormUtils.blockDisplayHidden(n,$(this).val().toLowerCase()==String(i).toLowerCase()):window.GenericTableContainerFormUtils.blockDisplayHidden(n,$(this).val()==i)})},this.handleBlockDisplay=function(n,t,i){var u=$("input[name='"+t+"']"),r=!1;u.each(function(){$(this).is(":radio")?$(this).is(":checked")&&(window.GenericTableContainerFormUtils.blockDisplay(n,$(this).val()==i),r=!0):$(this).is(":checkbox")&&$(this).is(":checked")&&(window.GenericTableContainerFormUtils.blockDisplay(n,$(this).val()==i),r=!0)});r==!1&&window.GenericTableContainerFormUtils.blockDisplay(n,!1)},this.blockDisplay=function(n,t){t?$("#generic-formtable-container"+n).removeClass("div-hide"):$("#generic-formtable-container"+n).addClass("div-hide");this.tabbingEnable(n,t)},this.blockDisplayHidden=function(n,t){t?$("#generic-formtable-container"+n).removeClass("div-hide"):$("#generic-formtable-container"+n).addClass("div-hide")},this.tabbingEnable=function(n,t){this.tabbingEnableElementsByType(n,t,"input");this.tabbingEnableElementsByType(n,t,"select")},this.tabbingEnableElementsByType=function(n,t,i){var r=$(i,$("#blockId"+n));r.each(function(){$(this).attr("tabindex")=="0"||$(this).attr("tabindex")=="-2"||(t?$(this).attr("tabindex",""):$(this).attr("tabindex","-1"))})},this.dependencyDisplayEvalGT=function(n,t,i){var r=$("input[name='"+t+"']");this.handleBlockDisplayEvalGT(n,t,i);r.change({eID:n,elEvalGT:t,elValue:i},function(n){var t=n;window.GenericTableContainerFormUtils.handleBlockDisplayEvalGT(t.data.eID,t.data.elEvalGT,t.data.elValue)});r.keypress({eID:n,elEvalGT:t,elValue:i},function(n){var t=n;window.GenericTableContainerFormUtils.handleBlockDisplayEvalGT(t.data.eID,t.data.elEvalGT,t.data.elValue)});r.keyup({eID:n,elEvalGT:t,elValue:i},function(n){var t=n;window.GenericTableContainerFormUtils.handleBlockDisplayEvalGT(t.data.eID,t.data.elEvalGT,t.data.elValue)})},this.dependencyDisplaySelect=function(n,t,i){var r=$("select[name='"+t+"']");this.handleBlockDisplaySelect(n,t,i);r.change({eID:n,elSelect:t,elValue:i},function(n){var t=n;window.GenericTableContainerFormUtils.handleBlockDisplaySelect(t.data.eID,t.data.elSelect,t.data.elValue)});r.keypress({eID:n,elSelect:t,elValue:i},function(n){var t=n;window.GenericTableContainerFormUtils.handleBlockDisplaySelect(t.data.eID,t.data.elSelect,t.data.elValue)});r.keyup({eID:n,elSelect:t,elValue:i},function(n){var t=n;window.GenericTableContainerFormUtils.handleBlockDisplaySelect(t.data.eID,t.data.elSelect,t.data.elValue)})},this.handleBlockDisplaySelect=function(n,t,i){var r=$("select[name='"+t+"']");t!=null&&t.length>0&&i!=null&&i.length>0&&this.blockDisplay(n,r.val()==i)},this.handleBlockDisplayEvalGT=function(n,t,i){var r=$("input[name='"+t+"']");t!=null&&t.length>0&&i!=null&&i.length>0&&this.blockDisplay(n,r.val()>i)},this.datepickerInitAndValidate=function(n,t){onChangevalidateDate(n,t);datepickerInit(n,t)},this.onChangevalidateCPR=function(n,t){var i=$("input[name='"+n+"']",t),r,u;i.addClass("hasCPRValidation");i.on("focus",function(){r=this.value!==""?this.value:""}).change(function(){u=r;r=this.value!==""?this.value:"";var n="";n=validateCPR(i)?r:u;i.val(normalizeCPR(i,n))})},this.onChangevalidate8Cifre=function(n,t){var r=$("input[name='"+n+"']",t),i,u;r.addClass("has8CifreValidation");r.on("focus",function(){i=this.value!==""?this.value:""}).change(function(){u=i;i=this.value!==""?this.value:"";normalize8Cifre(r,i)})},this.onChangevalidate4Cifre=function(n,t){var r=$("input[name='"+n+"']",t),i,u;r.addClass("has4CifreValidation");r.on("focus",function(){i=this.value!==""?this.value:""}).change(function(){u=i;i=this.value!==""?this.value:"";normalize4Cifre(r,i)})},normalizeCPR=function(n,t){var u=(t+"").replace("-",""),i=u.replace(" ",""),r;return i.length!=10||isNaN(i)?(i.length>0?n.addClass("error"):n.removeClass("error"),t):(r=i.substring(0,6)+"-"+i.substring(6,10),n.removeClass("error"),r)},normalize8Cifre=function(n,t){var i=t.replace(" ","");return i.length!=8||isNaN(i)?(i.length>0?n.addClass("error"):n.removeClass("error"),t):(n.removeClass("error"),i)},normalize4Cifre=function(n,t){var i=t.replace(" ","");return i.length!=4||isNaN(i)?(i.length>0?n.addClass("error"):n.removeClass("error"),t):(n.removeClass("error"),i)},onChangevalidateDate=function(n,t){var i=$("input[name='"+n+"']",t),r,u;i.on("focus",function(){r=this.value!==""?this.value:""}).change(function(){var n,t;u=r;r=this.value!==""?this.value:"";n="";try{n=r;t=$.datepicker.parseDate("dd-mm-yy",n);i.removeClass("invalid")}catch(f){i.addClass("invalid")}i.val(n)})},datepickerInit=function(n,t){$("input[name='"+n+"']",t).datepicker({showOn:"focus",buttonImage:"images/calendar.gif",buttonImageOnly:!0,buttonText:"Select date",changeMonth:!0,changeYear:!0,gotoCurrent:!0,dateFormat:"dd-mm-yy"})},validateCPR=function(n){var t=n.val();return t=t.replace("-",""),t.length<=10},this};window.GenericTableFormUtils=new GenericTableFormUtils;window.GenericTableContainerFormUtils=new GenericTableContainerFormUtils