/* This function can be run at any point after the left nav is dropped into the page.
   It will compare the left nav HREFs to the page URL and assign a class to the appropriate, 
   selected left nav item. To force a left nav item to be selected,
   first give it a unique id and then pass that ID into the function.
*/
function leftNavSelector(optionalID) {

var pageSubURL = decodeURI(document.location.pathname);

//strip 'index' file reference from URL (for comparison purposes)
if(pageSubURL.indexOf("/index.") >= 0) { pageSubURL = pageSubURL.substring( 0,pageSubURL.indexOf("/index.")+1 ); }

try {
	if(!optionalID) {
		topNavDiv = document.getElementById("leftNav");
		aArray = topNavDiv.getElementsByTagName("a");
		for(var i = 0; i < aArray.length; ++i) {
			
			var testHref = aArray[i].pathname;
			if(testHref.indexOf("/") != 0) { testHref = "/" + testHref; } // IE doesn't include beginning slash
			
			//strip 'index' file reference from link URLs (for comparison purposes)
			if(testHref.indexOf("/index.") >= 0) { testHref = testHref.substring( 0,testHref.indexOf("/index.")+1 ); }
			
			if(pageSubURL == testHref) {
				// set as selected
				aArray[i].className += " selected";
				
				break;
			} // if(pageSubURL ==...
		}// for i
	} else {
		document.getElementById(optionalID).className += " selected";
	}// else
} catch(err) {}
}

/*******************************************************************
VALIDATION VARs AND SUB-FUNCTIONS
*******************************************************************/

// validation vars
var validationErrorTitle = "Please complete the following information to continue:\n\n";
var postValidateFocus = "";

//Sets the first field with an error to be focused after validation.
function setFirstInvalid(inputObj) {
	if(!validationErrorMessage)	{postValidateFocus = document.getElementById(inputObj);}
}

// This function checks for a valid email address
function validateEmail(fieldID)	{
	var fldObj = document.getElementById(fieldID);
	if(fldObj.value.search(/^\w+((-\w+)|(\.\w+)|(\+\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9][A-Za-z0-9]+$/) == -1) {
		return false;
	} else {
		return true;
	}
}

// This function checks for a valid zip code
function validateZip(fieldID)	{
	var fldObj = document.getElementById(fieldID);
	if(fldObj.value.search(/^\d{5}$/) == -1) {
		return false;
	} else {
		return true;
	}
}