
// JavaScript Document - only for new browsers - sets the dockable nav into a usuable position

/* Stack up window.onload event using this function from Simon Willison - http://www.sitepoint.com/blog-post-view.php?id=171578 */
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}
/* addLoadEvent events */
addLoadEvent(adjustLayout);
addLoadEvent(eventListener);


/*****************************************
CSS Positioning Helper Script Ensures
Left, Center and Right Columns
are resized to same height
******************************************/
function adjustLayout() {
	// Get natural heights
	var lHeight = xHeight("leftContent");
	var cHeight = xHeight("centerContent");
	var rHeight = xHeight("rightContent");

	// Find the maximum height
	var maxHeight = Math.max(lHeight, Math.max(cHeight,rHeight));
  
	// Assign maximum height to all columns
	xHeight("leftContent", maxHeight);
	xHeight("centerContent", maxHeight);
	xHeight("rightContent", maxHeight);
  
	// Show the footer
	xShow("pageFooter");
}
function eventListener() {
	xAddEventListener(window, "resize", adjustLayout, false);
}

function adjustHomepageLayout() {
	// Get natural heights
	var column1Height = xHeight("column1");
	var column2Height = xHeight("column2");
	var column3Height = xHeight("column3");
	var column4Height = xHeight("column4");


	// Find the maximum height
	var maxHeight = Math.max(column1Height, Math.max(column2Height, Math.max(column3Height, column4Height)));
  
	// Assign maximum height to all columns
	xHeight("column1", maxHeight);
	xHeight("column2", maxHeight);
	xHeight("column3", maxHeight);
	xHeight("column4", maxHeight);
	xHeight("columns", maxHeight);
  
	// Show the footer
	xShow("pageFooter");
}

/*****************************************
Simple Image Preloader and Helper
Function
******************************************/
function callPreLoader() {
	preLoadImages('/images/shared/mbt_left_both.gif', '/images/shared/mbt_right_both.gif','/images/shared/pht_left_both.gif', '/images/shared/pht_right_both.gif');
}
function preLoadImages() {
	var arrImages = new Array();
	var temp = preLoadImages.arguments;
	for(x=0;x<temp.length;x++) {
		arrImages[x] = new Image();
		arrImages[x].src = preLoadImages.arguments[x];
	}
}

/*****************************************
Cookie Handler - generic interface to read
info from a cookie
******************************************/
function readCookie(cookieName) {
  var docCookies = document.cookie;
  var startIndex = docCookies.indexOf(cookieName);
  if (startIndex == -1) return false;
  startIndex += cookieName.length + 1;
  var endIndex = docCookies.indexOf(";",startIndex);
  if (endIndex == -1) endIndex = docCookies.length;
  var cookieValue = docCookies.substring(startIndex, endIndex);
  return unescape(cookieValue);
}


/*****************************************
Email Page - open window and get parent
window location, store in hidden form
variable to be used by asp script
******************************************/
function emailPage() {

	var pageLocation = window.location;
	var pageTitle = document.title;

	var metaArray = document.getElementsByName('Description');
	var pageDescription
	for (var i=0; i<metaArray.length; i++) {

		if (metaArray[i].content != "undefined") {
			pageDescription += (metaArray[i].content);
		}
		
	}
	pageDescription = pageDescription.replace('undefined', '')

	var emailLink = 'mailto:?subject=' + pageTitle + '&body=Here\'s something you might be interested in:%0D%0A%0D%0A' + pageDescription + '%0D%0A%0D%0AURL: ' + pageLocation;

	var emailWin = window.open(emailLink);
}


/*****************************************
Open New Window - open window and get parent
window location, store in hidden form
variable to be used by asp script
******************************************/
function openWin(theURL) {
	window.open(theURL,'','width=800,height=600,resizable=yes,scrollable=yes,toolbar=yes,location=yes,status=yes,menubar=yes');
}
