﻿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 bodyHeight = document.getElementById('Content').offsetHeight;
		var headerElement = document.getElementById('Header');
		var footerElement = document.getElementById('Footer');
		var middleElement = document.getElementById('Content');
		var midContentElement = document.getElementById('ctl00_phlMainContent_pnlMainContent');
		var midContentElement2 = document.getElementById('ctl00_phlMainContent_pnlCategoryContent');
		var footerHeight  = footerElement.offsetHeight;
		var headerHeight = headerElement.offsetHeight;
		
		bodyHeight += headerHeight + footerHeight + 24 + 18 + 108; //adding menu, breadcrumbs and footer content' height
		if (bodyHeight <= windowHeight) {
		    if (document.getElementById('FeaturedCategory')) {
		        middleElement.style.height = (windowHeight - footerHeight - headerHeight - 184) + "px";
		    }
		    else 
		    {
		        middleElement.style.height = (windowHeight - footerHeight - headerHeight - 70) + "px"
		        
		        //midContentElement.style.height = (windowHeight - footerHeight - headerHeight - 260) + "px";
		        //midContentElement2.style.height = (windowHeight - footerHeight - headerHeight - 240) + "px";
            }
            //alert("bodyHeight " + windowHeight + ", headerHeight " + headerHeight + ", footerHeight " + footerHeight + " = " + middleElement.style.height)
            //alert("middleElement" + middleElement.offsetHeight);
		}
		else
		{
		}
	}
}
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);
        }
    }
}



function changeOpacity2(elementIDForOpcity) {
    var ClientWindowWidth = getWindowWidth();
    var BackgroundContainer = document.getElementById('theBackgroundContainer');
    var thisElement = document.getElementById(elementIDForOpcity);
    
    thisElement.style.filter = 'alpha(opacity=' + 0 + ')';
    thisElement.style.opacity = '.' + 0 + '';
    thisElement.style.display = 'block';
    BackgroundContainer.style.width = ClientWindowWidth + 'px';
    var actStep = 0;
    var intOpacityIncrement = 2;

    var elemwidthChangeMemInt = window.setInterval(
	function() {
	    intOpacityIncrement = intOpacityIncrement + 2;
	    
	    thisElement.style.filter = 'alpha(opacity=' + intOpacityIncrement + ')';
	    thisElement.style.opacity = '.' + intOpacityIncrement + '';
	    actStep++;
	    if (actStep > 30) window.clearInterval(elemwidthChangeMemInt);
	    
	}
	, 5)

}

function setBackgroundWidth() {
    var ClientWindowWidth = getWindowWidth();
    var ClientWindowHeight = getWindowHeight();
    var BackgroundContainer = document.getElementById('theBackgroundContainer');
    BackgroundContainer.style.width = ClientWindowWidth + 'px';
    //BackgroundContainer.style.height = (ClientWindowHeight - 20) + 'px';
}

function SetBackgroundWhenResize() {
    var ClientWindowWidth = getWindowWidth();
    var BackgroundContainer = document.getElementById('theBackgroundContainer');
    BackgroundContainer.style.width = '103.3%';

}
