/**
* FICHIER JS pour la gestion de la vente complementaire
/* AVEC NVO SERVICES EREP DU 30 MARS 2009*/

/** #########################################
* Permet de generer la zone "Decouvrir plus"
*/                      
function getDecouvrirPlus(rootPath, urlRayon, urlProduit){
    _urlProduit = urlProduit ;
    
    var urlVcToCheck = new Array() ;
    urlVcToCheck[0] = urlProduit ;
    urlVcToCheck[1] = urlRayon ;
    
    _indexUrlToCheck = 0 ;
    
    //Recuperation des ventes complementaires associees aux differents niveaux
    getVc(urlVcToCheck, rootPath) ;
}

/** #########################################
* Permet de setter la VC ou de chercher la VC suivante
*/     
var POST_LOAD_VC_FUNCTION = function postGetVc(xmlHttp, httpStatus){
    //Si une VC repond, on va afficher l'iframe dans la bloc produit concerne 
    
    var blocDecouvrirVC = document.getElementById("bloc-decouvrirplus");
    
    if(httpStatus == "200"){
        //Url de la VC qui a repondu
        var urlVc = _urlVcToCheck[_indexUrlToCheck];
        if(xmlHttp.responseText.indexOf("vc-body")> -1){
            var iframeVc = "<iframe id='iframe-vc' src='"+_rootPath+urlVc+"VC.html?refProduit="+_urlProduit+"' scrolling='no' frameborder='0'></iframe>" ;
            setHtml("bloc-vc", iframeVc) ;   
        }
        else{
            _indexUrlToCheck++ ;
            getVc(_urlVcToCheck, _rootPath) ;
            if(blocDecouvrirVC){
                blocDecouvrirVC.style.display="none";
            }
        }                  
    }
    //Sinon on va chercher la VC au niveau superieur
    else{
        _indexUrlToCheck++ ;
        getVc(_urlVcToCheck, _rootPath) ;
        if(blocDecouvrirVC){
            blocDecouvrirVC.style.display="none";
        }
    }
}

/** #########################################
* Permet de recuperer les VC
*/     
function getVc(urlVcToCheck, rootPath){
    _urlVcToCheck = urlVcToCheck ;
    _rootPath = rootPath ;
    
    //Pour tous les niveaux (rayon, famille, produit) on va verifier si une VC y est associer
    if(_indexUrlToCheck < _urlVcToCheck.length){
        var urlVc = _urlVcToCheck[_indexUrlToCheck] ;
        
        if(urlVc && urlVc != ""){
             urlVc = _rootPath + urlVc + "VC.html"

            var oProcess = new IAjaxProcess(urlVc, POST_LOAD_VC_FUNCTION);
            oProcess.run();
        }
    }
}
