var sTabContainerClientId = null;

function doResize() {
    if (typeof (sLeftMenuId) == 'undefined')
        return;
        
    var oContainer = document.getElementById('masterMaster');
    var oLeftMenu = document.getElementById(sLeftMenuId);
    var oRightMenu = document.getElementById(sRightMenuId);

    if (!(oLeftMenu) && !(oRightMenu))
        return;

    var oOmniFindContainer;
    if (sTabContainerClientId != null)
        oOmniFindContainer = document.getElementById(sTabContainerClientId);

    var oContent = document.getElementById('ConArea');
    if (oContent == null)
        oContent = document.getElementById(sContentAreaId);

    var iContentWidthAdjuster = 0;
    if (typeof (iContentWidthAdjust) != 'undefined')
        iContentWidthAdjuster = iContentWidthAdjust;

    var bOldBrowser = !(window.XMLHttpRequest);
    
    // if not IE7+, Safari 3, Firefox or Opera 9+ then set to fixed width
    if (bOldBrowser)
    {

    }

    // ensure content pane is maximum width it can be
    var iContentWidth = 506 - iContentWidthAdjuster;
    if (!(oLeftMenu))
        iContentWidth += 232;
    if (!(oRightMenu))
        iContentWidth += 232;

    oContent.style.width = iContentWidth + 'px';
    
    // ensure content pane is at least 10 pixels longer than the left and right menu
    if ((oLeftMenu) && (!(oRightMenu) || oLeftMenu.offsetTop == oRightMenu.offsetTop))
    {
        var iMaxHeight = 0;
        if (oRightMenu)
            iMaxHeight = Math.max(oLeftMenu.offsetHeight, oRightMenu.offsetHeight)
        else
            iMaxHeight = oLeftMenu.offsetHeight;
        
        if (oOmniFindContainer)
        {
            iMaxHeight = Math.max(iMaxHeight, oOmniFindContainer.offsetHeight + 100);
        }

        if (oContent.offsetHeight < iMaxHeight + 10)
        {
            iMaxHeight += 10;
            oContent.style.height = iMaxHeight + 'px'
        }
    }
    else if (oContent)
    {       
        oContent.style.height = 'auto';
    }
}

function initCabiDotOrgPages()
{
    doResize()
    
    var oHeader = document.getElementById('top_corporate');
    
    if (oHeader)
    {
        oHeader.onclick = headerClickToHome_Click;
        oHeader.onmouseover = headerClickToHome_MouseOver;
        oHeader.onmouseout = headerClickToHome_MouseOut;
    }
}

function headerClickToHome_Click()
{
    var sUrl = document.location.href;
    
    sUrl = document.location.href;
    
    if (sUrl.toLowerCase().indexOf('templates.aspx') == -1)
    {
        if (sUrl.indexOf('?') == -1)
            document.location.href = sUrl
        else
            document.location.href = sUrl.split('?')[0];
    }
    else
    {
        // extract site ID from parent document's location
        var iSiteId = sUrl.toLowerCase();
        iSiteId = iSiteId.substring(iSiteId.indexOf('site=') + 5);
        iSiteId = iSiteId.split('&')[0];

        document.location.href = 'templates.aspx?site=' + iSiteId + '&page=339';
    }
}

function headerClickToHome_MouseOver()
{
    document.getElementById('top_corporate').style.cursor = 'pointer';
}

function headerClickToHome_MouseOut()
{
    document.getElementById('top_corporate').style.cursor = 'default';
}

window.onload = initCabiDotOrgPages;

window.onresize = doResize;


