// JavaScript Document

sape.Utils.printObjectProps = function(whichObj, doRecurse, whichLevel) {
//accepts an object reference and an optional boolean
//traces out all properties/values of whichObj
//if doRecurse is true (default is false), it recurses into nested objects
//usage:
//sape.Utils.printObjectProps(someObject, [true/false]);
	if (whichLevel == undefined) {
		whichLevel = 0;
	}
	var dispPrefix = "";
	for (var i=0; i<whichLevel; i++) {
		dispPrefix = dispPrefix + "----";
	}

	var recursing = false;
	if (doRecurse != undefined) {
		recursing = doRecurse;
	}
	for (var curProp in whichObj) {
		curVal = eval("whichObj." + curProp);
		if (typeof(curVal) == "object") {
			if (recursing) {
				trace(dispPrefix + "recursing into: " + curProp + "(" + typeof(curVal) + ")");
				sape.Utils.printObjectProps(curVal, true, whichLevel + 1);
			}
		} else {
			trace(dispPrefix + curProp + ": " + curVal + "(" + typeof(curVal) + ")");
		}
	}
}

sape.Utils.trace = function (whichString) {
	if (document.getElementById('tForm') == "undefined" || document.getElementById('tForm') == undefined) {
		var divWidth = 608;
		var divHeight = 326;
		var docHeight = document.documentElement.clientHeight;
		var docWidth = document.documentElement.clientWidth;
		var formHolder = document.createElement('div');
		formHolder.id = "tFormHolder";
		formHolder.style.zIndex = "1000";
		formHolder.style.background = "#666666";
		formHolder.style.overflow = "hidden";
		formHolder.style.position = "absolute";
		formHolder.style.width = divWidth + "px";
		formHolder.style.height = divHeight + "px";
		formHolder.style.left = "20px";
//		formHolder.style.top = "20px";
//		formHolder.style.left = (docWidth - divWidth) + "px";
		formHolder.style.top = (docHeight - divHeight) + "px";
		formHolder.style.color = "#FFFFFF";
		formHolder.style.fontFamily = "Verdana";
		formHolder.style.fontSize = "11px";
		formHolder.style.fontWeight = "bold";
		formHolder.style.paddingTop = "2px";
		formHolder.style.textAlign = "center";
		formHolder.innerHTML = "Trace Window (<a href='javascript:trace.toggleWindow()' style='color:#FFFFFF'>toggle</a>)";
		formHolder.onmousedown = function (event) { sape.Utils.startDrag(event, this); };
		formHolder.onmouseup = function () { sape.Utils.stopDrag(this); };
		
		var form = document.createElement('form');
		formHolder.appendChild(form);
		form.id = "tForm";
		var field = document.createElement('textarea');
		form.appendChild(field);
		field.rows = 5;
		field.cols = 18;
		field.id = "tText";
		field.style.position = "absolute";
		field.style.left = "1px";
		field.style.top = "20px";
		field.style.width = "600px";
		field.style.height = "300px";
    
		document.body.appendChild(formHolder);
	}
		
	var theField = document.getElementById('tText');
	theField.value = theField.value + "\n" + whichString;
	theField.scrollTop = theField.scrollHeight;
}
sape.Utils.trace.toggleWindow = function () {
	var d = document.getElementById('tFormHolder');
	if (d.style.height == "18px") {
		d.style.height = "326px";
	} else {
		d.style.height = "18px";
	}
}
window.trace = sape.Utils.trace;

sape.Utils.startDrag = function(e, whichElem) {
	var curMouseLoc = sape.Utils.getMouseXY(e);
	var xOffset = curMouseLoc.x - whichElem.offsetLeft;
	var yOffset = curMouseLoc.y - whichElem.offsetTop;
	document.onmousemove = function(e) {
		var curMouseLoc = sape.Utils.getMouseXY(e);
		var newX = curMouseLoc.x - xOffset;
		var newY = curMouseLoc.y - yOffset;
		whichElem.style.left = newX + "px";
		whichElem.style.top = newY + "px";
	}
}

sape.Utils.stopDrag = function(whichElem) {
	document.onmousemove = null;
}

sape.Utils.getMouseXY = function(e) {
	//must have an event (e.g. click, mousedown, mousemove, etc.) passed to it
	var curLoc = {};
	if (isIE) {
		curLoc.x = event.clientX + document.body.scrollLeft;
		curLoc.y = event.clientY + document.body.scrollTop;
	} else {
		curLoc.x = e.pageX;
		curLoc.y = e.pageY;
	}
	return curLoc;
}


function sendPrintJob() {
	removeToolTip();
	window.print();
}
//generic utils

/*  Prototype JavaScript framework, version 1.3.1
 *  (c) 2005 Sam Stephenson <sam@conio.net>
 *
 *  THIS FILE IS AUTOMATICALLY GENERATED. When sending patches, please diff
 *  against the source tree, available from the Prototype darcs repository. 
 *
 *  Prototype is freely distributable under the terms of an MIT-style license.
 *
 *  For details, see the Prototype web site: http://prototype.conio.net/
 *
/*--------------------------------------------------------------------------*/

var Prototype = {
  Version: '1.3.1',
  emptyFunction: function() {}
}

var Class = {
  create: function() {
    return function() { 
      this.initialize.apply(this, arguments);
    }
  }
}

Function.prototype.bind = function(object) {
  var __method = this;
  return function() {
    __method.apply(object, arguments);
  }
}

function $() {
  var elements = new Array();

  for (var i = 0; i < arguments.length; i++) {
    var element = arguments[i];
    if (typeof element == 'string')
      element = document.getElementById(element);

    if (arguments.length == 1) 
      return element;

    elements.push(element);
  }

  return elements;
}

/**
  *
  *  Copyright 2005 Sabre Airline Solutions
  *
  *  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
  *  file except in compliance with the License. You may obtain a copy of the License at
  *
  *         http://www.apache.org/licenses/LICENSE-2.0
  *
  *  Unless required by applicable law or agreed to in writing, software distributed under the
  *  License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
  *  either express or implied. See the License for the specific language governing permissions
  *  and limitations under the License.
  **/

//-------------------- ricoEffects.js

/**
  *  Use the Effect namespace for effects.  If using scriptaculous effects
  *  this will already be defined, otherwise we'll just create an empty
  *  object for it...
 **/
if ( window.Effect == undefined )
    window.Effect = {};

Effect.SizeAndPosition = Class.create();
Effect.SizeAndPosition.prototype = {
   initialize: function(element, x, y, w, h, duration, steps, options) {
      this.element = $(element);
      this.x = x;
      this.y = y;
      this.w = w;
      this.h = h;
      this.duration		= duration;
      this.steps		= steps;
      this.totalSteps	= steps;
      this.options		= arguments[7] || {};

      this.sizeAndPosition();
	  
//	  return this
   },

   sizeAndPosition: function() {
      if (this.isStarting()) {
		  if (this.y > this.element.offsetTop) {
			this.direction = "down";
		  } else {
			this.direction = "up";
		  }
		  
		  if (this.direction == "up") {
			navMgr.divsHolder.style.height = navMgr.clippedNavHeight + "px";
		  }
		  
      } else if (this.isFinished()) {
		  if (this.direction == "down") {
			navMgr.divsHolder.style.height = navMgr.fullNavHeight + "px";
			initCloseInterval();
		  }
		  
         if(this.options.complete) this.options.complete(this);
         return;
      }

      if (this.timer)
         clearTimeout(this.timer);

      var stepDuration = Math.round(this.duration/this.steps) ;

      // Get original values: x,y = top left corner;  w,h = width height
      var currentX = this.element.offsetLeft;
      var currentY = this.element.offsetTop;
      var currentW = this.element.offsetWidth;
      var currentH = this.element.offsetHeight;
	  
      // If values not set, or zero, we do not modify them, and take original as final as well
      this.x = (this.x) ? this.x : currentX;
      this.y = (this.y) ? this.y : currentY;
      this.w = (this.w) ? this.w : currentW;
      this.h = (this.h) ? this.h : currentH;

      // how much do we need to modify our values for each step?
      var difX = this.steps >  0 ? (this.x - currentX)/this.steps : 0;
      var difY = this.steps >  0 ? (this.y - currentY)/this.steps : 0;
      var difW = this.steps >  0 ? (this.w - currentW)/this.steps : 0;
      var difH = this.steps >  0 ? (this.h - currentH)/this.steps : 0;

      this.moveBy(difX, difY);
      this.resizeBy(difW, difH);

      this.duration -= stepDuration;
      this.steps--;

      this.timer = setTimeout(this.sizeAndPosition.bind(this), stepDuration);
   },

   isStarting: function() {
      return this.steps == this.totalSteps;
   },

   isFinished: function() {
      return this.steps <= 0;
   },

   moveBy: function( difX, difY ) {
      var currentLeft = this.element.offsetLeft;
      var currentTop  = this.element.offsetTop;
      var intDifX     = parseInt(difX);
      var intDifY     = parseInt(difY);

      var style = this.element.style;
	  var newLeft, newTop;
      if ( intDifX != 0 ) {
		 newLeft = (currentLeft + intDifX)
         style.left = newLeft + "px";
	  }
      if ( intDifY != 0 ) {
		 newTop = (currentTop + intDifY);
         style.top  = newTop + "px";
	  }
	  
	  //modify the size of the divsHolder to hide/reveal the navigation
	  //note: this custom addition makes this sizeAndPosition function specific to this app
//	  trace("navMgr.clippedNavHeight: " + navMgr.clippedNavHeight);
	  if (newTop > navMgr.clippedNavHeight) {
		  navMgr.navBG.style.height = Math.max(newTop, navMgr.clippedNavHeight) + "px";
	  } else {
		  navMgr.navBG.style.height = navMgr.clippedNavHeight + "px";
	  }
   },

   resizeBy: function( difW, difH ) {
      var currentWidth  = this.element.offsetWidth;
      var currentHeight = this.element.offsetHeight;
      var intDifW       = parseInt(difW);
      var intDifH       = parseInt(difH);

      var style = this.element.style;
      if ( intDifW != 0 )
         style.width   = (currentWidth  + intDifW) + "px";
      if ( intDifH != 0 )
         style.height  = (currentHeight + intDifH) + "px";
   }
}


///
var navMgr = new Object();

function initAnimVars() {
	if (document.getElementById("navTableHolder") != undefined) {
		var l = navMgr.animLine = document.getElementById("topLine");
		var t = document.getElementById("navTable");
		navMgr.divsHolder = document.getElementById("navTableHolder");
		navMgr.navBG = document.getElementById("navBG");
		navMgr.navTable = document.getElementById("navTable");
		
		navMgr.animDur = 100;
		navMgr.animSteps = 10;
		navMgr.lineStartY = l.offsetTop;
		navMgr.fullNavHeight = t.offsetHeight + 15; //add some padding so we clear the bottom row of the table
		navMgr.clippedNavHeight = navMgr.divsHolder.offsetHeight;
		
		
		navMgr.navTable.domouseover = function () {
			setOpenTimer();
		}
		navMgr.navTable.domouseout = function () {
			setCloseTimer();
		}
		
		navMgr.navTable.onmouseover = navMgr.navTable.domouseover;
	}
}

function goDown() {
	clearTimeout(openTimer);
	if (navMgr.effect != undefined) {
		clearTimeout(navMgr.effect.timer);
		delete navMgr.effect;
	}
	var targetLineWeight = 4;
	//SAFARI ISSUE: the thicker lines gets messed up when it overlaps flash movies, so we default to 1 pixel stroke for safari
	if (isSafari == true) {
		targetLineWeight = 1;
	}
	navMgr.effect = new Effect.SizeAndPosition('topLine', null, navMgr.fullNavHeight, null, targetLineWeight, navMgr.animDur, navMgr.animSteps);

	navMgr.navTable.onmouseover = null;
	navMgr.navTable.onmouseout = navMgr.navTable.domouseout;
	document.onmousemove = getMouseXY;
}

function goUp(withSnap) {
	var sF = document.getElementById("searchField");
	sF.blur();
	
	clearCloseInterval();
	clearCloseTimer();
	document.onmousemove = null;
	navMgr.navTable.onmouseoout = null;
	navMgr.navTable.onmouseover = navMgr.navTable.domouseover;
	
	if (withSnap == true) {
		navMgr.divsHolder.style.height = navMgr.clippedNavHeight + "px";
		navMgr.navBG.style.height = navMgr.clippedNavHeight + "px";
		navMgr.animLine.style.height = "1px";
		navMgr.animLine.style.top = navMgr.lineStartY + "px";
	} else {
		if (navMgr.effect != undefined) {
			clearTimeout(navMgr.effect.timer);
			delete navMgr.effect;
		}
		navMgr.effect = new Effect.SizeAndPosition('topLine', null, navMgr.lineStartY, null, 1, navMgr.animDur, navMgr.animSteps);
	}
}

////
//functions for opening/closing navigation
var isIE = document.all ? true : false;
var isSafari = navigator.userAgent.indexOf("Safari") != -1;

// Temporary variables to hold mouse x-y <a href="http://www.ntsearch.com/search.php?q=pos&v=56">pos</a>.s
var curMouseX = 0;
var curMouseY = 0;
// Main function to retrieve mouse x-y <a href="http://www.ntsearch.com/search.php?q=pos&v=56">pos</a>.s
function getMouseXY(e) {
	if (isIE) {
		curMouseX = event.clientX + document.body.scrollLeft;
		curMouseY = event.clientY + document.body.scrollTop;
	} else {
		curMouseX = e.pageX;
		curMouseY = e.pageY;
	}
	return true
}
var openTimer;
var openWait = 100; //milliseconds; time to wait before opening the nav when user mouses on
function setOpenTimer() {
	document.onmousemove = getMouseXY;
	clearTimeout(openTimer);
	openTimer = setTimeout('checkToOpenNav()', openWait);
}

function clearOpenTimer() {
	clearTimeout(openTimer);
	document.onmousemove = null;
}

function checkToOpenNav() {
	var myLeftEdge = getPageOffsetLeft(navMgr.navBG);
	var myTopEdge = getPageOffsetTop(navMgr.navBG);
	var myRightEdge = myLeftEdge + navMgr.navBG.offsetWidth;
	var myBottomEdge = myTopEdge + navMgr.navBG.offsetHeight;
	
//	trace("bounding box (top, left, right, bottom): " + myTopEdge + ", " + myLeftEdge + ", " + myRightEdge + ", " + myBottomEdge);
//	trace("bounding box (width, height): " + navMgr.navTable.offsetWidth + ", " + navMgr.navTable.offsetHeight);
	
	var inXBounds = curMouseX >= myLeftEdge && curMouseX <= myRightEdge;
	var inYBounds = curMouseY >= myTopEdge && curMouseY <= myBottomEdge;
	var inBounds = inXBounds && inYBounds;
	if (inBounds == true) {
		goDown();
	} else {
		clearOpenTimer();
	}
}

function getPageOffsetTop (whichElem) {
	var tOffsetTop = 0;
	var curCount = 0;
	var curElem = whichElem;
	//we cap the while loop to avoid any possible infinite loops
	while (curElem.offsetParent && curCount < 99) {
		tOffsetTop += curElem.offsetTop;
		curElem = curElem.offsetParent;
		curCount++;
	}
	return tOffsetTop;
}

function getPageOffsetLeft (whichElem) {
	var tOffsetTop = 0;
	var curCount = 0;
	var curElem = whichElem;
	//we cap the while loop to avoid any possible infinite loops
	while (curElem.offsetParent && curCount < 99) {
		tOffsetTop += curElem.offsetLeft;
		curElem = curElem.offsetParent;
		curCount++;
	}
	return tOffsetTop;
}

var closeTimer;
var closeWait = 300; //milliseconds; time to wait before closing the nav when user mouses off
function setCloseTimer() {
	clearTimeout(closeTimer);
	closeTimer = setTimeout('checkToCloseNav()', closeWait);
}

function clearCloseTimer() {
	clearTimeout(closeTimer);
}

function checkToCloseNav() {
	var myLeftEdge = getPageOffsetLeft(navMgr.navBG);
	var myTopEdge = getPageOffsetTop(navMgr.navBG);
	var myRightEdge = myLeftEdge + navMgr.navBG.offsetWidth;
	var myBottomEdge = myTopEdge + navMgr.navBG.offsetHeight;

	var inXBounds = curMouseX >= myLeftEdge && curMouseX <= myRightEdge;
	var inYBounds = curMouseY >= myTopEdge && curMouseY <= myBottomEdge;
	var inBounds = inXBounds && inYBounds;
	if (inBounds == false) {
		goUp();
	} else {
		clearCloseTimer();
	}
}

var closeInterval;
var closeIntervalTime = 1000; //milliseconds; time to check whether the user has moved off of the nav
function initCloseInterval() {
	clearInterval(closeInterval);
	closeInterval = setInterval('checkToCloseNavOnTimeout()', closeIntervalTime);
}

function clearCloseInterval() {
	clearInterval(closeInterval);
}

function checkToCloseNavOnTimeout(e) {
	var myLeftEdge = getPageOffsetLeft(navMgr.navBG);
	var myTopEdge = getPageOffsetTop(navMgr.navBG);
	var myRightEdge = myLeftEdge + navMgr.navBG.offsetWidth;
	var myBottomEdge = myTopEdge + navMgr.navBG.offsetHeight;

	var inXBounds = curMouseX >= myLeftEdge && curMouseX <= myRightEdge;
	var inYBounds = curMouseY >= myTopEdge && curMouseY <= myBottomEdge;
	var inBounds = inXBounds && inYBounds;
	if (inBounds == false) {
		goUp();
	}
}

var queryString = new Object();
var pairs = window.location.search.substring(1).split("&");
for(var i = 0; i < pairs.length; i++) {
	var pos = pairs[i].indexOf('=');
	if (pos >= 0) {
		queryString[pairs[i].substring(0, pos)] = unescape(pairs[i].substring(pos + 1));
	}
}

function doLinkRowMouseOver() {
	this.style.backgroundColor = '#E9E9DC';
	this.myLink.style.color = '#000000';
}

function doLinkRowMouseOut() {
	this.style.backgroundColor = '';
	this.myLink.style.color = '';
}

function doLinkRowClick() {
	var isScriptLink = this.myHref.indexOf("javascript") != -1;
	if (isScriptLink == true) {
		eval(this.myHref); //trigger the link's javascript function
		resetLinkRows(this);
		this.onmouseover = null;
		this.onmouseout = null;
	} else {
		window.location.href= this.myHref;
	}
}

function resetLinkRows(excludeRow) {
	var rows = document.getElementsByTagName('tr');
	for (var i=0; i<rows.length; i++) {
		var curRow = rows[i];
		if (curRow.className == 'linkRow') {
			if (curRow != excludeRow) {
				curRow.style.backgroundColor = '';
				curRow.myLink.style.color = '';
			}
			curRow.onmouseover = doLinkRowMouseOver;
			curRow.onmouseout = doLinkRowMouseOut;
		}
	}
}

function initLinkRows() {
//	window._linkList = document.getElementById('linkList');
	var x = document.getElementsByTagName('tr');
	for (var i=0; i<x.length; i++) {
		if (x[i].className == 'linkRow') {
			x[i].onmouseover = doLinkRowMouseOver;
			x[i].onmouseout = doLinkRowMouseOut;
			x[i].onclick = doLinkRowClick;
			x[i].style.cursor = "pointer";
			
			x[i].myLink = x[i].getElementsByTagName('a')[0];
			x[i].myHref = x[i].getElementsByTagName('a')[0].href;
//			x[i].myLink.href = 'javascript:void(0);';
		}
	}
	
	var x = document.getElementsByTagName('div');
	for (var i=0; i<x.length; i++) {
		if (x[i].className == 'linkRowDiv') {
			x[i].onmouseover = doLinkRowMouseOver;
			x[i].onmouseout = doLinkRowMouseOut;
			x[i].onclick = doLinkRowClick;
			x[i].style.cursor = "pointer";
			
			x[i].myLink = x[i].getElementsByTagName('a')[0];
			x[i].myHref = x[i].getElementsByTagName('a')[0].href;
		}
	}
}

function initTopNavKeyEvents() {
	//enable "Enter" key to work for search form submissions
	var sF = document.getElementById("searchField");
	var enterKeyCode = 13; //Unicode key code value for the enter key
	sF.onkeyup = function(e) {
		var curKeyCode = e ? e.keyCode : event.keyCode;
		if (curKeyCode == enterKeyCode && sF.value != "") {
			doSearch();
		}
	}
}

function doSearch(whichSearchTerm) {
	var mysearchterm = whichSearchTerm != undefined ? whichSearchTerm : document.getElementById('searchField').value;
	var mySearchURL = '/Search.aspx?query=' + mysearchterm;
	top.location.href = mySearchURL;
}

function initTopNavLinks() {
	//SAFARI ISSUE: the mouseover causes rendering issues when links overlap flash movies, so we disable them for safari
	if (isSafari == false) {
		var x = document.getElementsByTagName('ul');
		for (var i=0; i<x.length; i++) {
			if (x[i].className == 'navItems') {
				for (var j=0; j<x[i].childNodes.length; j++) {
					var curItem = x[i].childNodes[j];
					if (curItem.getElementsByTagName) {
						curItem.onmouseover = doTopNavMouseOver;
						curItem.onmouseout = doTopNavMouseOut;
						curItem.onclick = doNavClick;
						curItem.style.cursor = "pointer";
						
						curItem.myLink = curItem.getElementsByTagName('a')[0];
						curItem.myURL = curItem.getElementsByTagName('a')[0].href;
					}
				}
			}
		}
	}
}

function doTopNavMouseOver() {
	this.style.backgroundColor = '#EEEEEE';
	this.myLink.style.color = '#000000';
}

function doTopNavMouseOut() {
	this.style.backgroundColor = '';
	this.myLink.style.color = '';
}

function doNavClick() {
	window.location.href= this.myURL;
}

function initExpandoLinks() {
	//attach an onclick handler to each expandoLink to show/hide the associated content
	//the seemingly extraneous nodeName checks are needed for firefox (it adds an extra text node for all elements)
	var x = document.getElementsByTagName('ul');
	for (var i=0; i<x.length; i++) {
		var curList = x[i];
		if (curList.className == 'expandoList') {
			for (var j=0; j<curList.childNodes.length; j++) {
				var curItem = curList.childNodes[j];
				if (curItem.nodeName == "LI") {
					for (var k=0; k<curItem.childNodes.length; k++) {
						var curLink = curItem.childNodes[k];
						if (curLink.nodeName == "A") {
							curLink.onclick = toggleContent;
						}
					}
				}
			}
		}
	}
}

function toggleContent() {
	//scope of this function is the link, which "this" refers to
	var curContentNode;
	var curParent = this.parentNode;
	for (var j=0; j<curParent.childNodes.length; j++) {
		var curItem = curParent.childNodes[j];
		if (curItem.nodeName == "P") {
			curContentNode = curItem;
			break;
		}
	}
	var curViz = curContentNode.style.display;
	if (curViz == "block") {
		this.style.fontWeight = "normal";
		curContentNode.style.display = "none";
	} else {
		this.style.fontWeight = "bold";
		curContentNode.style.display = "block";
	}
}

function toggleDirections(pCountry) {
	var d = document.getElementById("directionsHolder_" + pCountry);
	var l = document.getElementById("directionsLink");
	var curViz = d.style.display;
	if (curViz == "block") {
		l.innerHTML = sape.Strings.s001;
		d.style.display = "none";
	} else {
		l.innerHTML = sape.Strings.s002;
		d.style.display = "block";
	}
}

function init() {
	initAnimVars();
	initLinkRows();
	initTopNavLinks();
	initExpandoLinks();
	
	//these are set here as we need a constant reference point for expandToWindowHeight()
	if (document.getElementById('masterTable') != undefined) {
		window.masterBottom = document.getElementById('masterTable').offsetHeight;
		window.contentTableHeight = document.getElementById('contentTable').offsetHeight;
		
		expandToWindowHeight();
	}
}

function expandToWindowHeight() {
	//the variable window.doExpandWindow can be set to false in any document
	//in which we don't want the page to auto-scale to the browser height (e.g. client success)
	if (window.doExpandWindow == undefined) window.doExpandWindow = true;
	if (document.getElementById('masterTable') != undefined) {
		window.masterBottom = document.getElementById('masterTable').offsetHeight;
		window.contentTableHeight = document.getElementById('contentTable').offsetHeight;
	}	
	if ((doExpandWindow == true) && (masterBottom != undefined)) {

		var minHeight = 330;
		var docHeight = isIE == true ? document.documentElement.clientHeight : window.innerHeight;
		

		var bottomOffset = docHeight - masterBottom;
		bottomOffset = Math.max(bottomOffset, 0);
		
		var content_table = document.getElementById('contentTable');
		var newHeight = contentTableHeight + bottomOffset;
		newHeight = Math.max(newHeight, minHeight);
		content_table.style.height = newHeight + "px";
	}
}

window.onload = init;
//window.onresize = expandToWindowHeight;



function initIndexDropDown() {
	window.indexYears = getYearsArray();
	var d = document.getElementById("indexHeader");
	
	var hiddenInput = document.getElementById("ctrlIndexer_hidSelectedYear");
	var selYear = hiddenInput.value;
	d.innerHTML = 'Index - ' + selYear;
	
	//add arrow and init dropdown if there are multiple years available
	if (indexYears.length > 1) {
		d.innerHTML += '<img src="' + imgDir + 'index_arrow.gif" width="14" height="9" border="0" />';
		d.onclick = removeDropDown;
		d.onmouseover = doDropDownMouseOver;
		d.onmouseout = doDropDownMouseOut;
		d.style.cursor = "pointer";
	}
}


function doDropDownMouseOver(e) {
	var srcDiv = e ? e.target : event.srcElement;
	if (srcDiv.nodeName != "DIV") { //safari DOM exception
		srcDiv = srcDiv.parentNode;
	}
	
	var curDropDownList;
	if (srcDiv.id == "indexHeader") {
		curDropDownList = indexYears;
	} else if (srcDiv.id == "geoSelect") {
		curDropDownList = geoDropValues;
	}
	
	initDropDown(curDropDownList, srcDiv);
}

function doDropDownMouseOut() {
	initKillDropDown();
}

function loadIndex(e) {
	removeDropDown();
	
	var srcDiv = e ? e.target : event.srcElement;
	if (srcDiv.nodeName != "DIV") { //safari DOM exception
		srcDiv = srcDiv.parentNode;
	}
	var selectedYear = srcDiv.innerHTML;
	var hiddenInput = document.getElementById("ctrlIndexer_hidSelectedYear");
	
	var newYearSelected = selectedYear != hiddenInput.value;
	if(newYearSelected == true) {
		hiddenInput.value = selectedYear;
		document.forms[0].submit();
	}
}



function DropDown (whichProps) {
	this.targetParentElement = document.body;

	this.listItems = whichProps.list;
	this.dropAnchor = whichProps.elem;
	
	//default fonts, and exceptions
	this._fontWeight = "bold";
	this._fontSize = "12px";
	this.forceWidth = true;
	if (this.dropAnchor.id == "geoSelect") {
		this._fontWeight = "normal";
		this._fontSize = "10px";
		this.forceWidth = false;
		this.listItemFunc = loadGeography;
	} else {
		this.listItemFunc = loadIndex;
	}
	
	this.yOffset = 4; //padding between target element and dropdown
	this.dropDownWidth = this.dropAnchor.offsetWidth + 10;
	
	this.listPadding = 5; //space around text
	
	
	this.listItemXPadding = 0; //space on left/right of text
	//see if the dropAnchor div has an image inside it. if so, we assume it's an arrow and offset text from the edges by that much
	var imgColl = this.dropAnchor.getElementsByTagName('img');
	if (imgColl.length > 0) {
		this.listItemXPadding = imgColl[0].offsetWidth;
	}
	
	this.listItemYPadding = 1; //space above/below text
	this.dropDownTextWidth = this.dropDownWidth - (this.listItemXPadding * 2) - (this.listPadding * 2);
	
	this.drawList();
	this.placeDropDown();
	
	return this;
}

DropDown.prototype.drawList = function() {
	var container = document.createElement('div');
	container.id = "dropDown";
	container.onmouseover = function () {
		clearTimeout(dropDownTimer);
	}
	container.onmouseout = function () {
		initKillDropDown();
	}
	with (container.style) {
		position = "absolute";
		top = "-300px";
		zIndex = "5000";
		display = "none";
	}
	this.dropDownDiv = container;
	
	this.listHolder = document.createElement('div');
	this.listHolder.id = "dropDownListHolder";
	with (this.listHolder.style) {
		position = "relative";
		zIndex = "100";
		backgroundColor = "#FFFFFF";
		padding = this.listPadding + "px";
		borderTop = "1px solid #CCCCCC";
		borderLeft = "1px solid #CCCCCC";
		borderRight = "1px solid #999999";
		borderBottom = "1px solid #999999";
	}
	
	for (var i=0; i<this.listItems.length; i++) {
		var curData = this.listItems[i];
		//use the first element of items when lists consist of arrays (e.g., geography values)
		if (typeof(curData) != "string") {
			curData = curData[0];
		}
		var curItem = document.createElement('div');
		var curZIndex = 100 + i;
		with (curItem) {
			id = "indexItem" + curData;
			innerHTML = curData;
			with (style) {
				position = "relative";
				zIndex = curZIndex;
				backgroundColor = "#FFFFFF";
				fontFamily = "Verdana, Arial, sans-serif";
				fontWeight = this._fontWeight;
				fontSize = this._fontSize;
				textAlign = "right";
				color = "#666666";
				paddingLeft = paddingRight = this.listItemXPadding + "px";
				paddingTop = paddingBottom = this.listItemYPadding + "px";
				if (this.forceWidth == true) {
					width = this.dropDownTextWidth + "px";
				}
				cursor = "pointer";
			}
//			trace("offsetWidth: " + offsetWidth);
		}
		curItem.onclick = this.listItemFunc;
		curItem.onmouseover = function() {
			this.style.backgroundColor = "#E0E0E0";
			this.style.color = "#333333";
		}
		curItem.onmouseout = function() {
			this.style.backgroundColor = "#FFFFFF";
			this.style.color = "#666666";
		}
		this.listHolder.appendChild(curItem);
	}
	
	this.shadow = document.createElement('div');
	this.shadow.id = "dropDownShadow";
	with (this.shadow.style) {
		position = "absolute";
		top = "3px";
		left = "3px";
		zIndex = "99";
		backgroundColor = "#D6D6D6";
		width = (this.dropDownWidth + 2) + "px";
	}
	
	container.appendChild(this.listHolder);
	container.appendChild(this.shadow);
	this.targetParentElement.appendChild(container);
	
	container.style.display = "block";
}

DropDown.prototype.placeDropDown = function() {
	var anchorBottom = getPageOffsetTop(this.dropAnchor) + this.dropAnchor.offsetHeight;
	var anchorRight = getPageOffsetLeft(this.dropAnchor) + this.dropAnchor.offsetWidth;
	var targetTop = anchorBottom + this.yOffset;
	var targetLeft = anchorRight - this.listHolder.offsetWidth + this.listPadding; // - (this.listHolder.offsetWidth - (this.listItemXPadding * 2));// - 2;
	
	this.dropDownDiv.style.top = targetTop + "px";
	this.dropDownDiv.style.left = targetLeft + "px";
	
	this.shadow.style.height = this.dropDownDiv.offsetHeight + "px";
	this.shadow.style.width = this.dropDownDiv.offsetWidth + "px";
}

DropDown.prototype.remove = function() {
	this.targetParentElement.removeChild(this.dropDownDiv);
}

window.dropDownWait = 300; //milliseconds to wait before showing
window.dropDownKillWait = 500; //milliseconds to wait before closing on mouseout
window.dropDownTimer = null;

function initKillDropDown() {
	clearTimeout(dropDownTimer);
	dropDownTimer = setTimeout(removeDropDown, dropDownKillWait);
}

function initDropDown(whichItems, whichElem) {
	clearTimeout(dropDownTimer);

	window.dropDownProps = {list: whichItems, elem: whichElem};
	dropDownTimer = setTimeout(showDropDown, dropDownWait);
}

function showDropDown() {
	removeDropDown();
	window.dropDown = new DropDown(dropDownProps);
}

function removeDropDown() {
	clearTimeout(dropDownTimer);
	if (window.dropDown != undefined) {
		window.dropDown.remove();
		window.dropDown = undefined;
	}
}
//DropDown functions


