/*
DHTML.js
03/07/2011 TAD added return of style so that calling page can persist
*/
function toggleLayer(whichLayer)
{
	if (document.getElementById)
	{
		// this is the way the standards work
		var style2 = document.getElementById(whichLayer).style;
        //style2.display = style2.display ? "":"block";
		style2.display = iif(style2.display == "" || style2.display == "none", "block", "none");
		
	}
	else if (document.all)
	{
		// this is the way old msie versions work
		var style2 = document.all[whichLayer].style;
        //style2.display = style2.display ? "":"block";
		style2.display = iif(style2.display == "" || style2.display == "none", "block", "none");
	}
	else if (document.layers)
	{
		// this is the way nn4 works
		var style2 = document.layers[whichLayer].style;
        //style2.display = style2.display ? "":"block";
		style2.display = iif(style2.display == "" || style2.display == "none", "block", "none");
    }
    else {
    return style2.display;
    }

}


function toggleLayerInline(whichLayer)
{
	if (document.getElementById)
	{
		// this is the way the standards work
		var style2 = document.getElementById(whichLayer).style;
//		style2.display = style2.display ? "":"block";
		style2.display = iif(style2.display == "" || style2.display == "none", "inline", "none");
	}
	else if (document.all)
	{
		// this is the way old msie versions work
		var style2 = document.all[whichLayer].style;
//		style2.display = style2.display ? "":"block";
		style2.display = iif(style2.display == "" || style2.display == "none", "inline", "none");
	}
	else if (document.layers)
	{
		// this is the way nn4 works
		var style2 = document.layers[whichLayer].style;
//		style2.display = style2.display ? "":"block";
		style2.display = iif(style2.display == "" || style2.display == "none", "inline", "none");
	}
}

function toggleLayerInlineOn(whichLayer) {
    if (document.getElementById) {
        // this is the way the standards work
        var style2 = document.getElementById(whichLayer).style;
        style2.display = "inline";
    }
    else if (document.all) {
        // this is the way old msie versions work
        var style2 = document.all[whichLayer].style;
        style2.display = "inline";
    }
    else if (document.layers) {
        // this is the way nn4 works
        var style2 = document.layers[whichLayer].style;
        style2.display = "inline";
    }
}

function toggleLayerNone(whichLayer)
{
	if (document.getElementById)
	{
		// this is the way the standards work
		var style2 = document.getElementById(whichLayer).style;
		style2.display = style2.display ? "":"none";
	}
	else if (document.all)
	{
		// this is the way old msie versions work
		var style2 = document.all[whichLayer].style;
		style2.display = style2.display ? "":"none";
	}
	else if (document.layers)
	{
		// this is the way nn4 works
		var style2 = document.layers[whichLayer].style;
		style2.display = style2.display ? "":"none";
	}
}

function toggleLayerOff(whichLayer)
{
	if (document.getElementById)
	{
		// this is the way the standards work
		var style2 = document.getElementById(whichLayer).style;
		style2.display = "none";
	}
	else if (document.all)
	{
		// this is the way old msie versions work
		var style2 = document.all[whichLayer].style;
		style2.display = "none";
	}
	else if (document.layers)
	{
		// this is the way nn4 works
		var style2 = document.layers[whichLayer].style;
		style2.display = "none";
	}
}
function toggleLayerOn(whichLayer)
{
	if (document.getElementById)
	{
		// this is the way the standards work
		var style2 = document.getElementById(whichLayer).style;
		style2.display = "block";
	}
	else if (document.all)
	{
		// this is the way old msie versions work
		var style2 = document.all[whichLayer].style;
		style2.display = "block";
	}
	else if (document.layers)
	{
		// this is the way nn4 works
		var style2 = document.layers[whichLayer].style;
		style2.display = "block";
	}
}

function toggleTableRow(whichLayer) 
{
	tr = document.getElementById(whichLayer);
    if (tr) 
    {
		if (tr.style.display == "none") 
		{
			try 
			{
				tr.style.display = "table-row";
			} 
			catch(e) 
			{
				tr.style.display = "block";
			}
        }
        else 
        {
			tr.style.display = "none";
        }
	}
}

function toggleTableRowOn(whichLayer) 
{
	tr = document.getElementById(whichLayer);
    if (tr) 
    {
		try 
		{
			tr.style.display = "table-row";
		} 
		catch(e) 
		{
			tr.style.display = "block";
		}
	}
}

function toggleTableRowOff(whichLayer) 
{
	tr = document.getElementById(whichLayer);
    if (tr) 
    {
		tr.style.display = "none";
	}
}

function toggleTableBodyOn(whichLayer) 
{
	tb = document.getElementById(whichLayer);
    if (tb) 
    {
		tb.style.display = "";
	}
}

function toggleTableBodyOff(whichLayer) 
{
	tb = document.getElementById(whichLayer);
    if (tb) 
    {
		tb.style.display = "none";
	}
}

function getElement(whichLayer)
{
	var element;
	
	if (document.getElementById)
	{
		// this is the way the standards work
		element = document.getElementById(whichLayer);
	}
	else if (document.all)
	{
		// this is the way old msie versions work
		element = document.all[whichLayer];
	}
	else if (document.layers)
	{
		// this is the way nn4 works
		element = document.layers[whichLayer];
	}

	return element;
}

function iif(exp, trueexp, falseexp)
{
	if (exp) {return trueexp;} else {return falseexp;}
}

function toggleExpandCollapse(imgid)
{
    var img = document.getElementById(imgid);
    img.src = iif(img.src.indexOf("foldertree_plus.gif") > -1, img.src.replace("foldertree_plus.gif", "foldertree_minus.gif"), img.src.replace("foldertree_minus.gif", "foldertree_plus.gif"))
}

function setClassNameByTag(whichLayer, whichTag, className) {

    var element;
    var tags;
    element = getElement(whichLayer);

    if (element) {
        tags = element.getElementsByTagName(whichTag);
        for (var i = 0; i < tags.length; ++i) {
            tags[i].className = className;
        }

    }

}

function setClassNameByID(whichLayer, whichTag, whichID, matchType, className) {

    var element;
    var tags;
    element = getElement(whichLayer);
    if (element) {

        tags = element.getElementsByTagName(whichTag);

        for (var i = 0; i < tags.length; ++i) {
            if (matchType == "0") {
                if (tags[i].id == whichID) {
                    tags[i].className = className;
                }
            }
            if (matchType == "1") {

                if (tags[i].id.indexOf(whichID) > -1) {
                    tags[i].className = className;
                }
            }
        }
    }

}

function getQueryVariable(variable, url) {
    var vars = url.split("&");

    for (var i = 0; i < vars.length; i++) {
        var pair = vars[i].split("=");
        if (pair[0] == variable) {
            return pair[1];
        }
    }
}

function getQSParameter(name) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regexS = "[\\?&]" + name + "=([^&#]*)";
    var regex = new RegExp(regexS);
    var results = regex.exec(window.location.href);
    if (results == null) {
        return "";
    }
    else {
        return results[1];
    }
}

