// JavaScript Document

/* Loops over LI's in the nav bar, setting the "urhere" class on whichever LI's id
matches the className in ul_mainMenu (populated dynamically via CF) */
function initURHere() {
	if (!document.getElementById) return;
	urhereID = document.getElementById("ul_mainMenu");
	if (!urhereID || !urhereID.className.length) return;
	var mnItms = document.getElementById("ul_mainMenu").getElementsByTagName("LI");
	for (var i=0; i<mnItms.length; i++) {
		if (mnItms[i].id.length && mnItms[i].id == urhereID.className) {
			mnItms[i].className+=" urhere";
		}
	}
}

sfHover = function() {
	var sfEls = document.getElementById("ul_mainMenu").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
			/* Above doesn't work for IE 6. The following does. */
			x = this.getElementsByTagName("UL");
			if (x.length > 0) x[0].style['display'] = 'block';
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
			/* Above doesn't work for IE 6. The following does. */
			x = this.getElementsByTagName("UL");
			if (x.length > 0) x[0].style['display'] = 'none';
		}
	}
}

/* The followuing works for IE AND Firefox */
window.onload = function() { 
	initURHere();
}

/* The following only appears to run in IE (and only needs to run in IE) */
if (window.attachEvent) window.attachEvent("onload", sfHover);


//
// TRIMMING FUNCTIONS 
//
// Trim the left side of a value. 
function ltrim(argvalue) {
	while (1) {
    	if (argvalue.substring(0, 1) != " ") break;
		argvalue = argvalue.substring(1, argvalue.length);
	}
	return argvalue;
}
// Trim the right side of a value. 
function rtrim(argvalue) {
	while (1) {
		if (argvalue.substring(argvalue.length - 1, argvalue.length) != " ") break;
		argvalue = argvalue.substring(0, argvalue.length - 1);
	}
	return argvalue;
}
// Trim both sides of a value. 
function trim(argvalue) {
	var tmpstr = ltrim(argvalue);
	return rtrim(tmpstr);
}
