astrNavSections = new Array; 
strOpenSectionID = "";
tmrMenuOff = null;

intMenuOffsetY = 18;

strUserAgent = navigator.userAgent.toLowerCase();
isMacOS9 = false;
isIE = false;
isMacOSX = false;
isKonqueror = false;
isOpera = false;
isMac = (strUserAgent.indexOf("mac")!=-1);
isSafari = (strUserAgent.indexOf("safari")!=-1);
isOpera = (strUserAgent.indexOf("opera")!=-1);
isKonqueror = (strUserAgent.indexOf("konqueror")!=-1);
if (isMac) {isMacOSX = (strUserAgent.indexOf("5.2")!=-1);}
if (isMac && !isMacOSX) { isMacOS9 = true; }
isIE = ((strUserAgent.indexOf("msie") != -1) && (strUserAgent.indexOf("gecko") == -1) && (strUserAgent.indexOf("opera") == -1) && (strUserAgent.indexOf("netscape") == -1));


// EVENT HANDLERS
window.onload = fncPageInit;
window.onresize = fncPageStateChange;


function fncOutputDate() {
  var astrMonths = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
  var current_date = new Date();
  document.write(astrMonths[current_date.getMonth()] + " " + current_date.getDate() + ", " + current_date.getFullYear());
}



//______________________________________________________________
// NAVIGATION FUNCTIONS


function fncNavOver(oElement) {
  oElement.className = "clsNavButtonOver";
}
function fncNavOut(oElement) {
  oElement.className = "clsNavButton";
}
function fncNavClick(strURL) {
  document.location.href = strURL;
}

function fncShowSubNav(oSection,strSectionID,intMenuShiftX) {
  if (isKonqueror || isOpera || (isMacOS9 && isIE)) {
    fncBuildSimpleNav(strSectionID);
  }
  else {
    fncHideSubNav(strOpenSectionID);
    if (document.getElementById(strSectionID) != null) {
      // subnav exists
      var oSubNav = document.getElementById(strSectionID);
      
      var intSectionX = fncGetAbsoluteX(oSection);
      var intSectionY = fncGetAbsoluteY(oSection);
      intSectionY = intSectionY + intMenuOffsetY;
      
      if (intMenuShiftX.length < 0) {
        intSectionX = intSectionX - 30;
      }
      else {
        intSectionX = intSectionX + intMenuShiftX
      }
      
      if (isMac && isIE) {
        intSectionY = intMenuOffsetY; //intSectionY - intMenuOffsetY;
        intSectionX = intSectionX - 10;
      }
      else if (isSafari) {
        intSectionY = intSectionY - 8;
      }
      oSubNav.style.top = intSectionY + "px";
      oSubNav.style.left = intSectionX + "px";
      
      oSubNav.style.display = "block";   
      strOpenSectionID = strSectionID;      
    }
  }
}     

function fncHideSubNav(strSectionID) {
  if (document.getElementById(strSectionID) != null) {
    fncCancelTimer();
    document.getElementById(strSectionID).style.display = "none";
  }
}

function fncDelayedHideSubNav(strSectionID) {
  if (document.getElementById(strSectionID) != null) {
    // subnav exists
    tmrMenuOff = setTimeout("document.getElementById('"+strSectionID+"').style.display='none';", 200);
    
  }
}

function fncHideAllNav() {
  if (astrNavSections.length > 0) {
    for(var i=0;i<=astrNavSections.length;i++) {
      if (typeof(astrNavSections[i][0]) != "undefined") {
        if (document.getElementById('idSection'+astrNavSections[i][0]) != null) {
          if (document.getElementById('idSection'+astrNavSections[i][0]).style.display != "none") {
            fncCancelTimer();
            fncHideSubNav('idSection'+astrNavSections[i][0]);
          }
        }
      }
    }
  }
}

function fncCancelTimer() {
  clearTimeout(tmrMenuOff);
}


function fncMouseOverSubNavItem(oSubNavItem) {
  oSubNavItem.className = "clsSubNavItemHover";
}

function fncMouseOutSubNavItem(oSubNavItem) {
  oSubNavItem.className = "clsSubNavItem";
}

function fncBuildSimpleNav(strSectionID) {
  var strLinkList = " ";
  if (astrNavSections[strSectionID][1] != null) {
    var astrLabels = astrNavSections[strSectionID][1].split("^");
    var astrLinks = astrNavSections[strSectionID][2].split("^");
    for (var i=0;i<=astrLabels.length-1;i++) {
      if (i >= 3 && (i % 3 == 0)) {
        strLinkList = strLinkList + "<br>";
      }
      else if (i > 0) {
        strLinkList = strLinkList + "&nbsp;&nbsp;|&nbsp;&nbsp;";
      }
      strLinkList = strLinkList + "<a href='" + astrLinks[i] + "'>" + astrLabels[i] + "</a>";
    }
  }
  document.getElementById("idSubNavSimpleLinks").innerHTML = strLinkList;
  
  if (strLinkList.length < 3) {
    document.getElementById("idSubNavSimpleLinks").style.visibility = "hidden";
  }
  else {
    document.getElementById("idSubNavSimpleLinks").style.visibility = "visible";
  }
}


//______________________________________________________________
// UTILITY FUNCTIONS

function fncGetAbsoluteX(oObjectToGetPosition) {
  // Utility function to get the absolute X-coordinate of an object on the page
  if (typeof(oObjectToGetPosition) == "string") {
    oObjectToGetPosition = document.getElementById(oObjectToGetPosition);
  }
  var intCoords = {x: 0};
  while (oObjectToGetPosition) {
    intCoords.x += oObjectToGetPosition.offsetLeft;
    oObjectToGetPosition = oObjectToGetPosition.offsetParent;
  }
  return intCoords.x;
}

function fncGetAbsoluteY(oObjectToGetPosition) {
  // Utility function to get the absolute Y-coordinate of an object on the page
  if (typeof(oObjectToGetPosition) == "string") {
    oObjectToGetPosition = document.getElementById(oObjectToGetPosition);
  }
  var intCoords = {y: 0};
  while (oObjectToGetPosition) {
    intCoords.y += oObjectToGetPosition.offsetTop;
    oObjectToGetPosition = oObjectToGetPosition.offsetParent;
  }
  return intCoords.y;
}

function fncGetWidth(oObjectToGetSize) {
  if (typeof(oObjectToGetSize) == "string") {
    oObjectToGetSize = document.getElementById(oObjectToGetSize);
  }
  var intWidth = oObjectToGetSize.offsetWidth;
  return intWidth;
}

function fncGetHeight(oObjectToGetSize) {
  if (typeof(oObjectToGetSize) == "string") {
    oObjectToGetSize = document.getElementById(oObjectToGetSize);
  }
  var intHeight = oObjectToGetSize.offsetHeight;
  return intHeight;
}

if (!Array.prototype.push) {
  Array.prototype.push = function () {
    for (var i = 0; i < arguments.length; i++) {
        this[this.length] = arguments[i];
    }
   return this.length;
  };
}



//______________________________________________________________
// UI TOOLS FUNCTIONS

function fncGetStyleProperty(oElement,strPropertyJS,strPropertyCSS) {
  var strPropertyValue = "";
  if (oElement.currentStyle) 
    strPropertyValue = oElement.currentStyle[strPropertyJS]; 
  else if (window.getComputedStyle){ 
    var elstyle = window.getComputedStyle(oElement, ""); 
    strPropertyValue = elstyle.getPropertyValue(strPropertyCSS); 
  } 
  return strPropertyValue;
}

function fncChangeFontSize(intDiff) {
  if (document.getElementById) {
  	var oElement = document.getElementById('idPrimaryContent');
  	var strFontSize = fncGetStyleProperty(oElement,'fontSize','font-size');
  	var intNewSize = parseInt(strFontSize) + (2*intDiff);
  	fncSetFontSize(oElement, intNewSize);
  }
}

function fncSetFontSize(oElement, intSize) {
  if (typeof(oElement) == "string") {
    oElement = document.getElementById(oElement);
  }
  oElement.style.fontSize = intSize + "px";
  if (typeof(fncSetCookie) == "function")
    fncSetCookie('fontsize', intSize, 'never', '/')
  window.status = "Font Size now " + intSize + "px";
  setTimeout("window.status = '';", 4000);
  fncPageStateChange();
}

function fncSetFontSizeDefault() {
  fncSetFontSize('idPrimaryContent', 12);
  if (typeof(fncSetCookie) == "function")
    fncSetCookie('fontsize', null, 'now', '/')
}

function fncChangeFace() {
  if (document.getElementById) {
  	var oElement = document.getElementById('idPrimaryContent');
	  var strSansSerifs = "verdana,geneva,arial,helvetica,sans-serif";
  	var strFontFace = fncGetStyleProperty(oElement,'fontFamily','font-family');
  	if (strSansSerifs.indexOf(strFontFace.toLowerCase()) >= 0) {
    	fncSetFontFace(oElement, "serif");
  	}
  	else {
    	fncSetFontFace(oElement, "sansserif");
  	}
  }
}

function fncSetFontFace(oElement, strFontFace) {
  if (typeof(oElement) == "string") {
    oElement = document.getElementById(oElement);
  }
	var strSerifs = "georgia,times new roman,times,serif";
	var strSansSerifs = "verdana,geneva,arial,helvetica,sans-serif";
	if (strFontFace == "serif") {
	  oElement.style.fontFamily = strSerifs;
    if (typeof(fncSetCookie) == "function")
      fncSetCookie('fontface', null, 'now', '/')
	}
	else {
	  oElement.style.fontFamily = strSansSerifs;
    if (typeof(fncSetCookie) == "function")
      fncSetCookie('fontface', 'sansserif', 'never', '/')
	}
  fncPageStateChange();
}


//______________________________________________________________
// POSITIONING FUNCTIONS

function fncPositionFooter() { 
  /* moves the footer to the bottom of the content if the pages is
      taller than the browser or to the bottom of the browser window
      if the content is shorter than the window.  Flakey on some browsers.
     Requires the footer to have absolute position and be inside main content.  */
   
  oMain = document.getElementById('idMain');
  oFooter = document.getElementById('idFooter');
  oPrimaryContainer = document.getElementById('idPrimaryContainer');
  
  oFooter.style.position = "absolute";
  var intMainHeight = fncGetHeight(oMain);
  var intFooterHeight = fncGetHeight(oFooter);
  var intPrimaryHeight = fncGetHeight(oPrimaryContainer);
  
  if (!isOpera) {
    if (isIE) {
      oFooter.style.top = "-1000px";
      if (intMainHeight+intFooterHeight >= fncGetAbsoluteY(oFooter)) {
        oFooter.style.top = (intMainHeight - intFooterHeight) + "px";
      }
    }
    else {
      oFooter.style.top = "-1000px";
      intPrimaryContainerHeight = fncGetHeight(oPrimaryContainer) + fncGetAbsoluteY(oPrimaryContainer) + intFooterHeight;
      if (intMainHeight >= intPrimaryContainerHeight) {
        oFooter.style.top = (intMainHeight - intFooterHeight) + "px";
      }
      else {
        oFooter.style.top = (intPrimaryContainerHeight - intFooterHeight) + "px";
      }
    }
    oFooter.style.visibility = "visible";
  }
}


//______________________________________________________________
// EVENT HANDLING FUNCTIONS

function fncPageInit() {
  //showDebug();
  
  if (!(isMac && isIE)) {
    window.onclick = fncHideAllNav();
  }
  
  if (fncReadCookie("fontsize")) {
    fncSetFontSize('idPrimaryContent', fncReadCookie("fontsize"));
  }
  if (fncReadCookie("fontface")) {
    fncSetFontFace('idPrimaryContent', fncReadCookie("fontface"));
  }
  
  
  // BROWSER FIXES
  if (!(isMac && isIE) && !isKonqueror && !isSafari && !isOpera) {
    document.getElementById("idUIFontTools").style.visibility = "visible";
  }
  if (isMac && isIE) {
    document.getElementById("idNavPrimary").style.position = "absolute";
    document.getElementById("idNavPrimary").style.top = "-10000px";
  }
  if (isSafari) {
    document.getElementById("idUIFontTools").style.top = "-10000px";
  }
  if (!isKonqueror && !isOpera) {
    document.getElementById("idUITools").style.visibility = "visible";
  }
    
    
  if (typeof(fncPageOnload) == "function")  {
    fncPageOnload();
  }
  fncPageStateChange();
}

function fncPageStateChange() {
  fncPositionFooter();
}


//______________________________________________________________
// DEBUGGING

function showDebug() {
  window.top.debugWindow =
      window.open("",
                  "Debug",
                  "left=0,top=0,width=300,height=700,scrollbars=yes,"
                  +"status=yes,resizable=yes");
  window.top.debugWindow.opener = self;
  // open the document for writing
  window.top.debugWindow.document.open();
  window.top.debugWindow.document.write(
      "<HTML><HEAD><TITLE>Debug Window</TITLE></HEAD><BODY><PRE>\n");
}

function debug(text) {
  if (window.top.debugWindow && ! window.top.debugWindow.closed) {
    window.top.debugWindow.document.write(text+"\n");
  }
}

function hideDebug() {
  if (window.top.debugWindow && ! window.top.debugWindow.closed) {
    window.top.debugWindow.close();
    window.top.debugWindow = null;
  }
}