﻿/*
=============================================================================
DESCRIPTION
Script to manage the sizing and location of the page footer.
It also ensures the page background fits the browser window.

Note: The usage of the iframe has been removed but the footer
still requires positioning.

HISTORY
Version    Date        By                    Modification
2009.1.0   2009-08-07  John Blair            Created
=============================================================================
*/



/***********************************************
* IFrame SSI script II- © Dynamic Drive DHTML code library (http://www.dynamicdrive.com)
* Visit DynamicDrive.com for hundreds of original DHTML scripts
* This notice must stay intact for legal use
***********************************************/

/*
//Input the IDs of the IFRAMES you wish to dynamically resize to match its content height:
//Separate each ID with a comma. Examples: ["myframe1", "myframe2"] or ["myframe"] or [] for none:
var iframeids = ["iframePageContent"];

//Should script hide iframe from browsers that don't support this script (non IE5+/NS6+ browsers. Recommended):
var iframehide = "yes";

var getFFVersion=navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1]
var FFextraHeight=parseFloat(getFFVersion)>=0.1? 16 : 0 //extra height in px to add to iframe in FireFox 1.0+ browsers

function resizeCaller() {
  var dyniframe = new Array()

  for (i = 0; i < iframeids.length; i++) {
    if (document.getElementById)
      resizeIframe(iframeids[i])
    //reveal iframe for lower end browsers? (see var above):
    if ((document.all || document.getElementById) && iframehide == "no") {
      var tempobj = document.all ? document.all[iframeids[i]] : document.getElementById(iframeids[i])
      tempobj.style.display = "block"
    }
  }
  //Re position the footer.
  resizeFooter();
}

function resizeIframe(frameid) {
  var currentfr = document.getElementById(frameid)
  if (currentfr && !window.opera) {
    currentfr.style.display = "block"
    if (currentfr.contentDocument && currentfr.contentDocument.body.offsetHeight) //ns6 syntax
      currentfr.height = currentfr.contentDocument.body.offsetHeight + FFextraHeight;
    else if (currentfr.Document && currentfr.Document.body.scrollHeight) //ie5+ syntax
      currentfr.height = currentfr.Document.body.scrollHeight;
    if (currentfr.addEventListener)
      currentfr.addEventListener("load", readjustIframe, false)
    else if (currentfr.attachEvent) {
      currentfr.detachEvent("onload", readjustIframe) // Bug fix line
      currentfr.attachEvent("onload", readjustIframe)
    }
  }
}

function readjustIframe(loadevt) {
  var crossevt = (window.event) ? event : loadevt
  var iframeroot = (crossevt.currentTarget) ? crossevt.currentTarget : crossevt.srcElement
  if (iframeroot)
    resizeIframe(iframeroot.id);
}

function loadintoIframe(iframeid, url) {
  if (document.getElementById)
    document.getElementById(iframeid).src = url
}
*/

/*
//	=============================================================================
//	DESCRIPTION
//	Resize the footer for IE and Firefox when the page is loaded or resized.
//
//	PARAMETERS
//
//	RETURN VALUE
//
//	HISTORY
//	Version    Date        By               Modification
//  2009.1.0   2009-08-07  John Blair       Created
//	=============================================================================
*/  

// Need footer to relocate when the user resizes the browser window.
if (window.addEventListener) {
  window.addEventListener("load", resizeFooter, false)
  window.addEventListener("resize", resizeFooter, false)
}
else if (window.attachEvent) {
window.attachEvent("onload", resizeFooter)
window.attachEvent("onresize", resizeFooter)
}
else {
  window.onload = resizeFooter
  window.onresize = resizeFooter
}



function resizeFooter() {
/*
//	=============================================================================
//	DESCRIPTION
//	Resize the footer for IE and Firefox.
//  Note: This method is being called from content html files and
//        should not be renamed.
//
//	PARAMETERS
//
//	RETURN VALUE
//
//	HISTORY
//	Version    Date        By               Modification
//  2009.1.0   2009-08-07  John Blair       Created
//  2009.1.1   2009-09-30  John Blair       Handle being called before page loaded
//                                          to accommodate spry widgets.
//	=============================================================================
*/  
  
  //Get the browser window height.
  var browserWindowHeight = typeof window.innerHeight != 'undefined' ? window.innerHeight : document.documentElement.clientHeight;
  
  //IE6: Following just gives the size of the body element which is not the height of the window.
  //var browserWindowHeight = typeof window.innerHeight != 'undefined' ? window.innerHeight : document.body.offsetHeight;

  //Get the heights for the body (banner, menu and content (iframe) ) i.e. all content except footer.
  var divBody = document.getElementById("body");
  if (divBody == null) 
  {
    //Resize method called before page loaded.
    return;
  }
  var divBodyHeight = divBody.offsetHeight;
  
  //Get the height of the footer.
  var divFooter = document.getElementById("footer");
  if (divFooter == null) 
  {
    //Resize method called before page loaded.
    return;
  }
  var divFooterHeight = divFooter.offsetHeight;

  //Make the "content" div at least the size of the window.
  //The content div contains the body div and the footer div.
  var divContent = document.getElementById("content");
  if (divContent == null) 
  {
    //Resize method called before page loaded.
    return;
  }
  
  if (browserWindowHeight < divBodyHeight + divFooterHeight) 
  {
    //Browser Window is smaller than content.
    //Don't absolute position footer i.e it will naturally locate below the body content.
    divFooter.className = "footerInline";
    divContent.style.height = "";
  }
  else 
  {
    //Content is less than window.
    //Extend the "content" to the size of the browser window - with 
    //footer absolutely positioned at the bottom of the browser.
    divFooter.className = "footer";
    //Use -1 below as a bottom border of 1px has been added to the "page" CSS class.
    divContent.style.height = browserWindowHeight -1 + "px"; 
  }

  // DEBUG: Display the heights of various page components in a new window.
  // This allows size comparison between different browsers.
  // debugPage();
}


function debugPage() {
  var w = window.open("Page Debug", "", "", "");
  w.document.open();
  
  var browserWindowHeight = typeof window.innerHeight != 'undefined' ? window.innerHeight : document.documentElement.clientHeight;
  w.document.write("<br/>browserWindow.Height:" + browserWindowHeight);
  
  var divBodyHeight = document.getElementById("body").offsetHeight;
  w.document.write("<br/>body.Height:" + divBodyHeight);
  
  //Internal Body Parts
  w.document.write("<br/>   divPageHeader.Height:" + document.getElementById("divPageHeader").offsetHeight);
  w.document.write("<br/>   divPageHeaderSubMenu.Height:" + document.getElementById("divPageHeaderSubMenu").offsetHeight);
  w.document.write("<br/>   divBodyContent.Height:" + document.getElementById("divBodyContent").offsetHeight);
  w.document.write("<br/>   divLeftColumn.Height:" + document.getElementById("divLeftColumn").offsetHeight);
  w.document.write("<br/>   divMiddleColumn.Height:" + document.getElementById("divMiddleColumn").offsetHeight);
  
  var divFooterHeight = document.getElementById("footer").offsetHeight;
  w.document.write("<br/>footer.Height:" + divFooterHeight);
  w.document.write("<br/>divFooterClassName:" + document.getElementById("footer").className);

  if (browserWindowHeight < divBodyHeight + divFooterHeight) {
    w.document.write("<br/>browserWindowHeight < divBodyHeight + divFooterHeight so expect footerInline class");
  }
  else {
    w.document.write("<br/>browserWindowHeight >= divBodyHeight + divFooterHeight so expect footer class ");
  }
  w.document.close();
}


