/* AVEC NVO SERVICES EREP DU 30 MARS 2009*/

/**
 * Prerequis :
 * La variable modelList est un objet de type ArrayList et doit oblgatoirement etre initialise dans la page HTML
 */
var _displayPrice = true ;
var nbModelToCheck = 0 ;
var nbModelHidden = 0 ;
var nbPdtReel=0;
var isModels=false;

var isErrorErep = false ;

//liste des modeles valides
var enableModelList = new ArrayList() ; 

/* AVEC LES NOUVEAUX SERVICES EREP */
var _storeNumber='';
var serviceId = "" ;
/* CONSTANTES CORRESPONDANTS AUX DIFFERENTS MODES DUTILISATION DU CONTEXTE */
var CONTEXT_MODE_RAYON = 'mode_1_1';
var CONTEXT_MODE_MODELES = 'mode_3_0';
var CONTEXT_MODE_MODELE = 'mode_3_1';

/* CONSTANTE POUR LES DIFFERENTS FILTRES */
var ACT_FILTRE_PRIX = SERVICE_CONSTANTS.DATA_FILTER_PRICE ; //FILTRE SUR LES PRIX
var ACT_FILTRE_ASS = SERVICE_CONSTANTS.DATA_FILTER_MIX ; //FILTRE SUR LES ASSORTIMENTS
/* FIN AVEC LES NOUVEAUX SERVICES EREP */

/**
 * Permet de recuperer les items d'un departement et de faire les traitement HTML et JS dessus
 * @param :
 *    - httpStatus : le statut HTTP apres l'appel ajax
 * @desc :
 *    - pour chaque item, on va verfier sa visibilite, si elle est a true alors on affiche le produit, sinon on ne l'affiche pas
*/
var POST_LOAD_ITEM_DEPARTMENT_FUNCTION = function postItemDepartmentService(httpStatus){
    if(httpStatus == "200"){
        if(modelList == null || modelList.length == 0){  // peut etre a remettre
            isErrorErep = true ;
        }
        
        checkModels(serviceId, _displayPrice, true, isSlideShow, false) ;        
        
        idBlocNbProduitReel = parent.document.getElementById('nbProduitReel') ;
        if(idBlocNbProduitReel){
            idBlocNbProduitReel.innerHTML=enableModelList.length();
        }
        //Somme nous dans l'html du slideshow ??
        //si oui alors on va checker quel produit afficher a partir du param _modeleCourant recupere depuis l'html        
        if(isSlideShow){
            displayPrevNextProduct(_modeleCourant) ; //rem : _modeleCourant provient de la page html produit
        }

        checkSwitchProductPages(false) ;
        
        verifCritereArbo() ;
        verifProduitEnable() ;
        
        recupCritere("sexe") ;
        getCritereAffichage("sexe") ;
        recupCritere("type") ;
        getCritereAffichage("type") ;
        recupCritere("couleur") ;
        getCritereAffichage("couleur");
        
    }
    else{
        displayBlocProduit();
    }
}

/**
 * Permet de recuperer les items a partir d'une liste de modeles et de faire les traitement HTML et JS dessus
 * @param :
 *    - httpStatus : le statut HTTP apres l'appel ajax
 * @desc :
 *    - pour chaque item, on va verfier sa visibilite, si elle est a true alors on affiche le produit, sinon on ne l'affiche pas
*/
var POST_LOAD_ITEM_MODELS_FUNCTION = function postItemModelsService(httpStatus){

    if(httpStatus == "200"){
    var nbItem=getNbItem(serviceId);
        if(nbItem == null || nbItem == 0){
            isErrorErep = true ;
        }
        
        checkModels(serviceId,_displayPrice, false, false, true) ;

        //Dans le cas des ventes complementaire, doit on cacher ou non le bloc
        //hideBlockModels("bloc-decouvrirplus") ;
        
        checkSwitchProductPages(false) ;
    }
}

/**
 * Permet de recuperer l'item d'un modele et de faire les traitement HTML et JS dessus
 * @param :
 *    - httpStatus : le statut HTTP apres l'appel ajax
 * @desc :
 *    - pour chaque item, on va verfier sa visibilite, si elle est a true alors on affiche le produit, sinon on ne l'affiche pas
*/
var POST_LOAD_ITEM_MODEL_FUNCTION = function postItemModelService(httpStatus){
    if(httpStatus == "200"){
        checkModel(serviceId, idModel, _displayPrice, isFromModel) ;        
        
        modelList = new ArrayList() ;
        modelList.add(idModel) ;
        
        checkSwitchProductPages(true) ;
    }
}

/**
 * Permet de verifier les switchs apres la recuperation des prix
*/
function checkSwitchProductPages(isModelPage){
    //appel des interrupteurs
    var _switchArrayAChecker = new Array() ;
    _switchArrayAChecker[0] = SWITCH_ACTIVATION_PRIX ;
    _switchArrayAChecker[1] = SWITCH_ACTIVATION_DEEE ;
    _switchArrayAChecker[2] = SWITCH_ACTIVATION_KOODZA ;        
    _switchArrayAChecker[3] = SWITCH_ACTIVATION_DEEE_KOODZA ;
    _switchArrayAChecker[4] = SWITCH_ACTIVATION_MDR ;
    _switchArrayAChecker[5] = SWITCH_ACTIVATION_MDR_SAISIE_PREDICTIVE ;     
    _switchArrayAChecker[6] = SWITCH_ACTIVATION_DOCUMENTS_ASSOCIES ; 
    _switchArrayAChecker[7] = SWITCH_ACTIVATION_ARBO_MULTI ;
    _switchArrayAChecker[8] = SWITCH_ACTIVATION_LIAGE_DKT ;
    
    if(isModelPage){
        _switchArrayAChecker[9] = SWITCH_ACTIVATION_OXYLANE_PROFIL ;
        _switchArrayAChecker[10] = SWITCH_ACTIVATION_OXYLANE_AVIS ;
        _switchArrayAChecker[11] = SWITCH_ACTIVATION_OXYLANE_PLUS_ONGLET ;
  
    }
    

    
    
    //Desactive car fonction oxylane seulement present sur page produit
    /*
    else{
        _switchArrayAChecker[5] = SWITCH_ACTIVATION_OXYLANE_PLUS_BT ;
    }
    */
    
    checkSwitches(_switchArrayAChecker, _client, THIRD_KIND_SITE, _siteNumber, _siteNumber, "", "", "", modelList) ;        
}

/**
 * Permet de cacher ou non le bloc produit et d'afficher le picto new
 * @param :
 *    - isDisplayPrice : true/false doit on gerer l'affichage des prix
 *    - isDisplayBlocProduit : Doit ton afficher oui ou non le blc produit
 *    - isSlideShow : Le cas a gerer est il le slideshow
 *    - isTypePageModel : true/false : type d'affichage du bloc prix : semblable a la page produit ou non
*/
function checkModels(_serviceId, isDisplayPrice, isDisplayBlocProduit, isSlideShow, isTypePageModel){      
    var verifBlocVc=false;
    if(modelList && modelList.length() > 0){
        //Nb de modele a verifier
        nbModelToCheck = modelList.length() ;
        var verifBlocVc=false;
        //Pour chaque modele de la liste global, on va recuperer l'objet Item
        for(var ii=0 ; ii<modelList.length() ; ii++){            
            var modelId = modelList.get(ii) ; //identifiant du modele a verifier
            isModels=true;
            checkModel(_serviceId, modelId, isDisplayPrice, isTypePageModel) ;
            
            testVc=getElement("decouvrirplus"+modelId, true, "") ;
            if(testVc && testVc.style.display=="block"){
                 verifBlocVc=true;
            }
            
        }
       
        if(isDisplayBlocProduit && !isSlideShow){
            displayBlocProduit() ;
        }       
    }
     if(!verifBlocVc && getElement("produits-associes", true, "")){
            getElement("produits-associes", true, "").style.display="none";
        }
}

/**
 * Permet de cacher ou non le bloc produit et d'afficher le picto new
 * @param :
 *    - isDisplayPrice : true/false doit on gerer l'affichage des prix
*/
function checkModel(_serviceId, idModel, isDisplayPrice, isFromModel){   
    var blocPrixEtape1et3 = getElement("prixEtape1et3-"+idModel, true, "") ;
    
    if(idModel){
        var forceDisplayBlock = false ;
        var item = getMyItem(_serviceId, idModel) ; //on recupere l'objet ITem associe
        //on recupere les blocs HTML a afficher ou a cacher
        //2 types :
        //    - vignetteproduit : utilise dans les pages familles
        //    - blocPrix : utilise dans la page produit
        var blocItemObj = getElement("vignetteproduit-"+idModel, true, "") ;
        forceDisplayBlock = true ;
        if(blocItemObj == null){
            if(blocItemObj == null){
                blocItemObj = getElement("decouvrirplus"+idModel, true, "") ;
                forceDisplayBlock = false ;
                if(blocItemObj == null || !isModels){
                    blocItemObj = getElement("bloc-prix"+idModel, true, "") ;
                    forceDisplayBlock = false ;
                    if(blocItemObj == null){
                        blocItemObj = getElement("decouvrirplus"+idModel, true, "") ;
                        forceDisplayBlock = false ;
                    }
                }
            }
        }
        //Le bloc prix affiche dans la fiche produit
        //contient en plus la phrase "Bientot en vente ..."
     var blocPrixFicheProduit = getElement("blocPrix"+idModel, true, "") ;
     var blocPhraseBientotDispoSurvol = getElement("bientotDispo"+idModel, true, "") ;
        //Si la reponse erep est fausse, on va quand meme afficher les produits
        if(isErrorErep){
            if(!forceDisplayBlock){
                nbModelHidden++ ;
                hideBloc(blocItemObj) ; //Par defaut, le bloc est cache
                hideBloc(blocPrixFicheProduit) ; //on cache le bloc prix de la fiche produit                
            }
            else{
                displayBloc(blocItemObj) ; //Par defaut, le bloc est affiche
            }
        }
        //Item existe donc on va recuperer les prix
        else if(item != null && (item.getStep()!="3" ||  isFromModel && blocItemObj.id.indexOf("decouvrirplus")>-1 && item.getStep()!="3" &&  modeleCourant!=idModel ||  isFromModel && blocItemObj.id.indexOf("decouvrirplus")==-1)){
            //Traitement que si le bloc HTML existe
            if(blocItemObj){
                var isEnable = item.isEnable() ; //l'item est-il valable, faut il l'afficher
                var step = item.getStep() ; //recuperation de son etat : 1/2 ou 3
                if(step == "-1" || !item.isStepHomogeneous()){ //Si les etapes du modele ne sont pas homogene, on va forcer l'etape du produit a 1
                    step = "1"  ; 
                }

                //Si l'item n'est pas valable, alors on cache le bloc HTML correspondant
                if(!isEnable){
                    if(!isFromModel){
                        hideBloc(blocItemObj) ;
                        hideBloc(blocPrixFicheProduit) ; //on cache le bloc prix de la fiche produit
                        
                        nbModelHidden++ ;
                    }
                    //On presente toujours le produit meme si le produit est inactif
                    /*
                    else{
                        redirectProduit(idModel, _urlFamille) //_urlFamille doit etre declare dans l'html
                    }*/
                }
                //sinon on l'affiche apres avoir verifie son etape de vie pour afficher les pictos NEW ou FIN
                else{
                    //le modele est coherent et peut donc etre affiche, on l'ajoute a la liste
                    enableModelList.add(idModel);                        
                    //le bloc contenant les pictos NEW et FIN DE COLLECTION                                      
                    var blocPictoInfoPrix = getElement("pictoInfoPrix"+idModel, true, "") ;                     
                    if(step != "1"){
                        if(step == "2"){ //etape de vie 2, picto NEW a afficher
                            var pictoNewItemObj = getElement("picto-new-"+idModel, true, "") ;    
                            if(pictoNewItemObj){
                                displayBloc(pictoNewItemObj) ;
                            }
                            // Cas particulier du survol dans les pages liste des pdts car c un fond decran qui change et non pas un picto                         
                            var pictoNewItemObjsurvol = getElement("infoproduit-fond"+idModel, true, "") ;    
                            if(pictoNewItemObjsurvol){
                                pictoNewItemObjsurvol.style.backgroundImage = 'url(../images/static/background-info-bulle-liste-produits-new.gif)'; 
                            }
                            // fin du cas particulier du survol
                            // Cas particulier de la fiche produit c un fond decran qui change et non pas un picto                         
                            
                             //nouvelle gestion pictogramme fiche produit pour AB testing
                                var pictoNewItemObjPDT = getElement("titre-fond-picto", true, "") ;      
                                     if(pictoNewItemObjPDT && blocItemObj.id.indexOf("decouvrirplus")==-1){
                                         pictoNewItemObjPDT.style.backgroundImage = 'url(../images/static/fpv2-background-fiche-produit-infos-produit-h2-new.gif)'; 
                                     }      
                            
                            
                            // fin du cas particulier de la fiche pdt
                             // Cas particulier de comparateur ou des favoris ou c un fond decran qui change et non pas un picto  (attention pas le meme fond que la fiche pdt)                       
                            var pictoNewItemObjFavorisComp = getElement("infoProduit-fond-favoris-comp"+idModel, true, "") ;    
                            if(pictoNewItemObjFavorisComp){
                                pictoNewItemObjFavorisComp.style.backgroundImage = 'url(../images/static/favoris-comp-new.gif)'; 
                            }
                            // fin du cas particulier des favoris
                            
                            //on va afficher le bloc contenant la phrase "bientot en vente ..."
                            var blocPhraseBientotDispo = getElement("bientotDispo"+idModel, true, "") ;
                            if(blocPhraseBientotDispo){
                                displayBloc(blocPhraseBientotDispo) ;
                            }
                            
                            if(!isFromModel){
                                hideBloc(blocPrixFicheProduit) ;
                            }

                            if(blocPrixEtape1et3){
                                hideBloc(blocPrixEtape1et3);
                            }

                        }
                        else if(step == "3"){ //etape de vie 3, picto FIN a afficher
                            var pictoFinItemObj = getElement("picto-fin-"+idModel, true, "") ;
                            if(pictoFinItemObj){
                                displayBloc(pictoFinItemObj) ;
                            }
                             // Cas particulier du survol dans les pages liste des pdts car c un fond decran qui change et non pas un picto
                            
                            var pictoNewItemObjsurvol = getElement("infoproduit-fond"+idModel, true, "") ;    
                            if(pictoNewItemObjsurvol){
                                pictoNewItemObjsurvol.style.backgroundImage = 'url(../images/static/background-info-bulle-liste-produits-fin-collection.gif)'; 
                            }
                            // fin du cas particulier du survol
                            // Cas particulier de la fiche produit c un fond decran qui change et non pas un picto                         
                            
                            
                             //nouvelle gestion pictogramme fiche produit pour AB testing
                                var pictoNewItemObjPDT = getElement("titre-fond-picto", true, "") ;   
                                     if(pictoNewItemObjPDT && blocItemObj.id.indexOf("decouvrirplus")==-1){
                                         pictoNewItemObjPDT.style.backgroundImage = 'url(../images/static/fpv2-background-fiche-produit-infos-produit-h2-fin-collection.gif)'; 
                                     }         
                            
                            // fin du cas particulier de la fiche pdt
                             // Cas particulier de comparateur ou des favoris ou c un fond decran qui change et non pas un picto  (attention pas le meme fond que la fiche pdt)                       
                            var pictoNewItemObjFavorisComp = getElement("infoProduit-fond-favoris-comp"+idModel, true, "") ;    
                            if(pictoNewItemObjFavorisComp){
                                pictoNewItemObjFavorisComp.style.backgroundImage = 'url(../images/static/favoris-comp-fincoll.gif)'; 
                            }
                            // fin du cas particulier des favoris
                        }
                        //on va afficher le bloc info picto prix
                        if(blocPictoInfoPrix){
                            displayBloc(blocPictoInfoPrix) ;
                        }
                    }                         
                    //on va afficher les prix Decathlon si le modele est en etape de vie different de 2 et que le booleen isDisplayPrice est a true                    
                    if(step != "2"){
                        //on va cacher le bloc info picto prix si l'etape est 1
                        if(step == "1"){
                            if(blocPictoInfoPrix){
                                hideBloc(blocPictoInfoPrix) ;
                            }
                                 // Cas particulier du survol dans les pages liste des pdts car c un fond decran qui change et non pas un picto
                                var pictoNewItemObjsurvol = getElement("infoproduit-fond"+idModel, true, "") ;    
                                if(pictoNewItemObjsurvol){
                                pictoNewItemObjsurvol.style.backgroundImage = 'url(../images/static/background-info-bulle-liste-produits.gif)'; 
                                }
                                // fin du cas particulier du survol
                                 // Cas particulier de la fiche produit c un fond decran qui change et non pas un picto                         
                                
                                //nouvelle gestion pictogramme fiche produit pour AB testing
                                var pictoNewItemObjPDT = getElement("titre-fond-picto", true, "") ;    
                                     if(pictoNewItemObjPDT && blocItemObj.id.indexOf("decouvrirplus")==-1){
                                         pictoNewItemObjPDT.style.backgroundImage = 'url(../images/static/fpv2-background-fiche-produit-infos-produit-h2.gif)'; 
                                     }                               
                                
                                
                                
                                // fin du cas particulier de la fiche pdt
                                 // Cas particulier de comparateur ou des favoris ou c un fond decran qui change et non pas un picto  (attention pas le meme fond que la fiche pdt)                       
                                var pictoNewItemObjFavorisComp = getElement("infoProduit-fond-favoris-comp"+idModel, true, "") ;    
                                if(pictoNewItemObjFavorisComp){
                                    pictoNewItemObjFavorisComp.style.backgroundImage = 'url(../images/static/favoris-comp-etape1.gif)'; 
                                }
                                // fin du cas particulier des favoris
                        }
                        var displayBlocItem = true ;
                        
                        //on va cacher le bloc contenant la phrase "bientot en vente ..."
                        var blocPhraseBientotDispo = getElement("bientotDispo"+idModel, true, "") ;
                         if(blocPhraseBientotDispo){
                                                    hideBloc(blocPhraseBientotDispo) ;                             
                        }        
                        if(isDisplayPrice && item.getMainPrice() != null){
                            //Rcuperation de l'ojet Prices qui contient tous les types de prix
                            var oPrice = item.getPrices() ;
                            var oCurrency = oPrice.getCurrency() ; //objet Currency qui va permettre de formater correctement le prix
                            if(oCurrency){
                                var oMainPrice = item.getMainPrice() ; //Prix principal = prix central
                                var valuePrice = oCurrency.formatValue(oMainPrice.getValue()) ; //on formatte le prix central
                                var isHomogenous = oMainPrice.isPriceHomogeneous() ;
                                if(valuePrice != ""){
                                
                                var fonctionGoToProduct = getLinkToDecathFunction(_rootPath, _serverUrl, _urlLiage, idModel, _siteRepositoryEnseigne) ;

                                setPrixDecathlon(idModel, valuePrice, isHomogenous, _language, isFromModel,fonctionGoToProduct) ; //Affichage du prix
                                }
                            }

                            //on va afficher le bloc prix
                           var blocPrixObj = getElement("blocPrix"+idModel, true, "") ;
                           if(!blocPrixObj){
                               blocPrixObj = parent.getElement("blocPrix"+idModel, true, "") ;
                           }
                            if(blocItemObj.id.indexOf("decouvrirplus")>-1){
                                blocPrixObj = getElement("bloc-prix"+idModel, true, "") ;
                               if(!blocPrixObj){
                                   blocPrixObj = parent.getElement("bloc-prix"+idModel, true, "") ;
                               }
                            }
                            if(blocPrixObj){
                                displayBloc(blocPrixObj) ;
                            }
                        }
                        else{
                            displayBlocItem = false ;
                        }
                        //on va afficher le bloc produit
                        if(displayBlocItem){
                            displayBloc(blocItemObj) ;
                            displayBloc(blocPrixFicheProduit) ; //on affiche le bloc prix de la fiche produit
                        }
                    }
                    else{
                        if(isFromModel){
                            displayBloc(blocPrixFicheProduit) ; //on affiche le bloc prix de la fiche produit
                        }
                    }
                }
            }
        }
        else{
            nbModelHidden++ ;
            hideBloc(blocItemObj) ; //Par defaut, le bloc est cache
            hideBloc(blocPrixFicheProduit) ; //on cache le bloc prix de la fiche produit
        }
    }
}

/**
 * Permet de charger tous les items d'un departement (ex: rayon)
 * @param :
 *    - _client : ITOOL
 *    - _departmentId : l'identifiant du departement masterdata
 *    - _idSite : l'identifiant du site
 *    - _idCentral : identifiant de la centrale
 *    - _displayPrice : recuperation ou non des prix
 * @desc :
 *    - recupere le serveur erep, initialise ce serveur et charge tous les items de la famille
*/
function getDepartment(_client, _departmentId, _idSite, _idCentral, _displayPrice, isSlideShow){
    //on va verifier si le client ne vient pas d'un autre pays
    var idCentral = _idCentral ;
    var valueCookieCountry = getCookie("country") ;
    if(valueCookieCountry){
        var enseigneSiteObj = mapUrlParPays.get(valueCookieCountry) ;
        if(enseigneSiteObj){
            idCentral = enseigneSiteObj.getCentrale() ;
        }
    }
    
    if(idCentral != "-1"){
        loadDepartment(_client, _departmentId, _idSite, idCentral, _displayPrice, isSlideShow, POST_LOAD_ITEM_DEPARTMENT_FUNCTION) ;
    }
    else{
        //on va afficher la bonne page
        displayBlocProduit() ;
        
        //on cache la phrase d'attente
        hideWaitingMessage() ;        
    }
}

/**
 * Permet de charger tous les items a partir d'une liste de modeles
 * @param :
 *    - _client : ITOOL
 *    - _familyId : l'identifiant de la famille masterdata
 *    - _idSite : l'identifiant du site
 *    - _idCentral : identifiant de la centrale
 *    - _displayPrice : recuperation ou non des prix
 * @desc :
 *    - recupere le serveur erep, initialise ce serveur et charge tous les items de la famille
*/
function getModels(_client, _idSite, _idCentral){    
    //on va verifier si le client ne vient pas d'un autre pays
    var idCentral = _idCentral ;
    var valueCookieCountry = getCookie("country") ;
    if(valueCookieCountry){
        var enseigneSiteObj = mapUrlParPays.get(valueCookieCountry) ;
        if(enseigneSiteObj){
            idCentral = enseigneSiteObj.getCentrale() ;
        }
    }
    
    if(idCentral != "-1"){
        loadModels(_client, _idSite, idCentral, POST_LOAD_ITEM_MODELS_FUNCTION) ;
    }
    else{
        //on cache la phrase d'attente
        hideWaitingMessage() ;
    }     
}

/**
 * Permet de charger tous les items a partir d'une liste de modeles
 * @param :
 *    - _client : ITOOL
 *    - _idModel : l'identifiant du modele (reference modele)
 *    - _idSite : l'identifiant du site
 *    - _idCentral : identifiant de la centrale
 * @desc :
 *    - recupere le serveur erep, initialise ce serveur et charge l'item correspondant au modele
*/
function getModel(_client, _idSite, _idCentral, _idModel, _isDisplayPrice, _isFromModel){
    //on va verifier si ce produit est deja dans la liste des favoris ou non
    verifMaSelection(_idModel) ;
    
    //on va verifier si le client ne vient pas d'un autre pays
    var idCentral = _idCentral ;
    var language = _language ;    
    var valueCookieCountry = getCookie("country") ;
    if(valueCookieCountry){
        var enseigneSiteObj = mapUrlParPays.get(valueCookieCountry) ;
        if(enseigneSiteObj){
            idCentral = enseigneSiteObj.getCentrale() ;
            language = valueCookieCountry ;
        }
    }
    
    if(idCentral != "-1"){    
        loadModel(_client, _idSite, idCentral, _idModel, _language, _isDisplayPrice, _isFromModel, POST_LOAD_ITEM_MODEL_FUNCTION) ;
    }
    else{
        //on va cacher le bloc ou acheter et les blocs oxylane
        var eltlocPrix = getElement("blocPrix"+_idModel, true, "") ;
        if(eltlocPrix){
            hideBloc(eltlocPrix) ;
        }
    
        var divOxyClubElement1 = getElement("ongletOxylaneAvis", true, "") ;
        var divOxyClubElement2 = getElement("ongletOxylaneService", true, "") ;
        var divOxyClubElement3 = getElement("oxylaneRecapAvis", true, "") ;
        if(divOxyClubElement1){
            hideBloc(divOxyClubElement1) ;
        }
        if(divOxyClubElement2){
            hideBloc(divOxyClubElement2) ;
        }
        if(divOxyClubElement3){
            hideBloc(divOxyClubElement3) ;
        }        
    }
}

/**
 * Permet de charger tous les items d'un departement et de lancer le traitement post appel Ajax
 * @param :
 *    - _client : ITOOL
 *    - _departmentId : l'identifiant du departement a recuperer
 *    - _idSite : l'identifiant du site
 *    - _idCentral : l'identifiant de la centrale
 *    - _bPriceData : recuperation ou non des prix
 *    - _isSlideShow : charge t on les donnees des produits rayons depuis la page slideshow
 *    - _localfunc : la fontion post ajax a appeler : par ex, POST_LOAD_SWITCH_VENTE_FUNCTION
 * @desc :
 *    - recupere le serveur erep, initialise ce serveur et charge tous les items de la famille
*/
function loadDepartment(_client, _departmentId, _idSite, _idCentral, _bPriceData, _isSlideShow, _localfunc){
    //doit on afficher les informations prix
    _displayPrice = _bPriceData ;
    isSlideShow = _isSlideShow ;
    
    //recupere le serveur eRep
    _urlErep = getUrlErep(_SERVICE_ITEM_DEPARTMENT, _client, "", _departmentId,  _idSite, _bPriceData,  _idCentral, "", _localfunc) ;
    if(_urlErep){
        /* RECUPERATION DU CONTEXT DE SERVICE */
        var oContext=getServiceContext(_urlErep, _language, _idSite, _idCentral);

        /* ACTIVATION DU MODE RAYON. */
        var departmentIdR3 = '13'; //Identifiant R3 du rayon        
        setModeContext(oContext, CONTEXT_MODE_RAYON, _departmentId);
                                        
        /* ACTIVATION DES FILTRES PRIX */
        activateDataFilter(oContext, true, ACT_FILTRE_PRIX);
        
        /* ACTIVATION DES FILTRES ASSORTIMENT */
        activateDataFilter(oContext, true, ACT_FILTRE_ASS);
                            
        /* recuperation de l id du service*/
        serviceId = executeService(oContext, POST_LOAD_ITEM_DEPARTMENT_FUNCTION);
        
   }
}

/**
 * Permet de charger tous les items a partir d'une liste de modeles et de lancer le traitement post appel Ajax
 * @param :
 *    - _client : ITOOL
 *    - _familyId : l'identifiant de la famille a recuperer
 *    - _subNumber1 : l'identifiant du site
 *    - _bPriceData : recuperation ou non des prix
 *    - _number2 : ""
 *    - _localfunc : la fontion post ajax a appeler : par ex, POST_LOAD_SWITCH_VENTE_FUNCTION
 * @desc :
 *    - recupere le serveur erep, initialise ce serveur et charge tous les items de la liste de modeles
*/
function loadModels(_client, _idSite, _idCentral, _localfunc){
    //recupere le serveur eRep
    _urlErep = getUrlErep(_SERVICE_ITEM_MODELS, _client, "", _idSite,  "", "",  _idCentral, "", _localfunc) ;
    
       // NOUVEAUX SERVICE
        // Creation du contexte
             var oContext = new JoServiceContext(_urlErep, _language, _idSite, _idCentral, _storeNumber);          
             
            /* ACTIVATION DU MODE MODELES. */            
            //var modelList = new ArrayList() ;

             if(_urlErep){
                    if(modelList && modelList.length() > 0){          
                        //charge les modeles pour les derniers modeles de la liste
                                  setModeContext(oContext, CONTEXT_MODE_MODELES, modelList);            
                    }
                    else{
                        //Dans le cas des ventes complementaire, on va cacher le bloc si aucun produit n'est dans la VC
                        hideBlockModels("bloc-decouvrirplus") ;
                    }
               }
               
               /* CONSTANTE POUR LES DIFFERENTS FILTRES */
                var ACT_FILTRE_PRIX = SERVICE_CONSTANTS.DATA_FILTER_PRICE ; //FILTRE SUR LES PRIX
                var ACT_FILTRE_ASS = SERVICE_CONSTANTS. DATA_FILTER_MIX ; //FILTRE SUR LES ASSORTIMENTS
               
                /* ACTIVATION DES FILTRES PRIX */
                activateDataFilter(oContext, true, ACT_FILTRE_PRIX);
                
                /* ACTIVATION DES FILTRES ASSORTIMENT */
                activateDataFilter(oContext, true, ACT_FILTRE_ASS);
                                                   
                  /* recuperation de l id du service*/
                  
                 serviceId = executeService(oContext, POST_LOAD_ITEM_MODELS_FUNCTION);
}

/**
 * Permet de charger tous les items d'une famille et de lancer le traitement post appel Ajax
 * @param :
 *    - _client : ITOOL
 *    - _idSite : l'identifiant du site
 *    - _idCentral : l'identifiant de la centrale
 *    - _idModel : identifiant du modele
 *    - _language : FR|EN|ES|IT ...
 *    - _localfunc : la fontion post ajax a appeler : par ex, POST_LOAD_SWITCH_VENTE_FUNCTION
 * @desc :
 *    - recupere le serveur erep, initialise ce serveur et charge tous les items de la famille
*/
function loadModel(_client, _idSite, _idCentral, _idModel, _language, _isDisplayPrice, _isFromModel, _localfunc){
    //doit on afficher les informations prix
    _displayPrice = _isDisplayPrice ;
    isFromModel =_isFromModel ;
    //recupere le serveur eRep
    _urlErep = getUrlErep(_SERVICE_ITEM_MODEL, _client, "", _idModel,  _idSite, _language,  _idCentral, "", _localfunc) ;
    idModel = _idModel ;

    // NOUVEAUX SERVICE
    // Creation du contexte
    var oContext = new JoServiceContext(_urlErep, _language, _idSite, _idCentral, _storeNumber);
    
    /* ACTIVATION DU MODE MODELE. */
    var _modelId = idModel; //Code modele du produit
    setModeContext(oContext, CONTEXT_MODE_MODELE, _modelId);
    
    /* CONSTANTE POUR LES DIFFERENTS FILTRES */
    var ACT_FILTRE_PRIX = SERVICE_CONSTANTS.DATA_FILTER_PRICE ; //FILTRE SUR LES PRIX
    var ACT_FILTRE_ASS = SERVICE_CONSTANTS. DATA_FILTER_MIX ; //FILTRE SUR LES ASSORTIMENTS            
            
    /* ACTIVATION DES FILTRES PRIX */
    activateDataFilter(oContext, true, ACT_FILTRE_PRIX);
    
    /* ACTIVATION DES FILTRES ASSORTIMENT */
    activateDataFilter(oContext, true, ACT_FILTRE_ASS);
                    
    /* recuperation de l id du service*/
    serviceId = executeService(oContext, POST_LOAD_ITEM_MODEL_FUNCTION);
}

/**
 * Permet de cacher le bloc de vente complementaire si tous les produits de la vente sont desactives
 * @param :
 *    - idBlockToHide : bloc VC a cacher
*/
function hideBlockModels(idBlockToHide){
    var blockToHide = getElement(idBlockToHide, true, "") ;
    if(!blockToHide){
        if(parent){
            blockToHide = parent.document.getElementById(idBlockToHide) ;
        }
    }
    
    if(blockToHide){
        //Si le nb de bloc cache est egal au nb de modele a afficher dans la VC, alors on va cacher ce bloc
        if(nbModelToCheck == nbModelHidden){
            hideBloc(blockToHide) ;
        }
        else{
            displayBlockModels(blockToHide) ;
        }
    }
}


/**
 * Permet d'afficher le bloc de vente complementaire
 * @param :
 *    - idBlockToDisplay : bloc VC a afficher
*/
function displayBlockModels(blockToDisplay){   
    if(blockToDisplay){
        blockToDisplay.style.display = "block" ;
    }
}


/**
 * Permet d'afficher le bloc de vente complementaire
 * @param :
 *    - _modeleCourant : le modele courant pour lequel il faut recuperer le produit precedent et le produit suivant
*/
function displayPrevNextProduct(_modeleCourant){
    //variable declarer dans la page html du slideshow            
    if(_modeleCourant && typeof _modeleCourant == "string"){
        var indexModeleCourant = enableModelList.contains(_modeleCourant) ;

        if(indexModeleCourant != -1){
            //on recupere le modele precedant
            var modelePrev = getPrevProduct(indexModeleCourant, indexModeleCourant-1) ;
            
            //si le modele precedent existe et que l'index du modele courant n'est pas 0, c'est a dire ce n'est pas le premier modele de la liste
            if(modelePrev != "" && indexModeleCourant > 0){
                var produitPrevObj = getElement("vignetteproduit-"+modelePrev , true, "") ; //alors on recupere le bloc html correspondant au modele precedent
                if(produitPrevObj){ //si ce bloc html est ok alors on affiche ce bloc
                    var destBlocHtmlPrev = getElement("blocnavigationinterne-prev", true, "") ;
                    if(destBlocHtmlPrev){
                        var libProduitNextObj = getElement("libProduitNext"+modelePrev, true, "") ;
                        var pictoProduitNextObj = getElement("pictoProduitNext"+modelePrev, true, "") ;
                        
                        hideBloc(libProduitNextObj) ;
                        hideBloc(pictoProduitNextObj) ;                    
                        destBlocHtmlPrev.innerHTML = produitPrevObj.innerHTML ;
                    }                
                }
            }
            
            //on recupere le modele precedant
            var modeleNext = getNextProduct(indexModeleCourant, indexModeleCourant+1) ;
            //si le modele suivant existe et que l'index du modele courant n'est le dernier modele de la liste
            if(modeleNext != "" && indexModeleCourant < modelList.length()){
                var produitNextObj = getElement("vignetteproduit-"+modeleNext , true, "") ; //alors on recupere le bloc html correspondant au modele suivant
                if(produitNextObj){ //si ce bloc html est ok alors on affiche ce bloc
                    var destBlocHtmlNext = getElement("blocnavigationinterne-next", true, "") ;
                    if(destBlocHtmlNext){
                        var libProduitPrevObj = getElement("libProduitPrev"+modeleNext, true, "") ;
                        var pictoProduitPrevObj = getElement("pictoProduitPrev"+modeleNext, true, "") ;
                        
                        hideBloc(libProduitPrevObj) ;
                        hideBloc(pictoProduitPrevObj) ;                    
                        destBlocHtmlNext.innerHTML = produitNextObj.innerHTML ;
                    }
                }
            }
        }
        
        //Renseignement des informations rayons            
        //_rayonName provient de la page HTML
        if(_rayonName && typeof _rayonName == "string"){
            var nomRayonNavObj = getElement("nomRayonNav", true, "") ;
            if(nomRayonNavObj){
                var libelleRetourRayon = _libelleRetourRayon.replace("_RAYON_", "\""+decodeURI(_rayonName)+"\"") ;                
                nomRayonNavObj.innerHTML = libelleRetourRayon ;
            }
        }
        
        //_retour provient de la page HTML
        if(_retourUrl && typeof _retourUrl == "string"){
            var retourRayonObj = getElement("lienproduitretour", true, "") ;
            if(retourRayonObj){
                retourRayonObj.href = "javascript:retourRayon(\'"+_retourUrl+"\')" ;
                
            }
        }
    }
}

/**
 * Permet de retourner au rayon
*/
function retourRayon(_retourUrl){
    parent.document.location.href = _retourUrl ;
}


/**
 * Permet de recuperer le produit precedent
 * @param :
 *    - _modeleCourant : le modele courant pour lequel il faut recuperer le produit precedent et le produit suivant
 *    - _indexModelePrev : l'index du modele precedent
*/
function getPrevProduct(_indexModeleCourant, _indexModelePrev){
    //recuperation du modele precedent
    var modelePrev = "" ;
    if(_indexModeleCourant > 0){
        modelePrev = enableModelList.get(_indexModelePrev) ;
    }
    return modelePrev ;
}


/**
 * Permet de recuperer le produit suivant
 * @param :
 *    - _modeleCourant : le modele courant pour lequel il faut recuperer le produit precedent et le produit suivant
 *    - _indexModeleNext : l'index du modele suivant
*/
function getNextProduct(_indexModeleCourant, _indexModeleNext){
    //recuperation du modele suivant
    var modeleNext = "" ;
    if(_indexModeleCourant < enableModelList.length()){
        modeleNext = enableModelList.get(_indexModeleNext) ;
    }
    return modeleNext ;
}
