var SpaLoginModel=function(){const n={jobApplication:0,openApplication:1,companyAdverts:2,applicationLogin:3,companyLogin:4,masterCv:10};var t=new kendo.data.ObservableObject({model:{},queryParams:undefined,showRecoveryCode:"hidden",showSendRecoveryCodeButton:"",showPhoneRecovery:"hidden",advertId:"",headerModel:headerVm,heading:"",isActOnConfirmationEmailVisible:!1,isMetaFetched:!1,initVm:function(){var t=this._getProcess();t===n.jobApplication||t===n.applicationLogin?this._fetchAdvertMeta():t===n.openApplication||t===n.companyLogin?this._fetchCompanyMeta():t===n.companyAdverts&&this._fetchCompanyMeta();$(".start-next-button").on("touchstart",function(n){n.preventDefault();n.keyCode=13;n.trigger("keypress")})},showSignIn:function(){var t=this._getProcess();return t===n.jobApplication||t===n.openApplication?!1:!0},showLogo:function(){return this.get("model.CompanyLogoLibUrl")?!0:!1},_fetchCompanyLogo:function(){var n=this,t="/api/company/companylogo/"+n.get("companyId"),i=function(t){n.set("model.CompanyLogoLibUrl",t)};We.get("",t,i)},_fetchAdvertMeta:function(){var t=this.get("advertId"),n=n="/api/advertmeta/"+t+"?language="+We.getTwoLetterLanguageCode();this._fetchMeta(n)},_fetchCompanyMeta:function(){var n=this.get("companyId")||this.get("loginCompanyId");url="/api/company/companymeta/"+n+"?language="+We.getTwoLetterLanguageCode();this._fetchMeta(url)},_fetchMeta:function(n){var t=this,i=function(n){bgModel.set("selectedPhoto",n.CandidateBackground?"url("+n.CandidateBackground+")":"");bgModel.set("asAdvertId",t.advertId);bgModel.set("asCompanyId",n.companyId);bgModel.set("hasAs",n.HasAccessibilityStatement);t.set("model.TenantId",n.TenantId);t.set("model.AdvertId",t.advertId);t.set("model.Heading",n.Heading);t.set("model.CompanyLogoLibUrl",n.CompanyLogoLibUrl);t.set("model.DueDate",n.ApplyWithinDate);t.set("model.ApplyWithinDate",n.ApplyWithinDate);t.set("model.JobDescription",n.Heading);t.set("model.CompanyName",n.CompanyName);t.set("model.CompanyNameWithTitle",n.CompanyNameWithTitle);t.set("model.Languages",n.Languages);t.set("model.ShowLanguages",n.Languages&&n.Languages.length>1);t.set("model.UseOpenId",n.IsIdPortenEnabled);t.set("model.IsConfidential",n.IsConfidential)},r=function(){We.displayView("notfound-view")};We.get(null,n,i,r)},showApply:function(){var t=this._getProcess();return t===n.jobApplication||t===n.openApplication},phoneNumber:function(n){n&&this.set("model.Register.MobilePhone.FormattedNumber",n);var t=this.get("model.Register.MobilePhone.CountryCode"),n=this.get("model.Register.MobilePhone.Number");return We.formatPhone(t,n)},hidePassword:function(){return this.get("model.IsConfidential")||this.get("hidePasswordLogin")},email:function(n){return n!==undefined&&(n=$.trim(n),this.set("model.Start.Email",n),this.set("model.Register.Email",n),this.set("model.Login.Email",n),this.set("model.RecoveryByEmail.Email",n)),this.get("model.Start.Email")},fullRecoveyBySMS:function(){return this.get("model.RecoveryBySMS.CountryCode")+" "+this.get("model.RecoveryBySMS.Phone")},validInfoAlertVisible:!1,validPhoneInfoAlertVisible:!1,toggleValidEmailInfo:function(){this.set("validInfoAlertVisible",!this.get("validInfoAlertVisible"))},toggleValidPhoneInfo:function(){this.set("validPhoneInfoAlertVisible",!this.get("validPhoneInfoAlertVisible"))},showValidInfo:function(){this.set("validInfoAlertVisible",!0)},isEmailValid:!1,isEmailConfirmedByUser:!1,proceedWithApplication:function(){this.model.IsConfidential?We.displayView("apply-register-view"):We.displayView("apply-view")},restartProcess:function(){this.set("isEmailConfirmedByUser",!1)},start:function(){var t=this,i,r;t.set("model.Start.Process",this._getProcess());We.showLoader(!0);$("#Start_Email").blur();i=function(n){We.displayView("login-view");t.set("isEmailValid",!0);t.set("model.Start.IsPhoneNumberRequired",n.IsPhoneNumberRequired);t.set("model.Login.IsPhoneNumberRequired",n.IsPhoneNumberRequired);We.showLoader(!1)};r=function(i){var r,u;We.setFocus($("#Start_Email"));i.responseText.length>1&&(r=$.parseJSON(i.responseText));r&&r.ModelState?App.ModelState.showResponseErrors($("#start-form"),i):i.status==403?(console.log("forbidden"),t.set("isActOnConfirmationEmailVisible",!0)):(u=t._getProcess(),u===n.jobApplication||u===n.openApplication?t.set("isEmailConfirmedByUser",!0):We.displayView("register-view"));We.showLoader(!1)};We.post(kendo.stringify(this.get("model.Start")),"/api/account/validateemail","#start-form",i,r)},isEmailHintsVisible:!0,toggleEmailHints:function(){this.set("isEmailHintsVisible",!this.get("isEmailHintsVisible"))},login:function(){var n=this;We.post(kendo.stringify(this.model.Login),"/api/account/login","#login-form",function(t){t.StartImport?(weLoadingVm.set("loadingText",We.translate("Importing CV from previous system...")),We.post(kendo.stringify(n.model.Login),"/api/cv/migrate","#login-form",function(){n.redirectNextRoute()},function(n){console.log("Error: "+n)})):t.CodeRequired?router.replace("verifycode"):n.redirectNextRoute()})},verifyCode:function(){var n=this;We.post(kendo.stringify(this.model.Login),"/api/account/verifycode","#login-form",function(t){t.StartImport?(weLoadingVm.set("loadingText",We.translate("Importing CV from previous system...")),We.post(kendo.stringify(n.model.Login),"/api/cv/migrate","#login-form",function(){n.redirectNextRoute()},function(n){console.log("Error: "+n)})):n.redirectNextRoute()})},redirectNextRoute:function(){$("#login-form").submit(function(n){n.preventDefault()});var t=We.addLanguage("/Home"),i=this._getProcess();i===n.jobApplication||i===n.openApplication?(t=We.addLanguage("/cv?"+$.param(this.get("queryParams").toJSON())+"#personalapply"),window.location.replace(t)):(this.get("returnUrl")&&this.get("returnUrl").match(/^\/(?!\/)/)&&(t=this.get("returnUrl")),window.location.replace(t))},forgotPass:function(){if(We.validate($("#forgot-form"))){var n="/api/account/passwordrecoverybyemail";this.get("returnUrl")&&(n="/api/account/passwordrecoverybyemail?returnUrl="+this.get("returnUrl"));We.post(kendo.stringify(this.model.RecoveryByEmail),n,"#forgot-form",function(){We.displayView("sentmail-view")});We.setFocus($("#RecoveryByEmail_Email"))}else console.log("Reset form is NOT valid!")},sendRecoveryCode:function(){We.validate($("#forgot-form-phone"))?(console.log("Reset form is valid, sending a recovery code to phone!"),We.post(kendo.stringify(this.model.RecoveryBySMS),"/api/account/passwordrecoverybysms","#forgot-form-phone",function(n){console.log("Recovery code sent successfully!");console.log(n);t.set("showRecoveryCode","");t.set("showSendRecoveryCodeButton","hidden")})):console.log("Reset form is NOT valid!")},validateRecoveryCode:function(){We.validate($("#forgot-form-phone"))?(console.log(this.model.RecoveryBySMS.toJSON()),alert("Cowabunga! - We have NOT come this far, but when we have you will be redirected to the password reset form as long as your coed is right.")):console.log("forgot is NOT valid!")},applyRegister:function(){We.post(kendo.stringify(this.model.Register),"/api/account/apply-register","#register-form",function(){We.displayView("login-view")})},register:function(){var n=this;We.post(kendo.stringify(this.model.Register),"/api/account/register","#register-form",function(){var t="";t=n.get("returnUrl")?n.get("returnUrl"):We.addLanguage("/Home");window.location.replace(t)})},loadModel:function(){var n=this;We.get("","/api/account/spalogin",function(t){var r=n.get("model"),u=$.extend(!0,t,r);n.set("model",u);n.queryParams.email&&n.email(n.queryParams.email);const f=new URLSearchParams(window.location.search),i=f.get("email");i&&(n.email(decodeURIComponent(i)),n.set("hidePassword",!0),n.start())})},parseParams:function(n){var f,s,t;n||(n=We.parseQueryParams());var e=n.advertid,i=n.tenantid,r=n.companyid,u=n.companylock,o=n["login-companyid"];e||i||r||u?this.set("queryParams",n):(f=n.returnurl,f?(s=f.split("?")[1],s?(t=We.parseQueryParams(s),e=t.advertid,i=t.tenantid,r=t.companyid,u=t.companylock,o=t["login-companyid"],this.set("queryParams",t)):this.set("queryParams",n),this.set("returnUrl",f)):this.set("queryParams",n));parsedLoginCompanyId=parseInt(o);parsedLoginCompanyId&&!isNaN(parsedLoginCompanyId)&&this.set("loginCompanyId",o);this.set("advertId",e);r?this.set("companyId",r):u?this.set("companyId",u):this.set("companyId",i);this.set("tenantId",i)},computedCompanyId:function(){return this.get("companyId")||this.get("loginCompanyId")},sendEmailConfirmation:function(){var t=this,i=this.get("model.Start.Email"),n={Email:i};console.log(n);We.post(kendo.stringify(n),"/api/account/sendemailconfirmation",undefined,function(){t.set("isActOnConfirmationEmailVisible",!1)})},actionHeader:function(){var i=this._getProcess(),t;return i===n.companyAdverts?We.translate("Handle job agents"):(t=this.get("currentView"),t==="forgot-view")?We.translate("Reset password"):t==="register-view"?We.translate("Create your profile"):We.translate("Sign in")},actionInfo:function(){var i=this._getProcess(),t;return i===n.companyAdverts?We.translate("To create or view job agents you have to create a profile or sign in..."):(t=this.get("currentView"),t==="register-view")?We.translate("Fill in contact information so your future employer can reach you"):We.translate("And get on the path to a new job")},isWebcruiterLogoVisible:function(){var t=this._getProcess();return t===n.masterCv},jobListLinkEnabled:function(){var t=this._getProcess();return t===n.masterCv},_getProcess:function(){return this.get("returnUrl")&&this.get("returnUrl").indexOf("companyadverts")>0?n.companyAdverts:this.get("advertId")?n.jobApplication:this.get("companyId")||this.get("tenantId")?n.openApplication:this.get("loginCompanyId")?n.companyLogin:n.masterCv},termsConditionSpacePress:function(){this.set("acceptedTerms",!this.get("acceptedTerms"))},showTermsSpacePress:function(n){this.showTerms(n)}}),i=location.search.substr(1),r=We.parseQueryParams(i,!0);return t.parseParams(r),t.initVm(),We.addTermsFunctions(t),kendo.observable(t)},dsSearchOptions={requestEnd:function(n){n.response&&n.response.length>0&&n.response.splice(0,0,{Id:"",Name:We.translate("--select--"),TwoLetterIsoCode:""})}},ApplyViewModel=kendo.Class.extend({model:{MobilePhone:{}},sendButtonText:We.translate("Send application"),countries:We.createReadDataSource("/api/list/country/",{id:"TwoLetterIsoCode"},dsSearchOptions),selectedNationality:function(n){var t,i;if(n)t=this.countries.data().filter(function(t){return t.Id===n})[0],this.set("model.IsEmptyNationality",!1),this.set("model.Nationality",t?t.Name:n),this.set("model.NationalityId",t?t.Id:null);else if(n===null)this.set("model.IsEmptyNationality",!0),this.set("model.Nationality",""),this.set("model.NationalityId",null);else return i=this.get("model.NationalityId"),i==null&&(i=""),i},selectedCountry:function(n){var t,i;if(console.log("selectedCountry"),n)t=this.countries.get(n),this.set("model.IsEmptyCountry",!1),this.set("model.CountryTwoLetterIsoCode",t?n:null),this.set("model.CountryName",t?t.Name:n),this.set("model.hasValidZipCode",!0);else if(n=="")this.set("model.IsEmptyCountry",!0),this.set("model.CountryTwoLetterIsoCode",null),this.set("model.CountryName","");else return i=this.get("model.CountryTwoLetterIsoCode"),i==null&&(i=""),i},dateFormat:function(){var n=kendo.culture().name;return"("+We.getDateFormat(n)+")"},birthDate:function(n){var t,u,i,r;return n?(t=kendo.parseDate(n,"d"),u=new Date(Date.UTC(t.getFullYear(),t.getMonth(),t.getDate())),this.set("model.BirthDate",t),!0):(i=this.get("model.BirthDate"),r=kendo.toString(i,"d"),r)},getCity:function(){var n=this,t=n.get("model.ZipCode"),i=!!t,r=i?$.validator.format("zipCode={0}",t):"",u=We.toLowerCase(n.get("model.CountryTwoLetterIsoCode"))==="no";i&&u&&We.get(r,"/api/candidate/city",function(t){n.set("model.City",t);n.set("model.hasValidZipCode",!!t)})},previewLinkText:We.translate("Preview my application"),load:function(n){var t=this;t.set("cancelInfoVisible",!1);t.set("imageSrc","url('/content/images/noimage.png')");t.set("imageValidationMessage","");var i="/api/account/apply/?"+$.param(vm.get("queryParams").toJSON()),r=function(i){t.set("model.showProfilePicture",i.PersonalDetails.ShowProfilePicture);t.set("model.requireProfilePicture",i.PersonalDetails.RequireProfilePicture);t.set("model.JobDescription",i.JobDescription);t.set("model.DueDate",i.DueDate);t.set("model.CompanyName",i.CompanyName);t.set("model.CompanyNameWithTitle",i.CompanyNameWithTitle);t.set("model.CompanyCity",i.CompanyCity);t.set("model.CompanyCountry",i.CompanyCountry);t.set("model.CompanyLogoLibUrl",i.CompanyLogoLibUrl);t.set("model.ApplyWithinDate",i.DueDate);t.set("model.ShowGender",i.PersonalDetails.ShowGender);t.set("model.RequireGender",i.PersonalDetails.RequireGender);t.set("model.ShowBirthDate",i.PersonalDetails.ShowBirthDate);t.set("model.RequireBirthDate",i.PersonalDetails.RequireBirthDate);t.set("model.ShowAddress",i.PersonalDetails.ShowAddress);t.set("model.RequireAddress",i.PersonalDetails.RequireAddress);t.set("model.ShowZipCode",i.PersonalDetails.ShowZipCode);t.set("model.RequireZipCode",i.PersonalDetails.RequireZipCode);t.set("model.ShowCountry",i.PersonalDetails.ShowCountry);t.set("model.RequireCountry",i.PersonalDetails.RequireCountry);t.set("model.ShowWorkingPermit",i.PersonalDetails.ShowWorkingPermit);t.set("model.RequireWorkingPermit",i.PersonalDetails.RequireWorkingPermit);t.set("model.ShowNationalIdNumber",i.PersonalDetails.ShowNationalIdNumber);t.set("model.RequireNationalIdNumber",i.PersonalDetails.RequireNationalIdNumber);t.set("model.ShowNationality",i.PersonalDetails.ShowNationality);t.set("model.RequireNationality",i.PersonalDetails.RequireNationality);t.set("model.TenantCountry",i.PersonalDetails.TenantCountry);t.set("model.TenantId",i.PersonalDetails.TenantId);t.set("model.hasValidZipCode",!0);t.set("companyPolicy",i.CompanyPolicy);t.set("companyName",i.CompanyName);t.set("hasQuestion",i.HasQuestions);t.set("isApplicationSectionEnabled",i.IsApplicationSectionEnabled);t.set("isVdoApplicationSectionEnabled",i.IsVdoApplicationSectionEnabled);t.set("isCvSectionEnabled",i.IsCvSectionEnabled);t.set("isAttachmentSectionEnabled",i.IsAttachmentSectionEnabled);(t.get("model.CompanyId")||t.get("model.TenantId"))&&!t.get("model.AdvertId")&&(t.set("model.ShowPassword",!0),t.set("previewLinkText",We.translate("Preview my CV")),t.set("sendButtonText",We.translate("Send CV")),t.set("checkBoxVisible",!0));t.set("isVisibility",t.get("model.AdvertId"));t.set("acceptedTerms",t.get("model.AdvertId"));n&&n()};We.get("",i,r)},imageSrc:"url('/content/images/noimage.png')",onImageSelectChange:function(n){if(n.currentTarget.files&&n.currentTarget.files[0]){var i=new FileReader,t=this;i.onload=function(i){t.validateFile(n.currentTarget.files[0]);t.get("imageValidationMessage")===""&&t.set("imageSrc","url('"+i.target.result+"')")};i.readAsDataURL(n.currentTarget.files[0]);this.imageHoverText()}},imageValidationMessage:"",validateFile:function(n){var t=["jpeg","jpg","png","gif","tif","tiff","bmp"],i=n.name.split(".").pop(),r=n.size;t.indexOf(i)===-1?this.set("imageValidationMessage",We.translate("The uploaded file has an invalid extension. Accepted file types are")+" "+t.join(", .")):r>5242880?this.set("imageValidationMessage",We.translate("The uploaded file is too big, please make sure it is less than")+" 5MB"):this.set("imageValidationMessage","")},onImageClick:function(n){n.preventDefault();$("#unregisteredProfileImage").click()},imageHoverText:function(){return this.get("imageSrc")==="url('/content/images/noimage.png')"?We.translate("Add"):We.translate("Update")},isMaleSelected:function(){return this.get("model.Gender")===1},isFemaleSelected:function(){return this.get("model.Gender")===0},isNoneSelected:function(){var n=this.get("model.Gender");return n===1||n===0?!1:!0},onFemaleSpacePress:function(){this.set("model.Gender",0)},onMaleSpacePress:function(){this.set("model.Gender",1)},isWorkPermitSelected:function(){return this.get("model.WorkingPermit")===!0},isNoWorkPermitSelected:function(){return this.get("model.WorkingPermit")===!1},onWorkPermitSpacePress:function(){this.set("model.WorkingPermit",!0)},onWorkPermitOffSpacePress:function(){this.set("model.WorkingPermit",!1)},termsConditionSpacePress:function(){this.set("acceptedTerms",!this.get("acceptedTerms"))},showTermsSpacePress:function(n){this.showTerms(n)},apply:function(){var n=this,t=!$("#BirthDate").val();n.set("model.EmptyBirthDate",t);n.set("model.ProfilePicture",$("#unregisteredProfileImage")[0].files.length>0?"There is a profile picture":null);console.log("Sending this model: "+n.model.toJSON());We.post(kendo.stringify(n.model),"/api/account/apply?"+$.param(vm.get("queryParams").toJSON()),"#apply-form",function(){We.showLoader(!0);var t,r=n.get("hasQuestion")?"/screening":"",i=$.param(vm.get("queryParams").toJSON());t=n.get("model.AdvertId")?We.addLanguage($.validator.format("/cv?{0}#apply{1}",i,r)):We.addLanguage($.validator.format("/cv?{0}#/expancv",i));$("#unregisteredProfileImage")[0].files.length&&!n.get("imageValidationMessage")?We.postFile("/api/attachment/?attachmentType=profileimage",$("#unregisteredProfileImage")[0].files,function(){window.location.replace(t)},function(){window.location.replace(t)}):window.location.replace(t)})},cancelInfoVisible:!1,showCancelInfo:function(){this.set("cancelInfoVisible",!0)},closeCancelInfo:function(){this.set("cancelInfoVisible",!1)},cancelApplication:function(n){n.preventDefault();window.history.back()}}),vm=new SpaLoginModel,language,clearContainers;vm.loadModel();language=We.getTwoLetterLanguageCode();kendo.culture(We.getLanguageCulture(language));var layout=new kendo.Layout("layout-template",{model:vm}),empty=new kendo.View("empty-view"),start=new kendo.View("start-template",{model:vm,init:function(){We.bindEnter($("#start-form"),$("#start-next-button"))}}),login=new kendo.View("login-template",{model:vm,init:function(){We.bindEnterToPassword($("#login-form"),$("input[id^='Login_Password']"),$("#login-next-button"))}}),twoFactorView=new kendo.View("verifycode-template",{model:vm,init:function(){We.bindEnter($("#verifycode-form"),$("#verifycode-next-button"))}}),register=new kendo.View("register-template",{model:vm,init:function(){We.bindEnter($("#register-form"),$("#register-next-button"),function(){return vm.acceptedTerms})}}),applyRegister=new kendo.View("apply-register-template",{model:vm,init:function(){We.bindEnter($("#register-form"),$("#register-next-button"),function(){return vm.acceptedTerms})}}),forgot=new kendo.View("forgot-template",{model:vm}),sentmail=new kendo.View("sentmail-template",{model:vm}),notfound=new kendo.View("notfound-template",{model:vm}),applyVm=kendo.observable(new ApplyViewModel),apply=new kendo.View("apply-template",{model:applyVm,show:function(){$('[data-toggle="popover"]').popover()}}),app=$("#application"),router=new kendo.Router({init:function(){layout.render(app)},routeMissing:function(n){var t=We.parseQueryParams(),i;t.returnurl&&(i="#"+n.url,window.history.pushState({},null,window.location.href.replace(i,encodeURIComponent(i))),query=location.search.substr(1),t=We.parseQueryParams(query,!0),vm.parseParams(t));router.navigate("")},change:function(){}});router.route("/",function(){clearContainers();layout.showIn("#content",start);We.setFocus($("#Start_Email"));vm._getProcess()===2?(headerVm.set("heading",We.translate("Job agent")),headerVm.showHeaderMenu(!1)):(headerVm.set("heading",We.translate("Candidate universe")),headerVm.showHeaderMenu(!0));App.ModelState.clearErrors($("#start-form"))});router.route("login-view",function(){var n,t;if(!vm.email())return router.replace(""),!1;clearContainers();layout.showIn("#content",login);We.setFocus($(".password-field"));App.ModelState.clearErrors($("#login-form"));n=document.getElementById("external-login");n&&(t=location.search.substr(1),n.action=n.action+"&"+t)});router.route("verifycode",function(){if(!vm.email())return router.replace(""),!1;clearContainers();layout.showIn("#content",twoFactorView);App.ModelState.clearErrors($("#verifycode-form"))});router.route("register-view",function(){if(!vm.email())return router.replace(""),!1;clearContainers();layout.showIn("#content",register);We.setNumeric($("#Register_Phone_Number"));We.setFocus($(".password-field"));App.ModelState.clearErrors($("#register-form"))});router.route("apply-register-view",function(){if(!vm.email())return router.replace(""),!1;clearContainers();layout.showIn("#content",applyRegister);We.setNumeric($("#Register_Phone_Number"));We.setFocus($(".password-field"));App.ModelState.clearErrors($("#register-form"))});router.route("forgot-view",function(){if(!vm.email())return router.replace(""),!1;layout.showIn("#content",forgot);We.disableEnter($("#forgot-form"));We.setFocus($("#RecoveryByEmail_Email"));App.ModelState.clearErrors($("#forgot-form"))});router.route("sentmail-view",function(){layout.showIn("#content",sentmail)});router.route("apply-view",function(){if(!vm.email())return router.replace(""),!1;clearContainers();applyVm.set("model.showNoProfileAlert",!0);applyVm.set("model.Email",vm.email());applyVm.set("model.AdvertId",vm.get("advertId"));applyVm.set("model.TenantId",vm.get("tenantId"));applyVm.set("model.CompanyId",vm.get("companyId"));applyVm.set("model.Language",vm.get("language"));We.addTermsFunctions(applyVm);layout.showIn("#content",apply);We.setFocus($(".password-field"));applyVm.load(function(){We.setNumeric($("#Phone_Number"))});headerVm.set("heading",We.translate("Fill in contact details"));headerVm.showHeaderMenu(!0);App.ModelState.clearErrors($("#apply-form"))});router.route("notfound-view",function(){layout.showIn("#content",notfound)});router.bind("change",function(n){vm.set("currentView",n.url)});clearContainers=function(){layout.showIn("#content",empty)};$(function(){router.start()})