/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
var oPage_products = {
    duration: 500,
    opened_products: [],
    current_opened: null,

    displayDetail: function(id_line) {
        var product = $('#product_details_'+id_line).parent().parent().find('input[name="id_product"]').val();
        if(!this.opened_products.in_array(product)) {
            this.opened_products.push(product);
            $.ajax({
                type: 'get',
                url: baseDir + 'ajax_product.php',
                async: false,
                dataType: 'json',
                data: 'ajaxGetDetails&product=' + product,
                success: function(response) {
                    // console.log(response);
                    $('#ajax_mainthumb_'+product).html(response[0]);
                    $('#ajax_thumbs_'+product).html(response[1]);
                    tb_init('a.thickbox' + product);
                }
            });
        }

        setTimeout( function() {
            $('#details_deroulant'+this.current_opened).slideUp(this.duration, null);
            // $('.product_detail_icon').removeClass('product_close_icon_uid');
            if(this.current_opened == id_line) {
                $('#product_details_'+this.current_opened).find('.more_detail,.close_detail').toggleClass('hidden');
                this.current_opened = null;
            }
            else {
                $('#details_deroulant'+id_line).slideDown(this.duration, null);
                $('#product_details_'+this.current_opened+',#product_details_'+id_line).find('.more_detail,.close_detail').toggleClass('hidden');
                this.current_opened = id_line;
                // $('#product_details_'+id_line).find('.product_detail_icon').addClass('product_close_icon_uid')
            }
            // $('#product_details_'+this.current_opened+',#product_details_'+id_line).find('.close_detail').toggleClass('hidden');
        }, 300);
    }
};

Array.prototype.in_array = function(needle, argStrict) {
    var key = '';
    var strict = !! argStrict;
     
    if (strict) {
        for (key in this) {
            if (this[key] === needle) return true;
        }
    } else {
        for (key in this) {
            if (this[key] == needle) return true;
        }
    } 
    return false;
}

function getPgQuantity(obj) {
    // récupère la quantité dans le champ de texte de la ligne concerné
    var qty = document.getElementById(obj).value;
    if(!isNaN(qty)) {
        return qty;
    } else {
        alert('Quantity must be a number');
        return 0;
    }

}



function addPgQuantity(obj) {

    var qty = getPgQuantity(obj);
    qty++;
    document.getElementById(obj).value = qty;

}





function removePgQuantity(obj) {

    var qty = getPgQuantity(obj);

    if(qty>0)
        qty--;
    document.getElementById(obj).value = qty;

}

function verif_nombre(champ)
{
    var chiffres = new RegExp("[0-9]");
    var verif;
    var points = 0;

    //alert (champ.value.length);
    for(x = 0; x < champ.value.length; x++)
    {
        verif = chiffres.test(champ.value.charAt(x));
        if(champ.value.charAt(x) == "."){
            points++;
        }
        if(points > 1){
            verif = false;
            points = 1;
        }
        if(verif == false){
            champ.value = champ.value.substr(0,x) + champ.value.substr(x+1,champ.value.length-x+1);
            x--;
        }
    }
}


    $(document).ready(function() {
        $(".qty_special_goo").val(0);
    });

