//Contenu milieu de la page
var contentMiddle = document.getElementById("content-middle") ;

/**********************************************************************************
*                                            Framework javascript
**********************************************************************************/
/** #########################################
* Permet de recuperer 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 recuperer 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 getElement(idObj, fromDocument, objSrc){
    if(fromDocument){
        var obj = document.getElementById(idObj) ;       
        return obj ;
    }
    else{
        var obj = document.getElementById(idObj) ;        
        if(!obj){
            obj = parent.document.getElementById(idObj);
        }
        return obj ;
    }
}


function setHtml(idObj, innerObj){
    var obj = getElement(idObj) ;
    
    if(obj){
        if(innerObj != ""){
            obj.innerHTML = innerObj ;
        }
    }    
}

function setIframeSrc(idObj, src){
    var obj = getElement(idObj) ;
    if(obj){
        if(src != ""){
            obj.src = src ;
        }
    }
}

function setHref(idObj, href, target){
    var obj = getElement(idObj) ;
    if(obj){
        if(href != ""){
            obj.href = href ;
        }
        if(target != ""){
            obj.target = target ;
        }
    }
}

function setImage(idObj, src, alt, title){
    var obj = getElement(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 setBackgroundImageElt(idObj, src){
    var obj = getElement(idObj) ;
    if(obj){
        obj.style.backgroundImage = "url(" + src + ")" ;
    }
}

function hideBloc(obj){
    if(obj){
        obj.style.display = "none" ;
    }
}

function displayBloc(obj){
    if(obj){
        obj.style.display = "block" ;
    }
}

function hideBlocId(objId){
    var obj = getElement(objId) ;
    hideBloc(obj) ;
}

function displayBlocId(objId){
    var obj = getElement(objId) ;
    displayBloc(obj) ;
}

function setVisibility(_objId){
    var obj = getElement(_objId) ;
    if(obj){
        if(obj.style.visibility == "hidden"){
            obj.style.visibility = "visible" ;
        }
        else{
            obj.style.visibility = "hidden" ;
        }
    }
}
function hiddenBlocId(objId){
    var obj = getElement(objId) ;
    obj.style.visibility = "hidden" ;
}

function visibleBlocId(objId){
    var obj = getElement(objId) ;
    obj.style.visibility = "visible" ;
}
/** #########################################
* Permet de recuperer les parametres passes a 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 de cacher ou de montrer la carte map decathlon dans la page "ou 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 recuperer la date d'expiration du cookie
*/
function getExpirationDateCookie(nbSemaines){
    var expdate = new Date ();
    var aujourdhui = new Date(0);
    var aujourdhuidate = aujourdhui.getTime();

   if(typeof nbSemaines == "undefined"){
        nbSemaines = 12;
    }
    if (aujourdhuidate > 0){
        expdate.setTime (expdate.getTime() - aujourdhuidate);
    }
    expdate.setTime (expdate.getTime() + (24 * 60 * 60 * 1000 * 7 * nbSemaines));
    var expDateToGMT = expdate.toGMTString() ;

    return expDateToGMT ;
}

/** #########################################
* Permet de creer le cookie
*/
function setCookie(langue, name, value) {      
    var argv=setCookie.arguments;
    var argc=setCookie.arguments.length;
    var path = langue != "" ? "/"+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 recuperer 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);
    if(cval){
        setCookie(langue, name, cval, exp.toGMTString());
    }
}

/** #########################################
* Permet d'afficher la popup de sondage
*/
function afficheSondage(language, nom, url, width, height, type, scroll) {
    //A la 1ere page, on affiche la popup
    nbPageDefault = 1 ;
    nbPageLu = getCookie(nom);
    // Le cookie n'existe pas
    if (nbPageLu == null ){
        nbPageLu = 1 ;
        setCookie(language, nom, nbPageLu, getExpirationDateCookie(1));
    }
    //sinon, il existe et on va incrementer la valeur du nombre de clic dans ce cookie
    else{
        nbPageLu++ ;
        setCookie(language, nom, nbPageLu, getExpirationDateCookie(1));
    }

    if(nbPageLu == nbPageDefault){

        var theWidth = "774" ;
        if(width != ''){
            theWidth = width ;
        }
        var theHeight = "437" ;
        if(height != ''){
            theHeight = height ;
        }

        displayPopupFilter('filtre', 'calquecontainer', url, theWidth, theHeight, 'iframe-sondage', true);
        if (typeof type != "undefined")
        {
            document.getElementById("calque").className = type;
        }
        else {
            document.getElementById("calque").className = 'sondage';
        }
    }
}

/** #########################################
* Permet de cacher ou afficher une div
*/
function hideSectionAdvice(obj){
    var parentSection = obj.parentNode ;
    if(parentSection){
        var section = parentSection.getElementsByTagName('div');
        for(i=0;i  < section.length; i++){
             section[i].className = 'rubConseil';
         }
    }
}

/** #########################################
* Permet d'afficher les fiches conseil par onglet
*/
function displaySection(obj, sectionDest, sectionId){    
    var sectionToDisplay = sectionId ;
    if(!obj || !document.getElementById(sectionId)){
        sectionToDisplay = "advice-links1" ;
        obj = document.getElementById("rubConseil1") ;
    }
    
    if(document.getElementById(sectionToDisplay)){
        var srcInnerrHtml = document.getElementById(sectionToDisplay).innerHTML ;
        if(document.getElementById(sectionDest)){
            document.getElementById(sectionDest).innerHTML = srcInnerrHtml ;
            document.getElementById(sectionDest).style.display = "block";
            
            if(obj){
                hideSectionAdvice(obj) ;
                obj.className = "rubConseilSelected" ;
                rubDefaut = obj.id ;
                advicesDefaut = sectionToDisplay ;
            }
        }
    }
}

/** #########################################
* Permet d'augmenter une zone de texte
*/
function increaseFontSize(idZones){
    var idZonesArr = idZones.split(';') ;
    for(var i=0 ; i<idZonesArr.length ; i++){
        var content = idZonesArr[i] ;
        increaseElement(content, "DIV") ;
        increaseElement(content, "A") ;
    }    
}


/** #########################################
* Permet de reduire une zone de texte
*/
function reduceFontSize(idZones){
    var idZonesArr = idZones.split(';') ;    
    for(var i=0 ; i<idZonesArr.length ; i++){
        var content = idZonesArr[i] ;
        reduceElement(content, "DIV") ; 
        reduceElement(content, "A") ;        
    }        
}


/** #########################################
* Permet de reduire les texte d'un bloc
*/
function reduceElement(content, elementType){    
    if(contentMiddle){
        var childNode = contentMiddle.getElementsByTagName(elementType);
        for(i=0;i  < childNode.length; i++){
            var childrenNode = childNode[i] ;
            if(childrenNode.id == content){
                if(childrenNode.style){
                    if(childrenNode.style.fontSize == "1.5em"){
                        childrenNode.style.fontSize ="1em" ;
                    }         
                    else if(childrenNode.style.fontSize == "" || childrenNode.style.fontSize == "1em"){
                        childrenNode.style.fontSize = "0.9em" ;
                    }
                }
            }
            if(childrenNode.className == content){
                childrenNode.style.height = "22em" ;
            }
        }
    }
}


/** #########################################
* Permet d'augmenter les textes d'un bloc
*/
function increaseElement(content, elementType){    
    if(contentMiddle){
        var childNode = contentMiddle.getElementsByTagName(elementType);
        for(i=0;i  < childNode.length; i++){
            var childrenNode = childNode[i] ;
            if(childrenNode.id == content){
                if(childrenNode.style){
                    if(childrenNode.style.fontSize == "0.9em"){
                        childrenNode.style.fontSize = "1em" ;
                    }         
                    else if(childrenNode.style.fontSize == "" || childrenNode.style.fontSize == "1em"){
                        childrenNode.style.fontSize = "1.5em" ;
                    }
                }            
            }
            if(childrenNode.className == content){
                childrenNode.style.height = "25em" ;
            }
        }       
    }
}


/** #########################################
* Permet de selectionner 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 caractere 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 nouvelle fenetre
*/
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 de remplacer une chaine de caractere d'un string
*/
function changeStyle(objId, newStyle) {
    var obj = document.getElementById(objId) ;
    if(obj){
        obj.className = newStyle ;
    }
}

/* #######################
* Permet de recuperer le server URL
*/
function getServerUrl(){
    var urlToReturn = "" ;
    var url = document.location.href ;
    if(url){
        var tabUrl = url.split("/") ;
        if(tabUrl && tabUrl.length > 3){
            for(var k=0 ; k<3 ; k++){                
                urlToReturn = urlToReturn + tabUrl[k] ;
                if(k != 2){
                    urlToReturn = urlToReturn + "/" ;
                }
            }
        }
    }
    return urlToReturn ;
}

/*########################################################
* 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 (var 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);
}

/*########################################################
* Permet de faire bouger une div vers le haut
*/
function moveUp(divId1, divId2){
    var divObj1 = getElement(divId1, true, "") ;
    var divObj2 = getElement(divId2, true, "") ;
    if(divObj1 != null){
        if(navigator.appName != 'Microsoft Internet Explorer' || (navigator.appName == 'Microsoft Internet Explorer' && navigator.appVersion.indexOf("MSIE 6.0") == -1)) {
            divObj1.style.marginTop = "-5px" ;
        }
    }
    if(divObj2 != null){
        if(navigator.appName != 'Microsoft Internet Explorer' || (navigator.appName == 'Microsoft Internet Explorer' && navigator.appVersion.indexOf("MSIE 6.0") == -1)) {
            divObj2.style.marginTop = "5px" ;
        }
    }
}

/*########################################################
* Permet de faire bouger une div vers le bas
*/
function moveDown(divId1, divId2){
    var divObj1 = getElement(divId1, true, "") ;
    var divObj2 = getElement(divId2, true, "") ;
    if(divObj1 != null){
        divObj1.style.marginTop = "0px" ;
    }
    if(divObj2 != null){
        divObj2.style.marginTop = "0px" ;    
    }
}

function hideWaitingMessage(){
    if(getElement("waitingMessage", true, "")){
        hideBloc(getElement("waitingMessage", true, "")) ;
        if(getElement("produits", true, "")){
            displayBloc(getElement("produits", true, "")) ;
        }
    }
}

function displayWaitingMessage(){
    if(getElement("waitingMessage", true, "")){
        if(getElement("produits", true, "")){
            hideBloc(getElement("produits", true, "")) ;
        }    
        displayBloc(getElement("waitingMessage", true, "")) ;
    }
}

function preventFrameIsolation(toRedirect) {
    if (parent.frames.length < 1 ) { 
        document.location.replace(toRedirect);      
    }
}

/*########################################################
* Permet de recuperer l'ambiance du site
*/
function getAmbiance() {
    var cookieAmb = getCookie("ambiance") ;

    if(cookieAmb != null){
        if(mapSiteAmbiance){ //declarer dans la page html
            var siteAmbianceObj = mapSiteAmbiance.get(cookieAmb) ;

            if(siteAmbianceObj){
                _bgimage = siteAmbianceObj.getBgImage() ;
                _mdrimage = siteAmbianceObj.getSearchConfirmButton() ;
                _mdrbgcolor = siteAmbianceObj.getSearchSelectBgImage() ;
                _menuhautbgcolor = siteAmbianceObj.getTopMenuBgColor() ;
                _mainbgcolor = siteAmbianceObj.getMainBgColor() ;
                _logoAmbiance = siteAmbianceObj.getLogoAmbiance() ;
                
                setAmbiance(cookieAmb, _bgimage, _mdrimage, _mdrbgcolor, _menuhautbgcolor, _mainbgcolor, _logoAmbiance) ;
            }
        }
    }
}

/*########################################################
* Permet de charger l'ambiance du site
*/
function setAmbiance(_newAmbiance, _bgimage, _mdrimage, _mdrbgcolor, _menuhautbgcolor, _mainbgcolor, _logoAmbiance){
    //Mise a jour du flash
    if(typeof urlFlash != "undefined"){
        var flashUrl = urlFlash ; //urlFlash declare dans l'html
        
        var newflashUrl = urlFlash.split("&ambiance=")[0] ;
        if(newflashUrl){
            newflashUrl = newflashUrl + "&ambiance=" + _newAmbiance ;  
        }
            
        if(typeFlash == -1){
            if(document.getElementById("banner-flash").movie){
                document.getElementById("banner-flash").movie = newflashUrl ;
            }
        }
        else if(typeFlash == 1){                    
            insert_flash(newflashUrl, '#FFFFFF',  widthFlash, heightFlash, 'banner-flash');
        }
        else if(typeFlash == 2){
            insert_flash2(newflashUrl, '#FFFFFF', widthFlash, heightFlash, 'banner-flash', idContainerFlash); //widthFlash, heightFlash et idContainerFlash declare dans l'html
        }
    }
    
    //fond d'ecran et couleur de fond
    document.body.style.backgroundImage = "url("+_bgimage+")" ;
    document.body.style.backgroundColor = _mainbgcolor ;
    
    //logo kalenji
    setImage("picto-logo", _logoAmbiance, "", "") ;
    
    //bouton OK du mdr
    if(document.getElementById("mdr-button")){
        document.getElementById("mdr-button").style.backgroundImage = "url("+_mdrimage+")" ;
    }
    
    //liste de selection du mdr
    if(document.getElementById("mdr-select")){
        document.getElementById("mdr-select").style.backgroundColor =_mdrbgcolor ;
    }
    
    //menu haut
    if(document.getElementById("content-bottom")){
        document.getElementById("content-bottom").style.backgroundColor =_menuhautbgcolor ;
     }
     
    //zone comment choisir page famille
    if(document.getElementById("content-choose")){
        document.getElementById("content-choose").style.backgroundColor =_menuhautbgcolor ;
     }
     
    //Zone titre de toutes les pages
    if(document.getElementById("content-title")){
        document.getElementById("content-title").style.backgroundColor =_menuhautbgcolor ;
     }
     
    //modification des styles de l'arbo rayon dans page famille
    var arboRayon = document.getElementById("menu-arbo") ;
    if(arboRayon){
        var sousRayons = arboRayon.getElementsByTagName("li") ;
    
        for(var i=0 ; i<sousRayons.length ; i++){
            if(sousRayons[i] && sousRayons[i].id == ''){
                sousRayons[i].style.backgroundColor =_menuhautbgcolor ;
            }
        }
    }
    
    //modification des styles des sous rayon dans page rayon
    var listeSousRayon = document.getElementById("sousrayons") ;
    if(listeSousRayon){
        var famille = listeSousRayon.getElementsByTagName("li") ;
    
        for(var i=0 ; i<famille.length ; i++){
            if(famille[i] && famille[i].className == 'sousrayon'){
                famille[i].style.backgroundColor =_menuhautbgcolor ;
            }
        }
    }
    
    //modification des styles des onglets
    var listeOnglets = document.getElementById("subheadings") ;
    if(listeOnglets){
        var ongletsImg = listeOnglets.getElementsByTagName("img") ;
    
        for(var i=0 ; i<ongletsImg.length ; i++){
            if(ongletsImg[i]){
                ongletsImg[i].style.backgroundColor =_menuhautbgcolor ;
            }
        }
    } 
    setCookie(_language, "ambiance", _newAmbiance) ;
    setCookie(_language, 'langue', _language.toLowerCase());
}


/*
########################################################################################################################
##############################################          OBJET         ##################################################
########################################################################################################################
*/

/* ############################################################# */
/* #####################   Hashmap   ########################### */
/* ############################################################# */
function KeyValue( key, value ){
    this.key = key;
    this.value = value;
}


/* ############################################################
* Constructeur
*/
function Map(){
    this.array = new Array();
}

/* ############################################################
* Methode put
* param :
*     key : cle
*     value : valeur
*/
Map.prototype.put = function( key, value ){
    if( ( typeof key != "undefined" ) && ( typeof value != "undefined" ) )
    {
        this.array[this.array.length] = new KeyValue( key, value );
    }
}

/* ############################################################
* Methode putIn
* param :
*    index : index pour inserer l'objet 
*    key : cle
*     value : valeur
*/
Map.prototype.putIn = function( index, key, value ){
    if( ( typeof key != "undefined" ) && ( typeof value != "undefined" ) )
    {
        if(index < this.array.length){
            this.array[index] = new KeyValue( key, value );
        }
    }
}

/* ############################################################
* Methode get
* param :
*     key : cle
* 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 "";
}

/* ############################################################
* Methode remove
* param :
*     key : cle
* 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 ;
}

/* ############################################################
* Methode getKeys
* return :
*     ArrayList	    
*/
Map.prototype.getKeys = function(){
    var keyList = new ArrayList() ;
    for( var k = 0 ; k < this.array.length ; k++ ){
        keyList.add(this.array[k].key) ;
    }
    return keyList ;
}

/* ############################################################
* Methode length
* return :
*     String	    
*/
Map.prototype.length = function(){
    return this.array.length;
}



/* ############################################################## */
/* #####################   ArrayList  ########################### */
/* ############################################################## */
function ArrayList(){
    this.arraylist = new Array();
}

/* ############################################################
* Methode add
* param :
*     value : valeur a ajouter
*/
ArrayList.prototype.add = function(value){
    if( typeof value != "undefined" )
    {
        this.arraylist[this.arraylist.length] = value ;
    }
}

/* ############################################################
* Methode get
* param :
*     index : index de la valeur a retourner
* return :
*     String	    
*/
ArrayList.prototype.get = function(index){
    if(this.arraylist[index]){
        return this.arraylist[index] ;    
    }
    else{
        return "" ;
    }
}

/* ############################################################
* Methode length
* return :
*     String	    
*/
ArrayList.prototype.length = function(){
    return this.arraylist.length;
}

/* ############################################################
* Methode contains
* param :
*     value : valeur a 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 ;
}

/* ############################################################
* Methode sort : permet de trier la liste (uniquement pour les liste de nombre)
* param :
*     isDesc : tri decroissant ?? 
* return :
*     boolean	    
*/
ArrayList.prototype.sort = function(isDesc)
{
    var sortedList = new Array() ;
    
    var max = this.arraylist[0] ;
    
    sortedList[0] = max ;
    
    if(isDesc){
        for(var k = 1 ; k < this.length() ; k++){
            var value = this.get(k) ;
            
            var length = sortedList.length ;
            var isValueAdd = false ;
            
            for(var i=0 ; i<length ; i++){                
                if(value > sortedList[i]){
                    for(var j=length ; j>i ; j--){
                        sortedList[j] = sortedList[j-1] ;                        
                    }
                    sortedList[i] = value ;
                    isValueAdd = true ;
                    break ;
                }
            }
            
            if(!isValueAdd){
                sortedList[length] = value ;
            }
        }
    }
    else{
        for(var k = 1 ; k < this.length() ; k++){
            var value = this.get(k) ;
            
            var length = sortedList.length ;
            var isValueAdd = false ;
            
            for(var i=0 ; i<length ; i++){                
                if(value < sortedList[i]){
                    for(var j=length ; j>i ; j--){
                        sortedList[j] = sortedList[j-1] ;
                    }
                    sortedList[i] = value ;
                    isValueAdd = true ;
                    break ;
                }
            }
            
            if(!isValueAdd){
                sortedList[length] = value ;
            }
        }
    }
    
    this.arraylist = sortedList ;
}


/* ############################################################
* Methode sort : permet de trier la liste (uniquement pour les liste de nombre)
* param :
*     isDesc : tri decroissant ?? 
* return :
*     boolean	    
*/
ArrayList.prototype.sortAlpha = function()
{
    this.arraylist = this.arraylist.sort() ;
}


/** #########################################
* Code pour xiti
*/
function calculateXiti(Xt_param) {
       if (window.xtparam!=null){Xt_param+=xtparam;} 
        try {Xt_r = top.document.referrer;} 
        catch(e) {Xt_r = document.referrer;} 
        Xt_h = new Date();      
           var xtorL=recupxtor("xtor");
                if(xtorL){
                     if(xtorL.indexOf("#")>-1)xtorL=xtorL.substring(0,xtorL.indexOf("#"));
                     wcookie("xtor",xtorL,false,_language +"/");
                 }
                 if(Getxtorcookie("xtor"))Xt_param+="&xto=" + Getxtorcookie("xtor").toUpperCase();
        Xt_i = '<img width="1" height="1" alt="" src="http://logi151.xiti.com/hit.xiti?'+Xt_param; 
      
        Xt_i += '&hl='+Xt_h.getHours()+'x'+Xt_h.getMinutes()+'x'+Xt_h.getSeconds(); 
        
        if(parseFloat(navigator.appVersion)>=4) {
            Xt_s=screen;
            Xt_i+='&r='+Xt_s.width+'x'+Xt_s.height+'x'+Xt_s.pixelDepth+'x'+Xt_s.colorDepth;
        }            
        
        return (Xt_i+'&ref='+Xt_r.replace(/[<>\"]/g, '').replace(/&/g, '$')+'" >');
}


/** #########################################
* Fonction pour ecrire une balise IMG dans lapage HTML
* @params :
*    - src : L'url complete de l'image
*    - width : La taille en largeur de l'image
*    - height : La taille en hauteur de l'image
*    - alt : Le texte alternatif de l'image
*/
function writeImage(src, alt, width, height, align){
    var taillesImage = "" ;
    if(width != ""){
        taillesImage = " width="+width ;
    }
    if(height != ""){
        taillesImage = taillesImage + " height="+height ;
    }    
    document.write('<img src="'+src+'"'+taillesImage+' align="'+align+'" alt="'+alt+'" title="'+alt+'"/>') ;
}


/** #########################################
/*deplacement carrousel decouverte page famille / produit*/
function decouvrerPrecedant(current,max){
    var newDec=current-1;
    if(current<=1){
        newDec=max;
    }
    document.getElementById('bloc-decouvrer-'+current).style.display='none';
    var i=newDec;
    while(i!=current && !document.getElementById('bloc-decouvrer-'+i)){
        if(i>=1){
            i--;
        }else{
            i=max;
        }
    }
    document.getElementById('bloc-decouvrer-'+i).style.display='block';
}


/** #########################################
/*deplacement carrousel decouverte page famille / produit*/
function decouvrerSuivant(current,max){
    var newDec=current+1;
    if(current>=max){
        newDec=1;
    }
    document.getElementById('bloc-decouvrer-'+current).style.display='none';
    var i=newDec;
    while(i!=current && !document.getElementById('bloc-decouvrer-'+i)){
        if(i<=max){
            i++;
        }else{
            i=1;
        }
    }
    document.getElementById('bloc-decouvrer-'+i).style.display='block';    
}


/** #########################################
* Permet d'ouvrir une page html
*/
function redirectPage(url){
    document.location.href = url ;
}

/** #########################################
* Permet d'ouvrir une page html
*/
function focusLink(idLink, isHover){
    var linkObj = getElement(idLink, true, "") ;
    if(linkObj){
        if(isHover){
            linkObj.className = "active" ;
        }
        else{
            linkObj.className = "" ;
        }
    }
}

/** #########################################
* Permet de setter le drapeau du pays
*/
function setCountryFlag(_lang, _cookieName, _idImgFlag, _mapImageCountry){
    if(_mapImageCountry){
        //changement du drapeaux pays en fonction du pays choisi
        var valueCookieCountry = getCookie(_cookieName) ;
        
        if(valueCookieCountry == null){
            valueCookieCountry = _lang ;
        }
        var infoCurrentPays = _mapImageCountry.get(valueCookieCountry) ;
        if(infoCurrentPays){
            if(getElement(_idImgFlag, true, "")){
                setImage(_idImgFlag, infoCurrentPays, "", "") ;
            }
            //var url = "/"+_lang+"/" ;
            //setCookie("", "redirect", _lang+"_"+valueCookieCountry+"_"+url, getExpirationDateCookie()) ;
            //Modifie par KIG : Ceci evite d'avoir des pb au niveau du redirect dans des cas bien particulier
        }
    }
}


/** #########################################
* Permet de modifer le message du lien vers la fiche produit
*/
function oxyComment_MessageToDisplay(messageReturn,messageGoTo,messageProduct) {
    var messageToDisplay = '';
    var urlCouranteSplit = (document.location.href).split("/");
    var urlPrecedenteSplit = (document.referrer).split("/");
    if ( (urlCouranteSplit[2] == urlPrecedenteSplit[2]) && (urlCouranteSplit[3] != 'nettools') ) {
        messageToDisplay = messageReturn;
    }
    else {
        messageToDisplay = messageGoTo;
    }
     document.getElementById("message").innerHTML = messageToDisplay + messageProduct;
}


/**
* Permet de modifier l'url d'un lien
*/
function contientParam(param, valeurAVerifier)
{
    var params = getParameters();
    if (params && params[0][0] && params[0][0].indexOf(param) > -1) {
        if (params[0][1] == valeurAVerifier) {
            return true;
        }
    }
    return false;
}


/**
 * Permet de nettoyer une URL en enlevant tous les parametres
 * @params :
 *    - _urlToClean : L'url a nettoyer
*/
function cleanUrl(_urlToClean){
    var urlClean = _urlToClean ;
    var urlParams =  _urlToClean.split("?") ;
    if(urlParams.length > 1){
        urlClean = urlParams[0] ;        
    }
    document.location.href = urlClean ;
}