// JavaScript Browser Sniffer
//	based on http://webreference.com/tools/browser/javascript.html
//
// convert all characters to lowercase to simplify testing
var agt=navigator.userAgent.toLowerCase();
var appVer = navigator.appVersion.toLowerCase();

// *** BROWSER VERSION ***
var minorVer = parseFloat(appVer);
var majorVer = parseInt(minorVer);

var is_opera = (agt.indexOf("opera") != -1);
var is_opera2 = (agt.indexOf("opera 2") != -1 || agt.indexOf("opera/2") != -1);
var is_opera3 = (agt.indexOf("opera 3") != -1 || agt.indexOf("opera/3") != -1);
var is_opera4 = (agt.indexOf("opera 4") != -1 || agt.indexOf("opera/4") != -1);
var is_opera5 = (agt.indexOf("opera 5") != -1 || agt.indexOf("opera/5") != -1);
var is_opera6 = (agt.indexOf("opera 6") != -1 || agt.indexOf("opera/6") != -1); // new 020128- abk
var is_opera7 = (agt.indexOf("opera 7") != -1 || agt.indexOf("opera/7") != -1); // new 021205- dmr
var is_opera5up = (is_opera && !is_opera2 && !is_opera3 && !is_opera4);
var is_opera6up = (is_opera && !is_opera2 && !is_opera3 && !is_opera4 && !is_opera5); // new020128
var is_opera7up = (is_opera && !is_opera2 && !is_opera3 && !is_opera4 && !is_opera5 && !is_opera6); // new021205 -- dmr

// Note: On IE, start of appVersion return 3 or 4
// which supposedly is the version of Netscape it is compatible with.
// So we look for the real version further on in the string
var iePos  = appVer.indexOf('msie');
if (iePos !=-1) {
   minorVer = parseFloat(appVer.substring(iePos+5,appVer.indexOf(';',iePos)))
   majorVer = parseInt(minorVer);
}

// ditto Konqueror
var is_konq = false;
var kqPos   = agt.indexOf('konqueror');
if (kqPos !=-1) {                 
   is_konq  = true;
   minorVer = parseFloat(agt.substring(kqPos+10,agt.indexOf(';',kqPos)));
   majorVer = parseInt(minorVer);
}                                 

var is_getElementById   = (document.getElementById) ? "true" : "false"; // 001121-abk
var is_getElementsByTagName = (document.getElementsByTagName) ? "true" : "false"; // 001127-abk
var is_documentElement = (document.documentElement) ? "true" : "false"; // 001121-abk

var is_safari = ((agt.indexOf('safari')!=-1)&&(agt.indexOf('mac')!=-1))?true:false;
var is_khtml  = (is_safari || is_konq);

var is_gecko = ((!is_khtml)&&(navigator.product)&&(navigator.product.toLowerCase()=="gecko"))?true:false;
var geckoVer  = 0;
if (is_gecko) geckoVer=navigator.productSub;

var is_moz   = ((agt.indexOf('mozilla/5')!=-1) && (agt.indexOf('spoofer')==-1) &&
				(agt.indexOf('compatible')==-1) && (agt.indexOf('opera')==-1)  &&
				(agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1)     &&
				(is_gecko) && 
				((navigator.vendor=="")||(navigator.vendor=="Mozilla")||(navigator.vendor=="Debian")));
var is_fb = ((agt.indexOf('mozilla/5')!=-1) && (agt.indexOf('spoofer')==-1) &&
			 (agt.indexOf('compatible')==-1) && (agt.indexOf('opera')==-1)  &&
			 (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1)     &&
			 (is_gecko) && (navigator.vendor=="Firebird"));
var is_fx = ((agt.indexOf('mozilla/5')!=-1) && (agt.indexOf('spoofer')==-1) &&
			 (agt.indexOf('compatible')==-1) && (agt.indexOf('opera')==-1)  &&
			 (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1)     &&
			 (is_gecko) && (navigator.vendor=="Firefox"));
if ((is_moz)||(is_fb)||(is_fx)) {  // 032504 - dmr
   var is_moz_ver = (navigator.vendorSub)?navigator.vendorSub:0;
   if(!(is_moz_ver)) {
	   is_moz_ver = agt.indexOf('rv:');
	   is_moz_ver = agt.substring(is_moz_ver+3);
	   is_paren   = is_moz_ver.indexOf(')');
	   is_moz_ver = is_moz_ver.substring(0,is_paren);
   }
   minorVer = is_moz_ver;
   majorVer = parseInt(is_moz_ver);
}
var is_fb_ver = is_moz_ver;
var is_fx_ver = is_moz_ver;

var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
			&& (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
			&& (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1)
			&& (!is_khtml) && (!(is_moz)) && (!is_fb) && (!is_fx));

// Netscape6 is mozilla/5 + Netscape6/6.0!!!
// Mozilla/5.0 (Windows; U; Win98; en-US; m18) Gecko/20001108 Netscape6/6.0
// Changed this to use navigator.vendor/vendorSub - dmr 060502   
// var nav6Pos = agt.indexOf('netscape6');
// if (nav6Pos !=-1) {
if ((navigator.vendor)&&
	((navigator.vendor=="Netscape6")||(navigator.vendor=="Netscape"))&&
	(is_nav)) {
   majorVer = parseInt(navigator.vendorSub);
   // here we need minorVer as a valid float for testing. We'll
   // revert to the actual content before printing the result. 
   minorVer = parseFloat(navigator.vendorSub);
}

var is_nav2 = (is_nav && (majorVer == 2));
var is_nav3 = (is_nav && (majorVer == 3));
var is_nav4 = (is_nav && (majorVer == 4));
var is_nav4up = (is_nav && minorVer >= 4);  // changed to minorVer for
											// consistency - dmr, 011001
var is_navonly      = (is_nav && ((agt.indexOf(";nav") != -1) ||
					  (agt.indexOf("; nav") != -1)) );

var is_nav6   = (is_nav && majorVer==6);    // new 010118 mhp
var is_nav6up = (is_nav && minorVer >= 6) // new 010118 mhp

var is_nav5   = (is_nav && majorVer == 5 && !is_nav6); // checked for ns6
var is_nav5up = (is_nav && minorVer >= 5);

var is_nav7   = (is_nav && majorVer == 7);
var is_nav7up = (is_nav && minorVer >= 7);

var is_ie   = ((iePos!=-1) && (!is_opera) && (!is_khtml));
var is_ie3  = (is_ie && (majorVer < 4));

var is_ie4   = (is_ie && majorVer == 4);
var is_ie4up = (is_ie && minorVer >= 4);
var is_ie5   = (is_ie && majorVer == 5);
var is_ie5up = (is_ie && minorVer >= 5);

var is_ie5_5  = (is_ie && (agt.indexOf("msie 5.5") !=-1)); // 020128 new - abk
var is_ie5_5up =(is_ie && minorVer >= 5.5);                // 020128 new - abk

var is_ie6   = (is_ie && majorVer == 6);
var is_ie6up = (is_ie && minorVer >= 6);

// KNOWN BUG: On AOL4, returns false if IE3 is embedded browser
// or if this is the first browser window opened.  Thus the
// variables is_aol, is_aol3, and is_aol4 aren't 100% reliable.

var is_aol   = (agt.indexOf("aol") != -1);
var is_aol3  = (is_aol && is_ie3);
var is_aol4  = (is_aol && is_ie4);
var is_aol5  = (agt.indexOf("aol 5") != -1);
var is_aol6  = (agt.indexOf("aol 6") != -1);
var is_aol7  = ((agt.indexOf("aol 7")!=-1) || (agt.indexOf("aol7")!=-1));
var is_aol8  = ((agt.indexOf("aol 8")!=-1) || (agt.indexOf("aol8")!=-1));

var is_webtv = (agt.indexOf("webtv") != -1);

var is_TVNavigator = ((agt.indexOf("navio") != -1) || (agt.indexOf("navio_aoltv") != -1)); 
var is_AOLTV = is_TVNavigator;

var is_hotjava = (agt.indexOf("hotjava") != -1);
var is_hotjava3 = (is_hotjava && (majorVer == 3));
var is_hotjava3up = (is_hotjava && (majorVer >= 3));

// *** JAVASCRIPT VERSION CHECK ***
// Useful to workaround Nav3 bug in which Nav3
// loads <SCRIPT LANGUAGE="JavaScript1.2">.
// updated 020131 by dragle
var is_js;
if (is_nav2 || is_ie3) is_js = 1.0;
else if (is_nav3) is_js = 1.1;
else if ((is_opera5)||(is_opera6)) is_js = 1.3; // 020214 - dmr
else if (is_opera7up) is_js = 1.5; // 031010 - dmr
else if (is_khtml) is_js = 1.5;   // 030110 - dmr
else if (is_opera) is_js = 1.1;
else if ((is_nav4 && (minorVer <= 4.05)) || is_ie4) is_js = 1.2;
else if ((is_nav4 && (minorVer > 4.05)) || is_ie5) is_js = 1.3;
else if (is_nav5 && !(is_nav6)) is_js = 1.4;
else if (is_hotjava3up) is_js = 1.4; // new 020128 - abk
else if (is_nav6up) is_js = 1.5;

// NOTE: In the future, update this code when newer versions of JS
// are released. 
// Always check for JS version compatibility
// with > or >=.

else if (is_nav && (majorVer > 5)) is_js = 1.4;
else if (is_ie && (majorVer > 5)) is_js = 1.3;
else if (is_moz) is_js = 1.5;
else if (is_fb||is_fx) is_js = 1.5; // 032504 - dmr

// HACK: no idea for other browsers; always check for JS version 
// with > or >=
else is_js = 0.0;
// HACK FOR IE5 MAC = js vers = 1.4 (if put inside if/else jumps out at 1.3)
if ((agt.indexOf("mac")!=-1) && is_ie5up) is_js = 1.4; // 020128 - abk

// Done with minorVer testing; revert to real for N6/7
if (is_nav6up) {
   minorVer = navigator.vendorSub;
}



var is_uplevel = ( is_ie5_5up || is_gecko || is_moz || is_opera7up || is_fb || is_fx || is_nav7up)

//*****************************************************************************
// Do not remove this notice.
//
// Copyright 2000-2004 by Mike Hall.
// See http://www.brainjar.com for terms of use.
//*****************************************************************************

//----------------------------------------------------------------------------
// Code for handling the menu bar and active button.
//----------------------------------------------------------------------------

var activeButton = null;

function buttonClick(event, menuId) {

  var button;

  // Get the target button element.
//  if (browser.isIE)
  if (is_ie)
    button = window.event.srcElement;
  else
    button = event.currentTarget;

  // Blur focus from the link to remove that annoying outline.
  button.blur();

  // Associate the named menu to this button if not already done.
  // Additionally, initialize menu display.
  if (button.menu == null) {
    button.menu = document.getElementById(menuId);
    if (button.menu.isInitialized == null)
      menuInit(button.menu);
  }

  // Set mouseout event handler for the button, if not already done.
  if (button.onmouseout == null)
    button.onmouseout = buttonOrMenuMouseout;

  // Exit if this button is the currently active one.
  if (button == activeButton)
    return false;

  // Reset the currently active button, if any.
  if (activeButton != null)
    resetButton(activeButton);

  // Activate this button, unless it was the currently active one.
  if (button != activeButton) {
    depressButton(button);
    activeButton = button;
  }
  else
    activeButton = null;

  return false;
}

function buttonMouseover(event, menuId) {

  var button;

  // Activates this button's menu if no other is currently active.
  if (activeButton == null) {
    buttonClick(event, menuId);
    return;
  }

  // Find the target button element.
//  if (browser.isIE)
  if (is_ie)
    button = window.event.srcElement;
  else
    button = event.currentTarget;

  // If any other button menu is active, make this one active instead.
  if (activeButton != null && activeButton != button)
    buttonClick(event, menuId);
}

function depressButton(button) {

  var x, y;

  // Update the button's style class to make it look like it's
  // depressed.

//	 modified VT - don't see the need for this 
 // button.className += " menuButtonActive";

  // Set mouseout event handler for the button, if not already done.

  if (button.onmouseout == null)
    button.onmouseout = buttonOrMenuMouseout;
  if (button.menu.onmouseout == null)
    button.menu.onmouseout = buttonOrMenuMouseout;

  // Position the associated drop down menu under the button and
  // show it.

  x = getPageOffsetLeft(button);
  y = getPageOffsetTop(button) + button.offsetHeight;

  // For IE, adjust position.

//  if (browser.isIE) {
  if ( is_ie )
  {
    x += button.offsetParent.clientLeft;
    y += button.offsetParent.clientTop;
  }

  button.menu.style.left = x + "px";
  button.menu.style.top  = y + "px";
  button.menu.style.visibility = "visible";
}

function resetButton(button) {

  // Restore the button's style class.

  removeClassName(button, "menuButtonActive");

  // Hide the button's menu, first closing any sub menus.

  if (button.menu != null) {
    closeSubMenu(button.menu);
    button.menu.style.visibility = "hidden";
  }
}

function closeSubMenu(menu) {

  if (menu == null || menu.activeItem == null)
    return;

  // Recursively close any sub menus.

  if (menu.activeItem.subMenu != null) {
    closeSubMenu(menu.activeItem.subMenu);
    menu.activeItem.subMenu.style.visibility = "hidden";
    menu.activeItem.subMenu = null;
  }
  removeClassName(menu.activeItem, "menuItemHighlight");
  menu.activeItem = null;
}

// Handler for mouseout event on buttons and menus.
function buttonOrMenuMouseout(event) {

  var el;

  // If there is no active button, exit.

  if (activeButton == null)
    return;

  // Find the element the mouse is moving to.

//  if (browser.isIE)
  if ( is_ie )
    el = window.event.toElement;
  else if (event.relatedTarget != null)
      el = (event.relatedTarget.tagName ? event.relatedTarget : event.relatedTarget.parentNode);

  // If the element is not part of a menu, reset the active button.
  if (getContainerWith(el, "DIV", "menu") == null) {
    resetButton(activeButton);
    activeButton = null;
  }
}

//----------------------------------------------------------------------------
// Code to initialize menus.
//----------------------------------------------------------------------------

function menuInit(menu) {

  var itemList, spanList;
  var textEl, arrowEl;
  var itemWidth;
  var w, dw;
  var i, j;

  // For IE, replace arrow characters.

//  if (browser.isIE) {
  if ( is_ie )
  {
    menu.style.lineHeight = "2.5ex";
    spanList = menu.getElementsByTagName("SPAN");
    for (i = 0; i < spanList.length; i++)
      if (hasClassName(spanList[i], "menuItemArrow")) {
        spanList[i].style.fontFamily = "Webdings";
        spanList[i].firstChild.nodeValue = "4";
      }
  }

  // Find the width of a menu item.

  itemList = menu.getElementsByTagName("A");
  if (itemList.length > 0)
    itemWidth = itemList[0].offsetWidth;
  else
    return;

  // For items with arrows, add padding to item text to make the
  // arrows flush right.

  for (i = 0; i < itemList.length; i++) {
    spanList = itemList[i].getElementsByTagName("SPAN");
    textEl  = null;
    arrowEl = null;
    for (j = 0; j < spanList.length; j++) {
      if (hasClassName(spanList[j], "menuItemText"))
        textEl = spanList[j];
      if (hasClassName(spanList[j], "menuItemArrow"))
        arrowEl = spanList[j];
    }
    if (textEl != null && arrowEl != null) {
      textEl.style.paddingRight = (itemWidth 
        - (textEl.offsetWidth + arrowEl.offsetWidth)) + "px";
      // For Opera, remove the negative right margin to fix a display bug.
//      if (browser.isOP)
	  if ( is_opera )
        arrowEl.style.marginRight = "0px";
    }
  }

  // Fix IE hover problem by setting an explicit width on first item of
  // the menu.

//  if (browser.isIE) {
  if ( is_ie )
  {
    w = itemList[0].offsetWidth;
    itemList[0].style.width = w + "px";
    dw = itemList[0].offsetWidth - w;
    w -= dw;
    itemList[0].style.width = w + "px";
  }

  // Mark menu as initialized.

  menu.isInitialized = true;
}

//----------------------------------------------------------------------------
// General utility functions.
//----------------------------------------------------------------------------

function getContainerWith(node, tagName, className) {

  // Starting with the given node, find the nearest containing element
  // with the specified tag name and style class.

  while (node != null) {
    if (node.tagName != null && node.tagName == tagName &&
        hasClassName(node, className))
      return node;
    node = node.parentNode;
  }

  return node;
}

function hasClassName(el, name) {

  var i, list;

  // Return true if the given element currently has the given class
  // name.

  list = el.className.split(" ");
  for (i = 0; i < list.length; i++)
    if (list[i] == name)
      return true;

  return false;
}

function removeClassName(el, name) {

  var i, curList, newList;

  if (el.className == null)
    return;

  // Remove the given class name from the element's className property.
  newList = new Array();
  curList = el.className.split(" ");
  for (i = 0; i < curList.length; i++)
    if (curList[i] != name)
      newList.push(curList[i]);
  el.className = newList.join(" ");
}

function getPageOffsetLeft(el) {

  var x;

  // Return the x coordinate of an element relative to the page.
  x = el.offsetLeft;
  if (el.offsetParent != null)
    x += getPageOffsetLeft(el.offsetParent);

  return x;
}

function getPageOffsetTop(el) {

  var y;

  // Return the x coordinate of an element relative to the page.

  y = el.offsetTop;
  if (el.offsetParent != null)
    y += getPageOffsetTop(el.offsetParent);

  return y;
}

//*****************************************************************************
// Copyright 2004 by Victor Taylor.
//*****************************************************************************
function tabSelect(tabId)
{
	if (document.getElementById)
	{
		var tab;
		tab = document.getElementById(tabId);
		tab.className = "menuButtonSelected";
		return;
	}
}
