function GetOpenedContentList( src )
{
	var work, list ="" , sublist, i;
	
	if(Debug == 2)
		return "";

	if(typeof(src.childNodes) == "undefined")
		return "";
	
	for(i=0;i<src.childNodes.length;i++)
	{
		work = src.childNodes[i];
		if(typeof(work.className) != "undefined" && work.className == "open")
		{
			list = (list.length != 0 ? list + ',' + i : i.toString());

			work = src.childNodes[++i];
			if( typeof(work.tagName) != "undefined" && work.tagName == "DIV")
			{
				if(list.length != 0 && (sublist = GetOpenedContentList( work )) != "")
					list += "<" + sublist + ">";
			}
		}
	}
	return list;
}

function MakeHistory( src )
{
	var work = new Date();
	work.setTime(work.getTime() + 1800000);
	document.cookie = document.location + "=" + GetOpenedContentList(src) + ";" + work.toString();
	if(Debug == 1)
		alert(document.cookie);
}

function OpenContent( node,list,expand,newer)
{
	var work,sublist;
	while(list != "")
	{
		work = parseInt(list.match(/[0-9]+/));
		if(work < node.childNodes.length-1)
		{
			if(newer)
				node.childNodes[work].insertAdjacentHTML("BeforeEnd","<img src='"+ DocRoot + "new.gif'>");

			if(node.childNodes[work+1].id == "node")
			{
				if(expand)
				{
					node.childNodes[work].className = "open";
					node.childNodes[work].childNodes[0].src = DocRoot + "tri-d.gif";
					node.childNodes[work+1].style.display = "block";
				}

				list = list.replace(/[0-9]+/,"");
				if(list.charAt(0) == '<')
				{
					sublist = list.match(/\<[0-9,]+\>/);
					list = list.replace(/\<[0-9,]+\>/,"");
					OpenContent(node.childNodes[work+1],String(sublist).replace(/[\<\>]/g,""),expand,newer);
				}
				list = list.substring(1,100);
			}else
			{
				alert(node.childNodes[work].id);
				break;
			}
		}else
		{
			alert(node.childNodes.length);
			break;
		}
	}
}

function OnClickHandler()
{
	var bOpened, work, parent, i;
	
	work = window.event.srcElement;
	bOpened = false;

	while(work != null && work != document)
	{
		if( typeof(work.className) != "undefined" )
		{
			switch(work.className)
			{
			case "open":
				bOpened = true;
			case "close":
				parent = work.parentNode;
				for(i=0;i<parent.childNodes.length; i++)
					if( parent.childNodes[i] == work )
						break;
				if( i == parent.childNodes.length )
					return;
				parent.childNodes[i+1].style.display = bOpened ? "none" : "block";
				work.className = bOpened ? "close" : "open";
				work.childNodes[0].src = DocRoot + (bOpened ? "tri-r.gif" : "tri-d.gif");

				return work;
			
			case "jump":
				document.URL = work.src;
				return null;
			}
		}
		work = work.parentNode;
	}
	return null;
}

function OnClickHandlerWithCookieHistory()
{
	var work;
	
	if((work = OnClickHandler()) != null)
		MakeHistory(eval(work.src));
}

function CreateTreeNode ( src, level, topname )
{
	var i, work, buffer, hl;

	if(typeof(toplevelnode) == "undefined")
		toplevelnode = src;

	hl = level > 3 ? 3 : level;

	buffer = "";
	for(i=0; i < src.childNodes.length; i++)
	{
		with(src.childNodes[i])
		{
			switch(nodeName)
			{
			case "DIV":
				switch(id)
				{
				case "node":
					buffer += "<h" + hl + " class='close' src='" + topname + "'><img src='" + DocRoot + "tri-r.gif'>" + innerHTML + "</h" + hl + ">";
					buffer += "<div class='level2' style='display:none' id='node'>";
					buffer += CreateTreeNode(src.childNodes[i+1], level+1, topname);
					buffer += "</div>";
					i++;
					break;

				case "jump":
					if(src.substring(0,7) != "http://")
						src = "http://" + src;
					buffer += "<h" + hl + " class='jump' src='" + src + "' onmouseover='javascript:window.status=" + '"Jump to ' + src + '"' + "' onmouseout='javascript:window.status = window.defaultStatus'><img src='" + DocRoot + "jump.gif'>" + innerHTML + "</h" + hl + ">";
					break;

				case "move":
					buffer += "<h" + hl + " class='jump' src='" + src + "'><img src='" + DocRoot + "move.gif'>" + innerHTML + "</h" + hl + ">";
					break;

				default:
					buffer += outerHTML;
				}
				break;
			
			case "#text":
				buffer += nodeValue;
				break;
			
			default:
				buffer += outerHTML;
			}
		}
	}
	return buffer;
}

function CreateTree( src, dest, bCookie)
{
	var i,j,buffer;

	dest.innerHTML = CreateTreeNode(src, 2, dest.id);

	if(bCookie)
	{
		buffer = String(document.cookie);
		i = buffer.lastIndexOf(document.location);
		if( i != -1 )
		{
			i += String(document.location).length;
			j = buffer.indexOf(";",i);
			if( j == -1)
				j = buffer.length;
			buffer = buffer.substring(i+1,j);
			if(buffer != ";")
				OpenContent(dest,buffer,true,false);
		}
		document.onclick = OnClickHandlerWithCookieHistory;
	}else
		document.onclick = OnClickHandler;
	if(typeof(WhatsNew)!="undefined" && WhatsNew.length != 0)
		OpenContent(dest,WhatsNew,false,true);
}
