function TreeView_OnHover(zpNodeIndex)
{
	t.GetNodeIndex()
}

function TreeView_OnExpand(zpNodeIndex)
{
	/*
		Event Handler for Treeview Expand event
	*/
	
	//Get reference to expanded node
	var opNode = tvwMain.getTreeNode(zpNodeIndex);
	var lpParentID;
	
	//Get reference to Child Nodes collection
	var arrChildNodes = opNode.getChildren();
	
	//Check to see if the child node data has already been loaded from a previous expansion
	if(arrChildNodes.length == 1)
	{
		if(arrChildNodes[0].getAttribute("id").indexOf("Dum") != -1)
		{
			//Data Needs loading
			
			//Get FunctionID
			var lpID = getSubValue(opNode.getAttribute("id"), "_", 1);
			var zpType = getSubValue(opNode.getAttribute("id"), "_", 0);
			
			//Set the currently expanding Node in a page level variable
			omExpandingNode = opNode;
			
			if (zpType == "L3")
			{
				//Get the parent L2 ID
				var opParent = opNode.getParent();
				lpParentID = getSubValue(opParent.getAttribute("id"), "_", 1);
			}
			else
				lpParentID = -1;
			
			//Fire Data Load page in hidden IFRAME
			fraData.location = "LoadTreeview.aspx?NodeType=" + zpType + "&NodeID=" + lpID + "&Level2ID=" + lpParentID;
		}
	}
}
function tvwMain_Click()
{
	//Get the clicked node
	var zpNodeID = getTreeSelectedNodeID(tvwMain);
		
	if(zpNodeID != "")
	{
		//Get the node prefix
		var zpPrefix = zpNodeID.slice(0, zpNodeID.indexOf("_"));
		
		//Get the selected numeric id
		var lpNodeID = zpNodeID.slice(zpNodeID.indexOf("_") + 1);
		
		switch(zpPrefix)
		{
			case "Lib":  //Library Notice Board
			
				main.location = "ViewLibraryNB.aspx";
				break;
				
			case "L1":	//Level 1 Area
			
				main.location = "ViewLibraryLevel1.aspx?Type=library&ID=" + lpNodeID;
				break;
				
			case "L2":	//Level 2 Area
				main.location = "ViewLibraryLevel2.aspx?Type=library&ID=" + lpNodeID;
				break;
				
			case "L3":	//Document
			
				//Open Selected document
				//openDocument("Library", lpNodeID);
				break;
				
			case "AssDoc":	//Supporting Document
			
				//Open Selected document
				//openDocument("AssDoc", lpNodeID);
				break;
		}
	}
}

function expandedNodeDataLoaded()
{
	/*
		This function is fired by the hidden page - the expanded node child functions data has loaded
	*/
	
	//Get reference to the DIV element containing the Treeview
	var opDiv = document.getElementById("divHolder");
	
	//get the current scroll values
	var lpScrollTop = opDiv.scrollTop;
	var lpScrollLeft = opDiv.scrollLeft;
	
	//Get reference to TABLE-TBODY data element in iframe
	var opTable = fraData.document.getElementById("tblData");
	
	//Remove Loading Data... dummy node
	var opChildNode = omExpandingNode.getChildren()[0];
	opChildNode.remove();
	
	//Loop through rows of IFRAME data table
	for(var i = 0; i < opTable.rows.length; i++)
	{
		//Create new Treeview Node
		var opNode = tvwMain.createTreeNode();
		var zpType = opTable.rows[i].cells[0].innerText;
		opNode.setAttribute("id", opTable.rows[i].cells[0].innerText + "_" + opTable.rows[i].cells[1].innerText);
		
		//Build up text string - wrapped in SPAN element to force control over tooltip
		var zpText;
		if (zpType == "L3")
		{
			zpText = "<a href='OpenDocument.aspx?Type=Library&ID=" + opTable.rows[i].cells[1].innerText + "' target=_blank style='text-decoration:none; color:black'>" + opTable.rows[i].cells[2].innerText + "</a>";
			if(parseInt(opTable.rows[i].cells[5].innerText) >= 1000000 && opTable.rows[i].cells[7].innerText == "0")
				zpText += "&nbsp;<img src='images/warningSmall.gif'>";
		}
		else if (zpType == "AssDoc")
		{
			zpText = "<a href='OpenDocument.aspx?Type=AssDoc&ID=" + opTable.rows[i].cells[1].innerText + "' target=_blank style='text-decoration:none; color:black'>" + opTable.rows[i].cells[2].innerText + "</a>";
			if(parseInt(opTable.rows[i].cells[5].innerText) >= 1000000)
				zpText += "&nbsp;<img src='images/warningSmall.gif'>";
		}
		else
		{
			zpText = opTable.rows[i].cells[2].innerText;
		}
		//Set Node Text
		opNode.setAttribute("text", zpText);
		
		//opNode.setAttribute("nodeData", opTable.rows[i].cells[1].innerText + "_" + opTable.rows[i].cells[2].innerText);
		var zpImage;
		
		if (zpType == "L1" || zpType == "L2")
		{
			if (opTable.rows[i].cells[7].innerText == "0")
				zpImage = "images/Library.gif";
			else
				zpImage = "images/LibraryNew.gif";
		}
		else if (zpType == "L3")
		{
			if(opTable.rows[i].cells[4].innerText == "0")
				zpImage = "images/Document.gif";
			else
				zpImage = "images/DocumentNew.gif";
				
		}
		else if (zpType == "AssDoc")
		{
			zpImage = "images/Document.gif";
		}
		opNode.setAttribute("imageUrl", zpImage);
		
		if (zpType == "L3" || zpType == "AssDoc")
		{
			if (opTable.rows[i].cells[3].innerText != "1")
			{
				opNode.setAttribute("text", "<span style='cursor:help' title='Copy can be requested from nakmo@bmtdsl.co.uk'>" + opTable.rows[i].cells[2].innerText + "</span>");
				opNode.setAttribute("id", "UC3_" + opTable.rows[i].cells[1].innerText);
				opNode.setAttribute("selectedStyle", "background-color:beige; color:rgb(0,0,128)");
				opNode.setAttribute("hoverStyle", "background-color:transparent; color:rgb(0,0,128)");
				opNode.setAttribute("defaultStyle", "background-color:transparent; color:rgb(0,0,128)");
			}
			
		}
		
		omExpandingNode.add(opNode);
		
		//Add Dummy node to newly added function node
		var opDummyNode = tvwMain.createTreeNode();
		opDummyNode.setAttribute("id", "Dum_" + opTable.rows[i].cells[0].innerText);
		opDummyNode.setAttribute("text", "Loading Data...");
		opNode.add(opDummyNode);
	}
	
	//reset the scroll values of the containing DIV element to remove "jumping" problem
	opDiv.scrollTop = lpScrollTop;
	opDiv.scrollLeft = lpScrollLeft;
}
