/*##############################################################################################
##################### JS DES FONCTIONS POUR LA DIV PRIX STOCK LOCAL  ############################# 
/*############################################################################################## */
/*############################################################################################## */
var marquePassion;

/*############################################################################################## */
/* Methode dans la fonction de post chargement d un article en magasin pour remplir le gabarit du div prix-stock-local (avec ou sans eresa)*/
function openLiveStock(){	   
    loaded = false;
    
    var func = function (xmlHttp, httpStatus) {
        oGlobalText = xmlHttp.responseText;
        if(oGlobalText!=null) {     	                
            setBlocByHtml('popup-local-price',xmlHttp.responseText);
            loaded = true;
            
            // Tag
            if (typeof pageTracker != 'undefined') {
                var gat = new gaTransac();
                gat.trackProcessStep("local_stock");
            }
        }
    };
    
    var oProcess = new IAjaxProcess(urlDivLocalPrice, func);	
    oProcess.run();
}
/*############################################################################################## */ 
/* Remplis les blocs declares dans la div prix stock local avec ou sans eresa par les infos prix recuperees de la methode getPriceStockModele  */
function displayLiveStock(serverDate, bEresa) {

    if (loaded) {
        // Marqueur marque passion
        marquePassion=getBlocHtml('marquePassion');
        
        // Remplissage infos produit
        var oHotPict = document.getElementById("hot_pict");
        if (oHotPict) {
            if (urlPhotoProduitLocalStock!='') {
                createElement_img("hot_pictureModel","",urlPhotoProduitLocalStock,"","","",oHotPict);
            }
        }        
        setBlocByHtml('hot_brand',getTitleBloc('logoMarqueCourante'));      
        setBlocByHtml('hot_libelleModel',libelleModele);	
        setBlocByHtml('hot_numModel',_modelId);              
        setBlocByHtml('hot_numItem',s.value);
        setBlocByHtml('hot_declinaison', s[s.selectedIndex].text);
/*
        // Affichage du logo fin de collection uniquement si l article est en etape 3 ou 7 ou 8
        if (etape==3 || etape==7 || etape==8) showBloc('fin-collection');                                                                                         
*/
        // Bloc prix
        if (afficheCartouchePrix=='Y') setBlocByHtml('hot_price',displayPriceArticle());
        else hideBloc('local-price');

        // Nom magasin
        setBlocByHtml('hot_storeLabel1',getEltFromUrl(cookieMagasin, 'magasin'));
        setBlocByHtml('hot_storeLabel2',getEltFromUrl(cookieMagasin, 'magasin'));
        setBlocByHtml('hot_storeLabel3',getEltFromUrl(cookieMagasin, 'magasin'));
        
        // Remplit bloc date et heure serveur
        setBlocByHtml('hot_infoDate',serverDate.getLiteralDate(getFormatDateHeure()));

        // Stock et ERESA
        if (stock == 3) showBloc('hot_libStockProchainement');
        if (stock == 2) showBloc('hot_libStockIndispo');
        if (stock == 1) {
            if (parseInt(valeur_stock) < 2) {
                setBlocByHtml('hot_stock1',valeur_stock);
                showBloc('hot_stock_sing');
            }
            else {
                setBlocByHtml('hot_stock2',valeur_stock);
                showBloc('hot_stock_plur');
            }

            // Remplisssage liste quantite et test affichage bloc quantite et bouton reserver
            // Si stock pas egal a 0  ET affichage prix produits ami autorisee ET article pas en etape 2 
            // ET pays autorise reservation sur articles soldes en periode de soldes
            // ET le niveau d arbo n est pas exclu de la eResa
            if (getSwitchSite('BOOKING') && getSwitchMagasin('FLAG_BOOKABLE')) {
                var listQuantity = document.getElementById("liste-quantite");
                if (listQuantity) {
                    if ( (marquePassion == 'true' || (marquePassion != 'true' && getSwitchSite('AMI_MAGASIN'))) && getSwitchSite('ACTIVATION_PRIX_MAGASIN') && getSwitchMagasin('ACTIVATION_PRIX_MAGASIN') && bEresa) {                             
                        if (!isSoldPrice || (isSoldPrice && getSwitchSite('RESERVATION_PERIODE_SOLDE')) ) {
                            for (var i = 1; i <= valeur_stock; i++) { 
                                listQuantity.options[listQuantity.options.length] = new Option(i,i);
                            }                                         
                            showBloc('book');
                        }              
                    }
                }
            }
        }       

        // Si eresa bloquee par switch alors affichage message informatif
        if (!bEresa) showBloc("hot_noEresa");

        // Infos etapes ERESA
        extractEbookingSteps(urlEbookingSteps, 'steps-ebooking', POST_EXTRACT_EBOOKING_STEPS_LOCAL_PRICE_FUNCTION);
        
        
        // SPECIFIQUE RO ET TEMPORAIRE (a supprimer qd RO aura la eresa)
        if(_siteNumber == 146621755 && !getSwitchSite('BOOKING') || !getSwitchMagasin('FLAG_BOOKABLE')) {
            urlMagasin = getEltFromUrl(cookieMagasin, "urlMag");
            // Recuperation des infos magasin
            getStoreInfos(urlMagasin,POST_LOAD_ERESA_STOREINFOS_FUNCTION);
        }
        
        // Affichage de la div prix stock local 			
        show_filter('filter');			
        show_popup('popup-local-price');
        defineWidth('formBook');
          }

    else window.setTimeout(function(){displayLiveStock(serverDate, bEresa);}, 10);
}

// SPECIFIQUE RO ET TEMPORAIRE (a supprimer qd RO aura la eresa)
var POST_LOAD_ERESA_STOREINFOS_FUNCTION = function(httpStatus, theFlow) {
    if(httpStatus != null && httpStatus == 200 && theFlow != "") {
        // Coordonnees du magasin
        var coordMag = theFlow.substring(theFlow.indexOf('<div class="coord">#BEGIN'));
        coordMag = coordMag.substring(0,coordMag.indexOf('#END</div>'));
        coordMag = coordMag.replace(/#BEGIN/, '');
        coordMag = coordMag.replace(/#END/, '');
        coordMag += "</div>";
        
        var infosSup = '';
        // Infos supplementaires
        if(theFlow.indexOf('<div class="infosupp"') != -1) {
            infosSup= theFlow.substr(theFlow.indexOf('<div class="infosupp">#BEGIN'));
            infosSup = infosSup.substring(0,infosSup.indexOf('#END</div>'));
            infosSup = infosSup.replace(/#BEGIN/, '');
            infosSup = infosSup.replace(/#END/, '');
            infosSup += "</div>";
        }
        
        coordMag += infosSup;
        
        if (coordMag != "") document.getElementById("coordMag-eresa").innerHTML = coordMag + document.getElementById("coordMag-eresa").innerHTML;
    }
}

/*############################################################################################## */ 
/* Fermeture de la popup*/
function closeLiveStock() {
    hide_all('popup-local-price');
}

/*############################################################################################## */ 
/* Ouverture popup plus d infos*/
function openLiveStockHowItWorks() {
    hide_popup('popup-local-price');
    show_popup('popup-commentcamarche');
}

/*############################################################################################## */ 
/* Validation du formulaire*/
function checkForAddBasketLiveStock() {
    // Gestion affichage
    hideBloc('popup-local-price');
    positionPopup('affWait');
    showBloc('affWait');

    // Ajout panier
    var qty = document.getElementById('liste-quantite')[document.getElementById('liste-quantite').selectedIndex].value;

    if (parseInt(qty) < 1) alert(libSelectQuantity);
    else addBasket(qty);
}
