strNavActiveSection = "";
oPopupTimer = null;
intPopupMenuGlobalShiftX = -15;
intPopupMenuGlobalShiftY = 30;

strUserAgent = navigator.userAgent.toLowerCase();
isMac = (strUserAgent.indexOf("mac") != -1);
isGaleon = (strUserAgent.indexOf("galeon") != -1);
isIE = ((strUserAgent.indexOf("msie") != -1) && (strUserAgent.indexOf("gecko") == -1) && (strUserAgent.indexOf("opera") == -1) && (strUserAgent.indexOf("netscape") == -1)); 


if (!(isMac && isIE) && !isGaleon) {
  if (window.addEventListener)
    window.addEventListener("load", fncPageLoadAll, false);
  else if (window.attachEvent)
    window.attachEvent("onload", fncPageLoadAll);
  else if (document.getElementById)
    window.onload=fncPageLoadAll;
}
  

function fncPageLoadAll() {
  if (fncReadCookie("fontsize")) {
    fncSetFontSize(fncReadCookie("fontsize"));
  }
  fncCreateShadowBox('idFooter', 'NavPopup');
}

function fncSetBackgroundColor(oElement, strColor) {
  oElement.style.backgroundColor = strColor;
}


//---------------------------------------------------------------------------
// FONT RESIZE FUNCTIONS
function fncSetFontSize(intSize) {
  oElement = document.getElementById("idMainContent");
  if (oElement) {
    fncSetElementFontSize(document.getElementById("idMainContent"), intSize)
  }
}

function fncSetElementFontSize(oElement, intSize) {
  if (typeof(oElement) == "string") {
    oElement = document.getElementById(oElement);
  }
  oElement.style.fontSize = intSize + "pt";
  fncSetFontButtonBorder(intSize);
  
  if (typeof(fncSetCookie) == "function")
  fncSetCookie('fontsize', intSize, 'never', '/')
  window.status = "Font Size now " + intSize + "px";
  setTimeout("window.status = '';", 4000);
}

function fncSetFontButtonBorder(intSize) {
  for (var i=0;i<=20;i++) {
    var strID = "idFontSizeButton" + i;
    if (document.getElementById(strID)) {
      if (i != intSize) {
        document.getElementById(strID).style.borderColor = "#CCCCCC";
      }
      else {
        document.getElementById(strID).style.borderColor = "#000000";
      }
    }
  }
}

function fncSetFontSizeDefault() {
  fncSetElementFontSize('idPrimaryContent', 12);
  if (typeof(fncSetCookie) == "function")
    fncSetCookie('fontsize', null, 'now', '/')
}
    

//---------------------------------------------------------------------------
// POPUP NAV FUNCTIONS

function fncNavPopupDelayHide() {
  oPopupTimer = setTimeout("fncNavPopupHide()",500);
}
function fncNavPopupCancelHide() {
  clearTimeout(oPopupTimer);
}

function fncNavPopupOver(oItem) {
  oItem.style.color = "#000000";
}
function fncNavPopupOut(oItem) {
  oItem.style.color = "#FFFFFF";
}

function fncNavPopupShow(strSection) {
  fncNavPopupCancelHide();
  if (!(isMac && isIE)) {
    // first argument is any horizontal offset for popup menu
    // second argument is any vertical offset for popup menu
    // third argument is specified width for popup menu
    if (arguments) {
      intMenuShiftX = 0;
      intMenuShiftY = 0;
      intMenuWidth = -1;
      if (arguments.length >= 2) {
        if (typeof(arguments[1]) == "number") {
          intMenuShiftX = arguments[1];
        }
      }
      if (arguments.length >= 3) {
        if (typeof(arguments[2]) == "number") {
          intMenuShiftY = arguments[2];
        }
      }
      if (arguments.length >= 4) {
        if (typeof(arguments[3]) == "number") {
          intMenuWidth = arguments[3];
        }
      }
      
      fncNavPopupHide();
      strNavActiveSection = strSection;
      
      if (typeof(document.getElementById('idNavButton_' + strSection)) != "undefined") {
        oPopupNavButton = document.getElementById('idNavButton_' + strSection);
        // disabled due to IE "flashing" if (!isIE) { oPopupNavButton.style.color = "#FFB800 !important"; }
      }
      
      if (typeof(document.getElementById('idNavPopup_' + strSection)) != "undefined" && document.getElementById('idNavPopup_' + strSection)) {
        oPopupNavMenu = document.getElementById('idNavPopup_' + strSection);
        oPopupNavMenu.style.display = "block";
        if (intMenuWidth > 0) {
          oPopupNavMenu.style.width = intMenuWidth + "px";
        }
        intLocationX = (fncGetAbsoluteX(oPopupNavButton)) + (intPopupMenuGlobalShiftX) + (intMenuShiftX);
        intLocationY = (fncGetAbsoluteY(oPopupNavButton)) + (intPopupMenuGlobalShiftY) + (intMenuShiftY);
        
        if (isIE) { intLocationY = intLocationY-11; intLocationX = intLocationX + 20; }
        
        oPopupNavMenu.style.left = intLocationX + "px";
        oPopupNavMenu.style.top = intLocationY + "px";
        fncSetNavPopupShadow('idNavPopup_' + strSection);
      }
    }
  }
}

function fncNavDelayHide() {
  fncNavPopupDelayHide();
}

function fncNavPopupHide() {
  if (strNavActiveSection.length > 0) {
    if (typeof(document.getElementById('idNavButton_' + strNavActiveSection)) != "undefined") {
      oPopupNavButton = document.getElementById('idNavButton_' + strNavActiveSection);
      // disabled due to IE "flashing" if (!isIE) { oPopupNavButton.style.color = "#FFFFFF"; }
    }
    if (typeof(document.getElementById('idShadowNavPopup')) != "undefined" && document.getElementById('idShadowNavPopup')) {
      document.getElementById('idShadowNavPopup').style.display = "none";
    }
    if (typeof(document.getElementById('idNavPopup_' + strNavActiveSection)) != "undefined" && document.getElementById('idNavPopup_' + strNavActiveSection)) {
      oPopupNavMenu = document.getElementById('idNavPopup_' + strNavActiveSection);
      oPopupNavMenu.style.display = "none";
    }
  }
}


//---------------------------------------------------------------------------
// UTILITY FUNCTIONS

function fncGetAbsoluteX(oObjectToGetPosition) {
  // Utility function to get the absolute X-coordinate of an object on the page
  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
  var intCoords = {y: 0};
  while (oObjectToGetPosition) {
    intCoords.y += oObjectToGetPosition.offsetTop;
    oObjectToGetPosition = oObjectToGetPosition.offsetParent;
  }
  return intCoords.y;
}

function fncGetWidth(oObjectToGetWidth) {
  // Utility function to get the width of an object on the page
	if (oObjectToGetWidth.style.pixelWidth) {
		return oObjectToGetWidth.style.pixelWidth;
	}
  if (oObjectToGetWidth.style.width) {
      return oObjectToGetWidth.style.width;
  } 
  return oObjectToGetWidth.offsetWidth;
}

function fncGetHeight(oObjectToGetHeight) {
  // Utility function to get the height of an object on the page
	if (oObjectToGetHeight.style.pixelHeight) {
		return oObjectToGetHeight.style.pixelHeight;
	}
  if (oObjectToGetHeight.style.height) {
      return oObjectToGetHeight.style.height;
  }
  return oObjectToGetHeight.offsetHeight;
}


//---------------------------------------------------------------------------
// COOKIE FUNCTIONS


function fncSetCookie (name, value, exp, path) {
 /*
    INPUT
      name (string) - name of the cookie
      value (string) - value of the cookie
      exp (string) - default is "never"
                     if "never" it sets exp to "Thu, 7 Dec 2113 01:00:00 UTC"
                     if "exp" it sets exp to "Fri, 13 Apr 1970 01:00:00 UTC"
                     if int (ie "5", "20", "60000") it translates to int hours from now
                     if valid GMT date then it uses that as exp
                     else it defaults to 840 hours (5 weeks)
      path (string)
 */
 if(exp == "") {
   exp = "never";
 }
 if (typeof(exp) == 'string') {
   if (exp == 'never') { 
     var strExp = "Thu, 7 Dec 2113 01:00:00 UTC";
   }
   else if (exp == 'exp' || exp == 'now') { 
     var strExp = "Fri, 13 Apr 1970 01:00:00 UTC";
   }
   else {
     if (Date.parse(exp)) {
      var strExp = exp;
     }
     else {
       exp = exp*1;
       if (isNaN(exp)) {
        var strExp = (new Date((new Date()).getTime() + 840*3600000)).toGMTString();
       }
       else {
        var strExp = (new Date((new Date()).getTime() + exp*3600000)).toGMTString();
       }
     }
   }
 }
 document.cookie = name + '=' + escape(value) + ((strExp)?(';expires=' + strExp):'') + ((path)?';path=' + path:'');
}



function fncReadCookie(name) {
 var strCookies = document.cookie;
 
 // find beginning of cookie value in document.cookie
 var prefix = name + "=";
 var begin = strCookies.indexOf("; " + prefix);
 if (begin == -1) {
   begin = strCookies.indexOf(prefix);
   if (begin != 0) return null;
 }
 else begin += 2;
 
 // find end of cookie value
 var end = document.cookie.indexOf(";", begin);
 if (end == -1) end = strCookies.length;
 
 // return cookie value
 return unescape(strCookies.substring(begin + prefix.length, end));
}



function fncKillCookie(name, path) {
 /*
    REQUIRED MODULES
      "fncReadCookie" function
      "fncSetCookie" function
 */
 fncSetCookie (name, null, 'now', path);
}


function fncKillAllCookies(path) {
 var strCookies = document.cookie;
 
 var astrCookies = document.cookie.split(";");
 
 for(var i=0;i<=astrCookies.length-1;i++) {
   var astrCookie = astrCookies[i].split("=");
   var strCookieName = astrCookie[0];
   if (i>0) {
     if (strCookieName.indexOf(" ") == 0) {
       // remove leading space
       strCookieName = strCookieName.substring(1,strCookieName.length)
     }
   }
   fncKillCookie(strCookieName, path);
 }
 alert('All cookies deleted for path ' + path);
}


//---------------------------------------------------------------------------
// PROTOTYPE FUNCTIONS

/* Non-IE browsers do not have the insertAdjacentElement function so we create it here */
if(typeof HTMLElement!="undefined" && !HTMLElement.prototype.insertAdjacentElement){	HTMLElement.prototype.insertAdjacentElement = function(where,parsedNode)
	{
		switch (where){
		case 'beforeBegin':
			this.parentNode.insertBefore(parsedNode,this)
			break;
		case 'afterBegin':
			this.insertBefore(parsedNode,this.firstChild);
			break;
		case 'beforeEnd':
			this.appendChild(parsedNode);
			break;
		case 'afterEnd':
			if (this.nextSibling) this.parentNode.insertBefore(parsedNode,this.nextSibling);
			else this.parentNode.appendChild(parsedNode);
			break;
		}
	}

	HTMLElement.prototype.insertAdjacentHTML = function(where,htmlStr)
	{
		var r = this.ownerDocument.createRange();
		r.setStartBefore(this);
		var parsedHTML = r.createContextualFragment(htmlStr);
		this.insertAdjacentElement(where,parsedHTML)
	}


	HTMLElement.prototype.insertAdjacentText = function(where,txtStr)
	{
		var parsedText = document.createTextNode(txtStr)
		this.insertAdjacentElement(where,parsedText)
	}
}
