var ecom=ecom||{};ecom.formControls=function(){var t,n,h=function(i,r){t=i;n=r},u=function(n,t){for($state=$("#State"),$state.find("option:gt(0)").remove(),i=0;i<t.length;i++)$state.append($("<option><\/option>").attr("value",n==="380"?t[i].Abbreviation:t[i].Name).text(t[i].Name))},c=function(n,t){$("#CountryId").val()==="380"||$("#CountryId").val()==="187"?($("#StateContainer").show(),$("#CountryId :selected").val()==="380"&&u("380",t),$("#CountryId :selected").val()==="187"&&u("187",n)):$("#StateContainer").hide();ecom.formControls.customSelects.customise("#CountryId")},f=function(){var n=$("#EmailType").val();n==="Business email"?($("#emi-personal-disclosure").hide(),$("#emi-business-disclosure").show(),$("#AcceptedMarketing").val("false")):n==="Personal email"?($("#emi-personal-disclosure").show(),$("#emi-business-disclosure").hide()):($("#emi-personal-disclosure").hide(),$("#emi-business-disclosure").hide())},l=function(){$("#EmailType").selectmenu({change:function(){$("#EmailType").selectmenu();f();$(this).valid()},select:function(){$("#EmailType").selectmenu();ecom.formControls.onCountryChange(canadaStateList,uSStateList);$("#EmailType").selectmenu("refresh");$("#EmailType-button").blur()}})},a=function(n,t,i){n!=null&&(t==null||t==="")?($("html, body").animate({scrollTop:$("#EmailType").offset().top+500},800),$("#PurchasingUserForm").submit()):i&&($("html, body").animate({scrollTop:$("#PostalCode").offset().top+50},800),$("#PurchasingUserForm").submit())},e=function(t){return t!=null&&t!==""&&n!=null&&n.length>0?$.inArray(t,n)>-1:!1},o=function(i){return i!=null&&i!==""&&t!=null&&t.length>0&&n!=null&&n.length>0?e(i)||$.inArray(i,t)>-1:!1},v=function(){$('.emi-custom-checkbox[for="AcceptedTandC"]').remove()},y=function(){var n=$('.emi-button-primary[value="creditcard"]');n.attr("disabled","disabled")},r=function(n){var t=$('.emi-button-primary[value="creditcard"]');t.length===1&&(n.toLowerCase()==="false"&&t.attr("disabled","disabled"),n.toLowerCase()==="true"&&t.attr("disabled",!1))},p=function(){var n=$('.emi-button-secondary[value="invoice"]');n.length===1&&(n.addClass("is-disabled"),n.attr("disabled","disabled"))},w=function(n,t,i){o(n)&&(r("false"),p(),v());parseFloat(t)>0&&i.toLowerCase()==="false"&&r("false")},s=function(n,t){var i=$(".emi-warning"),r;i!=null&&i.length>0&&(t?(r='<div class="row"><div class="field-validation-error"><div id="emi-blocked-warning">'+n+"<\/div><\/div><\/div><\/div>",i.html(r)):i.html(n))},b=function(n,t){var i="",r;o(n)?(r="",e(n)&&(r="in US$ "),i="Online transactions "+r+"to clients in "+t+" cannot be processed automatically. Please contact us by clicking the chat function or send an email to discuss this transaction.",s(i,!0)):s(i,!1)},k=function(){var n=$(".emi-custom-checkbox input[type=checkbox]");n.each(function(){$(this).is(":checked")&&$(this).parent().addClass("is-checked")});n.change(function(){$(this).parent().toggleClass("is-checked")})},d=function(){var n=$(".emi-custom-radio input[type=radio]");n.each(function(){$(this).is(":checked")&&$(this).parent().addClass("is-checked")});n.change(function(){var t=$(this).attr("name");n.each(function(){var n=$(this);n.attr("name")==t&&n.parent().removeClass("is-checked")});$(this).parent().addClass("is-checked")})},g=function(){$("#EmailType").val("");$("#AcceptedMarketing").val("false");ecom.formControls.onEmailTypeChange();$("#EmailType").selectmenu("refresh").trigger("change");$("#EmailType").valid()},nt=function(){var n=function(){var n=$("select.emi-form-select");n.each(function(){var n=$(this),f,t,e,i,r,u,o;if($(this)[0].id!=="CountryId"&&$(this)[0].id!=="State"&&$(this)[0].id!=="EmailType"){for(f=n.children("option").length,n.css({visibility:"hidden"}),n.parent(".emi-custom-select-container").length||(n.wrap('<div class="emi-custom-select-container"><\/div>'),n.after('<div class="emi-custom-select"><\/div>')),t=n.next("div.emi-custom-select"),e=n.children("option:selected").text(),t.text(e),n.siblings("ul.emi-custom-select-options").remove(),i=$("<ul />",{"class":"emi-custom-select-options"}).insertAfter(t),r=0;r<f;r++)$("<li />",{text:n.children("option").eq(r).text(),rel:n.children("option").eq(r).val()}).appendTo(i);n.val()==""?t.addClass("has-placeholder"):t.removeClass("has-placeholder");t.off("click");t.click(function(n){n.stopPropagation();$(this).hasClass("is-active")?$(this).removeClass("is-active").next("ul.emi-custom-select-options").hide():($("ul.emi-custom-select-options").hide(),$(this).addClass("is-active").next("ul.emi-custom-select-options").show())});u=i.children("li");o=n.val();u.off("click");u.click(function(r){r.stopPropagation();var u=$(this).attr("rel"),f=$(this).text();n.val(u);t.text(f).removeClass("is-active");i.hide();u==""?t.addClass("has-placeholder"):t.removeClass("has-placeholder");o==u||(n.blur(),n.change())});$("html").click(function(){t.removeClass("is-active");i.hide()})}})};return{customise:n}}();return{customCheckboxToggle:k,customRadioButtonToggle:d,customSelects:nt,blockedWarningToggle:b,disablePaymentButtons:w,toggleCreditCardButton:r,disableCreditCardButton:y,onEmailTypeChange:f,onCountryChange:c,onEmailAddressChange:g,setEmailTypeEvent:l,scrollToInvalidItem:a,init:h}}()