var open_nodes = new Object(); //stores any open filenodes

function update_nodememory()
{
	var node_string = open_nodes.toJSONString();

	document.tree_form.node_memory.value = node_string;
	document.tree_confirm.node_memory.value = node_string;
	
	if(document.tree_upload)
	{
		document.tree_upload.node_memory.value = node_string;
	}
}

function toggle_node(id)
{
	ul = document.getElementById(id + "_contents");
	link = document.getElementById(id + "_link");
	
	if(ul.className == "contents_open")
	{
		link.className = "node_closed";
		ul.className = "contents_closed";
		open_nodes[id] = "closed";
		update_nodememory();
	}
	else
	{
		link.className = "node_open";
		ul.className = "contents_open";
		open_nodes[id] = "open";
		update_nodememory();
	}
}

function hide_options(id)
{
	document.getElementById(id).className = "options_closed";
}

function show_options(id)
{
	document.getElementById(id).className = "options_open";
}

function hide_all()
{
	if(document.getElementById("notice_container"))
	{
		document.getElementById("notice_container").style.display = "none";
	}
	
	document.getElementById("confirm_container").style.display = "none";
	document.getElementById("form_container").style.display = "none";
	
	if(document.upload_form)
	{
		document.getElementById("upload_container").style.display = "none";
	}
}

function show_form(label,action,node,default_value)
{
	hide_all();
	form = document.tree_form;

	form.submit.value = label; //set the submit label
	form.action.value = action; //set the action
	form.node.value = node; //set the nodeectory
	document.getElementById("form_container").style.display = "block"; //show the form
	form.tree_form_field.value = default_value; //set the field to the default
	form.tree_form_field.focus(); //focus on the field
}

function show_confirm(label,action,node)
{
	hide_all();
	form = document.tree_confirm;

	document.getElementById("tree_confirm_label").innerHTML = label; //set the label
	form.action.value = action; //set the action
	form.node.value = node; //set the nodeectory
	document.getElementById("confirm_container").style.display = "block"; //show the form
}

function show_upload(node)
{
	hide_all();
	form = document.tree_upload;

	form.node.value = node;

	document.getElementById("upload_container").style.display = "block"; //show the form
}

function validate_tree_form()
{
	if(document.tree_form.tree_form_field.value == "")
	{
		return false;
	}
	else
	{
		return true;
	}
}




