var tocstr = "";
var lastlevel = 0;
var lasttext = "";
var lasthref = "";

var tocData = new Array();
var tocDivs = new Array();
var tocCells = new Array();
var tocImgs = new Array();

function tocIsTocFrame()
{
	var s = new String(self.location);
	s = s.substr(s.length - 7);
	return s == "toc.htm";
}

// Any page references tools.js should only load inside of <index.htm>
if (!tocIsTocFrame())
	if (top.location == self.location)
	{
		document.cookie = "RequestedLocation=" + escape(self.location);
		top.location = 'index.htm';
	}
	else
		window.onload = tocLoad;

function tocSelectStart()
{
	window.event.cancelBubble = true;
	window.event.returnValue = false;
	return false;
}

function tocBegin()
{
	tocstr =
		'<table id=tocTable class="toc" cellspacing=0 cellpadding=0 border=0 style="cursor:default"><tr><td>';
	lastlevel = 0;
	tocData.length = 0;
}

function tocWrite(text, href, level, hasChildren)
{
	tocstr = tocstr +
		'<div style="margin-top:0; margin-left:' + 17 * level + '">' +
		'<table cellspacing=0 cellpadding=0 border=0 ' + 
		(hasChildren ? 'style="cursor:hand"' : '') + '>' +
		'<tr height=19>' +
		'	<td><img id=img' + tocData.length + 
		' src="images/toc_' + (hasChildren ? 'plus' : 'dot') + '.gif"' + 
		' border=0 ' + (hasChildren ? 'onmousedown=tocDown();' : '') + ' index=' + tocData.length + '></td>' +
		'	<td><img src="images/tocdot.gif" width="3" border=0></td>' +
		'	<td class="toc" onmouseover=tocOver() onmouseout=tocOut() onmousedown=tocFire()' +
		' style="white-space:noWrap; ' +
		(hasChildren ? '' : 'cursor:hand') + '" index=' + tocData.length + ' id=cell' + tocData.length +
		' href="' + href + '">&nbsp;' + text + '&nbsp;</td>' +
		'</tr></table></div>';
	tocCells[tocCells.length] = "cell" + tocData.length;
	tocImgs[tocImgs.length] = "img" + tocData.length;
}

function tocAdd(text, href)
{
	var level = 0;
	while (level < text.length && text.charCodeAt(level) == 32) level++;
	if (level != 0) text = text.substr(level);
	
	if (lastlevel > level)
	{
		tocWrite(lasttext, lasthref, lastlevel, false);
		while (lastlevel-- > level) tocstr += "</DIV>";
	}
	else if (lastlevel < level)
	{
		tocWrite(lasttext, lasthref, lastlevel, true);
		tocstr += '<DIV id=div' + tocData.length + ' style="display:none">';
		tocDivs[tocDivs.length] = "div" + tocData.length;
	}
	else if (tocData.length > 0)
		tocWrite(lasttext, lasthref, lastlevel, false);
	
	// Add item definition
	lastlevel = level;
	lasttext = text;
	lasthref = href;
	tocData[tocData.length] = new Array(level, href);
}

function tocEnd()
{
	if (lastlevel > 0)
	{
		tocWrite(lasttext, lasthref, lastlevel, false);
		while (lastlevel-- > 0) tocstr += "</DIV>";
	}
	else if (tocData.length > 0)
		tocWrite(lasttext, lasthref, lastlevel, false);
	
	tocstr += "</td></tr></table>";
	document.write(tocstr);
	
	// Enum divs elements
	for (var i = 0; i < tocDivs.length; i++)
		tocDivs[i] = new Array(tocDivs[i], eval(tocDivs[i]));

	// Enum cells elements
	for (var i = 0; i < tocCells.length; i++)
		tocCells[i] = new Array(tocCells[i], eval(tocCells[i]));

	// Enum img  elements
	for (var i = 0; i < tocImgs.length; i++)
		tocImgs[i] = new Array(tocImgs[i], eval(tocImgs[i]));

	// Make data available for all frames
	top.toc = new Array(tocData, tocDivs, tocCells, tocImgs, -1);
}

function tocFind(array, index)
{
	for (var i = 0; i < array.length; i++)
		if (array[i][0] == index) return array[i][1];
	return null;
}

function tocSelect(index, selected)
{
	if (index != -1)
	{
		var e = tocFind(top.toc[2], 'cell' + index);
		if (e != null)
		{
			e.style.borderColor = selected ? "#9C9A9C" : "#F7F3F7";
			e.style.backgroundColor = selected ? "#FFFFFF" : "#F7F3F7";
		}
	}
}

function tocOver()
{
	var e=event.srcElement;
	e.style.borderColor = e.index == top.toc[4] ? "#9C9A9C" : "#9C9A9C";
	e.style.backgroundColor = e.index == top.toc[4] ? "#FFFFFF" : "#CECFCE";
}

function tocOut()
{
	var e=event.srcElement; 
	e.style.borderColor = e.index == top.toc[4] ? "#9C9A9C" : "#F7F3F7";
	e.style.backgroundColor = e.index == top.toc[4] ? "#FFFFFF" : "#F7F3F7";
}

function tocDown()
{
	var index = event.srcElement.index, div = eval("div" + index), img = eval("img" + index);
	if (div.style.display == "none")
	{
		div.style.display = "block";
		img.src = "images/toc_minus.gif";
	}
	else
	{
		div.style.display = "none";
		img.src = "images/toc_plus.gif";
	}
}

function tocFire()
{
	var index = event.srcElement.index;
	if (event.srcElement.href != "")
	{
		if (event.srcElement.href.substr(0, 4) == "http")
			top.location = event.srcElement.href;
		else
			top.frames[3].frames[0].location = event.srcElement.href;
	}
}

function tocFollow(href)
{
	// at first, try to find href in the toc list
	var index = -1, toc = top.toc, ln = toc[0].length;
	for (var i = 0; i < ln; i++) if (href == toc[0][i][1]) index = i;
	if (index != -1)
	{
		tocSelect(top.toc[4], false);
		top.toc[4] = index + 1;
		tocSelect(top.toc[4], true);
	}
	while (index != -1)
	{
		var level = toc[0][index][0];
		while (index != -1 && toc[0][index][0] >= level) index--;
		if (index != -1)
		{
			level = toc[0][index][0];
			var div = tocFind(toc[1], "div" + (index  + 1)), img = tocFind(toc[3], "img" + (index + 1));
			if (div.style.display == "none")
			{
				div.style.display = "block";
				img.src = "images/toc_minus.gif";
			}		
		}
	}
}

function tocLoad()
{
	var s = new String(window.location);
	var index = s.lastIndexOf("/");
	s = s.substr(index + 1);
	tocFollow(s);
}

function CreateToc()
{
	tocBegin();
	tocAdd("HiDialer 2000 overview",					"kb_hidialer.htm");
	tocAdd(" Short description or program",				"kb_hidialer_short_description.htm");
	tocAdd(" System requirements",						"kb_hidialer_system_requirements.htm");
	tocAdd(" Installation of HiDialer 2000",			"kb_hidialer_installation.htm");
	tocAdd("HiDialer 2000 Settings",					"kb_hidialer_settings.htm");
	tocAdd(" Appearance",								"kb_hidialer_appearance.htm");
	tocAdd(" Clock sync",								"kb_hidialer_sync.htm");
	tocAdd(" Entries",									"kb_hidialer_settings.htm");
	tocAdd("  General",									"kb_hidialer_settings.htm");
	tocAdd("   Account settings",						"kb_hidialer_entries_account.htm");
	tocAdd("   Dialing rules",							"kb_hidialer_entries_dialing.htm");
	tocAdd("   Keep alive",								"kb_hidialer_entries_keepalive.htm");
	tocAdd("   Limits",									"kb_hidialer_entries_limits.htm");
	tocAdd("   Phone book",								"kb_hidialer_entries_phones.htm");
	tocAdd("   Session costs",							"kb_hidialer_entries_rates.htm");
	tocAdd("  Launcher",								"kb_hidialer_entries_launcher.htm");
	tocAdd("  Scheduler",								"kb_hidialer_entries_scheduler.htm");
	tocAdd("  Session cost limits",						"kb_hidialer_entries_cost_limits.htm");
	tocAdd("  Session log",								"kb_hidialer_entries_log.htm");
	tocAdd("  Statistics",								"kb_hidialer_entries_statistics.htm");
	tocAdd(" Overall session log",						"kb_hidialer_overall.htm");
	tocAdd(" Files and folders",						"kb_hidialer_paths.htm");
	tocAdd(" Sounds",									"kb_hidialer_sound.htm");
	tocAdd(" Tracing",									"kb_hidialer_tracing.htm");
	tocAdd("Additional information", "");
	tocAdd(" Advanced hint",                                                                "hd2k0004.htm");
	tocAdd(" Advanced launcher",                                                            "hd2k0030.htm");
	tocAdd(" Advanced rating",                                                              "hd2k0028.htm");
	tocAdd(" Advanced scheduler",                                                           "hd2k0026.htm");
	tocAdd(" Billing",                                                                      "hd2k0008.htm");
	tocAdd(" Dialing different phones or entries at different time",                        "hd2k0024.htm");
//	tocAdd(" Entry name blinking can be disabled",                                          "hd2k0009.htm");
	tocAdd(" Error and debug logs realized",                                                "hd2k0018.htm");
	tocAdd(" Export to Microsoft Excel 2000 or higher",                                     "hd2k0021.htm");
	tocAdd(" HiDialer 2000 Client/Server mode",                                             "hd2k0006.htm");
	tocAdd(" HiDialer 2000 Service",                                                        "hd2k0029.htm");
	tocAdd(" Log files backing up",                                                         "hd2k0022.htm");
	tocAdd(" New tracing features",                                                         "hd2k0007.htm");
	tocAdd(" No more than a hundred lines in the event list",                               "hd2k0023.htm");
	tocAdd(" Optimizer",                                                                    "hd2k0027.htm");
	tocAdd(" Synchronizing time to own server",                                             "hd2k0025.htm");
	tocAdd("Known HiDialer 2000 problems", "");
	tocAdd(" Cannot create a shortcut for a program",                                       "hd2k0003.htm");
	tocAdd(" Cannot launch non-executable file",                                            "hd2k0017.htm");
//	tocAdd(" Clear idle timeout box isn't available under 95/98/ME",                        "hd2k0011.htm");
	tocAdd(" HiDialer incorrectly reports trial expired",                                   "hd2k0013.htm");
//	tocAdd(" HiDialer 2000 playes disconnect even no connection was established",           "hd2k0015.htm");
	tocAdd(" HiDialer 2000 settings apply only to currently logged user",                 "hd2k0014.htm");
	tocAdd(" HiDialer 2000 terminates program abnormally",                                  "hd2k0020.htm");
	tocAdd(" Keep alive reports error although host is alive",                              "hd2k0005.htm");
	tocAdd(" Lanching different programs under different tasks",                            "hd2k0012.htm");
	tocAdd(" Run when Windows starts doesn't work under Windows NT/2000/XP",                "hd2k0010.htm");
	tocAdd(" Scheduler reports incorrect run time for tasks",                               "hd2k0002.htm");
//	tocAdd(" There are different data in connection log and statistics",                    "hd2k0016.htm");
	tocAdd(" Time sync feature doesn't work",                                               "hd2k0019.htm");
	tocAdd(" When transparency is disabled, status windows doesn't appear when program run","hd2k0001.htm");
	tocAdd("HiDialer 2000 on the Web",				"http://www.hidialer2000.com/");
	tocAdd(" On-line documentation",				"http://www.hidialer2000.com/hd2k/");
	tocAdd(" Frequently asked questions",			"http://www.hidialer2000.com/faq/");
	tocAdd(" Known HiDialer 2000 bugs",				"http://www.hidialer2000.com/bugs/");
	tocEnd();
}
