/*##############################################################################################
########################### JS DE GESTION DES PRODUITS DES MINIS BOUTIQUES ###################### 
/*############################################################################################## */

var nbMinProductsToDisplayBoutique = 2;        // Seuil min de modeles pour afficher la mb
var nbMaxOngletsToDisplayBoutique = 2;         // Seuil max d onglets MB a afficher sur la page rayon

var iMbNbItemsToDisplay = 0;                              // Nombre total d items a afficher
var aMbItems                                                            // Liste complete des items
var aMbItemsResume = new Array();                  // Liste resume des items, support pour le tri et filtrage (resume : id, marque, prix)
var aMbItemsToDisplay = new Array();                // Liste des items a afficher (apres filtrage et tri)

var iMbPagiMaxItemsPerPage = 12;                    // Nb max d items par page
var iMbPagiCurrentPage = 1;                                // Page courrante
var iMbPagiNbPages = 0;                                      // Nb total de pages

/*############################################################################################## */
/*############################################################################################## */
/*##################################### MINI BOUTIQUE ########################################### */
/*############################################################################################## */
/*############################################################################################## */

/*############################################################################################## */
 // Fonction permettant de recuperer les parametres passes dans l url a la boutique
function retriveBoutiqueUrlParameters() {
    sRequete = window.location.search.substring(1);
    tRequete = sRequete.split('&amp;');

    // Recuperation code externe rayon depuis url
    if (tRequete.length > 0) _idDepartement = tRequete[0].split('=')[1];

    // Deduction des autres parametres
    if (_idDepartement != "") {
        oHtml = document.getElementById("r" + _idDepartement + "Titre");
        if (oHtml) titreRayon = oHtml.firstChild.nodeValue;
        oHtml = document.getElementById("r" + _idDepartement + "Url");
        if (oHtml) urlRayon = oHtml.firstChild.nodeValue;
    }

}
/*############################################################################################## */
/* Determine les parametres pour la chargement des modeles en TG en fonction de la presence du cookie : modeles central OU modeles magasin*/
function loadBoutiqueConnectOrNot(cookieMagasin) {
	// cookieMagasin est null si pas de cookie magasin ou switch localStock false
              // Cas magasin               
	if (cookieMagasin !=null) {	
		idMagasin = getEltFromUrl(cookieMagasin, 'idMagasin');		
		/* On recupere d abord les dates de soldes du magasin */
		loadThirdParty(_client, THIRD_KIND_STORE, idMagasin, idMagasin);	
	}
                // Cas centrale
	else {		
		loadModelsBoutique(_siteNumber, _centralNumber, null, _idDepartement, getErepLanguageCode(_language));		
	}
}
/*############################################################################################## */
// Fonction assurant le chargement des donnees pour la mini boutique (ajax)
function loadModelsBoutique(_siteNumber, _centralNumber, _storeNumber, _idDepartement, _language) {
    // Creation du contexte
    var oContext = new JoServiceContext(_urlErep, _language, _siteNumber, _centralNumber, _storeNumber);       
    // Definition du contexte
    oContext.setDepartment(_idDepartement);    
    // Activation des filtres de donnees 
    oContext.activateDataFilter();    
    // Filtre prix, marketing et assortiement
    oContext.enableDataFilter(SERVICE_CONSTANTS.DATA_FILTER_PRICE);
    oContext.enableDataFilter(SERVICE_CONSTANTS.DATA_FILTER_MARKETING);
    oContext.enableDataFilter(SERVICE_CONSTANTS.DATA_FILTER_MIX);
    // Filtre exclusion des modeles sans donnees marketing
    oContext.enableDataFilter(SERVICE_CONSTANTS.DATA_FILTER_MRK_AVAILABILITY);
    // Filtre en fonction du type de la boutique
    setFilterTypeBoutique(typeBoutique, oContext);       
    // Creation du service
    var oService = new JoService(oContext);  
    // Execution du service
    oService.execute(POST_LOAD_BOUTIQUE_FUNCTION);     
}
/*############################################################################################## */
// Charge le bon filtre en fonction du type de la boutique
// Appellee par loadModelsBoutique 
function setFilterTypeBoutique(typeBoutique, oContext) {
 // Boutique produit bleus
    if (typeBoutique=='shop-blue-product') oContext.setModelKindFilter(SERVICE_CONSTANTS.MODEL_KIND_BLUE);
    // Boutique fin de collection
     if (typeBoutique=='shop-end-of-collection') {
        oContext.enableStepFilter(SERVICE_CONSTANTS.STEP_3);
        oContext.enableStepFilter(SERVICE_CONSTANTS.STEP_7);
        oContext.enableStepFilter(SERVICE_CONSTANTS.STEP_8);
    }
    // Boutique promo
     if (typeBoutique=='shop-promo') oContext.setPriceKindFilter(SERVICE_CONSTANTS.PRICE_KIND_PROMO);
    // Boutique soldes
    if (typeBoutique=='shop-sales') { 
        oContext.setPriceKindFilter(SERVICE_CONSTANTS.PRICE_KIND_SOLD);
        // Exclusion des modeles suivant la regle BDFR
        oContext.enableDataFilter(SERVICE_CONSTANTS.DATA_FILTER_BDFR);
        }
}
/*############################################################################################## */
// Fonction de post chargement des produits de la mini boutique 
var POST_LOAD_BOUTIQUE_FUNCTION = function postLoadBoutique(httpStatus, _joService) {

    if(httpStatus != null && httpStatus==200) {
        // On masque le message d attente
        document.getElementById("affWait").style.display = "none";
        document.getElementById("middle_boutique").style.display = "block";
    
        // Recuperation du service
        var oContent = _joService.getContent();
        if (oContent) {
    	// Recuperation de la liste d items
    	aMbItems = oContent.getItemsList();
        }

        if (!aMbItems || aMbItems.length < nbMinProductsToDisplayBoutique) {
            noProducts();
            return;
        }

        // Initialisation
        _initBoutique();

        // Affichage des blocs adequats                             
        showBlocIfCookieBoutique(cookieMagasin);  
    }
}



/*############################################################################################## */
/*############################################################################################## */
// Lance le filtrage selon la marque
// _sMarque : nom de la marque selon laquelle il faut filtrer
function filterBoutiqueByMarque(_sMarque) {
    // on efface la liste ordonnee
    aMbItemsToDisplay = new Array();

    // Recherche
    for (var i = 0; i < aMbItemsResume.length; i++) if (aMbItemsResume[i][1] == _sMarque || _sMarque =='') aMbItemsToDisplay.push(aMbItemsResume[i][0]);

    // Reactualisation nombre total d items a afficher
    iMbNbItemsToDisplay = aMbItemsToDisplay.length;
    _updateDisplayNbOfItems();

    // Init page depart
    iMbPagiCurrentPage = 1;

    // Actualisation pagination
    _updateDisplayPagination(); 

    // Affichage des items
    _deleteAllDisplayItems();
    _updateDisplayItems();
 }
/*############################################################################################## */
// Permet de synchroniser les deux filtres par marque, haut et bas
// _master : indique la box appelanre : HAUT / BAS
function synchroFiltreBoutiqueMarque(_master) {
    if (_master == 'HAUT') document.getElementById('listeMarquesBas').selectedIndex = document.getElementById('listeMarquesHaut').selectedIndex;
    else document.getElementById('listeMarquesHaut').selectedIndex = document.getElementById('listeMarquesBas').selectedIndex;

}
/*############################################################################################## */
// Lance le tri par prix, croissant
function trierBoutiquePrixCroissant() {
    aMbItemsResume.sort(_trierCroissant);
    _sortAffectResultToDisplayArray();

    // Objet html tri, actualisation
    oAtri = document.getElementById("sensTriHaut");
    oAtri.className = "trier-selectionDecroissant";
    oAtri.onclick = trierBoutiquePrixDecroissant;
    oBtri = document.getElementById("sensTriBas");
    oBtri.className = "trier-selectionDecroissant";
    oBtri.onclick = trierBoutiquePrixDecroissant;

    // Reactualisation nombre total d items a afficher
    iMbNbItemsToDisplay = aMbItemsToDisplay.length;
    _updateDisplayNbOfItems();

    // Init page depart
    iMbPagiCurrentPage = 1;

    // Actualisation pagination
    _updateDisplayPagination(); 

    // Affichage des items
    _deleteAllDisplayItems();
    _updateDisplayItems();
}
/*############################################################################################## */
// Lance le tri par prix, decroissant
function trierBoutiquePrixDecroissant() {
    // Tri
    aMbItemsResume.sort(_trierDecroissant);
    _sortAffectResultToDisplayArray();
    
    // Objet html tri, actualisation
    oAtri = document.getElementById("sensTriHaut");
    oAtri.className = "trier-selectionCroissant";
    oAtri.onclick = trierBoutiquePrixCroissant;
    oBtri = document.getElementById("sensTriBas");
    oBtri.className = "trier-selectionCroissant";
    oBtri.onclick = trierBoutiquePrixCroissant;

    // Reactualisation nombre total d items a afficher
    iMbNbItemsToDisplay = aMbItemsToDisplay.length;
    _updateDisplayNbOfItems();

    // Init page depart
    iMbPagiCurrentPage = 1;

    // Actualisation pagination
    _updateDisplayPagination(); 

    // Affichage des items
    _deleteAllDisplayItems();
    _updateDisplayItems();
}
/*############################################################################################## */
// Permet d afficher une page specifique
function jumpToPage(_pNum) {
    // Masque l ancienne page et numero
    _updateDisplayPaginationPageNum(iMbPagiCurrentPage, "UNFOCUS");
    hideBloc("mb-page-" + iMbPagiCurrentPage);

    // pour ne pas avoir deux id identiques, il faut gerer le cas de la page qui affiche tous les modeles
    if (_pNum == 0 || iMbPagiCurrentPage == 0) _deleteAllDisplayItems();

    // Le numero de page demande devient la page courrante
    iMbPagiCurrentPage = _pNum;
    
    // Affiche nouvelle page / numero
    _updateDisplayPaginationPageNum(iMbPagiCurrentPage, "FOCUS");
    _updateDisplayItems();
}
/*############################################################################################## */
// Affiche message indiquant qu aucun modele est dans la mb
function noProducts() {
    // On masque les barres de nav haut et bas            
    document.getElementById("mbNavHaut").style.display = "none";
    document.getElementById("mbNavBas").style.display = "none";
    // On afffiche le message
    oBout = document.getElementById("middle_boutique");
    oSpan = document.createElement("span");
    oSpan.className = "aucunProduit";
    oTxt = document.createTextNode(libNoProducts);
    oSpan.appendChild(oTxt);
    oBout.appendChild(oSpan);
}



/*############################################################################################## */
/*############################################################################################## */
// Initialisation de la mb. Appel unique 
function _initBoutique() {
    // Objet html, init liste des marques
    oSelectHaut = document.getElementById("listeMarquesHaut");
    oSelectHaut.options[oSelectHaut.options.length] = new Option(libAllBrands,'');
    oSelectBas = document.getElementById("listeMarquesBas");
    oSelectBas.options[oSelectBas.options.length] = new Option(libAllBrands, '');

    // Parcours de la liste des items
    for (var i=0; i<aMbItems.length; i++) {
        oItem = aMbItems[aMbItems[i]];
        // Le modele existe                      
        if (oItem != null) {
            // Etat valide        
            if (oItem.isEnable()) {
                // Recuperation des donnees marketing
                oMarketing = oItem.getMarketing();                   
                if (oMarketing) {
                    oPrice = oItem.getMainPrice();
                    oValue = oPrice.getValue();
                    
                    // Ajout aux listes supports
                    aMbItemsResume.push(new Array(oItem.getId(), oMarketing.getBrand(), oValue.getInteger() + '.' + oValue.getDecimal()));
                    aMbItemsToDisplay.push(oItem.getId());

                    // Objet html liste des marques, creation de la liste
                    trouve = false;
                    j = 0;
                    while (j < oSelectHaut.options.length && !trouve) {
                        if (oSelectHaut.options[j].value == oMarketing.getBrand()) trouve= true;
                        j++;
                    }
                if (!trouve) {
                    oSelectHaut.options[oSelectHaut.options.length] = new Option(oMarketing.getBrand(), oMarketing.getBrand());
                    oSelectBas.options[oSelectBas.options.length] = new Option(oMarketing.getBrand(), oMarketing.getBrand());
                    }
                }
            }
        }
    }

    if (aMbItemsResume.length < nbMinProductsToDisplayBoutique) {
        noProducts();
        return;
    }

    // Si pagination, page vue par défaut
    iMbPagiCurrentPage = 1;

    // Objet html liste des marque, masquage si moins de 2 marques
    if (oSelectHaut.options.length < 3) {
        hideBloc("filtrer-selectionHaut");
        hideBloc("filtrer-selectionBas");
    }

    // Objet html tri
    trierBoutiquePrixCroissant();
}
/*############################################################################################## */
// Gere l affichage des modeles
function _updateDisplayItems() {
    iMaxHeight = 0;


    // Test existance div page courrante
    oDivP = document.getElementById("mb-page-" + iMbPagiCurrentPage);
    
    // La div correspondante existe, on l affiche directement
    if (oDivP) showBloc("mb-page-" + iMbPagiCurrentPage);
    // La div correspondante n existe pas, creation
    else {
        oBoutique = document.getElementById('middle_boutique');
        oDivP = createElement_div('mb-page-' + iMbPagiCurrentPage, '', '', oBoutique);
        if (oDivP) {

            // Calcul des bornes pour la pagination
            pagiBorneInf = 0;
            pagiBorneSup = iMbNbItemsToDisplay;
            if (iMbPagiCurrentPage > 0) {
                pagiBorneInf = (iMbPagiCurrentPage - 1)  * iMbPagiMaxItemsPerPage;
                if (pagiBorneInf < 1) pagiBorneInf = 0;
                pagiBorneSup = pagiBorneInf + iMbPagiMaxItemsPerPage - 1;
                if (pagiBorneSup > (iMbNbItemsToDisplay - 1)) pagiBorneSup = iMbNbItemsToDisplay - 1;
            }


            // Ajout des modeles a la div
            for (var i = pagiBorneInf; i < pagiBorneSup + 1; i++) {
    
                    oItem = aMbItems["#"+aMbItemsToDisplay[i]+"#"];            
                    // Le modele existe                      
                    if (oItem != null) {
                        // Etat valide        
        //                if (oItem.isEnable()) {
                                // Recuperation des donnees marketing
                                oMarketing = oItem.getMarketing();                   
                                if (oMarketing) {
                                        // Nouvelle ligne tous les 3 produits qu on affecte au div global
                                        if (i % 3 == 0) {
                                            var divLigneExt = createElement_div('', 'ligneExt', '', oDivP);
                                            var divLigneInt = createElement_div('', 'ligneInt', '', divLigneExt);
                                            // Affichage trait bottom partout sauf la derniere ligne
                                            iRestant = pagiBorneSup - i + 1;
                                            // Il reste plus de 3 elts a afficher
                                            if ( (iRestant) > 3) { 
                                                divLigneExt.style.background = "url(../images/static/separ-mb-h-bottom.gif) no-repeat 6px bottom";
                                                divLigneInt.style.background = "url(../images/static/separ-mb-v3.gif) repeat-y 292px top";
                                            }
                                            else if (iRestant > 1) divLigneInt.style.background = "url(../images/static/separ-mb-v" + iRestant + ".gif) repeat-y 292px top";
                                        }

                                        // BLOC PRODUIT           
                                        // On affecte chaque bloc produit a la ligne
                                        var div1 = createElement_div('modele_'+oItem.getId(), 'box_produit_bottom', '', divLigneInt);
                                        var div2 = createElement_div('', 'box_produit', '', div1);
                                        
                                        // PARTIE GAUCHE : photo et vendu unite          
                                        var div3 = createElement_div('', 'produit', '', div2);
                                        // Photo produit
                                        if (oMarketing.getPicture()) {
                                            var p1 = createElement_p('', 'produit_visuel', '', div3);     
                                            var a1 = createElement_a('', '', '', '/'+_language+oMarketing.getSurroundedUrl('/'),p1);       
                                            var img1 = createElement_img('', '', imagesPackShootPath+'/'+oMarketing.getPicture(), oMarketing.getLiteral(), '80', '80', a1);
                                        }
                                        else {
                                            var p1 = createElement_p('', 'produit_visuel non_dispo', '', div3);
                                            var a1 = createElement_a('', 'txt_non_dispo', libNoPicture, '#',p1);       
                                        }
    
                                        // Ligne grise sous photo                    
                                        var p2 = createElement_p('', 'produit_bottom', ' ', div3);  
                                        
                                        // PARTIE DROITE HAUTE : marque - libelle - concu pour    
                                        var div4 = createElement_div('', 'description', '', div2);            
                                        var div5 = createElement_div('', 'description_top', '', div4);
                                        // Marque            
                                        var p4 = createElement_p('', 'marque', oMarketing.getBrand() , div5);    
                                        // Libelle           
                                        var p5 = createElement_p('', 'intitule', '', div5);            
                                        var a2 = createElement_a('', '', oMarketing.getLiteral(), '/'+_language+oMarketing.getSurroundedUrl('/'),p5);
                                        // Concu pour            
                                        var p5 = createElement_p('', '', libConcuPour+oMarketing.getDesignFor(), div5);    
                                        
                                        // PARTIE DROITE BASSE : prix et dispo            
                                        if (oMarketing.isPassionBrand()) _passion = 'true';
                                        else _passion = 'false';
                                        // Recuperation des infos prix stock        		    
                                        getPriceStockProduct(oItem);     
                                        // Prix
                                        if (afficheCartouchePrix == 'Y') { 
                                            var div6 = createElement_div('prixModele_'+oItem.getId(), 'description_middle','', div4);
                                            div6.innerHTML = displayPriceStockFamille(oItem.getId());
                                            if (affichePrixRouge) changeBlocClass('prixFamille_'+oItem.getId(),'prixRouge');
                                            if (kiloLitre_price != "") var p6 = createElement_p('prixKgLitre_'+oItem.getId(), 'unitPrice', kiloLitre_price, div6);
                                        }
                                        // Dispo            
                                        var div7 = createElement_div('', 'description_bottom', '', div4);        
                                        var p7 = createElement_p('', 'dispo_pdt', '', div7);          
                                        var a3 = createElement_a('', '', lib_stock, '/'+_language+oMarketing.getSurroundedUrl('/'), p7);
                                  }
                                  // Reinitialisation de certaines variables
                                  reInitPriceVars();
//                        }
                   }
    
            }


        }
    }

}
/*############################################################################################## */
// Efface tous les items
function _deleteAllDisplayItems() {
    oBoutique = document.getElementById('middle_boutique');
    if (oBoutique.hasChildNodes()) while (oBoutique.childNodes.length > 0) oBoutique.removeChild(oBoutique.firstChild);
}
/*############################################################################################## */
// Gere l affichage du nombre total de modeles
function _updateDisplayNbOfItems() {
    s = iMbNbItemsToDisplay + " ";
    if (iMbNbItemsToDisplay > 1) s +=  libProducts;
    else s +=  libProduct;
    
    oTxt = document.getElementById("mbNbProducts").childNodes;
    oTxt[0].nodeValue = s;
}
/*############################################################################################## */
// Gere l a ffichage de pa pgination
function _updateDisplayPagination() {
    bPaginationRequested =false;
    iNbPages = 0;
    
    // Calcul nb de pages
    if (iMbNbItemsToDisplay < 1) return;
    iNbPages = Math.ceil(iMbNbItemsToDisplay / iMbPagiMaxItemsPerPage);

        // On efface l ancien contenu
        oPagiHaut = document.getElementById('mbNumPagesHaut');
        if (oPagiHaut.hasChildNodes()) while (oPagiHaut.childNodes.length > 0) oPagiHaut.removeChild(oPagiHaut.firstChild);
        oPagiBas = document.getElementById('mbNumPagesBas');
        if (oPagiBas.hasChildNodes()) while (oPagiBas.childNodes.length > 0) oPagiBas.removeChild(oPagiBas.firstChild);


        // On affiche la pagination seulement si le nb de pages > 1
        if (iNbPages > 1) {
            bPaginationRequested =true;
            for (var i=1; i < iNbPages + 1; i++) {
                myClass = "";
                if (iMbPagiCurrentPage == i) myClass = "active";
                // Liste du haut
                oA = createElement_a("pagiHaut_"+i, myClass, i, "", oPagiHaut);
                    oA.onclick = JUMP_FUNCTION;
                // Liste du bas
                oAb = createElement_a("pagiBas_"+i, myClass, i, "", oPagiBas);
                    oAb.onclick = JUMP_FUNCTION;
            }
            visibleBloc("mbPaginationHaut");
            visibleBloc("mbPaginationBas");
        }
        else {
            invisibleBloc("mbPaginationHaut");
            invisibleBloc("mbPaginationBas");
        }
        
        return bPaginationRequested;
}
/*############################################################################################## */
// Permet de passer a une page specifique
var JUMP_FUNCTION = function () {
    myP = this.id.split("_");
    if (myP[1] != iMbPagiCurrentPage) jumpToPage(myP[1]);
}
/*############################################################################################## */
// Met en focus / unfocus le numero de page
// _numPage : numero de page concerne
// _display : FOCUS / UNFOCUS
function _updateDisplayPaginationPageNum(_numPage, _display) {
    oA = document.getElementById("pagiHaut_" + _numPage);
    oB = document.getElementById("pagiBas_" + _numPage);
    if (oA && oB) {
        if (_display == "FOCUS") {
            oA.className = "active";
            oB.className = "active";
        }
        else {
            oA.className = "";
            oB.className = "";
        }
    }
}
/*############################################################################################## */
// Fct interne, pour le tri
function _trierCroissant(x1,x2) { 
    return ( parseFloat(x1[2]) > parseFloat(x2[2]))? 1 : -1;
}
/*############################################################################################## */
// Fct interne, pour le tri
function _trierDecroissant(x1,x2) { 
    return ( parseFloat(x1[2]) < parseFloat(x2[2]))? 1 : -1;
}
/*############################################################################################## */
// Fct interne, pour le tri (affectation des resultats)
function _sortAffectResultToDisplayArray() {
    tmpTabOrdered = aMbItemsToDisplay;
    aMbItemsToDisplay = new Array();

    for (var i=0; i < aMbItemsResume.length; i++) {
        for (var j=0; j < tmpTabOrdered.length; j++) {
            if (aMbItemsResume[i][0] == tmpTabOrdered[j]) aMbItemsToDisplay.push(tmpTabOrdered[j]);
        }
    }
}





/*############################################################################################## */
/*############################################################################################## */
/*####################################### RAYON ################################################ */
/*############################################################################################## */
/*############################################################################################## */

/*############################################################################################## */
// Appelee :
// - si le rayon possede au moins 1 lien interne poitant vers une mini-boutique
// - et switch MINI_BOUTIQUE active pour le site
// - apres le chargement des modeles et le calcul de ceux autorises (apres getAffichageTGRayon) si le rayon possede des TG  (PSI_QMODELS_ARRAY.length>0)
// ou dans la post chargement des switchs (postSwitchAction) si le rayon ne possede pas de TG (PSI_QMODELS_ARRAY.length=0)
// - afin de recuperer la cardinalite (nombre de produits autorises) de la boutique pour le rayon dans le bon contexte (magasin ou centrale) 
function loadCardinaliteBoutiqueConnectOrNot(cookieMagasin) {  
    // cookieMagasin est null si pas de cookie magasin ou switch localStock false
    // Cas magasin               
    if (cookieMagasin !=null) {	
        idMagasin = getEltFromUrl(cookieMagasin, 'idMagasin');	
        loadCardinaliteBoutique( _siteNumber, _centralNumber, idMagasin, _idDepartement, getErepLanguageCode(_language));	
    }
    // Cas centrale
    else {
        loadCardinaliteBoutique( _siteNumber, _centralNumber, null, _idDepartement, getErepLanguageCode(_language));
    }
 }
 /*############################################################################################## */
// Fonction assurant la recuperation de la cardinalite pour la mini boutique du rayon (ajax)
function loadCardinaliteBoutique(_siteNumber, _centralNumber, _storeNumber, _idDepartement, _language) {
     // Creation du contexte
    var oContext = new JoServiceContext(_urlErep, _language, _siteNumber, _centralNumber, _storeNumber);
    // Definition du contexte
    oContext.setFamilies(_idDepartement);     
     // Activation des filtres 
    oContext.activateDataFilter();    
    // Filtre cardinalites
    oContext.enableDataFilter(SERVICE_CONSTANTS.DATA_FILTER_CARDINALITY);
    // Filtre exclusion des modeles sans donnees marketing
    oContext.enableDataFilter(SERVICE_CONSTANTS.DATA_FILTER_MRK_AVAILABILITY);
    // Creation du service
    var oService = new JoService(oContext);
    // Execution du service
    oService.execute(POST_LOAD_CARD_BOUTIQUE_FUNCTION);
}
  /*############################################################################################## */
 // Fonction de post chargement de la cardinalite de la mini boutique 
// On y gere l affichage des onglets sur la page rayon
var POST_LOAD_CARD_BOUTIQUE_FUNCTION = function postLoadCardBoutique(httpStatus, _joService) {
    if(httpStatus != null && httpStatus==200) {
    
        // Recuperation des cardinalites du service
        var oCardinalities = _joService.getCardinality();              
        var cardBoutique = 0;
        
        // Nombre de MB ayant un nb de modeles superieur au seuil min
        var nbBoutiqueOk = 0;
        
        if (oCardinalities) {      
            for (var i=0;i<tabTypeBoutique.length;i++) {
            
                if (nbBoutiqueOk < nbMaxOngletsToDisplayBoutique) {
                    // Recuperation des cardinalites pour chaque type de boutique
                    if (tabTypeBoutique[i]=='shop-blue-product') {
                        var oCard  = oCardinalities.getCardinality(SERVICE_CONSTANTS.CARD_KIND_MODEL_KIND, SERVICE_CONSTANTS.CARD_MODEL_KIND_BLUE);
                        if (oCard) cardBoutique = oCard.getModelCardinality();
                    }
                    if (tabTypeBoutique[i]=='shop-end-of-collection') {
                        var oCard1  = oCardinalities.getCardinality(SERVICE_CONSTANTS.CARD_KIND_STEP, SERVICE_CONSTANTS.STEP_3);
                        if (oCard1) cardBoutique += (oCard1.getModelCardinality())*1;       
                        var oCard2  = oCardinalities.getCardinality(SERVICE_CONSTANTS.CARD_KIND_STEP, SERVICE_CONSTANTS.STEP_7);
                        if (oCard2) cardBoutique += (oCard2.getModelCardinality())*1; 
                        var oCard3  = oCardinalities.getCardinality(SERVICE_CONSTANTS.CARD_KIND_STEP, SERVICE_CONSTANTS.STEP_8);
                        if (oCard3) cardBoutique += (oCard3.getModelCardinality())*1; 
                    }
                    if (tabTypeBoutique[i]=='shop-promo') {
                        var oCard  = oCardinalities.getCardinality(SERVICE_CONSTANTS.CARD_KIND_PRICE_KIND, SERVICE_CONSTANTS.PRICE_PROMO);
                        if (oCard) cardBoutique = oCard.getModelCardinality();                
                    }
                        if (tabTypeBoutique[i]=='shop-sales') {
                        var oCard  = oCardinalities.getCardinality(SERVICE_CONSTANTS.CARD_KIND_PRICE_KIND, SERVICE_CONSTANTS.PRICE_SOLD);
                        if (oCard) cardBoutique = oCard.getModelCardinality();                
                    }
                      
                    // Affichage des onglets boutique si cardinalite > nb de produits definis dans nbMinProductsToDisplayBoutique
                    if (cardBoutique>nbMinProductsToDisplayBoutique) {
                        nbBoutiqueOk  = nbBoutiqueOk + 1;
                        showBloc('ongletBoutique_'+(i+1));

                        // On reaffecte le lien mb soldes vers boutique soldes
                        if (getSwitchSite('SHOP_SALES') && tabTypeBoutique[i] == "shop-sales") {
                            var iMyCpt = i+1;                         
                            oL = document.getElementById("zoneBoutiqueLink_" + iMyCpt);
                            if (oL) {
                                try {
                                    var sTheUrl = oL.href;
                                    var sTheRayonId = sTheUrl.substring(sTheUrl.indexOf("?idRayon="));
                                    oL.href = shopUrl + sTheRayonId; 
                                }
                                catch (e) {}
                            }
                        }

                        // Si pas de TG ou aucune TG autorisees : c est l onglet boutique qui est le premier actif                
                        if (tabPrdTg.length==0 && idOngletActif=='') {
                            idOngletActif='men'+(i+2);  	
                            idContenuOngletActif='zoneBoutique_'+(i+1);       
                            showBloc('zoneBoutique_'+(i+1));
                            //changeBlocClass('ongletBoutique_'+(i+1), 'onglet1 premier actif ongletBoutique_'+tabTypeBoutique[i]);
                            changeBlocClass('men'+(i+2), 'actif');
                        }
                    }
                    
                    // Reinitialisation pour traitement de la prochaine boutique
                    cardBoutique = 0;
                }
                
            }      
        }                   
        
    }        
}
/*############################################################################################## */
 // Fonction permettant de construire le lien vers une mini-boutique
function createLinkToBoutique(_url, _idRayon, _rangLien) {
    lnkOutput = _url + '?idRayon=' + _idRayon;
    myA = document.getElementById("zoneBoutiqueLink_" + _rangLien);
    if (myA) myA.href = lnkOutput;
}