/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

$(document).ready(function(){
    
    $('#button_calculate').bind('click', function(){
        var cost = parseInt($('#your_cost').val());
        if (!$('#brend').val()) {
            alert("Укажите марку");
            $('#result').val('');
            $('#your_cost').val('');
            return false;
        }
        if (!$('#model').val()) {
            alert("Укажите модель");
            $('#result').val('');
            $('#your_cost').val('');
            return false;
        }
        if (!$('#kuzov').val()) {
            alert("Укажите тип кузова");
            $('#result').val('');
            $('#your_cost').val('');
            return false;
        }
        if (!$('#kpp').val()) {
            alert("Укажите тип КПП");
            $('#result').val('');
            $('#your_cost').val('');
            return false;
        }
        if (!$('#engine_type').val()) {
            alert("Укажите тип двигателя");
            $('#result').val('');
            $('#your_cost').val('');
            return false;
        }
        if (!$('#way').val()) {
            alert("Укажите пробег");
            $('#result').val('');
            $('#your_cost').val('');
            return false;
        }
        if (!cost) {
            alert("Укажите сколько хотите получить за машину");
            $('#result').val('');
            $('#your_cost').val('');
            return false;
        }
        cost = Math.floor(cost*0.95);
        $('#result').val(cost);
        return false;
    });
    
    $('#your_cost').bind('keypress', function(e){
        $('#result').val('');
        if (e.which<48 || e.which>57) {
            return false;
        }
    })
})

