function validate(obj){
    if (isNaN(obj.value)) {
        obj.value = 0;
    } else {
        obj.value=parseFloat(parseInt(obj.value*100)/100);
    }
}    
function toInt(arg){
    if (isNaN(arg)) {
        return 0;
    } 
    return parseInt(arg);
}    
function toFloat(arg){
    var a = parseFloat(arg);
    if (isNaN(a)) { return 0; } 
    return a;
}
function typesCoefficient(){

    var types_option;
    var omega_coef1 = 0;
    var omega_coef2 = 0;
    var omega = 0;
    var calc = 0;
    
    var extra0 = document.getElementById('extra0');
    var extra0 = extra0.value;
    
    var extra1 = document.getElementById('extra1');
    var extra1 = extra1.value;
    
    var extra2 = document.getElementById('extra2');
    var extra2 = extra2.value;
    
    var to=document.getElementById('types_options');
    types_option = to.value; // текущий выбранный тип

        if (types_option == 'types_0_0'){
            omega_coef1 = 0.0035;
            omega_coef2 = 0.07;
        }                    
        if (types_option == 'types_0_1'){
            omega_coef1 = 0.0025;
            omega_coef2 = 0.05;
        }                    
        if (types_option == 'types_0_2'){
            omega_coef1 = 0.002;
            omega_coef2 = 0.045;
        }                    
        if (types_option == 'types_0_3'){
            omega_coef1 = 0.003;
            omega_coef2 = 0.055;
        }    
        if (types_option == 'types_0_4'){
            omega_coef1 = 0.0032;
            omega_coef2 = 0.065;
        }                    
        if (types_option == 'types_1_0'){
            omega_coef1 = 0.003;
            omega_coef2 = 0.01;
        }                    
        if (types_option == 'types_1_1'){
            omega_coef1 = 0.002;
            omega_coef2 = 0.09;
        }                    
        if (types_option == 'types_1_2'){
            omega_coef1 = 0.0025;
            omega_coef2 = 0.015;
        }                    
        if (types_option == 'types_1_3'){
            omega_coef1 = 0.003;
            omega_coef2 = 0.014;
        }                    
        if (types_option == 'types_1_4'){
            omega_coef1 = 0.002;
            omega_coef2 = 0.09;
        }                    
        if (types_option == 'types_2_0'){
            omega_coef1 = 0.001;
            omega_coef2 = 0.016;
        }                    
        if (types_option == 'types_2_1'){
            omega_coef1 = 0.001;
            omega_coef2 = 0.012;
        }
        
        CurDate = new Date();
        var CurMonth = toInt(CurDate.getMonth());
        var CurFullYear = toInt(CurDate.getFullYear());
        
        var date_coef = 0;
        var date_coef = (CurFullYear - extra1)*12 + (CurMonth - extra2);
        var date_FullYearcoef = (CurFullYear - extra1) + (CurMonth/12 - extra2/12);
        
        if (date_coef<=0) {
        calc = 0;
        }
        else{
        omega = omega_coef1*(extra0/1000)+omega_coef2*date_FullYearcoef;
        calc = 1-1/Math.pow(2.7182,omega);
        }

        return calc;
}
function ComputeAmount(){

    var costege = document.getElementById('cost');
    var costege = toInt(costege.value); // Стоимость

    var coef = typesCoefficient();
    var coef2009  = 0.062;

    var outsum = document.getElementById('outsum');
        var errorinp = document.getElementById('errorinp');

        var extra0 = document.getElementById('extra0');
    var extra0 = extra0.value;

    if (costege<=0 || extra0.value<=0 || coef<=0) {errorinp.style.visibility = 'visible'; outsum.value = "-";} 
    else{
                sum = costege-costege*coef ;
                sum = Math.round(sum-sum*coef2009);
                outsum.value = sum;
                errorinp.style.visibility = 'hidden';
}
}

