(function(n){n.Models.Profile.NewPasswordModel=function(n,t){var i=this;return i.username=ko.observable(n),i.otp=ko.observable().extend({required:!0}),i.newPassword=ko.observable().extend({notEqual:{params:i.username,message:_.wrap("ValidationErrors.PasswordCannotEqualUsername",ko.i18n)}}),i.newPasswordRepeat=ko.observable().extend({equal:{params:i.newPassword,message:_.wrap("ValidationErrors.RepeatedPasswordsMustEqual",ko.i18n)}}),i.data=ko.validatedObservable({loginId:t,otp:i.otp,newPassword:i.newPassword,newPasswordRepeat:i.newPasswordRepeat}),i}})(App),function(n,t,i,r){"use strict";n.loginViewModel=function(u){var f=this,e=u.loginId,a=null,s=function(n){return n.status!==400&&n.status!==401&&n.status!==503?!1:(f.currentMode()||f.currentMode(f.mode.login),f.currentState(f.state.error),f.error(n.status===503?ko.i18n("Mobile.ErrorHeaders.503"):(n.statusText||"").replace(/^"|"$/g,"")),!0)},l=function(n){return $("<a/>").attr("href",$("<a/>").attr("href",n)[0].href)[0].hostname},c=function(n,t){var i=window,r=n;for(t&&(r+=/\?/.test(r)?(/\?./.test(r)?"&":"")+t:"?"+t),l(location.href)!==l(r)&&(r="/");i.parent&&i.parent!==i;)i=i.parent;i.location.replace&&u.returnUrl?i.location.replace(r):i.location.href=r},h=function(t){t.loginId&&(e=t.loginId);switch(t.status){case"PwdChange":f.newPasswordModel(new n.Models.Profile.NewPasswordModel(t.username,e));f.currentState(f.state.init);f.currentMode(f.mode.newPassword);break;case"PwdOnceAlways":f.currentState(f.state.init);f.currentMode(f.mode.otp);break;case"PwdOnceAdmin":f.currentState(f.state.init);f.currentMode(f.mode.otpSelection);a=t;break;case"Success":r.reset();c(t.returnUrl||u.returnUrl)}},v=function(){f.usernameOrEmail(null);f.password(null);f.usernameOrEmail.isModified(!1);f.password.isModified(!1)},o;return f.mode={login:"login",anonymousLogin:"anonymousLogin",newPassword:"newPassword",otp:"otp",otpSelection:"otpSelection"},f.state={init:"init",error:"error",progress:"progress"},f.usernameOrEmail=ko.observable().extend({required:!0}),f.password=ko.observable().extend({required:!0}),f.newPasswordModel=ko.observable(),f.otp=ko.observable(),f.error=ko.observable(null),f.currentMode=ko.observable(null),f.currentState=ko.observable(f.init),f.currentMode.subscribe(v),f.loginModelState=ko.validatedObservable({username:f.usernameOrEmail,password:f.password}),f.send=function(){switch(f.currentMode()){case f.mode.login:f.loginModelState.whenValid(function(){f.currentState(f.state.progress);i.ajaxPost("account/login",f.loginModelState(),null,h,s)});break;case f.mode.anonymousLogin:f.currentState(f.state.progress);c(u.returnUrl,"anonymous=true");break;case f.mode.newPassword:f.newPasswordModel().data.whenValid(function(){f.currentState(f.state.progress);i.ajaxPost("account/changePassword",f.newPasswordModel().data(),null,h,s)});break;case f.mode.otp:f.currentState(f.state.progress);i.ajaxPost("account/otpLogin",{loginId:e,otp:f.otp()},null,h,s);break;case f.mode.otpSelection:f.currentState(f.state.progress);t.ajaxPost("account/issueOtp",{loginId:e},App.apiLanguage,function(){f.currentState(f.state.init);f.currentMode(f.mode.otp)},s)}},f.init=function(){e?i.ajaxPost("account/otpLogin",{loginId:e},null,h,s):f.currentMode(f.mode.login)},f.initAnonymous=function(){f.currentMode(f.mode.anonymousLogin)},f.continue=function(){e&&c(u.returnUrl,"loginId="+e)},o={},o[f.mode.login]="Account.Login.LoginHeader",o[f.mode.newPassword]="Account.Profile.NewPassword",o[f.mode.otp]="Account.Login.LoginHeader",o[f.mode.otpSelection]="Account.Login.LoginHeader",f.header=ko.pureComputed(function(){return f.currentMode()?o[f.currentMode()]:""}),f}}(App,App.apiClient,App.sasClient,App.OrderSession),function(n,t,i){n.forgottenPasswordViewModel=function(n,r){var u=this,f=r||{},e;return u.status={success:"success",error:"error",loading:"loading"},u.username=ko.observable(f.userId).extend({required:{onlyIf:_.constant(n=="username")}}),u.email=ko.observable().extend({email:!0,required:{onlyIf:_.constant(n=="email")}}),u.currentStatus=ko.observable(null),u.errorText=ko.observable(""),e=ko.validatedObservable({username:u.username,email:u.email}),u.send=function(){if(!!f.loginId){location.href=i.buildUrl("login",null,{loginId:f.loginId});return}var n=function(n){u.currentStatus(u.status.error);u.errorText(n.responseJSON||ko.i18n("Account.ForgottenPasswordError"))};e.whenValid(function(){u.currentStatus(u.status.loading);t.ajaxPost("account/remindpassword",e,App.apiLanguage,_.wrap(u.status.success,u.currentStatus),n)})},u}}(App,App.apiClient,App.sasClient)