// JavaScript Document
var rootNodeId = "root";	//Set the ID of the top-level DOM node in the tree
var useExpandImages = true;	//When set to true it will replace the "folder" icon with an expanded/contracted image
var backgroundColor = "#E0DFE3";

function nodeClick(node) {
	var treeParent;
	//Check to see which type of node was clicked
	if (node.nodeName=="IMG") {
		//Get the parent node for this part of the treeview
		treeParent = node.parentNode.parentNode.parentNode.parentNode;	//Equivalent to the tbody tag
		
	} else if (node.nodeName=="TR") {
		//Get the parent node for this part of the treeview
		treeParent = node.parentNode;	//Equivalent to the tbody tag
	}
	//Loop through all children (except the first child)
	for (var i=1; i < treeParent.childNodes.length; i++) {
		//Ignore nodes that are just tabs (compatibability with Mozilla...IE ignores blank space)
		if (treeParent.childNodes[i].nodeName!="#text") {
			if (treeParent.childNodes[i].style.display=="") {
				//Hide this node and all child nodes
				treeParent.childNodes[i].style.display="none";
			} else {
				//The selected node is currently hidden, let's show it
				treeParent.childNodes[i].style.display="";
			}
		}
	}
	
	var imgNode;
	//Check to see which type of node was clicked
	if (node.nodeName=="IMG") {
		//Get the image node
		imgNode = node;
	} else if (node.nodeName=="TR") {
		//Get the image node
		try {
			imgNode = node.childNodes[0].childNodes[0].childNodes[0];
		} catch(e) {
		}
		//Check to see if a valid node was found
		if (imgNode==null) {
			//Ignore nodes that are just tabs (compatibability with Mozilla...IE ignores blank space)
			//We need to step back one more node
			imgNode = node.childNodes[1].childNodes[1].childNodes[0];
		}
	}
	//Now change the expandor image
	var imgUrl = imgNode.getAttribute("src").toLowerCase();
	if (imgUrl.indexOf("plus") > -1) {
		//Node is currently displaying a contracted image, so let's now change
		//the image to show that is it has been expanded
		imgNode.setAttribute("src", imgUrl.replace("plus", "minus"));
	} else {
		//Node is currently displaying an expanded image, so let's now change
		//the image to show that is it has been contracted
		imgNode.setAttribute("src", imgUrl.replace("minus", "plus"));
	}
	
	//Check to see if we should change the "folder" icon also
	if (useExpandImages==true) {
		var folderIcon;
		//Check to see which type of node was clicked
		if (node.nodeName=="IMG") {
			//Get the folder icon node
			folderIcon = node.parentNode.parentNode.parentNode.childNodes[1].childNodes[0].childNodes[0];
			//Check to see if a valid node was found
			if (folderIcon==null||folderIcon.nodeName=="#text") {
				//Ignore nodes that are just tabs (compatibability with Mozilla...IE ignores blank space)
				//We need to step back one more node
				folderIcon = node.parentNode.parentNode.parentNode.childNodes[3].childNodes[1].childNodes[0];
			}
		} else if (node.nodeName=="TR") {
			//Get the image node
			folderIcon = node.childNodes[1].childNodes[0].childNodes[0];
			//Check to see if a valid node was found
			if (folderIcon==null||folderIcon.nodeName=="#text") {
				//Ignore nodes that are just tabs (compatibability with Mozilla...IE ignores blank space)
				//We need to step back one more node
				folderIcon = node.childNodes[3].childNodes[1].childNodes[0];
			}
		}
		
		var folderUrl = folderIcon.getAttribute("src").toLowerCase();
		if (folderUrl.indexOf("plus") > -1) {
			//Folder icon is currently displaying a contracted image, so let's now change
			//the image to show that is it has been expanded
			folderIcon.setAttribute("src", folderUrl.replace("plus", "minus"));
		} else {
			//Folder icon is currently displaying an expanded image, so let's now change
			//the image to show that is it has been contracted
			folderIcon.setAttribute("src", folderUrl.replace("minus", "plus"));
		}
	}
}
function selectNode(node, deselectonly) {
	//Deselect current node
	var textNode;
	//Get curent selected node
	textNode = document.getElementById("selected");
	//Check to see if a valid node was found
	if (textNode!=null) {
		//Change the background back to normal
		textNode.style.backgroundColor="";
		//Remove id from the node
		textNode.removeAttribute("id");
	}

	if (deselectonly==null) {
		var treeNode;
		//Start at this node
		treeNode = node;
		
		//Check to see if this is a TR node
		if (treeNode.nodeName!="TR") {
			//Create a loop that will continue until we find the tbody tag
			do {
				//Get parent node
				treeNode = treeNode.parentNode;
			} while (treeNode.nodeName!="TR");
		}
		
		//Try and get the text span
		textNode = treeNode.childNodes[1].childNodes[0].childNodes[1];
	
		//Check to see if this a valid text node
		if (textNode==null||textNode.nodeName=="IMG") {
			//Account for empty text nodes
			textNode = treeNode.childNodes[3].childNodes[1].childNodes[1];
		}
		
		//The selected node is currently hidden, let's show it
		textNode.style.backgroundColor=backgroundColor;
		
		//Set this node as selected
		textNode.setAttribute("id", "selected");
	}
}