var programLexus2010 = function(completion)
{
    this.name = 'Программа «Лексус 2010»';
    this.programType = 1;
    this.codeName = 'lexus2010';
    
    this.price = Math.round(completion.price);
    this.completionPrice = Math.round(completion.price);
    this.metallicPrice = completion.CostColorMetalic;
    this.metallicPriceUSD = completion.CostColorMetallicUSD;
    this.completion = completion;
}

extend(programLexus2010, programStandard);

programLexus2010.prototype.updateInterestRate = function()
{
    this.interestRate = 14.9;
}

programLexus2010.prototype.onCalcSuccess = function(data)
{
    _self = facade.program;
    
    _self.monthlyPay = data.monthlyPay1.toFixed(2);
    _self.totalPay = (_self.monthlyPay * _self.term).toFixed(2);
    _self.totalPayRate = (_self.totalPay - (_self.loanAmount - _self.endLoanAmount)).toFixed(2);
    _self.summCredit = ((_self.loanAmount - _self.endLoanAmount) - _self.commission).toFixed(2);
    
    
    $('#InterestRate').html(_self.interestRate);
    $('#SummCredit').html(_self.summCredit);
    $('#Commission').html(_self.commission);
    $('#MonthlyPay').html(_self.monthlyPay);
    $('#VisualMonthlyPay').html(_self.monthlyPay);
    $('#TotalPay').html(_self.totalPayRate);
}

programLexus2010.prototype.calc = function()
{
    _self = this;
    _self.updateInterestRate();
    _self.loanAmount = _self.price * (1 - _self.firstPay / 100) + (_self.price * _self.insurance / 100);
    _self.endLoanAmount = _self.price * 0.35;
    
    _self.term = 36;
    var response = $.ajax(
    {
        url: 'calc.php?action=calcBackCredit',
        type: 'post',
        data: {loanAmount:_self.loanAmount, term1: _self.term, term2: 1, interestRate: _self.interestRate, endLoanAmount: _self.endLoanAmount},
        dataType: 'json',
        success: _self.onCalcSuccess
    });
}

programLexus2010.prototype.init = function(startData, programSwitch)
{
    if (typeof programSwitch == 'undefined')
    {
        programSwitch = false;
    }
    this.termMin = 36;
    this.termMax = 36;
    this.firstPayMin = 30;
    this.firstPayMax = 100;
    
    $('#CalcCredit input[name=onSumCredit]').attr('disabled', false);
    facade.program.setTerm(36);
    facade.program.setFirstPay(30);
    facade.program.commission = 6000;
    this.insurance = 0;
    
    if (!programSwitch)
    {
        facade.program.currency = 'rub';
        this.USDRate = false;
    }
    
    facade.page.sliderTerm.slider('option', 'disabled', true);
    facade.page.sliderTermInner.slider('option', 'disabled', true);
    facade.page.sliderFirstPay.slider('option', 'disabled', false);
    
    if (!programSwitch)
    {
        $('#currency_selector_rub').attr('checked', true);
        $('.currency_label').html('Руб');
        $('#metallic_off').attr('checked', true);
    }
    
    $('#onSumCredit_off').attr('checked', true);
    $('#CalcCredit input[name=SumCreditCur]').val('').attr('disabled', false);
    $('#CalcCredit input[name=SumCreditRate]').val('').attr('disabled', false);
    $('#LsTerm').hide();
    
    $('#FormExchangeRate').hide();
    $('.program50_field').hide();
    $('.standard_field').show();    
    $('.so_sign').hide();
    $('.disclaimer p').hide();
    $('#so_notice_standart').show();
    
    
    
    $('#TotalIntegCost').val(Math.round(parseFloat(this.price)));
    if ((typeof startData != 'undefined') && startData)
    {
        this.setData(startData);
    }
    facade.program.calc();
    facade.program.bindEvents();
}
