﻿// WARN ON LEAVE CODE
function warn_on_leave(site)
{
    var msg = "\nLinks which take you out of Abbott Laboratories worldwide \n"+
    "web site are not under the control of Abbott Laboratories, \n"+
    "and Abbott Laboratories is not responsible for the contents \n"+
    "of any such site or any further links from such site. Abbott \n"+
    "Laboratories is providing these links to you only as a \n"+
    "convenience, and the inclusion of any link does not imply \n"+
    "endorsement of the linked site by Abbott Laboratories.\n\n"+
    "Do you wish to leave this site?";
    
    if (confirm(msg))
    {
        window.open(site);
    }
    else
    {
        return;
    }
}

function SetMinimumPageHeight()
{
    var currentHeight = $("div.fade_height").outerHeight();

    if(currentHeight < 706)
    {
        if($.browser.msie && $.browser.version < 7)
        {
            $("div.fade_height").css("height", "706px");
        }
        else
        {
            $("div.fade_height").css("min-height", "706px");
        }
    }    
    
    //check if not on homepage
    if($("div#main_content_area").length > 0)
    {
        var mainAreaHeight = $("div#main_content_area").outerHeight();

        if(mainAreaHeight < 606)
        {
            if($.browser.msie && $.browser.version < 7)
            {
                $("div#main_content_area").css("height", "606px");
            }
            else 
            {
                $("div#main_content_area").css("min-height", "606px");
            }       
        }
    }   
    
}

//height SHOULD NOT include and top/bottom padding on the div
function SetMinimumContainerHeight(container, height)
{
    var jQueryID = "#" + container;

    var currentHeight = $(jQueryID).outerHeight();

    if (currentHeight < height)
    {
        if ($.browser.msie && $.browser.version < 7)
        {
            $(jQueryID).css("height", height + "px");
        }
        else 
        {
            $(jQueryID).css("min-height", height + "px");
        }
    }
}


/* product explorer functions */

function ToggleProductExplorerCategory(id)
{
    // see if clicked item is open item
    var selected = $(id).hasClass("selected");
    
    if(selected)
    {
        $(id).find("ul.items").slideUp();
        $(id).removeClass("selected");
    }
    else
    {
        // close open item
        var currentlyOpen = $(id).parent().find("li.selected");
        $(currentlyOpen).find("ul.items").slideUp();
        $(currentlyOpen).removeClass("selected");
        
        $(id).addClass("selected");        
        $(id).find("ul.items").slideDown();
    }    
}

/* end product explorer functions */

function ToggleFAQItem(id)
{
    var jQueryID = "#" + id;

    $(jQueryID).slideToggle();
}

function ShowChampionOverlay(id)
{
    var overlayContainer = "div#thumbnails";
    
    var containerWidth = $(overlayContainer).outerWidth();
    var containerHeight = $(overlayContainer).outerHeight();
        
    var overlay = "div#champion_overlay_container";
    var popup_content = "#" + id + " > div.popup_bio_content";
    var newContent = $(popup_content).clone(true);
        
    $(overlay).html(newContent);    

    var overlayWidth = $(overlay).outerWidth();
    var overlayHeight = $(overlay).outerHeight();
   
    var leftPos = (containerWidth / 2) - (overlayWidth / 2);
    var topPos = (containerHeight / 2) - (overlayHeight / 2);
    
    $(overlay).css("left", leftPos + "px");
    $(overlay).css("top", topPos + "px");
        
    $(overlay).show();
}

function CloseChampionOverlay()
{
    var overlay = "div#champion_overlay_container";
    
    if($(overlay).css("display") == "block")
    {
        $(overlay).hide();
    }
}

function ChangePage(page, maxPage)
{
    var pagesToShow = 5;
    var hiddenCssClass = "hidden";
    var edgeButtonClass = "edge_button";
    var currentPageCssClass = "current";

    //determine which elements need to be visible   
    $("ul#paging > li").addClass(hiddenCssClass);
    
    var pageSelector = "ul#paging > li:not(\"." + edgeButtonClass + "\")";
    
    $(pageSelector).filter(function(index) {

        if(page < pagesToShow - 2)
        {
            return index < pagesToShow;
        }
        
        if(page > maxPage - pagesToShow + 2)
        {
            return index > maxPage - pagesToShow;
        }

        if(index >= page - 2 && index <= page + 2) 
        {
            return true;
        }
        else
        {
            return false;
        }
    }).removeClass(hiddenCssClass);

    if(page > 0)
    {
        $("#page-first").removeClass(hiddenCssClass);
        $("#page-previous").removeClass(hiddenCssClass);
    }
    
    if(page < maxPage)
    {
        $("#page-last").removeClass(hiddenCssClass);
        $("#page-next").removeClass(hiddenCssClass);
    }    
    
    $("ul#paging li").removeClass(currentPageCssClass);

    var currentPagejQuerySelector = "li#page-" + page;
    $(currentPagejQuerySelector).addClass(currentPageCssClass);        
    
    //remove right margin from last shown button
    $("ul#paging li").removeClass("last_button");
    $("ul#paging li:not('.hidden'):last").addClass("last_button");
    
    //make sure changing page hasn't shrunk main area
    SetMinimumPageHeight();
    
    SetPagingUrl(page);
}

//variables for paging url parameters
var pagingUrlPrefix = "#pg-";
var pageNumRegex = "#pg-[0-9]+$"

function SetPagingUrl(pageNum)
{
    var currentUrl = window.location.toString();    
    var currentPageAnchor = pagingUrlPrefix + (pageNum + 1);
    
    if(currentUrl.match(pageNumRegex) != null)
    {
        var regexObj = new RegExp(pageNumRegex);
    
        window.location = currentUrl.replace(regexObj, currentPageAnchor);
    }
    else
    {
        var newUrl = currentUrl + currentPageAnchor;
    
        window.location = newUrl;
    }
}

function ReadPagingUrl()
{
    var currentUrl = window.location.toString();
    
    if(currentUrl.match(pageNumRegex) != null)
    {
        var p = currentUrl.match(pageNumRegex);
        
        var rVal = p[0].toString();
        
        var start = pagingUrlPrefix.length;
        
        // actual paging is zero-based
        // for cosmetic/url purposes, show 1-based in paging buttons and url 
        return (rVal.substring(start) - 1)        
    }
    else
    {
        return -1;
    }    
}

function AddPagingHoverEffects()
{
    $("ul#paging li").hover(
        function(){
            $(this).addClass("hover");
        },
        
        function()
        {
            $(this).removeClass("hover");
        }
    );
}

function ToggleTool(id)
{
    var jQueryID = "#" + id;
    
    var allToolsSelector = "div.tool_container:not(" + jQueryID + ")";
    
    $(allToolsSelector).slideUp();

    $(jQueryID).slideToggle();
}

function ToggleGuideSection(id)
{
    var jQueryID = "#" + id;

    $(jQueryID).slideToggle();
}
