﻿
function togglePanelVisibility(panelid) {
    var ThePanel = document.getElementById(panelid);    
    if (ThePanel) {
        var expand = (ThePanel.style.display == "none");
        ThePanel.style.display = (expand ? "block" : "none");
        createCookie(panelid, ThePanel.style.display, 0);
    }
}

function togglePannelStatus(header, content, ScriptToRunOnExpand) {
    var expand = (content.style.display == "none");
    var isItalic;
    content.style.display = (expand ? "block" : "none");
    isItalic = (expand ? false : true);
    header.style.fontStyle = (isItalic ? "normal" : "italic");
    window.scrollBy(0, 150);
    createCookie(header.id, content.style.display, 0);
    if (expand && ScriptToRunOnExpand != '') {
        eval(ScriptToRunOnExpand);
    }
 }

// current animated collapsible panel content
var currentContent = null;

function togglePannelAnimatedStatus(header, content, ScriptToRunOnExpand, interval, step) {
    // wait for another animated expand/collapse action to end
    if (currentContent == null) {
        currentContent = content;
        var expand = (content.style.display == "none");
        var currentStyle = (header.style.fontstyle == "italic");

        if (expand) {
            content.style.display = "block";
            header.style.fontStyle = "italic";
            setTimeout("window.scrollBy(0, 150);", 1000);
        }
        else {
            header.style.fontStyle = "normal";
        }
        
        var max_height = content.offsetHeight;
        var step_height = step + (expand ? 0 : -max_height);
       
        // schedule first animated collapse/expand event
        content.style.height = Math.abs(step_height) + "px";
        setTimeout("togglePannelAnimatingStatus(" + interval + "," + step + "," + max_height + "," + step_height + ")", interval);
        if (expand && ScriptToRunOnExpand != '') {
            setTimeout("eval(ScriptToRunOnExpand);", 500);
        }      
    }
}

function togglePannelAnimatingStatus(interval, step, max_height, step_height) {
    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("togglePannelAnimatingStatus(" + interval + "," + step + "," + max_height + "," + step_height + ")", interval);
    }
    // animated expand/collapse done
    else {
        if (step_height_abs < step)
            currentContent.style.display = "none";
        currentContent.style.height = "";
        currentContent = null;
    }
}               

