/*
** v2.0.20060106
**
** gMenu is a customizable collection of JavaScript routines which can be used
** to quickly create platform independent drop down menus.
**
** gMenu has been tested on IE 6.0, Netscape 7.1, FireFox 1.0, and Opera 8.5
**
** Copyright (C) 2004-2005  Brain Book Software LLC (formfields.com, info@formfields.com)
**
** This program is free software; you can redistribute it and/or
** modify it under the terms of the GNU General Public License
** as published by the Free Software Foundation; either version 2
** of the License, or (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
**
** See http://www.gnu.org/ for an up-to-date copy of the GPL.
*/
var IE_4 = document.all;
var NS_6 = document.getElementById && !document.all;
// The maximum depth of sub menus (not including the root menu)
var MAX_MENUS = 5;
// The number of milliseconds to delay before hiding a menu
var HIDE_MENU_DELAY = 500;
// The number of pixels to offset the top-left corner of the top menu from a
// root menu item.
var TOP_MENU_LEFT_OFFSET = 0;
// This array keeps track of whether the mouse is over a given menu.
var menuFocus = new Array();
for (i = 1; i <= MAX_MENUS; i++)
menuFocus["menu" + i] = false;
var activeRootMenuId;
var curItemHasChildren = false;
var hideMenuCounter = 0;
function delayHideMenu(menu) {
menuFocus[menu.id] = false;
hideMenuCounter++;
setTimeout('hideMenus()', HIDE_MENU_DELAY);
}
function getPosOffset(what, offsetType, child, isTop, directMenu) {
var totalOffset = (offsetType == "left") ? what.offsetLeft : what.offsetTop;
var parentEl = what.offsetParent;
while (parentEl != null) {
totalOffset = (offsetType == "left") ? totalOffset + parentEl.offsetLeft : totalOffset + parentEl.offsetTop;
parentEl = parentEl.offsetParent;
}
if (offsetType == "left" && (directMenu == "left" || directMenu == "top_left"))
{
if (isTop == true)
totalOffset = totalOffset - (child.offsetWidth - what.offsetWidth) - 5;
else
totalOffset = totalOffset - child.offsetWidth - what.offsetWidth;
}
if (offsetType == "top" && (directMenu == "top_left" || directMenu == "top_right"))
{
if (isTop == true)
totalOffset = totalOffset - child.offsetHeight - what.offsetHeight;
else
totalOffset = totalOffset - child.offsetHeight + 20;
}
return totalOffset;
}
function stripPx(x) {
if (x.length <= 2)
return x;
return eval(x.substr(0,x.length-2));
}
function addDimensions(x1, x2) {
return (stripPx(x1) + stripPx(x2)) + 'px';
}
// This is needed so that a user doesn't cause a js error by doing a mouse over on the menu
// before the menu has completely loaded.
function enableRootMenus() {
var i = 1;
while ( (rootMenu = document.getElementById("rootMenu" + (i++))) ) {
rootMenu.disabled = false;
}
}
function focusMenu(menu) {
menuFocus[menu.id] = true;
}
function getHighlightedClass(curClass) {
if (curClass.substr(0, 12) == 'subMenuItemL')
return 'subMenuItemLeafHighlight';
else
return 'subMenuItemHighlight';
}
function getNotHighlightedClass(curClass) {
if (curClass.substr(0, 12) == 'subMenuItemL')
return 'subMenuItemLeaf';
else
return 'subMenuItem';
}
// Highlight current item and "unhighlight" other items in current menu
function setHighlighting(selectedNode) {
for (i = 0; i < (selectedNode.parentNode).childNodes.length - 1; i++) {
var curNode = (selectedNode.parentNode).childNodes[i];
if (curNode.id == selectedNode.id) {
if (curNode.className != getHighlightedClass(curNode.className))
curNode.className = getHighlightedClass(curNode.className);
} else {
if (curNode.className != getNotHighlightedClass(curNode.className))
curNode.className = getNotHighlightedClass(curNode.className);
}
}
}
function createLink(text, url, isparent, directMenu, cssClass) {
if (url == null)
return text;
var leftpoint = '&nbsp;';
var rightpoint = '&nbsp;';
if (isparent != null)
{
if (directMenu == "left" || directMenu == "top_left")
rightpoint = '&lt;';
if (directMenu == "right" || directMenu == "top_right")
leftpoint = '&gt;';
}
return '<table width="100%" border="0" cellpadding="0" cellspacing="0"><tr><td align="center" style="width:16px; font-size:14px; color:#AA6A48;">' + rightpoint + '</td><td><a class="' + cssClass + '" href="' + url + '">' + text + '</a></td><td align="center" style="width:16px; font-size:14px; color:#AA6A48;">' + leftpoint + '</td></tr></table>';
//<a class="' + cssClass + '" href="' + url + '" style="height:100%; width:100%;">' + text + '</a>
//	'<a class="' + cssClass + '" href="' + url + '" style="height:100%; width:100%;">' + text + ' >' + '</a>';
//	return text;
}
// Fill in the sub menus. This is done every time a menu pops up.
function drawSubMenu(menuId, menuArray, directMenu) {
var menu = document.getElementById(menuId);
var html = '';
for (i = 0; i < menuArray.length; i++) {
if (menuArray[i] != null)
html += '<div id="' + menuId + "-" + i + '" class="' + (menuArray[i][2] == null ? 'subMenuItemLeaf' : 'subMenuItem"') + '"'
+ ' onmouseover="' + (menuArray[i][2] == null ? '' : 'showMenu(\'' + menuId + '\', ' + menuArray[i][2] + ', this, \'' + directMenu + '\');') + 'highlightIfNeeded(this);"'
+ '>'
+ createLink(menuArray[i][0], menuArray[i][1], menuArray[i][2], directMenu, 'subMenuItem')
+ '</div>';
}
html += '<div class="menuBottom"></div>';
menu.innerHTML = html;
return menu;
}
// Shows a level 1 menu, right below the root menus.
// Had to adjust the top location for netscape?????????
function showTopMenu(curMenu, menuArray, directMenu) {
curMenu.className = curMenu.id + 'Highlight';
if (menuFocus['menu1'])
subMenu = document.getElementById('menu1');
else
subMenu = drawSubMenu('menu1', menuArray, directMenu);
//subMenu.style.top = curMenu.offsetParent.offsetTop + curMenu.offsetParent.offsetHeight;
//subMenu.style.top = curMenu.offsetParent.offsetTop + curMenu.offsetTop + curMenu.offsetHeight;
subMenu.style.top = getPosOffset(curMenu, "top", subMenu, true, directMenu) + curMenu.offsetHeight + "px";
subMenu.style.left = getPosOffset(curMenu, "left", subMenu, true, directMenu) + TOP_MENU_LEFT_OFFSET + "px";
//subMenu.style.left = curMenu.offsetParent.offsetLeft + curMenu.offsetLeft;
//var subMenuBase = document.getElementById('menuBase1');
//subMenuBase.childNodes[0].style.height = subMenu.offsetHeight;
//subMenuBase.style.top = subMenu.style.top;
//subMenuBase.style.left = subMenu.style.left;
subMenu.style.visibility = 'visible';
//subMenuBase.style.visibility = 'visible';
menuFocus[curMenu.id] = true;
activeRootMenuId = curMenu.id;
curItemHasChildren = true;
hideMenus2();
}
function highlightIfNeeded(curItem) {
if (curItem.className != "subMenuItemHighlight")
setHighlighting(curItem);
curItemHasChildren = !(curItem.className.substr(0, 15) == "subMenuItemLeaf");
}
// Shows a level2..leveln menu, directly to the right of the selected item.
function showMenu(curMenuId, menuArray, curItem, directMenu) {
if (curItem.className == "subMenuItemHighlight")
return;
var curMenu = document.getElementById(curMenuId);
var subMenuId = 'menu' + (eval((curMenuId).substr(4,1)) + 1);
//setHighlighting(curItem);
//var subMenuBaseId = 'menuBase' + (eval((curMenuId).substr(4,1)) + 1);
//var subMenuBase = document.getElementById(subMenuBaseId);
var subMenu;
if (menuFocus[subMenuId])
subMenu = document.getElementById(subMenuId);
else
subMenu = drawSubMenu(subMenuId, menuArray);
//subMenu.style.top = curItem.offsetParent.offsetTop + curItem.offsetTop;
//subMenu.style.left = stripPx(curMenu.style.left) + curMenu.offsetWidth;
subMenu.style.top = getPosOffset(curMenu, "top", subMenu, false, directMenu) + curItem.offsetTop + "px";
subMenu.style.left = getPosOffset(curMenu, "left", subMenu, false, directMenu) + curMenu.offsetWidth + "px";
//subMenuBase.style.top = subMenu.style.top;
//subMenuBase.childNodes[0].style.height = subMenu.offsetHeight;
//subMenuBase.style.left = subMenu.style.left;
subMenu.style.visibility = 'visible';
//subMenuBase.style.visibility = 'visible';
var subSubMenuId = 'menu' + (eval((curMenuId).substr(4,1)) + 2);
hideMenu(subSubMenuId, subMenuId);
}
// Recursively check all sub menus of the current menu.
// If the mouse has left a menu and all its sub menus then hide that menu.
function hideMenu(curMenuId, parentId) {
var curMenu = document.getElementById(curMenuId);
var hideChild = true;
var childId = 'menu' + (eval((curMenu.id).substr(4,1)) + 1);
//var curMenuBaseId = 'menuBase' + (eval((curMenu.id).substr(4,1)));
//var curMenuBase = document.getElementById(curMenuBaseId);
var child = document.getElementById(childId);
if (child != null) {
hideChild = hideMenu(child.id, curMenu.id);
}
if (!menuFocus[curMenuId] && hideChild && (!menuFocus[parentId] || !curItemHasChildren)) {
curMenu.style.visibility = 'hidden';
return true;
} else {
return false;
}
}
function hideMenus() {
if (--hideMenuCounter > 0)
return;
hideMenus2();
}
function hideMenus2() {
var i = 1;
var menusHidden = hideMenu('menu1', activeRootMenuId);
while ( (rootMenu = document.getElementById("rootMenu" + (i++))) ) {
if ( (!menuFocus[rootMenu.id] && activeRootMenuId == rootMenu.id && menusHidden)
|| (activeRootMenuId != rootMenu.id && rootMenu.className == rootMenu.id + "Highlight") ) {
rootMenu.className = rootMenu.id;
}
}
}
