// These scripts were originally found on cooltype.com.
// Modified 01/01/1999 by Tobias Ratschiller for linuxapps.com

// Modified 7th June 2000 by Brian Birtles for Mozilla 5.0
// compatibility for phpMyAdmin

// Rewritten and put in a libray 2nd May 2001 by Loïc Chapeaux

// Slight modifications April 25, 2002 for mesglobal.com by Brian Sullivan

// Test passed with:
// - Mozilla 0.8.1-0.9.6 for Windows (js enabled & disabled)
// - IE5, 5.01, 5.5, 6.0 for Windows
// - Netscape 4.75 for Windows

// Test failed (crappy DOM implementations) with:
// - Opera 5.02 for windows: 'getElementsByTagName' is unsupported
// - Opera 5.10 to 5.12 for windows, Opera 5+ for Linux: 'style.display' can't
//   be changed
// - Konqueror 2+: 'style.display' can't be changed


var isExpanded   = false;

/**
 * Gets the id of the first collapsible room
 *
 * @param  string  the name of the first collapsible room
 *
 * @return  integer  the index number corresponding to this room
 *
 * @access  public
 */
function nsGetIndex(el) {
	var ind       = null;
	var theLayers = document.layers;
	var layersCnt = theLayers.length;
	for (var i = 0; i < layersCnt; i++) {
		if (theLayers[i].id == el) {
			ind = i;
			break;
		}
	}
	return ind;
} // end of the 'nsGetIndex()' function


/**
 * Positions layers under NS4+
 *
 * @access  public
 */
function nsArrangeList() {
	if (typeof(firstInd) != 'undefined' && firstInd != null) {
		var theLayers = document.layers;
		var layersCnt = theLayers.length;
		var nextY     = theLayers[firstInd].pageY + theLayers[firstInd].document.height;
		for (var i = firstInd + 1; i < layersCnt; i++) {
			if (theLayers[i].visibility != 'hide') {
				theLayers[i].pageY = nextY;
				nextY              += theLayers[i].document.height;
			}
		}
	}
} // end of the 'nsArrangeList()' function


/**
 * Expand databases at startup
 *
 * @access  public
 */
function nsShowAll() {
	var theLayers = document.layers;
	var layersCnt = theLayers.length;
	for (i = firstInd; i < layersCnt; i++) {
		theLayers[i].visibility = 'show';
	}
} // end of the 'nsShowAll()' function

/**
 * Collapses databases at startup
 *
 * @access  public
 */
function initIt()
{
	if (!capable)
		return;

	var tempColl    = null;
	var tempCollCnt = null;
	var i           = 0;

	if (is_dom) {
		tempColl = document.getElementsByTagName('DIV');
		tempCollCnt = tempColl.length;
		for (i = 0; i < tempCollCnt; i++) {
			if (tempColl[i].className == 'catitem')
				tempColl[i].style.display = 'none';
		}
	} // end of the DOM case
	else if (is_ie4up) {
		tempColl = document.all.tags('DIV');
		tempCollCnt = tempColl.length;
		for (i = 0; i <= tempCollCnt; i++) {
			if (tempColl(i).className == 'catitem')
				tempColl(i).style.display = 'none';
		}
	} // end of the IE4 case
	else if (is_nav4up) {
		var theLayers = document.layers;
		var layersCnt = theLayers.length;
		for (i = 0; i < layersCnt; i++) {
			if (theLayers[i].id.indexOf('catitem') != -1)
				theLayers[i].visibility   = 'hide';
			else
				theLayers[i].visibility   = 'show';
		}
		nsArrangeList();
	} // end of the NS4 case
} // end of the 'initIt()' function


/**
 * Collapses/expands a database when the user require this to be done
 *
 * @param  string  the name of the database to act on
 * @param  boolean whether to expand or to collapse the database content
 *
 * @access  public
 */
function expandBase(el, unexpand)
{
	if (!capable)
		return true;

	var whichEl = null;

	if (is_dom) {
		whichEl = document.getElementById(el + 'Child');
		if (whichEl.style.display == 'none') {
			whichEl.style.display  = 'block';
		}
		else if (unexpand) {
			whichEl.style.display  = 'none';
		}
	} // end of the DOM case
	else if (is_ie4up) {
		whichEl = document.all(el + 'Child');
		if (whichEl.style.display == 'none') {
			whichEl.style.display  = 'block';
		}
		else if (unexpand) {
			whichEl.style.display  = 'none';
		}
	} // end of the IE4 case
	else if (is_nav4up) {
		whichEl = document.layers[el + 'Child'];
		if (whichEl.visibility == 'hide') {
			whichEl.visibility  = 'show';
		}
		else if (unexpand) {
			whichEl.visibility  = 'hide';
		}
		nsArrangeList();
	} // end of the NS4 case
	return true;
} // end of the 'expandBase()' function


//window.onload = initIt;
