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

    chm2web Javascript Help Contents Viewer 1.2
    Copyright (c) 2002 A!K Research Labs (http://www.aklabs.com)  
    http://chm2web.aklabs.com - HTML Help Conversion Utility

    Tested with: Internet Explorer 5, Opera 6, Mozilla 1.2, NN6
    Best viewed with: Internet Explorer 5+, Mozilla 1.x+
                
**************************************************************************/


var licons = {
	'target'  : 'content',  
	'icon_e'  : 'icons/0.gif', 
	'icon_l'  : 'icons/90.gif',
	'icon_2'  : 'icons/91.gif',
	'icon_3'  : 'icons/92.gif',
	'icon_18' : 'icons/93.gif',
	'icon_19' : 'icons/94.gif',
	'icon_26' : 'icons/95.gif',
	'icon_27' : 'icons/96.gif' 
};

var a_safemode = true;

var trees = [];

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

function GetIcon (b_junction) {
       if (!b_junction) {
         cur = this.a_prop[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 licons['icon_' + ((this.n_depth ? 0 : 32) +
           (this.a_childlist.length ? 16 : 0) + 
           (this.a_childlist.length && this.b_opened ? 8 : 0) + 
           2 + (this.is_last() ? 1 : 0))];
       }
}

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

function TreeNode (o_parent, n_order) {

	this.n_depth  = o_parent.n_depth + 1;
	this.a_prop = o_parent.a_prop[n_order + (this.n_depth ? 3 : 0)];
	if (!this.a_prop) 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_childlist[n_order] = this;

	this.a_childlist = [];
	for (var i = 0; i < this.a_prop.length - 2; i++)
		new TreeNode(this, i);

	this.get_icon = GetIcon;
	this.open     = OpenItem;
	this.select   = FocusItem;
	this.init     = InitItem;
	this.is_last  = function () { 
           return this.n_order == this.o_parent.a_childlist.length - 1 };
}

function OpenItem (b_close) {
	var a_childlist = [];
	var o_idiv = get_element('i_div' + this.n_id);
	if (!o_idiv) return;
	
        if (a_safemode) {
		document.write(a_childlist.join(''));
		for (var i = 0; i < this.a_childlist.length; i++) {
			document.write(this.a_childlist[i].init());
			this.a_childlist[i].open();
		}
	} else {
		if (!o_idiv.innerHTML) {
			for (var i = 0; i < this.a_childlist.length; i++)
				a_childlist[i]= this.a_childlist[i].init();
			o_idiv.innerHTML = a_childlist.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();
	}
}

function FocusItem (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';
	return Boolean(this.a_prop[1]);
}

function MakeTree (itm) {

        a_safemode = !DHTMLSupported(); this.a_prop = itm; 
        this.o_root = this; this.a_index = []; this.o_selected = null;
        this.n_depth = -1; 
	
	var o_icone = new Image(),
	o_iconl = new Image();
	o_icone.src = licons['icon_e'];
	o_iconl.src = licons['icon_l'];
	licons['im_e'] = o_icone;
	licons['im_l'] = o_iconl;
	for (var i = 0; i < 64; i++)
		if (licons['icon_' + i]) {
			var o_icon = new Image();
			licons['im_' + i] = o_icon;
			o_icon.src = licons['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.a_childlist = [];
	for (var i = 0; i < itm.length; i++) {
		new TreeNode(this, i);
        }

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

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

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

	for (var i = this.n_depth; i > 1; i--) {
		a_offset[i] = '<img src="' + licons[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_childlist.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_prop[1] == null) ? '<a ' : '<a href="' + this.a_prop[1] + 
          '" target="' + licons['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_prop[0] + '</a></td></tr></table>' + (this.a_childlist.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_childlist.length ? 
          '<a href="javascript: trees[' + this.o_root.n_id + '].toggle(' + 
          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_prop[1] + 
          '" target="' + licons['target'] + '" onclick="return trees[' + 
          this.o_root.n_id + '].select(' + this.n_id + ')" ondblclick="trees[' + 
          this.o_root.n_id + '].toggle(' + 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_prop[0] + '</a></td></tr></table>' + (this.a_childlist.length ? 
          '<div id="i_div' + this.n_id + '" style="display:none"></div>' : '');
	}

}

