'),$("#signup-popup .dimmer").click(joSignup.closeDialog)},apiInit:function(){var e=window.location.hostname;"local.jamieoliver.com"==e?joSignup.env="dev":"stage.jamieoliver.com"==e?joSignup.env="stage":joSignup.env="prod"},getApiEndpoint:function(){return window.location.host.match("local.jamieoliver.com")?"https://signup.jamieoliver.local":window.location.host.match("stage.jamieoliver.com")?"https://stage.signup.jamieoliver.com":"https://signup.jamieoliver.com"},autoPopup:function(){if(!joUser.checkLogin()){var e="jo-splash";if(!$.cookie(e)){joSignup.launchSignup();var o={path:"/",expires:30};$.cookie(e,1,o)}}},getCurrentSectionElement:function(){return $("#signup-popup section").eq(joSignup.currentSection-1)},launchDialog:function(e,o){return joSignup.isBusy?(console.log("joSignup is busy"),!1):(0==$("#signup-popup").length&&joSignup.init(),$("body").addClass("popup-open"),$("#signup-popup").fadeIn(joSignup.fadeSpeed),joSignup.busy(!0),void $.ajax({url:"/home/wp-content/themes/jamieoliver/_partials/signup/"+e+".php?n="+joSignup.version}).done(function(e){joSignup.busy(!1),$("#signup-popup .content").html(e),CookieControl.isAccepted("functionality")?($("#signup-social").removeClass("hidden"),$("#login-social").removeClass("hidden"),$("#signup-email-header").addClass("hidden")):($("#signup-social").addClass("hidden"),$("#login-social").addClass("hidden"),$("#signup-email-header").removeClass("hidden")),$("#signup-popup .signup-close").click(joSignup.closeDialog),$("#signup-popup .init-focus").first().focus(),o()}))},launchSignup:function(e){if(joUser.checkLogin())return void joProfile.redirectToProfile();$("form#signup-form").length>0&&$("form#signup-form").remove(),"undefined"!=typeof e&&$(e.target).data("referrer")&&joBlaize.setReferrer($(e.target).data("referrer"),!1),joSignup.currentSection=1;var o=function(){joSignup.setupFormListeners(),joSignup.getCurrentSectionElement().addClass("active"),joSignup.autoSelectCountry(),joSignup.jumpToSection(1),joSocialSignup.stateKey&&joSignup.signupWithSocial()};joSignup.launchDialog("signup",o)},closeDialog:function(){$("#signup-popup").fadeOut(joSignup.fadeSpeed,function(){$("#signup-popup .content").html("")}),$("body").removeClass("popup-open")},busy:function(e){joSignup.isBusy=e,e?$("#signup-popup").addClass("busy"):$("#signup-popup").removeClass("busy")},setupFormListeners:function(){$("#signup-popup .signup-steps a").click(function(e){joSignup.jumpToSection($(this).data("step"))}),joSocialSignup.addEventListeners(),$("#signup-popup form").submit(function(e){var o=joSignup.getCurrentSectionElement();return joSignup.validateForm(o)&&joSignup.submitForm(),!1}),$("#signup-form select").each(function(){$(this).styledSelect()})},autoSelectCountry:function(){if($("#geo-region").data("region")){var e=$("#geo-region").data("region").toUpperCase(),o=$("#signup-sel-country");o.val(e),o.change()}},validateForm:function(e){e.find(".has-error").removeClass("has-error"),e.find(".error").remove(),$(".form-error").removeClass("active");var o=0;return e.find("[required]").each(function(){if(!$(this).val()){$(this).prop("tagName").toLowerCase();if($(this).data("req-msg"))var e=$(this).data("req-msg");else var e="Please enter a value";joSignup.fieldError($(this),e),o++}}),e.find('input[type="password"]').each(function(){""!=$(this).val()&&$(this).val().length<6&&(joSignup.fieldError($(this),"Minimum length is 6"),o++)}),e.find('[type="email"]').each(function(){var e=$(this).val();""==e||/^[a-z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i.test(e)||(joSignup.fieldError($(this),"Please enter a valid email address"),o++)}),e.find("input.phone").each(function(){""!=$(this).val()&&$(this).val().length<10?(joSignup.fieldError($(this),"Phone number must be at least 10 digits"),o++):""==$(this).val()||/^([0-9 ]*)$/.test($(this).val())||(joSignup.fieldError($(this),"Phone number can only contain numbers"),o++)}),e.find(".form-group.required").each(function(){if(console.log($(this),e.find("input:checked").length),0==e.find("input:checked").length){if($(this).data("req-msg"))var i=$(this).data("req-msg");else var i="Please select a value";joSignup.fieldError($(this),i),o++}}),!(o>0)},fieldError:function(e,o){var i=e.closest(".signup-input, .form-input");i.addClass("has-error"),i.append(''+o+""),console.error("Error:",o)},submitForm:function(){if(joSignup.isBusy)return console.log("joSignup is busy"),!1;var e=joSignup.getCurrentSectionElement().find("input, select, textarea");if(0==e.length)return void joSignup.nextSection();var o=joSignup.compileFormData(e);if($("#signup-txt-email").length){$("#signup-txt-email").val()}var i=function(){1==joSignup.currentSection&&joSignup.recordSignup(o["opt-in-core"],e),joSocialSignup.stateKey=!1,3==joSignup.currentSection&&joLogin.refreshAvatar(),joRedeye.eventRegistrationStepSaved(joSignup.currentSection,o),joSignup.nextSection()},n=function(e){console.log("request",e.status),409==e.status?joSignup.formError(e,'A user already exists with this email address, please Log In'):joSocialSignup.stateKey&&400==e.status?joSignup.formError(e,"Sorry, unable to create your account. PLease make sure you have allowed Facebook to give us your email address."):joSignup.formError(e,"Sorry, there was a problem creating your account.")},t=function(){joSignup.busy(!1)};joSignup.busy(!0),1==joSignup.currentSection&&joSocialSignup.stateKey?joBlaize.registerUserSocial(joSocialSignup.stateKey,o,i,n,t):1==joSignup.currentSection?joBlaize.registerUser($("#signup-txt-email").val(),$("#signup-txt-password").val(),o,i,n,t):joBlaize.updateUser(o,i,n,t)},recordSignup:function(e,o){var i=function(i){joSignup.subscribe("/record/signup",i,o,"header-nav",e)};joBlaize.fetchUserEmail(i)},compileFormData:function(e){var o={};return e.each(function(){if($(this).data("key")){var e=$(this).data("key");"checkbox"==$(this).attr("type")&&"[]"==e.substr(-2)?(e=e.substr(0,e.length-2),o[e]||(o[e]=[]),$(this).prop("checked")&&o[e].push($(this).val())):"radio"==$(this).attr("type")?o[e]=$('input[data-key="'+e+'"]:checked').val():"checkbox"==$(this).attr("type")?o[e]=$(this).prop("checked"):""!=$(this).val()&&(o[e]=$(this).val())}}),o},formError:function(e,o){if(e&&e.responseJSON&&e.responseJSON.error)var i=e.responseJSON.error;else if("timeout"==e.statusText)var i="Sorry, we seem to be unable to process your request at the moment.";else var i=o;$(".form-error").html(i),$(".form-error").addClass("active"),joSignup.scrollToPopupTop(),console.error("Error",i)},jumpToSection:function(e){joSignup.currentSection=e,$("#signup-popup section").removeClass("active"),joSignup.getCurrentSectionElement().addClass("active"),joSignup.scrollToPopupTop();var o=["","/signup_dialog/start","/signup_dialog/thanks","/signup_dialog/about","/signup_dialog/skill","/signup_dialog/food","/signup_dialog/interests","/signup_dialog/done"];dataLayer.push({event:"signup-dialog-page",eventLabel:o[e]})},scrollToPopupTop:function(){$(".signup-container").animate({scrollTop:0},300)},nextSection:function(){joSignup.jumpToSection(joSignup.currentSection+1)},loadUserDetails:function(){joSignup.busy(!0);var e=function(e){joSignup.populateForm(e)},o=function(e){joSignup.formError(e,"Error")},i=function(e,o,i){joSignup.busy(!1)};joBlaize.fetchProfile(e,o,i)},populateForm:function(e){for(var o in e){var i=e[o];if($.isArray(i))for(var n in i)joSignup.populateInput(o,i[n]);else joSignup.populateInput(o,i)}},populateInput:function(e,o){var i="string"==typeof o?o.replace(/"/g,"""):o,n=$('#signup-form [data-key="'+e+'"], #signup-form [data-key="'+e+'[]"]');if(n.length>1)return n.each(function(){$(this).val()==i&&($(this).prop("checked",!0),$(this).closest("label").addClass("checked"))}),!0;var n=$('#signup-form [type="checkbox"][data-key="'+e+'"]');if(n.length>0)return o===!0?(n.prop("checked",!0),n.first().closest("label").addClass("checked")):(n.prop("checked",!1),n.first().closest("label").removeClass("checked")),!0;var n=$('#signup-form select[data-key="'+e+'"]');if(n.length>0)return n.val(o),n.change(),!0;var n=$('#signup-form [type="text"][data-key="'+e+'"], #signup-form [type="email"][data-key="'+e+'"], #signup-form [type="hidden"][data-key="'+e+'"]');return n.length>0?(n.val(o),n.change(),!0):(console.log("Element not found: "+e),!1)},signupWithSocial:function(){$("#signup-form .social-signup-remove").remove(),$("#signup-form .social-signup-add").removeClass("hidden")},subscribe:function(e,o,i,n,t,a){var r=i.serializeArray(),s=joSignup.getApiEndpoint(),c={form:n,formdata:r,optin:t,email:o};$.ajax({url:s+e,method:"POST",data:c}).done(function(e){console.log("Subscription logged",e),a&&a(e)})},loginPrompt:function(e,o,i){joSignup.loginPromptClose();var n='
";var t=$(n);t.find("a.login").click(joLogin.launchLogin),t.find("a.signup").click(joSignup.launchSignup),t.find("a.close").click(joSignup.loginPromptClose),e.append(t),joSignup.$promptOpen=t},loginPromptClose:function(){joSignup.$promptOpen&&(joSignup.$promptOpen.remove(),joSignup.$promptOpen=!1)}},joProfile={email:!1,trackingId:!1,init:function(){window.location.hash&&"#signup-account-cancelled"==window.location.hash&&joProfile.addCancellationBanner(),0!=$("#signup-form.profile-page").length&&(joSignup.setupFormListeners(),$("#signup-form").submit(function(){return joSignup.validateForm($("#signup-form"))?joProfile.submitForm():joProfile.scrollToFirstError(),!1}),joUser.checkLogin()?(joProfile.loadUserDetails(),joProfile.loadMealplans(),joProfile.loadUserEmail()):($("#profile-loading").addClass("hidden"),$("#profile-login").removeClass("hidden")))},loadUserEmail:function(){var e=function(e){joProfile.email=e,joProfile.trackingId=joBlaize.trackingId;var o=$("#signup-txt-email");o.val(e),o.prop("disabled",!0)},o=function(){console.log("Error loading email")};joBlaize.fetchUserEmail(e,o)},loadUserDetails:function(e){var o=function(o){$("#signup-form").removeClass("hidden"),joSignup.populateForm(o),joProfile.addListeners(),e&&e()},i=function(e){joSignup.formError(e),joUser.logout(!1)},n=function(){$("#profile-loading").addClass("hidden")};joBlaize.fetchProfile(o,i,n);var t=function(e,o){if(o)for(var i in o)joSignup.populateInput(e,o[i])};for(var a in joBlaize.extendedProfileFields)joBlaize.fetchExtendedProfile(joBlaize.extendedProfileFields[a],t,i,!1)},loadMealplans:function(){var e=["mealplan","5dvc"],o=function(e,o){if(o)if("mealplan"==e)for(var i in o){var n=$('[data-planpromokey="'+i+'"]');n.find(".caption").html(n.data("ctagoto"))}else if("5dvc"==e){var t='
';t+='",t+="
",$(".mealplan-tiles").append(t)}};for(var i in e)joBlaize.fetchExtendedProfile(e[i],o,!1,!1)},submitForm:function(){if(joSignup.isBusy)return console.log("joSignup is busy"),!1;var e=$("#signup-form").find("input, select, textarea"),o=joSignup.compileFormData(e);joSignup.busy(!0),$("#signup-save-button").addClass("busy");var i=function(){joLogin.headerBannerMessage("Profile saved"),joLogin.refreshAvatar(),joRedeye.eventProfileUpdate(o),setTimeout(function(){$("#signup-header-banner-message").fadeOut(300)},5e3)},n=function(e){joSignup.formError(e,"Error")},t=function(){joSignup.busy(!1),$("#signup-save-button").removeClass("busy")};joBlaize.updateUser(o,i,n,t)},cancelAccountConfirm:function(){if(joSignup.isBusy)return console.log("joSignup is busy"),!1;joSignup.busy(!0),$("button.cancel-account-confirm").addClass("busy");var e=function(){joUser.logout(function(){window.location="/#signup-account-cancelled"})},o=function(e){joSignup.formError(e,"Error"),$("button.cancel-account-confirm").removeClass("busy")},i=function(){joSignup.busy(!1)};joSignup.subscribe("/record/delete",joProfile.email,$("#signup-form"),"profile",!1),joBlaize.cancelAccount(e,o,i)},goToSubscriptions:function(){if(0==joProfile.email||0==joProfile.trackingId)return!1;var e="/signup/unsubscribe/#"+joProfile.email+"/"+joProfile.trackingId;window.location=e},moreOptionsExpand:function(e){$("#signup-more-options-buttons").removeClass("expand"),$("#signup-more-options-responses").addClass("expand"),$("#signup-more-options-responses .section").hide(),$("#signup-more-options-responses .section."+e).show()},moreOptionsCollapse:function(){$("#signup-more-options-buttons").addClass("expand"),$("#signup-more-options-responses").removeClass("expand")},addListeners:function(){$("#profile-page button.reset-password").click(function(){joPasswordReset.launchForgottenPassword()}),$("#profile-page button.cancel-account-confirm").click(function(){joProfile.cancelAccountConfirm()}),$("#profile-page button.cancel-account").click(function(){joProfile.moreOptionsExpand("cancel")}),$("#profile-page button.collapse-more-options").click(function(){joProfile.moreOptionsCollapse()}),$("#profile-page button.unsubscribe").click(function(){joProfile.goToSubscriptions()})},jumpToSection:function(e){$("html, body").animate({scrollTop:$("section."+e).offset().top},600)},scrollToFirstError:function(){$("html, body").animate({scrollTop:$(".has-error").first().offset().top},600)},addCancellationBanner:function(){joLogin.headerBannerMessage("Your account has been deleted."),window.location.hash=""},redirectToProfile:function(){window.location="/signup/profile/"}},joPasswordReset={init:function(){$("form#password-reset-form").submit(joPasswordReset.passwordResetFormSubmit)},launchForgottenPassword:function(){joSignup.launchDialog("forgotten-password",function(){$("#signup-popup form").submit(joPasswordReset.forgottenPasswordFormSubmit)})},forgottenPasswordFormSubmit:function(){if(!joSignup.validateForm($("#forgotten-password-form")))return!1;joSignup.busy(!0),$("#forgotten-password-success span.email-address").html($("#forgotten-txt-email").val());var e=function(){$.cookie("forgotten-password-redirect",window.location.href,{path:"/"}),$("#forgotten-password-form").addClass("hidden"),$("#forgotten-password-success").removeClass("hidden")},o=function(e){joSignup.formError(e,"Error")},i=function(){joSignup.busy(!1)};return joBlaize.forgottenPassword($("#forgotten-txt-email").val(),e,o,i),!1},passwordResetFormSubmit:function(){if(!joSignup.validateForm($("#password-reset-form")))return!1;var e=$("#txt-password1").val(),o=$("#txt-password2").val();if(e!=o)return joSignup.formError(!1,"Passwords do not match"),!1;var i=joPasswordReset.getResetStateId();if(!i)return joSignup.formError(!1,"Sorry, the password reset link seems to be incorrect. Please check your email and try again."),!1;$("#password-reset-form").addClass("hidden"),$("#password-reset-busy").removeClass("hidden");var n=function(){$("#password-reset-success").removeClass("hidden")},t=function(e){joSignup.formError(e,'There was a problem resetting your password. Please try again or request a new password reset link.'),$("#password-reset-form").removeClass("hidden")},a=function(){$("#password-reset-busy").addClass("hidden")};return joBlaize.passwordReset(i,e,n,t,a),!1},getResetStateId:function(){if(window.location.hash){var e=window.location.hash.replace("#","");return e}return!1}},joSocialSignup={intent:"signup",stateKey:!1,addEventListeners:function(){$(".js-facebook-signup").click(joSocialSignup.loginFacebook),$(".js-google-signup").click(joSocialSignup.loginGoogle)},loginFacebook:function(){return 1==navigator.doNotTrack?(joSignup.formError(!1,'Unfortunately you cannot use Sign In with Facebook in private browsing mode or when "Do Not Track" is selected in your browser.'),!1):void joSocialSignup.loginSocial("facebook",$(this).data("intent"))},loginGoogle:function(){joSocialSignup.loginSocial("google",$(this).data("intent"))},loginSocial:function(e,o){joSignup.busy(!0),joSocialSignup.intent=o,void 0==joSocialSignup.intent&&(joSocialSignup.intent="signup");var i=function(e,o,i){if(console.log("register success",e+","+o+","+i),console.log("intent",joSocialSignup.intent),joSocialSignup.stateKey=i,"signup"==joSocialSignup.intent)joSignup.busy(!1),joSignup.signupWithSocial();else if("login"==joSocialSignup.intent)joSignup.busy(!1),joSignup.launchSignup();else{var n=new CustomEvent("socialRegister");window.dispatchEvent(n)}},n=function(e,o,i){if(console.log("login success",e+","+o+","+i),console.log("intent",joSocialSignup.intent),joLogin.renderMenu(!0,!0),"login"==joSocialSignup.intent)joSignup.busy(!1),joSignup.closeDialog(),joLogin.checkLoginOnRestrictedPage(),joLogin.dispatchLoggedInEvent();else if("signup"==joSocialSignup.intent)joSignup.busy(!1),joSignup.loadUserDetails(),joSignup.jumpToSection(2);else{var n=new CustomEvent("socialLogin");window.dispatchEvent(n)}},t=function(){joSignup.formError(!1,"Sorry, there was a problem contacting "+e)},a=function(){joSignup.busy(!1)};joBlaize.launchSocialSignin(e,i,n,t,a)}},joUnsubscribe={wrapperId:"#unsubscribe-page",busy:!1,email:!1,trackingId:!1,subscribed:!0,campaignRef:"",init:function(){if(0!=$(joUnsubscribe.wrapperId).length){if(joUnsubscribe.setBusy(!0),joUnsubscribe.getCampaignRef(),joUnsubscribe.parseUrl(),!joUnsubscribe.email||!joUnsubscribe.trackingId)return void joUnsubscribe.error("Sorry, the unsubscribe link seems to be invalid.",!0);joUnsubscribe.loadSubscriptions(),$("#unsubscribe-page").css("min-height",$(window).height()),$(joUnsubscribe.wrapperId+" #btn-subscribe").click(joUnsubscribe.submitSubscribe),$(joUnsubscribe.wrapperId+" #btn-unsubscribe").click(joUnsubscribe.submitUnsubscribe)}},renderForm:function(){$(joUnsubscribe.wrapperId+" .active").removeClass("active"),$(joUnsubscribe.wrapperId+" button").prop("disabled",!0),$(joUnsubscribe.wrapperId+" .checkbox input").prop("checked",!1),$(joUnsubscribe.wrapperId+" .checkbox input").bind("change",function(){var e=$(this).prop("checked");$(joUnsubscribe.wrapperId+" button").prop("disabled",!e)}),joUnsubscribe.subscribed?$(joUnsubscribe.wrapperId+" .unsubscribe-form").addClass("active"):$(joUnsubscribe.wrapperId+" .subscribe-form").addClass("active"),joUnsubscribe.setBusy(!1)},setBusy:function(e){joUnsubscribe.busy=e,$(joUnsubscribe.wrapperId).toggleClass("busy",e)},error:function(e,o){o&&(e+=" Please email unsubscribe@jamieoliver.com and we will unsubscribe you manually."),$(joUnsubscribe.wrapperId+" .active").removeClass("active"),$(joUnsubscribe.wrapperId+" .error-msg").addClass("active"),$(joUnsubscribe.wrapperId+" .error-msg p").html(e)},success:function(){$(joUnsubscribe.wrapperId+" .active").removeClass("active"),$(joUnsubscribe.wrapperId+" .success").addClass("active")},submitSubscribe:function(){joUnsubscribe.submit(!0)},submitUnsubscribe:function(){joUnsubscribe.submit(!1),joUnsubscribe.trackUnsubscribe()},submit:function(e){if(joUnsubscribe.busy)return!1;joUnsubscribe.setBusy(!0);var o={optIn:e,campaignRef:joUnsubscribe.campaignRef},i=$.ajax({url:joSignup.getApiEndpoint()+"/subscriptions/"+joUnsubscribe.email+"/"+joUnsubscribe.trackingId,dataType:"JSON",method:"POST",data:o});i.done(function(o){joUnsubscribe.success();var i={};i.email_address=joUnsubscribe.email,i.form=e?"subscription-centre":"subscription-centre-unsubscribe";var n=e?$(joUnsubscribe.wrapperId+" .subscribe-form").closest("form"):$(joUnsubscribe.wrapperId+" .unsubscribe-form").closest("form");joSignup.subscribe("/record/optin",i.email_address,n,i.form,e),
joRedeye.eventSubscriptionSubmit(joUnsubscribe.email,e)}),i.fail(function(e){console.log(e),joUnsubscribe.error("Sorry, there was a problem updating your subscriptions",!0)}),i.always(function(){joUnsubscribe.setBusy(!1)})},loadSubscriptions:function(){var e=$.ajax({url:joSignup.getApiEndpoint()+"/subscriptions/"+joUnsubscribe.email+"/"+joUnsubscribe.trackingId,dataType:"JSON",method:"GET",cache:!1});e.done(function(e){1==e.subscribed?joUnsubscribe.subscribed=!0:joUnsubscribe.subscribed=!1,joUnsubscribe.renderForm()}),e.fail(function(e){joUnsubscribe.error("Sorry, there was a problem loading your subscriptions",!0),joUnsubscribe.setBusy(!1)})},parseUrl:function(){if(window.location.hash){var e=window.location.hash.replace("#","");e=e.replace(/\?.*/,"");var o=e.split("/");return 2==o.length&&(joUnsubscribe.email=o[0],joUnsubscribe.trackingId=o[1],!0)}return!1},getCampaignRef:function(){var e=jo.getUrlParameter("r3mailref"),o=jo.getUrlParameter("r3serialref");e&&o&&(joUnsubscribe.campaignRef=e+","+o)},trackUnsubscribe:function(){var e=jo.getUrlParameter("utm_campaign");return!!e&&void jo.track("signup/unsubscribe/"+e,"Unsubscribe event")}};$.fn.styledSelect=function(){$(this).parent().hasClass("select-wrapper")||$(this).wrap('