var g_objOpenMenu = null;
var iMenuTestDelay = 25;

// Closes a popup menu
function closeMenu()
{
	if (g_objOpenMenu != null)
	{
		ActivateMenu(g_objOpenMenu.name, false);
		g_objOpenMenu = null;
	}
}

// Opens a popup menu, ensures only one menu open.
function openMenu(objMenuDiv, objTrigger)
{
	// if there is a currently open menu that
	// isn't the one we want open, then close it.
	if ((g_objOpenMenu != null) && (g_objOpenMenu.name != objMenuDiv.name))
	{
		closeMenu();
	}
		
	// Keep a handle to the open menu and set it's display.
	g_objOpenMenu = objMenuDiv;
	//AdjustContextMenu(objTrigger.iNodeID);
	ActivateMenu(objMenuDiv.name, true);
}


function TestForClose()
{
	// as long as there's an open menu, check to see if we need to close it.
	if (g_objOpenMenu != null)
	{
		// Test to see if the mouse is over the open menu div or the trigger.
		if (g_objOpenMenu.mutex == 1)
		{
			// it is, so just set up another timeout and bail
			setTimeout("TestForClose()", iMenuTestDelay);
			return;
		}
		else
		{
			// it isn't, so close the menu.
			closeMenu();
			return;
		}
	}
}

//////////////////////////////////////////////////
// These are the mouse event handlers that need
// to be applied to the menu objects.
//
function MenuOver(obj)
{
	obj.mutex = 1;
}

function MenuOut(obj)
{
	obj.mutex = 0;
		
	// and see if we need to close the menu
    setTimeout("TestForClose()", iMenuTestDelay);
}
//
//////////////////////////////////////////////////
	
//////////////////////////////////////////////////
// These are the mouse event handlers that need
// to be applied to the triggers.
//
function MenuTriggerOver(objTrigger, objMenu)
{
	if (objMenu == null)
		return;
		
	// Check to see if we're over the right trigger...
	if (objMenu.originatingTriggerName != objTrigger.name)
	{
		// Tell it to close.
		TestForClose();
	}

	// Always set the mutex
	objMenu.mutex = 1;

	// Only make changes if the menu is not already open...
	if ((g_objOpenMenu == null) || (objMenu.name != g_objOpenMenu.name))
	{
		// Set the originating trigger.
		objMenu.originatingTriggerName = objTrigger.name;
			
		// And open the menu
		openMenu(objMenu, objTrigger);
	}
}

function MenuTriggerOut(objTrigger, objMenu)
{
	if (objMenu == null)
		return;
		
	// deselect the mutex
	objMenu.mutex = 0;
		
	// and see if we need to close the menu
    setTimeout("TestForClose()", iMenuTestDelay);
}
//
///////////////////////////////////////////////////
	

// Switches based on browser to always do the right thing.
function GetMenu(strMenuName)
{
//	if (document.getElementById)
//		return document.getElementById(strMenuName);
//	else if (document.all)
//		return document.all[strMenuName];
//	else if (document.layers)
//		return document.layers[strMenuName];

	// Disabled for Netscape (styles don't work right,
	// and having trouble keeping menus open.)
	if (document.all)
		return document.all[strMenuName];
	else
		return null;
}

function GetStyleObj(strMenuName)
{
	if (document.getElementById)
		return document.getElementById(strMenuName).style;
	else if (document.all)
		return document.all[strMenuName].style;
	else if (document.layers)
		return document.layers[strMenuName];
}


// Turns menu display on and off.
function ActivateMenu(strMenuName, bOn)
{
	var objStyle = GetStyleObj(strMenuName);
	var objMenu = GetMenu(strMenuName);
	if (bOn == true)
	{
		// Adjust the location of the div based on where the website's
		// outer table is floating at.  Divide the client width of the
		// window minus the table size, by two, and add that to the
		// base value (103, for this case).
		var iLeftMargin = 103;
		var objTable = document.all('tblOuter');
		var iTableWidth = objTable.clientWidth;
		var iWindowWidth = window.document.body.clientWidth;
		if (iWindowWidth > iTableWidth)
			objStyle.left = iLeftMargin + parseInt((iWindowWidth - iTableWidth)/2, 10);
		else
			objStyle.left = iLeftMargin;
		
		objStyle.visibility = "visible";
	}
	else
		objStyle.visibility = "hidden";
}


// Specific for Summation
function ColorChange(objDiv, strBase, iMode)
{
	var objTR, i;
	i = 1;
	for (i=1; i<=3; i++)
	{
		objTR = document.all(strBase + '_' + i);
		if (objTR != null)
		{
			if (iMode == 1)
				objTR.className = "excontextmenuselected";
			else
				objTR.className = "";
		}
	}
}

// SRW added 8/1/02 - popup window dimensions for demo modules

function winSpec() {
    if(navigator.userAgent.indexOf("MSIE") != -1) {
    return 'toolbar=no,resizable=no,width=738,height=568,screenX=0,screenY=0'
	// SRW 3/24/03 - changed height from 588 to 568
  } else if(navigator.appName.indexOf("Netscape") != -1) {
    return 'toolbar=no,resizable=no,width=738,height=525,screenX=0,screenY=0'
	// SRW 3/24/03 - changed height from 545 to 525
  }
}

function newWindow() {

	demoWindow = window.open ("http://info.summation.com/demo/modules.htm" , "demoWin" , winSpec())

	}

// end demo modules winspec



