/**
 * JavaScript footer for A+ webpages
 * Version 1.0, September 2006
 *
 * These functions are executed at the end of the page and operate on
 * existing page content.
 *  
 * @author      John King
 */

if (!hideContents) {
	endPadding();
	removeNavLinks();
}
insertWBRs();

/**
 * Concludes the code used to nudge the main page contents.
 */
function endPadding() {
	document.write('  </td></tr></table>\n');
}

/**
 * Hides the 'navlinks' that are used instead of the contents tree.
 */
function removeNavLinks() {
	var divList = document.getElementsByTagName('div');
	for (var i = 0; i < divList.length; i++) {
		if (divList[i].className == 'navlinks') {
			divList[i].style.display = "none";
		}
	}
}

/**
 * Inserts non-W3C <WBR> tags within URLs, allowing them to wrap
 * at the end of a line.
 */
function insertWBRs() {

	// This code requires that URL elements have the attribute 'name="url"'
	var urlList = document.getElementsByName('url');
	var urlString;
	for (var i = 0; i < urlList.length; i++) {
		urlString = urlList[i].innerHTML;
		urlString = urlString.replace(/\/(?!(\/|$))/gm, "/<wbr>");
			// Regular expression matches '/' but not '//' or '/' at end of a line.
		urlString = urlString.replace(/\#/gm, "<wbr>#");
			// Regular expression matches '#' tag delimiter
		urlString = urlString.replace(/\?/gm, "<wbr>?");
			// Regular expression matches '?' query delimiter
		urlString = urlString.replace(/\?/gm, "<wbr>&");
			// Regular expression matches '&' query parameter delimiter
		urlList[i].innerHTML = urlString.replace(/\+/gm, "<wbr>+");
			// Regular expression matches '+' query space character
	}
}

function showTree() {
        deleteCookie("AplusHideContents");
        location.href = location.href;
}

