/*
Expand or collapse a node in a tree view, or a show or hide a block element
on a page.
*/

var former;

function visitTopic(frame, where, id)
{
/*
	If we cannot run because of an unsupported bit of Javascript, bow out now.
*/

	if (!document.getElementsByTagName || !document.getElementById)
	{
		return true;
	}

/*
	Change the background color of the link with the specified ID.
*/
	var divs;
	if (document.getElementsByTagName)
	{
		divs = document.getElementsByTagName("div");

		var progress = "";

		if (divs != null && divs.length > 0)
		{
			for (i = 0; i < divs.length; i++)
			{
				var currentDiv = divs[i];
				if ((currentDiv.id != null) && (currentDiv.id.match(/^div[0-9]+$/)))
				{
					currentDiv.style.backgroundColor = "inherit";
					progress += ".";
				}
			}
//			alert("Changed div background colors to inherit: " + progress);
		}
	}

	var visitedTopic;
	if (document.getElementById)
	{
		visitedTopic = document.getElementById("div"+id);

		if (visitedTopic != null)
		{
				if (visitedTopic.style.backgroundColor)
				{
					visitedTopic.style.backgroundColor = "#f7f7e7";
				}
				else if (visitedTopic.style.setProperty)
				{
					visitedTopic.style.setProperty("backgroundColor","#f7f7e7",null);
				}
				else if (visitedTopic.bgColor)
				{
					visitedTopic.bgColor = "#f7f7e7";
				}
				else
				{
					alert("None of the usual style-setting options are available");
				}
		}
		else
		{
			alert("No visited topic to highlight");
		}
	}
	else
	{
		alert("No browser support for getElementById");
	}

	if (parent.frames[frame])
	{
		document.lastVisitedTopic = where;
		parent.frames[frame].location = where;
	}
	else
	{
/*		alert("We are not actually inside a frame"); */
		where = where.replace(/frame=right/,"frame=");
		document.lastVisitedTopic = where;
		document.location = where;
	}

	return false;
}

function noFrames()
{
//	alert("About to hide frames...");
	if (document.lastVisitedTopic)
	{
//		alert("Setting window URL to last visited topic (" + document.lastVisitedTopic + "...");
		var unframedTopic = document.lastVisitedTopic;
		if (unframedTopic.match(/frame=right/))
		{
/*			alert("Mangling URL for better unframed experience..."); */
			unframedTopic = unframedTopic.replace(/frame=right/,"frame=");
		}
		top.location = unframedTopic;
	}
	else
	{
//		alert("Setting window URL to default (homepage)...");
//		top.location = "homepage";
		top.location = "portal.portal_db2?frame=";
	}
	return false;
}

function reFrame()
{
//	alert("About to show frames...");

	top.location = "portal.portal_db2";
	return false;

	if (document.lastVisitedTopic)
	{
		var unframedTopic = document.lastVisitedTopic;
		if (unframedTopic.match(/frame=right/))
		{
			unframedTopic = unframedTopic.replace(/frame=right/,"frame=");
		}
		top.location = unframedTopic;
	}
	else
	{
		top.location = "portal.portal_db2";
	}
	return false;
}

function flipEntry(name)
{
	var item = document.getElementById(name);
	var showlink = document.getElementById(name + '_show');
	var hidelink = document.getElementById(name + '_hide');

	if (item.style.display == 'none')
	{
		item.style.display = former;
		hidelink.style.display = '';
		showlink.style.display = 'none';

	}
	else
	{
		former = item.style.display;
		item.style.display = 'none';
		hidelink.style.display = 'none';
		showlink.style.display = '';
	}
}

/* Force item to be hidden. */

function hideEntry(name)
{
	var item = document.getElementById(name);
	var showlink = document.getElementById(name + '_show');
	var hidelink = document.getElementById(name + '_hide');

	if (item.style.display == 'none')
	{
		;
	}
	else
	{
		former = item.style.display;
		item.style.display = 'none';
		hidelink.style.display = 'none';
		showlink.style.display = '';
	}
}

/* Force item to be visible. */

function showEntry(name)
{
	var item = document.getElementById(name);
	var showlink = document.getElementById(name + '_show');
	var hidelink = document.getElementById(name + '_hide');

	if (item.style.display == 'none')
	{
		item.style.display = former;
		showlink.style.display = 'none';
		hidelink.style.display = '';
	}
	else
	{
		;
	}
}

/* Switch back to a single-frame view. */
function hideFrames()
{
//	alert("Asked to close frames...");

//	alert("Old location: " + window.parent.location);
//	alert("New location: " + parent.frames[1].location);

  window.parent.location.href = parent.frames[1].location.href;
}
