﻿var down = 0;
var IsInMainDiv = 0;
var IsInInnerDiv = 0;

function ShowDeroulante(visible, gauche, element)
{
    try
    {
        der = element.children[0];
    }
    catch (e)
    {
        der = element.childNodes[1];
    }

    if (visible == true)
    {
        der.style.display = "block";
        der.style.left = element.offsetParent.offsetParent.offsetParent.offsetLeft + gauche + 1 + "px";
        der.style.top = "116px";
        //$("#" + der.id).fadeIn("slow");
    }
    else {
        der.style.display = "none";
        //$("#" + der.id).fadeOut("slow");
    }
}

function PushBouton(hover, element, combien)
 {
    if (hover == true)
    {
        element.width = element.width - combien;
    }
    else
    {
        element.width = element.width + combien;
    }
}

/*function PushBouton(hover, element, menu_rollover_element_id, combien)
{
    menu_rollover_element = document.getElementById(menu_rollover_element_id);
    
    //alert(menu_rollover_element);
    if (hover == true)
    {
        //alert(menu_rollover_element);
        //HideAllRollOverMenus();
        //alert("2");

        element.width = element.width - combien;
        //alert(menu_rollover_element.style.display);
        menu_rollover_element.style.display = 'block';
        //alert(menu_rollover_element.style.display);
    }
    else
    {
        element.width = element.width + combien;
        //menu_rollover_element.style.visibility = 'hidden';
    }
}*/

//function IsInMainDivFunc(IsIn, evt, o)
function IsOutOf(evt, o)
{
    //IsInMainDiv++; // = IsIn;
    //console.log(IsInMainDiv);
    //console.log(o);
 
    evt = evt || window.event
    var targ = evt.target || evt.srcElement;
    /*if (targ.nodeName !== 'DIV' || targ.id !== 'thediv') {
        return;
    }*/
    //console.log("------");
    //console.log(targ);

    var relTarg = evt.relatedTarget || evt.toElement;
    
    while (relTarg !== o && relTarg.nodeName !== 'HTML')
    {
        relTarg = relTarg.parentNode;
    }
    //console.log(relTarg);
    
    if (relTarg === o)
    {
        return false;
    }
    //console.log("mouse out of div area");

    return true;

    /*if (IsInInnerDiv >= 2)
    {
        var menu_rollover_lentilles_correctrices = document.getElementById("menu_rollover_lentilles_correctrices");
        menu_rollover_lentilles_correctrices.style.display = 'none';
    }*/

    //IsInInnerDiv = 0;
}

function HideMenuRollOver(e, o)
{
    var OutOf = IsOutOf(e, o);
    //console.log(OutOf);
    if (OutOf == true)
        o.style.display = 'none';
}

/*function IsInInnerDivFunc(IsIn)
{
    IsInInnerDiv = IsIn;
}*/

function HideAllRollOverMenus()
{
    //alert("HideAllRollOverMenus");
    //console.log("HideAllRollOverMenus")
    var menu_rollover_lentilles_correctrices = document.getElementById("menu_rollover_lentilles_correctrices");
    //alert(menu_rollover_lentilles_correctrices);
    var menu_rollover_lentilles_couleurs = document.getElementById('menu_rollover_lentilles_couleurs');
    var menu_rollover_produits_entretien = document.getElementById('menu_rollover_produits_entretien');
    menu_rollover_lentilles_correctrices.style.display = 'none';
    menu_rollover_lentilles_couleurs.style.display = 'none';
    menu_rollover_produits_entretien.style.display = 'none';
}

/*function DisplayRollOverMenu(menu)
{
    console.log("DisplayRollOverMenu " + menu)
    //alert("DisplayRollOverMenu");
    //alert(menu);
    //alert(menu_rollover_lentilles_correctrices);
    menu.style.display = 'block;';
}*/

//------------------------------
// repositionnement du scroll
//------------------------------

function InitScrollPosition() {
    document.cookie = "yPos=!~0~!";
}

function SetScrollPosition() {
    var strCook = document.cookie;
    if (strCook.indexOf("!~") != 0) {
        var intS = strCook.indexOf("!~");
        var intE = strCook.indexOf("~!");
        var strPos = strCook.substring(intS + 2, intE);
        document.documentElement.scrollTop = strPos;
    }
}

function GetScrollPosition() {
    var intY = document.documentElement.scrollTop;
    document.cookie = "yPos=!~" + intY + "~!";
}

function SetLoading() {
    try {
        document.getElementById('Chargement').style.height = (document.getElementById('options').offsetHeight - 15) + "px";
    }
    catch (e) {
    }
}

function ouvre(fichier, width, height) {
    window.open(fichier, "popup", "directories=0,location=0,addressbar=0,toolbar=0,copyhistory=0,status=0,scrollbars=1,modal=0,menu=0,dialog=0,menubar=0,resizable=0,titlebar=0,personalbar=0,width=" + width + ",height=" + height);
}

function RetourCatalogue() {
    //    if (parent.location.pathname != '/catalogue.aspx')
    //        history.go(-3);
    //    else
    //        history.go(-1);
    //

    history.go(history.previous);
}



function EffaceChamp(valeur, champ) {
    txt = document.getElementById(champ);
    if (txt == null)
    {
        txt = document.getElementById("ctl00_" + champ);
    }
    if (txt == null) {
        txt = document.getElementById("ctl00_Body_" + champ);
    }
    if (txt == null)
        txt = document.getElementById("ctl00_ctl00_" + champ);
    if (txt != null) {
        if (txt.value == valeur)
            txt.value = '';
    }
}

function ShowHide(s) {
    if (document.getElementById(s).style.display != 'none')
        document.getElementById(s).style.display = 'none';
    else document.getElementById(s).style.display = 'inline';
}


$(document).ready(function() {

    $("img.Suivant, img.je_choisis_mes_produits, input.Suivant, a.Suivant img").hover(
    function() {
        if (this.src.search("_hover") == -1)
            this.src = this.src.substring(0, this.src.length - 4) + "_hover.png";
    },

    function() {
        this.src = this.src.replace("_hover", "");
    }
    );

    $("img,[class]").each(function() {
        if ($(this).css("background-image") != null) {
            //$(this).css("behavior", "url(/js/iefix/iepngfix.htc)");
        }
    });

});
