// collapsetable
// Version: 2
/* Tree View Grid Properties & Functions */

        var plusImage = "http://siteresources.worldbank.org/EXTEAPASTAE/Images/plus_bullet.gif";
        var minusImage = "http://siteresources.worldbank.org/EXTEAPASTAE/Images/minus_bullet.gif";
        var imageTagPrefix = "img";
        var nodeSeparator = ".";
        var nodeHighlightColor = "ffffff";
        var nodeMouseOverColor = "ffffff";
        var n = 1;
        var ApplyStyle = true;

/*      Function to collapse a Node
        Function will be called Recursively till the Last Child of the Node
*/
        function Collapse(Node)
        {		objNode = document.getElementById(Node);
				if (ApplyStyle) objNode.style.backgroundColor=nodeHighlightColor;
				
                /* Get n'th child of Node <n starts from 1 till the last child>*/
                objChildNode = document.getElementById(Node + nodeSeparator + n);
                
                /* Get image object of Node */
                objImg  = document.getElementById(imageTagPrefix + nodeSeparator + Node);
                
                /* Check if Child exists. If does not exist then Reset n = 1 & exit function & */
                if(objChildNode != null)
                {       
                        /* Toggle the Child Status i.e. if visible then make it invisible & vis-versa */
                        if (objChildNode.style.display == "")
                        {       
                                /* Close all the Childs, Sub-Childs and so on of the Node*/
                                if (objImg != null)objImg.src = plusImage;
                                closeAllChilds(Node)
                                return;
                        }else 
                        {       
                                objChildNode.style.display = "";
                                if (objImg != null)objImg.src = minusImage;
                        }
                        /* Call Collapse for the Next Child be increamenting n*/
                        n = n + 1;
                        Collapse(Node);
                }else n = 1;
        }

        /*if p_direction = 0 then Close else Open*/
        function ExplicitCollapse(Node,p_direction)
        {       
				objNode = document.getElementById(Node);
				if (ApplyStyle) objNode.style.backgroundColor="";

                objChildNode = document.getElementById(Node + nodeSeparator + n);
                
                objImg  = document.getElementById(imageTagPrefix + nodeSeparator + Node);
                
                if(objChildNode != null)
                {       
                        if (p_direction == "0")
                        {       
                                objChildNode.style.display = "none";
                                if (objImg != null)objImg.src = plusImage;
                                if(!closeAllChilds(objChildNode.id)) return false;
                        }else 
                        {       
                                objChildNode.style.display = "";
                                if (objImg != null)objImg.src = minusImage;
                        }

                        n = n + 1;
                        ExplicitCollapse(Node,p_direction);
                }else n = 1;
        }

/*      Function to close all the childs of a Node
        As Each Child Node ID contains its Parent Node ID, Close all the rows having the Node ID as a prefix in their IDs.
*/
        function closeAllChilds(nNode)
        {       var tempNode,objTempNode,objNode,tempImg,objBody;
                objNode= document.getElementById(nNode);
				if (ApplyStyle) objNode.style.backgroundColor="";
                
                /* Get the Parent Element of Node ie. the Table Object */
				objTable = objNode.parentElement?objNode.parentElement:objNode.parentNode;
				
		var browserName=navigator.appName; 
		if (browserName=="Microsoft Internet Explorer")
		{
	        tagNm = objTable.tagName;
		}else
		{
			tagNm = "TBODY";
		}

                /* Get the Parent Element is not a Table then exit function */
                if(tagNm.toUpperCase() == "TBODY")
                {       
                        /* For each TR of the Table*/
                        for(i=0;i<objTable.rows.length;i++)
                        {       
                                /* Get the ID of the TR i.e. Node ID */
                                tempNode = objTable.rows[i].id;
                                
                                /* If the ID of the TR contains nNode then make the TR invisible*/
                                if (tempNode != nNode)
                                {       if(tempNode.indexOf(nNode) >= 0)
                                        {       objTempNode     = document.getElementById(tempNode);
                                                tempImg         = document.getElementById(imageTagPrefix + nodeSeparator + tempNode);
                                                if (tempImg != null)tempImg.src = plusImage;
                                                objTempNode.style.display = "none";
                                                if (ApplyStyle) objTempNode.style.backgroundColor="";
                                        }
                                }
                        }
                }else
                {       alert("Table Tag not found");
                        return false;
                }
                return true;
        }
/*      Function to keep a Node open onLoad
        This function also opens up the corresponding Parent Nodes of that perticular Node
*/
        function OpenNode(strNode,p_direction)
        {       var objNode;
                var arrNode = strNode.split(nodeSeparator);
                var str = "";
                for(i=0;i<arrNode.length;i++){
                        if(str == "")
                        {  str = arrNode[i];
                        }else
                        {
                           str = str + nodeSeparator + arrNode[i];
                        }
                        objNode = document.getElementById(str);
                        if (objNode != null)
                        {
                                if (p_direction == "1")
                                {
                                        ExplicitCollapse(str,p_direction);
                                }else
                                {
                                        Collapse(str);
                                }
                        }
                         
                }
        }
        
        function mOver(Node)
        {	if (ApplyStyle) {
			objNode = document.getElementById(Node);
			objNode.style.backgroundColor=nodeMouseOverColor; }
        }
        function mOut(Node)
        {		if (ApplyStyle) { 
				objNode = document.getElementById(Node);
				objImg  = document.getElementById(imageTagPrefix + nodeSeparator + Node);
				if (objImg != null)
				{	strSrc  = objImg.src;
					if(strSrc.indexOf(minusImage) < 0)
					objNode.style.backgroundColor="";
					else
					objNode.style.backgroundColor=nodeHighlightColor;
				}else
				{
					objNode.style.backgroundColor="";
				}}
        }
