// Called upon page loading (onload handler in the body tag).
// This script sets global event handlers for the menu structure as well as
// for table row highlighting.
function setEventHandler()
{
	var cells = document.getElementById('menu').childNodes;
	for ( var i=0; i<cells.length; i++ )
	{
		if ( cells[i].nodeName.toLowerCase() != 'li' )
			continue;
		cells[i].onmouseover = Menu_HoverIn;
		cells[i].onmouseout  = Menu_HoverOut;
	}
	
	var rows = document.getElementsByTagName( 'tr' );
	for ( var i=0; i<rows.length; i++ )
	{
		var table = rows[i].parentNode.parentNode;
		if ( table.className == 'vert' || table.className == 'left' )
		{
			rows[i].onmouseover = TR_HoverIn;
			rows[i].onmouseout  = TR_HoverOut;
		}
	}
}

var Menu_class_hover = 'hover';
var TR_class_hover = 'hover';

function Menu_HoverIn()
{
	this.oldClass  = this.className;
	this.className = Menu_class_hover;
}

function Menu_HoverOut()
{
	this.className = this.oldClass;
}

function TR_HoverIn()
{
	this.oldClass  = this.className;
	this.className = TR_class_hover;
}

function TR_HoverOut()
{
	this.className = this.oldClass;
}

function openWindow(uri, width, height)
{
	if ( !width )  width = 420;
	if ( !height ) height = 400;
	
	var options = 'width='+width+',height='+height;
	
	var wndPopup = window.open( uri, 'wndPopup', options );
}

function toggleSection(id)
{
	var divid = 'table_' + id;
	var imgid = 'img_' + id;
	if ( document.getElementById(divid).style.display == 'none' )
	{
		openSection(id);
	}
	else
	{
		closeSection(id);
	}
}

function openSection(id)
{
	var divid = 'table_' + id;
	var imgid = 'img_' + id;
	document.getElementById(divid).style.display = '';
	document.getElementById(imgid).src = '/btn/small.php?i=ard';
}

function closeSection(id)
{
	var divid = 'table_' + id;
	var imgid = 'img_' + id;
	document.getElementById(divid).style.display = 'none';
	document.getElementById(imgid).src = '/btn/small.php?i=arr';
}

// calculates the x-position of the upper left corner.
function getLeftOffset( obj )
{
	if (obj == null)
		return 0;
	
	return obj.offsetLeft + getLeftOffset(obj.offsetParent);
}

// calculates the y-position of the upper left corner.
function getTopOffset( obj )
{
	if (obj == null)
		return 0;
	
	return obj.offsetTop + getTopOffset(obj.offsetParent);
}
