﻿//true after the first master pageLoad
var isMasterLoaded = false;
//the master_contentWrapper div located during pageLoad.
var master_contentWrapper = null;
//the master_content div located during pageLoad.
var master_content = null;
//the master_backToTop div located during pageLoad.
var master_backToTop = null;
//handles page loading
function pageLoad()
{
    if(!isMasterLoaded)
    {
        isMasterLoaded = true;
        //locate master_contentWrapper
        master_contentWrapper = $get("master_contentWrapper");
        //locate master_content
        master_content = $get("master_content");
        //locate master_backToTop
        master_backToTop = $get("master_backToTop");
        //adjust the height of master_body and wire up events that should trigger a resize
        $addHandler(window, "resize", master_resize);
        Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(pageLoaded);
    }
    master_AdjustHeights();
    //call contentPageLoad for any content pages that have defined it.
    if(typeof(contentPageLoad) === "function")
    {
        contentPageLoad();
    }
}
function pageLoaded(sender, args)
{
    master_AdjustHeights();
}
/*---------------------------------------------------------------------------------------------------------------------------------------------------------------*/
// adjust menu and content heights to max of viewport or actual content height
function master_AdjustHeights()
{
    var vOffset = Sys.UI.DomElement.getLocation(master_contentWrapper).y ;
    var height = Micro21.Web.UI.getViewPortSize().height - vOffset - Sys.UI.DomElement.getBounds(master_backToTop).height;
    var contentHeight = Sys.UI.DomElement.getBounds(master_content).height;
    height = Math.max(contentHeight, height);
    master_contentWrapper.style.height = height + "px";
}
//calls master_AdjustHeights based on the user's browser
function master_resize()
{
    //IE fires the resize event multiple times while browser is resizing; therefore, set a timer to call master_AdjustHeights
    //after 10ms allowing the multiple resize events to finish executing. For other browsers it is safe to immediately call
    //master_AdjustHeights since they fire the resize event after the browser has been resized.
    if(Sys.Browser.agent == Sys.Browser.InternetExplorer)
    {
        window.resizeEnd = (window.resizeEnd == null ) ? (new Object()) : window.resizeEnd;
        clearTimeout(window.resizeEnd);
        window.resizeEnd = setTimeout(master_AdjustHeights, 10);
    }
    else
    {
        master_AdjustHeights();
    }
}
//adds the handlers to collapsible panels to adjust the heights
function master_addCPEHandlers(cpe)
{
    if(cpe != null)
    {
       cpe.add_expandComplete(master_AdjustHeights);
       cpe.add_collapseComplete(master_AdjustHeights);
    }
}
//let the script manager know we've finished loading this script.
if (typeof(Sys) !== "undefined"){Sys.Application.notifyScriptLoaded();}
