var requestContext = null;
function contextualizeFrontPage() {
if(contextvalide == 1 && curentGloblaContext !="notexist"){
    clearTimeout(requestContext);
    //alert("contextvalide "+contextvalide)
}
else{
   // DWRContextualizer.getCurrentContext({callback:function(data) {
       var data=getCurrentContext();
        var currentShop = data;
        
        if(currentShop) {
            if ( currentShop.save =='false' || currentShop.save == false ) {
                var defaultlink = "";
                if(prisme!='1090509516'){
                 defaultlink = "<a onclick=\"xt_med('C','1','zone_permanente::prismes::magasins_et_services','N');\" href=\"/mpng2-front/pre?zone=zonecatalogue&amp;idLSPub=1090509516&amp;renderall=on\" accesskey=\"5\"><img name=\"Services\" src=\"/images/main_top_tabs/magasins_et_services.gif\" alt=\"Magasins et services\"  /></a>";
                }else{
                 defaultlink = "<a onclick=\"xt_med('C','1','zone_permanente::prismes::magasins_et_services','N');\" href=\"/mpng2-front/pre?zone=zonecatalogue&amp;idLSPub=1090509516&amp;renderall=on\" accesskey=\"5\"><img name=\"Services\" src=\"/images/main_top_tabs/magasins_et_services_on.gif\" alt=\"Magasins et services\"  /></a>";

                }
                dwr.util.setValue("divmag", defaultlink , { escapeHtml:false } );
                  DWRContextualizer.getContext("anonymous", {callback:function(data) {
                        var contextShop = data;
                        //if(contextShop.save == 'true' ){  
                        var accbegin = '<a onclick="xt_med(\'C\',\'38\',\'acceder_magasin_arche\',\'N\');" href="javascript:restoreContext();"><img src="/images/pickup/chevron-magasin.gif" alt="acceder" /> Acc&eacute;der &agrave; votre magasin de ';
                        var accend = '</a>';
                        DWRShopContextualizer.getContextualizedShopByCode( currentShop.shop,  function(data) {
                            var contextualizedShop = data;
                            if(document.getElementById('pathbarmag')){
                            dwr.util.setValue("pathbarmag", accbegin + contextualizedShop.name + accend, { escapeHtml:false } );
                            }

                        });
                        //}
                    }
                    });
                    DWRContextualizer.getContext("ci",  {callback:function(dataci) {
                        var contextShopCI = dataci;
                        if(contextShopCI) {
                            if(contextShopCI.save != null) {
                                if(contextShopCI.save == 'false'){
                                    var accbegin = '<a onclick="xt_med(\'C\',\'38\',\'acceder_magasin_arche\',\'N\');" href="javascript:accederMagsinCI();"><img src="/images/pickup/chevron-magasin.gif" alt="acceder" /> Acc&eacute;der &agrave; votre magasin de ';
                                    var accend = '</a>';
                                    DWRShopContextualizer.getContextualizedShopByCode( contextShopCI.shop, function(data) {
                                        var contextualizedShop = data;
                                        if(document.getElementById('pathbarmag')){
                                        dwr.util.setValue("pathbarmag", accbegin + contextualizedShop.name + accend, { escapeHtml:false } );
                                        }
                                    });
                                }
                            }
                        }
                    }
                    });                
                  contextvalide=1;
            } else {
                DWRShopContextualizer.getContextualizedShopEIIDByCode(currentShop.shop, {callback:function(eiid) {
                    var shopeiid = eiid;
                    var link = "";
                var defaultlink = "";
                if(prisme!='1090509516'){
                 link = "<a onclick=\"xt_med('C','1','zone_permanente::prismes::magasins_et_services','N');\" href=\"/mpng2-front/pre?zone=zonecatalogue&amp;idEILSPub=" + shopeiid + "&amp;renderall=on\" accesskey=\"5\"><img name=\"Services\" src=\"/images/main_top_tabs/mon_magasin.gif\" alt=\"Magasins et services\"  /></a>";
                }else{
                 link = "<a onclick=\"xt_med('C','1','zone_permanente::prismes::magasins_et_services','N');\" href=\"/mpng2-front/pre?zone=zonecatalogue&amp;idEILSPub=" + shopeiid + "&amp;renderall=on\" accesskey=\"5\"><img name=\"Services\" src=\"/images/main_top_tabs/mon_magasin_on.gif\" alt=\"Magasins et services\"  /></a>";

                }
                    dwr.util.setValue("divmag", link , { escapeHtml:false } );
                    
                    //affichage de l'onglet 'trouver un magasin'
                    if(document.getElementById('trouvermag')){
                        obj = document.getElementById("trouvermag");
                        obj.style.display = 'inline';
                    }
                }
                });
                if(currentShop.shop=='139'){
                  getImgvenduenline();
                }
                if(currentShop.shop=='14' || currentShop.shop=='13' || currentShop.shop=='60'){
                    var shopName = "";
                    switch(currentShop.shop){
                        case "139":
                            shopName="larochelle";
                            break;
                        case "13":
                            shopName="montigny";
                            break;
                        case "14":
                            shopName="valenciennes";
                            break;
                        case "60":
                            shopName="caen";
                            break;
                    }
                    if(document.getElementById("ongletretrait")){
                        document.getElementById("ongletretrait").href="http://retrait-"+shopName+".leroymerlin.fr";
                        if(document.getElementById("liretrait")){
                            document.getElementById("liretrait").style.display="block";
                        }
                    }
                }
                var img = '/images/pickup/leroymerlin_'+currentShop.shop +'.gif';           
                if(document.getElementById('logoimgarche')){
                    document.getElementById('logoimgarche').setAttribute("src", img);
                    document.getElementById('mouseoutlogo').innerHTML=img;
                }
                if(document.all){
                    document.getElementById('logoimg').setAttribute('className','logopickup');
                }else{
                    document.getElementById('logoimg').setAttribute('class','logopickup');
                }
                displayContextualizePart();
                contextvalide=1;
                    
                if(logg == 'false' && document.getElementById('pathbarmag') && document.getElementById('pathbarmag').innerHTML == '') {
                    //affichage du lien uniquement si on n'est pas logge au CI, cf logpersonalaccount.tpl                    � � 
                    var quitterbegin = '<a onclick="xt_med(\'C\',\'38\',\'quitter_magasin_arche\',\'N\');" href="javascript:removeContext();"><img src="/images/pickup/chevron-magasin.gif" alt="quitter" /> Quitter votre magasin de ';
                    var quitterend = '</a>';
                    DWRShopContextualizer.getContextualizedShopByCode( currentShop.shop, {callback:function(data) {
                        var contextualizedShop = data;
                        if(document.getElementById('pathbarmag')){
                            document.getElementById('pathbarmag').innerHTML=quitterbegin + contextualizedShop.name + quitterend;
                        }
                        //dwr.util.setValue("pathbarmag", quitterbegin + contextualizedShop.name + quitterend, { escapeHtml:false } );       	
                        //alert('context ok');
                    }, 
                    timeout:5000,       
                    errorHandler:function(msg) {
                        //   alert("Une erreur s'est produite : "+ msg);
                    }
                    });
                }  
            } 
        } else {
                var defaultlink = "";
                if(prisme!='1090509516'){
                 defaultlink = "<a onclick=\"xt_med('C','1','zone_permanente::prismes::magasins_et_services','N');\" href=\"/mpng2-front/pre?zone=zonecatalogue&amp;idLSPub=1090509516&amp;renderall=on\" accesskey=\"5\"><img name=\"Services\" src=\"/images/main_top_tabs/magasins_et_services.gif\" alt=\"Magasins et services\"  /></a>";
                }else{
                 defaultlink = "<a onclick=\"xt_med('C','1','zone_permanente::prismes::magasins_et_services','N');\" href=\"/mpng2-front/pre?zone=zonecatalogue&amp;idLSPub=1090509516&amp;renderall=on\" accesskey=\"5\"><img name=\"Services\" src=\"/images/main_top_tabs/magasins_et_services_on.gif\" alt=\"Magasins et services\"  /></a>";

                }
            dwr.util.setValue("divmag", defaultlink , { escapeHtml:false } );
             contextvalide=1;
        }
        
   /* },
    timeout:5000,       
    errorHandler:function(msg) {
        //   alert("Une erreur s'est produite : "+ msg);
    }
    
    });*/
    }
}
      
function displayContextualizePart() {

    if(document.getElementById('bloccontextualize1')){
        obj = document.getElementById("bloccontextualize1");
        obj.style.display = 'block';
    }
    if(document.getElementById('bloccontextualize2')){
        obj = document.getElementById("bloccontextualize2");
        obj.style.display = 'block';
    }
    if(document.getElementById('bloccontextualize3')){
        obj = document.getElementById("bloccontextualize3");
        obj.style.display = 'block';
    }
}  
function getImgvenduenline() {
    tags = document.getElementsByTagName('img');
  //  alert("tags.length"+tags.length)
    for (i = 0; i < tags.length; i++) {
        if (tags[i].id == 'imagevenduenline') {
            tags[i].style.display="none";

        }
    }
}
