﻿$addHandler(window, "load", MaximiseContentPane);
$addHandler(window, "resize", MaximiseContentPane);

var HEADER_ID = "Header";
var FOOTER_ID = "Footer";
var CONTENT_PANE_ID = "MiddleContent";
var MINIMUM_HEIGHT = 600;
var PX = "px";
var AUTO = "auto";
var NUMBER = "number";

function MaximiseContentPane()
{
    var middleContent = $get(CONTENT_PANE_ID);
    
    middleContent.style.height = AUTO;
    
    var header = $get(HEADER_ID);
    var footer = $get(FOOTER_ID);
    
    var windowSize = GetWindowSize();    
    var totalHeight = middleContent.offsetHeight + header.offsetHeight + footer.offsetHeight;

    if (totalHeight < windowSize.height)
    {
        middleContent.style.height = (windowSize.height - header.offsetHeight - footer.offsetHeight) + PX;
    }
}

function GetWindowSize() 
{
  var windowWidth = 0, windowHeight = 0;
  
  if( typeof( window.innerWidth ) == NUMBER ) 
  {
    //Non-IE
    windowWidth = window.innerWidth;
    windowHeight = window.innerHeight;
  } 
  else if ( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
  {
    //IE 6+ in 'standards compliant mode'
    windowWidth = document.documentElement.clientWidth;
    windowHeight = document.documentElement.clientHeight;
  } 
  else if ( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 
  {
    //IE 4 compatible
    windowWidth = document.body.clientWidth;
    windowHeight = document.body.clientHeight;
  }
  
 return new Point(windowWidth, windowHeight);
}

function Point(w, h)
{
    this.width = w;
    this.height = h;
}