/*
 * @Copyright@
 * @Common@
 */

/*
	Feel free to use your custom /HSUSWeb/images/tigra for the tree. Make sure they are all of the same size.
	If you don't use some keys you can just remove them from this config
*/
function expiresdate() {
	var exp = new Date();
	exp.setTime(exp.getTime() + ( 1/*days*/ * 24/*hours*/ * 60/*minutes*/ * 60/*seconds*/ *1000/*milliseconds*/)); // ~1 year	
	return exp.toGMTString();
}
var tree_tpl = {

	// general
	'target':'_blank',	// name of the frame links will be opened in
							// other possible values are:
							// _blank, _parent, _search, _self and _top
	//aditional info to save with cookies (selected & opened)
	'cookie_ext':'expires='+expiresdate()+';',
	//allow several items to be selected
	'multiselections':true,

	//'b_solid':true, //if true will significantly effect appearance delay of the control on huge hierarchy

	
	'icon_18':webroot+'/images/tigra/arr1.gif', // junction for closed node
	'icon_19':webroot+'/images/tigra/arr1.gif',       // junctioin for last closed node
	'icon_26':webroot+'/images/tigra/arr2.gif',// junction for opened node
	'icon_27':webroot+'/images/tigra/arr2.gif',      // junctioin for last opended node

	// /HSUSWeb/images/tigra - root junctions	------------------ comment the following block to hide root's +/- /HSUSWeb/images/tigra ----------------------
	'b_rootcollapse':false,      //                                                                                                
	

	// /HSUSWeb/images/tigra - misc
	'icon_e':webroot+'/images/tigra/empty.gif', // empty image
	'icon_l':webroot+'/images/tigra/empty.gif',  // vertical line


	// styles - root
	'style_48':'mout', // normal root caption style
	'style_52':'mout', // selected root catption style
	'style_56':'mout', // opened root catption style
	'style_60':'mout', // selected opened root catption style
	'style_112':'mover', // mouseovered normal root caption style
	'style_116':'mover', // mouseovered selected root catption style
	'style_120':'mover', // mouseovered opened root catption style
	'style_124':'mover', // mouseovered selected opened root catption style
	
	// styles - node
	'style_16':'t0ic', // normal node caption style
	'style_20':'t0ic', // selected node catption style
	'style_24':'t0ic', // opened node catption style
	'style_28':'t0ic', // selected opened node catption style
	'style_80':'t0io', // mouseovered normal node caption style
	'style_84':'t0io', // mouseovered selected node catption style
	'style_88':'t0io', // mouseovered opened node catption style
	'style_92':'t0io', // mouseovered selected opened node catption style

	// styles - leaf
	'style_0':'t1io', // normal leaf caption style
	'style_4':'t2io', // selected leaf catption style
	'style_64':'t1ic', // mouseovered normal leaf caption style
	'style_68':'t2io', // mouseovered selected leaf catption style

	
		// event handlers - item
	'onItemOpen':'getTables' // on item open event handler
	
	
};

/*
 * This function is used to create the fully loaded Chapters
 */	
function getTables(o_item) {
	if (o_item.a_config[0].search("Tables") < 0) return true;
	if (o_item.a_config[2]['sb'] == "true") return true;
	var actionString = o_item.a_config[1];
	o_item.a_config[2]['sb'] = "true";
	var sWidth = screen.width;
	if(tableId == 'undefined'){
		document.forms[0].action = webroot+"/toc/showFullChapterContent.do?chapId="+actionString + '&tocid=' + o_item.n_id ;
	}else{		
		document.forms[0].action = webroot+"/toc/showFullChapterContent.do?chapId="+actionString + '&tocid=' + o_item.n_id +'&id='+tableId+'&swidth='+sWidth;
	}
	document.forms[0].submit();
	return false;	
}


/* collapses all nodes of the tree
 */
function collapse_all() {
	return collapse_nodes(0,1);
}


/* collapses nodes of the tree
	n_index - zero based index of the tree on the pate
                  if omited then applied to first tree (n_index==0)
	n_depth - zero based level to which the tree with be collapsed
	          if omitted the tree will collapsed to second level (n_depth==1)
 */
function collapse_nodes (n_index, n_depth) {
	if (checkTOCTree == 'undefined' || checkTOCTree == null){ return;}
	var a_nodes = o_tree.a_nodes;
	for (var i = a_nodes.length - 1; i >= 0; i--)
		if (a_nodes[i].n_depth >= n_depth && a_nodes[i].open)
			a_nodes[i].open(1, 1);
}

function selectItemById(id,sid) {
	if (checkTOCTree == 'undefined' || checkTOCTree == null){ return ;}
 	var o_item = o_tree.o_root.a_index[id],
	n_id = o_item.n_id,
	n_depth = o_item.n_depth,
	a_index = o_item.o_root.a_index,
	a_parents = [o_item];
	
	while (n_depth > 0) {
		if (a_index[n_id].n_depth < n_depth) {
			a_parents[a_parents.length] = a_index[n_id];
			n_depth--;
		}
		n_id--;
	}
	for (var i = a_parents.length-1; i >= 0; i--) {
		if (a_parents[i].n_state & 48){
			a_parents[i].open();
		}
	}
	
		return false;
	
}
 
