// ======================================
// nav_functions.js
// Side navigation menu system
// Created 06/2002
// by Jeremy Stockman
// ======================================
// Modified 10/2002 by Jeremy Stockman: 
// integrated Gecko/W3C DOM compatibility
// integrated old browser compatibility
// appearance/style/spacing changed
// added width/height=1 to spacer images
// added replacement for some name chars
// neutered DHTML expand/contract
// ======================================

var bModernBrowser = false;

if ( ((navigator.appName == "Microsoft Internet Explorer") && (navigator.appVersion.charAt(0) >= 4)) || ((navigator.appName == "Netscape") && (navigator.appVersion.charAt(0) > 4)) ) {
	bModernBrowser = true;
}

function Menu(strName) {
	this.size = 0;
	this.menuName = strName;
	this.menuURL = "blank";
	this.linkNames = new Array();
	this.linkURLs = new Array();
}

Menu.prototype.addItem = function (strName, strURL) {
	this.linkNames[this.size] = strName;
	this.linkURLs[this.size] = strURL;
	this.size++;
}

Menu.prototype.getName = function (intPos) {
	return this.linkNames[intPos];
}

Menu.prototype.getURL = function (intPos) {
	return this.linkURLs[intPos];
}

Menu.prototype.build = function () {

	var strSubMenuName;

	strSubMenuName = replace(this.menuName, " ", "_");
	strSubMenuName = replace(strSubMenuName, "/", "_");
	strSubMenuName = replace(strSubMenuName, "&amp;", "_");
	strSubMenuName = replace(strSubMenuName, "&reg;", "_");
	strSubMenuName = replace(strSubMenuName, "&", "_");
	strSubMenuName = replace(strSubMenuName, "-", "_");
	strSubMenuName = replace(strSubMenuName, "?", "_");
	strSubMenuName = replace(strSubMenuName, "!", "_");
	strSubMenuName = replace(strSubMenuName, "'", "_");
	strSubMenuName = replace(strSubMenuName, "@", "_");
	strSubMenuName = replace(strSubMenuName, ",", "_");
	strSubMenuName = replace(strSubMenuName, ".", "_");
	strSubMenuName = replace(strSubMenuName, "\"", "_");
	
	document.writeln("<div class='sideNavGap2'><img src='/images/transparent.gif' border='0' width='1' height='1' /></div>");

	if(this.menuURL == "blank") {
            if(document.title.indexOf(this.menuName) >= 0) { // current page title is contained in menuName string
		if (bModernBrowser) {
			document.writeln("<div style='height: 20px; width: 160px; margin-top: 2px; margin-bottom: 2px;'><a class='sideNavTitle' name='" + strSubMenuName + "' style='color: #000000;' href='javascript:void(0)' onclick=\"toggleDisplay('nav" + strSubMenuName + "_Options')\">" + this.menuName + "</a></div>");

			// start submenu div
			document.writeln("<div class='sideNavOptions' style='display: block;' id='nav" + strSubMenuName + "_Options'>");
		
		} else { // !bModernBrowser (Netscape4)
		
			// instead of a clickable menu title that expands submenu, make a link with the text of the menu title that points to the href of the first link in submenu 
			//alert("test");
			document.writeln("<div style='height: 20px; width: 160px; margin-top: 2px; margin-bottom: 2px;'><a class='sideNavTitle' name='" + strSubMenuName + "' style='color: #000000;' href='" + this.getURL(0) + "'>" + this.menuName + "</a></div>");
		}
            } else { // current page title is NOT contained in menuName string
		if (bModernBrowser) {
//			document.writeln("<div style='width: 160px; height: 20px; margin-top: 2px; margin-bottom: 2px;'><a class='fade' name='" + strSubMenuName + "' href='javascript:void(0)' onclick=\"toggleDisplay('nav" + strSubMenuName + "_Options')\" style='font-weight: normal;'>" + this.menuName + "</a></div>"); // expand submenu code
			document.writeln("<div style='width: 160px; height: 20px; margin-top: 2px; margin-bottom: 2px;'><a class='fade' name='" + strSubMenuName + "' href=\"" + this.getURL(0) + "\" style='font-weight: normal;'><img src='/images/accents/down.gif' border='0' align='right' style='margin-right: 5px; margin-top: 2px;'/>" + this.menuName + "</a></div>"); // neutered version - instead of expanding, just take user to first page in the submenu
			
			// start submenu div
			document.writeln("<div class='sideNavOptions' id='nav" + strSubMenuName + "_Options'>");
		
		} else { // !bModernBrowser (Netscape4) 
		
			// instead of a clickable menu title that expands submenu, make a link with the text of the menu title that points to the href of the first link in submenu 
			document.writeln("<div style='width: 160px; height: 20px; margin-top: 2px; margin-bottom: 2px;'><a name='" + strSubMenuName + "' href='" + this.getURL(0) + "' style='font-weight: normal;'>" + this.menuName + "</a></div>");
		}
            }

	    if (bModernBrowser) { // only create submenus if IE4+ or NS6+/Gecko

			for(intSz=0; intSz < this.size ; intSz++) {

				if(document.title.indexOf(this.menuName + ": " + this.getName(intSz) + " ") >= 0) {
					document.writeln("<div><img style='border-right: 5px solid #FFFFFF; border-top: 4px solid #FFFFFF;' src='/images/accents/arrow_gold_right.gif' width='14' height='7' align='right'><a name='" + strSubMenuName + intSz + "' class='sideNavLink' style='font-weight: bold; color: #EAA000; font-size: 10px;' href='" + this.getURL(intSz) + "'>" + this.getName(intSz) +  "</a></div>");
				} else {
					document.writeln("<div style='margin-top: 2px; margin-bottom: 2px;'><a class='fade2' name='" + strSubMenuName + intSz + "' href='" + this.getURL(intSz) + "' style='font-size: 10px;'>" + this.getName(intSz) +  "</a></div>");
				}
				
			}

			document.writeln("<div class='sideNavGap'><img src='/images/transparent.gif' border='0' width='1' height='1' /></div>");
	
			// close submenu div
			document.writeln("</div>");
	
	    } // end if (bModernBrowser)

	    document.writeln("<!-- horizontal rule --><div class='navRule'><img src='/images/transparent.gif' border='0' width='1' height='1' /></div>");

	} else { // menuURL != "blank"

		if(document.title.indexOf(this.menuName) >= 0) {
			//alert("1 menuURL != blank AND menuName IS in page title");
			//* document.writeln("<div style='width: 160px; height: 20px; margin-top: 2px; margin-bottom: 2px;'><img style='border-right: 5px solid #FFFFFF; border-top: 4px solid #FFFFFF;' src='/images/accents/arrow_gold_right.gif' width='14' height='7' align='right'><a class='sideNavTitle' style='color: #EAA000;' href='" + this.menuURL + "'>" + this.menuName + "</a></div>");
			if (bModernBrowser) {
				document.writeln("<div style='width: 160px; height: 20px; margin-top: 2px; margin-bottom: 2px;'><img style='border-right: 5px solid #FFFFFF; border-top: 4px solid #FFFFFF;' src='/images/accents/arrow_gold_right.gif' width='14' height='7' align='right'><a class='sideNavTitle' style='color: #EAA000;' href='" + this.menuURL + "'>" + this.menuName + "</a></div>");
			} else {
				document.write("<div style='width: 160px; height: 20px;'><a class='sideNavTitle' style='color: #EAA000;' href='" + this.menuURL + "'>" + this.menuName + "</a></div>");
			}
		} else {
			if (bModernBrowser) {
				document.writeln("<div style='width: 160px; height: 20px; margin-top: 2px; margin-bottom: 2px;'><a class='fade' name='" + strSubMenuName + "' href='" + this.menuURL + "' style='font-weight: normal;'>" + this.menuName + "</a></div>");
			} else {
				//alert("2 menuURL != blank and menuName NOT in page title");
				document.writeln("<div style='width: 160px; height: 20px; margin-top: 2px; margin-bottom: 2px;'><a name='" + strSubMenuName + "' href='" + this.menuURL + "' style='font-weight: normal;'>" + this.menuName + "</a></div>");
			}
		}

		document.writeln("<!-- horizontal rule --><div class='navRule'><img src='/images/transparent.gif' border='0' width='1' height='1' /></div>");

	}
	
}


function toggleDisplay(obj) {

	if ((navigator.appName == "Microsoft Internet Explorer") && (navigator.appVersion.charAt(0) >= 4)) {
		// INTERNET EXPLORER 4+
		if (eval("document.all." + obj).style.display == 'block') {
			eval("document.all." + obj).style.display = 'none';
		} else {
			eval("document.all." + obj).style.display = 'block';
		}
	} else if ((navigator.appName == "Netscape") && (navigator.appVersion.charAt(0) > 4)) {
		// W3C DOM (NETSCAPE 6+/GECKO)
		if (eval("document.getElementById('" + obj + "')").style.display == 'block') {
			eval("document.getElementById('" + obj + "')").style.display = 'none';
		} else {
			eval("document.getElementById('" + obj + "')").style.display = 'block';
		}

	}

}


function replace(string,text,by) {

	// Replaces text with by in string

	var strLength = string.length, txtLength = text.length;
	if ((strLength == 0) || (txtLength == 0)) return string;

	var i = string.indexOf(text);

	if ((!i) && (text != string.substring(0,txtLength))) return string;

	if (i == -1) return string;

	var newstr = string.substring(0,i) + by;

	if (i+txtLength < strLength) {
		newstr += replace(string.substring(i+txtLength,strLength),text,by);
	}    

	return newstr;
}

