<!--
// define TopicsTree object
function TopicsTree() {
   if( typeof( _TopicsTree_prototype_called ) == 'undefined' ) {
      _TopicsTree_prototype_called = true;
      TopicsTree.prototype.init = init;
      TopicsTree.prototype.submit = submit;
      TopicsTree.prototype.expand = expand;
      TopicsTree.prototype.more = more;
      TopicsTree.prototype.checked = checked;
   }
   // Performs tree initialization on page load.
   // Real implementation should be provided in the onTreeInit function.
   function init( nodeN, parentN, expandOnSelect ) {
      if( window.onTreeInit ) {
         onTreeInit( nodeN, parentN, expandOnSelect );
      }
   }
   // Handles click on the tree node (topic).
   // Real implementation should be provided in the onTreeTopicClick function.
   function submit( nodeN, parentN, nodePath, action ) {
      if( window.onTreeTopicClick ) {
         onTreeTopicClick( nodeN, parentN, nodePath, action );
      }
   }
   // Handles click on the "More topics..." link.
   // Real implementation should be provided in the onTreeMoreLinkClick function.
   function more( nodeN, parentN, path ) {
      if( window.onTreeMoreLinkClick ) {
         onTreeMoreLinkClick( nodeN, parentN, path );
      }
   }
   // Handles click on the node icon.
   // Default behavior is defined. But it may be changed defining the onTreeExpand function.
   function expand( nodeN ) {
      if( window.onTreeExpand ) {
         onTreeExpand( nodeN );
      }
      else {
         showBranch( nodeN );
         swapFolder( nodeN );
      }
   }
   // Handles click on checkboxes.
   // Real implementation should be provided in the onTreeCheckboxClick function.
   function checked( nodeN, path ) {
      // change state
      var checkbox = document.getElementById( "check" + nodeN );
      if( checkbox ) {
         var idx = checkbox.src.indexOf( "uncheckedbox.gif" );
         var new_src;
         if( idx != -1 ) {
            new_src = checkbox.src.substring( 0, idx ) + "checkedbox.gif";
         }
         else {
            idx = checkbox.src.indexOf( "checkedbox.gif" );
            new_src = checkbox.src.substring( 0, idx ) + "uncheckedbox.gif";
         }
         checkbox.src = new_src;
      }
      // call custom handler if defined
      if( window.onTreeCheckboxClick ) {
         onTreeCheckboxClick( path );
      }
   }
}
// topics tree handler
var tree = new TopicsTree();


function showBranch(node){
   var branch = "branch" + node;
	var objBranch = document.getElementById(branch);
	if( !objBranch ) return;
	objBranch = objBranch.style;
	if(objBranch.display=="block")
		objBranch.display="none";
	else
		objBranch.display="block";
}

function swapFolder(node){
   var img = "folder" + node;
	var objImg = document.getElementById(img);
	if( !objImg ) return;
	if( objImg.src.indexOf( "leaf" ) > -1 ) return;

	idx = objImg.src.indexOf( "/categories/" );
	src = objImg.src.substring( 0, idx ) + "/categories/tree_node_";

	if (objImg.src.indexOf('tree_node_sub_opened.gif')>-1)
	{
		objImg.src = src + 'sub.gif';
	}
	else if (objImg.src.indexOf('tree_node_sub_opened_yellow.gif')>-1)
	{
		objImg.src = src + 'sub_yellow.gif';
	}
	else if (objImg.src.indexOf('tree_node_sub.gif')>-1)
	{
		objImg.src = src + 'sub_opened.gif';
	}
	else if (objImg.src.indexOf('tree_node_sub_yellow.gif')>-1)
	{
		objImg.src = src + 'sub_opened_yellow.gif';
	}
	else if(objImg.src.indexOf('tree_node_top.gif')>-1)
	{
		objImg.src = src + 'top_opened.gif';
	}
	else if(objImg.src.indexOf('tree_node_top_yellow.gif')>-1)
	{
		objImg.src = src + 'top_opened_yellow.gif';
	}
	else if(objImg.src.indexOf('tree_node_top_opened.gif')>-1)
	{
		objImg.src = src + 'top.gif';
	}
	else objImg.src = src + 'top_yellow.gif';
}

-->