window.fusionFormLogics={onReady:function(){jQuery(".fusion-form input, .fusion-form select, .fusion-form textarea").on("change keyup",function(){window.fusionFormLogics.formLogics(jQuery(this))})},formLogics:function(o=""){""===o?jQuery(".fusion-form.fusion-form-builder").each(function(){var o=jQuery(this).data("form-id");window.fusionFormLogics.applyLogics(o)}):window.fusionFormLogics.applyLogics(o.closest(".fusion-form-field").data("form-id"),o.attr("name"))},applyLogics:function(o,i=""){var n=jQuery(".fusion-form-form-wrapper.fusion-form-"+o).data("config").field_logics,e={};""!==i&&jQuery.each(n,function(o,n){-1===i.indexOf(o)&&-1===n.indexOf(i)||""===n||(e[o]=n)}),n=Object.keys(e).length?e:n,jQuery.each(n,function(i,n){window.fusionFormLogics.checkFieldLogic(i,n,o)})},checkFieldLogic:function(o,i,n){var e=""!==i?JSON.parse(i):[],r=jQuery(".fusion-form-"+n),t=r.find('[name="'+o+'"]'),u=!1,a=[];t=t.length?t:r.find('[name="'+o+'[]"]'),jQuery.each(e,function(o,i){var n,e=[],t=void 0!==i.operator?i.operator:"",u=void 0!==i.comparison?i.comparison:"",s=void 0!==i.field?i.field:"",f=void 0!==i.value?i.value:"";n=window.fusionFormLogics.getFieldValue(s,r),e.push(t),e.push("false"!==n&&window.fusionFormLogics.isMatch(n,f,u)),a.push(e)}),a.length&&(u=window.fusionFormLogics.MatchConditions(a),window.fusionFormLogics.toggleField(u,t))},toggleField:function(o,i){var n=i.attr("aria-required");o?(i.closest(".fusion-form-field").removeClass("fusion-form-field-hidden"),void 0!==n&&"true"===n&&i.attr("required",!0)):i.closest(".fusion-form-field").addClass("fusion-form-field-hidden")},getFieldValue:function(o,i){var n=i.find('[name="'+o+'"]'),e=-1!==jQuery.inArray(n.attr("type"),["checkbox","radio"]);return!n.closest(".fusion-form-field-hidden").hasClass("fusion-form-field-hidden")&&(e?window.fusionFormLogics.getArrayTypeValue(n,i):n.val())},getArrayTypeValue:function(o,i){var n=[];return"radio"===o.attr("type")?i.find('input[name="'+o.attr("name")+'"]:checked').val():(jQuery.each(i.find('input[name="'+o.attr("name")+'"]:checked'),function(){n.push(jQuery(this).val())}),n.join(" | "))},isMatch:function(o,i,n){switch(o=o?o.toLowerCase():"",i=i?i.toLowerCase():"",n){case"equal":return o===i;case"not-equal":return o!==i;case"greater-than":return parseFloat(o)>parseFloat(i);case"less-than":return parseFloat(o)<parseFloat(i);case"contains":return 0<=o.indexOf(i)}},MatchConditions:function(o){var i,n=null;if(-1==o.toString().indexOf("and")){for(i=0;i<o.length;i++)n=(n=null===n?o[i][1]:n)||o[i][1];return n}if(-1==o.toString().indexOf("or")){for(i=0;i<o.length;i++)n=(n=null===n?o[i][1]:n)&&o[i][1];return n}return window.fusionFormLogics.matchMixedConditions(o)},matchMixedConditions:function(o){var i,n=[],e="",r=0,t=0,u=o.length,a=[],s="",f="",c="",d="",l="";for(i=0;i<u;i++)void 0===n[r]&&(n[r]=[]),""===e||e==o[i][0]?(n[r][t]=o[i][1],t++,n[r][t]=o[i][0],t++,e=o[i][0]):(n[r][t]=o[i][1],t++,n[r][t]=o[i][0],r++,t=0,e="");if(jQuery.each(n,function(o,n){if(3>(u=n.length))return a.push(n[0]),void a.push(n[1]);for(i=0;i<u-1;i++)""===f?(d=n[i],l=n[i+2],c=n[i+1],f="or"===c?d||l:d&&l,i+=2):(d=f,l=n[i+1],c=n[i],f="or"===c?d||l:d&&l,i++),!0!==f&&(f=!1);s=n,a.push(f),a.push(s[u-1]),f=""}),f="",c="",d="",l="",3>(u=a.length))return a[0];for(i=0;i<u-1;i++)""===f?(d=a[i],l=a[i+2],c=a[i+1],i+=2,f="or"===c?d||l:d&&l):(d=f,l=a[i+1],c=a[i],f="or"===c?d||l:d&&l,i++),!0!==f&&(f=!1);return f}},function(o){o(document).ready(function(){window.fusionFormLogics.onReady(),window.fusionFormLogics.formLogics()})}(jQuery);