
// Global string variables for image locations...
var gsIMAGE_EXPAND = "/Publications/images/plus.gif"
var gsIMAGE_COLLAPSE = "/Publications/images/minus.gif"

//-------------------------------------------------------------------------------------

function ShowHideDiv(vsDivId, vsImageId)
{
	// If the element exists...
	if (document.getElementById(vsDivId))
	{
		// If it is currently hidden...
		if (document.getElementById(vsDivId).style.display == 'none')
		{
			// Toggle it so that it will be displayed...
			ShowDiv(vsDivId)
			
			// If there is an image associated with the element...
			if (document.getElementById(vsImageId))
			{
				// Display the image as well...
				ShowImage(vsImageId)
			}
		}
		else
		{
			// The elment is currently being displayed, so toggle it to be hidden...
			HideDiv(vsDivId)

			// If there is an image associated with the element...
			if (document.getElementById(vsImageId))
			{
				// Hide the image as well...
				HideImage(vsImageId)
			}

		}
	}
}

//-------------------------------------------------------------------------------------

function ShowDiv(vsDivId)
{
	if (document.getElementById(vsDivId))
	{
		document.getElementById(vsDivId).style.display = '';
	}
}

//-------------------------------------------------------------------------------------

function HideDiv(vsDivId)
{
	if (document.getElementById(vsDivId))
	{
		document.getElementById(vsDivId).style.display = 'none';
	}
}

//-------------------------------------------------------------------------------------

function ShowImage(vsImageId)
{
	// Preload image...
	var imgExpand = new Image();
	var imgCollapse = new Image();
	imgExpand.src = gsIMAGE_EXPAND;
	imgCollapse.src = gsIMAGE_COLLAPSE;

	if (document.getElementById(vsImageId))
	{
		document.getElementById(vsImageId).style.display = '';
	}
}

//-------------------------------------------------------------------------------------

function HideImage(vsImageId)
{
	// Preload image...
	var imgExpand = new Image();
	var imgCollapse = new Image();
	imgExpand.src = gsIMAGE_EXPAND;
	imgCollapse.src = gsIMAGE_COLLAPSE;

	if (document.getElementById(vsImageId))
	{
		document.getElementById(vsImageId).style.display = 'none';
	}
}

//-------------------------------------------------------------------------------------
//This method is called from the Results page to show the bodies
//of all results tables
function showAllPubTables(vsLanguage)
{
	var sLinkText
	
	var imgMinus = new Image();
	imgMinus.src = gsIMAGE_COLLAPSE;

	var tableList = document.getElementsByTagName("table");
		
	switch (vsLanguage.toUpperCase()) {
		case "ENGLISH":
			sLinkText = "<a href=\"javascript:void(0)\" style=\"cursor:pointer;cursor:hand\" language=\"JavaScript\" onclick=\"hideAllPubTables('English');\" title=\"Click to hide the results for all Publication Categories.\">Hide All</a><br/><br/>"
			break;
			
		case "SPANISH":
			sLinkText = "<a href=\"javascript:void(0)\" style=\"cursor:pointer;cursor:hand\" language=\"JavaScript\" onclick=\"hideAllPubTables('Spanish');\" title=\"Haga “clic” para ocultar los resultados de todas las categorías de la publicación.\">Ocultar todo</a><br/><br/>"
			break;

		case "CHINESE":
			sLinkText = "<a href=\"javascript:void(0)\" style=\"cursor:pointer;cursor:hand\" language=\"JavaScript\" onclick=\"hideAllPubTables('Chinese');\" title=\"Click to hide the results for all Publication Categories.\">Hide All</a><br/><br/>"
			break;
	}
	
	if (tableList.length > 0) 
	{
		if (document.getElementById("ShowHideAll"))
		{
			document.getElementById("ShowHideAll").innerHTML = sLinkText
		}
	}
	
	for(var i = 0; i < tableList.length; i++)
	{
		if (tableList[i].id.substring(0,6) == 'Table-' )
		{
			showPubTableRowsBody(tableList[i].id.substring(6), vsLanguage);
		}
	}
}

//-------------------------------------------------------------------------------------
//This method is called from the Results page to hide the bodies
//of all results tables
function hideAllPubTables(vsLanguage)
{

	var sLinkText
	
	var imgPlus = new Image();
	imgPlus.src = gsIMAGE_EXPAND;

	var tableList = document.getElementsByTagName("table");
	
	switch (vsLanguage.toUpperCase()) {
		case "ENGLISH":
			sLinkText = "<a href=\"javascript:void(0)\" style=\"cursor:pointer;cursor:hand\" language=\"JavaScript\" onclick=\"showAllPubTables('English');\" title=\"Click to show the results for all Publication Categories.\">Show All</a><br/><br/>"
			break;
			
		case "SPANISH":
			sLinkText = "<a href=\"javascript:void(0)\" style=\"cursor:pointer;cursor:hand\" language=\"JavaScript\" onclick=\"showAllPubTables('Spanish');\" title=\"Haga “clic” para ver los resultados de todas las categorías de la publicación.\">Mostrar todo</a><br/><br/>"
			break;

		case "CHINESE":
			sLinkText = "<a href=\"javascript:void(0)\" style=\"cursor:pointer;cursor:hand\" language=\"JavaScript\" onclick=\"showAllPubTables('Chinese');\" title=\"Click to show the results for all Publication Categories.\">Show All</a><br/><br/>"
			break;
	}
	
	if (tableList.length > 0) 
	{
		if (document.getElementById("ShowHideAll"))
		{
			document.getElementById("ShowHideAll").innerHTML = sLinkText
		}
	}

	for(var i = 0; i < tableList.length; i++)
	{
		if (tableList[i].id.substring(0,6) == 'Table-' )
		{
			hidePubTableRowsBody(tableList[i].id.substring(6), vsLanguage);
		}
	}
}

//-------------------------------------------------------------------------------------
// This routine provides show/hide functionality for an individual Pub table.
// The div associated with the given table is examined and its current state
// is toggled between show/hide
function showHidePubResults(vsID, vsLanguage)
{
	var vDiv="Div-"
	
	// Look for the footer that is associated with this table.
	if (document.getElementById(vDiv + vsID) != null)
	{
		// ...and if it is currently hidden...
		if (document.getElementById(vDiv + vsID).style.display == 'none')
		{
			// ...then toggle it so that it will be displayed...
			showPubTableRowsBody(vsID, vsLanguage);
		}				
		else
		{
			// The elment is currently being displayed, so toggle it to be hidden...
			hidePubTableRowsBody(vsID, vsLanguage);
		}
	} 
}

//-------------------------------------------------------------------------------------
//This routine provides show functionality used to reveal the body of a
//results table.
function showPubTableRowsBody(vsID, vsLanguage)
{
	var sTitleText
	
	// Some images do not display correctly in certain browsers. To help 
	// alleviate this issue,  the images are pre-loaded...
	var imgMinus = new Image();
	
	var vTableRow = "TableRow-"
	var vImage = "Image-"
	var vDiv = "Div-"
	var vA = "A-"
	
	imgMinus.src = gsIMAGE_COLLAPSE;

	var trList = document.getElementsByTagName("tr");
	
	switch (vsLanguage.toUpperCase()) {
		case "ENGLISH":
			sTitleText = "Click to hide the results for this Publication Category."
			break;
			
		case "SPANISH":
			sTitleText = "Haga “clic” para ocultar los resultados de esta categoría de la publicación."
			break;

		case "CHINESE":
			sTitleText = "Click to hide the results for this Publication Category."
			break;
	}
	
	// Look at each table row on the page
	for(var i = 0; i < trList.length; i++)
	{
		// if the TR is a part of the table for the given Pub
		if ( trList[i].id == (vTableRow + vsID) )
		{
			// ...then toggle it so that it will be displayed...
			trList[i].style.display = '';
		}				
	} 
	
	// ...switch the image to collapse
	if (document.getElementById(vImage + vsID) != null)
	{
		document.getElementById(vImage + vsID).src = imgMinus.src;
		document.getElementById(vImage + vsID).title = sTitleText;
	}
	
	// ...switch the title on the link
	if (document.getElementById(vA + vsID) != null)
	{
		document.getElementById(vA + vsID).title = sTitleText;
	} 
				
	// ...reveal the div (footer with anchor)
	if (document.getElementById(vDiv + vsID) != null)
	{
		document.getElementById(vDiv + vsID).style.display = '';
	}
			
	return false;
}

//-------------------------------------------------------------------------------------
//This routine provides show functionality used to hide the body of a
//results table.
function hidePubTableRowsBody(vsID, vsLanguage)
{
	var sTitleText
	
	// Some images do not display correctly in certain browsers. To help 
	// alleviate this issue,  the images are pre-loaded...
	var imgPlus = new Image();
	
	var vTableRow = "TableRow-"
	var vImage = "Image-"
	var vDiv = "Div-"
	var vA = "A-"
	imgPlus.src = gsIMAGE_EXPAND;

	var trList = document.getElementsByTagName("tr");
	
	switch (vsLanguage.toUpperCase()) {
		case "ENGLISH":
			sTitleText = "Click to show the results for this Publication Category."
			break;
			
		case "SPANISH":
			sTitleText = "Haga “clic” para ver los resultados de esta categoría de la publicación."
			break;

		case "CHINESE":
			sTitleText = "Click to show the results for this Publication Category."
			break;
	}
	
	// Look at each table row on the page
	for(var i = 0; i < trList.length; i++)
	{
		// if the TR is a part of the table for the given Pub
		if ( trList[i].id == (vTableRow + vsID) )
		{
			// The elment is currently being displayed, so toggle it to be hidden...
			trList[i].style.display = 'none';
		}
	} 
	
	// ...switch the image to expand
	if (document.getElementById(vImage + vsID) != null)
	{
		document.getElementById(vImage + vsID).src = imgPlus.src;
		document.getElementById(vImage + vsID).title = sTitleText;
	}
	
	// ...switch the title on the link
	if (document.getElementById(vA + vsID) != null)
	{
		document.getElementById(vA + vsID).title = sTitleText;
	} 
				
	// ...hide the div (footer to the table containing anchor)
	if (document.getElementById(vDiv + vsID) != null)
	{
		document.getElementById(vDiv + vsID).style.display = 'none';
	}
			
	return false;
}

//-------------------------------------------------------------------------------------

