﻿//PageLoad
function pageLoad(sender, eventArgs) {    
    //Search functions
    /*if (!eventArgs.get_isPartialLoad()) {
        $addHandler($get("searchBtn"), "click", Function.createDelegate(this, search));
        $addHandler($get("searchBox"), "keypress", Function.createDelegate(this, searchButtonPress));
    }*/
    $addHandler($get("searchBtn"), "click", Function.createDelegate(this, search));
    $addHandler($get("searchBox"), "keypress", Function.createDelegate(this, searchButtonPress));

    //Silverlight Sniffer message
    setTimeout("updateSilverlightMessage()", 0);

    //To restore state from history points
    Sys.Application.add_navigate(onNavigate);
}

function changeHeroClass(newClassName) {
    $("hero_accordion").className = newClassName;    
}

//Gets set once the RightNav loads
var isPRB = true;

var whoClicked = "";
//document.onclick=hideFlyout;
document.onclick = hideOpened;

function hideOpened() {
    hideFlyout();
    hideDropTabs(); //CC only
    hideSharePopUp();
}

//RightNav over states
function changeClass(thisElement, newClassName) {
    var actualClassName = thisElement.className;
    if (actualClassName != newClassName) {
        if (newClassName == "tab_on_last" && actualClassName == "tab_on") {
            // does nothing
        }
        else if (actualClassName == "tab_active") {
            //does nothing
        }
        else {
            thisElement.className = newClassName;
        }
    }
}

/*:::::::::::::: Tabs CONCERNS/QUESTIONS - Resources page ::::::::::::::*/
function changeTab(thisElement) {    
    var tabs = thisElement.parentNode.childNodes;    

    for (i = 0; i < tabs.length; i++) {
        if (tabs[i] == thisElement) {
            tabs[i].className = "on";
        }
        else {
            tabs[i].className = "off";
        }        
    }
}

function changeTabOver(thisElement) {
    if (thisElement.className == "off") {
        thisElement.className = "off_over";
    }
}

function changeTabOut(thisElement) {
    if (thisElement.className == "off_over") {
        thisElement.className = "off";
    }
}

/*:::::::::::::: ToolTips - Resources page ::::::::::::::*/
var currentTop;
var newTop;

var xCoord = 0;
var yCoord = 0;

var isIE;

document.onmouseover = setXY;

/*function setXY(e) {    
    isIE = document.all;
    
    if (!e) e = window.event;
    if (e) {        
        xCoord = isIE ? (e.clientX + document.body.scrollLeft) : e.pageX;
        yCoord = isIE ? (e.clientY + document.body.scrollTop) : e.pageY;        
    }
}*/


/*var browser = navigator.appName;
var b_version = navigator.appVersion;
var version = parseFloat(b_version);*/

function getIEVersionNumber() {
    var ua = navigator.userAgent;
    var MSIEOffset = ua.indexOf("MSIE ");

    if (MSIEOffset == -1) {
        isIE = false;
        return 0;
    } 
    else {
        isIE = true;
        return parseFloat(ua.substring(MSIEOffset + 5, ua.indexOf(";", MSIEOffset)));
    }
}

var isIE7Min = getIEVersionNumber() >= 7;

function setXY(e) {
    if (!e) e = window.event;
    if (e) {
        xCoord = isIE ? (e.clientX + document.body.scrollLeft) : e.pageX;
        yCoord = isIE ? (e.clientY + document.body.scrollTop) : e.pageY;
    }
}

var tempTop;
function showToolTip(thisElement) {

    var tooltipWraper;

    var linkOver = false;
    var tooltipOver = false;    

    //If rolling over link
    if (thisElement.nodeName == "A") {
        tooltipWraper = thisElement.previousSibling;
        if (tooltipWraper.nodeName != "DIV") {
            tooltipWraper = thisElement.previous();
        }
        linkOver = true;
    }
    //If rolling over tooltip
    else {
        tooltipWraper = thisElement;
        tooltipOver = true;
    }      
        
    if (tooltipWraper.className == "tooltip_wrap hide") {        

        //Position Top
        currentMarginTop = 0;
        
        if (isIE) {
            newTop = currentMarginTop - $(tooltipWraper.id).getHeight() + 3;
        }
        else {
            newTop = currentMarginTop - $(tooltipWraper.id).getHeight();
        }

        var gapCurrentTop_yCoord = yCoord - tooltipWraper.offsetTop;

        //If links takes two lines --> it's height = 24px (12px per line).
        if ($(thisElement).getHeight() > 20) {
            newTop += 13;            
        }
        else {
            //If link takes only one line, but it's the first link on the line
            if ($(thisElement).positionedOffset()["left"] < 100 || $(thisElement).positionedOffset()["left"] > 240) {                
                if (isIE) {                                      
                    
                    if (isIE7Min) {
                        newTop += 5;
                    }
                    else {                        
                        newTop += 10;
                    }                    

                }
                else {
                    newTop += 7;                    
                }
            }
            else {
                if (isIE) {
                    //If IE6
                    if (!isIE7Min) {
                        //newTop -= 13;
                    }

                }
                else {
                    newTop -= 5;
                }
            }
        }        
               
        if (tooltipOver) {
            tooltipWraper.style.marginTop = tempTop + "px";            
        }
        else {
            tooltipWraper.style.marginTop = newTop + "px";
            tempTop = newTop;
        }     
        
        if (linkOver) {
            //Position Left

            var leftSpace = (document.body.clientWidth - 190 - 213) / 2; //602: width hero area, 213:width right nav
            
            if (isIE) {
                if (isIE7Min) {                    
                    tooltipWraper.style.left = xCoord - leftSpace - 60 + "px";
                }
                else {
                    tooltipWraper.style.left = xCoord - 60 - 370 + "px";                    
                }
            }
            else {                
                tooltipWraper.style.left = xCoord - leftSpace - 60 + "px";
            }            
        }

        tooltipWraper.className = "tooltip_wrap";
    }    
}

function hideToolTip(thisElement) {

    var tooltipWraper;    

    //If rolling over link
    if (thisElement.nodeName == "A") {
        tooltipWraper = thisElement.previousSibling;
        if (tooltipWraper.nodeName != "DIV") {
            tooltipWraper = thisElement.previous();
        }
    }
    //If rolling over tooltip
    else {
        tooltipWraper = thisElement;
    }

    if (tooltipWraper.className == "tooltip_wrap") {
        tooltipWraper.className = "tooltip_wrap hide";
        //tooltipWraper.style.top = currentTop + "px";
        //tooltipWraper.style.top = "0px";
    }
}

/*:::::::::::::: ToolTips - Thumbnails Resources page ::::::::::::::*/
function showThumbnailTooltip(thisElement) {
    thisElement.parentNode.parentNode.parentNode.parentNode.className = 'selected_L_on'    
}

function hideThumbnailTooltip(thisElement) {
    thisElement.parentNode.parentNode.parentNode.parentNode.className = 'selected_L'
}

/*:::::::::::::: Rotator - Thumbnails Resources page ::::::::::::::*/
var xPos_ini = 0;
var xPos_limit;
var setInitial = false;
var totalThumbnails;
var totalWidth;
var xPos = xPos_ini; //to start

var timerThumbnails;
var elementToMove;
var arrowLeft;
var arrowRight;

function thumbnailsLeft(thisElement) {

    if (thisElement.className == "thumb_arrow_l") {

        //IE
        if (thisElement.parentNode.nextSibling.nodeName == "DIV") {
            elementToMove = thisElement.parentNode.nextSibling.firstChild;            
            arrowLeft = thisElement;
            arrowRight = thisElement.parentNode.parentNode.lastChild.firstChild;
            if (setInitial) {
                xPos = elementToMove.offsetLeft;
                moveThumbnailsLeft();
            }
            else {
                setInitialValues(thisElement, "left");
            }
        }
        //FF
        else {
            elementToMove = thisElement.parentNode.next().firstDescendant();            
            arrowLeft = thisElement;
            //arrowRight = thisElement.parentNode.parentNode.lastChild.firstDescendant();
            if (setInitial) {
                xPos = elementToMove.offsetLeft;
                moveThumbnailsLeft();
            }
            else {
                setInitialValues(thisElement, "left");
            }
        }        
    }    
}

function thumbnailsRight(thisElement) {

    if (thisElement.className == "thumb_arrow_r") {
        //IE
        if (thisElement.parentNode.previousSibling.nodeName == "DIV") {
            elementToMove = thisElement.parentNode.previousSibling.firstChild;            
            arrowRight = thisElement;
            arrowLeft = thisElement.parentNode.parentNode.firstChild.firstChild;
            if (setInitial) {
                xPos = elementToMove.offsetLeft;
                moveThumbnailsRight();
            }
            else {
                setInitialValues(thisElement, "right");
            }
        }
        //FF
        else {
            elementToMove = thisElement.parentNode.previous().firstDescendant();            
            arrowRight = thisElement;
            arrowLeft = thisElement.parentNode.parentNode.firstDescendant().firstDescendant();            
            if (setInitial) {
                xPos = elementToMove.offsetLeft;
                moveThumbnailsRight();
            }
            else {
                setInitialValues(thisElement, "right");
            }
        }        
    }    
}

function moveThumbnailsLeft() {
    elementToMove.style.width = totalWidth + "px";
    //Move Left
    if (xPos < xPos_ini) {
        xPos += 2;
        elementToMove.style.left = xPos + "px";
        arrowRight.className = "thumb_arrow_r";
    }
    else {
        arrowLeft.className = "thumb_arrow_l_off";
    }

    timerThumbnails = setTimeout("moveThumbnailsLeft()", 0.1);
}

function moveThumbnailsRight() {
    elementToMove.style.width = totalWidth + "px";
    //Move Right
    if (xPos > xPos_limit) {
        xPos -= 2;
        elementToMove.style.left = xPos + "px";
        arrowLeft.className = "thumb_arrow_l";
    }
    else {
        arrowRight.className = "thumb_arrow_r_off";
    }

    timerThumbnails = setTimeout("moveThumbnailsRight()", 0.1);    
}

function setInitialValues(thisElement, side)
{
    if(side =="left")
    {
        //IE
        if (thisElement.parentNode.nextSibling.nodeName == "DIV") {
            totalThumbnails = thisElement.parentNode.nextSibling.firstChild.childNodes.length;
        }
        //FF
        else {            
            totalThumbnails = 0;
            //Counting real childNodes
            for (j = 0; j < thisElement.parentNode.next().firstDescendant().childNodes.length; j++) {
                if (thisElement.parentNode.next().firstDescendant().childNodes[j].nodeName == "A") {
                    totalThumbnails++;
                }
            }            
        }
        
        totalWidth = (totalThumbnails * 75);  //+ 21; //70 = 50px width of the image plus a 20px margin (see css for thumbnail).        
    }
    else
    {
        //IE
        if (thisElement.parentNode.previousSibling.nodeName == "DIV") {
            totalThumbnails = thisElement.parentNode.previousSibling.firstChild.childNodes.length;
        }
        //FF
        else {            
            totalThumbnails = 0;
            //Counting real childNodes            
            for (j = 0; j < thisElement.parentNode.previous().firstDescendant().childNodes.length; j++) {                
                if (thisElement.parentNode.previous().firstDescendant().childNodes[j].nodeName == "A") {
                    totalThumbnails++;
                }
            }            
        }
        
        totalWidth = (totalThumbnails * 75);  //+ 21; //70 = 50px width of the image plus a 20px margin (see css for thumbnail).                
    }
    xPos_limit = 0 - totalWidth + 220; //200px is the width of the limitThumbnails (see css) + 20px margin right.

    setInitial = true;

    if (side == "left") {
        moveThumbnailsLeft();
    }
    else {
        moveThumbnailsRight();
    }
}

function stopThumbnails() {
    clearTimeout(timerThumbnails);
}

/*:::::::::::::: Browse Articles Pagination ::::::::::::::*/
function previousPageArticles(thisElement) {
    $("aNextArticles").className = "nextPage";

    var totalBrowseArticlesPages;
    
    //IE
    if (thisElement.parentNode.previousSibling.nodeName == "DIV") {
        totalBrowseArticlesPages = thisElement.parentNode.previousSibling.childNodes.length;

        for (i = 0; i < totalBrowseArticlesPages; i++) {
            if (thisElement.parentNode.previousSibling.childNodes[i].className == "show") {
                //If it's not the first one
                if (i != 0) {
                    thisElement.parentNode.previousSibling.childNodes[i].className = "hide";
                    thisElement.parentNode.previousSibling.childNodes[i - 1].className = "show";

                    if (i == 1) {
                        $("aPrevArticles").className = "prevPage_off";
                    }

                    return;
                }
            }
        }
    }
    //FF
    else {
        totalBrowseArticlesPages = 0;
        //Counting real childNodes        
        for (j = 0; j < thisElement.parentNode.previous().childNodes.length; j++) {
            if (thisElement.parentNode.previous().childNodes[j].nodeName == "DIV") {
                totalBrowseArticlesPages++;
            }
        }        
        
        //If the first one isn't a DIV then start on the next one
        var startPosition = 0;

        while (thisElement.parentNode.previous().childNodes[startPosition].nodeName != "DIV") {
            startPosition++;
        }


        for (i = startPosition; i <= totalBrowseArticlesPages; i++) {
            
            if (thisElement.parentNode.previous().childNodes[i].className == "show") {
                
                //If it's not the first one
                if (i != startPosition) {                    
                    thisElement.parentNode.previous().childNodes[i].className = "hide";
                    thisElement.parentNode.previous().childNodes[i - 1].className = "show";

                    if (i == (startPosition+1)) {
                        $("aPrevArticles").className = "prevPage_off";
                    }

                    return;
                }                
            }
        }
    }    
}

function nextPageArticles(thisElement) {
    $("aPrevArticles").className = "prevPage";

    var totalBrowseArticlesPages;    

    //IE
    if (thisElement.parentNode.previousSibling.nodeName == "DIV") {
        totalBrowseArticlesPages = thisElement.parentNode.previousSibling.childNodes.length;
        
        for (i = 0; i < totalBrowseArticlesPages; i++) {
            if (thisElement.parentNode.previousSibling.childNodes[i].className == "show") {
                //If it's not the last one
                if (i != totalBrowseArticlesPages - 1) {
                    thisElement.parentNode.previousSibling.childNodes[i].className = "hide";
                    thisElement.parentNode.previousSibling.childNodes[i + 1].className = "show";

                    if (i == totalBrowseArticlesPages - 2) {
                        $("aNextArticles").className = "nextPage_off";
                    }

                    return;
                }
            }
        }
    }
    //FF
    else
    {        
        totalBrowseArticlesPages = 0;
        //Counting real childNodes        
        for (j = 0; j < thisElement.parentNode.previous().childNodes.length; j++) {
            if (thisElement.parentNode.previous().childNodes[j].nodeName == "DIV") {
                totalBrowseArticlesPages++;
                
            }
        }        

        for (i = 0; i < totalBrowseArticlesPages; i++) {
            
            if (thisElement.parentNode.previous().childNodes[i].className == "show") {
                
                thisElement.parentNode.previous().childNodes[i].className = "hide";
                thisElement.parentNode.previous().childNodes[i + 1].className = "show";

                if (i == totalBrowseArticlesPages - 1) {
                    $("aNextArticles").className = "nextPage_off";
                }

                return;
            }
        }
    }
}

/*:::::::::::::: Browse Case Studies Pagination ::::::::::::::*/
function previousPageCaseStudies(thisElement) {
    $("aNextCaseStudies").className = "nextPage";

    var totalBrowseCaseStudiesPages;
    
    //IE
    if (thisElement.parentNode.previousSibling.nodeName == "DIV") {
        totalBrowseCaseStudiesPages = thisElement.parentNode.previousSibling.childNodes.length;

        for (i = 0; i < totalBrowseCaseStudiesPages; i++) {
            if (thisElement.parentNode.previousSibling.childNodes[i].className == "show") {
                //If it's not the first one
                if (i != 0) {
                    thisElement.parentNode.previousSibling.childNodes[i].className = "hide";
                    thisElement.parentNode.previousSibling.childNodes[i - 1].className = "show";

                    if (i == 1) {
                        $("aPrevCaseStudies").className = "prevPage_off";
                    }

                    return;
                }
            }
        }
    }
    //FF
    else {
        totalBrowseCaseStudiesPages = 0;
        //Counting real childNodes        
        for (j = 0; j < thisElement.parentNode.previous().childNodes.length; j++) {
            if (thisElement.parentNode.previous().childNodes[j].nodeName == "DIV") {
                totalBrowseCaseStudiesPages++;
            }
        }

        //If the first one isn't a DIV then start on the next one
        var startPosition = 0;

        while (thisElement.parentNode.previous().childNodes[startPosition].nodeName != "DIV") {
            startPosition++;
        }

        for (i = startPosition; i <= totalBrowseCaseStudiesPages; i++) {
            if (thisElement.parentNode.previous().childNodes[i].className == "show") {
                //If it's not the first one
                if (i != startPosition) {
                    thisElement.parentNode.previous().childNodes[i].className = "hide";
                    thisElement.parentNode.previous().childNodes[i - 1].className = "show";

                    if (i == (startPosition+1)) {
                        $("aPrevCaseStudies").className = "prevPage_off";
                    }

                    return;
                }
            }
        }
    }    
}

function nextPageCaseStudies(thisElement) {
    $("aPrevCaseStudies").className = "prevPage";
    var totalBrowseCaseStudiesPages;

    //IE
    if (thisElement.parentNode.previousSibling.nodeName == "DIV") {
        totalBrowseCaseStudiesPages = thisElement.parentNode.previousSibling.childNodes.length - 1;

        for (i = 0; i < totalBrowseCaseStudiesPages; i++) {
            if (thisElement.parentNode.previousSibling.childNodes[i].className == "show") {
                //If it's not the last one
                if (i != totalBrowseCaseStudiesPages - 1) {
                    thisElement.parentNode.previousSibling.childNodes[i].className = "hide";
                    thisElement.parentNode.previousSibling.childNodes[i + 1].className = "show";

                    if (i == totalBrowseCaseStudiesPages - 2) {
                        $("aNextCaseStudies").className = "nextPage_off";
                    }

                    return;
                }
            }
        }
    }
    //FF
    else {

        totalBrowseCaseStudiesPages = 0;
        //Counting real childNodes        
        for (j = 0; j < thisElement.parentNode.previous().childNodes.length; j++) {
            if (thisElement.parentNode.previous().childNodes[j].nodeName == "DIV") {
                totalBrowseCaseStudiesPages++;

            }
        }
        totalBrowseCaseStudiesPages--;      
        
        for (i = 0; i < totalBrowseCaseStudiesPages; i++) {

            if (thisElement.parentNode.previous().childNodes[i].className == "show") {
                            
                thisElement.parentNode.previous().childNodes[i].className = "hide";
                thisElement.parentNode.previous().childNodes[i + 1].className = "show";

                if (i == totalBrowseCaseStudiesPages - 1) {
                    $("aNextCaseStudies").className = "nextPage_off";
                }

                return;
            }
        }
    }
}

/*:::::::::::::: Items (Concerns/Questions) Pagination ::::::::::::::*/
function previousPageItems(thisElement) {

    var totalItemsPages;
    
    //IE
    if (thisElement.nextSibling.nodeName == "A") {
        thisElement.nextSibling.className = "nextPage";
        totalItemsPages = thisElement.parentNode.previousSibling.childNodes.length;

        for (i = 0; i < totalItemsPages; i++) {
            if (thisElement.parentNode.previousSibling.childNodes[i].className == "show") {
                //If it's not the first one
                if (i != 0) {
                    thisElement.parentNode.previousSibling.childNodes[i].className = "hide";
                    thisElement.parentNode.previousSibling.childNodes[i - 1].className = "show";

                    if (i == 1) {
                        thisElement.className = "prevPage_off";
                    }

                    return;
                }
            }
        }
    }
    //FF
    else {
        thisElement.next().className = "nextPage";        

        totalItemsPages = 0;
        //Counting real childNodes        
        for (j = 0; j < thisElement.parentNode.previous().childNodes.length; j++) {
            if (thisElement.parentNode.previous().childNodes[j].nodeName == "DIV") {
                totalItemsPages++;
            }
        }

        //If the first one isn't a DIV then start on the next one
        var startPosition = 0;

        while (thisElement.parentNode.previous().childNodes[startPosition].nodeName != "DIV") {
            startPosition++;
        }

        for (i = startPosition; i <= totalItemsPages; i++) {
            if (thisElement.parentNode.previous().childNodes[i].className == "show") {
                //If it's not the first one
                if (i != startPosition) {
                    thisElement.parentNode.previous().childNodes[i].className = "hide";
                    thisElement.parentNode.previous().childNodes[i - 1].className = "show";

                    if (i == (startPosition+1)) {
                        thisElement.className = "prevPage_off";
                    }

                    return;
                }
            }
        }
    }    
}

function nextPageItems(thisElement) {

    var totalItemsPages;
    
    //IE
    if (thisElement.previousSibling.nodeName == "A") {
        thisElement.previousSibling.className = "prevPage";
        totalItemsPages = thisElement.parentNode.previousSibling.childNodes.length;
        
        for (i = 0; i < totalItemsPages; i++) {
            if (thisElement.parentNode.previousSibling.childNodes[i].className == "show") {
                
                //If it's not the last one
                if (i != totalItemsPages - 1) {
                    thisElement.parentNode.previousSibling.childNodes[i].className = "hide";
                    thisElement.parentNode.previousSibling.childNodes[i + 1].className = "show";

                    if (i == totalItemsPages - 2) {
                        thisElement.className = "nextPage_off";
                    }

                    return;
                }
            }
        }
    }
    //FF
    else {
        thisElement.previous().className = "prevPage";        

        totalItemsPages = 0;
        //Counting real childNodes        
        for (j = 0; j < thisElement.parentNode.previous().childNodes.length; j++) {
            if (thisElement.parentNode.previous().childNodes[j].nodeName == "DIV") {
                totalItemsPages++;
            }
        }
        
        for (i = 0; i < totalItemsPages; i++) {
            if (thisElement.parentNode.previous().childNodes[i].className == "show") {

                thisElement.parentNode.previous().childNodes[i].className = "hide";
                thisElement.parentNode.previous().childNodes[i + 1].className = "show";

                if (i == totalItemsPages - 1) {
                    thisElement.className = "nextPage_off";
                }

                return;
            }
        }    
    }
}

/*:::::::::::::: Sniffer Pagination ::::::::::::::*/
function previousPageSniffer(thisElement) {
    $("aNextSnifferPage").className = "nextPage";

    var totalSnifferPages;

    totalSnifferPages = $(thisElement.id).ancestors()[0].previous().childElements().length;

    for (i = 0; i < totalSnifferPages; i++) {
        if ($(thisElement.id).ancestors()[0].previous().childElements()[i].className == "show") {
            //If it's not the first one
            if (i != 0) {
                $(thisElement.id).ancestors()[0].previous().childElements()[i].className = "hide";
                $(thisElement.id).ancestors()[0].previous().childElements()[i-1].className = "show";

                if (i == 1) {
                    $("aPrevSnifferPage").className = "prevPage_off";
                }

                return;
            }
        }
    }    
}

function nextPageSniffer(thisElement) {    
    $("aPrevSnifferPage").className = "prevPage";

    var totalSnifferPages;

    totalSnifferPages = $(thisElement.id).ancestors()[0].previous().childElements().length;

    for (i = 0; i < totalSnifferPages; i++) {        
        if ($(thisElement.id).ancestors()[0].previous().childElements()[i].className == "show") {
            //If it's not the last one
            if (i != totalSnifferPages - 1) {                
                $(thisElement.id).ancestors()[0].previous().childElements()[i].className = "hide";
                $(thisElement.id).ancestors()[0].previous().childElements()[i + 1].className = "show";

                if (i == totalSnifferPages - 2) {
                    $("aNextSnifferPage").className = "nextPage_off";
                }

                return;
            }
        }
    }    
}


/*:::::::::::::: Getting installed Silverlight ::::::::::::::*/

var silverlightversion;

if (Silverlight.isInstalled("2.0.31005")) {
    silverlightversion = "2.0.31005";  
}
else if (Silverlight.isInstalled("2.0.30523")) {
    silverlightversion = "2.0.30523";    
}
else if (Silverlight.isInstalled("1.0")) {
    silverlightversion = "1.0";    
}
else if (Silverlight.isInstalled("2.0")) {
    silverlightversion = "2.0";    
}

function updateSilverlightMessage() {   
    
    //If it is not the latest version
    if (silverlightversion != "2.0.31005") {
        //If it is an old version
        if (silverlightversion == "1.0" || silverlightversion == "2.0" || silverlightversion == "2.0.30523") {            
            if ($("divOldInstalled") != null && $("divSLNotInstalled") != null) {                
                $("divOldInstalled").show();
                $("divOldInstalledExtra").show();
                $("divDownloadBtn").show();                
            }
        }
        //If it is not installed
        else {            
            if ($("divOldInstalled") != null && $("divSLNotInstalled") != null) {
                $("divSLNotInstalled").show();                                                              
                $("divDownloadBtn").show();                
            }
        }        
    }
    //If latest is installed
    else {        
        if ($("divlblContent")!=null) {
            $("divlblContent").show();
        }

        //Show whiteBox
        if ($("whiteBoxHero") != null) {            
            $("titleHero").show();
            //$("contentTitle").show();
        }      
    }
}

function installLatestSilverlight() {
    Silverlight.getSilverlight('2.0');
}

/*:::::::::::::: Show/Hide showDropTabs ::::::::::::::*/

function showDropTabs() {
    //whoClicked = "viewDropTabs";
    
    /*if ($("dropTabs").style.display == "none") {
        $("dropTabs").show();
    }
    else {
        $("dropTabs").hide();
    } */
    $("dropTabs").show();
}

function hideDropTabs() {    
    /*if (whoClicked == "viewDropTabs") {
        whoClicked = "";
    }
    else {
        if ($("dropTabs") != null) {
            $("dropTabs").hide();    
        }        
    }*/
    if ($("dropTabs") != null) {
        $("dropTabs").hide();
    }
}

/*:::::::::::::: Client ID Values Flyouts ::::::::::::::*/

//divFlyout - PRB
var flyoutArticlesClientID;
var flyoutVideosClientID;
var flyoutDemosClientID;
var flyoutEventsClientID;
var flyoutOffersClientID;

//PanelFlyout - PRB
var pnlVideosClientID;
var pnlArticlesClientID;
var pnlDemosClientID;
var pnlEventsClientID;
var pnlOffersClientID;

//wraperRptr - PRB
var wraperRptrArticlesClientID;
var wraperRptrVideosClientID;
var wraperRptrDemosClientID;
var wraperRptrEventsClientID;
var wraperRptrOffersClientID;

//lnkBtnPrev - PRB
var lnkBtnPrevArticlesClientID;
var lnkBtnPrevVideosClientID;
var lnkBtnPrevDemosClientID;
var lnkBtnPrevEventsClientID;
var lnkBtnPrevOffersClientID;

//lnkBtnNext - PRB
var lnkBtnNextArticlesClientID;
var lnkBtnNextVideosClientID;
var lnkBtnNextDemosClientID;
var lnkBtnNextEventsClientID;
var lnkBtnNextOffersClientID;

//wraperRightElements - CC
//var wraperRightOffersClientID;

//To be set once the flyout has been chosen
var linkPrev;
var linkNext;
//--PRB
var totalArticles;
var totalVideos;
var totalDemos;
var totalEvents;
var totalElements;
//--CC
var totalOffers


/*:::::::::::::: Accordion Panes - PRB ::::::::::::::*/
var headerVideosClientID;
var headerArticlesClientID;
var headerDemosClientID;
var headerGraphClientID;
var headerContactsClientID;
var headerToolsClientID;
//var headerOffersPRBClientID;

/*:::::::::::::: Accordion Panes - PRB & CC ::::::::::::::*/
var headerEventsClientID;
var headerOffersClientID;

/*:::::::::::::: Accordion Panes - CC ::::::::::::::*/
var headerFindPartnerClientID;
var headerContactMicrosoftClientID;
var headerTalkTDMClientID;

function changeBackHeaders(site) {

    if (site == "prb") {
        if (headerVideosClientID != null && headerVideosClientID != "")
            $(headerVideosClientID).className = "tab";
        if (headerArticlesClientID != null && headerArticlesClientID != "")
            $(headerArticlesClientID).className = "tab";
        if (headerDemosClientID != null && headerDemosClientID != "")
            $(headerDemosClientID).className = "tab";
        if (headerGraphClientID != null && headerGraphClientID != "")
            $(headerGraphClientID).className = "tab";
        if (headerEventsClientID != null && headerEventsClientID != "")
            $(headerEventsClientID).className = "tab";
        if (headerContactsClientID != null && headerContactsClientID != "")
            $(headerContactsClientID).className = "tab";
        if (headerToolsClientID != null && headerToolsClientID != "")
            $(headerToolsClientID).className = "tab";
        if (headerOffersClientID != null && headerOffersClientID != "")
            $(headerOffersClientID).className = "tab";
    }
    //If CC
    else {
        if (headerFindPartnerClientID != null && headerFindPartnerClientID != "")
            $(headerFindPartnerClientID).className = "tab";
        if (headerContactMicrosoftClientID != null && headerContactMicrosoftClientID != "")
            $(headerContactMicrosoftClientID).className = "tab";
        if (headerTalkTDMClientID != null && headerTalkTDMClientID != "")
            $(headerTalkTDMClientID).className = "tab";
        if (headerEventsClientID != null && headerEventsClientID != "")
            $(headerEventsClientID).className = "tab";
        if (headerOffersClientID != null && headerOffersClientID != "")
            $(headerOffersClientID).className = "tab";        
    }    
}


/*:::::::::::::: Accordion Panes hero ::::::::::::::*/

var headerMainHeroClientID = "closeAllTabBtn";

function hideMainHeader() {
    $(headerMainHeroClientID).hide();
}

function showMainHeader() {
    $(headerMainHeroClientID).show();
    $(headerMainHeroClientID).parentNode.style.display = "block";
}

var headerHeroAccordionsString = "";
var headersAccordionArray;

var headersAccordionArray_default = "";
var headersAccordionArray_solutions = "";
var headersAccordionArray_proof = "";
var headersAccordionArray_resources = "";

function setHeaderArrays() {    
    switch (actualPage) {
        case "default":
            if (headersAccordionArray_default == "") {
                headersAccordionArray_default = headerHeroAccordionsString.split(";");
            }            
            break;

        case "solutions":
            if (headersAccordionArray_solutions == "") {
                headersAccordionArray_solutions = headerHeroAccordionsString.split(";");
            }            
            break;

        case "proof":
            if (headersAccordionArray_proof == "") {
                headersAccordionArray_proof = headerHeroAccordionsString.split(";");
            }            
            break;

        case "resources":
            if (headersAccordionArray_resources == "") {
                headersAccordionArray_resources = headerHeroAccordionsString.split(";");
            }            
            break;
    }
}

function changeBackHeadersHero() {       
    switch (actualPage) {
        case "default":
            headersAccordionArray = headersAccordionArray_default;            
            break;

        case "solutions":
            headersAccordionArray = headersAccordionArray_solutions;            
            break;

        case "proof":
            headersAccordionArray = headersAccordionArray_proof;            
            break;

        case "resources":
            headersAccordionArray = headersAccordionArray_resources;            
            break;
    }

    for (var i = 0; i < headersAccordionArray.length; i++) {
        $(headersAccordionArray[i]).className = "accordionTab";
    }    
}

function changeClassHeaderHero(thisElement, newClassName) {
    var actualClassName = thisElement.className;
    if (actualClassName != newClassName) {
        thisElement.className = newClassName;        
    }
}

function addHeaderID(newHeadersIDs) {
    headerHeroAccordionsString = newHeadersIDs;
    setHeaderArrays();
}

/*:::::::::::::: Show and Hide Flyouts ::::::::::::::*/

var target = ""; //Target to animate
var item; //Item to show and hide (target container)
var wraperRepeater; //Wraper that contains the repeater for the current flyout
var pageFlyout;
var widthFlyout = 520;
var heightFlyout = 450;
//var heightFlyout;
var pageposition;
var maxPagesFlyout;
var flyoutShown = false;
var headerAccordionOpened; //Header to set the top coordinate of the flyout

function showFlyout(type) {    
    whoClicked = "viewFlyout";
    
    setCurrentElements(type);
    
    if(item.style.display == 'block')
    {  
        animateHide();     
    }
    else
    {    
        setFlyout(type);
        item.show();        
        animateShow();
    }
    flyoutShown = true;  
}

function hideFlyout() {
    if (whoClicked == "viewFlyout" || whoClicked == "changePage") {
        whoClicked = "";
    }
    else {
        if (target != "") {
            animateHide();
            flyoutShown = false;         
        }
    }
}

function setCurrentElements(type)
{
    switch(type)
    {
        //----- PRB -----// 
        case "Articles":
            item = $(flyoutArticlesClientID);
            target = pnlArticlesClientID;
            headerAccordionOpened = headerArticlesClientID;
            totalElements = totalArticles;
            wraperRepeater = wraperRptrArticlesClientID;
            linkPrev = lnkBtnPrevArticlesClientID;
            linkNext = lnkBtnNextArticlesClientID;
            break;

        case "Videos":
            item = $(flyoutVideosClientID);
            target = pnlVideosClientID;
            headerAccordionOpened = headerVideosClientID;
            totalElements = totalVideos;
            wraperRepeater = wraperRptrVideosClientID;
            linkPrev = lnkBtnPrevVideosClientID;
            linkNext = lnkBtnNextVideosClientID;
            break;

        case "Demos":
            item = $(flyoutDemosClientID);
            target = pnlDemosClientID;
            headerAccordionOpened = headerDemosClientID;
            totalElements = totalDemos;
            wraperRepeater = wraperRptrDemosClientID;
            linkPrev = lnkBtnPrevDemosClientID;
            linkNext = lnkBtnNextDemosClientID;
            break;        

        //----- PRB & CC -----//
        case "Events":
            item = $(flyoutEventsClientID);
            target = pnlEventsClientID;
            headerAccordionOpened = headerEventsClientID;
            totalElements = totalEvents;
            wraperRepeater = wraperRptrEventsClientID;
            linkPrev = lnkBtnPrevEventsClientID;
            linkNext = lnkBtnNextEventsClientID;
            break;

        case "Offers":
            item = $(flyoutOffersClientID);
            target = pnlOffersClientID;
            headerAccordionOpened = headerOffersClientID;
            totalElements = totalOffers;
            wraperRepeater = wraperRptrOffersClientID;
            linkPrev = lnkBtnPrevOffersClientID;
            linkNext = lnkBtnNextOffersClientID;            
            break;
    }    
}

function setFlyout(type)
{
    //Initial values
    pageFlyout = 1;
    pageposition = 0;
    $(wraperRepeater).style.left = pageposition;  
        
    //Setting pagination   
    if(totalElements<=6)
    {
        $(linkNext).hide();
    }
    else
    {
        $(linkNext).show();
    }
    if(pageFlyout == 1)
    {
        $(linkPrev).hide();
    }
    else
    {
        $(linkPrev).show();
    }    
    
    //Setting Width and Height for the flyout
    var nbElementsVertical = 3;
    var nbElementsFlyout = nbElementsVertical*2;
                 
    var extra;
    
    if(totalElements%nbElementsFlyout)
    {
        extra = 1;
    }
    else
    {
        extra = 0;
    }
        
    maxPagesFlyout = Math.floor((totalElements/nbElementsFlyout) + extra);
    
    var totalWidth = maxPagesFlyout*widthFlyout;
    var totalHeight;

    //totalHeight = $("headlineWrap").offsetHeight + $("wraperRight" + type).offsetHeight + $("wraperViewAll" + type).offsetHeight + 10 + 11; //10 is the top margin + bottom margin on the View All wraper, 11 is for the controls class
        
    totalHeight = $("wraperRight" + type).offsetHeight - $("wraperViewAll" + type).offsetHeight - 5;
    if (isIE) {
        if (isIE7Min) {
            //nothing
        }
        else {
            totalHeight -= 12;
        }
    }

    //$(wraperRepeater).style.height = $("wraperRight" + type).offsetHeight - $("wraperViewAll" + type).offsetHeight - 5 + "px";

    $(wraperRepeater).style.height = totalHeight + "px";
    
    /*if (isPRB) {
        totalHeight = $("headlineWrap").offsetHeight + $("wraperRight" + type).offsetHeight + $("wraperViewAll" + type).offsetHeight + 10 + 11; //10 is the top margin + bottom margin on the View All wraper, 11 is for the controls class
        $(wraperRepeater).style.height = $("wraperRight" + type).offsetHeight - $("wraperViewAll" + type).offsetHeight - 5 + "px";
    }
    else {        
        totalHeight = $("headlineWrap").offsetHeight + $(wraperRightOffersClientID).offsetHeight + $("wraperViewAllElements").offsetHeight + 10 + 11; //10 is the top margin + bottom margin on the View All wraper, 11 is for the controls class
        $(wraperRepeater).style.height = $(wraperRightOffersClientID).offsetHeight - $("wraperViewAllElements").offsetHeight - 5 + "px";
    } */   
    
    $(wraperRepeater).style.width = totalWidth + "px";    
}

window.addEventListener?window.addEventListener("resize", moveFlyout, false):window.attachEvent("onresize", moveFlyout);

function moveFlyout()
{
    if ($(target) != null)
    {
        var flyout = $get(target);
        var header = $get(headerAccordionOpened);
        
        var pnlFlyout = Sys.UI.DomElement.getLocation(flyout);
        var headerLocation = Sys.UI.DomElement.getLocation(header);
    
        flyout.style.left = parseInt(headerLocation.x - 520 + 213, 10) + 'px';
    }
}

/*:::::::::::::: Pagination Flyouts ::::::::::::::*/
function previousPage()
{
    whoClicked = "changePage";
    if(pageFlyout>1)
    {
        pageFlyout --;
        pageposition += widthFlyout;
        $(wraperRepeater).style.left = pageposition + "px";
        if(pageFlyout==1)
        {
            $(linkPrev).hide();
        }
        $(linkNext).show();        
    }
}

function nextPage()
{
    whoClicked = "changePage";
    if(pageFlyout<maxPagesFlyout)
    {
        pageFlyout ++;
        pageposition -= widthFlyout;
        $(wraperRepeater).style.left = pageposition + "px";
        if(pageFlyout==maxPagesFlyout)
        {
            $(linkNext).hide();
        }
        $(linkPrev).show();        
    }
}


/*:::::::::::::: Animation Flyouts ::::::::::::::*/
var animation = null;

function animateShow() 
{
    var coordinatesHeader = $(headerAccordionOpened).cumulativeOffset();
    $(target).style.left = coordinatesHeader[0] + $(headerAccordionOpened).getWidth() + "px";
    var top = coordinatesHeader[1] - 2;
    $(target).style.top = top + "px";
    
    //$AA.MoveAnimation = function(target, duration, fps, horizontal, vertical, relative, unit)
    var animationMoveLeft = new $AA.MoveAnimation($get(target), 0.5, 10, -520, 0, true, "px");

    //$AA.ResizeAnimation = function(target, duration, fps, width, height, unit)
    var animationResizeMaximizeWidth = new $AA.ResizeAnimation($get(target), 0.5, 10, widthFlyout, 25, "px");

    //$AA.ParallelAnimation = function(target, duration, fps, animations)
    var animationMoveLeft_ResizeMaximizeWidth = new $AA.ParallelAnimation($get(target), 0.5, 10, [animationMoveLeft, animationResizeMaximizeWidth]);
    
    //$AA.ResizeAnimation = function(target, duration, fps, width, height, unit)
    var animationResizeMaximizeHeight = new $AA.ResizeAnimation($get(target), 0.5, 10, widthFlyout, heightFlyout, "px");

    //$AA.SequenceAnimation = function(target, duration, fps, animations, iterations)
    if (animation == null) {
        animation = new $AA.SequenceAnimation($get(target), 0.5, 10, [animationMoveLeft_ResizeMaximizeWidth, animationResizeMaximizeHeight], 1);
    }
    animation.play();    
    animation = null;
}

function animateHide() 
{
    if (flyoutShown) {
        //$AA.ResizeAnimation = function(target, duration, fps, width, height, unit)
        var animationResizeMinimizeHeight = new $AA.ResizeAnimation($get(target), 0.5, 10, widthFlyout, 0, "px");

        //$AA.MoveAnimation = function(target, duration, fps, horizontal, vertical, relative, unit)
        var animationMoveRight = new $AA.MoveAnimation($get(target), 0.5, 10, 520, 0, true, "px");

        //$AA.ResizeAnimation = function(target, duration, fps, width, height, unit)
        var animationResizeMinimizeWidth = new $AA.ResizeAnimation($get(target), 0.5, 10, 0, 25, "px");

        //$AA.ParallelAnimation = function(target, duration, fps, animations)
        var animationMoveLeft_ResizeMinimizeWidth = new $AA.ParallelAnimation($get(target), 0.5, 10, [animationResizeMinimizeWidth, animationMoveRight]);

        //$AA.SequenceAnimation = function(target, duration, fps, animations, iterations)
        if (animation == null) {
            animation = new $AA.SequenceAnimation($get(target), 0.5, 10, [animationResizeMinimizeHeight, animationMoveLeft_ResizeMinimizeWidth], 1);
        }
        animation.play();
        animation = null;
    }
}

/*
Download
*/

function openDownloadWindow(downloadPageUrl)
{
    window.open(downloadPageUrl, null, "height=20,width=400,left=100,top=100,status=no,toolbar=no,menubar=no,location=no", false);
}

/* survey assessment section */
function showAssessmentSurvey() {
    $("heroContainer").hide();
    $("assessmentWhitebox").hide();
    $("selfAssesmentSurvey").show();
}


/*:::::::::::::: Search bar ::::::::::::::*/

var locale;

function search(sender, eventArgs) {    
    //document.URL = "http://search.microsoft.com/results.aspx?mkt=en-US&setlang=en-US&q=" + $get("searchBox").value;
    //window.location = "http://search.microsoft.com/results.aspx?mkt=en-US&setlang=en-US&q=" + $get("searchBox").value;

    //window.open("http://search.microsoft.com/results.aspx?mkt=en-US&setlang=en-US&q=" + $get("searchBox").value);
    window.open("http://search.microsoft.com/results.aspx?mkt=" + locale + "&setlang=" + locale + "&q=" + $get("searchBox").value);
    $get("searchBox").value = "";
    return false;
}

function searchButtonPress(sender, eventArgs) {
    if (sender.rawEvent.keyCode == Sys.UI.Key.enter) {
        search(sender, eventArgs);
        return false;
    }
}

function checkKey(e) {
    var characterCode;

    if(e && e.which){ //if which property of event object is supported (NN4)
        e = e;
        characterCode = e.which;  //character code is contained in NN4's which property
    }
    else{
        e = event;
        characterCode = e.keyCode;  //character code is contained in IE's keyCode property
    }

    if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
        return false;
    }
    else{
        return true;
    }
}

/*:::::::::::::: Share Bar ::::::::::::::*/

function hideSharePopUp() {
    //alert(whoClicked);
    if ($("shareFlyout") != null) {
        if (whoClicked == "share") {
            whoClicked = "";
        }
        else {
            $("shareFlyout").hide();
        }
    }
}

/*:::::::::::::: History Points ::::::::::::::*/

var actualPage = "default";

function changeActualPage(newPage) {
    actualPage = newPage;

    /*if (actualPage == "proof" && isPRB) {
        updateSilverlightMessage();
    }*/
}

var userNavigated = true;

function addHistoryPoints(poid, ng) {
    userNavigated = false;
        
    var historyPoints =
        {
            "poid": poid,
            "ng": ng
        };

    Sys.Application.addHistoryPoint(historyPoints);
    userNavigated = true;
}

function onNavigate(sender, e) {
    var poid = e.get_state().poid;
    var ng = e.get_state().ng;
    
    //If back/forward button only
    if (userNavigated && (ng==actualPage)) {
        restoreState(poid);        
    }
}

//var accordionClientID = "ctl00_ctrlHeroPanel_ctl01_ctrlAccordionHero";
var accordionClientID;

function restoreState(poid) {

    if ($(accordionClientID) != null) {
        changeBackHeadersHero();
        $get(accordionClientID).AccordionBehavior.set_SelectedIndex(poid);
                
        if (poid > 0) {
            showMainHeader();
            $(headersAccordionArray[poid - 1]).className = "accordionTab_on";            
        }
    }
}

function setctrlAccordionHeroId(newClientID) {
    accordionClientID = newClientID;
}

/*:::::::::::::: Preloading images ::::::::::::::*/
var imgs = new Array();

//RightNav Over States
imgs[0] = "Common/img/rightnav_bg_base_last_on.gif";
imgs[1] = "Common/img/rightnav_bg_base_last_on.png";
imgs[2] = "Common/img/rightnav_bg_base_on.gif";
imgs[3] = "Common/img/rightnav_bg_base_on.png";
imgs[4] = "Common/img/rightnav_bg_on.gif";
imgs[5] = "Common/img/rightnav_bg_on.png";
imgs[6] = "Common/img/rightnav_bg_top_on.gif";
imgs[7] = "Common/img/rightnav_bg_top_on.png";

//Hero Accordion Header Over States
imgs[8] = "Common/img/hero_accordionTab_on.gif";
imgs[9] = "Common/img/hero_accordionTab_on.png";
imgs[10] = "Common/img/hero_accordionTab_on_base.gif";
imgs[11] = "Common/img/hero_accordionTab_on_base.png";
imgs[12] = "Common/img/hero_accordionTab_on_base_last.gif";
imgs[13] = "Common/img/hero_accordionTab_on_base_last.png";
imgs[14] = "Common/img/hero_accordionTab_on_top.gif";
imgs[15] = "Common/img/hero_accordionTab_on_top.png";

//Buttons overstates
imgs[17] = "Common/img/btn_blue_C_over.gif";
imgs[18] = "Common/img/btn_blue_C_over.png";
imgs[19] = "Common/img/btn_blue_L_over.gif";
imgs[20] = "Common/img/btn_blue_L_over.png";
imgs[21] = "Common/img/btn_blue_R_over.gif";
imgs[22] = "Common/img/btn_blue_R_over.png";
imgs[23] = "Common/img/btn_go_C_over.gif";
imgs[24] = "Common/img/btn_go_C_over.png";
imgs[25] = "Common/img/btn_go_L_over.gif";
imgs[26] = "Common/img/btn_go_L_over.png";
imgs[27] = "Common/img/btn_go_R_over.gif";
imgs[28] = "Common/img/btn_go_R_over.png";
imgs[29] = "Common/img/btn_go_C.gif";
imgs[30] = "Common/img/btn_go_C.png";
imgs[31] = "Common/img/btn_go_L.gif";
imgs[32] = "Common/img/btn_go_L.png";
imgs[33] = "Common/img/btn_go_R.gif";
imgs[34] = "Common/img/btn_go_R.png";
imgs[35] = "Common/img/btn_arrow_on.png";

function preload() {
    var tmp = null;

    //Preload images
    for (var i = 0; i < imgs.length; i++) {
        tmp = imgs[i];
        imgs[i] = new Image();
        imgs[i].src = tmp;
    }
}

void (preload());