var browser = '';

if (browser == '')
{
	if (navigator.appName.indexOf('Microsoft') != -1)
   	browser = 'IE'
	else if (navigator.appName.indexOf('Netscape') != -1)
		browser = 'Netscape'
	else browser = 'Unknown';
}

//------------------------------------------------------------------
// helper functions
//------------------------------------------------------------------

function showSectionName( sectionName )
{
	var section = document.getElementById( sectionName );
	if( section.visible == true )
	{
		section.visible = false;
		newdisplay = 'none';
	}
	else
	{
		section.visible = true;
		newdisplay = (browser == 'IE')? "block" : "table-row";
	}
	// switch rows' visibility
	var i = 1;
	while( line = document.getElementById( sectionName+'-'+i ) )
	{
		line.style.display = newdisplay;
		i++;
	}

	// switch background and link
	var cells =	section.getElementsByTagName("th");	
	for( i=0, n = cells.length; i<n; i++)
	{
		if( section.visible == true )
		{
			cells[i].oldbgcolor = cells[i].style.backgroundColor;
			cells[i].oldbgimg = cells[i].style.backgroundImage;
			cells[i].style.background = "#7F7772";
		}
		else
		{
			cells[i].style.backgroundColor = cells[i].oldbgcolor;
			cells[i].style.backgroundImage = cells[i].oldbgimg;
		}
	}
	cells = section.getElementsByTagName("td");	
	for( i=0, n = cells.length; i<n; i++)
	{
		if( section.visible == true )
		{
			cells[i].oldbgcolor = cells[i].style.backgroundColor;
			cells[i].style.backgroundColor = "#7F7772";
		}
		else
			cells[i].style.backgroundColor = cells[i].oldbgcolor;
	}
	// switch link color and icon
	links = section.getElementsByTagName("a");	
	for( i=0, n = links.length; i<n; i++)
		if( links[i].className == 'expand' )
			if( section.visible == true )
			{
				links[i].style.backgroundPosition = '0 -72px';
				links[i].style.color = "white"
			}
			else
			{
				links[i].style.backgroundPosition = '0 1px';
				links[i].style.color = "black"
			}

}

//--------------------------------------------

function switchAll( expand )
{
	table = document.getElementById("T");
	var rows = table.getElementsByTagName("tr");	
	for( var r = 0; r < rows.length; r++ )
	{	
		if( (rows[r].id != '') && (rows[r].className != 'hidden') )
		{
			if( expand )
			{
				if( rows[r].visible != true )	
					showSectionName( rows[r].id );
			}
			else
			{
				if( rows[r].visible == true )					
					showSectionName( rows[r].id );
			}
		}
	}

}

//------------------------------------------------------------------
// Functions to call from html
//------------------------------------------------------------------
function showSection(sectionID)
{
	showSectionName( 'line' + sectionID );
}

function expandAll()
{
	switchAll( true );
}

function collapseAll()
{
	switchAll( false );
}
