﻿//<![CDATA[
function showHideSection(sender, sectionId, contentSectionId, toggleIndicator, highlightTableRow, innerTable)
{   
    if(innerTable)
    {
        var t = document.getElementById(innerTable);
        if(t && t.style && t.style.visibility == 'visible')
        {
            t.style.visibility = 'hidden';
        }
    }
    
    togglePanelAnimatedStatus(document.getElementById(contentSectionId), 25, 50, innerTable);
    if(sender && sender.innerHTML)
    {
        if(sender.innerHTML == 'hide')
        {
            document.cookie = 'DivisionInfoView=1;expires=' + new Date(new Date().getTime() + (90*1000*60*60*24)).toGMTString();
            sender.innerHTML = 'show';
        }
        else if(sender.innerHTML == 'show')
        {
            document.cookie = 'DivisionInfoView=0;expires=' + new Date(new Date().getTime()-1).toGMTString();
            sender.innerHTML = 'hide';
        }
    }
    if(toggleIndicator)
    {
        var ti = document.getElementById(toggleIndicator);
        if(ti.src && ti.src.toLowerCase().indexOf('/general/images/silk/bullet_toggle_minus.png') >= 0)
        {
            ti.src = '/general/images/silk/bullet_toggle_plus.png';
        }
        else
        {
            ti.src = '/general/images/silk/bullet_toggle_minus.png';
        }
    }
    if(highlightTableRow)
    {
        var tr = document.getElementById(highlightTableRow);
        if(tr)
        {
            if(tr.className.indexOf('ActiveRow') >= 0)
                setTimeout('document.getElementById(\'' + highlightTableRow + '\').className = \'\';', 750);
            else
                setTimeout('document.getElementById(\'' + highlightTableRow + '\').className = \'ActiveRow\';', 50);
        }
    }
    return false;
}

// current animated collapsible panel content
var currentContent = null;

function togglePanelAnimatedStatus(content, interval, step, innerTable)
{
    // wait for another animated expand/collapse action to end
    if (currentContent==null)
    {
        currentContent = content;
        var expand = (content.style.display=="none");
        if (expand)
            content.style.display = "block";
        var max_height = content.offsetHeight;

        var step_height = step + (expand ? 0 : -max_height);
        //toggleChevronIcon(content);
                
        // schedule first animated collapse/expand event
        content.style.height = Math.abs(step_height) + "px";
        setTimeout("togglePanelAnimatingStatus("
            + interval + "," + step
            + "," + max_height + "," + step_height + ",'" + innerTable + "')", interval);
    }
}

function togglePanelAnimatingStatus(interval,step, max_height, step_height, innerTable)
{
    var step_height_abs = Math.abs(step_height);

    // schedule next animated collapse/expand event
    if (step_height_abs>=step && step_height_abs<=(max_height-step))
    {
        step_height += step;
        currentContent.style.height = Math.abs(step_height) + "px";
        setTimeout("togglePanelAnimatingStatus("
            + interval + "," + step
            + "," + max_height + "," + step_height + ",'" + innerTable + "')", interval);
    }
    // animated expand/collapse done
    else
    {
        if (step_height_abs<step)
            currentContent.style.display = "none";
        currentContent.style.height = "";
        currentContent = null;
        var t = document.getElementById(innerTable);
        if(t && t.style)
            t.style.visibility = 'visible';
    }
}
//]]>
