// Script:   common.js 
// Purpose:  Provides JavaScript that is common to all or most pages on the site. 
// Author:   Gerry Stanford
// Date Written: August of 2006

function getObj(theObj) {
	if (document.getElementById) return document.getElementById(theObj);
	else if (document.all)       return document.all.item(theObj);
	else return false;
}


//
// Navigation (Mouse-over) Functions
//
function mouseOverInit(whichNav,idStub,ext,hilite)
{
	if (document.getElementById(whichNav))
		var x = document.getElementById(whichNav).getElementsByTagName('IMG');
	else if (document.all[whichNav])
		var x = document.all[whichNav].all.tags('IMG');
	else return;
	var hiliteid = idStub + '_' + hilite;
	var preloads = new Object();
	for (var i=0;i<x.length;i++)
	{
		if (x[i].id.length >= 5 && x[i].id.substring(0,5) == idStub) {
			preloads['n'+x[i].id] = new Image;
			preloads['n'+x[i].id].src = 'images/'+ x[i].id + '_off.' + ext;
			preloads['o'+x[i].id] = new Image;
			preloads['o'+x[i].id].src = 'images/'+ x[i].id + '_on.' + ext;
			if (hiliteid == x[i].id) { x[i].src = preloads['o'+x[i].id].src; }
			else {
				x[i].onmouseover = function () {this.src=preloads['o'+this.id].src;}
				x[i].onmouseout = function () {this.src=preloads['n'+this.id].src;}
			}
		}
	}
}

function initNav(hilite) {
	var hilite = (hilite == null) ? 'none' : hilite;
	mouseOverInit('MainNav','a1_n1','gif',hilite);
	mouseOverInit('SubNav','a1_n2','gif',hilite);
}


//
// 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);
}

//
// FORM VALIDATION
//

// Make sure the main search box is not submitted empty. 
function validateSearch (cri) {
	cri = trim(cri);
	if (cri.length) return true;
	else {
		alert('Please enter the keyword(s) on which you would like to search');
		return false;
	}
}