// Copyright © 2007 Jeffrey Bazinet, http://www.vwd-cms.com/

function VwdCmsTreeList_ExpandNode(img)
{
	if (img)
	{
		img.src = img.src.replace(/tree-expand.gif/, "tree-collapse.gif");
		img.onclick = new Function("VwdCmsTreeList_CollapseNode(this);");
		var div = img.parentElement.parentElement;
		if (div)
		{
			div.style.overflow="";
			div.style.height="";
		}
	}
}

function VwdCmsTreeList_CollapseNode(img)
{
	if (img)
	{
		img.src = img.src.replace(/tree-collapse.gif/, "tree-expand.gif");
		img.onclick = new Function("VwdCmsTreeList_ExpandNode(this);");
		var div = img.parentElement.parentElement;
		if (div)
		{
			div.style.overflow="hidden";
			div.style.height = "18px";
		}
	}
}

function checkFile(checkbox)
{
	var parent = checkbox.parentElement;
	if (parent.className != "VwdCmsTreeList_node")
	{
		// set all child checkboxes to same as this one
		var container = checkbox.parentElement.parentElement; 
		checkChildren(container, checkbox.checked);
	}
}
function checkChildren(container, checked)
{
	// set all child checkboxes to checked		
	var c = null;
	var i = null;
	var chk = null;
	for (i = 0; i < container.childNodes.length; i++)
	{
		c = container.childNodes[i];
		if ( c.className == "VwdCmsTreeList_node" )
		{
			chk = c.childNodes[0];
			chk.checked = checked;
		}
		else if ( c.className == "VwdCmsTreeList_folder" )
		{
			chk = c.childNodes[1];
			chk.checked = checked;
		}
		else if ( c.className == "VwdCmsTreeList_container" )
		{
			checkChildren(c, checked);
		}
	}
}	
