if(typeof authentication==undefined||!authentication)var authentication={};authentication.welcome={};authentication.welcome=function(){var r,u,f,h,t,i,c,l,a,n,e,o,v,s=!1,y=function(n){return/^([a-z\d!#$%&'*+\-\/=?^_`{|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+(\.[a-z\d!#$%&'*+\-\/=?^_`{|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+)*|"((([ \t]*\r\n)?[ \t]+)?([\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|\\[\x01-\x09\x0b\x0c\x0d-\x7f\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))*(([ \t]*\r\n)?[ \t]+)?")@(([a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|[a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF][a-z\d\-._~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]*[a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])\.)+([a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|[a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF][a-z\d\-._~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]*[a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])\.?$/i.test(n)},p=function(n){return/^([0-9]{3})([- /.]?)([0-9]{2,3})([- /.]?)([0-9]{2,6})([- /.]?)([0-9]{0,6})/.test(n)},w=function(n){if(r.show(),u.hide(),f.val("True"),n.ShowCountryCode&&(h.show(),i.text("Please select your country code."),t.show(),$(".select2-post-page-load-select").select2({templateResult:authentication.global.select2CustomTemplateRender,templateSelection:authentication.global.select2CustomTemplateRender})),n.ShowUseApplicationLogin)switch(n.ApplicationLoginToShow){case"Wellbeing360":i.text("Welcome back. It looks like you've used a Vitality Works service in the past. Please use your login details here, or click 'Forgot your password?'");t.show();break;case"VitalityHub":i.text("Please log in with your VitalityHub login.");t.show()}},k=function(n){n.Success&&(s=n.CanLogin,n.CanLogin&&w(n))},d=function(n){n.Success&&(s=n.CanLogin,n.CanLogin?w(n):($("#Password").val(""),e.submit()))},b=function(n,t){$.ajax({url:"/Authentication/Authentication/ProcessWelcome",data:{__RequestVerificationToken:a,key:n},type:"POST",success:function(n){t(n)},error:function(){l.text("An unexpected error occured, please contact us for support.");c.show()}})},g=function(){r=$(".login-control-wrapper");u=$(".welcome-control-wrapper");f=$("#ShowLoginControl");h=$("#country-code-wrapper");t=$("#display-message-wrapper");i=$("#display-message");c=$("#error-message-wrapper");l=$("#error-message");e=$("form");a=$('input[name="__RequestVerificationToken"]',e).val();n=$("#UserName");o=$("#remember-me-link");v=$("#remember-me-display");$("#Action").val("NoAction");f.val()==="True"&&(r.show(),u.hide());n.on("keyup keypress",function(){var n=$(this).val();y(n)||p(n)?b(n,k):$("#password-wrapper").hide()});$("#get-started").on("click",function(){if(!s){var t=n.val();return(y(t)||p(t))&&b(t,d),!1}return!0});$("#login-link").on("click",function(){return r.show(),u.hide(),f.val("True"),n.off("keyup keypress"),i.text(""),t.hide(),n.val(""),!1});o.on("click",function(){o.hide();v.show()});$("#forgot-password").on("click",function(){if(n.val()!=="")$("#Action").val("ForgotPassword"),e.submit();else return!0;return!1})};return{init:function(){return g()}}}();$(document).ready(function(){authentication.welcome.init()})