﻿// JScript File
// Global 
// call : Default.master body onload
// use  : swap the href of the LanguageHyperLink from the dfc header
function switchLanguage(){
    var languageLink = document.getElementById("MenuTop1_LanguageHyperLink");
    if(languageLink){
    alert(languageLink);
        var currentURL = location.href; 
        if(currentURL.indexOf("CultureCode=fr") > -1)
            currentURL = currentURL.replace("=fr","=en");
        if(currentURL.indexOf("CultureCode=en") > -1)
            currentURL = currentURL.replace("=en","=fr");    
        if(currentURL.indexOf("/en/") > -1)
            currentURL = currentURL.replace("/en/","/fr/");
        if(currentURL.indexOf("/fr/") > -1)
            currentURL = currentURL.replace("/fr/","/en/");
            
        languageLink.href = currentURL;
    }
}
//**************************************************************************
// function for Request-for-material.aspx
//**************************************************************************
var inter;
var lockPopUp = false;

function showDetailsPopUp(leTitre, image, description, category, myEvent, downloadLinkVisibility, downloadLink){
    document.getElementById("downloadDocument").style.visibility = downloadLinkVisibility;
    document.getElementById("ctl00_ContentPlaceHolder1_popUpDownloadDocument").href = downloadLink;
    document.getElementById("popUpResourceShortDesc").innerHTML = description;
    document.getElementById("popUpResourceImage").src = image.replace("~/","");
    document.getElementById("popUpResourceTitle").innerHTML = leTitre;
    document.getElementById("popUpCategoryTDColor").setAttribute("class", category);
    document.getElementById("popUpCategoryTDColor").setAttribute("className", category);
    divDetailsPopUp = document.getElementById("detailsPopUp");
    divDetailsPopUp.style.top = Math.round(document.documentElement.scrollTop + myEvent.clientY - 15) + "px"; //Math.round((document.documentElement.clientHeight/2)-(divDetailsPopUp.style.height/2)+document.documentElement.scrollTop)+'px';
    divDetailsPopUp.style.visibility = "visible";
}

function searchAndHidePopUp(){
    var divPopUp = document.getElementById("detailsPopUp");
    if(divPopUp && lockPopUp == false){
        var lienPourDoc = document.getElementById("downloadDocument")
        divPopUp.style.visibility = "hidden";
        lienPourDoc.style.visibility = "hidden";
    }  
}

function showPopUp(){
    var divPopUp = document.getElementById("detailsPopUp");
    divPopUp.style.visibility = "visible";
    if(divPopUp.style.visibility == "visible"){
        window.clearInterval(inter);
        lockPopUp = false;
    }
}

function doLockPopUp(element){
    lockPopUp = true;
    inter = window.setInterval("showPopUp()", 50);
}

function changeTab(id){
    if(document.getElementById(id).className="tab")
    {
        document.getElementById(id).className="selectedTab";
    }
    if(id == "all")
    {
        document.getElementById("hpConso").className="tab";
        document.getElementById("hphp").className="tab";
    }
    else if(id == "hpConso")
    {
        document.getElementById("all").className="tab";
        document.getElementById("hphp").className="tab";
    }
    else if(id == "hphp")
    {
        document.getElementById("hpConso").className="tab";
        document.getElementById("all").className="tab";
    }
}

// FROM http://www.codeproject.com/KB/aspnet/EnterKeyToButtonClick.aspx
function doClick(buttonName,e)
{

    //the purpose of this function is to allow the enter key to 
    //point to the correct button to click.
    var key;

    if(window.event)
        key = window.event.keyCode;     //IE
    else
        key = e.which;     //firefox        
    
    if (key == 13)
    {
    //Get the button the user wants to have clicked
        var btn = document.getElementById(buttonName);
        if (btn != null)
        { //If we find the button click it
            btn.click();
            /*if(window.event)
                window.event.keyCode = 0;     //IE
            else
                e.which = 0;     //firefox      
           */
        }
    }
}

//**************************************************************************
// End of function for Request-for-material.aspx
//**************************************************************************
