
function ShowElement(sParentId,sElementId,sAction) {
    if (sElementId.tagName) {
        // sElementId is actually an element object.
        rdShowSingleElement(sElementId,sAction)

    } else {
	    var sIds = sElementId.split(",")
	    for (k=0; k < sIds.length; k++) {

            var sId = sIds[k]
            
            var sCurrAction = sAction
            if(sId.split(":").length==2){
                //The action is in the element ID.
                sCurrAction = sId.split(":")[1]
                sId = sId.split(":")[0]
            }
            
            //When in a data table, the sParentID will have a row number.
            //It gets appended to the ID of the element so that only that row is affected.
            //Adjust the indexOf value to look for the lastIndexOf in case the user has placed _Row
            //as part of the ID.
            if (sParentId) {
                if (sParentId.lastIndexOf("_CtCol") != -1) {
                    //For crosstab columns:
                    var idSuffix = sParentId.substr(sParentId.lastIndexOf("_CtCol"))
                    //idSuffix = idSuffix.substr(0,col.indexOf("_Row")) 
                    if (sId.indexOf(idSuffix) == -1) {
                        sId = sId + idSuffix
                    }
                }else if(sParentId.lastIndexOf("_Row") != -1) {
                    //For rows in tables"
                    var idSuffix = sParentId.substr(sParentId.lastIndexOf("_Row"))
                    if (sId.indexOf(idSuffix) == -1) {
                        sId = sId + idSuffix
                    }
                }
            }

            var c = document.getElementById(sId);

            if (c==null) {
                  if (sId.indexOf("_Row") != -1) {
                        c = document.getElementById(sId.substr(0,sId.lastIndexOf("_Row")));
                  }
            }
    		
		    if (c==null) {
			    alert ("Unable to find the element with the ID value " + sId + ".")
			    return
		    }
		    
//		    if (c.id.indexOf("rdCollapsibleGroupStart")!=-1){
//		        rdShowCollapsibleGroups(c,sCurrAction)
//		    }else{
		        //Standard path:
   		        rdShowSingleElement(c,sCurrAction,sId)
//   		    }
    		
	    } //Next ID.
	}
	
	if (typeof window.rdRepositionSliders != 'undefined') {
		//Move CellColorSliders, if there are any.
		rdRepositionSliders()
	}
}


function rdShowSingleElement(c,sAction,sId) {
    //Show a single element.  "c" is the element itself.
	if(c.nodeName == "COL" && navigator.product == "Gecko" && navigator.productSub && navigator.productSub > "20041010" && (navigator.userAgent.indexOf("rv:1.8") != -1 || navigator.userAgent.indexOf("rv:1.9") != -1)) {
		//Allow table column hiding for Mozilla.
		c.style.display=""
		if (sAction=="Show"){
			c.style.visibility="";
		}else if (sAction=="Hide") {
			c.style.visibility="collapse";
		} else {
			c.style.visibility=(c.style.visibility=="" ? "collapse":"");  //Toggle.
		}
	} else {
		if (sAction=="Show"){
			c.style.display="";
		}else if (sAction=="Hide") {
			c.style.display="none";
		} else {
			c.style.display=(c.style.display=="" ? "none":"");  //Toggle.
		}
	}
	
	if (sId) {
	    var windowCurr = window
	    while (windowCurr) {
	        var rdShowElementHistory = windowCurr.document.getElementById("rdShowElementHistory")
	        if (rdShowElementHistory) {
		        rdShowElementHistory.value = rdShowElementHistory.value + sId + "=" + (c.style.display=="" ? "Show":"Hide") + ","
    		}
    		try {
                //If there's a parent, this is running as an IFRAME.  Add this shown element to the parent's ShowElementHistory. #6634
                if (windowCurr.frameElement) {
                    windowCurr = windowCurr.parent
                }else{
                    windowCurr = null
                }
            }
            catch(e){
	            windowCurr = null
	            }
            finally {}
	    }
	}
	
	if (c.style.display != "none") {
       if (typeof rdUseFadeIn != "undefined") {
	        //rdFadeElement(c.firstChild,0,1,250)
	        rdFadeElement(c,0,1,250)
	    }
		
		//Special handling for any IFrame subelements.
		//Set the SRC attribute of all subordinate IFrames so that the requested pages are downloaded now.
		
		cFrames = c.getElementsByTagName("IFRAME");
		for (var i = 0; i < cFrames.length; i++) 
		{
			var cFrame = cFrames[i];
			if (isParentVisible(cFrame,c)) 
			{
				if (true) 
				{
					var sSrc = cFrame.getAttribute("HiddenSource");
					if (sSrc != null) {   //There is no HiddenSource if the element was initially visible.
						if (cFrame.getAttribute("src") == null) {   //For nonIE
							cFrame.setAttribute("src", sSrc + "&rdRnd=" + Math.floor(Math.random() * 100000));
						}										    //For IE.
						if (cFrame.getAttribute("src").indexOf(sSrc) == -1) {
							cFrame.setAttribute("src", sSrc + "&rdRnd=" + Math.floor(Math.random() * 100000));
						}
					}
				} 
				else {
					if (cFrame.height < 2) {
						cFrame.src = cFrame.src;  // The frame hasn't been shown yet.  Refresh it.
					}
				}
			}
		}
		
		if (c.getAttribute("rdPopupPanel")=="True") {
            rdShowPopupPanel(c)
        }    

		if (typeof rdSliderElements!='undefined') {
            rdShowHiddenInputSliders(c)
        }    

    } else {  //Hiding
        if (c.getAttribute("rdPopupPanel")=="True") {
            rdHidePopupPanel(c)
        }    
	}

	//More special IFrame handling.  If this page is in a frame,
	//the frame needs to be resized from the parent window.
	try {
	    if (frameElement) {
		    if (frameElement.contentWindow) {
			    if (parent.iframeResize) {
				    parent.iframeResize(frameElement)
			    }
		    }
	    }
    }
    catch(e){}

}

function isParentVisible(cChild,cShowing) {
	// See if there are any parent elements, above the element that we're showing,
	// that are invisible.  Don't want to load an IncludeFrame in that case.
	//var cParent = cChild.parentElement
	var cParent = cChild.parentNode
	while (cParent.id != cShowing.id) {
		if (cParent.style.display == "none") {
			return false 
		} 
		cParent = cParent.parentNode
	}
	return true
}


function rdShowElementsFromHistory() {
	var hiddenShowElementHistory = document.getElementById("rdShowElementHistory")
	if (hiddenShowElementHistory) {
		var sHistory = hiddenShowElementHistory.value
		var sEvents = sHistory.split(",")
		for (i=0; i < sEvents.length; i++) {
			var sElementID = sEvents[i].split("=")[0]
			var sAction = sEvents[i].split("=")[1]
			if (document.getElementById(sElementID)) {
				ShowElement(null,sElementID,sAction)
			}
		}
		hiddenShowElementHistory.value = sHistory
	}
}

function rdColumnDisplayVisibility() {
	if(navigator.product == "Gecko" && navigator.productSub && navigator.productSub > "20041010" && (navigator.userAgent.indexOf("rv:1.8") != -1 || navigator.userAgent.indexOf("rv:1.9") != -1)) {
		var cCols = document.getElementsByTagName("COL")
		for (var i = 0; i < cCols.length; i++) {
		    if (cCols[i].style.display == "none") {
			    cCols[i].style.display = null
			    cCols[i].style.visibility = "collapse"
		    }
		}
	}
}



function rdFadeElement(ele, nOpNext, nOpLast, nDuration, nOpIncrement,x) {
    if (nOpNext > nOpLast) {
        nOpNext = nOpLast
    }

    rdSetElementOpacity(ele, nOpNext)
    
    var nFrameRate = 50
    if(!nOpIncrement){
        nOpIncrement = (nOpLast - nOpNext) / (nDuration / nFrameRate) 
    }
    
    nOpNext = nOpNext + nOpIncrement
        
    if (nOpNext <= nOpLast) {
        setTimeout(function(){rdFadeElement(ele, nOpNext, nOpLast, nDuration, nOpIncrement)},nFrameRate)
    }
}
function rdSetElementOpacity(ele, alpha) {
    var style = ele.style;
    if( style.MozOpacity != undefined ) { //Moz and older
        style.MozOpacity = alpha;
    }
    else if( style.filter != undefined ) { //IE
        if (ele.tagName.toUpperCase() == "TR") {
            for (var i=0; i < ele.childNodes.length; i++) {
                if (ele.childNodes[i].tagName.toUpperCase() == "TD") {
                    rdSetElementOpacity(ele.childNodes[i], alpha)
                }
            }
        }else{
            style.zoom = 1 //Sets currentStyle.hasLayout=true
            style.filter = "alpha(opacity=" + (alpha * 100) + ")";
            ele.filters.alpha.opacity = ( alpha * 100 );
       }
    }
    else if( style.opacity != undefined ) { //WebKit
        style.opacity = alpha;
    }
}

function rdTabsShowTabContents(sTabsId, sReportId) {

    if(typeof rdSliderElements!='undefined'){rdShowHiddenInputSliders(document.getElementById('" & sElementID & "'))};

    //The tab's contents may need to come from a RefreshElement.
    var sActiveTabId = document.getElementById("rdActiveTabId_" + sTabsId).value
    var eleActiveTab = document.getElementById("rdTabPanel_" + sActiveTabId)
    if (eleActiveTab.innerHTML.indexOf("SubmitForm(") == 0) {
        var sRefreshPageFunction = eleActiveTab.innerHTML
        eleActiveTab.innerHTML = ""
   		eval(sRefreshPageFunction)
        return 
    }
    if (eleActiveTab.innerHTML.length == 0) {
        //Ajax Refresh
        rdAjaxRequestWithFormVars("rdAjaxCommand=RefreshElement&rdRefreshTabPanel=True&rdCurrTabId=" + sActiveTabId + "&rdRefreshElementID=rdTabPanel_" + sActiveTabId + "," + sActiveTabId + "&rdReport=" + sReportId, false, "")
    }
    
    //In some cases, deselected tab panels don't get shown/hidden. Fix this.
    var eleTabs = eleActiveTab.parentNode
    for (var i=0; i < eleTabs.childNodes.length; i++) {
        if (eleTabs.childNodes[i].id == eleActiveTab.id) {
            eleTabs.childNodes[i].style.display=""
        }else{
            eleTabs.childNodes[i].style.display="none"
        }
    }
    
}



//function rdShowCollapsibleGroups(c,sAction) {
//    //Showing or hiding?
//    var sCollapseAction
//    if (sAction=="Toggle"){
//        if (c.getAttribute("rdGroupCollapsed")=="True"){
//            c.setAttribute("rdGroupCollapsed","False")
//            sCollapseAction="Show"
//        }else{
//            c.setAttribute("rdGroupCollapsed","True")
//            sCollapseAction="Hide"
//        }
//    }
//    //Look for TR elements to hide or show.
//    var sEndId = c.id.replace("rdCollapsibleGroupStart","rdCollapsibleGroupEnd")
//    sEndId = sEndId.substr(0,sEndId.lastIndexOf("_Row"))
//    var cSibling = c.nextSibling 
//    while (cSibling) {  
//        if (cSibling.id==sEndId){
//            return
//        }
//        if (cSibling.tagName=="TR"){
//            if (cSibling.id.indexOf("rdCollapsibleGroup")!=0) {
//                var nCollapseCnt = parseInt(0+cSibling.getAttribute("rdCollapseCnt"))
//                if (sCollapseAction=="Hide"){
//                    nCollapseCnt += 1
//                }else{
//                    nCollapseCnt -= 1
//                }
//                if (nCollapseCnt > 0) {
//                    rdShowSingleElement(cSibling,"Hide")
//                }else{
//                    rdShowSingleElement(cSibling,"Show")
//                }
//                cSibling.setAttribute("rdCollapseCnt",nCollapseCnt)
//            }
//        }
//        cSibling = cSibling.nextSibling    
//    } 

//}
