﻿var globalValueForHidingElements = 'none';
var globalValueForShowingElements = '';
var globalValueForShowingBlockElements = 'block';

function isVisible(element) {
    var display = element.style.display.toLowerCase();

    if (display == globalValueForHidingElements) {
        return false;
    } else {
        return true;
    }
}

function isElementVisible(elementId) {
    var element = document.getElementById(elementId);
    var display = element.style.display.toLowerCase();

    if (display == globalValueForHidingElements) {
        return false;
    } else {
        return true;
    }
}

function toggleElementVisibility(id, blnShow) {
    if (blnShow)
        showElement(id);
    else
        hideElement(id);
}

function toggleObjectVisibility(obj, blnShow) {
    if (blnShow)
        showObject(obj);
    else
        hideObject(obj);
}

function hideElement(id) {
	var el = document.getElementById(id);
	if (el != null) { el.style.display = globalValueForHidingElements; }
}
function showElement(id) {
    var el = document.getElementById(id);
    if (el != null) { el.style.display = globalValueForShowingElements; }
}

function hideObject(obj) {
    if (obj != null) { obj.style.display = globalValueForHidingElements; }
}
function showObject(obj) {
    if (obj != null) { obj.style.display = globalValueForShowingElements; }
}

function isObjectHidden(obj) {
    if (obj != null) { return (!StringIsNullOrEmpty(obj.style.display) && obj.style.display.toLowerCase() == globalValueForHidingElements); }
}

function isObjectShown(obj) {
    if (obj != null) { return (obj.style.display == null || obj.style.display.toLowerCase() == 'block' || obj.style.display == globalValueForShowingElements); }
}

function StringIsNullOrEmpty(obj) {
    return ((obj == null) || obj == globalValueForShowingElements);
}

/*
 *  Putting this in here because other scripts expecting these functions
 */
function hidelayer(id) {
	var el = document.getElementById(id);
	if (el != null) { el.style.display = globalValueForHidingElements; }
}
function showlayer(id) {
	var el = document.getElementById(id);
	if (el != null) { el.style.display = globalValueForShowingBlockElements; }
}

function ToggleCollapseTableRows(sTableID, iHideRowsAfterRowNumber, bShowAllRows) {
    var allTableRows = document.getElementById(sTableID).getElementsByTagName("tr");
    for(var i = 0 ; i < allTableRows.length ; i++)
    {
        if (bShowAllRows) {
            allTableRows[i].style.display = globalValueForShowingElements;
        } else {
            if (i >= iHideRowsAfterRowNumber)
                allTableRows[i].style.display = globalValueForHidingElements;
        }
    }
}