// JavaScript support functions
// variables linkholder, togglelink and outerspan only defined and used in these functions
// function showTocToggle2, variable tocHideText2,tocShowText2 are in html code
// 'toctitle'/'toctitle2', 'toc'/'toc2' are defined in the html code
// 'span', 'internal' not explicitly in code

function showTocToggle2() {
	if (document.createTextNode) {
		// Uses DOM calls to avoid document.write + XHTML issues

		var linkHolder2 = document.getElementById('toctitle2');
		if (!linkHolder2) {
			return;
		}

		var outerSpan2 = document.createElement('span2');
		outerSpan2.className = 'toctoggle2';

		var toggleLink2 = document.createElement('a');
		toggleLink2.id = 'togglelink2';
		toggleLink2.className = 'internal2';
		toggleLink2.href = 'javascript:toggleToc2()';
		toggleLink2.appendChild(document.createTextNode(tocHideText2));

		outerSpan2.appendChild(document.createTextNode('['));
		outerSpan2.appendChild(toggleLink2);
		outerSpan2.appendChild(document.createTextNode(']'));

		linkHolder2.appendChild(document.createTextNode(' '));
		linkHolder2.appendChild(outerSpan2);

		toggleToc2();

		var cookiePos = document.cookie.indexOf("hidetoc=");
		// remove above toggleToc2() and change below == from 0 to 1 if want to default to showing text
		if (cookiePos > -1 && document.cookie.charAt(cookiePos + 8) == 0) {
			toggleToc2();
		}
	}
}

function changeText(el, newText) {
	// Safari work around
	if (el.innerText) {
		el.innerText = newText;
	} else if (el.firstChild && el.firstChild.nodeValue) {
		el.firstChild.nodeValue = newText;
	}
}

function toggleToc2() {
	var toc2 = document.getElementById('toc2').getElementsByTagName('ul')[0];
	var toggleLink2 = document.getElementById('togglelink2');

	if (toc2 && toggleLink2 && toc2.style.display == 'none') {
		changeText(toggleLink2, tocHideText2);
		toc2.style.display = 'block';
		document.cookie = "hidetoc=0";
	} else {
		changeText(toggleLink2, tocShowText2);
		toc2.style.display = 'none';
		document.cookie = "hidetoc=1";
	}
}


