﻿// Fichier JScript

function showExpressShopLink(linkId)
{
    document.getElementById(linkId).style.display = "block";
}

function hideExpressShopLink(linkId)
{
    document.getElementById(linkId).style.display = "none";
}

function hideControls(controlType, classToHide, hide, secondModalIdTab)
{
//    if (navigator.userAgent.toLowerCase().indexOf('msie 6') > -1){
        var inputs = document.getElementsByTagName(controlType);
        for(i = 0; i < inputs.length; i++)
            if((classToHide == '') || (inputs[i].className == classToHide))
            {
                changeVisibility = true;
                if(secondModalIdTab != '')
                {
                    for(j = 0; j < secondModalIdTab.length; j++)
                    {
                        if(inputs[i].id.indexOf(secondModalIdTab[j]) != -1)
                        {
                            changeVisibility = false;
                        }
                    }
                }
                    
                if(changeVisibility)
                {
                    if(hide)
                    {
                        inputs[i].style.visibility = 'hidden';
                    }
                    else
                    {
                        inputs[i].style.visibility = '';
                    }
                }
            }
//    }
}

function setModalVisible(modalId, modal, visible, secondModalIdTab)
{
    if(visible)
    {   
        document.getElementById(modalId).style.display = "block";
        if(modal)
        {
            document.getElementById("couverture").style.display = "block";
        }
    }
    else
    {
        document.getElementById(modalId).style.display = "none";
        if(modal)
        {
            document.getElementById("couverture").style.display = "none";
        }
        
        if(secondModalIdTab != '')
        {
            for(i = 0; i < secondModalIdTab.length; i++)
            {
                var tabElement = document.getElementById(secondModalIdTab[i]);
                if(tabElement && tabElement.style.display == "block")
                {
                    visible = true;
                }
            }
        }
    }
    
    hideControls('SELECT', '', visible, secondModalIdTab);
    
    return false;
}

function setExpressShopModalForShow()
{
    centerDiv();
    document.getElementById("couverture").style.display = "block";
    hideControls('SELECT', '', true, '');
    
    return false;
}

function setTimer()
{
    hideCartTimer = setTimeout('hideCart()', 10000);
}

function hideCart()
{
    setModalVisible("ExpressBasket", false, false, ["modale_zoom","ExpressShop"]);
    
    clearTimeout(hideCartTimer);
}

function openPopup(url)
{
    window.open(url,'openPopup','width=600,height=570,toolbar=no,status=no,menubar=no,scrollbars=yes,resizable=no');
}

function openSizedPopup(url, width, height)
{
    window.open(url,'openPopup','width=' + width + ',height=' + height + ',toolbar=no,status=no,menubar=no,scrollbars=no,resizable=no');
}

function openRassurance(topic)
{
    var popupFeatures = 'toolbar=0, location=0, directories=0, status=0, scrollbars=0, resizable=0, copyhistory=0, menuBar=0, width=600, height=350';
    window.open('/StaticPages/Rassurance.aspx#' + topic,'Reassurance',popupFeatures);
}

function centerDiv()
{
  if (parseInt(navigator.appVersion) > 3)
  {
    var winW = 0;
    var winH = 0;
    if (navigator.appName.indexOf("Microsoft")!=-1)
    {
        winW = document.body.offsetWidth;
        winH = document.body.offsetHeight;
    }
    else
    {
        winW = window.innerWidth;
        winH = window.innerHeight;
    }

    var expressShopDiv = document.getElementById("ExpressShop");
    
    var scrOfX = 0;
    var scrOfY = 0;
    if( typeof( window.pageYOffset ) == 'number' )
    {
      //Netscape compliant
      scrOfY = window.pageYOffset;
      scrOfX = window.pageXOffset;
    }
    else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) )
    {
      //DOM compliant
      scrOfY = document.body.scrollTop;
      scrOfX = document.body.scrollLeft;
    }
    else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) )
    {
      //IE6 standards compliant mode
      scrOfY = document.documentElement.scrollTop;
      scrOfX = document.documentElement.scrollLeft;
    }
    
    isIE = navigator.userAgent.indexOf("MSIE") > -1 
    if (isIE)
    {
      //IE specific
      scrOfY = document.documentElement.scrollTop;
      scrOfX = document.documentElement.scrollLeft;
    }

      // First bury expressShop div at a negative z-index so it won't show.
    // Then set display to "" in order to get an accurate offsetHeight value for the div.
    expressShopDiv.style.zIndex="-100";
    expressShopDiv.style.display="";
    leftMarginBegins = ((winW-expressShopDiv.offsetWidth)/2) + scrOfX;
    topMarginBegins = ((winH-expressShopDiv.offsetHeight)/2) + scrOfY;
    expressShopDiv.style.left = leftMarginBegins + "px";

    
    if (isIE)
    {//IE specific
      //expressShopDiv.style.top = (scrOfY + 90) + "px";
      expressShopDiv.style.top = (scrOfY + 260) + "px";
      
    }
    else
    {//Everyone else
      expressShopDiv.style.top = topMarginBegins + "px";
      
    }
    
    //Sauvegarde des valeurs calculees
    document.getElementById("ctl00_ExpressShop1__hdfTop").value = expressShopDiv.style.top;
    document.getElementById("ctl00_ExpressShop1__hdfLeft").value = expressShopDiv.style.left;
  }
}

