$(document).ready(function (){
    $('#montant input[type=radio]').click(function() {
        reset_inputs();
        $(this).attr('checked', true);
    });

    $('#montant input[type=text]').keyup(function(){
        if ($(this).val() == '' || is_numeric($(this).val())) {
            remove_error($(this));
        }
        if ($(this).val() != '') {
            var val = $(this).val();
            reset_inputs();
            $(this).val(val);
        }
        if ($(this).val() != '' && !is_numeric($(this).val())) {
            add_error($(this));
        }
    });
});

function reset_inputs() {
    $('#montant input').attr('checked', false).each(function(){
        remove_error($(this));
    });
    $('#montant input[type=text]').val('');
}

function is_numeric(input) {
   return (input - 0) == input && input.length > 0;
}

function add_error(field) {
    field.addClass('form-error');
}

function remove_error(field) {
    field.removeClass('form-error');
}