/*##############################################################################################
############ JS DES FONCTIONS DE GESTION D'AFFICHAGE DE LA PAGE DE CONNEXION AU MAGASIN ######### 
/*############################################################################################## */

// Variable GLOBALE
var DocRef;
var AfficheFiltre = false;
var X_navigateur = navigator.appName.toLowerCase();
var X_Platform   = navigator.platform.toLowerCase();
var X_version    = navigator.appVersion.toLowerCase();
var DocParent;

// Version de Internet Explorer
if(X_navigateur == 'microsoft internet explorer'){
    X_version_deb = X_version.indexOf('(') + 1;
    X_version_fin = X_version.indexOf(')');
    X_version     = X_version.substring(X_version_deb, X_version_fin);
    XtabTmp       = X_version.split(';');
    for(i in XtabTmp){
        if(XtabTmp[i].indexOf('msie') > -1){
            X_version = parseInt(XtabTmp[i].replace('msie', ''));
            break;
        }
    }
}


/** #########################################
* Permet d'ouvrir une popup filter
*/
function displayPopupFilter(idObj, idObjContainer, content, width, height, iframeName, dofilter, doScroll, isUrl){
    if(dofilter == null || dofilter){
        show_filter(idObj);
    }
    
    var playerVideoObj = getElement("player-video", true, "") 
    if(playerVideoObj){
        playerVideoObj.style.visibility = "hidden" ;
    }
    
    if(idObjContainer){        
        getElement(idObjContainer, true, "").innerHTML = "" ;
        show_popup("calque", content, width, height, iframeName, idObjContainer, doScroll, isUrl);        
    }
    
    var flash=null;
    var flashs=document.getElementsByTagName('embed');
    if(flashs.length==0) flashs=document.getElementsByTagName('object');
    for(var i=0;i<flashs.length;i++){
        if(flashs[i].id=='body-flash-hp') flash=flashs[i] ;
    }
    
    var listeFamille = document.getElementById('liste-familles');
    if(listeFamille)listeFamille.style.display='none';
    var noflash = document.getElementById('noflash');
    
    if(flash){
        var isDisplayFlash = true ;
        if(navigator.appName == "Microsoft Internet Explorer"){
            var wmodeFlash = "" ;
            if(flash.wmode){
                wmodeFlash = flash.wmode.toLowerCase() ;
            }
            
            if(wmodeFlash == "opaque" || wmodeFlash == "transparent"){
                isDisplayFlash = false ;
            }
            else{
                isDisplayFlash = true ;
            }
        }
        else{
            var divElt = document.getElementById("body-flash-hp") ;           
            if(divElt){
                var html = divElt.innerHTML ;
                if(html && html.indexOf('wmode="opaque"') > -1 || html.indexOf('wmode="transparent"') > -1){
                    isDisplayFlash = false ;
                }
                else{
                    isDisplayFlash = true ;
                }
            }
        }
        
        if(isDisplayFlash){
            flash.style.display = 'none';
            if(noflash)noflash.style.display = 'block';
        }
    }
}


/** #########################################
* Permet de fermer une popup filter pour le produit
*/
function hidePopup(){   
    var heightcalquedefault = "577px" ;
    var widthcalquedefault = "560px" ;

    var calquecontainer = getElement("calquecontainer", false, "") ;
    
    var calque =  getElement("calque", false, "") ;
    if(calque && calquecontainer){
        hide_all(calque.id) ;
        if(heightcalquedefault){
            calque.style.height = heightcalquedefault ;
        }
        if(widthcalquedefault){
            calque.style.width = widthcalquedefault ;
        }
        calquecontainer.style.backgroundImage = "" ;
    }
    
    var flash=null;
    var flashs = document.getElementsByTagName('embed');
    if(!flashs){
        flashs = parent.document.getElementsByTagName('embed');
    }
    if(!flashs){
        flashs = parent.parent.document.getElementsByTagName('embed');
    }
    
    if(flashs.length==0){
        flashs = document.getElementsByTagName('object');
        if(!flashs){
            flashs = parent.document.getElementsByTagName('object');
        }
        if(!flashs){
            flashs = parent.parent.document.getElementsByTagName('object');
        }
    }
    
    for(var i=0;i<flashs.length;i++){
        if(flashs[i].id=='body-flash-hp')flash=flashs[i];
    }

    var listeFamille = getElement('liste-familles', false, "");
    if(listeFamille)listeFamille.style.display='block';
    
    var noflash = getElement('noflash', false, "");
    if(flash){
        flash.style.display = 'block';
        if(noflash)noflash.style.display='none';
    }
    
    var playerVideoObj = getElement("player-video", false, "") 
    if(playerVideoObj){
        playerVideoObj.style.visibility = "visible" ;
    }
    var bodyflashhp = getElement("body-flash-hp", false, "") ;
    if(bodyflashhp){
        bodyflashhp.style.display = "block" ;
    }
    
}


/*############################################################################################## */
// Document en cours
function MonDocument(){
    if(DocRef == null){
        if(parent.document.documentElement && parent.document.documentElement.clientWidth){
            DocRef = parent.document.documentElement;
        }else{
            DocRef = document.body;
        }
    }
}


/*############################################################################################## */
function MonParent(){
   if (parent) { // It is an iframe and there is a parent window
        if (parent.document.documentElement && parent.document.documentElement.clientHeight) {
            return parent.document.documentElement;
        } else {
            return parent.document.body;
        }
   } else { 
        if(!DocRef) {
        	MonDocument();
        }
        return DocRef;
   }
}


/*############################################################################################## */
// Action de resize sur le filter
function gestion_filtre(objName){
    var X_block = document.getElementById(objName);
   
}


/*############################################################################################## */
// Affiche le filtre d'opacite

function show_filter(objName){   
    var filtre = parent.document.getElementById(objName);
    if(!filtre){
        filtre = parent.parent.document.getElementById(objName);
    }
    if(filtre){
        filtre.style.display = 'block';

        if(!DocRef){
            MonDocument() ;
        }
        var X_largeur = DocRef.scrollWidth;
        var X_hauteur = DocRef.scrollHeight;
        
        filtre.style.width = X_largeur + 'px';
        filtre.style.height = X_hauteur + 'px';
        filtre.style.marginTop = '0';
        filtre.style.marginLeft = '0';
        
        //Change opacite
        changeOpac(70, objName);
    }
}


/*############################################################################################## */
//Change opacite
function changeOpac(opacity, id){
    var object = parent.document.getElementById(id);
    if(!object){return false;}
    object = object.style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}


/*############################################################################################## */
//Desactivation de l'opacite
function hideOpac(id){
    var object = parent.document.getElementById(id);
    if(!object){return false;}
    object = object.style;
    object.opacity =  "" ;
    object.MozOpacity =  "" ;
    object.KhtmlOpacity =  "" ;
    object.filter = "";
}


/*############################################################################################## */
// Cache le filtre d'opacite
function hide_filter(objName){
    var X_block = parent.document.getElementById(objName);
    if(!X_block){
        X_block = parent.parent.document.getElementById(objName);
    }    
    if(!X_block){
         X_block = document.getElementById(objName);
    }
    
    if(X_block){
        //hideOpac(objName);
        X_block.style.display = "none" ;
    }
}


/*############################################################################################## */
// Affiche la popup/Iframe
function show_popup(objName, content, width, height, iframeName, idCalqueContainer, doScroll, isUrl){
    var X_block = parent.document.getElementById(objName);
    if(!X_block){
        X_block = parent.parent.document.getElementById(objName);
    }    
    if(!X_block){
         X_block = document.getElementById(objName);
    }
    
    if(X_block) {
        X_block.style.visibility = 'hidden';
        X_block.style.display = 'block';
        PositionPopup(objName,width,height);
        X_block.style.visibility = 'visible';
        if(width != "") {
            X_block.style.width = width +"px" ;       
        }        
        if(height != ""){
             X_block.style.height = height +"px" ;
        }

        var imageBottom = getElement("calquebottom", true, "") ;
        if(imageBottom){
            hideBloc(imageBottom) ;
        }

        var scroll = true;
        if (typeof doScroll != "undefined")
        {
            scroll = doScroll;
        }

        var isUrlContent = true ;
        if(typeof isUrl != "undefined"){
            isUrlContent = isUrl ;
        }
        
        if(isUrlContent){
            if(iframeName && iframeName != ''){
                var calqueContainerObj = getElement(idCalqueContainer, true, "") ;
                if(calqueContainerObj){
                    if (iframeName=='iframe-3d'){
                        calqueContainerObj.innerHTML = '<div id="bloc_fermer"><a href="javascript:hidePopup();""><img src="/FR/images/static/0810-closepopup.gif" align="absmiddle" alt="close" onclick="hidePopup();"/></a></div>'  + 
                        '<iframe id="'+iframeName+'" scrolling="no" frameborder="0" marginheight="0" marginwidth="0" src="'+content+'" width="'+(width)+'" height="'+(height-60)+'"></iframe>' ;
                    }
                    else if(iframeName=='map-decathlon'){
                        calqueContainerObj.innerHTML = '<div id="bloc_fermer"><a href="javascript:hidePopup();""><img src="/FR/images/static/0810-closepopup.gif" align="absmiddle" alt="close" onclick="hidePopup();"/></a></div>'  + '<iframe id="'+iframeName+'" scrolling="' + scroll + '" frameborder="0" marginheight="0" marginwidth="0" src="'+content+'" width="'+width+'" height="'+height+'"></iframe>' ;
                    }
                    else if(iframeName=='iframe-sondage'){
                        calqueContainerObj.innerHTML = '<div id="bloc_fermer"><a href="javascript:hidePopup();""><img src="/FR/images/static/1812-closepopup.gif" align="absmiddle" alt="close" onclick="hidePopup();"/></a></div>'  + '<iframe id="'+iframeName+'" scrolling="' + scroll + '" frameborder="0" marginheight="0" marginwidth="0" src="'+content+'" width="'+width+'" height="'+height+'"></iframe>' ;
                    }
                    else if(iframeName=='iframehd'){
                        if(imageBottom){
                            displayBloc(imageBottom) ;
                        }
                        calqueContainerObj.style.backgroundImage = "url(../images/static/0810-bg-calquephotospdt.gif)" ;                    
                        calqueContainerObj.innerHTML ='<iframe id="'+iframeName+'" scrolling="no" frameborder="0" marginheight="0" marginwidth="0" src="'+content+'" width="'+(width-2)+'" height="'+(height-30)+'"></iframe>' ;
                    }
                    else{
                        calqueContainerObj.innerHTML ='<iframe id="'+iframeName+'" scrolling="no" frameborder="0" marginheight="0" marginwidth="0" src="'+content+'" width="'+width+'" height="'+height+'">' ;
                    }
                    X_block.style.display = "block" ;
                }
            }
            else{
                var calqueContainerObj = getElement(idCalqueContainer, true, "") ;
                if(calqueContainerObj){
                    loadContentPage(content, calqueContainerObj) ;
                }
            }
        }
        else{
            var calqueContainerObj = getElement(idCalqueContainer, true, "") ;
            if(calqueContainerObj){
                if(content == "player-video"){
                    calqueContainerObj.innerHTML = '<div id="bloc_fermer"><a href="javascript:hidePopup();""><span>'+fermerFenetreLib+'</span><img src="/FR/images/static/0810-closepopup.gif" align="absmiddle" alt="close" onclick="hidePopup();"/></a></div><div id="player"></div>' ;
                    
                    setPlayerFlash(idContainer, fileNameFlash, "flash", playerPath, width, height, versionFlash, "true", "flv") ;
                }
            }
        }
    } 
    else {
        return false;
    }
}


/*############################################################################################## */
// Cache le Filtre et popup/iframe
function hide_all(TsPopup){
    hide_popup(TsPopup);
    
    //on va verifier que la fiche produit n'est plus affiche
    var objCalqueProduit = parent.document.getElementById("calqueproduit");
    if(!objCalqueProduit){
        objCalqueProduit = parent.parent.document.getElementById("calqueproduit");
    }    
    if(!objCalqueProduit){
         objCalqueProduit = document.getElementById("calqueproduit");
    }
    
    if(!objCalqueProduit || (objCalqueProduit && objCalqueProduit.style.display == "none")){
        hide_filter('filtre');
    }
}


/*############################################################################################## */
// Cache la popup/Iframe
function hide_popup(objName){
    var X_block = parent.document.getElementById(objName);
    if(!X_block){
        X_block = parent.parent.document.getElementById(objName);
    }    
    if(!X_block){
         X_block = document.getElementById(objName);
    }
    
    if(X_block){
        X_block.style.display = 'none';      
        X_block.style.backgroundImage="";
    } else {
        return false;
    }
}


/*############################################################################################## */
// Calcule la position de la popup/iframe
function PositionPopup(X_obj,width,height){
    var X_block = parent.document.getElementById(X_obj);
    if(!X_block){
        X_block = parent.parent.document.getElementById(X_obj);
    }    
    if(!X_block){
         X_block = document.getElementById(X_obj);
    }
    
    var heightBloc = X_block.offsetHeight ;
    if(height && height != ''){
        heightBloc = parseInt(height) + 2 ;
    }
    var widthBloc = X_block.offsetWidth ;
    if(width && width != ''){
        widthBloc = parseInt(width) + 2 ;
    }
    
    if( !X_block ){return false;}
    if(!DocRef){MonDocument();}
    var X_blockTop = (parseInt(DocRef.clientHeight) - parseInt(heightBloc)) /2;
    X_block.style.top = parseInt(DocRef.scrollTop) + parseInt(X_blockTop) + 'px';
    var X_blockLeft = (parseInt(DocRef.clientWidth) - parseInt(widthBloc)) /2;
    var leftPosition = parseInt(DocRef.scrollLeft) + parseInt(X_blockLeft);
    
    X_block.style.left=parseInt(leftPosition)+'px';    
}


/*############################################################################################## */
// Affiche ou Cache les SELECT de la page
function gestion_select(X_option){
    var X_balises = document.getElementsByTagName('select');
    for(i=0; i<X_balises.length; i++){
       X_balises[i].style.visibility = X_option;
    }
    if (window.frames['basketContent']){
        var X_balisesFrame=window.frames['basketContent'].document.getElementsByTagName('select');
         for(i=0; i<X_balisesFrame.length; i++){
           X_balisesFrame[i].style.visibility = X_option;
        }
     }
    // Cela cache egalement les select de la popup recherche. 
    // Il faut donc reafficher ces select
    if (document.getElementById("popuprecherche")) {
        X_balises = document.getElementById("popuprecherche").getElementsByTagName('select');
        for(i=0; i<X_balises.length; i++){
            X_balises[i].style.visibility = 'visible';
        }
    }
    if (document.getElementById("localprice-resa")) {
      X_balises = document.getElementById("localprice-resa").getElementsByTagName('select');
        for(i=0; i<X_balises.length; i++){
            X_balises[i].style.visibility = 'visible';
        }
    }
    
}


/*############################################################################################## */
// Gestion du filtre au onresize et onscroll
window.onscroll = window.onresize = function(){gestion_filtre();}
/*############################################################################################## */
// Affiche ou Cache le bloc reconnaitre du formulaire de connexion magasin en fonction de la case cochee ou non
function gestion_checkbox() {    
    if(isCheck('checkb')) {
            showBloc('reconnaitre');                	
            window.parent.document.getElementById('filter_frame').style.height=475;
            changeHeight('contenuquestion',180);       
            checkOrUncheck('checkb', true);
       }
       else {
            checkOrUncheck('checkb', false);
            hideBloc('reconnaitre');                          	
    }       
}
/** #########################################
* Permet d'ouvrir une popup filter video
*/
function displayPopupFilterVideo(idObj, idObjContainer, idBlock, width, height, iframeName, dofilter){
    if(dofilter == null || dofilter){
        show_filter(idObj);
    }  
    
    if(idObjContainer){        
        document.getElementById(idObjContainer).innerHTML = "" ;
        show_popup_video("calque",  width, height, iframeName, idBlock);        
    }    

    var listeFamille = document.getElementById('liste-familles');
    if(listeFamille)listeFamille.style.display='none';
    
    if(document.getElementById('div-main-3d')){
        document.getElementById('div-main-3d').style.display='none';
        if(document.getElementById('div-main-picture')){
            document.getElementById('div-main-picture').style.display='block';
        }
    }
    if(document.getElementById('body-flash')){
        document.getElementById('body-flash').style.visibility='hidden';
    }
}


/* pour la video produit */
function hidePopupVideo(){   
    var heightcalquedefault = "577px" ;
    var widthcalquedefault = "560px" ;

    var calquecontainer = document.getElementById("calquecontainer") ;
    if(!calquecontainer)calquecontainer = parent.document.getElementById("calquecontainer") ;
    
    var calque =  document.getElementById("calque") ;
    if(!calque)calque = parent.document.getElementById("calque") ;
    
    if(calque && calquecontainer){
        hide_all(calque.id) ;
        if(heightcalquedefault){
            calque.style.height = heightcalquedefault ;
        }
        if(widthcalquedefault){
            calque.style.width = widthcalquedefault ;
        }
    }
    
    displayElement() ;
    
    
    var blockVideoProduit = getElement("blocVideo",true,"");
     if(blockVideoProduit){
        blockVideoProduit.style.display = "none" ;
    }
    
    if(document.getElementById('body-flash')){
        document.getElementById('body-flash').style.visibility='visible';
    }
    if(document.getElementById("flash-player-video")){
        document.getElementById("flash-player-video").innerHTML="";
    }
}


// Affiche la popup/Iframe
function show_popup_video(objName,  width, height, iframeName, idCalqueContainer){	
    var X_block = parent.document.getElementById(idCalqueContainer);
    if(!X_block){
        X_block = parent.parent.document.getElementById(idCalqueContainer);
    }    
    if(!X_block){
         X_block = document.getElementById(idCalqueContainer);
    }
    
    if(X_block) {
        X_block.style.visibility = 'hidden';
        X_block.style.display = 'block';
        PositionPopup(idCalqueContainer,width,height);
        X_block.style.visibility = 'visible';
        if(width != "") {
            X_block.style.width = width +"px" ;       
        }        
        if(height != ""){
             X_block.style.height = height +"px" ;
        }

        var imageBottom = getElement("calquebottom", true, "") ;
        if(imageBottom){
            hideBloc(imageBottom) ;
        }
         var flash = getElement("body-flash-hp", true, "") ;
         if(flash){
             flash.style.display='block';
         }
      
        var calqueContainerObj = getElement(idCalqueContainer, true, "") ;
        if(calqueContainerObj){   
            calqueContainerObj.style.display="block" ;
        }
    } 
    else {
        return false;
    }
}
/** #########################################
* Permet d'afficher les elements suivant lorsqu'un calque filter est ferme
*/
function displayElement(){
    var flash=null;
    var flashs = document.getElementsByTagName('embed');
    if(!flashs){
        flashs = parent.document.getElementsByTagName('embed');
    }
    if(!flashs){
        flashs = parent.parent.document.getElementsByTagName('embed');
    }
    
    if(flashs.length==0){
        flashs = document.getElementsByTagName('object');
        if(!flashs){
            flashs = parent.document.getElementsByTagName('object');
        }
        if(!flashs){
            flashs = parent.parent.document.getElementsByTagName('object');
        }
    }
   
    for(var i=0;i<flashs.length;i++){
        if(flashs[i].id=='body-flash-hp')flash=flashs[i];
    }
    
    var listeFamille = getElement('liste-familles', false, "");
    if(listeFamille)listeFamille.style.display='block';
    
    var noflash = document.getElementById('noflash');
    if(!noflash)noflash=parent.document.getElementById('noflash');
    if(flash){
        flash.style.display = 'block';
        if(noflash)noflash.style.display='none';
    }
    
    var playerVideoObj = getElement("player-video", false, "") 
    if(playerVideoObj){
        playerVideoObj.style.visibility = "visible" ;
    }
     if(document.getElementById('div-main-3d')){
        document.getElementById('div-main-3d').style.display='block';
        if(document.getElementById('div-main-picture')){
            document.getElementById('div-main-picture').style.display='none';
        }
    }
}
/*############################################################################################## */
var _blocContainer = null ;

var POST_LOAD_CONTENT_PAGE_FUNC = function postILoadContentPage(xmlHttp, httpstatus){    
    if(httpstatus == 200){
        var oXmlDoc = xmlHttp.responseText ;
        _blocContainer.innerHTML = oXmlDoc ;
        _blocContainer.style.display = "block" ;
    }
    else{
    }
}

// Charge le contenu dans la popup
function loadContentPage(urlContent, blocContainer){
    _blocContainer = blocContainer ;

    var ajaxProc = new IAjaxProcess(urlContent, POST_LOAD_CONTENT_PAGE_FUNC) ;
    ajaxProc.run() ;
}

