/*##############################################################################################
############ 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 douvrir une popup filter*/

function displayPopupFilter(idObj, idObjContainer, urlContent, width, height, iframeName, dofilter){
    if(dofilter == null || dofilter){
        show_filter(idObj);
    }
    
    if(idObjContainer){
        if(idObjContainer != "calqueVideoPopup" && idObjContainer != "calqueOxyAvis" && idObjContainer != "calqueOxyPlus" && idObjContainer != "calqueNews"){
            getElement(idObjContainer, true, "").innerHTML = "" ;
        }
        show_popup("calque", urlContent, width, height, iframeName, idObjContainer);        
    }
}

/** ######################################### */
/*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 = "" ;
    }
}

/** ######################################### */
/*Permet de fermer une popup filter pour le produit
*/
function hidePopupOxylane(){   
    var heightcalquedefault = "723px" ;
    var widthcalquedefault = "500px" ;
        
    var calqueOxylane =document.getElementById("calqueOxylane");        
    var filtreOxylane =document.getElementById("filtreOxylane");        
    var IframeOxylaneServices = document.getElementById("oxylaneServices");    
    var IframeOxylaneAvis = document.getElementById("oxyIframeAvis");    

    if(calqueOxylane){
        calqueOxylane.style.display="none";
    }
    
    if(IframeOxylaneAvis){
         IframeOxylaneAvis.style.display="none";
    }

    if(IframeOxylaneServices){
         IframeOxylaneServices.style.display="none";
    }
    
    if(filtreOxylane){
        filtreOxylane.style.display="none";
    }
    
    if(heightcalquedefault){
        calqueOxylane.style.height = heightcalquedefault ;
    }
    if(widthcalquedefault){
        calqueOxylane.style.width = widthcalquedefault ;
    }
    
    var calqueOxylaneAvis = document.getElementById("calqueOxyAvis");
    if(calqueOxylaneAvis){
        calqueOxylaneAvis.style.display="none";
    }
    var calqueOxylanePlus = document.getElementById("calqueOxyPlus");
        if(calqueOxylanePlus){
        calqueOxylanePlus.style.display="none";
    }          
}

/*############################################################################################## */
// 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 = parseInt(DocRef.scrollWidth);
        var X_hauteur = parseInt(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, urlContent, width, height, iframeName, idCalqueContainer){	

    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) ;
        }

        if(idCalqueContainer == 'calqueVideoPopup'){ //Utiliser pour afficher les video dans une popup
            var calqueContainerObj = getElement(idCalqueContainer, true, "") ;
            if(calqueContainerObj){
                calqueContainerObj.style.display = "block" ;
                
                //on va afficher le titre de la video
                var titreVideoObj = getElement("titreVideo", true, "") ;
                var videoObjId = urlContent ; //urlContent est dans ce cas le titre de la video
                var videoObj = mapVideo.get(videoObjId) ; //Map declarer dans l'HTML et contenant toutes les videos
                
                if(videoObj && titreVideoObj){
                    titreVideoObj.innerHTML = videoObj.titre ;
                }
                
                if(videoObj){ //on va charger la video
                    var urlPlayer = videoObj.urlPlayer ;
                    var urlVideo = videoObj.urlVideo ;
                    
                    var soPlayer = new SWFObject(urlPlayer,'flashswf', playerWidth,playerHeight,'8','');
                    
                    soPlayer.addParam("quality","high");
                    soPlayer.addParam("wmode","transparent");
                                
                    soPlayer.addVariable("flv",urlVideo);
                    soPlayer.write('playervideo');
                }
                
                X_block.style.display = "block" ;
                
            }
        }
        else if(iframeName && iframeName != ''){
            var calqueContainerObj = getElement(idCalqueContainer, true, "") ;
            if(calqueContainerObj){
                if(iframeName=='map-decathlon'){
                    calqueContainerObj.innerHTML = '<div id="bloc_fermer"><a href="javascript:hidePopup()" ><img src="../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="'+urlContent+'" width="'+width+'" height="'+height+'"></iframe>' ;
                }
                else if(iframeName == 'iframehd'){
                    if(imageBottom){
                        displayBloc(imageBottom) ;
                    }          
                    calqueContainerObj.innerHTML ='<iframe id="'+iframeName+'" scrolling="no" frameborder="0" marginheight="0" marginwidth="0" src="'+urlContent+'" width="'+(width-2)+'" height="'+(height-30)+'"></iframe>' ;
                }
                else if(iframeName == 'iframenews'){
                    calqueContainerObj.innerHTML ='<iframe id="'+iframeName+'" scrolling="no" frameborder="0" marginheight="0" marginwidth="0" src="'+urlContent+'" width="'+(width-2)+'" height="'+(height-100)+'"></iframe>' ;
                }                
                else if(iframeName != 'iframeOxyServices'){
                    calqueContainerObj.innerHTML ='<iframe id="'+iframeName+'" scrolling="no" frameborder="0" marginheight="0" marginwidth="0" src="'+urlContent+'" width="'+width+'" height="'+height+'">' ;
                }
                X_block.style.display = "block" ;
            }
        }
        else{
            var calqueContainerObj = getElement(idCalqueContainer, true, "") ;
            if(calqueContainerObj){
                loadContentPage(urlContent, calqueContainerObj) ;
            }
        }
    } 
    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';       
    } 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');                          	
        	}       
}

/*############################################################################################## */
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() ;
}


/* ############################################################################################ */
function hidePopupNews(){    
    var calque = getElement("calque", true, "") ;
    if(!calque){
        calque = parent.parent.document.getElementById("calque") ;
    }
    if(!calque){
        calque = parent.document.getElementById("calque") ;
    }
    hide_all(calque.id) ;
}

/* ############################################################################################ */
/* ############################################################################################ */

function affichePopupOxylaneAvis(bloc){    
    var tag="";
    var tagCountry = "/"+_language+"/" ;
    if(bloc){
        tag=tagCountry+tagLink+"lire_avis";
    }else{
        tag=tagCountry+tagLink+"onglet_avis";
    }
    for(i=0;i<pageTracker.length;i++){
       doLinkTag(tag,i);
    }
    var calqueOxylane = document.getElementById("calqueOxylane");
    var calqueOxylaneAvis = document.getElementById("calqueOxyAvis");
    var calqueOxylanePlus = document.getElementById("calqueOxyPlus");
    var IframeOxylaneAvis = document.getElementById("oxyIframeAvis");    
    
    PositionPopup("calqueOxylane",'500','723');
       
    calqueOxylanePlus.style.display="none";        
    show_filter('filtreOxylane');
    calqueOxylane.style.display="block";
    calqueOxylaneAvis.style.display="block";
    
    if(IframeOxylaneAvis){
        IframeOxylaneAvis.style.display="block";
    }
}
        
        /* ############################################################################################ */
/* ############################################################################################ */

function affichePopupOxylanePlus(){    
    var calqueOxylane = document.getElementById("calqueOxylane");
    var calqueOxylanePlus = document.getElementById("calqueOxyPlus");
    var calqueOxylaneAvis = document.getElementById("calqueOxyAvis");
    var IframeOxylaneServices = document.getElementById("oxylaneServices");    
    
    PositionPopup("calqueOxylane",'500','723');
        
    calqueOxylaneAvis.style.display="none";
    show_filter('filtreOxylane');
    calqueOxylane.style.display="block";
    calqueOxylanePlus.style.display="block";         
    if(IframeOxylaneServices){
        IframeOxylaneServices.style.display="block";
    }
}

/* ############################################################################################ */
/* ############################################################################################ */

function ouvrirMenuDeroulant(idBlocAAfficher){
        var blocAAfficher =document.getElementById(idBlocAAfficher);        
        if(blocAAfficher){
            blocAAfficher.style.display="block";
        }
}

/* ############################################################################################ */
/* ############################################################################################ */

function fermerMenuDeroulant(idBlocACacher){
        var blocACacher =document.getElementById(idBlocACacher);
        if(blocACacher){
            blocACacher.style.display="none";
        }
}

/* ############################################################################################ */
/* ############################################################################################ */
function afficherConseilsEntretien(ongletSelectionne, blocAAfficher) {
    var blocAAfficher = document.getElementById(blocAAfficher);
    var blocVetement = document.getElementById('vetements');
    var blocChaussure = document.getElementById('chaussures');
    var blocGant = document.getElementById('gants');    

    var ongletVetement = document.getElementById('onglet-vetements');
    var ongletChaussure = document.getElementById('onglet-chaussures');
    var ongletGant = document.getElementById('onglet-gants');    
    
    //Ici nous gerons les bloc avec le texte
    
    if(blocAAfficher && blocAAfficher !=''){
        if(blocVetement && blocVetement!=null && blocVetement !=blocAAfficher ){
            blocVetement.className='close';
        }
        if(blocChaussure && blocChaussure!=null && blocChaussure !=blocAAfficher ){
            blocChaussure.className='close';
        }    
        if(blocGant && blocGant!=null &&blocGant !=blocAAfficher ){
            blocGant.className='close';
        }
        if(blocAAfficher){
            blocAAfficher.className='open';
        }  
    }
    else{
        if(blocVetement && blocVetement!=null){
            blocVetement.className='open';
        }
        else if(blocChaussure && blocChaussure!=null){
           blocChaussure.className='open';
        }
        else if(blocGant && blocGant!=null){
           blocGant.className='open';
        }
    }
    
    if(ongletSelectionne && ongletSelectionne !=''){
        //Ici nous gerons les onglets
        if(ongletVetement && ongletVetement != ongletSelectionne){
            ongletVetement.className='non-selectionne';
        }    
        if(ongletChaussure && ongletChaussure != ongletSelectionne){
            ongletChaussure.className='non-selectionne';
        }    
        if(ongletGant && ongletGant != ongletSelectionne){
            ongletGant.className='non-selectionne';
        }    
        if(ongletSelectionne){
            ongletSelectionne.className='selectionne';
        }
    }
    else{
        if(ongletVetement){
            ongletVetement.className='selectionne';
            if(ongletChaussure){
                ongletChaussure.className='non-selectionne';
            }
            if(ongletGant){
                ongletGant.className='non-selectionne';
            }
        }
        else if (ongletChaussure){        
           ongletChaussure.className='selectionne';
           if(ongletGant){
               ongletGant.className='non-selectionne';
           }
        }
        else if (ongletGant) {
             ongletGant.className='selectionne';
        }
    }
}




   