
/******************************************************************************
	DHTML Menu Functions
******************************************************************************/
function Browser() {
	var ua, s, i;
	this.version = 0;
	this.ok = false;
	
	ua = ua=navigator.userAgent.toLowerCase();
	
	this.isOpera = ua.indexOf('opera') != -1;
	this.isKonq = ua.indexOf('konqueror') != -1;
	this.isIE = ua.indexOf('msie') != -1;
	if (this.isIE) this.version = parseFloat(ua.substr(ua.indexOf('msie') + 4));
	this.isAol = ua.indexOf('aol') != -1;
	this.isNav = ua.indexOf('netscape6/') != -1;
	if (this.isNav) this.version = parseFloat(ua.substr(ua.indexOf('netscape6/') + 10));
	this.isGecko = ua.indexOf('gecko') != -1;
	if (this.isGecko){
		this.isNav = true;
		this.version = 6.1;
	}
	this.isSafari = ua.indexOf("safari") != -1;
	
	this.isMac = ua.indexOf('mac') != -1;
	this.isWin = ua.indexOf('win') != -1;
	this.isLin = !(this.bMac || this.bWin);
	
	this.isMacIE = this.isIE && this.isMac;
	
	this.ok = 	(this.isIE && this.isWin && this.version >= 4) || 
				(this.isIE && this.isMac && this.version >= 5) || 
				(this.isNavigator && this.version >= 5) || 
				(this.isGecko) || 
				(this.Safari);
	//alert(this.ok);
}

var browser = new Browser();
//----------------------------------------------------------------------------
// Code for handling the menu bar and active button.
//----------------------------------------------------------------------------
var activeButton = null;
function dmRootButtonGo(event, menuId, xOffset, yOffset) {
	var button;
	// Get the target button element.
	if (browser.isIE) button = window.event.srcElement;
	else button = event.currentTarget;
	
	button.blur();		// Blur focus from the link to remove that annoying outline.

	// 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) dmResetRootButton(activeButton);
	
	// Activate this button, unless it was the currently active one.
	if (button != activeButton) {
		dmDepressRootButton(button, xOffset, yOffset);
		activeButton = button;
	} else activeButton = null;
	
	return false;
}

function dmRootButtonOver(event, menuId, xOffset, yOffset) {
	var button;
	
	if (!browser.ok) return;
	bMouseOut = false;
	
	if(!xOffset) xOffset = 0;
	if(!yOffset) yOffset = 0;
	
	// Activates this button's menu if no other is currently active.
	if (activeButton == null) {
		dmRootButtonGo(event, menuId, xOffset, yOffset);
		return;
	}
	
	// Find the target button element.
	if (browser.isIE) 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) dmRootButtonGo(event, menuId, xOffset, yOffset);
}

function dmDepressRootButton(button, xOffset, yOffset) {
	var x, y;
	// opens the submenu
	
	// 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) + xOffset;
	y = getPageOffsetTop(button) + button.offsetHeight + yOffset;
	//dmHideBleeders();		//button.menu.id
	button.menu.style.left = x + "px";
	button.menu.style.top  = y + "px";
	button.menu.style.visibility = "visible";
}

function dmResetRootButton(button) {
	// Restore the button's style class.	
	removeClassName(button, "dmRootButtonActive");

	// Hide the button's menu, first closing any sub menus.
	if (button.menu != null) {
		closeSubMenu(button.menu);
		//dmUnHideBleeders();		//button.menu.id
		button.menu.style.visibility = "hidden";
	}
}

//----------------------------------------------------------------------------
// Code to handle the menus and sub menus.
//----------------------------------------------------------------------------

function dmMenuMouseover(event) {
	var menu;
	
	bMouseOut = false;
	
	// Find the target menu element.
	if (browser.isIE) menu = getContainerWith(window.event.srcElement, "DIV", "dmMenu");
	else menu = event.currentTarget;
	
	// Close any active sub menu.
	if (menu.activeItem != null) closeSubMenu(menu);
}

function dmMenuItemMouseover(event, menuId) {
	var item, menu, x, y;
	// Find the target item element and its parent menu element.
	
	bMouseOut = false;
		
	if (browser.isIE) item = getContainerWith(window.event.srcElement, "A", "dmMenuItem");
	else item = event.currentTarget;
	menu = getContainerWith(item, "DIV", "dmMenu");

	// Close any active sub menu and mark this one as active.
	if (menu.activeItem != null) closeSubMenu(menu);
	menu.activeItem = item;
	
	// Highlight the item element.
	item.className += " dmMenuItemHighlight";
	
	// Initialize the sub menu, if not already done.
	if (item.subMenu == null) {
		item.subMenu = document.getElementById(menuId);
		if (item.subMenu.isInitialized == null) menuInit(item.subMenu);
	}

	// Set mouseout event handler for the sub menu, if not already done.
	if (item.subMenu.onmouseout == null) item.subMenu.onmouseout = buttonOrMenuMouseout;
		
	// Get position for submenu based on the menu item.
	x = getPageOffsetLeft(item) + item.offsetWidth;
	y = getPageOffsetTop(item);
	
	// Adjust position to fit in view.
	var maxX, maxY;
	
	if (browser.isNav) {
		maxX = window.scrollX + window.innerWidth;
		maxY = window.scrollY + window.innerHeight;
	} else if (browser.isMacIE) {
		maxX = document.body.scrollLeft + document.body.clientWidth;
		maxY = document.body.scrollTop + document.body.clientHeight;
	} else if (browser.isIE) {
		maxX = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft) +
		(document.documentElement.clientWidth != 0 ? document.documentElement.clientWidth : document.body.clientWidth);
		maxY = Math.max(document.documentElement.scrollTop, document.body.scrollTop) +
		(document.documentElement.clientHeight != 0 ? document.documentElement.clientHeight : document.body.clientHeight);
	}
	maxX -= item.subMenu.offsetWidth;
	maxY -= item.subMenu.offsetHeight;

	if (x > maxX) x = Math.max(0, x - item.offsetWidth - item.subMenu.offsetWidth + (menu.offsetWidth - item.offsetWidth));
	y = Math.max(0, Math.min(y, maxY));
	
	//dmHideBleeders();		//item.subMenu.id

	// Position and show the sub menu.
	item.subMenu.style.left = x + 5 + "px";
	item.subMenu.style.top  = y + 5 + "px";
	item.subMenu.style.visibility = "visible";

	// Stop the event from bubbling.
	if (browser.isIE) window.event.cancelBubble = true;
	else event.stopPropagation();
}

function closeSubMenu(menu) {
	if (menu == null || menu.activeItem == null) return;
	// Recursively close any sub menus.
	if (menu.activeItem.subMenu != null) {
		closeSubMenu(menu.activeItem.subMenu);
		//dmUnHideBleeders();			//menu.activeItem.subMenu.id
		menu.activeItem.subMenu.style.visibility = "hidden";
		menu.activeItem.subMenu = null;
	}
	removeClassName(menu.activeItem, "dmMenuItemHighlight");
	menu.activeItem = null;
}


var bMouseOut = false;
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) 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", "dmMenu") == null) {
		bMouseOut = true;
		setTimeout('buttonOrMenuMouseout_2();',500);
	}
}

function buttonOrMenuMouseout_2(){
	if (bMouseOut){
		bMouseOut = false;
		dmResetRootButton(activeButton);
		activeButton = null;
	}
}

//----------------------------------------------------------------------------
// Code to initialize menus.
//----------------------------------------------------------------------------
function menuInit(menu) {
	var itemList, spanList;
	var textEl, arrowEl;
	var itemWidth;
	var w, dw;
	var i, j;
	
	// Find the width of a menu item.
	itemList = menu.getElementsByTagName("A");
	if (itemList.length > 0) itemWidth = itemList[0].offsetWidth;
	else return;
	
	if (browser.isIE && browser.isMac){
		itemList[0].style.display = 'inline';
		iMaxItemWidth = itemList[0].offsetWidth;
		for (i=1; i < itemList.length; i++) {
			itemList[i].style.display = 'inline';
			iMaxItemWidth = Math.max(iMaxItemWidth, itemList[i].offsetWidth);
			itemList[i].style.display = 'block';
		}
		for (i=0; i < itemList.length; i++) itemList[i].style.width = iMaxItemWidth;
	} else if (browser.isIE) {
		// Fix IE hover problem by setting an explicit width on first item of the menu.	
		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.
//----------------------------------------------------------------------------

/*
var colDmBleeders = new Object();
function dmHideBleeders(mnID){
	if (!colDmBleeders[mnID]) return;
	var arBleedIds = colDmBleeders[mnID];
	for (var i=0; i<arBleedIds.length; i++){
		document.getElementById(arBleedIds[i]).style.visibility = 'hidden';
	}
}
function dmUnHideBleeders(mnID){
	if (!colDmBleeders[mnID]) return;
	var arBleedIds = colDmBleeders[mnID];
	for (var i=0; i<arBleedIds.length; i++){
		document.getElementById(arBleedIds[i]).style.visibility = 'inherit';
	}
}
*/

function dmHideBleeders(){
	for (i=0; i<document.form.elements.length; i++){
		tag = document.form.elements[i];
		if (tag.type == "select-one") {
			//document.getElementById(tag.id).style.visibility = 'hidden';
			//tag.style.visibility = 'hidden';
			tag.style.display = 'none';
		}
	}	

}
function dmUnHideBleeders(){
	for (i=0; i<document.form.elements.length; i++){
		tag = document.form.elements[i];
		if (tag.type == "select-one") {
			//tag.style.visibility = 'inherit';
			tag.style.display = "";
		}
	}	
}

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[newList.length] = (curList[i]);
	el.className = newList.join(" ");
}

function getPageOffsetLeft(el) {
	var x;
	x = el.offsetLeft;
	if (browser.isSafari && getContainerWith(window.event.srcElement, "DIV", "dmMenu")){
		x -= document.getElementsByTagName('BODY').item(0).offsetLeft;
	} else if (browser.isMacIE && getContainerWith(window.event.srcElement, "DIV", "dmMenu")) {
		x += parseInt(document.body.currentStyle.marginLeft) - 8;
	}
	while (el.offsetParent != null){
		el = el.offsetParent;
		x += el.offsetLeft;
	}
	return x;
}

function getPageOffsetTop(el) {
	var y;
	y = el.offsetTop;
	//alert(el.nodeName+':'+el.offsetTop);
	if (browser.isSafari && getContainerWith(window.event.srcElement, "DIV", "dmMenu")){
		y -= document.getElementsByTagName('BODY').item(0).offsetTop;
	} else if (browser.isMacIE && getContainerWith(window.event.srcElement, "DIV", "dmMenu")) {
		y += parseInt(document.body.currentStyle.marginTop) - 6;
	}
	while (el.offsetParent != null){
		el = el.offsetParent;
		//alert(el.nodeName+':'+el.offsetTop);
		y += el.offsetTop;
	}
	return y;
}
/******************************************************************************
	END OF DHTML Menu Functions
******************************************************************************/
