
function addHeadingLinks(container, title) {
	var base = document.location.pathname;

	function addLinks(elems) {
		for (var i = 0; i < elems.length; i++) {
			var hn = elems[i];
			var al = hn.getElementsByTagName('a');
			var a;

			for (var j = 0; j < al.length; j++) { if (al[j].name) { a = al[j]; break; }}

			if (a) {
				// TODO: hn.innerHTML and replace tags
				var sectionTitle = a.innerHTML;
				var j = sectionTitle.indexOf('<');
				if (j >= 0) { sectionTitle = sectionTitle.substring(0, j); }
				var link = document.createElement('a');
				link.href = base + '#' + a.name;
				link.className = 'anchor';
				link.title = title.replace(/\$id/, sectionTitle);
				link.appendChild(document.createTextNode(' \u00B6'));
				hn.appendChild(link);
			}
		}
	}

	for (var lvl = 1; lvl <= 3; lvl++) {
		addLinks(container.getElementsByTagName('h' + lvl));
	}
}


function addLiveInternet() {
	document.write('<a href="http://www.liveinternet.ru/click" target=_blank style="float: right;">');
	document.write('<img src="http://counter.yadro.ru/hit?t24.14;r' + escape(document.referrer) +
		((typeof(screen) == 'undefined') ? '' :
		';s' + screen.width + '*' + screen.height + '*' + (screen.colorDepth ? screen.colorDepth : screen.pixelDepth)) +
		';u' + escape(document.URL) +
		';i' + escape('Жж' + document.title.substring(0,80)) + ';' + Math.random() + '" ' +
		'title="LiveInternet: показано число посетителей за сегодня" border=0 width=88 height=15>');
	document.write('</a>');
}
