/*##############################################################################################
############# JS DES FONCTIONS D APPEL DE CHARGEMENT AJAX DES XML ET DE POST CHARGEMENT ####### 
#################################### POUR LA PARTIE PRICE ##################################### */
var PSI_QMODELS_ARRAY = new Array();
var MAX_LOAD_MODELS = 20; // sert a eviter de depasser la limite de caracteres d une requete GET
var desactiveAffichageProduit='N';
var afficheCartouchePrix='Y';
var casmagasin = false;
var libelle = '';
var gamme = 1;
var stock='';
var lib_stock='';
var valeur_stock='';
var main_price='';
var main_price_integer='';
var main_price_decimal='';
var currencySymbol='';
var currencyCode='';
var isPromoOrSoldPrice = false;
var isSoldPrice = false;
var cacheListeArticles = false;
var libellebis = '';
var etape='';
var dateDebut='';
var dateFin='';
var markdown='';
var strike_price='';
var affichePrixRouge=false;
var afficheBDFR2 = false;
var weee_price='';
var itemId='';
var kiloLitre_price='';
var itemFamR3Id = '';

/*############################################################################################## */
/* Reinitalise certaines variables globales servant pour les prix pouvant ne pas etre ecrasees par une nouvelle valeur : utile dans le cas des tg */
function reInitPriceVars() {
            desactiveAffichageProduit='N';
            afficheCartouchePrix='Y';
            gamme=1;
            isPromoOrSoldPrice = false;
            isSoldPrice = false;
            cacheListeArticles = false;
            libellebis = '';
            dateDebut='';
            dateFin='';
            markdown='';
            affichePrixRouge=false;
            afficheBDFR2 = false;
            strike_price='';
            kiloLitre_price='';
            weee_price='';
}
/*############################################################################################## */
/* Liste des actions a executer apres la recuperation des infos du modele pour la page modele classic */
var POST_LOAD_MODEL_SERVICE_FUNCTION = function postModelService(httpStatus, _joService) {
          if(httpStatus != null && httpStatus==200) {     
        	        // Recuperation du modele
        	        var oContent = _joService.getContent();
        	        if(oContent != null){
                           var oItem = oContent.getItem(_modelId);
                           var oContext = _joService.getContext();
                           var _storeNumber = oContext.iStoreId;
                           // Le modele existe                      
        	            if (oItem != null) {
        		// Etat valide
        		if (oItem.isEnable()) {        		
        		    // Recuperation des infos prix stock
        		    getPriceStockProduct(oItem);
                                // IDentifiant R3/Masterdata de la famille correspondante
                                itemFamR3Id = oItem.getFamilyId();
                                //Ventes de substitution - On les propose lorsque on est connecte et que le modele / article n est pas en gamme ou sans stock
                                if (cookieMagasin!=null && getSwitchSite('VENTES_SUBSTITUTION') && (oItem.isUnavailable() || oItem.isPartiallyAvailable()) && casmagasin ) {
                                    loadVs(_siteNumber, _centralNumber, _storeNumber, _modelId, _language,main_price_integer+"."+main_price_decimal, typologie, modeleFamilleId);
                                }
        		    // Recuperation des articles du modele          		    
        		    getDeclinaisons(oItem, _language);
        		}
                             //  Etat non valide
                             else {                           
                                     desactiveAffichageProduit = 'Y';
                                     if (cookieMagasin!=null) casmagasin=true;                                
                              }	
                         // Le modele n existe pas
                        }else {
                                desactiveAffichageProduit = 'Y';
                                if (cookieMagasin!=null) casmagasin=true;
                        }                       
                            // Affichage du prix et du prix au litre ou au kilo                       
                           if (afficheCartouchePrix=='Y') {
                               setBlocByHtml('prixModele',displayPriceStockModele());
                               if (kiloLitre_price!='') {
                                       setBlocByHtml('prixKgLitre',kiloLitre_price);        
                                       showBloc('prixKgLitre');
                               }
                           }
                           else {
                               if(cookieMagasin==null) hideBloc ("blocPrixTpsReel");
                               hideBloc ("blocPrix");
                           }
                       }
                       else{
                           desactiveAffichageProduit = 'Y';
                           if (cookieMagasin!=null) casmagasin=true;
                       }
                            // Affichage des blocs adequats
            	            showBlocModeleClassic();
                           showBlocIfCookieModeleClassic(cookieMagasin);
               }             
}
/*############################################################################################## */
/* Liste des actions a executer apres la recuperation des infos des modeles en TG ou Produit hero de la famille */
var POST_LOAD_MODELS_SERVICE_FUNCTION = function postModelsService(httpStatus, _joService) {
          if(httpStatus != null && httpStatus==200) {
        	        // Recuperation des modeles
                      var oContent = _joService.getContent();
                      if(oContent != null){
                      var listItems = oContent.getItemsList();
        	       for (var i=0; i<listItems.length; i++) {
        	           var oItem = listItems[listItems[i]];
        	            // Le modele existe
        	            if (oItem != null) {
        		// Etat valide
        		if (oItem.isEnable()) {
        		     // Reinitialisation de certaines variables
                                  reInitPriceVars();
        		    // Recuperation du flag marque passion
        		     _passion = getBlocHtml('isPassion_'+oItem.id);
        		      // Recuperation de valeur unite et valeur poids pour prix au litre ou kilo
        		     valeurPoids = getBlocHtml('poids_'+oItem.id);
        		     valeurUnite = getBlocHtml('unite_'+oItem.id);
        		     // Recuperation des infos prix stock
        		    getPriceStockProduct(oItem);
        		    // Pour les TG Homepage, page Rayon ou Homepage marque et VS modele : affichage prix et prix au litre ou au kilo
        		    if ((typePage=='homepage' || typePage=='rayon' || typePage=='HPMarque' || typePage=='modele-vc' || (typePage=='modele' && PSI_QMODELS_ARRAY.length > 0)) && afficheCartouchePrix=='Y') {
                		     setBlocByHtml('ct-prix_'+oItem.id,displayPriceStockTg(oItem.id));   
                		     if (kiloLitre_price!='') {
                		         setBlocByHtml('prixKgLitreTG_'+oItem.id, kiloLitre_price);   
                		         showBloc('prixKgLitreTG_'+oItem.id);
                		     }
                                  }
                                  // Pour le Produit hero de la page Famille : affichage prix et dispo et prix au litre ou au kilo
                                  if (typePage=='famille-hero' && afficheCartouchePrix=='Y') {                                                 
                		    setBlocByHtml('ct-prix_'+oItem.id,displayPriceStockProduitHero(oItem.id));           
                		    setBlocByHtml('disponibilite-hero_'+oItem.id, lib_stock);                
                		    if (kiloLitre_price!='') {
                		        setBlocByHtml('prixKgLitreHero_'+oItem.id, kiloLitre_price);  
                		        showBloc('prixKgLitreHero_'+oItem.id);
                		    }
                                  }
                                  // Pour prix rouge
                                 if (affichePrixRouge){
                                             changeBlocClass('prixTG_'+oItem.id,'prixRouge');
                                 }
                                  // Ajout au tableau des modeles autorises a s afficher
                                  tabPrdTg[nbProdTg]='product_'+oItem.id;
                                  nbProdTg++;
        		}
        	            }
                     }
                     }
                     // Affichage des modeles
                     getAffichageModels();
          }
}
/*############################################################################################## */
/* Appelle les bonnes fonctions en fonction du type de page (homepage, rayon, ...) */
function getAffichageModels(){
    // Affichage des blocs adequats
    switch(typePage){
        case 'homepage' : getAffichageTGHP(tabPrdTg);break;
        case 'rayon' : 
            getAffichageTGRayon(tabPrdTg);
            if (tabTypeBoutique.length > 0 && getSwitchSite('THEMATIC_SHOPS')) loadCardinaliteBoutiqueConnectOrNot(cookieMagasin);
            break;
        case 'HPMarque' : getAffichageTGBrandHP(tabPrdTg);break;
        case 'famille-hero' : 
           typePage = 'famille';
           getAffichageProduitHero(tabPrdTg);
           loadFamilyConnectOrNot(cookieMagasin);
           break;
        case 'modele-vc' : getAffichageVc(tabPrdTg);break;
        case 'modele' : getAffichageVsModele(tabPrdTg);break;
        case 'dktTv' : 
            for (var ref in videosModele) {
                // On montre la vignette produit associee
                for(var j=0; j < videosModele[ref].length; j++) // Parcours des differentes videos associees au produit
                    showBloc(videosModele[ref][j] + '_' + ref);
            }
            break;
    }
}
/*############################################################################################## */
/* Liste des actions a executer apres la recuperation des infos des modeles de la famille */
var POST_LOAD_FAMILY_SERVICE_FUNCTION = function postFamilyService(httpStatus, _joService) {
            if(httpStatus != null && httpStatus==200) {   
                    // Liste des marques
                    if (document.getElementById('listeMarquesHaut') && document.getElementById('listeMarquesBas')) {
    	          var listeDistinctMarquesEnable='';
                         var lmh = document.getElementById('listeMarquesHaut');
                         var lmb = document.getElementById('listeMarquesBas');
                         // Vide la liste des marques haut et bas en ne laissant que la 1ere ligne avec le texte toutes les marques
                         lmh.options.length = 1;
                         lmb.options.length = 1;
                     }
                     // Recuperation des modeles
                     var oContent = _joService.getContent();
                     if(oContent != null){
                         var listItems = oContent.getItemsList();
                     
        	          for (var i=0; i<listItems.length; i++) {
        	               var oItem = listItems[listItems[i]];
        	                // Le modele existe
        	                if (oItem != null) {
        		    // Etat valide
        		    if (oItem.isEnable() && oItem.id != refPrdHero) {
        		       // Reinitialisation de certaines variables
                                    reInitPriceVars();
        		      // Recuperation du flag marque passion
        		     _passion = getBlocHtml('isPassion_'+oItem.id);          	
        		     // Recuperation de valeur unite et valeur poids pour prix au litre ou kilo
        		     valeurPoids = getBlocHtml('poids_'+oItem.id);    
        		     valeurUnite = getBlocHtml('unite_'+oItem.id);         		     
        		     // Recuperation des infos prix stock
        		     getPriceStockProduct(oItem);
                                   // Affichage du prix et stock et du prix au litre ou au kilo
                                   if (afficheCartouchePrix=='Y') {
                                     setBlocByHtml('ct-prix-famille_'+oItem.id,displayPriceStockFamille(oItem.id));                                       
                                     setBlocByHtml('disponibilite-famille_'+oItem.id, lib_stock);    
                                     if (kiloLitre_price!='') {
                                         setBlocByHtml('prixKgLitre_'+oItem.id, kiloLitre_price);    
                                         showBloc('prixKgLitre_'+oItem.id);
                                     }
                                 }
                                 // Pour prix rouge                                
                                 if (affichePrixRouge){
                                       changeBlocClass('prixFamille_'+oItem.id,'prixRouge');
                                 }                                 
                                  // Remplissage de la matrice de dimension des produits autorises a s afficher         		     
        		    tabPrd[nbProd]=new Array();
        		     // col1 : id modele
                                 tabPrd[nbProd][0]='product-famille_'+oItem.id;                               
                                 // col2 : 1 si prd bleu - 0 sinon
                                 if (getBlocHtml('isProduitBleu_'+oItem.id)=='') tabPrd[nbProd][1]=0;                               
                                 else tabPrd[nbProd][1]=1;         
                                 // col3 : libelle marque
                                 tabPrd[nbProd][2]= getBlocHtml('libelleMarque_'+oItem.id); 
                                 // col4 : 1 si etape 3 - 0 sinon
                                 if (etape==3 || etape==7 || etape==8) tabPrd[nbProd][3]=1;
                                 else tabPrd[nbProd][3]=0;                                 
                                 // Ajout de la marque a la liste des marques distinctes des produits autorises a s afficher
                                 if (document.getElementById('listeMarquesHaut') && document.getElementById('listeMarquesBas')) {
                                     if (listeDistinctMarquesEnable.indexOf(tabPrd[nbProd][2])==-1 && tabPrd[nbProd][2]!=false) {
                                         listeDistinctMarquesEnable += tabPrd[nbProd][2]+';';
                                         lmh.options[lmh.options.length] = new Option(tabPrd[nbProd][2], tabPrd[nbProd][2]);
                                         lmb.options[lmb.options.length] = new Option(tabPrd[nbProd][2], tabPrd[nbProd][2]);
                                     }
                                 }
                                 nbProd++;
        		}
        	            }
        	        }
        	     }
                remplissagePage();
            }
}
/*############################################################################################## */
/* Liste des actions a executer apres la recuperation des infos des modeles du gdbc de la famille */
var POST_LOAD_FAMILY_GDBC_SERVICE_FUNCTION = function postFamilyGdbcService(httpStatus, _joService) {
            if(httpStatus != null && httpStatus==200) {
                     // Recuperation des modeles
                     var oContent = _joService.getContent();
                     var listItems = oContent.getItemsList();
        	      for (var i=0; i<listItems.length; i++) {        	             	       
        	           var oItem = listItems[listItems[i]];
        	            // Le modele existe           	      
        	            if (oItem != null) {       
        		// Etat valide        		
        		if (oItem.isEnable()) {             		
        		      // Recuperation du flag marque passion
        		     _passion = getBlocHtml('isPassion_'+oItem.id);      
        		      // Recuperation de valeur unite et valeur poids pour prix au litre ou kilo
        		     valeurPoids = getBlocHtml('poids_'+oItem.id);    
        		     valeurUnite = getBlocHtml('unite_'+oItem.id);    
        		     // Recuperation des infos prix stock        		    
        		    getPriceStockProduct(oItem);          		   
                                 // Affichage du prix et du prix au litre ou au kilo                                
                                 if (afficheCartouchePrix=='Y') {
                                     setBlocByHtml('ct-prix-gdbc_'+oItem.id,displayPriceStockGdbc(oItem.id)); 
                                      if (kiloLitre_price!='') {
                                         setBlocByHtml('prixKgLitre_'+oItem.id, kiloLitre_price);  
                                         showBloc('prixKgLitre_'+oItem.id);
                                     }
                                 }
                                 // Pour prix rouge
                                 if (affichePrixRouge){
                                       changeBlocClass('prixComparaison_'+oItem.id,'prixRouge');
                                 }    
                                 // Reinitialisation de certaines variables
                                 reInitPriceVars();
                                 
                             // Affichage de la colonne du modele si present dans gdbcItemsToShow ou si cette derniere est vide
                            if (gdbcItemsToShow.contains(oItem.id) > -1 || gdbcItemsToShow.length() < 1) {
                                showBloc('modele_info_'+oItem.id);
                                showBloc('modele_autre_'+oItem.id);
                                showBloc('modele_bu_'+oItem.id);
                             }
                        }
                    }
                }
            }
}
/*############################################################################################## */
/* Liste des actions a executer apres la recuperation des infos de l article */
var POST_LOAD_ARTICLE_SERVICE_FUNCTION = function postArticleService(httpStatus, _joService) {
              if(httpStatus != null && httpStatus==200) {                          
	        // Recuperation de l article
	        var oContent = _joService.getContent();
                       var listItems = oContent.getItemsList();
                       var oItem = listItems[listItems[0]];
                       // Recuperation de la date d'execution
                       var serverDate = _joService.getHeader().getTime();
                       // L article existe
                       if (oItem != null) {    
                                // Reinitialisation de certaines variables
                                reInitPriceVars();
                               // Recuperation du flag passion de l article
                               _passion = getBlocHtml('marquePassion');
                               // Cas centrale : mise a jour du cartouche prix
                               if (cookieMagasin==null) {             
                                    // Recuperation des infos prix stocks
                                   getPriceStockProduct(oItem);
                                    // Affichage du prix
                                   setBlocByHtml('prixModele',displayPriceStockModele());
                                    if (getSwitchSite('ALSOLIA')) {
                                        getAlsolia();
                                    }
                                    if (affichePrixRouge){
                                        changeBlocClass("prixModele_"+_modelId,"prixRouge");
                                    }
                              }
                              // Cas magasin : ouverture div prix stock local
                              else {
                                    // HOT_DATA a true                                         
                                    if (getSwitchSite('HOT_DATA')) {
                                        // Etat valide
                                        if (oItem.isEnable()) {
                                            // Recuperation des infos article
                                            getPriceStockProduct(oItem);
                                            if(stock == 2 && getSwitchSite('STOCK_MULTI_MAG')){
                                                // Article indisponible : visualisation stock multi-magasins
                                                showPsdButton();
                                            }
                                            else{
                                                // Retourne gabarit du div prix stock local 
                                                openLiveStock();                		               
                                                // Remplissage des blocs et affichage de la div                                                            
                                                displayLiveStock(serverDate);
                                            }
                                        }
                                        //  Etat non valide
                                        else {                           
                                            alert(locaPriceServiceIndispo);               
                                        }
                                    }
                                    // HOT_DATA a false
                                    else {
                                        alert(locaPriceServiceIndispo);
                                    }
                              }                             
                       }
              }
}
/*############################################################################################## */
/* Determine les parametres pour le chargement du modele en fonction de la presence du cookie : modele central OU modele magasin*/
function loadModelConnectOrNot(cookieMagasin, languageCode) {
	// 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 {	
		loadModel(_client, _siteNumber, _centralNumber, null, _modelId, languageCode);
	}
}
/*############################################################################################## */
/* Determine les parametres pour le chargement des modeles en TG en fonction de la presence du cookie : modeles central OU modeles magasin*/
function loadModelsConnectOrNot(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 {
		loadModels(_client, _siteNumber, _centralNumber, null);
	}
}
/*############################################################################################## */
/* Determine les parametres pour le chargement des modeles de la famille en fonction de la presence du cookie : modeles central OU modeles magasin*/
function loadFamilyConnectOrNot(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 {	
		loadFamily(_client, _siteNumber, _centralNumber, null, _familyId, true);
	}
}
/*############################################################################################## */
/* Charge le modele (centrale OU magasin) */
function loadModel(_client, _siteNumber, _centralNumber, _storeNumber, _modelId, _language,_localFunc) {
             // Creation du contexte
             var oContext = new JoServiceContext(_urlErep,getErepLanguageCode( _language), _siteNumber, _centralNumber, _storeNumber);
             oContext.setModel(_modelId);
             // Activation des filtres de donnees 
             oContext.activateDataFilter();    
             // Filtres prix, assortiement, enfants, declinaisons, substitution
             oContext.enableDataFilter(SERVICE_CONSTANTS.DATA_FILTER_PRICE);
             oContext.enableDataFilter(SERVICE_CONSTANTS.DATA_FILTER_MIX);
             oContext.enableDataFilter(SERVICE_CONSTANTS.DATA_FILTER_CHILDREN);
             oContext.enableDataFilter(SERVICE_CONSTANTS.DATA_FILTER_VARIATIONS);
             oContext.enableDataFilter(SERVICE_CONSTANTS.DATA_FILTER_SUBSTITUTE);
             
             var oService = new JoService(oContext);
             if(!_localFunc){
                 _localFunc = POST_LOAD_MODEL_SERVICE_FUNCTION;
             }
             // Si le service ne s execute pas on lance les fonctions gerant l affichage des differents blocs
             if(!oService.execute(_localFunc)){
                 if(_localFunc == POST_LOAD_MODEL_SERVICE_FUNCTION){
                     cacheListeArticles = true;
                    // Affichage des blocs adequats
                    showBlocModeleClassic();
                    showBlocIfCookieModeleClassic(cookieMagasin);
                }
                // pour DktTv
                priceToDisplay = '';
             }
}
/*############################################################################################## */
/* Charge les modeles des TG (centrale OU magasin) */
function loadModels(_client, _siteNumber, _centralNumber, _storeNumber,_localFunc) {
             // Creation du contexte
             var oContext = new JoServiceContext(_urlErep, getErepLanguageCode( _language), _siteNumber, _centralNumber, _storeNumber);
             oContext.setModels();
             // Activation des filtres de donnees 
             oContext.activateDataFilter();    
             // Filtres prix, assortiement
             oContext.enableDataFilter(SERVICE_CONSTANTS.DATA_FILTER_PRICE);
             oContext.enableDataFilter(SERVICE_CONSTANTS.DATA_FILTER_SUBSTITUTE);
             oContext.enableDataFilter(SERVICE_CONSTANTS.DATA_FILTER_MIX);
             
             for (i=0; i < PSI_QMODELS_ARRAY.length; i++) {
		oContext.addModels(PSI_QMODELS_ARRAY[PSI_QMODELS_ARRAY[i]]);
             }
             var oService = new JoService(oContext);
             if(!_localFunc){
                 _localFunc = POST_LOAD_MODELS_SERVICE_FUNCTION;
             }
             // Si le service ne s execute pas on traite les modeles entres dans le tableau PSI_QMODELS_ARRAY
             if(!oService.execute(_localFunc)){
                 if(_localFunc == POST_LOAD_MODELS_SERVICE_FUNCTION)
                     for (var i=0; i < PSI_QMODELS_ARRAY.length; i++) tabPrdTg[i] = 'product_'+PSI_QMODELS_ARRAY[PSI_QMODELS_ARRAY[i]];
                 getAffichageModels();
             }
             
}
/*############################################################################################## */
/* Charge les modeles des TG (centrale OU magasin) */
function loadFamily(_client, _siteNumber, _centralNumber, _storeNumber, _familyId) {
             // Creation du contexte
             var oContext = new JoServiceContext(_urlErep,getErepLanguageCode( _language), _siteNumber, _centralNumber, _storeNumber);
             oContext.setFamily(_familyId);
             // Activation des filtres de donnees 
             oContext.activateDataFilter();    
             // Filtres prix, assortiement, substitution
             oContext.enableDataFilter(SERVICE_CONSTANTS.DATA_FILTER_PRICE);
             oContext.enableDataFilter(SERVICE_CONSTANTS.DATA_FILTER_MIX);
             oContext.enableDataFilter(SERVICE_CONSTANTS.DATA_FILTER_SUBSTITUTE);
             
             // Filtre prix min et prix max passes en parametres dans l url
             var urlParams = document.location.search;
             var min = '';
             var max = '';
             if(urlParams.indexOf('min=') != -1) {
                 min = urlParams.substr(urlParams.indexOf('min=') + 4);
                 if(min.indexOf('&') != -1) min = min.substring(0,min.indexOf('&'));
             }
             if(urlParams.indexOf('max=') != -1) {
                 max = urlParams.substr(urlParams.indexOf('max=') + 4);
                 if(max.indexOf('&') != -1) max = max.substring(0,max.indexOf('&'));
             }
             if(min || max) {
                 oContext.setPriceRangeFilter(min, max);
             
                 document.forms["formFiltrerPrix"].min.value = unescape(min);
                 document.forms["formFiltrerPrix"].max.value = unescape(max);
                 if(max == '') {
                     var prixMin = aPartirDe + '<span class="valeur-filtre-prix">&nbsp;';
                     if(_siteNumber == '52333') prixMin += devise + '&nbsp;' + min;
                     else prixMin += min + '&nbsp;' + devise;
                     prixMin += '</span>';
                     setBlocByHtml('resultFiltrePrix',prixMin);
                 }
                 else if(min == '') {
                     var prixMax = jusque + '<span class="valeur-filtre-prix">&nbsp;';
                     if(_siteNumber == '52333') prixMax +=  devise + '&nbsp;' + max;
                     else prixMax += max + '&nbsp;' + devise;
                     prixMax += '</span>';
                     setBlocByHtml('resultFiltrePrix',prixMax);
                 }
                 else {
                     var resultFiltrePrix = getBlocHtml('resultFiltrePrix');
                     resultFiltrePrix = resultFiltrePrix.replace("#prixDe", min);
                     resultFiltrePrix = resultFiltrePrix.replace("#prixA", max);
                     setBlocByHtml('resultFiltrePrix',resultFiltrePrix);
                 }
                 showBloc('result-filtre');
             }

             var oService = new JoService(oContext);
             if (typePage=='famille') {
                 // Si le service ne s execute pas : on affiches les produits de la famille presents dans itool
	   if(!oService.execute(POST_LOAD_FAMILY_SERVICE_FUNCTION)) displayFamilyProducts();
             }
             if (typePage=='famille-gdbc') {
                 // Creation des blocs modeles dans la page gdbc
                 createGdbcProducts();
                 // Si le service ne s execute pas on affiche les blocs des modeles
	  if(!oService.execute(POST_LOAD_FAMILY_GDBC_SERVICE_FUNCTION))
	      for(var i=0;i<gdbcItemsToShow.length();i++){
	          showBloc('modele_info_'+gdbcItemsToShow.get(i));
	          showBloc('modele_autre_'+gdbcItemsToShow.get(i));
	          showBloc('modele_bu_'+gdbcItemsToShow.get(i));
                    }
             }
             if (typePage=='modele') {
                 // Si le service ne s execute pas on affiche le slideshow dans l ordre itool
	   if(!oService.execute(POST_FAMILY_MODELE_SLIDESHOW_SERVICE_FUNCTION)){
	       slideshowSortMethod = "ITOOL";
	       getAffichageSlideshow(null);
	   }
             }	
}
/*############################################################################################## */
/* Charge l article (centrale OU magasin) */
function loadArticle(_client, _siteNumber, _centralNumber, _storeNumber, _articleId, _language) {
             // Creation du contexte
             var oContext = new JoServiceContext(_urlErep, getErepLanguageCode( _language), _siteNumber, _centralNumber, _storeNumber);
             oContext.setArticle(_articleId);
             // Activation des filtres de donnees 
             oContext.activateDataFilter();    
             // Filtres prix, assortiement, hot_data
             oContext.enableDataFilter(SERVICE_CONSTANTS.DATA_FILTER_PRICE);
             oContext.enableDataFilter(SERVICE_CONSTANTS.DATA_FILTER_MIX);
             oContext.enableDataFilter(SERVICE_CONSTANTS.DATA_FILTER_HOT_DATA);
             
             var oService = new JoService(oContext);
             oService.execute(POST_LOAD_ARTICLE_SERVICE_FUNCTION);
}
/*############################################################################################## */
/* Retourne le format des dates */
function getFormatDate() {
                if(formatDate == 1)  
                    return SERVICE_CONSTANTS.DATE_FORMAT_DD_MM_YY;     
                else if(formatDate == 2) 
                    return SERVICE_CONSTANTS.DATE_FORMAT_YY_MM_DD;              
                else if(formatDate == 3) 
                    return SERVICE_CONSTANTS.DATE_FORMAT_MM_DD_YY;           
                else 
                    return SERVICE_CONSTANTS.DATE_FORMAT_DD_MM_YY;
}
/*############################################################################################## */
/* Retourne le format des dates et heure */
function getFormatDateHeure() {
                if(formatDate == 1)                  
                    return SERVICE_CONSTANTS.DATE_FORMAT_DD_MM_YY_HH_MI_SS;
                else if(formatDate == 2)                    
                    return SERVICE_CONSTANTS.DATE_FORMAT_YY_MM_DD_HH_MI_SS;                
                else if(formatDate == 3)                   
                    return SERVICE_CONSTANTS.DATE_FORMAT_MM_DD_YY_HH_MI_SS;
                else 
                    return SERVICE_CONSTANTS.DATE_FORMAT_DD_MM_YY_HH_MI_SS;                             
}

/*############################################################################################## */
// Differences avec l ancienne gestion :
// - getter sur tous les elements (oItem.getStep...)
// - modele ou article (oItem.isModel(), oItem.isArticle())
// - recuperation de la devise (un noeud au dessus)
// - pas de prix au litre kilo
/* Recupere les infos prix du modele */
function getPriceStockProduct(oItem) {
            var priceDateFormat;        // Contient le format de la date
            var dateDebutSoldes = '';
            var dateFinSoldes = '';

               // CAS MAGASIN
	if (cookieMagasin!=null && ((oItem.isModel() && oItem.isStore()) || oItem.isArticle())) {
                        casmagasin=true;
                        libelle=libPrixMagasin;
                        // LIBELLE STOCK
                        lib_stock = libStock1;
                       
                        // RECUP STOCK 
                        if (oItem.isAvailable()) stock = 1;
                        if (oItem.isUnavailable()) stock = 2;
                        if (oItem.isPartiallyAvailable()) stock = 3;
                        
                        // RECUP VALEUR STOCK (POUR ARTICLE UNIQUEMENT)   
                        if (oItem.isArticle() && oItem.getStock()!=null) valeur_stock=oItem.getStock();

                        // RECUP GAMME
                        if (oItem.isInRange()) gamme = 1;
                        if (oItem.isNotInRange()) gamme = 2;
                        if (oItem.isPartiallyInRange()) gamme = 3;	   
                          
                         // TEST AFFICHAGE PRIX PRODUIT AMI EN MAGASIN
                        if (_passion=='false' && !getSwitchSite('AMI_MAGASIN') || !getSwitchSite('ACTIVATION_PRIX_MAGASIN') || !getSwitchMagasin('ACTIVATION_PRIX_MAGASIN')){             
                                afficheCartouchePrix = 'N';          
                        }                                              
	}
	// CAS CENTRALE
               else {
                        casmagasin = false;
                        libelle=libPrixConseille;
                        
                        // LIBELLE STOCK
                        lib_stock = libStock2;
                        
                         // TEST AFFICHAGE PRIX CENTRAL TOUS PRODUITS ET PRIX CENTRAL PRODUIT AMI
                        if(!getSwitchSite('ACTIVATION_PRIX_CENTRAL') || (_passion=='false' && !getSwitchSite('AMI_CENTRAL'))) {
                                afficheCartouchePrix = 'N'; 
                        }
                }
              
                // DEVISE
                var oPrices = oItem.getPrices();
                if (oPrices) oCurrency = oPrices.getCurrency();
		
                // PRIX PRINCIPAL : FORT, PROMO OU SOLDE
                var oMainPrice = oItem.getMainPrice();

                if (oMainPrice!= null) {
                         // PRIX PRINCIPAL ET DEVISE FORMATE 
                        if (oMainPrice.value != null && oCurrency != null) {
                                    main_price_integer=oMainPrice.value.integer;
                                    main_price_decimal=oMainPrice.value.decimal.substring(0,2);                                    
                                    currencySymbol = oCurrency.getSymbol();
                                    currencyCode = oCurrency.getId();
                                    main_price = oCurrency.formatValue(oMainPrice.value);
                                    priceDateFormat = oMainPrice.getDateFormat();
                                    if (thirdSoldDateBegin != null) dateDebutSoldes = thirdSoldDateBegin.getLiteralDate(priceDateFormat);
                                    if (thirdSoldDateEnd != null) dateFinSoldes = thirdSoldDateEnd.getLiteralDate(priceDateFormat);

                                    // HOMOGENEITE EN PRIX ET EN TYPE - HOMOGENEITE EN DATES SEULEMENT SI ON CONTROLE LES DATES
                                     if (oMainPrice.isPriceHomogeneous() && oMainPrice.isKindHomogeneous()) {
                                             if (oItem.isGotRule(SERVICE_CONSTANTS.DISPLAY_START_DATE) && oItem.isRuleEnable(SERVICE_CONSTANTS.DISPLAY_START_DATE, false)) {
                                                     if (oMainPrice.isDateHomogeneous()) {
                                                                cacheListeArticles = true;
                                                     }
                                                     else if (oItem.kind==SERVICE_CONSTANTS.SERVICE_MODEL_IDX) {
                 	               	    libellebis = aPartirDe;
                 	                       }
                                             }
                                             else {
                                                      cacheListeArticles = true;
                                            }
                                     }
                                     else if (oItem.isModel()) {
                 	               libellebis = aPartirDe;
                 	        }

                                    // TEST TYPE PRIX PRINCIPAL
		       if(oMainPrice.isPromo() || oMainPrice.isSold()) {
		       
                                        // TEST RG BDFR2
                                        if (oItem.isBDFR2()) {
                                            afficheBDFR2 = true;

                                            // HOMOGENEITE EN DATES DEBUT ET FIN SUR LE MODELE
                                            if(oMainPrice.isBeginDateHomogeneous() || (!(oMainPrice.isBeginDateHomogeneous()) && oItem.kind==SERVICE_CONSTANTS.SERVICE_ARTICLE_IDX)) {
                                                // DATE DEBUT PRIX PRINCIPAL SI PROMO OU SOLDE
                                                if(oMainPrice.getBegin() != null) {
                                                    // REGLES DE GESTION AFFICHAGE DATE DE DEBUT
                                                    if (oItem.isGotRule(SERVICE_CONSTANTS.DISPLAY_START_DATE)) {
                                                        // REGLE DE GESTION AFFICHAGE DATE DEBUT : OUI
                                                        if (oItem.isRuleEnable(SERVICE_CONSTANTS.DISPLAY_START_DATE, false)) {
                                                            // On peut afficher la date de debut
                                                            dateDebut = oMainPrice.begin.getLiteralDate(priceDateFormat);
                                                            // Si solde et magasin en periode de soldes on recupere date debut
                                                            if(oMainPrice.isSold()) {
                                                                idMagasin = getEltFromUrl(cookieMagasin, 'idMagasin');
                                                                if(getSwitchMagasin('FLAG_IS_SOLD_PERIOD')) {                                                                            
                                                                    if (dateDebutSoldes!='' && dateFinSoldes!='') dateDebut = dateDebutSoldes;
                                                                }                                                                                                                                              
                                                            }                                                   
                                                        }
                                                    }
                                                }
                                            }
                                            if(oMainPrice.isEndDateHomogeneous() || (!(oMainPrice.isEndDateHomogeneous()) && oItem.kind==SERVICE_CONSTANTS.SERVICE_ARTICLE_IDX)) {
                                                // DATE FIN PRIX PRINCIPAL SI PROMO OU SOLDE
                                                if(oMainPrice.getEnd() != null) {
                                                    // REGLES DE GESTION AFFICHAGE DATE DE FIN
                                                    if (oItem.isGotRule(SERVICE_CONSTANTS.DISPLAY_END_DATE)) {
                                                        // REGLE DE GESTION AFFICHAGE DATE FIN : OUI                                                                                        
                                                        if (oItem.isRuleEnable(SERVICE_CONSTANTS.DISPLAY_END_DATE, false)) {
                                                            // On peut afficher la date de fin 
                                                            dateFin = oMainPrice.end.getLiteralDate(priceDateFormat);
                                                            // Si solde et magasin en periode de soldes on recupere date debut
                                                            if(oMainPrice.isSold()) {
                                                                idMagasin = getEltFromUrl(cookieMagasin, 'idMagasin');
                                                                if(getSwitchMagasin('FLAG_IS_SOLD_PERIOD')) {                                                                            
                                                                    if (dateDebutSoldes!='' && dateFinSoldes!='') dateFin = dateFinSoldes;
                                                                }                                                                                                                                              
                                                            }
                                                        }	
                                                    }
                                                }                                                            
                                            }    
                                        }
                                        else {
                                            // TEST RG BDFR1
                                            if (!oItem.isBDFR1()) {
	       
                                                // PRIX BARRE = PRIX FORT UNIQUEMENT SI LE PRIX PRINCIPAL EST UN PRIX PROMO OU SOLDE
    		                   var oStrikePrice = oItem.getStrikePrice();

                                                // PRIX BARRE NON NULL SI PRIX PROMO OU SOLDES < PRIX BARRE FORT
                                                if (oStrikePrice!= null) {
		                       isPromoOrSoldPrice = true;
		           
                                                    // HOMOGENEITE EN PRIX
                                                    if (!oStrikePrice.isPriceHomogeneous() && oItem.kind==SERVICE_CONSTANTS.SERVICE_MODEL_IDX) {
                                                        libellebis = aPartirDe;
                                                        cacheListeArticles = false;
                                                    }
                                                         
                                                    // DATE DEBUT PRIX PRINCIPAL SI PROMO OU SOLDE
                                                    if(oMainPrice.begin!= null) {
                                                        // REGLES DE GESTION AFFICHAGE DATE DE DEBUT
                                                        if (oItem.isGotRule(SERVICE_CONSTANTS.DISPLAY_START_DATE)) {
                                                            // REGLE DE GESTION AFFICHAGE DATE DEBUT : OUI
                                                            if (oItem.isRuleEnable(SERVICE_CONSTANTS.DISPLAY_START_DATE, false)) {
                                                                // On peut afficher la date de debut
                                                                dateDebut = oMainPrice.begin.getLiteralDate(priceDateFormat);
                                                            }
                                                        }
                                                    }

                                                    // DATE FIN PRIX PRINCIPAL SI PROMO OU SOLDE
                                                    if(oMainPrice.end!= null) {
                                                        // REGLES DE GESTION AFFICHAGE DATE DE FIN
                                                        if (oItem.isGotRule(SERVICE_CONSTANTS.DISPLAY_END_DATE)) {
                                                            // REGLE DE GESTION AFFICHAGE DATE FIN : OUI                                                                                        
                                                            if (oItem.isRuleEnable(SERVICE_CONSTANTS.DISPLAY_END_DATE, false)) {		
                                                                // On peut afficher la date de fin 
                                                                dateFin = oMainPrice.end.getLiteralDate(priceDateFormat);
                                                            }	
                                                        }
                                                    }                                                            
                                                   
                                                    // AFFICHAGE DU MOT SOLDES  ET RECUP DES DATES SI PRIX SOLDE ET MAGASIN EN PERIODE DE SOLDES                                                                   
                                                    if(oMainPrice.isSold()) {                                                                          
                                                        idMagasin = getEltFromUrl(cookieMagasin, 'idMagasin');
                                                        if(getSwitchMagasin('FLAG_IS_SOLD_PERIOD')) {                                                                            
                                                            isSoldPrice = true;
                                                            if (dateDebutSoldes!='' && dateFinSoldes!='') {
                                                                dateDebut = dateDebutSoldes;
                                                                dateFin = dateFinSoldes;
                                                            }                                                                                
                                                        }                                                                                                                                              
                                                    }                                                   
                                                                                                              
                                                    // REGLES DE GESTION AFFICHAGE PRIX BARRE POUR LES AMI     
                                                    if(_passion=='false' && oItem.isGotRule(SERVICE_CONSTANTS.DISPLAY_STRIKE_AMI)) {
                                                        // REGLE DE GESTION AFFICHAGE PRIX BARRE POUR AMI: OUI                                                                  
                                                        if (oItem.isRuleEnable(SERVICE_CONSTANTS.DISPLAY_STRIKE_AMI, false)) {
                                                            // On peut afficher le prix barre pour cet AMI
                                                            // PRIX BARRE ET DEVISE FORMATE 
                                                            if (oStrikePrice.value != null && oCurrency != null) {
                                                                strike_price=oCurrency.formatValue(oStrikePrice.value);       
                                                            }
                                                        }
                                                    }
                                                    
                                                    // REGLES DE GESTION AFFICHAGE PRIX BARRE POUR LES PASSIONS                                                               
                                                    if(_passion=='true' && oItem.isGotRule(SERVICE_CONSTANTS.DISPLAY_STRIKE_PASSION)) {
                                                        // REGLE DE GESTION AFFICHAGE PRIX BARRE POUR PASSION: OUI                                                                  
                                                        if (oItem.isRuleEnable(SERVICE_CONSTANTS.DISPLAY_STRIKE_PASSION, false)) {
                                                            // On peut afficher le prix barre pour ce passion
                                                            // PRIX BARRE ET DEVISE FORMATE 
                                                            if (oStrikePrice.value != null && oCurrency  != null) {
                                                                strike_price=oCurrency.formatValue(oStrikePrice.value);        
                                                            }
                                                        }
                                                    }

                                                    // POURCENTAGE DE REDUCTION SI PROMO OU SOLDES
                                                    if(oMainPrice.markdown!= null && strike_price!='') {
                                                        // REGLES DE GESTION AFFICHAGE POURCENTAGE REDUCTION
                                                        if (oItem.isGotRule(SERVICE_CONSTANTS.DISPLAY_DEMARK_PURCENT)) {
                                                            // REGLE DE GESTION AFFICHAGE POURCENTAGE : OUI
                                                            if(oItem.isRuleEnable(SERVICE_CONSTANTS.DISPLAY_DEMARK_PURCENT, false)) {
                                                                // On peut afficher le pourcentage de reduction
                                                                markdown = oMainPrice.getMarkdown();
                                                            }
                                                        }
                                                    }
                                                    
                                                }

                                            }
                                            // BDFR1 est verifie
                                            else {
                                                if (oItem.isGotRule(SERVICE_CONSTANTS.DISPLAY_DEMARK_LT_PERMANENT)) {
                                                    // REGLE DE GESTION AFFICHAGE BDFR1
                                                    if (oItem.isRuleEnable(SERVICE_CONSTANTS.DISPLAY_DEMARK_LT_PERMANENT, false)) {
                                                        affichePrixRouge=true;
                                                        // HOMOGENEITE EN PRIX ET TYPE - PAS D HOMOGENEITE EN DATES
                                                        if (oMainPrice.isPriceHomogeneous() && oMainPrice.isKindHomogeneous()) {
                                                            cacheListeArticles = true;
                                                            libellebis = '';
                                                        }
                                                        else if (oItem.isModel()) {
                                                            libellebis = aPartirDe;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }

                                    // PRIX AU KILO OU LITRE
                                    if (typeof valeurUnite != 'undefined' && typeof valeurPoids != 'undefined') {
                                        if (valeurUnite!='' && valeurPoids!='') kiloLitre_price = getPriceByLiterWeight(valeurUnite,valeurPoids);
                                    }
                                    else {
                                        var sWuUnit = oItem.getUnit();
                                        var sWuWeight = oItem.getWeight();
                                        if (sWuUnit != '' && sWuWeight != '') kiloLitre_price = getPriceByLiterWeight(sWuUnit, sWuWeight);
                                    }
                        }
                 }
              
                 // TAXE WEEE
                 if (getSwitchSite('DEEE')) {
                        var oWeeePrice = oItem.getWeeePrice();
                        if (oWeeePrice!= null) {
                                // TAXE ET DEVISE FORMATE 
                                if (oWeeePrice.value != null && oCurrency != null) {	
                                        weee_price= oCurrency.formatValue(oWeeePrice.value);                                
                                }
                         }
                 }
                 
                // ETAPE (Pour le Logo fin de collection)
                etape = oItem.getStep() ; 
}
/*############################################################################################## */ 
/* Retourne le prix au Litre ou Kg pour les produits de type alimentation, soin et entretien */
function getPriceLitreKg(valeurUnite, valeurPoids) {   
            if ((valeurUnite=='Kg' || valeurUnite=='L') && valeurPoids!=0){		     
                    //donne le prix au kilo ou au litre
                    var prixAuKgOuL=(parseFloat(main_price_integer+'.'+main_price_decimal)*1/valeurPoids);                                               
                    prixAuKgOuL=Math.round(prixAuKgOuL*100)/100;
                    // convertion en string pour separer la partie entiere et decimale et construire l objet value                
                    prixAuKgOuL = prixAuKgOuL.toString();  
                    if (prixAuKgOuL.indexOf('.')!=-1) {
                        var prixAuKgOuL_value = new Value(prixAuKgOuL.substring(0,prixAuKgOuL.indexOf('.')), prixAuKgOuL.substring(prixAuKgOuL.indexOf('.')+1));
                    }
                    else {
                        var prixAuKgOuL_value = new Value(prixAuKgOuL, '00');
                    }
                    // construction de l objet currency pour utiliser la methode de formatage du prix
                    var oCurrency = new Currency(1, currencySymbol, currencyObject.getDecimalNumber(), currencyObject.getDecimalDelimiter(), currencyObject.getThousandDelimiter(), currencyObject.isBehind());
                    return oCurrency.formatValue(prixAuKgOuL_value) +' / ' +valeurUnite;
            }         
            else return '';
}
/*############################################################################################## */ 
/* Retourne le prix au Litre ou au Kg */
function getPriceByLiterWeight(sUnit, sValue) {   
    try {
        if (sUnit == "Kg" || sUnit == "L") {
            if (sValue != null) {
                sValue = parseFloat(sValue);
                if (sValue != 0) {
                    //Calcul du prix
                    sValue = parseFloat(sValue);
                    var iMainPrice = parseFloat(main_price_integer+'.'+main_price_decimal);
                    var iUnitPrice = iMainPrice / sValue;
                    var sUnitPrice = iUnitPrice.toFixed(2);
                    
                    // Construction de l objet value pour alimenter l objet currency
                    var oValue = new JoValue();
                    oValue.setInteger(sUnitPrice.substring(0,sUnitPrice.indexOf('.')));
                    oValue.setDecimal(sUnitPrice.substring(sUnitPrice.indexOf('.')+1));
                  
                    // Retour de la chaine formatte
                    return oCurrency.formatValue(oValue) + " / " + sUnit;
                }
            }
        }
        
        return "";
    }
    catch (err) {
        return "";
    }
}
/*############################################################################################## */ 
/* Fonction qui permet de trier un tableau contenant des valeurs numeriques */
function triCroissant(a,b) {
if(a>b) return 1;
if(a<b) return -1;
} 
/*############################################################################################## */ 
/* Recupere les declinaisons du modele  pour remplir la liste deroulante des articles et l onglet tailles et coloris*/
function getDeclinaisons(oItem, _language) {
            // Recuperation + tri des articles selon balise order
            var lChildrenTemp = oItem.getChildren();
            var lChildren = new Array();
            var orders = new Array();
            for(var i=0;i<lChildrenTemp.length;i++){
                orders[i] = parseInt(oItem.getChildOrder([lChildrenTemp[lChildrenTemp[i]]]));
                lChildren[orders[i]] = lChildrenTemp[i];
                lChildren[lChildren[orders[i]]] = lChildrenTemp[lChildrenTemp[i]];
            }
           orders.sort(triCroissant);
            // Trie les declinaisons
            var listeDeclinaisons = document.getElementById('listeArticles');
            var strDeclinaisons='';
            var indice;
            for (var i = 0; i< orders.length; i++) {
                            indice = orders[i];
                            var lDeclinaisons=oItem.getChildVariations(lChildren[lChildren[indice]]);
                            if (lDeclinaisons!=null) {
                                    for (var j = 0; j < lDeclinaisons.length; j++) {
                                            if (lDeclinaisons[j] == oItem.getChildBiggestLiteral(lChildren[lChildren[indice]])) {
                                                     // Nouvelle ligne a la listbox des articles avec comme texte le libelle de l article s il existe et comme valeur le num article
                                                    listeDeclinaisons.options[listeDeclinaisons.options.length] = new Option(lDeclinaisons[j], lChildren[lChildren[indice]]);
                                                    // Ajout de la declinaison chaine des declinaisons separee par des virgules (pour tailles et coloris)
                                                    strDeclinaisons += lDeclinaisons[j];
                                            }
                                    }
                                    if (i!= lChildren.length-1){
        		           strDeclinaisons += ', ';
        	                     }
                            }
                            else listeDeclinaisons.options[listeDeclinaisons.options.length] = new Option('.', lChildren[lChildren[indice]]);
            }
            if (strDeclinaisons!='') {
                setBlocByHtml('valeurListeTaille', strDeclinaisons);
            }
}
/*############################################################################################## */
/* Liste des actions a executer apres la recuperation des infos des modeles dans dkt_tv */
var POST_LOAD_MODEL_SERVICE_FUNCTION_DKT_TV = function postModelService(httpStatus, _joService) {
    if(httpStatus != null && httpStatus==200) {
        // Recuperation du modele
         var oContent = _joService.getContent();
         if(oContent != null){
             var oItem = oContent.getItem(_modelId);
            // Le modele existe
            if (oItem != null) {
                // Etat valide        		
                if (oItem.isEnable()) {        		
                    // Recuperation des infos prix stock
            	     getPriceStockProduct(oItem);
                    priceToDisplay = displayPriceStockDktTv();
                } else priceToDisplay = '';
                
            } else priceToDisplay = '';
             // Pour prix rouge
             if (affichePrixRouge){
                 changeBlocClass('box_price','prixRouge');
             }
             else{
                 changeBlocClass('box_price','');
             }
         }
         else priceToDisplay = '';
    }
    // Reinitialisation de certaines variables
    reInitPriceVars();
}             
/*############################################################################################## */
/* Liste des actions a executer apres la recuperation des infos des modeles dans dkt_tv */
var POST_LOAD_MODELS_SERVICE_FUNCTION_DKT_TV = function postModelsService(httpStatus, _joService) {
          if(httpStatus != null && httpStatus==200) {   
        	       // Recuperation des modeleshttpStatus, _joService
                     var oContent = _joService.getContent();
                     var listItems = oContent.getItemsList();
        	       for (var i=0; i<listItems.length; i++) {        	     
        	           var oItem = listItems[listItems[i]];
        	            // Le modele existe
        	            if (oItem != null) {
        		if (oItem.isEnable()) {
        		    // On montre la vignette produit associee
        		    for(var j=0; j < videosModele[oItem.id].length; j++) // Parcours des differentes videos associees au produit
        		        showBloc(videosModele[oItem.id][j] + '_' + oItem.id);
        	                  }
                           }  
	       }      	
          }
}

/*############################################################################################## */
/* Determine les parametres pour le chargement du modele de dkt_tv en fonction de la presence du cookie : modele central OU modele magasin*/
function loadModelDktTvConnectOrNot(cookieMagasin,languageCode) {
	// 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 {
		loadModeltDktTv(_client, _siteNumber, _centralNumber, null, _modelId,languageCode);
	}
}
/*############################################################################################## */
/* Charge un modele dkt_tv */
function loadModeltDktTv(_client, _siteNumber, _centralNumber, _storeNumber,_modelId,_language) {
               loadModel(_client, _siteNumber, _centralNumber, _storeNumber, _modelId,_language,POST_LOAD_MODEL_SERVICE_FUNCTION_DKT_TV);
}
/*############################################################################################## */
/* Charge les modeles dkt_tv */
function loadModelsDktTv(_client, _siteNumber, _centralNumber, _storeNumber) {
               var compteur = 0;
               for(var i in videosModele){
                   compteur++;
                   psiAddModelForService(i);
                   // On appelle le service models plusieurs fois si il y a plus de MAX_LOAD_MODELS modeles a charger
                   if(compteur % MAX_LOAD_MODELS == 0){
                       loadModels(_client, _siteNumber, _centralNumber, _storeNumber,POST_LOAD_MODELS_SERVICE_FUNCTION_DKT_TV);
                       PSI_QMODELS_ARRAY = new Array();
                   }
	}
	if(compteur % MAX_LOAD_MODELS != 0) loadModels(_client, _siteNumber, _centralNumber, _storeNumber,POST_LOAD_MODELS_SERVICE_FUNCTION_DKT_TV);
}
/*############################################################################################## */
/* Gere le slideshow de la page modele */
var POST_FAMILY_MODELE_SLIDESHOW_SERVICE_FUNCTION = function postFamilySlideShowService(httpStatus, _joService) {
            var currentModeleIndex = '';    // Index dans la table slideshowArray du modele en cours
            var previousModele = "";         // Id du modele suivant le modele en cours
            var nextModele = "";                 // Id du modele precedent le modele en cours

            if(httpStatus != null && httpStatus==200) {        	        
                    // Recuperation des modeles
                    var oContent = _joService.getContent();
                    // Affichage du slideshow
                    getAffichageSlideshow(oContent.getItemsList());
               }
}
/*############################################################################################## */
/* Affiche le slideshow : si listItems est null (erep ne repond pas), l ordre utilise est forcement celui d itool et il n y a pas de controle de l etat des modeles */
function getAffichageSlideshow(listItems){
    // Tri du slideshow
    slideshowArray = _slideShowSort(listItems,slideshowArray, slideshowSortMethod);
    
    // Recuperation du numero d index du modele en cours
    currentModeleIndex = slideshowArray.contains(_modelId);
    
    //Recherche du modele precedent
    if(listItems) previousModele = _slideShowFindPrevious(listItems,slideshowArray,currentModeleIndex);
    else previousModele = slideshowArray.get(currentModeleIndex - 1);
    if (previousModele != "") {
        setHref('slideshow_previous','/'+_language+getBlocHtml('slide_'+ previousModele))
        showBloc("slideshow_previous","inline");
        // Tag
        if (typeof webAnaWT != 'undefined') {
            if (webAnaWT == 'true') {
                var lnk = document.getElementById('slideshow_previous');
                if (lnk) lnk.onclick = function () {dcsMultiTrack('DCS.dcsuri','/link/model_slideshow_previous/', 'WT.ti', 'Model%20Slideshow%20Previous');}
            }
        }
        if (typeof webAnaGA != 'undefined') {
            if (webAnaGA == 'true') {
                var lnk = document.getElementById('slideshow_previous');
                if (lnk) lnk.onclick = function () {pageTracker._trackPageview('/link/model_slideshow_previous/');}
            }
        }
        if (typeof webAnaXT != 'undefined') {
            if (webAnaXT == 'true') {
                var lnk = document.getElementById('slideshow_previous');
                if (lnk) lnk.onclick = function () {xt_med('C','', 'model_slideshow_previous','N');}
            }
        }
    }
    
    //Recherche du modele suivant
    if(listItems) nextModele = _slideShowFindNext(listItems,slideshowArray,currentModeleIndex);
    else nextModele = slideshowArray.get(currentModeleIndex + 1);
    if (nextModele != "") {
        setHref('slideshow_next','/'+_language+getBlocHtml('slide_'+ nextModele))
        showBloc("slideshow_next","inline");
        // Tag
        if (typeof webAnaWT != 'undefined') {
            if (webAnaWT == 'true') {
                var lnk = document.getElementById('slideshow_next');
                if (lnk) lnk.onclick = function () {dcsMultiTrack('DCS.dcsuri','/link/model_slideshow_next/', 'WT.ti', 'Model%20Slideshow%20Next');}
            }
        }
        if (typeof webAnaGA != 'undefined') {
            if (webAnaGA == 'true') {
                var lnk = document.getElementById('slideshow_next');
                if (lnk) lnk.onclick = function () {pageTracker._trackPageview('/link/model_slideshow_next/');}
            }
        }
        if (typeof webAnaXT != 'undefined') {
            if (webAnaXT == 'true') {
                var lnk = document.getElementById('slideshow_next');
                if (lnk) lnk.onclick = function () {xt_med('C','', 'model_slideshow_next','N');}
            }
        }
    }
}
/*############################################################################################## */
/*INTERNE SLIDESHOW : recupere la reference du modele precedent*/
function _slideShowFindPrevious(listItems,htmlModelesArray,currentIndex) {
    var i=0;
    var trouve = false;
    var pModele = '';

    if (currentIndex > 0) {
        i=currentIndex - 1;
        
        while (i >= 0 && trouve==false) {
            pModele = htmlModelesArray.get(i);
            trouve = _slideShowModelIsAccessible(listItems,pModele);
            i--;
        }
        
    }
    
    if (trouve == true) return pModele; 
    else return '';
}
/*############################################################################################## */
/*INTERNE SLIDESHOW : recupere la reference du modele suivant*/
function _slideShowFindNext(listItems,htmlModelesArray,currentIndex) {
    var i=0;
    var trouve = false;
    var nModele = '';

    if (currentIndex < (htmlModelesArray.length() - 1)) {
        i = currentIndex + 1;
        
        while (i < htmlModelesArray.length() && trouve==false) {
            nModele = htmlModelesArray.get(i);
            trouve = _slideShowModelIsAccessible(listItems,nModele);
            i++;
        }
        
    }

    if (trouve == true) return nModele; 
    else return '';
}
/*############################################################################################## */
/*INTERNE SLIDESHOW : determine si le modele passe en parametre est activee sous eRep (magasin)*/
function _slideShowModelIsAccessible(listItems,modelIdToFind) {

    for (var k=0; k<listItems.length; k++) {
        var oItem = listItems[listItems[k]];

        // Le modele existe           	      
        if (oItem != null) {       
            // Etat valide        		
            if (oItem.isEnable()) {
                //Test si le modele correspond au modele recherche
                if (oItem.id == modelIdToFind) {
                    return true;
                }
            }
        }
        
    }        
    
    return false;
}
/*############################################################################################## */
/*INTERNE SLIDESHOW : tri le tableau "slideshowArray" (itool) en fonction du parametre de trie itool (ordre itool, prix asc ou desc)*/
function _slideShowSort(listItems,htmlModelesArray,sort) {

    if (sort == 'PRIX') {
        //Trier par prix
        var sortedArray = new ArrayList();
        var tempArray = new Array();
        
        //Construction du tableau tempArray contenant la reference du modele et son prix
        for (var i = 0, lenHtmlTab = htmlModelesArray.length(); i < lenHtmlTab; i++) {

            //Recherche du prix
            var oMainPrice;
            var price = 1000000;
            var trouve = false;
            var modeleIdCurrent = htmlModelesArray.get(i); 

            for (var k = 0, lenPrice = listItems.length; k < lenPrice && trouve == false; k++) {
                var oItem = listItems[listItems[k]];
                // Le modele existe           	      
                if (oItem != null) {
                    if (oItem.id == modeleIdCurrent) {
                        trouve = true;
                        oMainPrice = oItem.getMainPrice();
                        if (oMainPrice != null) price = parseFloat(oMainPrice.value.integer+"."+oMainPrice.value.decimal);                        
                    }
                }
            }

            //Construction effective du tableau            
            tempArray[i] = new Array();
            tempArray[i][0] = modeleIdCurrent;
            tempArray[i][1] = price;
        }
        
        //Tri
        tempArray.sort(_slideShowSortAsc);
        
        //Construction du tableau de sortie de la fonction
        for (var i = 0, lenTempTab = tempArray.length; i < lenTempTab; i++) sortedArray.add(tempArray[i][0]);
        
        return sortedArray;
    }
    else {
        // Trier par ordre itool
        return htmlModelesArray;
    }

}
/*############################################################################################## */
/*INTERNE SLIDESHOW : fonction specifique de tri pour la  methode sort */
function _slideShowSortAsc(x1,x2) {
    return ( parseFloat(x1[1]) > parseFloat(x2[1]))? 1 : -1;
}
/**
 * This method was used to retrieve the item index key.
 * _id ....: The item id.
 * _kind ..: The item kind.
 * return .: The item's index key.
 *           Null if item's id or kind is null.
 */
function getModelsServiceIndexKey(_id) {
	if (_id == null) {
		return null;
	}
	return '#' + _id + '#';
}
/**
 * This method was used to add an item in item static array.
 * _oItem .: the item to add.
 * return .: true if added.
 *           false if item, item's id or item's kind is null.
 */
function psiAddModelForService(_id) {
	var sIndexKey = null;

	/* Retrieve Item Index Key. */
	sIndexKey = getModelsServiceIndexKey(_id);
	
	/* Check key.*/
	if (sIndexKey == null) {
		return false;
	}
	if (PSI_QMODELS_ARRAY.length > MAX_LOAD_MODELS) {
		return false;
	}
	/* Check that item does not allready exists. */
	if(PSI_QMODELS_ARRAY[sIndexKey] == null) {
		PSI_QMODELS_ARRAY.push(sIndexKey);
	}
	PSI_QMODELS_ARRAY[sIndexKey] = _id;
	return true;
}