/*************************************************************************
        Javascript Help Contents Viewer 1.1  (21 Aug 2002)
        Tested with: Internet Explorer 5+, Opera 6+, Mozilla, NN6+

        Copyright (c) 2002 A!K Research Labs (http://www.aklabs.com)  
        Special for chm2web software (http://www.chm2web.com)
                
	Based on Source Code: 
         Copyright (c) 2002 Tigra Tree 
         Version: 1.0: 07-20-2002 (mm-dd-yyyy)

**************************************************************************/


var a_tpl = {
	'target'  : 'content',    // name of the frame links will be opened in

	'icon_e'  : 'icons/0.gif',  // empty image
	'icon_l'  : 'icons/90.gif', // vertical line
	
	'icon_2'  : 'icons/91.gif', // junction for leaf
	'icon_3'  : 'icons/92.gif', // junction for last leaf
	'icon_18' : 'icons/93.gif', // junction for closed node
	'icon_19' : 'icons/94.gif', // junctioin for last closed node
	'icon_26' : 'icons/95.gif', // junction for opened node
	'icon_27' : 'icons/96.gif'  // junctioin for last opended node
};

var a_safemode = true;

function DHTMLSupported () {
	try {
		var tmp = "";
		tmp = document.body.innerHTML;
		if (tmp.length <= 0) return false;
	} catch(e) {
		return false;
	}
	return true;
}


function tree (a_items) {

	this.a_config   = a_items;
	this.o_root     = this;
	this.a_index    = [];
	this.o_selected = null;
	this.n_depth    = -1;

	a_safemode	= !DHTMLSupported();
	
	var o_icone = new Image(),
		o_iconl = new Image();
	o_icone.src = a_tpl['icon_e'];
	o_iconl.src = a_tpl['icon_l'];
	a_tpl['im_e'] = o_icone;
	a_tpl['im_l'] = o_iconl;
	for (var i = 0; i < 64; i++)
		if (a_tpl['icon_' + i]) {
			var o_icon = new Image();
			a_tpl['im_' + i] = o_icon;
			o_icon.src = a_tpl['icon_' + i];
		}
	
	this.toggle = function (n_id) {	var o_item = this.a_index[n_id]; 
           o_item.open(o_item.b_opened) };
	this.select = function (n_id) { return this.a_index[n_id].select(); };
	this.mout   = function (n_id) { this.a_index[n_id].upstatus(true) };
	this.mover  = function (n_id) { this.a_index[n_id].upstatus() };                                              

	this.a_children = [];
	for (var i = 0; i < a_items.length; i++) {
		new tree_item(this, i);
        }

	this.n_id = trees.length;
	trees[this.n_id] = this;

	for (var i = 0; i < this.a_children.length; i++) {
		document.write(this.a_children[i].init());
		this.a_children[i].open();
	}

	
}
function tree_item (o_parent, n_order) {

	this.n_depth  = o_parent.n_depth + 1;
	this.a_config = o_parent.a_config[n_order + (this.n_depth ? 3 : 0)];
	if (!this.a_config) return;

	this.o_root    = o_parent.o_root;
	this.o_parent  = o_parent;
	this.n_order   = n_order;
	this.b_opened  = (a_safemode ? true : !this.n_depth);

	this.n_id = this.o_root.a_index.length;
	this.o_root.a_index[this.n_id] = this;
	o_parent.a_children[n_order] = this;

	this.a_children = [];
	for (var i = 0; i < this.a_config.length - 2; i++)
		new tree_item(this, i);

	this.get_icon = item_get_icon;
	this.open     = item_open;
	this.select   = item_select;
	this.init     = item_init;
	this.upstatus = item_upstatus;
	this.is_last  = function () { 
           return this.n_order == this.o_parent.a_children.length - 1 };
}

function item_open (b_close) {
	var a_children = [];
	var o_idiv = get_element('i_div' + this.n_id);
	if (!o_idiv) return;
	
        if (a_safemode) {
		document.write(a_children.join(''));
		for (var i = 0; i < this.a_children.length; i++) {
			document.write(this.a_children[i].init());
			this.a_children[i].open();
		}
	} else {
		if (!o_idiv.innerHTML) {
			for (var i = 0; i < this.a_children.length; i++)
				a_children[i]= this.a_children[i].init();
			o_idiv.innerHTML = a_children.join('');
		}
		o_idiv.style.display = (b_close ? 'none' : 'block');
		this.b_opened = !b_close;
		var o_jicon = document.images['j_img' + this.n_id],
			o_iicon = document.images['i_img' + this.n_id];
		if (o_jicon) o_jicon.src = this.get_icon(true);
		if (o_iicon) o_iicon.src = this.get_icon();
		this.upstatus();
	}
}

function item_select (b_deselect) {
	if (!b_deselect) {
		var o_olditem = this.o_root.o_selected;
		this.o_root.o_selected = this;
		if (o_olditem) o_olditem.select(true);
	}
	var o_iicon = document.images['i_img' + this.n_id];
	if (o_iicon) o_iicon.src = this.get_icon();
	get_element('i_txt' + this.n_id).style.fontWeight = b_deselect ? 'normal' : 'bold';
	
	this.upstatus();
	return Boolean(this.a_config[1]);
}

function item_upstatus (b_clear) {
       if (!a_safemode) {
		window.setTimeout('window.status="' + (b_clear ? '' : this.a_config[0] + 
		(this.a_config[1] ? ' ('+ this.a_config[1] + ')' : '')) + '"', 10);
	}
}

function item_init () {
	var a_offset = [],
		o_current_item = this.o_parent;

	for (var i = this.n_depth; i > 1; i--) {
		a_offset[i] = '<img src="' + a_tpl[o_current_item.is_last() ? 'icon_e' : 'icon_l'] + '" border="0" align="absbottom">';
		o_current_item = o_current_item.o_parent;
	}

	if (a_safemode) {	
  
	return '<table cellpadding="0" cellspacing="0" border="0"><tr><td nowrap>' + 
          (this.n_depth ? a_offset.join('') + (this.a_children.length ? 
          '<img src="' + this.get_icon(true) + 
          '" border="0" align="absbottom" name="j_img' + this.n_id + 
          '"></a>' : '<img src="' + this.get_icon(true) + 
          '" border="0" align="absbottom">') : '') + 
          ((this.a_config[1] == null) ? '<a ' : '<a href="' + this.a_config[1] + 
          '" target="' + a_tpl['target'] + '" ') + ' class="t' + 
          this.o_root.n_id + 'i" id="i_txt' + this.n_id + '"><img src="' + 
          this.get_icon() + '" border="0" align="absbottom" name="i_img' + 
          this.n_id + '" class="t' + this.o_root.n_id + 'im">&nbsp;' + 
          this.a_config[0] + '</a></td></tr></table>' + (this.a_children.length ? 
          '<div id="i_div' + this.n_id + '" style="display:none"></div>' : '');

	} else {

	return '<table cellpadding="0" cellspacing="0" border="0"><tr><td nowrap>' + 
          (this.n_depth ? a_offset.join('') + (this.a_children.length ? 
          '<a href="javascript: trees[' + this.o_root.n_id + '].toggle(' + 
          this.n_id + ')" onmouseover="trees[' + this.o_root.n_id + '].mover(' + 
          this.n_id + ')" onmouseout="trees[' + this.o_root.n_id + '].mout(' + 
          this.n_id + ')"><img src="' + this.get_icon(true) + 
          '" border="0" align="absbottom" name="j_img' + this.n_id + 
          '"></a>' : '<img src="' + this.get_icon(true) + 
          '" border="0" align="absbottom">') : '') + '<a href="' + this.a_config[1] + 
          '" target="' + a_tpl['target'] + '" onclick="return trees[' + 
          this.o_root.n_id + '].select(' + this.n_id + ')" ondblclick="trees[' + 
          this.o_root.n_id + '].toggle(' + this.n_id + ')" onmouseover="trees[' + 
          this.o_root.n_id + '].mover(' + this.n_id + ')" onmouseout="trees[' + 
          this.o_root.n_id + '].mout(' + this.n_id + ')" class="t' + 
          this.o_root.n_id + 'i" id="i_txt' + this.n_id + '"><img src="' + 
          this.get_icon() + '" border="0" align="absbottom" name="i_img' + 
          this.n_id + '" class="t' + this.o_root.n_id + 'im">&nbsp;' + 
          this.a_config[0] + '</a></td></tr></table>' + (this.a_children.length ? 
          '<div id="i_div' + this.n_id + '" style="display:none"></div>' : '');
	}

}

function item_get_icon (b_junction) {
       if (!b_junction) {
         cur = this.a_config[2];
         if (this.b_opened) {
           if ((cur == '1') || (cur == '2')) cur = '2';
           if ((cur == '3') || (cur == '4')) cur = '4';
           if ((cur == '5') || (cur == '6')) cur = '6';
           if ((cur == '7') || (cur == '8')) cur = '8';
          };
         if (!this.b_opened) {
           if ((cur == '1') || (cur == '2')) cur = '1';
           if ((cur == '3') || (cur == '4')) cur = '3';
           if ((cur == '5') || (cur == '6')) cur = '5';
           if ((cur == '7') || (cur == '8')) cur = '7';
          };
         return 'icons/' + cur + '.gif';
       } else {
         return a_tpl['icon_' + ((this.n_depth ? 0 : 32) +
           (this.a_children.length ? 16 : 0) + 
           (this.a_children.length && this.b_opened ? 8 : 0) + 
           2 + (this.is_last() ? 1 : 0))];
       }
}

var trees = [];
get_element = document.all ?
	function (s_id) { return document.all[s_id] } :
	function (s_id) { return document.getElementById(s_id) };


