var VTCI=VTCI||{};VTCI.Warranty=VTCI.Warranty||{};VTCI.Warranty.CMSCategory=function(){var n={};return n.category=ko.wrap.fromJS(ViewBag.Category),n};VTCI=VTCI||{};VTCI.Warranty=VTCI.Warranty||{};VTCI.Warranty.CMSPage=function(){var n={};return n.page=ko.wrap.fromJS(ViewBag.Page),n};VTCI=VTCI||{};VTCI.Warranty=VTCI.Warranty||{};VTCI.Warranty.Products=function(n){var t={};return t.products=ko.observableArray(),ko.wrap.updateFromJS(t.products,n.RegisteredProducts),t};VTCI=VTCI||{};VTCI.Warranty=VTCI.Warranty||{};VTCI.Warranty.Register=function(n){var t={},i,r;t.countries=ko.wrap.fromJS(ViewBag.countries);t.states=ko.wrap.fromJS(ViewBag.states);t.errorMessages=errorMessages;t.currentStep=ko.observable(1);t.currentStep.subscribe(function(){$("html").animate({scrollTop:0},"slow");$("body").animate({scrollTop:0},"slow");t.currentStep()<=4&&u()});t.goToStep1=function(){t.currentStep(1)};t.returnToStart=function(){t.currentStep(1);t.productConfirmationModal("");t.qrCode(null);t.removeSelectedDealer();t.dealers.removeAll();t.showOtherDealerForm(!1)};t.productSearch=ko.observable();t.qrCode=ko.observable();t.product=ko.observable();t.serialNumber=ko.observable();t.productConfirmationModal=ko.observable("");t.isProductCodeValid=ko.observable(!0);t.currentCountry=ko.observable("currentUser"in window?currentUser.CountryCode:common.PossibleCountry);t.searchProduct=function(){t.isProductCodeValid(!0);$.get("/api/product/search",{search:t.productSearch()}).done(function(n){n==null?t.productConfirmationModal("ERROR"):n.BlockUSVersion&&t.currentCountry()=="US"?t.productConfirmationModal("USVERSION"):(ko.wrap.updateFromJS(t.product,n),i())}).fail(function(){toastr.error("Unable to complete product search, please try again later")})};i=function(){t.product().IsQrMandatory()==!1&&t.product().IsQrPresent()==!1&&t.goToStep2();t.product().IsQrMandatory()==!1&&t.product().IsQrPresent()==!0&&t.productConfirmationModal("QR");t.product().IsQrMandatory()==!0&&t.product().IsQrPresent()==!0&&t.productConfirmationModal("QRMANDATORY")};t.isQrCodeValid=ko.observable(!0);t.checkQrCode=function(){t.qrCode()==""||t.qrCode()==null?t.isQrCodeValid(!1):$.get("/api/product/checkQr",{qrCode:t.qrCode(),sku:t.product().SKU()}).done(function(n){t.isQrCodeValid(n);n?t.selectProduct():(t.isQrCodeValid(!1),toastr.error("Unable to verify QR Code"))}).fail(function(){t.isQrCodeValid(!1);toastr.error("Unable to verify QR Code")})};t.selectProductWithoutQr=function(){t.qrCode(null);t.isQrCodeValid(!0);t.goToStep2()};t.selectProduct=function(){t.goToStep2()};t.goToStep2=function(){t.currentStep(2)};t.goToStep3ButtonVisible=function(){return t.dealersFilter.storeTypeSearch()!=null&&t.purchaseDate()!=null&&t.purchaseDate().startOf("day")<=moment().startOf("day")&&t.purchaseDate()>moment().add(-1,"y")};t.goToStep3=function(){t.currentStep(3);t.dealersFilter.storeTypeSearch()=="online"&&t.searchDealers()};t.dealersFilter={countryCode:ko.observable("currentUser"in window?currentUser.CountryCode:common.PossibleCountry),state:ko.observable(""),name:ko.observable(""),city:ko.observable(""),storeTypeSearch:ko.observable("retail")};t.purchaseDate=ko.observable(moment());t.dealers=ko.observableArray();t.dealersLoading=ko.observable(!1);t.goToStep4=function(){t.currentStep(4)};t.dealerSearchDone=ko.observable(!1);t.searchDealers=function(){t.dealersLoading(!0);$.get("/api/dealer/search",t.dealersFilter).done(function(n){t.dealerSearchDone(!0);ko.wrap.updateFromJS(t.dealers,n);n!=null&&n.length>0&&$("html, body").animate({scrollTop:$("#dealers-table").offset().top-200},600)}).fail(function(){toastr.error("Unable to find dealers");t.dealersLoading(!1)})};t.selectedDealer=ko.observable();t.chooseDealer=function(n){t.selectedDealer(null);var i=$("#dealer-"+n.Id()),u=i.parent().parent().parent().scrollTop(),r=i.parent().parent().parent();r.animate({scrollTop:u+i.offset().top-r.offset().top},300);t.selectedDealer(n)};t.showOtherDealerForm=ko.observable(!1);t.otherDealerName=ko.observable();t.otherDealerCountryCode=ko.observable();t.goToOtherDealer=function(){t.otherDealerName(t.dealersFilter.name());t.otherDealerCountryCode(t.dealersFilter.countryCode());t.showOtherDealerForm(!0);var n=$("#otherDealerForm");$("html").animate({scrollTop:n.offset().top-150},"slow");$("body").animate({scrollTop:n.offset().top-150},"slow")};t.chooseOtherDealer=function(){var n={Address:null,City:null,Country:t.otherDealerCountryCode(),Id:null,Name:(t.otherDealerName()||"OTHER")+" - "+t.dealersFilter.storeTypeSearch(),ShipToCountries:null,State:null};t.selectedDealer(ko.wrap.fromJS(n));t.goToStep4()};t.removeSelectedDealer=function(){t.selectedDealer(null)};t.goToStep5=function(){r();t.currentStep(5)};t.registrationDetail=ko.observable();t.isSaving=ko.observable(!1);t.warrantyExpirationDate=ko.observable();t.warrantyMonths=ko.observable();t.warrantyLegalMonths=ko.observable();t.warrantyTitle=ko.observable();t.warrantyDescription=ko.observable();t.isWarrantyExtended=ko.observable();t.warrantyStatus=ko.observable();r=function(){t.isSaving(!0);var n=ko.toJSON({qrCode:t.qrCode(),sku:t.product().SKU(),dealerId:t.selectedDealer().Id(),dealerName:t.selectedDealer().Name(),dealerCountryCode:t.selectedDealer().Country(),purchaseDate:t.purchaseDate(),serialNumber:t.serialNumber(),publicUserGuid:ViewBag.publicUserGuid,purchaseType:t.dealersFilter.storeTypeSearch()});$.post("/api/register/saveproduct",n).done(function(n){t.warrantyExpirationDate(n.WarrantyExpirationDate);t.warrantyMonths(n.WarrantyMonths);t.warrantyLegalMonths(n.WarrantyLegalMonths);t.isWarrantyExtended(n.IsWarrantyExtended);t.warrantyStatus(n.WarrantyStatus);ko.wrap.updateFromJS(t.warrantyTitle,n.WarrantyTitle);ko.wrap.updateFromJS(t.warrantyDescription,n.WarrantyDescription);t.currentStep(5);t.isSaving(!1)}).fail(function(){t.isSaving(!1)})};t.goToSupport=function(){location.href="/home/support?sendProductData=true"};var u=function(){if(!e("localStorage"))throw"Storage not available, upgrade your browser.";var n={currentStep:t.currentStep(),product:ko.wrap.toJS(t.product()),selectedDealer:ko.wrap.toJS(t.selectedDealer()),qrCode:t.qrCode(),serialNumber:t.serialNumber(),dealersFilter:ko.wrap.toJS(t.dealersFilter),purchaseDate:t.purchaseDate()};localStorage.setItem("warrantyreg",JSON.stringify(n))},o=function(){localStorage.setItem("warrantyReg",null)},f=function(){var i=localStorage.getItem("warrantyreg"),n;i!=null&&(n=JSON.parse(i),ko.wrap.updateFromJS(t.product,n.product),ko.wrap.updateFromJS(t.selectedDealer,n.selectedDealer),t.purchaseDate(n.purchaseDate?moment(n.purchaseDate):null),t.dealersFilter.countryCode(n.dealersFilter.countryCode||""),t.dealersFilter.state(n.dealersFilter.state||""),t.dealersFilter.name(n.dealersFilter.name||""),t.dealersFilter.city(n.dealersFilter.city||""),t.dealersFilter.storeTypeSearch(n.dealersFilter.storeTypeSearch||""),t.qrCode(n.qrCode||null),t.serialNumber(n.serialNumber||null),t.currentStep(n.currentStep),$("html").animate({scrollTop:0},"slow"),$("body").animate({scrollTop:0},"slow"))},e=function(n){try{var i=window[n],t="__storage_test__";return i.setItem(t,t),i.removeItem(t),!0}catch(r){return!1}};return n===!0&&f(),t};VTCI=VTCI||{};VTCI.Warranty=VTCI.Warranty||{};VTCI.Warranty.RegisterShipment=function(n){var t={},i;return t.shipment=ko.observable(),t.shipmentId=ko.observable(n),t.errorMessages=errorMessages,t.saveProduct=function(n){var i={ShipmentId:t.shipmentId(),Product:n};$.post("/api/register/SaveShipmentProduct",ko.toJSON(i)).done(function(t){t!=null?(n.IsWarrantyExtended(t.IsWarrantyExtended),n.WarrantyExpirationDate(t.WarrantyExpirationDate),n.WarrantyMonths(t.WarrantyMonths),n.WarrantyTitle(t.WarrantyTitle),n.WarrantyDescription(t.WarrantyDescription),n.WarrantyStatus(t.WarrantyStatus)):toastr.error("Unable to register the product")}).fail(function(){toastr.error("Unable to register the product")})},i=function(){$.get("/api/product/getshipment",{id:t.shipmentId()}).done(function(n){ko.wrap.updateFromJS(t.shipment,n)}).fail(function(){toastr.error("Unable to get products from server, please try again later")})},t.init=function(){i()},t.checkQr=function(n){n.IsQrMandatory()==!1&&(n.QrCode()==""||n.QrCode()==null)?n.IsQrCodeValid(!0):n.QrCode()==""||n.QrCode()==null?n.IsQrCodeValid(!1):$.get("/api/product/checkQr",{qrCode:n.QrCode(),sku:n.Sku()}).done(function(t){n.IsQrCodeValid(t)}).fail(function(){n.IsQrCodeValid(!1);toastr.error("Unable to verify QR Code")})},t};VTCI=VTCI||{};VTCI.Warranty=VTCI.Warranty||{};VTCI.Warranty.Support=function(n,t){var i={},f,r,u;if(i.dataToSend={name:ko.observable(),email:ko.observable(),userCountry:ko.observable("currentUser"in window?currentUser.CountryCode:common.PossibleCountry),description:ko.observable(),requestType:ko.observable(),productData:ko.observable(),captchaValue:ko.observable()},i.countries=ko.wrap.fromJS(n),i.currentStep=ko.observable(1),i.isLoading=ko.observable(!1),i.formDataIsValid=ko.computed(function(){return i.dataToSend.description()!=null&&i.dataToSend.description()!=""}),t){if(f=localStorage.getItem("warrantyreg"),f==null)return;r=JSON.parse(f);u={};r.product&&(u.Sku=r.product.SKU,u.Brand=r.product.Brand,u.IsQrPresent=r.product.IsQrPresent,u.IsQrMandatory=r.product.IsQrMandatory,u.ShortDescription=r.product.ShortDescription.en);r.selectedDealer&&(u.Dealer=r.selectedDealer.Name,u.DealerCountry=r.selectedDealer.Country,u.QrCode=r.qrCode);i.dataToSend.productData(JSON.stringify(u))}return i.showValidationError=ko.observable(!1),i.sendRequest=function(){i.formDataIsValid()?(i.dataToSend.captchaValue(grecaptcha.getResponse()),i.isLoading(!0),i.showValidationError(!1),$.post("/api/support/addNewRequest",ko.toJSON(i.dataToSend)).done(function(){i.currentStep(2);i.isLoading(!1)}).fail(function(n){toastr.error("Unable to send support request: "+n.responseJSON.Message);i.isLoading(!1);grecaptcha.reset()})):i.showValidationError(!0)},i};VTCI=VTCI||{};VTCI.Warranty=VTCI.Warranty||{};VTCI.Warranty.UserAccount=function(n){var t={};return t.activeTab=ko.observable("home"),t.goToTab=function(n){t.activeTab(n)},t.products=ko.observableArray(),ko.wrap.updateFromJS(t.products,n.RegisteredProducts),t.optionLevels=ko.wrap.fromJS(n.Levels),t.optionStyles=ko.wrap.fromJS(n.Styles),t.optionGears=ko.wrap.fromJS(n.Gears),t.profile=ko.observable(ko.wrap.fromJS(n.UserProfile)),t.profileDirtyFlag=new ko.dirtyFlag(t.profile,!1,["Interests"]),t.interestsDirtyFlag=new ko.dirtyFlag(t.profile,!1,["Address","City","CountryCode","Email","Fax","FirstName","LastName","PhoneNumber","ZipCode","State"]),t.activeProfileTab=ko.observable("profile"),t.countries=ko.wrap.fromJS(n.Countries),t.saveUserProfile=function(){$.post("/api/user/SaveUserProfile",ko.toJSON(t.profile)).done(function(){t.profileDirtyFlag.reset();toastr.info("User info updated")}).fail(function(){toastr.error("Unable to update the user info, server error")})},t.saveUserInterest=function(){$.post("/api/user/SaveUserInterest",ko.toJSON(t.profile)).done(function(){t.interestsDirtyFlag.reset();toastr.info("User interests updated")}).fail(function(){toastr.error("Unable to update the user interests, server error")})},t.changePasswordForm={OldPassword:ko.observable(""),NewPassword:ko.observable(""),ConfirmNewPassword:ko.observable("")},t.changePassword=function(){var i=$('#ChangePasswordForm input[name="__RequestVerificationToken"]').val(),n={};n.__RequestVerificationToken=i;$.ajax({type:"POST",url:"/api/user/ChangeUserPassword",contentType:"application/json; charset=utf-8",headers:n,data:ko.toJSON(t.changePasswordForm),dataType:"json"}).done(function(){t.changePasswordForm.OldPassword("");t.changePasswordForm.NewPassword("");t.changePasswordForm.ConfirmNewPassword("");toastr.success("Password changed")}).fail(function(n){n!=null&&n.responseJSON!=null&&n.responseJSON.Message?toastr.error(n.responseJSON.Message):toastr.error("Unable to change the user password, server error")})},t.changeEmailForm={Password:ko.observable(""),NewEmail:ko.observable(""),ConfirmNewEmail:ko.observable(""),Email:t.profile().Email},t.emailHasChanged=ko.observable(!1),t.emailChangeError=ko.observable(!1),t.emailHasChangedWithErrors=ko.observable(!1),t.changeEmail=function(){t.emailHasChanged(!1);t.emailHasChangedWithErrors(!1);var i=$('#ChangeEmailForm input[name="__RequestVerificationToken"]').val(),n={};n.__RequestVerificationToken=i;$.ajax({type:"POST",url:"/api/user/ChangeUserEmail",contentType:"application/json; charset=utf-8",headers:n,data:ko.toJSON(t.changeEmailForm),dataType:"json"}).done(function(){t.emailHasChanged(!0);t.changeEmailForm.Email(t.changeEmailForm.NewEmail());t.changeEmailForm.Password("");t.changeEmailForm.NewEmail("");t.changeEmailForm.ConfirmNewEmail("");toastr.success("Email changed")}).fail(function(n){t.emailHasChanged(!1);n!=null&&n.responseJSON!=null&&n.responseJSON.Message?(toastr.error(n.responseJSON.Message),t.emailChangeError(n.responseJSON.Message),t.emailHasChangedWithErrors(!0)):toastr.error("Unable to change the user email, server error")})},t}