var $get = function (id){return document.getElementById(id);}
//Firebug : var DEB = {info:console.info, warn:console.warn, error:console.error};
//Disabled : var DEB = { info: function() { }, warn: function() { }, error: function() { } };
// Chrome / Firebug var DEB = { info: function(arg) { if (console && console.info) console.info(arg); }, warn: function(arg) { if (console && console.warn) console.warn(arg); }, error: function(arg) { if (console && console.error) console.error(arg); } };
var DEB = { info: function(arg) { if (console && console.info) console.info(arg); }, warn: function(arg) { if (console && console.warn) console.warn(arg); }, error: function(arg) { if (console && console.error) console.error(arg); } };

/* Formulaire connexion */
function FormulaireConnexion(login, password, lien) {
    login = document.getElementById(login).value;
    password = document.getElementById(password).value;
    //Création du formulaire
    var outForm = document.createElement("form");
    outForm.setAttribute("method", "POST");
    outForm.setAttribute("action", lien);
    /*outForm.setAttribute("target", "_blank");*/
    /* création du login */
    var input = document.createElement("input");
    input.setAttribute("name", "log");
    input.setAttribute("type", "hidden");
    input.setAttribute("value", login);
    outForm.appendChild(input); /* On ajoute l'élément au formulaire */
    /* création du password */
    var pass = document.createElement("input");
    pass.setAttribute("name", "pass");
    pass.setAttribute("type", "hidden");
    pass.setAttribute("value", password);
    outForm.appendChild(pass); /* On ajoute l'élément au formulaire */
    document.body.appendChild(outForm);
    outForm.submit();
    return false;
}
/* Formulaire connexion */

/******* GESTION DU MENU ********/

function bindMouseHandlersToMenu() {
    $(".topCat dt").each(function(indexx) {
        $(this).bind('mouseenter', mouseEnterEventHandler);
        $(this).bind('mouseleave', mouseLeaveEventHandler);
    })
    $(".topCat dd").each(function(indexx) {
        $(this).bind('mouseenter', mouseEnterEventHandler);
        $(this).bind('mouseleave', mouseLeaveEventHandler);
    })
}

function mouseEnterEventHandler(e) {
    catID = this.id.split('_');
    if (catID && catID[1])
        fireShowCat(catID[1], true);
}

function mouseLeaveEventHandler(e) {
    catID = this.id.split('_');
    if (catID && catID[1])
        fireShowCat(catID[1], false);
}

function fireShowCat(nCatId, bShow) {
    if (!nCatId)
        return;

    // chargement des controles
    if (!this.load)
        this.load = new Array();

    //DEB.warn("fireshowcat " + nCatId + " " + bShow);

    // On regarde si l'action n'est pas déjà effectué
    var hDTerm = document.getElementById("cat_" + nCatId);
    if (hDTerm.IsCatVisible == bShow) {
        //DEB.warn(" |-> Cat is marked as visible...");
        return;
    }

    this.previousCatId = nCatId;
    this.previousCatShow = bShow;

    // Chargement ajax du menu si besoin
    if ($.trim($("#cat_" + nCatId + "_dd").text()).length <= 0 && !this.load[nCatId]) {
        this.load[nCatId] = true;
        $("#cat_" + nCatId + "_dd").load("/CategoryRenderNav-n" + nCatId + "/ .inner");
        var a = new qqq();
    }
    ShowCat(nCatId, bShow);
}


function ShowCat(nCatId, bShow) {
    //DEB.warn(" |-> In ShowCat");
    var hDTerm = document.getElementById("cat_" + nCatId);
    var hDDesc = document.getElementById("cat_" + nCatId + "_dd");
    //DEB.info("ShowCat(" +nCatId + ", " + bShow + ");");
    // Si le div actuel est déja dans l'état demandé, on ne fait rien
    if ((hDTerm.IsCatVisible == bShow) && bShow) {
        //DEB.warn(" |-> Menu already in right state");
        return;
    }

    // Une catégorie est ouverte, on la ferme
    if (this.OpenedCat) {
        //DEB.warn(" |-> Previous opened cat found, closing ");
        this.OpenedCat.dt.className = this.OpenedCat.dt.className.replace(" selected", "");
        this.OpenedCat.dd.className = this.OpenedCat.dd.className.replace(" selected", "");
        //$(this.OpenedCat.dd).slideUp('fast', function() { });
        this.OpenedCat.dt.IsCatVisible = false;
    }
    
    if(bShow)
    {
        //DEB.info(" |-> show cat ");
        hDTerm.className += " selected";
        hDDesc.className += " selected";
        //$(hDDesc).stop(false, false).slideDown('slow', function() { });
        //$(hDDesc).stop(false, false).fadeIn('slow', function() { });
        //$(hDDesc).stop(true).animate({height:'toggle'},1000, function(){});

        // Sauvegarde l'élement ouvert
        this.OpenedCat = {dt:hDTerm,dd:hDDesc};
    } else 
    {
        //DEB.info(" |-> hide cat ");
        hDTerm.className = hDTerm.className.replace(" selected", "");
        hDDesc.className = hDDesc.className.replace(" selected", "");
        //$(hDDesc).stop(false, false).slideUp('slow', function() { });
        //$(hDDesc).stop(false, false).fadeOut('slow', function() { });
        //$(hDDesc).stop(true).animate({ height: 'toggle' }, 1000, function() { });

        // Si l'element a fermer est enregistré, on le supprime
        if(this.OpenedCat && (this.OpenedCat.dt == hDTerm))
        {
            //DEB.warn(" |-> clear previous opened cat ");
            this.OpenedCat = null;
        }
    }
    hDTerm.IsCatVisible = bShow;
    //DEB.info("ShowCat==============> END");
}

/******* FIN DE LA GESTION DU MENU ********/



//switch l'affichage d'une popup (et cache eventuellement une autre popup actuellement affichée)
// forceDisplayPopup = variable permettant de forcer l'affichage de la popup (contrairement a un swap classique)
function switchPopup(id, forceDisplayPopup) 
{
    if (typeof(currentPopId)!='undefined' && currentPopId!=id) 
    {
      oldpopitem = $get(currentPopId);
      if(oldpopitem) oldpopitem.style.display = 'none';
    }
    popitem = $get(id);
    if(popitem)
    {
        currentPopId = id;
        popitem.style.display = (popitem.style.display == 'none' || popitem.style.display == '' || (typeof(forceDisplayPopup)!='undefined' && forceDisplayPopup) ) ? 'block' : 'none';
    }
}

//switch l'affichage d'une DIV
function switchDiv ( div_id ) 
{
	mydiv = $get(div_id);
	mydiv.style.display = (mydiv.style.display == "none" || mydiv.style.display == "") ? "block" : "none";
	//return false;
}

// switch l'affichage d'une DIV v2
function switchDiv2(div_id) {
    mydiv = $get(div_id);
    if (mydiv.style.display == "block" || mydiv.style.display == "") {
        mydiv.style.display = "none";
    }
    else {
        mydiv.style.display = "block";
    }
}

function hasClass(element, specificClass)
{
    return ((element != null) && (element.className != null) && (element.className.indexOf(specificClass) > -1));
}




function switchClass(elementId, specificClass)
{
    var element = document.getElementById(elementId);
    if(hasClass(element, specificClass))
        element.className = element.className.replace(specificClass, "");
    else
        element.className += " " + specificClass;
}

/* Sauvegarde la note choisie pour le commentaire dans un champ cache */
function checkNote(noteID, validator) 
{
	var notation    = $find(noteID).get_Rating();
	var test        = document.getElementById(validator);
	test.value      = notation;
}

/* Affichage d'une page en popup */
function PopPage(url)
{
	var style = "toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=860,height=600";
	var pop = window.open(url, "Popup", style);
	if (pop)
	{
	    pop.focus();
	}
}

/* Onglet par defaut selon le contexte */
function loadDefaultOnglet(elementId, containerName) {
    var element   = document.getElementById(elementId);
    var container = document.getElementById(containerName);
    
    if (element != null && container != null) {
        element.className   = element.className.replace("productContentOff", "productContentOn");
        container.className = container.className = "productMenuOn";
    }        
}
function switchOnglet(elementId, containerName)
{
    var element = document.getElementById(elementId);
    tabOnglets = new Array('productFiche', 'productComments', 'productPack', 'productRelated');
    for (i = 0; i < tabOnglets.length; i++) 
    {
        if (document.getElementById(tabOnglets[i]) != null) {
            if (tabOnglets[i] == elementId) {
                element.className = element.className.replace("productContentOff", "productContentOn");
                document.getElementById(containerName + "_li" + elementId).className = "productMenuOn";
            }
            else if (document.getElementById(containerName + "_li" + tabOnglets[i]) != null) {
                document.getElementById(tabOnglets[i]).className = document.getElementById(tabOnglets[i]).className.replace("productContentOn", "productContentOff");
                document.getElementById(containerName + "_li" + tabOnglets[i]).className = "";
            }
            else {
                document.getElementById(tabOnglets[i]).className = document.getElementById(tabOnglets[i]).className.replace("productContentOn", "productContentOff");
            }
        }
    }
}
/*
function Navigate3D(sFeed)
{   
    var hEl = document.getElementById('navigate3d');
    if(!hEl) return;
    if(hEl.isRunning)
    {
        hEl.innerHTML = '';
        hEl.isRunning = false;
        return false;
    }
    
    hEl.innerHTML = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' width='760' height='450'><param name='movie' value='http://apps.cooliris.com/embed/cooliris.swf' /><param name='flashvars' value='feed=" + sFeed + "' /><param name='allowFullScreen' value='true' /><param name='allowScriptAccess' value='always' /><!--[if !IE]>--><object id='coolirisSWF' type='application/x-shockwave-flash'data='http://apps.cooliris.com/embed/cooliris.swf' width='760' height='450'><param name='flashvars' value='feed=" + sFeed + "' /><param name='allowFullScreen' value='true' /><param name='allowScriptAccess' value='always' /><!--<![endif]--><div><p><a href='http://www.adobe.com/go/getflashplayer'>Get Adobe Flash</a></p></div><!--[if !IE]>--></object><!--<![endif]--></object>";
    hEl.isRunning = true;
    return false;
}*/


/* Gestion de l'impression de la modalpopup Comparateur */
function goCompare(id) 
{
    var hModal = document.getElementById(id);
    var hClone = hModal.cloneNode(true);
    
    /* On clone la div en dehors de la page pour l'imprimer */
    hClone.id = "modalPopupClone";
    hClone.style.position = "relative";
    hClone.style.left = "0";
    hClone.style.top = "0";
    hClone.style.display = "";
    hClone.className = hClone.className + " clearfix";
    if (document.getElementById("modalPopupClone"))
        document.getElementsByTagName('body').item(0).removeChild(document.getElementById("modalPopupClone"));
    document.getElementsByTagName('body').item(0).appendChild(hClone);
    
    /* Ajout de la feuille de style print pour la div clonée */
    var file = '/css/printCompare.css';
    var ext = file.substring(file.lastIndexOf('.')+1);
    var inc = document.createElement('link');
    inc.setAttribute('type','text/css');
    inc.setAttribute('rel','stylesheet');
    inc.setAttribute('media','print');
    inc.setAttribute('href',file);
    inc.setAttribute('id','printCompare');
    document.getElementsByTagName('head').item(0).appendChild(inc);
}

/* Fermeture de la modalpopup Comparateur */
function closeCompare()
{
    /* Suppression de la feuille de style print */
    if (document.getElementById("printCompare"))
        document.getElementsByTagName('head').item(0).removeChild(document.getElementById("printCompare"));
    /* Suppression de la div clonée */
    if (document.getElementById("modalPopupClone"))
        document.getElementsByTagName('body').item(0).removeChild(document.getElementById("modalPopupClone"));
}


function PreventDoubleClick(hEl)
{
    //hEl.style.visibility = "hidden"; // utilisé dans la commande
}

function switchBlog(containerName, index)
{
    var hBlogList = eval(containerName);
    
    if(hBlogList)
    {
        var hImage  = $get(containerName + "_imgArticle");
        var hTitle  = $get(containerName + "_hlTitle");
        var hText   = $get(containerName + "_lbDesc");
        var hLink   = $get(containerName + "_hlRead");
        
        hImage.src          = hBlogList[index].Image;
        hTitle.innerHTML    = hBlogList[index].Title;
        hTitle.href         = hBlogList[index].Url;
        hText.innerHTML     = hBlogList[index].Text;
        hLink.href          = hBlogList[index].Url;
    }
    
    for (i = 0; i < hBlogList.length; i++) 
    {
        img = document.getElementById("liBlog_" + i);
        if (img.className == "blogList blogSelected")
            img.className = "blogList";
    }
    var img = document.getElementById("liBlog_" + index);
    img.className = "blogList blogSelected";
    
    return false;
}

/*
function AddBookmark(url, title) {
    if (window.sidebar) { // Mozilla Firefox
        window.sidebar.addPanel(title, url, "");
    } else if (document.all) { // IE
        window.external.AddFavorite(url, title);
    } else if (window.opera && window.print) {
        return true;
    }
} */

function switchZoom(containerName, index, enableLink)
{
    var hZoomList = eval(containerName);
    
    if(hZoomList)
    {
        var hImage  = $get(containerName + "_ImgProduct");
        hImage.src = hZoomList[index].Image;
        
        if (enableLink)
        {
            var hLink  = $get(containerName + "_hplZoom");
            hLink.href = hZoomList[index].Url;
        }
    }
    
    if (enableLink)
    {
        for (i = 0; i < hZoomList.length; i++) 
        {
            img = document.getElementById("liZoom_" + i);
            if (img.className == "vignette selected")
                img.className = "vignette";
        }
        var img = document.getElementById("liZoom_" + index);
        img.className = "vignette selected";
    }
    return false;
}

/* Show all params in comparator popup 
function showAllParams() {
    $(".allparams").css("display", "table-row");
    $(".mainparams").css("display", "none");
}
*/
/* Display more than 8 listing filters if available */
function showMoreFilters(input) {
    $(".moreFilter").css("display", "block");
    $(".moreFilterBt").css("display", "none");
    $(".moreFilter .slider").each(function(index) {
        if (this.reset)
            this.reset();
    });
    $("#"+input+"").val("1");
}

    
/*var nbTops          = 8;*/
var nbDisplayTops   = 4;
var topIndex        = 0;
var topWidth        = 220;

function animTops(direction) {
    var fleG = $get("fleG");
    var fleD = $get("fleD");

    if (direction == 'right') {
        if (topIndex+nbDisplayTops<nbTops)
        {
            topIndex++;
            leftPos=(0 - topWidth*topIndex)+"px";
            $("#animContent").animate({ left: leftPos }, 500);
        }
        
        if (topIndex>0)
            fleG.className = fleG.className.replace("_inactive", "_active");     
        if (topIndex+nbDisplayTops==nbTops)
            fleD.className = fleD.className.replace("_active", "_inactive");
    }
    
    if (direction == 'left') {
        if (topIndex>0)
        {
            topIndex--;
            leftPos = (0 - topWidth*topIndex)+"px";
            $("#animContent").animate({ left: leftPos }, 500);
        }
        
        if (topIndex==0)
            fleG.className = fleG.className.replace("_active", "_inactive");
        if (topIndex+nbDisplayTops<nbTops)
            fleD.className = fleD.className.replace("_inactive", "_active");
    }
}

/* menuDefilant */
var headline_count;
var headline_interval;
var old_headline = 0;
var current_headline = 0;
var headlines;

function headline_init() {
    jQuery.fx.interval = 33;

    headline_count = $("p.headline").size();
    headlines = $("p.headline");
    $(headlines[current_headline]).css('top', '0px');

    headline_interval = setInterval(headline_rotate, 5000); //time in milliseconds
    $('.menuDefilantHome').hover(function() {
        clearInterval(headline_interval);
    }, function() {
        headline_interval = setInterval(headline_rotate, 5000); //time in milliseconds
        headline_rotate();
    });
}

function headline_rotate() {
    current_headline = (old_headline + 1) % headline_count;
    $(headlines[old_headline]).stop(true).animate({ top: 30 }, "slow", function() {
        $(this).css('top', '-30px');
    });
    $(headlines[current_headline]).stop(true).animate({ top: 0 }, "slow");
    old_headline = current_headline;
}
/* menuDefilant end */

function switchDispo(list, link)
{
    var ddl = document.getElementById(list);
    var infos = (ddl.options[ddl.selectedIndex].value).split(";");
    var icone = document.getElementById(link);
    $("#" + link).fadeOut("200", function() {
        icone.className = "lir dispo d" + ("0" + infos[1]).slice(-2);
        icone.href = infos[2];
        $("#" + link).show();
    });
}


function getGuide(index, bgUrl, linkText, linkUrl, pnlImgId, hplGuideItemId, hplCurrentGuide) {
    var img = new Image();
    $(img).attr("src", bgUrl);
    $(img).load(); 
    var container = $("#btImgContainers a.btImg");
    container.removeClass("selected");
    var count = 0;
    $("#btImgContainer a.btImg").each(function(indexx) {
        $(this).removeClass("selected");
        if (indexx == index) {
            $(this).addClass('selected');
            $(".zoneHome").animate({ width: "0", height: "200" }, 300, function() {
                $("#" + hplGuideItemId).html("&rsaquo; " + linkText);
                $("#" + hplGuideItemId).attr("href", linkUrl);

                $("#" + hplCurrentGuide).attr("href", linkUrl);
                
                $(".zoneHome").attr("src", bgUrl);
                $(".zoneHome").animate({ width: "675" }, 300);
            });
        }
    });
}

function textReplacement(input) {
    var originalvalue = input.val();
    input.addClass('default');
    input.focus(function() {
        if ($.trim(input.val()) == originalvalue) { input.val(''); input.removeClass('default'); }
    });
    input.blur(function() {
        if ($.trim(input.val()) == '') { input.val(originalvalue); input.addClass('default'); }
    });
}

function NewletterSubscribe(page) {
    var temp = document.getElementById('emailNewsletter').value;
    url = 'Newsletter/?email=' + temp;
    
    if(temp == "")
        return false;
    window.location = url;
    return true;
}
          
function MoveAssistantBasket() {
    var divBasket = $(".divBasket");
    var divRepere = $(".repere");
    if (divBasket.offset() != null) {
        var topbas = jQuery(window).height() + $(window).scrollTop();
        if (topbas > divRepere.offset().top) {
            divBasket.addClass("basket2");
        } else if (topbas < divRepere.offset().top) {
            divBasket.removeClass("basket2");
        }
    }
}

function SlideParams(direction) {
    
    //Position maximale
    var posMaxUp = $("#tblParams").height() - $("div.ListingCompare.overflow").height();
    //Durée de l'animation
    var timeOut = 15;
    //Distance de déplacement
    var dist = 15;
    //Position top actuel
    var tblParamsTop = parseInt($("#tblParams").css("top"));  
    
    if (direction == "up") {
        //alert("tblParamsTop = " + tblParamsTop + "-->-posMaxUp=" + -posMaxUp);
        if (tblParamsTop - dist < -posMaxUp) {dist = posMaxUp + tblParamsTop; }
        $("#tblParams").animate({ "top": "-=" + dist + "px" }, timeOut, function() { SlideParams(direction); });
    }
    else if (direction == "down") {
        if (tblParamsTop + dist > 0) { dist = 0 - tblParamsTop; }
        $("#tblParams").animate({ "top": "+=" + dist + "px" }, timeOut, function() { SlideParams(direction); });
    }        
}

function AutoSlideParams(element) {
    element = jQuery(element);
    var posMax = $("#tblParams").height() - $("div.ListingCompare.overflow").height();
    var move = function(event) {
        if (element.data('mouseMove')) {
            var changeY = event.clientY - element.data('mouseY');
            var newY = parseInt(element.css('top')) + changeY;
            if (newY > 0) { newY = 0; }
            if (newY < -posMax) { newY = -posMax; }
            element.css('top', newY);
            element.data('mouseY', event.clientY);
        }
    }
    element.mousedown(function(event) {
        element.data('mouseMove', true);
        element.data('mouseY', event.clientY);
    });
    element.parents(':last').mouseup(function() {
        element.data('mouseMove', false);
    });

    element.mouseout(move);
    element.mousemove(move);
}
 
function aceSearchCat_ItemSelected(source, eventArgs) {
    if (eventArgs._item.nodeName != "A") {
        $get(lbSearchId).click();
    }
    else {
        document.location.href = eventArgs._item.href;
    }
}
function Suggest_Populated(sender, e) {
    var Suggest = sender.get_completionList().childNodes;
    var globalResource = searchCategoryText;
    var sTest = "";
    for (var i = 0; i < Suggest.length; i++) {
        if (Suggest[i]._value != Suggest[i].innerHTML) {
            sTest = sTest + Suggest[i]._value + "\n"
            var a = document.createElement("SPAN");
            a.innerHTML = "<" + "a href='" + Suggest[i]._value + "'>" + globalResource + Suggest[i].innerHTML + "</a>";
            Suggest[i].appendChild(a);
        }
    }
}

function ScrollCompare() {
    var iTop = 0;
    var iLeft = 0;
    $('#ctl00_cphMainContent_ucComparatorAddControl_pnlModalCompare').scroll(function() {
        iLeft = $(this).scrollLeft();
        iTop = $(this).scrollTop();       
        $("#ctl00_cphMainContent_ucComparatorAddControl_hplClose").css("top", iTop + "px");
        $("#ctl00_cphMainContent_ucComparatorAddControl_hplClose").css("right", -iLeft + "px");        
    });    
}


function resetFilters() {

    $(".slider").each(function (index) {
        if (this.resetToDefault)
            this.resetToDefault();
    });

    $(".mde").each(function (index) {
        if (this.resetToDefault)
            this.resetToDefault();
    });

    //$(".filterButton").click();
    eval($(".filterButton").get(0).href);

    /*for (var i = 0; i < window.sliders.length; i++) {
        //console.info("hello");
        window.sliders[i].resetToDefault();
     }*/
}

function redirectOnFilter(baseUrl) {
    filterUrl = '';
    $("#filterBloc .filter").each(function(index) {
    tmpFilterString = buildFilterString(this);
        if (tmpFilterString && tmpFilterString.length>0)
            filterUrl += '+' + tmpFilterString;
    });
    baseUrl = baseUrl.replace('{0}', filterUrl);
    window.location = baseUrl.replace('/.html', '/');
    //alert(baseUrl); 
}

function redirectOnSimilarFilter(baseUrl) {
    filterUrl = '';
    $("#productParametersList input[rel]").each(function (index) {
        if ($(this).is(':checked'))
            filterUrl += $(this).attr('rel');
    });
    baseUrl = baseUrl.replace('{0}', filterUrl);
    window.location = baseUrl.replace('/.html', '/');
}

function toggleSearchButton() {
    showButton = false;
    $("#productParametersList input[rel]").each(function (index) {
        if ($(this).is(':checked'))
            showButton = true;
    });
    //if (showButton)
    $(".searchSimilar").toggleClass("hidden", !showButton); // (showButton);
}

function buildFilterString(filter) {
    var strFilter = '';
    if (filter.className.indexOf('valFilterList', 0) > 0)
        strFilter = buildValFilterString(filter);
    else if (filter.className.indexOf('intervalFilter', 0) > 0)
        strFilter = buildIntervalFilterString(filter);
    else if (filter.className.indexOf('blFilter', 0) > 0)
        strFilter = buildBinaryFilterString(filter);
    else if (filter.className.indexOf('inputFilter', 0) > 0)
        strFilter = buildInputFilterString(filter);
    
    if (strFilter && strFilter.length > 0)
        return $(filter).attr('rel') + '-' + strFilter;

    return null;
}

function buildIntervalFilterString(iFilter) {
    var result = '';
    leftHandle = $(iFilter).find('.left');
    rightHandle = $(iFilter).find('.right');
    if (!leftHandle || !rightHandle) return;

    currentLeftValue = leftHandle.html();
    currentRightValue = rightHandle.html();
    defaultLeftValue = leftHandle.attr('rel');
    defaultRightValue = rightHandle.attr('rel');

    if (defaultLeftValue && currentLeftValue && currentLeftValue != defaultLeftValue)
        result += 'l' + currentLeftValue;

    if (defaultRightValue && currentRightValue && currentRightValue != defaultRightValue)
        result += 'h' + currentRightValue;
    
    return result;
}

function buildValFilterString(vFilter) {
    sel = $(vFilter).find('select');
    if (!sel)
        return '';
    
    selectedValue = sel.val();
    optionsArray = sel.find('option');
    if (!selectedValue || !optionsArray)
        return '';

    if (selectedValue.length > 0 /*&& selectedValue.length < optionsArray.length*/)
        return selectedValue;

    return '';
}

function buildBinaryFilterString(bFilter) {
    sel = $(bFilter).find('select');
    if (sel) {
        selectedValue = sel.val()
        if (selectedValue && selectedValue != 2)
            return selectedValue;
    }
    return '';
}

function buildInputFilterString(iFilter) {
    sel = $(iFilter);
    if (sel) {
        selectedValue = sel.val()
        if (selectedValue && selectedValue != 0)
            return selectedValue;
    }
    return '';
}

function enableAutoCloseOnModalPopup() {
    for (var itemKey in Sys.Application._components) {
        var item = Sys.Application._components[itemKey];
        if (item instanceof Sys.Extended.UI.ModalPopupBehavior) {
            item.add_shown(function (mpe) {
                if (mpe._backgroundElement) {
                    mpe._backgroundElement.onclick = function () {
                        mpe.hide();
                    };
                }
            });
        }
    }
}

function copyClipboard(intext) {
    // alert('"' + intext + '" est maintenant dans le presse-papier !');
    if (window.clipboardData) {
        window.defaultStatus = '"' + intext + '" est maintenant dans le presse-papier !';
        window.clipboardData.setData('Text', intext);
    }
}

/* Affiche un textbox pour un autre email (dans detail de commande, renvoi du mail) */
function showAltEmail() {
    // $(".altemail").css("display", "block");
    $(".altemail").show("fast");
}

function accentsTidy(s) {
    var r = s.toLowerCase();
    r = r.replace(new RegExp("[\t]", 'g'), " ");
    r = r.replace(new RegExp("[àáâãäå]", 'g'), "a");
    r = r.replace(new RegExp("æ", 'g'), "ae");
    r = r.replace(new RegExp("ç", 'g'), "c");
    r = r.replace(new RegExp("[èéêë]", 'g'), "e");
    r = r.replace(new RegExp("[ìíîï]", 'g'), "i");
    r = r.replace(new RegExp("ñ", 'g'), "n");
    r = r.replace(new RegExp("[òóôõö]", 'g'), "o");
    r = r.replace(new RegExp("œ", 'g'), "oe");
    r = r.replace(new RegExp("[ùúûü]", 'g'), "u");
    r = r.replace(new RegExp("[ýÿ]", 'g'), "y");
    r = r.replace(new RegExp(" or ", 'g'), " OR ");
    return r;
};

function searchRedirect(ev) {
    var hElSearch = $("#" + txtSearchId);
    var hElSearchType = $("#" + ddlSearchId); 
    window.location = "/SearchRedirect.aspx?t=" + hElSearchType.val() + "&q=" + escape(accentsTidy(hElSearch.val()));
    return false;
}

function selfCloseSplash() {
    $.colorbox.close();
}


/******* GESTION DE LA VERIFICATION DU PANIER ********/

function bindMouseHandlersToCompatElements() {
    $(".compatElts").each(function (indexx) {
        $(this).bind('mouseenter', mouseEnterEventHandlerCompatibility);
        $(this).bind('mouseleave', mouseLeaveEventHandlerCompatibility);
    })
    $(".compatElts").each(function (indexx) {
        $(this).bind('mouseenter', mouseEnterEventHandlerCompatibility);
        $(this).bind('mouseleave', mouseLeaveEventHandlerCompatibility);
    })
}

function mouseEnterEventHandlerCompatibility(e) {
    var classe = this.className;
    if (!classe) return;
    classes = classe.split(' ');
    if (!classes) return;

    for (var i = 0; i < classes.length; i++) {
        if (classes[i].indexOf("AR") === 0) {
            $(".compatElts." + classes[i]).addClass("hovered");  //css("background", "#fab");
        }
    }

}

function mouseLeaveEventHandlerCompatibility(e) {
    var classe = this.className;
    if (!classe) return;
    classes = classe.split(' ');
    if (!classes) return;

    for (var i = 0; i < classes.length; i++) {
        if (classes[i].indexOf("AR") === 0) {
            $(".compatElts." + classes[i]).removeClass("hovered");  //css("background", "#fff");
        }
    }

}

