$(document).ready(function(){
    $('#montant input[type=radio]').not('.cadeau').click(function() {
        update_reduction_impots($(this).val(), mensuel($(this)));
    });

    $('#montant input[type=text]').keyup(function(){
        if ($(this).val() != '' && is_numeric($(this).val())) {
            update_reduction_impots($(this).val(), mensuel($(this)));
        }
    });
});
function update_reduction_impots(montant, mensuel) {
    console.log(mensuel);
    var montant_reduit = (montant * 0.34).toFixed(2);
    if (montant_reduit * 100 % 100 == 0) {
        montant_reduit = (montant * 0.34).toFixed(0);
    };
    $('.montant-don-reduit .don-initial').html(montant.replace('.', ','));
    $('.montant-don-reduit .don-final').html(montant_reduit.replace('.', ','));
    if (mensuel) {
        $('.montant-don-reduit .mensuel').html(" par mois");
    } else {
        $('.montant-don-reduit .mensuel').html("");
    }
}
function mensuel(element) {
    return element.attr('name').indexOf('monthly') != -1;
}
