$(document).ready(function(){
    
    $(".product_bat_panier").click(function() {
        $.post("/override/ajax/Chg_Etat_Bat.php", {
            id_cart_product : this.title,
            product_attribute : this.name,
            cocher : this.value,
            id_cart : $('#id_panier').val()
        },
        function success(data){
            javascript:location.reload();
        });
    })
    
     $(".poubelle").click(function() {
        var td = $(this).parent().parent().attr('id');
        var id = td.split('_');
        
        $.post("/modules/upload_client/php/Del_Fichiers.php", {
            id_cart_product : id[0],
            id_cart : id[1],
            id_product : id[2]
        },
        function success(data){
            javascript:location.reload();
        });
    })
    
    $(".open_dialog_modal_upload_cart").click(function() {
        var td = $(this).parent().parent().attr('id');
        var id = td.split('_');

        $.post("/modules/upload_client/php/Open_Modal_Upload.php", {
            id_cart_product : id[0],
            id_cart : id[1],
            id_product : id[2],
            id_customer : id[3]
        },
        function success(data){
            $('#dialog_form_upload').html(data);
        });
    })
    
    $(".open_dialog_modal_upload").click(function() {
        var td = $(this).parent().attr('id');
        var id = td.split('_');

        $.post("/modules/upload_client/php/Open_Modal_Upload.php", {
            id_cart_product : id[0],
            id_cart : id[1],
            id_product : id[2],
            id_customer : id[3],
            nok : id[4]
        },
        function success(data){
            $('#dialog_form_upload').html(data);
        });
    })
    
    $(".valider_produit").click(function() {
        var td = $(this).parent().parent().attr('id');
        var id = td.split('_');

        $.post("/modules/upload_client/php/Validation_Upload.php", {
            id_cart_product : id[0],
            id_cart : id[1]
        },
        function success(data){
            var donnees = eval('(' + data + ')'); //Décode le json reçu

            if (donnees.validation == 1) {
                $('#'+td).parent().fadeOut();
            }
            else {
                $('#msg_'+td).html(donnees.validation);
            }
            if (donnees.nb_commandes > 1)
                $('#nb_commandes').html(donnees.nb_commandes+' commandes');
            else
                $('#nb_commandes').html(donnees.nb_commandes+' commande');
        });
    })
    
    $(".valider_fnok").click(function() {
        var td = $(this).parent().parent().attr('id');
        var id = td.split('_');

        $.post("/modules/upload_client/php/Validation_Fnok.php", {
            id_cart_product : id[0],
            id_cart : id[1],
            id_upload : id[2]
        },
        function success(data){
            var donnees = eval('(' + data + ')'); //Décode le json reçu

            if (donnees.validation == 1) {
                $('#'+td).parent().fadeOut();
            }
            else {
                $('#msg_'+td).html(donnees.validation);
            }
            if (donnees.nb_commandes > 1)
                $('#nb_commandes_nok').html(donnees.nb_commandes_nok+' commandes');
            else
                $('#nb_commandes_nok').html(donnees.nb_commandes_nok+' commande');
        });
    })
    
});
