﻿    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 setFooter() {
	    if (document.getElementById) {
		    var windowHeight = getWindowHeight();
		    if (windowHeight > 0) {
		    
		        // Get the header height
		        var headerElement = document.getElementById('headerWrapper');
		        var headerHeight = headerElement.offsetHeight;
		      	
		      	// Get the Footer	        
		        var footerElement = document.getElementById('footerWrapper');
			    var footerHeight  = footerElement.offsetHeight;

                // Set the footer for all content Pages
			    if (document.getElementById('secondaryNav')) {
			        var secondaryNavElement = document.getElementById('secondaryNav');
			        var secondaryNavHeight = secondaryNavElement.offsetHeight;

			        if (document.getElementById('nav2xc')) {
			            var secondaryNavULElement = document.getElementById('nav2xc');
			            var secondaryNavULHeight = secondaryNavULElement.offsetHeight;
			        }
			        
			        if (document.getElementById('content')) {
			            var contentElement = document.getElementById('content');
			            var contentHeight = contentElement.offsetHeight;
			        }

			        if (document.getElementById('topBorder')) {
                        var topBorderElement = document.getElementById('topBorder');

                        topBorderElement.style.width = (document.body.clientWidth - 207);
                    }
                    
                    // Set the content width to be less then the side nav width and required space on right side of page
                    contentElement.style.width = (document.body.clientWidth - 275);
                                            
       		        if (windowHeight > (contentHeight + footerHeight + headerHeight + 80)) {
       		            if ( secondaryNavULHeight > ((windowHeight - headerHeight) - footerHeight)) {
		                    // Set the secondaryNav height when content div is shorter then windowheight
		                    secondaryNavElement.style.height = secondaryNavULHeight + 'px';
		                } else {
		                    secondaryNavElement.style.height = ((windowHeight - headerHeight) - footerHeight) + 'px';
		                }
		            }
		            else {
		                if (secondaryNavULHeight > (footerElement.offsetTop - headerHeight)) {
		                    // Set the secondaryNav height when content div is higher then windowheight
		                    secondaryNavElement.style.height = secondaryNavULHeight + 'px';
		                } else {
		                    secondaryNavElement.style.height = (footerElement.offsetTop - headerHeight) + 'px';
		                }
		            }
			    } else { // Set the footer for the home page 
       			    var contentWrapperElement = document.getElementById('contentWrapper');
    			    var contentWrapperheight = contentWrapperElement.offsetHeight;
                    var marginHeights = 0;

                    if (navigator.appName == "Microsoft Internet Explorer") {
                        marginHeights = 20;
                    } else {
                        marginHeights = 70;
                    }

			        if (windowHeight > (headerHeight + footerHeight + contentWrapperheight)) {
			            contentWrapperElement.style.height = (windowHeight - ((headerHeight + footerHeight) + marginHeights))  + 'px';
			        } else {
   			            contentWrapperElement.style.height = '580px';
			        }
			    }
		    }
	    }
    }

    window.onresize = function() {
	    setFooter();
    }
    
//    window.onload = function() {
//	    setFooter();
//    }