storefront.stayInLoop=function(){var n={load:function(t,i){$.post("/Shared/GetSubscriptionPanel",{context:t,idElement:i,keywordsIds:storefront.keywordsIds},function(data){data&&data.trim().length>0&&($("#js-stay-in-loop-wrapper").append(data).fadeIn("slow"),eval($("#js-stay-in-loop-binding").text()),n.attachEvents(),n.setAutocompleteCategories(),window.dispatchEvent(new window.CustomEvent("storefront.stayInLoop.modal:ready")))})},addStayInLoopCategory:function(t,i){if(t+="",!n.isCategoryAlreadyInList(t)){var r=$("#js-stay-in-loop-template").text().replace(/\${id}/g,t).replace(/\${name}/g,i);$("#js-stay-in-loop-category-list").append(r)}},init:function(){window.dispatchEvent(new window.CustomEvent("storefront.stayInLoop:ready"))},attachEvents:function(){$(".js-stay-in-loop-category .js-stay-in-loop-category-close").on("click",function(n){$(this).closest(".js-stay-in-loop-category").remove();n.preventDefault()});$("#js-stay-in-loop-collapsible-trigger").on("click",function(n){n.preventDefault();$(this).hasClass("collapsed")?$("#js-stay-in-loop-collapsible-trigger").html('open <i class="fa fa-chevron-down"><\/i>'):$("#js-stay-in-loop-collapsible-trigger").html('close <i class="fa fa-chevron-up"><\/i>')});$.validator.addMethod("hasCategoriesSelected",function(){return n.getCurrentCategories().length>0},"Please, type your interests");$("#js-stay-in-loop-form").validate({errorPlacement:validation.errorPlacement,success:validation.success,highlight:validation.highlight,unhighlight:validation.unhighlight,onkeyup:validation.onkeyup,rules:{email:{required:!0,email:!0},searchCategories:{hasCategoriesSelected:!0}},ignore:[],onkeyup:!1,onfocusout:!1,onblur:!1,submitHandler:storefront.stayInLoop.postInterests})},setAutocompleteCategories:function(){var t=$("#js-stay-in-loop-autocomplete-box").autocomplete({source:"/Shared/GetInterestCategories",messages:{noResults:"",results:function(){return""}},minLength:2,select:function(t,i){return i.item&&n.addStayInLoopCategory(i.item.value,i.item.label),this.value="",!1},focus:function(n){n.preventDefault()}}).data("ui-autocomplete");t._resizeMenu=function(){var n=this.menu.element;n.outerWidth(this.element.outerWidth())}},getCurrentCategories:function(){return $(".js-stay-in-loop-category").map(function(){return $(this).attr("data-id-category")}).get()},isCategoryAlreadyInList:function(t){return n.getCurrentCategories().indexOf(t)>=0},postInterests:function(){$("#js-stay-in-loop-wrapper").overlayLoadingMask();$.ajax({url:"/Shared/SetSubscriptionsInterests",type:"POST",dataType:"json",data:JSON.stringify({categories:n.getCurrentCategories(),email:$("#js-stay-in-loop-email").val()}),contentType:"application/json; charset=utf-8",cache:!1,success:function(result){result.js&&eval(result.js);result.html&&(googleanalytics.saveTag("Interactions","Subscribe Interests Submit",window.location.href,0),$("#js-stay-in-loop-wrapper").html($(result.html).fadeIn("slow")))}})}};return n}();storefront.stayInLoop.modal=function(){var n={view:!1,firstExecution:!1,idButton:"",idForm:"",dataPost:"",attachNoModal:function(){$(n.idButton).off("click");$(n.idButton).click(function(t){t.preventDefault();n.sendSubscriptions()})},attachModal:function(){$(n.idButton).off("click");$(n.idButton).on("click",function(n){n.preventDefault()});$(n.idButton).loadView({view:modalViewer.urlViews.modalViewerSignIn,container:"#headerSite",identifyPreposition:"js-sim-",idmodal:"sign-in",titleComplete:"You're already registered. Please sign in to continue.",userEmail:"#js-stay-in-loop-email",callbackMethodjs:"subscriptionsInterests",successCallback:function(){window.dispatchEvent(new window.CustomEvent("storefront.stayInLoop.modal:view"))},preCallback:n.preCallback})},preCallback:function(){return $("#js-stay-in-loop-email").val()!=""&&n.checkEmailNotExists($("#js-stay-in-loop-email").val())?(n.sendSubscriptions(),!1):$(n.idForm).valid()},postRequestOauthProvider:function(){var n=storefront.stayInLoop.getCurrentCategories().join();$.ajax({url:"/Shared/AuthorizationToCallBack",data:{data:n},type:"POST"})},checkEmailNotExists:function(n){var t=!0;return $.ajax({url:"/Shared/CheckEmailExists",type:"POST",async:!1,data:{email:n},dataType:"json",success:function(n){t=n}}),t},sendSubscriptions:function(){googleanalytics.saveTag("Interactions","Subscribe Interests Click",window.location.href,0);$(n.idForm).submit()},sendSubscriptionOauthProvider:function(){googleanalytics.saveTag("Interactions","Subscribe Interests Click",window.location.href,0);$("#js-stay-in-loop-wrapper").overlayLoadingMask();$.ajax({url:"/Shared/SetSubscriptionsInterests",type:"POST",dataType:"json",data:JSON.stringify({categories:n.dataPost,email:user.email}),contentType:"application/json; charset=utf-8",cache:!1,success:function(result){result.js&&eval(result.js);result.html&&(googleanalytics.saveTag("Interactions","Subscribe Interests Submit",window.location.href,0),$("#js-stay-in-loop-wrapper").html($(result.html).fadeIn("slow")))}})},init:function(){user.idContactPerson>0&&n.view&&!n.firstExecution?(n.firstExecution=!0,n.attachNoModal(),n.sendSubscriptions()):user.idContactPerson>0&&n.dataPost&&xprtUtils.getURLParameters("callBackMethodJs").includes("subscriptionsInterests")?(n.firstExecution=!0,n.attachNoModal(),n.sendSubscriptionOauthProvider()):user.idContactPerson>0?n.attachNoModal():n.attachModal()}};return n}()