/**********************************************************************************
*                                            Framework javascript
**********************************************************************************/
/** #########################################
* Permet de récupérer l'objet IFRAME
*/
function getIframeObjectMore(iframeName){                            
   if(document.frames){
   //IE 5
   IFrameObj = document.frames[iframeName];
   }
   else {
   //DOM IMPLEMENTED BROWSERS
   IFrameObj = document.getElementById(iframeName);
   }
   
   if(IFrameObj){
   if(IFrameObj.contentWindow){
   //IE 5.5 and more
   iframeObject = IFrameObj.contentWindow.document;        
   }
   else if(IFrameObj.contentDocument){
   //GECKO
   iframeObject = IFrameObj.contentDocument.document;        
   }
   else if(IFrameObj.document){
   //IE 5
   iframeObject = IFrameObj.document;
   }
   
   return iframeObject ;
   }
   return null ;
}

/** #########################################
* Permet de récupérer l'objet AJAX
*/
function getXhr(){
   if (window.ActiveXObject){
   try{
   xhr = new ActiveXObject("Msxml2.XMLHTTP");
   }
   catch (e){
   xhr = new ActiveXObject("Microsoft.XMLHTTP");
   }
   }
   else if(window.XMLHttpRequest)
   // Firefox et autres
   xhr = new XMLHttpRequest(); 
   else{
   // XMLHttpRequest not supported by browser
   alert("Your browser doesn't support XMLHTTPRequest objects..."); 
   xhr = false; 
   }                        
   return xhr ;
}

function setHtml(idObj, innerObj){
    var obj = document.getElementById(idObj) ;
    
    if(obj){
        if(innerObj != ""){
            obj.innerHTML = innerObj ;
        }
    }    
}

function setHref(idObj, href, target){
    var obj = document.getElementById(idObj) ;
    if(obj){
        if(href != ""){
            obj.href = href ;
        }
        if(target != ""){
            obj.target = target ;
        }
    }
}

function setImage(idObj, src, alt, title){
    var obj = document.getElementById(idObj) ;
    if(obj){
        if(src != ""){
            obj.src = src ;
        }
        if(alt != ""){
            obj.alt = alt ;
        }
        if(title != ""){
            obj.title = title ;
        }        
    }
}

function setImageObj(obj, src, alt, title){    
    if(obj){
        if(src != ""){
            obj.src = src ;
        }
        if(alt != ""){
            obj.alt = alt ;
        }
        if(title != ""){
            obj.title = title ;
        }        
    }
}

function getElement(idObj, fromDocument, objSrc){
    if(fromDocument){
        if(document.getElementById(idObj)){
            return document.getElementById(idObj) ;
        }
        else{
            return null ;
        }
    }
    else{
        if(objSrc && objSrc != ""){
            if(objSrc.document.getElementById(idObj)){
                return document.getElementById(idObj) ;
            }
            else{
                return null ;
            }
        }
        else{
            return null ;
        }
    }
}

function hideBloc(obj){
    if(obj){
        obj.style.display = "none" ;
    }
}

function displayBloc(obj){
    if(obj){
        obj.style.display = "block" ;
    }
}

/** #########################################
* Permet de récupérer les paramètres passés à l'url
*/
function getHtmlInnerNode(htmlDoc, splitTagArray, isAddedTags){    
    var result = "" ;
    if(splitTagArray && splitTagArray.length == 2){
        if(htmlDoc.split(splitTagArray[0])[1] && (htmlDoc.split(splitTagArray[0])[1]).split(splitTagArray[1])[0]){
            result = (htmlDoc.split(splitTagArray[0])[1]).split(splitTagArray[1])[0] ;
            if(isAddedTags){
                return splitTagArray[0]+result+splitTagArray[1] ;
            }
            else{
                return result ;
            }
        }
    }
    else{
        return result ;
    }
}

/** #########################################
* Permet de récupérer les paramètres passés à l'url
*/
function getParameters() {
    urlGet = document.location.search;
    params = urlGet.split("&");
    param = new Array();
    for(j=0;j<params.length; j++){
       param.push(params[j].split("=")) ;
    }
    return param;
}

/*########################################################
* Permet d'éviter d'ouvrir l'iframe seule
*/
function preventFrameIsolation(page) {
    if (parent.frames.length < 1 ) {
        document.location.replace(page);
    }
}

/** #########################################
* Permet de cacher ou de montrer la carte map decathlon dans la page "où acheter"
*/
function displayMap(){
    if(document.getElementById('map-decathlon').style.display == "none"){
        document.getElementById('map-decathlon').style.display="block" ;
    }
    else{
        document.getElementById('map-decathlon').style.display="none" ;                            
    }
}

/** #########################################
* Permet de charger vue3D
*/
function chargeVue3d(urlVue3d, nomVue3d){
    if(document.getElementById('iframe-vue3d')){
        document.getElementById('iframe-vue3d').src = urlVue3d ;
	document.getElementById('title-vue3d').innerHTML = nomVue3d ;
    }    
}

/** #########################################
* Permet de créer un cookie --> Fonction de création par défaut
*/
function setCookie(langue, name, value) {      
    var argv=setCookie.arguments;
    var argc=setCookie.arguments.length;
    var path="/"+langue+"/" ;
    var exp = (argc > 3) ? argv[3] : null;
    var domain=(argc > 4) ? argv[4] : null;
    var secure=(argc > 5) ? argv[5] : false;    
    
    document.cookie=name+"="+escape(value)+
        ((exp==null) ? "" : ("; expires="+exp))+
        ((path==null) ? "" : ("; path="+path))+
        ((domain==null) ? "" : ("; domain="+domain))+
        ((secure==true) ? "; secure" : "");
}
/** #########################################
* Permet de récupérer les informations d'un cookie
*/
function getCookieVal(offset)
{
   var endstr=document.cookie.indexOf (";", offset);
   if (endstr==-1) endstr=document.cookie.length;
   return unescape(document.cookie.substring(offset, endstr));
}

function getCookie (name) {
    var arg=name+"=";
    var alen=arg.length;
    var clen=document.cookie.length;
    var i=0;
    while (i<clen) {
        var j=i+alen;
        if (document.cookie.substring(i, j)==arg)
            return getCookieVal (j);
        i=document.cookie.indexOf(" ",i)+1;
        if (i==0) 
            break;
    }
    return null;
}

/** #########################################
* Permet de supprimer un cookie
*/
function deleteCookie(langue, name) {
    var exp=new Date();
    exp.setTime (exp.getTime() - 100000);
    var cval=getCookie(name);
    setCookie(langue, 'panier', cval, exp.toGMTString());

    window.location.reload() ;
}

/** #########################################
* Permet d'afficher la popup de sondage
*/
function afficheSondage(nom, url){
    //A la 4ème page, on affiche la popup
    nbPageDefault = 4 ;
    nbPageLu = getCookie(nom);
    // Le cookie n'existe pas
    if (nbPageLu == null ){
        nbPageLu = 1 ;
        setCookieDef(nom, nbClic, "");
    }
    //sinon, il existe et on va incrémenter la valeur du nombre de clic dans ce cookie
    else{
        nbPageLu++ ;
        setCookieDef(nom, nbClic, "");
    }
   
    if(nbPageLu == nbPageDefault){
        var win2 = window.open(url, 'sondage','width=550, height=450, scrollbars=yes, resizable =yes,alwaysLowered=yes');	
    }
}

/** #########################################
* Permet de cacher ou afficher une div
*/
function displaySection(sectionDest, sectionId){
    if(document.getElementById(sectionId)){
        var srcInnerrHtml = document.getElementById(sectionId).innerHTML ;
        if(document.getElementById(sectionDest)){
            document.getElementById(sectionDest).innerHTML = srcInnerrHtml ;
            document.getElementById(sectionDest).style.display = "block";
        }
    }
}

/** #########################################
* Permet d'augmenter une zone de texte
*/
function increaseFontSize(idZone){
    var node = document.getElementById(idZone);
    var nextBrother = getNextBrotherNode(node) ;
    while(nextBrother){        
        nextBrother = getNextBrotherNode(nextBrother) ;
        if(nextBrother){
            for(var i=0 ; i<nextBrother.childNodes.length ; i++){
                 var childNode = nextBrother.childNodes[i] ;
                 if(childNode.style){
                     if(childNode.style.fontSize == "0.9em"){
                        childNode.style.fontSize = "1em" ;
                    }         
                    else if(childNode.style.fontSize == "" || childNode.style.fontSize == "1em"){
                        childNode.style.fontSize = "1.5em" ;
                    }
                }
            }            
        }
    }
}

/** #########################################
* Permet de réduire une zone de texte
*/
function reduceFontSize(idZone){
    var node = document.getElementById(idZone);
    var nextBrother = getNextBrotherNode(node) ;
    while(nextBrother){        
        nextBrother = getNextBrotherNode(nextBrother) ;
        if(nextBrother){
            for(var i=0 ; i<nextBrother.childNodes.length ; i++){
                 var childNode = nextBrother.childNodes[i] ;
                 if(childNode.style){
                     if(childNode.style.fontSize == "" || childNode.style.fontSize == "1em" ){
                        childNode.style.fontSize = "0.9em" ;
                    }
                    else if(childNode.style.fontSize == "1.5em"){
                        childNode.style.fontSize = "1em" ;
                    }
                }
            }            
        }
    }    
}


/** #########################################
* Permet de récupérer le frère d'un noeud
*/
function getNextBrotherNode(node){
    return node.nextSibling ;
}


/** #########################################
* Permet de récupérer le contenu d'un noeud
*/
function getContentNode(node){
    return node.innerHTML ;
}

/** #########################################
* Permet de sélectionner le pays dans le footer
*/
function selectPays(){
    var url = document.location.href ;
    var tabUrl = url.split('/') ;
    var pays = "" ;
    if(tabUrl.length > 0){
        pays = tabUrl[3] ;
        if(document.getElementById("site-"+pays+"-selected")){
            document.getElementById("site-"+pays+"-selected").style.display = "block" ;
            if(document.getElementById("footer-site")){
                document.getElementById("footer-site").style.display = "block" ;
            }
            if(document.getElementById("langue-"+pays)){
                document.getElementById("langue-"+pays).style.display = "none" ;
            }
        }
    }
}

/* #######################
* Permet de remplacer une chaine de caractère d'un string
*/
function replaceAll( str, replacements ) {
    var idx = str.indexOf( replacements[0] );

    while ( idx > -1 ) {
        str = str.replace( replacements[0], replacements[1] ); 
        idx = str.indexOf( replacements[0] );
    }
    return str;
}

/** #########################################
* Permet d'ouvrir une popup
*/
function openWindow(url, largeur, hauteur, scrolls, location, under){
    var timestamp = Math.floor((new Date()).getTime() / 1000) ;
    window.open(url, 'nw'+timestamp, 'top=screen.height,left=0,width='+largeur+',height='+hauteur+',menubar=yes,toolbar=yes,scrollbars='+scrolls+',resizable=yes,location='+location+','+under) ;
}

/** #########################################
* Permet d'ouvrir une popup de zoom pour la photo produit
*/
function ouvrirZoom(imageName){
        var blocIframe = "calquecontainer" ;
     
        if(blocIframe != ""){        
            var calqueconteneur = document.getElementById(blocIframe) ;   
            if(calqueconteneur){
               var zonefermer= document.getElementById('bloc_fermer-zoom');
               zonefermer.style.display = 'block';
               calqueconteneur.style.display = 'block';
            } 
            calqueconteneur.style.width='420px';
            calqueconteneur.style.height='430px';
            displayPopupFilter('filtre', 'calquecontainer', imageName, '420', '430', blocIframe);                        
       }
       else{
            window.open(imageName , "", "top=screen.height,left=0,width=420, height=430, location=0, titlebar=0, status=0,menubar=0" );
       }
}

/*########################################################
* Permet de faire le liage entre la fiche marque et la fiche enseigne
*/
function goToProduct(rootPath, urlLiage, urlEnseigne){
    var xhr = getXhr();
    
    xhr.onreadystatechange = function(){
        if(xhr.readyState == 4 && xhr.status == 200){
            responseAjax = xhr.responseXML ;
            if(responseAjax.getElementsByTagName("product")[0]){
                var productTag = responseAjax.getElementsByTagName("product")[0] ;
                var urlProductEnseigne = "" ;
                
                for (i=0; i<productTag.childNodes.length; i++){
                    if (productTag.childNodes[i].nodeName=="url"){
                        if(productTag.childNodes[i].firstChild.nodeValue){
                            urlProductEnseigne = rootPath+"/"+productTag.childNodes[i].firstChild.nodeValue ;
                        }
                    }
                }  	
                window.open(urlEnseigne+urlProductEnseigne, "", "width=800,height=600,resizable=yes,location=yes,scrollbars=yes,toolbar=yes") ;
            }
            else{
                window.open(urlEnseigne, "", "width=800,height=600,resizable=yes,location=yes,scrollbars=yes,toolbar=yes") ;
            }
        }
    }
    xhr.open("GET", urlLiage, true);
    xhr.setRequestHeader('Content-Type','text/xml');
    xhr.send(null);
}

/*
########################################################################################################################
##############################################          OBJET         ##################################################
########################################################################################################################
*/

/* ############################################################# */
/* #####################   Hashmap   ########################### */
/* ############################################################# */
function KeyValue( key, value ){
    this.key = key;
    this.value = value;
}


/* ############################################################
* Constructeur
*/
function Map(){
    this.array = new Array();
}

/* ############################################################
* Méthode put
* param :
*     key : clé
*     value : valeur
*/
Map.prototype.put = function( key, value ){
    if( ( typeof key != "undefined" ) && ( typeof value != "undefined" ) )
    {
        this.array[this.array.length] = new KeyValue( key, value );
    }
}

/* ############################################################
* Méthode get
* param :
*     key : clé
* return :
*     String	    
*/
Map.prototype.get = function( key ){
    for( var k = 0 ; k < this.array.length ; k++ )
    {
        if( this.array[k].key == key ) {
            return this.array[k].value;
        }
    }
    return "";
}

/* ############################################################
* Méthode remove
* param :
*     key : clé
* return :
*     String	    
*/
Map.prototype.remove = function( key ){
    for( var k = 0 ; k < this.array.length ; k++ )
    {
        if( this.array[k].key == key ) {
            this.array[k] = "" ;
            return k ;
        }
    }
    return -1 ;
}


/* ############################################################
* Méthode length
* return :
*     String	    
*/
Map.prototype.length = function(){
    return this.array.length;
}



/* ############################################################## */
/* #####################   ArrayList  ########################### */
/* ############################################################## */
function ArrayList(){
    this.arraylist = new Array();
}

/* ############################################################
* Méthode add
* param :
*     value : valeur à ajouter
*/
ArrayList.prototype.add = function(value){
    if( typeof value != "undefined" )
    {
        this.arraylist[this.arraylist.length] = value ;
    }
}

/* ############################################################
* Méthode get
* param :
*     index : index de la valeur à retourner
* return :
*     String	    
*/
ArrayList.prototype.get = function(index){
    if(this.arraylist[index]){
        return this.arraylist[index] ;    
    }
    else{
        return "" ;
    }
}

/* ############################################################
* Methode length
* return :
*     String	    
*/
ArrayList.prototype.remove = function(index){
    if(this.arraylist[index]){
        if(index != this.arraylist.length - 1){
            for(var i=index ; i< this.arraylist.length ; i++){
                if(this.arraylist[i+1]){
                    arraylist[i] = this.arraylist[i+1] ; 
                }
            }
        }
        this.arraylist[this.arraylist.length] == null ;
    }
    else{
        return "" ;
    }
}

/* ############################################################
* Methode length
* return :
*     String	    
*/
ArrayList.prototype.length = function(){
    return this.arraylist.length;
}

/* ############################################################
* Méthode contains
* param :
*     value : valeur à rechercher
* return :
*     boolean	    
*/
ArrayList.prototype.contains = function(value)
{
    for( var k = 0 ; k < this.arraylist.length ; k++ )
    {
        if( this.arraylist[k] == value ) {
            return k ;
        }
    }
    return -1 ;
}

/* ############################################################
* Méthode delete
* return :
*     boolean
*/
ArrayList.prototype.remove = function(index){
    if(this.arraylist[index]){
        if(index != this.arraylist.length - 1){
            for(var i=index ; i< this.arraylist.length ; i++){
                if(this.arraylist[i+1]){
                    this.arraylist[i] = this.arraylist[i+1] ; 
                }
            }
        }
        this.arraylist[this.arraylist.length-1] = null ;
        this.arraylist.length = this.arraylist.length-1 ;
        return true ;
    }
    else{
        return false ;
    }
}
/** #########################################
* Permet d'ouvrir une popup filter
*/
function displayPopupFilter(idObj, idObjContainer, urlContent, width, height, iframeName, dofilter){
    var largeurmonfiltre=document.documentElement.scrollWidth;
    var hauteurmonfiltre=document.documentElement.scrollHeight;
    
    // Si dans itool pour le lien interne aucune hauteur et ou largeur n est saisi, alors on fixe une valeur par default pour que ca fenetre souvre qd meme en popup
    if(width==''){     width='800'; }
    if(height==''){    height='600'; }
    
     if(dofilter == null || dofilter){
            show_filter(idObj);
     }

    if(idObjContainer == "calquecontainer"){
        var bloccalquecontainer = "calquecontainer" ;
        var blocIframe = "iframenews" ;
        var blocmonfiltre = "filtre" ;
        
        if(blocmonfiltre != ""){    //ce bloc de code sert a adapter le filtre a la totalite de la page 
                monfiltre = document.getElementById(blocmonfiltre) ;
                if(monfiltre){
                    monfiltre.style.width = document.documentElement.scrollWidth +'px' ;
                    monfiltre.style.height = document.documentElement.scrollHeight + 'px';
                }
            }   // fin

       // on va desactiver toutes les videos car sinon elle passe au dessus des calque+filtre
       var blocVideo = document.getElementById("player") ;
       if(blocVideo){              
           blocVideo.style.display="none";    
       }
                 
        if(blocIframe != ""){
            var calquecontainerNewsPopup = parent.parent.document.getElementById(bloccalquecontainer ) ;
            var iframeNewsPopup = parent.parent.document.getElementById(blocIframe) ;
            if(!iframeNewsPopup){
                iframeNewsPopup = parent.document.getElementById(blocIframe) ;
            }
             if(!iframeNewsPopup){
                iframeNewsPopup = document.getElementById(blocIframe) ;
            }
            
            if(!iframeNewsPopup){
                iframeNewsPopup = getElement(blocIframe, true, "") ;
            }
            
            if(iframeNewsPopup){
                iframeNewsPopup.src = urlContent ;
                iframeNewsPopup.style.display = 'block';
                iframeNewsPopup.style.visibility = 'visible';
                iframeNewsPopup.style.width = width +'px' ;
                iframeNewsPopup.style.height = height + 'px';
            }
  
            if(!calquecontainerNewsPopup){
                calquecontainerNewsPopup = parent.document.getElementById(bloccalquecontainer) ;
            }
             if(!calquecontainerNewsPopup){
                calquecontainerNewsPopup = document.getElementById(bloccalquecontainer) ;
            }            
            if(!calquecontainerNewsPopup){
                calquecontainerNewsPopup = getElement(bloccalquecontainer, true, "") ;
            }
            if(calquecontainerNewsPopup){
                 calquecontainerNewsPopup.style.width = width +'px' ;
                 calquecontainerNewsPopup.style.height = height + 'px';                 
            }
            
            // On masque le flash recrutement
            var flashtRecrutement = document.getElementById('flash-hp-recrObj');				
                            if(flashtRecrutement){
                                flashtRecrutement.style.display='none';
             }
             
            show_popup(idObjContainer, urlContent, width, height);
            
            //on va modifier le style du bloc fermer
            var blocFermer = document.getElementById("bloc_fermer-zoom") ;
            if(blocFermer){
                blocFermer.style.marginLeft = (width-120)+"px" ;
                var anchorFermer = blocFermer.getElementsByTagName("A") ;
                for(var k=0 ; k<anchorFermer.length ; k++){
                    //anchorFermer[k].style.color = "#ffcc33" ;
                    anchorFermer[k].className='bloc_fermer-zoom ';
                }
            }                    
                 
        }
    }
}


/*########################################################
* Permet de faire cacher les blocs div d'un bloc blocpage
*/
function hideAllautre(blocpage, idPageACacher){
    var pagesDIV = document.getElementById(blocpage);
    if(pagesDIV){
        var page = pagesDIV.getElementsByTagName('div');
        for(var i=0;i  < page.length; i++){
            if(idPageACacher && idPageACacher != ""){
                if(page[i].id && page[i].id != "" && page[i].id.indexOf(idPageACacher) > -1){
                    page[i].style.display = 'none';
                }
            }
            else{
                 page[i].style.display = 'none';
            }
         }
     }
}


/*########################################################
* Permet de faire cacher les blocs div d'un bloc blocpage
*/
function resetClass(blocPage, oldClass, blocType){
    var blocsDIV = document.getElementById(blocPage) ;
    if(blocsDIV){
        var blocs = blocsDIV.getElementsByTagName(blocType);
        for(var j=0; j < blocs.length; j++){
            blocs[j].className = oldClass ;
         }
     }
}

