/**
 * @fileoverview
 * Provides methods for hiding and showing an element.
 */
 
/**
 * Flips the visibility of the element and the plus / minus sign associated with the link.
 * The id of the plus/minus image must be elementId + '_plusminus'.
 *
 * @param(String) elementId the id of the element in the document that you want to show/hide.
 */
function toggleShowHideOfElementAndPlusMinus(elementId) {

    // flip the image
    var pmImage = getElementById(elementId + '_plusminus');
    var altImg = pmImage.getAttribute('altsrcimage');;
    pmImage.setAttribute('altsrcimage', pmImage.src);
    pmImage.src = altImg;
    
    // flip the element
    if (isHidden(elementId)) {
        show(elementId);
    }
    else {
        hide(elementId);    
    }
}

/**
 * Shows or hides the element and sets the image as appropriate.
 * 
 * @param(boolean) booleanShow 		True to show the element, false to hide it.
 * @param(String) elementId the 	Id of the element in the document that you want to show/hide.
 * @param(String) imageWhenShown 	The image to display when the element is shown
 * @param(String) imageWhenHidden	The image to display when the element is hidden
 */
function showElementAndPlusMinus(booleanShow, elementId, imageWhenShown, imageWhenHidden) {
    var pmImage = getElementById(elementId + '_plusminus');
	if (booleanShow) {
	    show(elementId);
	    pmImage.setAttribute('altsrcimage', imageWhenHidden);
	    pmImage.src = imageWhenShown;
	} 
	else {
	    hide(elementId);
	    pmImage.setAttribute('altsrcimage', imageWhenShown);
	    pmImage.src = imageWhenHidden;
	} 
}

/**
 * Hide the element specified by elementId
 * @param {String} elementId the element id in the document that you want to hide
 */
function hide(elementId)
{
	var element = getElementById(elementId);
	hideElement(element);
}

function hideElement(element)
{
	element.style.display = "none";
}

function isHidden(elementId)
{
	var element = getElementById(elementId);
	return isElementHidden(element);
}

/**
 * Checks the div (or span) is displayed.  Recursively check all
 * parent elements in case one of those is hidden.
 */
function isDivOrSpanDisplayed(divOrSpan)
{
	var body=window.document.body;
	var parentElement = divOrSpan;
	while(parentElement !=  body) {
		if(parentElement.style.display=="none" || parentElement.style.visibility=="hidden" ) {
			return false;
		}
		else {
			parentElement=parentElement.parentNode;
		}
	}
	return true; 
}

function isElementHidden(element)
{
	return element.style.display == "none";
}

/**
 * Show the element specified by elementId
 * @param {String} elementId the element id in the document that you want to show
 */
function show(elementId)
{
	var element = getElementById(elementId);
	showElement(element);
}

function showElement(element)
{
	element.style.display = "block";
}

function showSpan(elementId)
{
	var element = getElementById(elementId);
	element.style.display = "inline";
}

function showTableRow(elementId)
{
	var element = getElementById(elementId);
	showTableRowElement(element);
}

function showTableRowElement(element)
{
 	if (element.tagName == 'tr' || element.tagName == 'TR')
 	{
   		try
    	{
    		// for Firefox
        	element.style.display = "table-row";
     	}
     	catch (exception)
     	{
     		// for IE
        	element.style.display = "block";
	  	}
  	}
 }

function getElementById(id)
{
	if (document.getElementById)
	{
		return document.getElementById(id);
	}
	else if (document.all)
	{
		return document.all[id];
	}
	else if (document.layers)
	{
		return document.layers[id];
	}
}