//   ======= КОРОЛЛА СТАНДАРТ ==========
var programCorollaStandard = function(completion)
{
    if (facade.car.name == 'Corolla')
    {
        this.name = 'Стандарт Королла 2010';
        this.codeName = 'corollaStandard';
    }
    else
    {
        this.name = 'Специальная программа';
        this.codeName = 'special15';
    }
    
    this.programType = 1;
    
    this.price = Math.round(completion.price);
    this.completionPrice = Math.round(completion.price);
    this.metallicPrice = completion.CostColorMetalic;
    this.metallicPriceUSD = completion.CostColorMetallicUSD;
    this.completion = completion;
}
extend(programCorollaStandard, programStandard);

programCorollaStandard.prototype.init = function(startData, programSwitch)
{
    if (typeof programSwitch == 'undefined')
    {
        programSwitch = false;
    }
    this.termMin = 12;
    this.termMax = 60;
    this.firstPayMin = 15;
    this.firstPayMax = 90;
    
    $('#CalcCredit input[name=onSumCredit]').attr('disabled', false);
    facade.program.setTerm(60);
    facade.program.setFirstPay(15);
    facade.program.commission = 6000;
    this.insurance = 0;
    
    if (!programSwitch)
    {
        facade.program.currency = 'rub';
        this.USDRate = false;
    }
    
    facade.page.sliderTerm.slider('option', 'disabled', false);
    facade.page.sliderTermInner.slider('option', 'disabled', false);
    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', true);
    $('#CalcCredit input[name=SumCreditRate]').val('').attr('disabled', true);
    $('#LsTerm').hide();
    
    $('#FormExchangeRate').hide();
    $('.standard_field').show();
    $('.program50_field').hide();
    $('.additional_field').hide();
    $('.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();
}

programCorollaStandard.prototype.updateInterestRate = function()
{
    _self = this;
    
    if (_self.firstPay < 30)
    {
        if (_self.term < 37)
        {
            _self.interestRate = 12.9;
        }
        else
        {
            _self.interestRate = 13.9;
        }
    }
    else
    {
        if (_self.term < 37)
        {
            _self.interestRate = 11.9;
        }
        else
        {
            _self.interestRate = 12.9;
        }
    }
}

programCorollaStandard.prototype.setFirstPay = function(firstPay)
{
    _self = facade.program;
    
    if (facade.program.firstPay == firstPay)
    {
        return true;
    }
    
    if (firstPay > _self.firstPayMax)
    {
        firstPay = _self.firstPayMax;
    }
    else if (firstPay < _self.firstPayMin)
    {
        firstPay = _self.firstPayMin;
    }
    
    if (firstPay == 15)
    {
        $('#CalcCredit input[name=onSumCredit]').attr('disabled', true);
        $('#CalcCredit input[name=SumCreditCur]').val('').attr('disabled', true);
        $('#CalcCredit input[name=SumCreditRate]').val('').attr('disabled', true);
        _self.insurance = 0;
    }
    else
    {
        $('#CalcCredit input[name=onSumCredit]').attr('disabled', false);
    }
    
    facade.program.firstPay = firstPay;
    facade.page.sliderFirstPay.slider('value', firstPay);
    $('#CalcCredit input[name=FirstPayRate]').val(parseFloat(firstPay).toFixed(2));
    $('#CalcCredit input[name=FirstPayCur]').val((this.price * firstPay / 100).toFixed(2));
    $('#program50_FirstPayCur').html((this.price * firstPay / 100).toFixed(2));
    
    
    return true;
}



//   ======= КОРОЛЛА СПЕЦИАЛЬНАЯ АКЦИЯ ==========
var programCorollaSpecial = function(completion)
{
    if (facade.car.name == 'Corolla')
    {
        this.name = 'Королла 2010 специальная акция';
        this.codeName = 'corollaSpecial';
    }
    else
    {
        this.name = 'Специальная акция';
        this.codeName = 'special50';
    }
    
    this.programType = 2;
    this.price = Math.round(completion.price);
    this.completionPrice = Math.round(completion.price);
    this.metallicPrice = completion.CostColorMetalic;
    this.metallicPriceUSD = completion.CostColorMetallicUSD;
    this.completion = completion;
}
extend(programCorollaSpecial, program50x50);

programCorollaSpecial.prototype.init = function(startData, programSwitch)
{
    if (typeof programSwitch == 'undefined')
    {
        programSwitch = false;
    }
    this.termMin = 60;
    this.termMax = 60;
    this.firstPayMin = 50;
    this.firstPayMax = 90;
    
    $('#CalcCredit input[name=onSumCredit]').attr('disabled', false);
    facade.program.setTerm(60);
    facade.program.setFirstPay(50);
    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', true);
    $('#CalcCredit input[name=SumCreditRate]').val('').attr('disabled', true);
    $('#LsTerm').hide();
    
    $('#FormExchangeRate').hide();
    $('.standard_field').hide();
    $('.program50_field').show();
    $('.additional_field').hide();
    $('#standard_FirstPay').show();
    $('#program50_FirstPay').hide();
    
    $('.so_sign').hide();
    $('.disclaimer p').hide();
    $('#so_notice_standart').show();
    
    
    $('#TotalIntegCost').val(Math.round(parseFloat(this.price)));
    facade.program.calc();
    facade.program.bindEvents();
}

programCorollaSpecial.prototype.updateInterestRate = function()
{
    this.interestRate = 12.9;
}