function updateWb () {}
updateWb.prototype.inStock = '<font class="PBLongTxt">En stock</font>';
updateWb.prototype.delayedStock = '<font class="PBLongTxt">Livré sous 72h</font>';
updateWb.prototype.outOfStock = '<font class="PBLongTxt">En rupture</font>';
updateWb.prototype.stockMode = false;
updateWb.prototype.testMode = false;
updateWb.prototype.exec = function () {
 
    var domElements = $('input[name^="WBFSKU"]');
    var domContainer = domElements.closest('tr');
    var thisForm = $('form[name="WBForm"]');
    if (!thisForm.length || !domElements.length) return;
    
    if ( this.testMode ) {
        var uriCourant = document.location.href,
        reg= new RegExp ("[&\\?]testMode=(\\d+)", "g"),
        infosInUrl = reg.exec(uriCourant);
        if ( !(infosInUrl && infosInUrl.length>0 && parseInt(infosInUrl[1])>0) ) return;
    }
      
    if (window.console) console.log ('updateWb triggered');  
            
    // vérification des champs obligatoires
    var thisFormTester = thisForm.serializeArray();
    var key;
    var me = this;      
    var skuList ="ws/wsGetProducts.asp?pageidx=1&pagesize=" + domElements.length;
               
    for (key in thisFormTester) {
        var reg = RegExp("WBFSKU\\[([^\\]]*)\\]","g"),
        tempName=thisFormTester[key].name,
        tempSku = reg.exec(tempName);
        if (tempSku && tempSku.length) {
            skuList += "&SKU=" + tempSku[1];
        }   
    }

    $.ajax({
        url:skuList,
        cache: false,
        dataType:'json',
        success: function(Data) {
            importInWb (Data);
        }
    });

    function importInWb (data) {

        if (!data || !data.currencies) return;
      
                
        $.each(data.products, function(key, val) {
            var thisArea = domContainer.has('input[name="WBFSKU['+ val.sku +']"]').eq(0);
            var thisZoneTorepalce = $('td:has(font.PBCurrency)', thisArea); 
            var price = '';

            if (val.priceorg != val.price)  price +=  '<div class="PBStrike">' + data.currencies.mainFormat.replace( '#', numberToPrice ( Math.ceil(val.priceorg * 100), data.currencies.thousandsSep , data.currencies.decSep) ) + '</div>';

            price +=  '<span class="PBSalesPrice">' + data.currencies.mainFormat.replace( '#', numberToPrice ( Math.ceil(100 * val.price), data.currencies.thousandsSep , data.currencies.decSep) ) + '</span>';
            if (me.stockMode) { 
               
                var HtmlTemplate = '<div class="dynamicWbZone"><span class="PBCurrency">';
                HtmlTemplate += price
                HtmlTemplate += '</span><br>';
                if ( val.outofstock ) HtmlTemplate += me.outOfStock;
                if ( val.quantity>0  && !val.outofstock ) HtmlTemplate += me.inStock;
                if ( val.quantity<=0  && !val.outofstock ) HtmlTemplate += me.delayedStock;
                HtmlTemplate += '<div>';
                
                if (thisZoneTorepalce.length) thisZoneTorepalce.html(HtmlTemplate);
                
            } else {
                
               var thisPriceTorepalce = $('font.PBCurrency', thisArea);
               if (thisPriceTorepalce.length) thisPriceTorepalce.html(price);
               thisZoneTorepalce.wrapInner('<div class="dynamicWbZone" />')
                
            }
    
        });
    }

}
