CarsViewModel={};var CarData=DataProvider.getCars();CarsViewModel.data=CarData&&0<CarData.length?CarData:DefaultCarData;DefaultCarData=null;CarsViewModel._History=[];CarsViewModel.cars=ko.observableArray();CarsViewModel.bottomPanelVisible=ko.observable(!1);CarsViewModel.isFirstLevel=ko.observable(!1);CarsViewModel.isLastLevel=ko.observable(!1);CarsViewModel.basicPrice=ko.observable(0);CarsViewModel.accessoriesPrice=ko.observable(0).extend({validateFloat:{}});
CarsViewModel.fullPrice=ko.computed(function(){return CarsViewModel.basicPrice()+CarsViewModel.accessoriesPrice()});CarsViewModel.residualValueChartId=ko.observable();CarsViewModel.CarDescription=ko.observableArray();CarsViewModel.reset=function(){CarsViewModel.cars(CarsViewModel.data);CarsViewModel._History.splice(0);CarsViewModel.CarDescription([]);CarsViewModel.isFirstLevel(!0);CarsViewModel.isLastLevel(!1);CarsViewModel.bottomPanelVisible(!1);$('input[data-type="search"]').val("")};
CarsViewModel.selectChildCommand=function(b){CarsViewModel.bottomPanelVisible(!b.Children||0==b.Children.length);CarsViewModel.basicPrice(b.Price);CarsViewModel.accessoriesPrice(0);CarsViewModel.residualValueChartId(b.RestValueChartId);2<CarsViewModel.CarDescription().length&&CarsViewModel.CarDescription.pop();CarsViewModel.CarDescription.push(b.Name);if(!b.Children||0==b.Children.length)if(2==CarsViewModel._History.length)CarsViewModel.isLastLevel(!0);else{CarsViewModel.CarDescription.pop();var b=
Culture.translations().stringTextNoData+".",a=Culture.translations().stringTextSelectACar;navigator.notification?navigator.notification.alert(b,void 0,a,Culture.translations().stringTextOk):alert(b)}else CarsViewModel._History.push(CarsViewModel.cars()),CarsViewModel.cars([]),$(window).scrollTop(0),CarsViewModel.cars(b.Children),CarsViewModel.isFirstLevel(!1),$('input[data-type="search"]').val("")};
CarsViewModel.selectParentCommand=function(){0==CarsViewModel._History.length?history.back():(CarsViewModel.CarDescription.splice(CarsViewModel._History.length-1,3),CarsViewModel.bottomPanelVisible(!1),CarsViewModel.isLastLevel(!1),CarsViewModel.cars(CarsViewModel._History[CarsViewModel._History.length-1]),CarsViewModel._History.splice(-1,1),0==CarsViewModel._History.length&&CarsViewModel.isFirstLevel(!0),$('input[data-type="search"]').val(""))};
CarsViewModel.selectCarCommand=function(){Log("createNewCalculation");Log(PageParameters.createNewCalculation);PageParameters.createNewCalculation&&(window.CurrentlyEditedCalculation.reset(),window.CurrentlyEditedCalculation.calculate(),window.CurrentlyEditedCalculation.selectedObjectType(ObjectTypes.Car));window.CurrentlyEditedCalculation.objectTypesDisabled(!0);var b="",a="";ko.utils.arrayForEach(CarsViewModel.CarDescription(),function(a){b=b+" "+a});window.CurrentlyEditedCalculation.make(void 0!=
CarsViewModel.CarDescription()[0]?CarsViewModel.CarDescription()[0]:"");window.CurrentlyEditedCalculation.model(void 0!=CarsViewModel.CarDescription()[1]?CarsViewModel.CarDescription()[1]:"");window.CurrentlyEditedCalculation.type(void 0!=CarsViewModel.CarDescription()[2]?CarsViewModel.CarDescription()[2]:"");window.CurrentlyEditedCalculation.description($.trim(b));Log(window.CurrentlyEditedCalculation.id());Log(CarsViewModel.CarDescription());null===CarsViewModel.residualValueChartId()?a=Settings.getDefaultResidualValueChart():
(a=Settings.getResidualValueChartById(CarsViewModel.residualValueChartId()),null===a&&(Log("Default residual value chart was taken."),a=Settings.getDefaultResidualValueChart()));window.CurrentlyEditedCalculation.carsResidualValueChartId(CarsViewModel.residualValueChartId());window.CurrentlyEditedCalculation.residualValueChart(a);window.CurrentlyEditedCalculation.accessoriesValue(CarsViewModel.accessoriesPrice());a=window.CurrentlyEditedCalculation.selectedUsage()==Usages.Private?CarsViewModel.basicPrice():
CalculateNetValue(CarsViewModel.basicPrice(),window.CurrentlyEditedCalculation.taxRate);window.CurrentlyEditedCalculation.baseValue(a);a=0.2*window.CurrentlyEditedCalculation.presentValue();a>window.CurrentlyEditedCalculation.constraints.oneOff.max&&(a=window.CurrentlyEditedCalculation.constraints.oneOff.max);a<window.CurrentlyEditedCalculation.constraints.oneOff.min&&(a=window.CurrentlyEditedCalculation.constraints.oneOff.min);window.CurrentlyEditedCalculation.oneOffPayment(a);CarsViewModel.bottomPanelVisible(!1);
PageParameters.createNewCalculation?$.mobile.changePage("EditCalculation.html"):$.mobile.changePage("EditCalculation2.html")};
