//
// Inline IE detect to cope with browser badness
//
var isMSIE = false;
var isMSIE7 = false;
var detect = navigator.userAgent.toLowerCase();
if( detect.indexOf("msie") >= 0 )	isMSIE = true;
if( detect.indexOf("msie 7") >= 0 )	isMSIE7 = true;

//
// Show all branch bodies
//
function ShowAllBodies( topList, otherList ) {

	var IDlist;
	var i;
	var nextID;
	
	// Lower-level branches first, hope they are
	// hidden and user won't see ripple
	if( otherList.length > 0 ) {
	
		IDlist = otherList.split( "," );
		
		for( i = 0; i < IDlist.length; i++ ) {
			nextID = IDlist[i] + "_B";
			showD( nextID );						
			graphicMinus( IDlist[i] );						
		}
		
	}
	
	// Top-level branches to make it all show
	if( topList.length > 0 ) {
	
		IDlist = topList.split( "," );
		
		for( i = 0; i < IDlist.length; i++ ) {
			nextID = IDlist[i] + "_B";
			showD( nextID );						
			graphicMinus( IDlist[i] );						
		}
		
	}

	return true;
}

//
// Hide all branch bodies
//
function HideAllBodies( topList, otherList ) {

	var IDlist;
	var i;
	var nextID;
	var labelObj;

	var targetY;
				
	// Top-level branches first, for hide speed
	if( topList.length > 0 ) {
	
		IDlist = topList.split( "," );
		
		for( i = 0; i < IDlist.length; i++ ) {
			nextID = IDlist[i] + "_B";
			hideD( nextID );
			graphicPlus( IDlist[i] );						
		}
		
	}

	forceReflow( "start" );
				
	// Lower-level branches hide while in hiding
	if( otherList.length > 0 ) {
	
		IDlist = otherList.split( "," );
		
		for( i = 0; i < IDlist.length; i++ ) {
			nextID = IDlist[i] + "_B";
			hideD( nextID );						
			graphicPlus( IDlist[i] );						
		}
		
	}

	// IE nested-ghost-elimination hack.  IEvilReload is
	// assumed to be a page-scope boolean set by the markup
	// sent from the server!  Ghost elimination is not
	// needed for non-indented trees, or for IE7.
	if( isMSIE && IEvilReload && !isMSIE7 )		window.location.reload( false );
	
	return true;
}

//
// Client-side left-indent injection for any branch bodies
// and force HasLayout for bodies within IE
//
function IndentBodies( bodyList, indent ) {

	var bodyObj;
	var i;
	var nextID;

	var bodyIDs = bodyList.split( "," );

	for( i = 0; i < bodyIDs.length; i++ ) {

		nextID = bodyIDs[i] + "_B";
		bodyObj = document.getElementById( nextID );
		alert( "Runtime fixup of: "+nextID );

		bodyObj.style.marginLeft = indent;
	
		if( isMSIE ) 
			bodyObj.style.width = "100%";

	}

	return true;
}

//
// Toggle the body of a branch between hidden and shown
//
function ToggleBranch( branchID ) {

	var bodyID = branchID + "_B";
	var bodyObj = document.getElementById( bodyID );

	var imgID = branchID + "_G";
	var imgObj = document.getElementById( imgID );

	if ( bodyObj.style.display == "block" ) {
		hideD( bodyID );
		graphicPlus( branchID );
		forceReflow( "start" );
	}
	else {
		showD( bodyID );
		graphicMinus( branchID );
		forceReflow( "start" );
	}

	return true;
}

//
// Leading graphic to "push to open" display
//
function graphicPlus( branchID ) {

	var imgID = branchID + "_G";
	var imgObj = document.getElementById( imgID );

	imgObj.src = "/_images-site/toggleDLplus_11.gif";
	
	return true;
}

//
// Leading graphic to "push to close" display
//
function graphicMinus( branchID ) {

	var imgID = branchID + "_G";
	var imgObj = document.getElementById( imgID );

	imgObj.src = "/_images-site/toggleDLminus_11.gif";
	
	return true;
}

//
// Make a DIV visible
//
function showD( divID ) {

	var divObj = document.getElementById( divID );

//	alert( "About to Show: "+divID );
	divObj.style.display = "block";

	return true;
}

//
// Hide a DIV
//
function hideD( divID ) {

	var divObj = document.getElementById( divID );

//	alert( "About to Hide: "+divID );
	divObj.style.display = "none";
	
	return true;
}

//
// Object vertical location
//
function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop;
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

//
// Explicit force-reflow for page body
//
function forceReflow( step ) {

	// Forced reflow not needed for IE
	if( isMSIE ) return

	var bodyObj;
//	alert( "forceReflow, step: "+step );
				
	switch( step ) {
	
		// Tweak border and client-side scroll, reschedule
		case "start":
			bodyObj = document.getElementsByTagName( "body" )[0];
			bodyObj.style.borderBottomColor = "#ffffff";
			bodyObj.style.borderBottom = "1px solid transparent";

//			window.scrollBy( 0, 1 );
//			window.scrollBy( 0, 0 );
			window.setTimeout( "forceReflow('next')", 2 );
			
			break;
					
		// Put it back, reschedule (is another iteration/delay needed)?
		case "next":
			bodyObj = document.getElementsByTagName( "body" )[0];
			bodyObj.style.borderBottom = "";

//			window.scrollBy( 0, -1 );
//			window.scrollBy( 0, 0 );
//			window.setTimeout( "forceReflow('end')", 5 );
			
			break;
		
		default:
			break;
			
	}

	return true;	
}

// *** PARKED CRUFT ***

//	var imgID = branchID + "_G";
//	var imgObj = document.getElementById( imgID );
//	var targetY = findPosY( imgObj );

//	var divY = findPosY( divObj );
//	if ( divY != 0 ) {
//		var newY = Math.max( ( divY - 50 ), 0 );
//		window.scrollTo( 0, newY );
//	}
