function show_error(field, msg){
    modal_window({
        message: '<div class="alert alert-danger">' + msg + '</div>',
        title: 'Error in ' + field,
        close: function(){
            $j('#' + field).focus();
            $j('#' + field).parents('.form-group').addClass('has-error');
        }
    });
    
    return false;
}

/* cacher le champs depense si recettes est selectionné */
$j('#mouvement').on('change', function(){
	if($j('#mouvement').val() == "RECETTES"){
	$j('#depense').parents('.form-group').hide();
	}else{
	$j('#depense').parents('.form-group').show();
	}
})

/* cacher le champs recette si depenses est selectionné */
$j('#mouvement').on('change', function(){
	if($j('#mouvement').val() == "DEPENSES"){
	$j('#recette').parents('.form-group').hide();
	}else{
	$j('#recette').parents('.form-group').show();
	}
})

$j(function(){
/* set montant ttc field to read only*/
$j('#solde').prop('readonly', true);

/* calcul du champs montant_ttc */
$j('#recette, #depense, #solde').change(function(){
	var recettes = parseFloat($j('#recette').val()) || 0;
	var depenses = parseFloat($j('#depense').val()) || 0;
	
	var restant = recettes - depenses;
	$j('#solde').val(restant);
});

/* calculate total price on opening the detail view form*/
$j('#recette, #depense').change();

})