	var g_nTvIndex = 0;
	var g_strTv = "";
	
	var g_nLevelFilter = -1;

	// Cookie data
	//
	g_Cookie = new Array();
	
	if (document.cookie)
	{
		var strCookieSplit;
		var strSplitted;
		
		strCookieSplit = document.cookie.split(";");
		
		for (n = 0; n < strCookieSplit.length; n++)
		{
			strSplitted = strCookieSplit[n].split("=");
			
			// look for "TreeState" entry, it contains our new treeview state
			//
			if ("TreeState" == strSplitted[0])
			{
				if (strSplitted.length < 2)
					g_Cookie = "";
				else
					g_Cookie = strSplitted[1].split("!");
				break;
			}
		}
	}
	
	InitializeTreeView();

	for (g_nTvIndex = 0; g_nTvIndex < g_TvItem.length; g_nTvIndex++)
	{
		var nItemLevel, strFill;
		var n, strPreFill, strSplitted;
		
		nItemLevel = GetItemLevel(g_TvItem[g_nTvIndex]);
		
		if (g_nLevelFilter != -1)
		{
			if (nItemLevel > g_nLevelFilter)
			{	
				continue;
			}
		}
			
		g_nLevelFilter = -1;
	
		nRC = GetItemRelation(g_nTvIndex);
		
		if (nRC & 2)
			strFill = "<IMG ALIGN=AbsMiddle BORDER=0 SRC=\"images/trb.gif\">";
		else
			strFill = "<IMG ALIGN=AbsMiddle BORDER=0 SRC=\"images/tr.gif\">";

		if (nRC & 1)
		{
			if (IsItemExpanded(g_TvItem[g_nTvIndex]))
			{
				if (nRC & 2) 
					strFill = "<A HREF=\"javascript:location.reload()\" ONCLICK=\"CollapseItem('" + GetSubItem(g_TvItem[g_nTvIndex], 0) + "')\" TARGET=\"_self\"><IMG ALT=\"Click to collapse tree\" BORDER=0 ALIGN=AbsMiddle SRC=\"images/exp_m.gif\"></A>";
				else
					strFill = "<A HREF=\"javascript:location.reload()\" ONCLICK=\"CollapseItem('" + GetSubItem(g_TvItem[g_nTvIndex], 0) + "')\" TARGET=\"_self\"><IMG ALT=\"Click to collapse tree\" BORDER=0 ALIGN=AbsMiddle SRC=\"images/exp.gif\"></A>";
			}
			else
			{
				g_nLevelFilter = nItemLevel;

				if (nRC & 2) 
					strFill = "<A HREF=\"javascript:location.reload()\" ONCLICK=\"ExpandItem('" + GetSubItem(g_TvItem[g_nTvIndex], 0) + "')\" TARGET=\"_self\"><IMG ALT=\"Click to expand tree\" BORDER=0 ALIGN=AbsMiddle SRC=\"images/col_m.gif\"></A>";
				else
					strFill = "<A HREF=\"javascript:location.reload()\" ONCLICK=\"ExpandItem('" + GetSubItem(g_TvItem[g_nTvIndex], 0) + "')\" TARGET=\"_self\"><IMG ALT=\"Click to expand tree\" BORDER=0 ALIGN=AbsMiddle SRC=\"images/col.gif\"></A>";
			}
		}
		
		strPreFill = "";
		strSplitted = GetSubItem(g_TvItem[g_nTvIndex], 0).split(".");
		
		for (n = 0; n < nItemLevel - 1; n++)
		{
			var m, strTest;

			strTest = strSplitted.slice(0, n + 1).join(".");

			for (m = 0; m < g_TvItem.length; m++)
			{
				if (GetSubItem(g_TvItem[m], 0) == strTest)
					break;
			}
			
			nRC = GetItemRelation(m);
			
			if (nRC & 2)
				strPreFill += "<IMG ALIGN=AbsMiddle BORDER=0 SRC=\"images/tb.gif\">";
			else
				strPreFill += "<IMG HEIGHT=17 WIDTH=17 ALIGN=AbsMiddle SRC=\"images/blank.gif\">";

		}
		g_strTv += strPreFill + strFill;

		g_strTv += LinkItem(g_TvItem[g_nTvIndex]) + "<BR>";
	}

	/////////////////////////////////////////////////////////////////////
	//
	// functions
	//
	// checks properties of current item vs. next items
	//
	// returns: combination
	//			1 has child(s)
	//			2 has more items at same item level
	//
	function GetItemRelation(nIndex)
	{
		var nRet = 0;
		var nItemLevel = GetItemLevel(g_TvItem[nIndex]);
		
		if (nIndex + 1 < g_TvItem.length)
		{
			var n;
			var nTempLevel;

			// checks for child items
			//
			if (nItemLevel < GetItemLevel(g_TvItem[nIndex + 1]))
			{
				nRet += 1;
			}
			
			// checks for more items
			//
			for (n = nIndex + 1; n < g_TvItem.length; n++)
			{
				if (nItemLevel == (nTempLevel = GetItemLevel(g_TvItem[n])))
				{
					nRet += 2;
					break;
				}

				if (nItemLevel > nTempLevel)
				{
					if (nRet & 2)
						nRet -= 2;
					break;
				}
			}
		}

		return nRet;
	}

	// checks treeview item, if it has a link
	//
	function HasItemURL(strItem)
	{
		var strSplitted;
		
		strSplitted = strItem.split("!");
		
		if (strSplitted.length < 3)
			return false;
		else
			return true;
	}

	// retrieves the amount of levels of the current item
	//
	function GetItemLevel(strItem)
	{
		var strSplitted;
		
		strSplitted = GetSubItem(strItem, 0).split(".");
		
		return strSplitted.length;
	}
	
	// retrieves the subitem of the specified index
	//
	function GetSubItem(strItem, nIndex)
	{	
		var strSplitted;
		
		strSplitted = strItem.split("!");
		
		if (strSplitted.length < (nIndex + 1))
			return "";
		
		return strSplitted[nIndex];			
	}

	// parse cookie if specified item is expanded
	//
	function IsItemExpanded(strItem)
	{
		var strItemID, n;

		strItemID = GetSubItem(strItem, 0);
		
		for (n = 0; n < g_Cookie.length; n++)
		{
			if (g_Cookie[n].indexOf(strItemID) == 0)
				return true;
		}
		
		return false;
	}

	function ExpandItem(strItem)
	{
		var strTemp = "";
		var n;
		
		newTVState = new Array();
		var newTVStateIdx = 0;
		
		if (g_Cookie)
		{
			if (g_Cookie.length)
			{
				for (n = 0; n < g_Cookie.length; n++)
				{
					if (strItem.indexOf(g_Cookie[n]) != 0)
					{
						newTVState[newTVStateIdx++] = g_Cookie[n];
					}
				}
				
				if (newTVStateIdx)
				{
					strTemp = newTVState.join("!");
					strTemp += "!" + strItem;
				}
			}
		}
		
		if (strTemp == "")
			strTemp = strItem;
		
		document.cookie = "TreeState=" + strTemp;
	}

	function CollapseItem(strItem)
	{
		var n;

		newTVState = new Array();
		var newTVStateIdx = 0;

		if (g_Cookie)
		{
			if (g_Cookie.length)
			{
				for (n = 0; n < g_Cookie.length; n++)
				{
					if (g_Cookie[n].indexOf(strItem) == 0)
						newTVState[newTVStateIdx++] = GetParentItem(strItem);
					else
						newTVState[newTVStateIdx++] = g_Cookie[n];
				}
				
				document.cookie = "TreeState=" + newTVState.join("!");
			}
		}
	}

	function GetParentItem(strItem)
	{
		var strTemp;
		var strSplitted = strItem.split(".");

		if (strSplitted.length == 1)
			return "";

		strTemp = strSplitted.slice(0, strSplitted.length - 1);
		
		return strTemp.join(".");
	}
	
	function LinkItem(strItem)
	{
		var strSplitted;
		
		strSplitted = strItem.split("!");
		
		if (strSplitted.length < 3)
			return strSplitted[1];
		else
			return "<A HREF=\"" + strSplitted[2] + "\">" + strSplitted[1] + "</A>"
	}

