function getCookie(strName) {
	var cookies, bits;
	cookies = document.cookie.split(";");
	for (i = 0; i < cookies.length; i++) {
		cookies[i] = cookies[i].replace(" ", "");
		bits = cookies[i].split("=");
		if (bits[0] == strName) { return bits[1]; }
	}
	return false;
}

function setTempCookie(strName, strValue) {
	document.cookie = strName + "=" + strValue + "; ";
}

function xBrowserGetElement(elename) {
	// support for ie4/ie5/ie6/moz5+
	if (document.all) { return document.all[elename]; }
	else { return document.getElementById(elename); }
}

function ffHideLeftbar() {

		if (!document.all) {
			var lb = xBrowserGetElement("ffLB");
			var logotext = xBrowserGetElement("logotext");
			var lbtdr = xBrowserGetElement("ffLBtdr");
			var lbtd = xBrowserGetElement("ffLBtd");
		}
		else {
			// ie 4 compatibility
			var lb = document.all.ffLB;
			var logotext = document.all.logotext;
			var lbtdr = document.all.ffLBtdr;
			var lbtd = document.all.ffLBtd;
		}

		lb.style.display = "none";
		logotext.style.display = "none";
		document.images["ffLBC"].src = "Templates/right.gif";
		lbtd.style.width = "10";
		lbtdr.style.width = "100%";
		setTempCookie("leftbar", "hidden");
}
function ffShowLeftbar() {

		document.images["ffLBC"].src = "Templates/left.gif";
		xBrowserGetElement("ffLB").style.display = "";
		xBrowserGetElement("logotext").style.display = "";
		xBrowserGetElement("ffLBtdr").style.width = "80%";
		xBrowserGetElement("ffLBtd").style.width = "20%";

		// work around moz bug to force reflow
		if (navigator.appName != "Microsoft Internet Explorer") {
			tmp = xBrowserGetElement("ffLBtdr").innerHTML;
			xBrowserGetElement("ffLBtdr").innerHTML = "";
			setTimeout("ffReflow()", 100);
		}
		setTempCookie("leftbar", "visible");
}
function ffReflow() {
		xBrowserGetElement("ffLBtdr").innerHTML = tmp;
}
function ffToggleLeftbar() {
	if (ffLeftbarVisible) {
		ffLeftbarVisible = false;
		ffHideLeftbar();
	}
	else {
		ffLeftbarVisible = true;
		ffShowLeftbar();
	}
}
function ffLoadLeftbarPrefs() {
	if (getCookie("leftbar") == "hidden") { ffLeftbarVisible = false; ffHideLeftbar(); }
	// now run LinkHelper

	if (document.getElementById)
		ffLinkHelper();

	// Mozilla compatibility (doesn't like to scroll)
	if ((navigator.appName == "Microsoft Internet Explorer") && (navigator.userAgent.indexOf("Win") != -1) && (navigator.userAgent.indexOf("MSIE 4") == -1)) {
		document.body.style.overflowY = "hidden";
		xBrowserGetElement("ffLBtable").style.height = "100%";
		xBrowserGetElement("ffLB").style.overflowY = "auto";
		xBrowserGetElement("ffLB").style.height = "100%";
		xBrowserGetElement("mozwrap").style.height = "100%";
		xBrowserGetElement("mozwrap").style.overflow = "auto";
	}
	tmpl_new_resize();
}
function tmpl_new_resize() {
	if (window.innerHeight) { inner = window.innerHeight; } else { inner = document.body.clientHeight; }
	xBrowserGetElement("maintable").style.height = inner + "px";
	xBrowserGetElement("ffLBtd").style.height = "" + (inner - xBrowserGetElement("ffTMBtd").offsetHeight) + "px";
}
function ffLinkHelper() {
	var contentDiv = xBrowserGetElement("content");
	var leftBar = xBrowserGetElement("ffLB");
	var networkOnlyLinks = 0;

	window.defaultStatus = "Building page links...";

	networkOnlyLinks += ffLinkHelperDoObj(contentDiv);
	networkOnlyLinks += ffLinkHelperDoObj(leftBar);

	if (networkOnlyLinks > 0) {
		contentDiv.innerHTML = "<div style='border: 2px solid red; padding: 3px; margin-top: 3px'><b>This page contains links that will only function correctly when using the intranet from within the school network.  Such links are marked with this icon: <img src='Templates/linkfile.gif'>.</b></div>" + contentDiv.innerHTML;
	}

	window.defaultStatus = "";
	ffImageHelper(contentDiv);
}
function ffImageHelper(container) {
	var images = container.getElementsByTagName("IMG");
	for (i = 0; i < images.length; i++) {
		if (images[i].style.height && (images[i].src.indexOf("image.aspx") != -1)) {
			images[i].src += "&height=" + parseInt(images[i].style.height) + "&width=" + parseInt(images[i].style.width);
		}
	}
}
function ffLinkHelperDoObj(node) {

	contentLinks = node.getElementsByTagName("A");
	var thisServer = location.protocol + "//" + location.host + location.port + location.pathname;
	var networkOnlyLinks = 0;

	for (i = 0; i < contentLinks.length; i++) {

			if (contentLinks[i].href && contentLinks[i].innerText != "") {
				tsrc = ""; talt = ""; ttarget="";
				if (contentLinks[i].href.length > 7) {
					if (contentLinks[i].href.substring(0,7) == "mailto:") { tsrc = 'Templates/linkmail.gif'; talt='Link to e-mail address'; }
					if (contentLinks[i].href.substring(0,7) == "http:\/\/") { 
						// check no same server link
						if (contentLinks[i].href.length >= thisServer.length) {
							if (contentLinks[i].href.substring(0, thisServer.length) != thisServer) {
								tsrc='Templates/linkext.gif'; talt='Link to external web site (opens in a new window)'; ttarget = "_new";
							}
						} else {
							tsrc= 'Templates/linkext.gif'; talt='Link to external web site (opens in a new window)'; ttarget = "_new";
						}
					}
					if (contentLinks[i].href.substring(0,7) == "file:\/\/") {  networkOnlyLinks++; tsrc='Templates/linkfile.gif'; talt='Link to file on network share (only available on internal network)';  }

				}
				if (tsrc != "") {
					// we have a glyph to add
				if (!document.all) {
					var newglyph = document.createElement("img");
					var src = document.createAttribute("src"); src.value = tsrc; newglyph.setAttributeNode(src);
					var border = document.createAttribute("border"); border.value = "0"; newglyph.setAttributeNode(border);
					var alt = document.createAttribute("alt"); alt.value = talt; newglyph.setAttributeNode(alt);
					contentLinks[i].appendChild(newglyph);
					newglyph.style.marginLeft = "3px";
				}
				else {
					contentLinks[i].innerHTML += "<img src='" + tsrc + "' alt='" + talt + "' border=0 style='margin-left: 3px'>";
				}
					if (ttarget != "") { contentLinks[i].target = ttarget; }
				}
			}

	}
	return networkOnlyLinks;
}

var ffLeftbarVisible = true;
var tmp;
