﻿function getWindowHeight() {
	var windowHeight = 0;
	if (typeof (window.innerHeight) == 'number') {
		windowHeight = window.innerHeight;
	}
	else {

	    if (document.documentElement && document.documentElement.clientHeight) {
            windowHeight = document.documentElement.clientHeight;
		}
		else {
			if (document.body && document.body.clientHeight) {
                windowHeight = document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}
function getWindowWidth() {
	var windowWidth = 0;
	if (typeof(window.innerWidth) == 'number') {
	    // firefox scrollbar is 18px width
		windowWidth = window.innerWidth - 18;
	}
	else {
	    // internet explorer
		if (document.documentElement && document.documentElement.clientWidth) {
			windowWidth = document.documentElement.clientWidth;
		}
		else {
			if (document.body && document.body.clientWidth) {
				windowWidth = document.body.clientWidth;
			}
		}
		windowWidth-=  1;
	}
	return windowWidth;
}
function SetFooter() {
    if (document.getElementById) {
        var windowHeight = getWindowHeight();
        var bodyElement = document.getElementById('Content');
        var bodyHeight = bodyElement.offsetHeight;
        var headerElement = document.getElementById('Header');
        var footerElement = document.getElementById('Footer');
        var middleElement = document.getElementById('Content');
        var footerHeight = footerElement.offsetHeight;
        var headerHeight = headerElement.offsetHeight;
        var originalBodyHeight = bodyHeight;

        if (bodyHeight > 0) {
            originalBodyHeight = bodyHeight;
            bodyHeight = windowHeight - (headerHeight + footerHeight + 24 + 18); //adding menu and breadcrumbs' height
        }
        else {
            bodyHeight += windowHeight - (headerHeight + footerHeight + 24 + 18); //adding menu and breadcrumbs' height
        }

        //home page
        //alert("body height is " + bodyHeight + " and window height is " + windowHeight);
        if (bodyHeight + headerHeight + footerHeight <= windowHeight && originalBodyHeight == 0) {
            if (document.getElementById('FeaturedCategory')) {
                middleElement.style.height = (windowHeight - footerHeight - headerHeight - 195) + "px";
            }
            else {
                middleElement.style.height = (windowHeight - footerHeight - headerHeight - 318) + "px"

                if (document.getElementById('ctl00_phlStaffMenu_ctl00_lblStaffFullName')) {
                    middleElement.style.height = (windowHeight - footerHeight - headerHeight - 347) + "px"
                }
            }
            //alert("bodyHeight " + windowHeight + ", headerHeight " + headerHeight + ", footerHeight " + footerHeight + " = " + middleElement.style.height)
            //alert("middleElement" + middleElement.offsetHeight);

            
        }
        else {
                if(navigator.appName == "Microsoft Internet Explorer" && (navigator.appVersion.indexOf("MSIE 7.0") > 0)) {

                    if (originalBodyHeight > 420) {
                        middleElement.style.height = (originalBodyHeight) + "px"
                    }
                    else {
                        middleElement.style.height = (originalBodyHeight + 41) + "px"

                        if (document.getElementById('ctl00_phlStaffMenu_ctl00_lblStaffFullName')) {
                            middleElement.style.height = (originalBodyHeight + 12) + "px"
                        }
                    }

                    if (document.getElementById('ctl00_phlMainContent_pnlStatus')) {
                        middleElement.style.height -= 60 + "px";
                    }
                    
                }
        }
    }
}
function SetMainRightWidth() {

    var BodyWidth = getWindowWidth();

    var LeftContentElement = document.getElementById('PublicLeftContent');
    var MainRightContentElement = document.getElementById('PublicMainRightContent');
    
    var LeftContentWidth = LeftContentElement.offsetWidth;
    
    //alert("bodyWidth: " + BodyWidth + " Left: " + LeftContentWidth)
    
    MainRightContentElement.style.width = (BodyWidth - LeftContentWidth) + "px";	
}
function SetBorderHeights()
{
    /*
    - Enforces min height
    - Adjusts the height of left, main, and right section of the page to be the same.
    */

    var arrContainerNames = new Array("FeaturedCategory", "FeaturedCaseStudy", "StaticHomePageText");

    var intMininumHeightAllowed = 0;
    var intMinimumHeight = intMininumHeightAllowed; // the mininum height out of the three sections
    var intMaximumHeight = intMininumHeightAllowed; // the maximum height out of the three sections

    for(i=0;i<arrContainerNames.length;i++)
    {
        var obj = document.getElementById(arrContainerNames[i]);
        if(obj != null)
        {
            var intCurrentHeight = obj.offsetHeight;
            //alert(intCurrentHeight);
            
            // find minimum height
            if(intCurrentHeight > intMininumHeightAllowed // must be at least greater than the height allowed
                && intCurrentHeight < intMinimumHeight)
            {
                intMinimumHeight = intCurrentHeight;
            }
            
            // find maximum height
            if(intCurrentHeight > intMaximumHeight)
            {
                intMaximumHeight = intCurrentHeight;
            }
        }
    }

    // by now, min and max height are found    

    for(i=0;i<arrContainerNames.length;i++)
    {
        var obj = document.getElementById(arrContainerNames[i]);
        if(obj != null)
        {
            obj.style.height = intMaximumHeight + "px";
            //alert(arrContainerNames[i] + intMaximumHeight);
        }
    }    
}
