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