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;
}

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

    /* calcul du champs montant_ttc */
    $j('#quantite, #prixunitaire, #fis, #comm, #acompte').change(function () {
        var quantity = parseFloat($j('#quantite').val()) || 0;
        var unitPrice = parseFloat($j('#prixunitaire').val()) || 0;
        var frais = parseFloat($j('#fis').val()) || 0;
        var commi = parseFloat($j('#comm').val()) || 0;
        var acpte = parseFloat($j('#acompte').val()) || 0;

        var totalPrice = quantity * unitPrice + frais + commi;
        var rpayer = totalPrice - acpte;
        $j('#total').val(totalPrice);
        $j('#reste_payer').val(rpayer);
    });

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

})
