function getTreeSelectedNodeIndex(tvw)
{
	/*
		Created by Sam Dorling 13/12/04
		Returns the index of the selected treeview node
		
		tvw = Treeview object
	*/
	
	//Get the clicked node
	var opSelectedNode = tvwMain.getTreeNode(tvw.selectedNodeIndex);
	var opHoverNode = tvwMain.getTreeNode(tvw.hoverNodeIndex);
	
	//Get the clicked node index and ID
	if(opHoverNode != null)
		var zpNodeIndex = tvw.hoverNodeIndex;
	else if(opSelectedNode != null)
		var zpNodeIndex = tvw.selectedNodeIndex;
	else
		var zpNodeIndex = "";
		
	return zpNodeIndex;
}

function getTreeSelectedNodeID(tvw)
{
	/*
		Created by Sam Dorling 13/12/04
		Returns the id of the selected treeview node
		
		tvw = Treeview object
	*/
	
	//Get the clicked node
	var opSelectedNode = tvwMain.getTreeNode(tvw.selectedNodeIndex);
	var opHoverNode = tvwMain.getTreeNode(tvw.hoverNodeIndex);
	
	//Get the clicked node index and ID
	if(opHoverNode != null)
		var zpNodeID = opHoverNode.getAttribute("ID");
	else if(opSelectedNode != null)
		var zpNodeID = opSelectedNode.getAttribute("ID");
	else
		var zpNodeID = "";
		
	return zpNodeID;
}

function getTreeSelectedNode(tvw)
{
	/*
		Created by Sam Dorling 10/01/05
		Returns the selected treeview node
		
		tvw = Treeview object
	*/
	
	//Get the clicked node
	var opSelectedNode = tvwMain.getTreeNode(tvw.selectedNodeIndex);
	var opHoverNode = tvwMain.getTreeNode(tvw.hoverNodeIndex);
	
	//Get the clicked node index and ID
	if(opHoverNode != null)
		var opNode = opHoverNode;
	else if(opSelectedNode != null)
		var opNode = opSelectedNode;
	else
		var opNode = null;
		
	return opNode;
}

function getOffsetLeft(el)
{
	var parent = el.offsetParent;
	var offsetLeft = el.offsetLeft;
	
	while(parent.tagName.toLowerCase() != "body")
	{
		offsetLeft += parent.offsetLeft;
		parent = parent.offsetParent;
	}
	
	return offsetLeft;
}

function getOffsetTop(el)
{
	var parent = el.offsetParent;
	var offsetTop = el.offsetTop;
	
	while(parent.tagName.toLowerCase() != "body")
	{
		offsetTop += parent.offsetTop;
		parent = parent.offsetParent;
	}
	
	return offsetTop;
}
/*function getOffsetTop(element)
{
	// Author:	Jon Peters:
	// Date:	04/11/05
	// Purpose: Loop through parent structure and get total offset top

	var opParent = element.offsetParent;
	var lpOffset = element.offsetTop;
	try
	{
		while (1 != 2)
		{
			// If div has overflow set then this is end of offset
			if(opParent.nodeName == "DIV")
			{
				if (opParent.style.overflow == "auto" || opParent.style.overflowY == "auto")
				{
					return lpOffset;
				}
			}		

			lpOffset += opParent.offsetTop;

			if (opParent.style.borderTopWidth)
				lpOffset += parseInt(opParent.style.borderTopWidth);

			opParent = opParent.offsetParent;
		}
	}
	catch(e)
	{
		return lpOffset;
	}
}*/

function GetDateObjectFromShortDateString(dateStr) 
{ 
    if(!(dateStr == null) && !(dateStr.length == 0)) 
    { 
        var newDate = new Date(); 

        if(dateStr.slice(0, 1) == "0") 
			var day = parseInt(dateStr.slice(1, 2)); 
        else 
            var day = parseInt(dateStr.slice(0, 2)); 

        if(dateStr.slice(3, 4) == "0") 
			var month = parseInt(dateStr.slice(4, 5)); 
        else 
            var month = parseInt(dateStr.slice(3, 5)); 

        var year = dateStr.slice(6, 10); 

        newDate.setDate(day); 
        newDate.setMonth(month - 1); 
        newDate.setYear(year); 
        newDate.setHours(0, 0, 0, 0); 
        
        return newDate; 
    } 
    else 
		return null; 
} 

function openDocument(zpType, lpDocID)
{
	newWin = window.open("OpenDocument.aspx?Type=" + zpType + "&ID=" + lpDocID);
	newWin.focus();
}

function getSubValue(zpValue, zpDelimitor, lpIndex)
{
	/*
		Sam Dorling 10/01/05
		Retrieves a value from a delimited string at the specified index
	*/
	
	//Split Value string to array
	zpValue = new String(zpValue);
	var arrValues = zpValue.split(zpDelimitor);
	return arrValues[lpIndex];
}