//<!-- <script type="text/javascript"> -->

/** 
 * paneSplitter Variable. If not defined yet, it will be defined now, if already defined, this definition is ignored 
 */
var paneSplitter;

/** 
 * Sets the active stylesheet.
 * @param aTitle The title of the alternate stylesheet. Allowed values are 'fontsize70', 'fontsize100', 'fontsize120' and 'fontsize150'
 */
function setActiveStyleSheet(aTitle) {
  var i, a;
  var northHeight=87;
  
if (typeof NORTH_HEIGHT == 'undefined' ) {
	  northHeight=87;
  } else {
	  northHeight=parseInt(NORTH_HEIGHT);
  }
	  

  // In some browsers (IE, Opera) the alternative stylesheet is not pickedup during the load of the page.
  // But setting it in the "onload" doesn't have effect because it was still set.
  // Unsetting the alternative stylesheet (and then setting it again) forces the browser to rerender the page.
  if (getActiveStyleSheet() == aTitle && aTitle != "dummy") {  
		setActiveStyleSheet("dummy");
  }
  // Set the active stylesheet for the top frame and included frames.
  setActiveStyleSheetInFrame (aTitle, top);


	// Don't do the underlying code for the "dummy" title.
  if (aTitle.indexOf("fontsize")<0 || self != top) {
		return;
  }
  
  // Change the image sources
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("alternate stylesheet") != -1 && a.getAttribute("title")) {
      if (a.getAttribute("title") != aTitle) {
	      unselectImage (a.getAttribute("title"));
	  }
	  else {
      	selectImage (aTitle);
      }
    }
  }
  
  // Change the height of the northern pane (the header).
  // Defines the height of the 'header' (north pane).
  var northPaneSizes = {'fontsize70': northHeight, 'fontsize100': northHeight+1, 'fontsize120': northHeight+7, 'fontsize150': northHeight+13};
  var southPaneSizes = {'fontsize70':'20', 'fontsize100': '20', 'fontsize120': '29', 'fontsize150': '33'};
  if (paneSplitter) {
	  paneSplitter.setSizeOfPane('north',northPaneSizes[aTitle]);
	  paneSplitter.setSizeOfPane('south',southPaneSizes[aTitle]);
  }
  
  if (typeof onChangeFontSize == 'function') {
	  onChangeFontSize(aTitle);
  }
  
  storeFontsize();
}

/**
 * Sets the active stylesheet in the given and all lower level frames
 * @param aTitle The title of the alternate stylesheet. Allowed values are 'fontsize70', 'fontsize100', 'fontsize120' and 'fontsize150'
 * @param aFrame The frame in which the stylesheet should be actived.
 */

function setActiveStyleSheetInFrame (aTitle, aFrame) {
  var i, a;
  var currentDocument = aFrame.document;

  // Loop over all alternate stylesheets to enable the given stylesheet and disable all others.
  for(i=0; (a = currentDocument.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("alternate stylesheet") != -1 && a.getAttribute("title")) {
      if (a.getAttribute("title") != aTitle) {
	      a.disabled = true;
	  }
	  else {
      	a.disabled = false;
      }
    }
  }
  
  // If this frame has subframes
  if (aFrame.frames) {
  	  // Loop over all subframes and active the stylesheet in there.
	  for(i=0; i<aFrame.frames.length; i++) {
	  	setActiveStyleSheetInFrame (aTitle, aFrame.frames[i]);
	  }
  }
}

/** 
 * Gets the name of the currently active stylesheet.
 * @return The name of the currently active stylesheet of null of not found.
 */
function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("alternate stylesheet") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

/** 
 * Gets the name of the default stylesheet. This stylesheet is used in case the cookie was not found.
 * @return 'fontsize70'
 */
function getPreferredStyleSheet() {
  return ('fontsize70');
}

/**
 * Unselects the image for the given stylesheet.
 * @param aTitle The title of the alternate stylesheet. Allowed values are 'fontsize70', 'fontsize100', 'fontsize120' and 'fontsize150'
 */
function unselectImage (title) {
  // Retrieve the image. The image id looks like "Header_Form:fontsize70"
  var image = document.getElementById("header_Form:"+title);
  if (!image) {
  	return;
  }

  // Get the current source of the image.
  var src = image.src;

  // Check if the image is selected. (sources look like fontswitcher_70_selected.gif)
  var selectedIdx = src.indexOf("_selected");
  if (selectedIdx >0) {
    // Remove the '_selected' from the filename. (sources look like fontswitcher_70_selected.gif)
  	var newSource = src.substring(0, selectedIdx) + src.substring(selectedIdx + 9);
    image.src = newSource;
  }
}  

/**
 * Selects the image for the given stylesheet.
 * @param aTitle The title of the alternate stylesheet. Allowed values are 'fontsize70', 'fontsize100', 'fontsize120' and 'fontsize150'
 */
function selectImage (title) {
  // Retrieve the image. The image id looks like "Header_Form:fontsize70"
  var image = document.getElementById("header_Form:"+title);
  if (!image) {
  	return;
  }

  // Get the current source of the image.
  var src = image.src;

  // Check if the image is selected. (sources look like fontswitcher_70_selected.gif)
  var selectedIdx = src.indexOf("_selected");
  if (selectedIdx <0) {
    // Add _selected in front of the ".gif"
  	var dotGifIdx = src.indexOf(".gif");
  	newSource = src.substring(0, dotGifIdx) + "_selected" + src.substring(dotGifIdx);
    image.src = newSource;
  }
}  
  
/**
 * Create a new cookie
 * @param name The name of the cookie
 * @param value The value of the cookie
 * @param days The number of days this cookie stays valid
 */
function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

/** 
 * Reads the value from a cookie.
 * @param the name of the cookie
 * @return The value of the cookie or null of not found.
 */
function readCookie(name) {
  var nameEQ = name + "=";
  
  // Loop over all cookies.
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    // Trim the cookie.
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

/**
 * Reads the correct active alternative stylesheet from the cookie.
 */
function loadFontsize() {
  var cookie = readCookie("milnavstyle");

  // if cookie doesn't exist, use default stylesheet.
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
}

/**
 * Stores the selected active alternative stylesheet in a cookie.
 */
function storeFontsize() {
  var title = getActiveStyleSheet();
  // if active stylesheet doesn't exist, use default stylesheet.
  if (!title) {
  	title = getPreferredStyleSheet();
  }
  
  // Store cookie for 1 year.
  createCookie("milnavstyle", title, 365);
}


// Static function, run when javascript loads.
// If this is the TOP page (so we're not in any of the IFRAMEs).
if (self == top) 
{

    // Store the old onload function.
	var fontSizeOldOnload = window.onload; 

	// Register a new onload function.
	window.onload = function(e) {
	  loadFontsize();
	  if (fontSizeOldOnload) {
	  	fontSizeOldOnload(e);
	  }
	}

	// Store the old onunload function.
	var fontSizeOldOnunload = window.onunload; 
	
	// Register a new onunload function.
	window.onunload = function(e) {
	  storeFontsize();
	  if (fontSizeOldOnunload) {
	  	fontSizeOldOnunload(e);
	  }
	}
}

// For every page, try to active the current alternate stylesheet as soon as possible,
// to avoid loading the page in a different fontsize than the selected one.
// Other functions like setting the correct images or the header height might not be
// available at this time. Those will be done at the window.onload.
loadFontsize();

//</script>