var formSubmitted = false;

function hiliteEntry(o) {
	var c = o.className;
	rExp = / FieldError/gi;
	newC = c.replace(rExp,'');
	o.className = newC + ' FieldOnFocus';
	if (o.type != 'select-one') {
		if (o.focus) { o.focus() }
		if (o.select) { o.select() }
	}
}

function hiliteHelpBtn(i,b) {
	if (document.getElementById) {
		el = document.getElementById(i);
		if (el) {
			if (b == true) {
				var c = el.className;
				rExp = /showHelpImage/gi;
				newC = c.replace(rExp,'showHelpImageHover');
				rExp = /showHelpLabel/gi;
				newC = newC.replace(rExp,'showHelpLabelHover');
				rExp = /hideHelpImage/gi;
				newC = newC.replace(rExp,'hideHelpImageHover');
				rExp = /hideHelpLabel/gi;
				newC = newC.replace(rExp,'hideHelpLabelHover');
				el.className = newC;
			}
			else {
				var c = el.className;
				rExp = /showHelpImageHover/gi;
				newC = c.replace(rExp,'showHelpImage');
				rExp = /showHelpLabelHover/gi;
				newC = newC.replace(rExp,'showHelpLabel');
				rExp = /hideHelpImageHover/gi;
				newC = newC.replace(rExp,'hideHelpImage');
				rExp = /hideHelpLabelHover/gi;
				newC = newC.replace(rExp,'hideHelpLabel');
				el.className = newC;
			}
		}
	}
}

function hiliteImageBtn(i,b) {
	if (document.getElementById) {
		el = document.getElementById(i);
		if (el) {
			if (b == true) {
				var c = el.className;
				rExp = /imageButtonImage/gi;
				newC = c.replace(rExp,'imageButtonImageHilite');
				rExp = /imageButtonLabel/gi;
				newC = newC.replace(rExp,'imageButtonLabelHilite');
				el.className = newC;
			}
			else {
				var c = el.className;
				rExp = /imageButtonImageHilite/gi;
				newC = c.replace(rExp,'imageButtonImage');
				rExp = /imageButtonLabelHilite/gi;
				newC = newC.replace(rExp,'imageButtonLabel');
				el.className = newC;
			}
		}
	}
}

function hiliteMetroBtn(i,b) {
	if (document.getElementById) {
		el = document.getElementById(i);
		if (el) {
			if (b == true) {
				var c = el.className;
				rExp = /showLinksImage/gi;
				newC = c.replace(rExp,'showLinksImageHover');
				rExp = /showLinksLabel/gi;
				newC = newC.replace(rExp,'showLinksLabelHover');
				rExp = /hideLinksImage/gi;
				newC = newC.replace(rExp,'hideLinksImageHover');
				rExp = /hideLinksLabel/gi;
				newC = newC.replace(rExp,'hideLinksLabelHover');
				el.className = newC;
			}
			else {
				var c = el.className;
				rExp = /showLinksImageHover/gi;
				newC = c.replace(rExp,'showLinksImage');
				rExp = /showLinksLabelHover/gi;
				newC = newC.replace(rExp,'showLinksLabel');
				rExp = /hideLinksImageHover/gi;
				newC = newC.replace(rExp,'hideLinksImage');
				rExp = /hideLinksLabelHover/gi;
				newC = newC.replace(rExp,'hideLinksLabel');
				el.className = newC;
			}
		}
	}
}

function hiliteFormsNav(o,i,b) {
	if (document.getElementById) {
		el = document.getElementById('FormsNav_' + i + '_Btn');
		if (el) {
			if (el != o) {
				hiliteFormsNavContinue(el,b);
			}
		}
		el = document.getElementById('FormsNav_' + i + '_Print');
		if (el) {
			if (el != o) {
				hiliteFormsNavContinue(el,b);
			}
		}
		el = document.getElementById('FormsNav_' + i + '_Label');
		if (el) {
			if (el != o) {
				hiliteFormsNavContinue(el,b);
			}
		}
	}
}

function hiliteFormsNavContinue(el,b) {
	if (b == true) {
		var c = el.className;
		rExp = /formsNavText/gi;
		newC = c.replace(rExp,'formsNavTextHover');
		rExp = /gotoForm/gi;
		newC = newC.replace(rExp,'gotoFormHover');
		rExp = /printPDF/gi;
		newC = newC.replace(rExp,'printPDFHover');
		el.className = newC;
	}
	else {
		var c = el.className;
		rExp = /formsNavTextHover/gi;
		newC = c.replace(rExp,'formsNavText');
		rExp = /gotoFormHover/gi;
		newC = newC.replace(rExp,'gotoForm');
		rExp = /printPDFHover/gi;
		newC = newC.replace(rExp,'printPDF');
		el.className = newC;
	}
}

function clearHilite(o) {
	var c = o.className;
	rExp = / FieldOnFocus/gi;
	newC = c.replace(rExp,'');
	o.className = newC;
}

function hiliteButton(o) {
	var c = o.className;
	o.className = c + ' ButtonMouseover';
}

function clearButtonHilite(o) {
	var c = o.className;
	rExp = / ButtonMouseover/gi;
	newC = c.replace(rExp,'');
	o.className = newC;
}

function setError(o) {
	var c = o.className;
	o.className = c + ' FieldError';
	if (document.getElementById) {
		i = o.id;
		v = document.getElementById(i+'Validate');
		if (v) {
			v.value = 1;
		}
		l = document.getElementById(i+'Label');
		if (l) {
			lc = l.className;
			l.className = lc + ' LabelError';
		}
	}
}

function clearError(o) {
	var c = o.className;
	rExp = / FieldError/gi;
	newC = c.replace(rExp,'');
	o.className = newC;
	if (document.getElementById) {
		i = o.id;
		v = document.getElementById(i+'Validate');
		if (v) {
			v.value = 0;
		}
		l = document.getElementById(i+'Label');
		if (l) {
			lc = l.className;
			rExp = / LabelError/gi;
			newLc = lc.replace(rExp,'');
			l.className = newLc;
		}
		ttServerMsg = document.getElementById(i+'ServerMsg');
		if (ttServerMsg) { ttServerMsg.innerHTML = '' }
		ttClientMsg = document.getElementById(i+'ClientMsg');
		if (ttClientMsg) { ttClientMsg.innerHTML = '' }
	}
}

function trimString(str) {
	rExp = /^\s*|\s*$/g;
	return str.replace(rExp,'');
}

function capLock(e) {
	if( !e ) {
		e = window.event;
	}
	kc = e.keyCode?e.keyCode:e.which;
	if (kc == 20) {
		return true;
	}
	sk = e.shiftKey?e.shiftKey:((kc == 16)?true:false);
	// get the src element
	var src = e.srcElement?e.srcElement:e.target;
	// get the last character
	var c = src.value.substr( src.value.length-1,1 );
	// check Upper/Lower case
	if((c != c.toLowerCase() && !sk) || (c != c.toUpperCase() && sk)) {
		alert('CAPS LOCK is on!\n\nThis could adversely impact your logon\nand data entry activities...');
	}
	return true;
}

function properCase(v) {
	var vProper = '';
	var iTemp = v.length;
	if (iTemp == 0) {
		return '';
	}
	vUpper = v.toUpperCase();
	vLower = v.toLowerCase();
	if (v == vUpper || v == vLower) {
		vProper = properCaseContinued(v);
	}
	else {
		vProper = v;
	}
	return vProper;
}

function properCaseContinued(v) {
	var vProper = '';
	var iTemp = v.length;
	if (iTemp == 0) {
		return '';
	}
	var UcaseNext = false;
	if (v.charCodeAt(1) == 39 && v.charAt(0) != 'o') {
		vProper += v.charAt(0).toLowerCase();
	}
	else {
		vProper += v.charAt(0).toUpperCase();
	}
	for (var iCounter=1;iCounter < iTemp;iCounter++) {
		if (UcaseNext == true) {
			vProper += v.charAt(iCounter).toUpperCase();
		}
		else {
			vProper += v.charAt(iCounter).toLowerCase();
		}
		var iChar = v.charCodeAt(iCounter);
		if (iChar == 32 || iChar == 39 || iChar == 45 || iChar == 46 || iChar == 47 || iChar == 92) {
			UcaseNext = true;
		}
		else {
			UcaseNext = false
		}
		if (iChar == 99 || iChar == 67) {
			if (v.charCodeAt(iCounter-1) == 77 || v.charCodeAt(iCounter-1) == 109) {
				UcaseNext = true;
			}
		}
	}
	return vProper;
}

function testCharCode(v) {
	alert(v.charCodeAt(0));
}

function isEmpty(o,v) {
	clearError(o);
	if (document.getElementById) {
		i = o.id;
		var ttHTML = '';
		ttIcon = document.getElementById(i+'TooltipIcon');
		ttMsg = document.getElementById(i+'TooltipMsg');
		if (ttMsg) { ttHTML = ttMsg.innerHTML }
		ttClientMsg = document.getElementById(i+'ClientMsg');
		var clientHTML = '';
		v = trimString(v);
		if (v == '') {
			clientHTML = 'This is a required entry!';
			if (ttClientMsg) { ttClientMsg.innerHTML = clientHTML }
			setError(o);
			if (ttIcon) { ttIcon.className = 'iTooltipError' }
		}
		else {
			if (ttHTML != '') {
				if (ttIcon) { ttIcon.className = 'iTooltip' }
			}
			else {
				if (ttIcon) { ttIcon.className = 'iTooltipHidden' }
			}
		}
		validateForm(o.form);
	}
}

function isRequired(v,r) {
	var e = '';
	if ((r == '-1') || (r == 'True')) {
		if (trimString(v) == '') {
			e = 'This is a required entry!';
		}
	}
	return e;
}

function finishVal(o,clientHTML) {
	o.value = trimString(o.value);
	if (document.getElementById) {
		i = o.id;
		var ttHTML = '';
		ttIcon = document.getElementById(i+'TooltipIcon');
		ttMsg = document.getElementById(i+'TooltipMsg');
		if (ttMsg) { ttHTML = ttMsg.innerHTML }
		ttClientMsg = document.getElementById(i+'ClientMsg');
		ttServerMsg = document.getElementById(i+'ServerMsg');
		if (clientHTML != '') {
			setError(o);
			if (ttClientMsg) { ttClientMsg.innerHTML = clientHTML }
			if (ttServerMsg) { ttServerMsg.innerHTML = '' }
			if (ttIcon) { ttIcon.className = 'iTooltipError' }
		}
		else {
			if (ttHTML != '') {
				if (ttIcon) { ttIcon.className = 'iTooltip' }
			}
			else {
				if (ttIcon) { ttIcon.className = 'iTooltipHidden' }
			}
		}
		validateForm(o.form);
	}
}

function isName(o,v,r) {
	clearError(o);
	var clientHTML = isRequired(v,r);
	if (clientHTML == '' && v != '') {
		rExp = /^[a-z A-ZĄ-’-\'\s]+$/;
		if (!rExp.test(v)) {
			clientHTML = clientHTML + '<p>Name contains invalid characters!</p>';
		}
		o.value = properCase(v);
	}
	finishVal(o,clientHTML);
}

function isNameOrInitial(o,v,r) {
	clearError(o);
	var clientHTML = isRequired(v,r);
	if (clientHTML == '' && v != '') {
		rExp = /^[a-z A-ZĄ-’.\-\'\s]+$/;
		if (!rExp.test(v)) {
			clientHTML = clientHTML + '<p>Name(s) contain invalid characters!</p>';
		}
		else {
			w = rExp.exec(v);
			
		}
		o.value = properCase(v);
	}
	finishVal(o,clientHTML);
}

function isLastName(o,v,r) {
	clearError(o);
	var clientHTML = isRequired(v,r);
	if (clientHTML == '' && v != '') {
		rExp = /^[a-z A-ZĄ-’.\-\'\s]+$/;
		if (!rExp.test(v)) {
			clientHTML = clientHTML + '<p>Name contains invalid characters!</p>';
		}
		o.value = properCase(v);
	}
	finishVal(o,clientHTML);
}

function isSSN(o,v,r) {
	if (document.getElementById) {
		i = o.id;
		part = i.substring(0,i.length - 1);
		var ssn = '';
		var clientHTML = '';
		partA = document.getElementById(part+'A');
		partB = document.getElementById(part+'B');
		partC = document.getElementById(part+'C');
		clearError(partA);
		clearError(partB);
		clearError(partC);
		clientHTML = clientHTML + isRequired(partA.value,r);
		if (trimString(partA.value) != '') {
			ssn = partA.value;
			rExp = /^\d{3}$/;
			if (!rExp.test(partA.value)) {
				clientHTML = clientHTML + '<p>1st part of SSN not formatted correctly!</p>';
			}
		}
		else {
			if (trimString(partB.value) != '' || trimString(partC.value) != '') {
				clientHTML = clientHTML + '<p>1st part of SSN is missing!</p>';
			}
		}
		clientHTML = clientHTML + isRequired(partB.value,r);
		if (trimString(partB.value) != '') {
			ssn = ssn + partB.value;
			rExp = /^\d{2}$/;
			if (!rExp.test(partB.value)) {
				clientHTML = clientHTML + '<p>2nd part of SSN not formatted correctly!</p>';
			}
		}
		else {
			if (trimString(partA.value) != '' || trimString(partC.value) != '') {
				clientHTML = clientHTML + '<p>2nd part of SSN is missing!</p>';
			}
		}
		clientHTML = clientHTML + isRequired(partC.value,r);
		if (trimString(partC.value) != '') {
			ssn = ssn + partC.value;
			rExp = /^\d{4}$/;
			if (!rExp.test(partC.value)) {
				clientHTML = clientHTML + '<p>3rd part of SSN not formatted correctly!</p>';
			}
		}
		else {
			if (trimString(partA.value) != '' || trimString(partB.value) != '') {
				clientHTML = clientHTML + '<p>3rd part of SSN is missing!</p>';
			}
		}
		if (clientHTML == '') {
			char1 = ssn.charAt(0);
			var n = 0;
			for (x=0;x<ssn.length;x++) {
				if (ssn.charAt(x) == char1) {
					n++;
				}
			}
			if (n > 5) {
				clientHTML = clientHTML + '<p>Does not appear to be a valid SSN (there are too many repeating numbers)!</p>';
			}
		}
		finishVal(partA,clientHTML);
		finishVal(partB,clientHTML);
		finishVal(partC,clientHTML);
	}
}

function isEmail(o,v,r) {
	clearError(o);
	var clientHTML = isRequired(v,r);
	if (clientHTML == '' && v != '') {
		rExp = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
		if (!rExp.test(v)) {
			clientHTML = clientHTML + '<p>E-mail address not formatted correctly!</p>';
		}
	}
	finishVal(o,clientHTML);
}

function isEmailOld(o,v,r) {
	clearError(o);
	var clientHTML = isRequired(v,r);
	if (clientHTML == '' && v != '') {
		rExp = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
		if (!rExp.test(v)) {
			clientHTML = clientHTML + '<p>E-mail address not formatted correctly!</p>';
		}
		else {
			optout = o.id + 'Optout';
			if (document.getElementById(optout)) {
				document.getElementById(optout).checked = false;
			}
		}
	}
	else {
		optout = o.id + 'Optout';
		if (document.getElementById(optout)) {
			if (document.getElementById(optout).checked == true) {
				clientHTML = '';
			}
		}
	}
	finishVal(o,clientHTML);
}

function optoutEmail(i) {
	o = document.getElementById(i);
	if (o) {
		v = o.value;
		r = false;
		isEmail(o,v,r);
	}
}

function isLogonId(o,v,r) {
	clearError(o);
	var clientHTML = isRequired(v,r);
	if (clientHTML == '' && v != '') {
		rExp = /^d{7}$/;
		if (!rExp.test(v)) {
			clientHTML = clientHTML + '<p>Logon ID not formatted correctly!</p>';
		}
	}
	finishVal(o,clientHTML);
}

function isPassword(o,v,r) {
	clearError(o);
	var clientHTML = isRequired(v,r);
	if (clientHTML == '' && v != '') {
		rExp1 = /^[A-Za-z]\w{4,}[A-Za-z]$/;
		rExp2 = /^\w*(?=\w*\d)(?=\w*[a-z])(?=\w*[A-Z])\w*$/;
		if (!rExp1.test(v) || !rExp2.test(v)) {
			clientHTML = clientHTML + '<p>Password not formatted correctly!</p>';
		}
	}
	finishVal(o,clientHTML);
}

function isUSPhone(o,v,r) {
	clearError(o);
	var clientHTML = isRequired(v,r);
	if (clientHTML == '' && v != '') {
		rExpUS = /^((\([1-9]\d{2}\)\s?)|([1-9]\d{2}(\.|\-|\s)?))([1-9]\d{2})(\.|\-|\s)?(\d{4})(\s?((x|xtn|ext|extn|extension)\s?)?\d(1,5))?$/;
		if (!rExpUS.test(v)) {
			clientHTML = clientHTML + '<p>Phone number not formatted correctly!</p>';
		}
	}
	finishVal(o,clientHTML);
}

function isIntlPhone(o,v,r) {
	clearError(o);
	var clientHTML = isRequired(v,r);
	if (clientHTML == '' && v != '') {
		rExpIntl = /^(\+\d{1,3}(\.|\-|\s)?)?((\(\d{2,5}\)\s?)|(\d{2,5}(\.|\-|\s)?))(\d{3}(\.|\-|\s)?\d{0,7})(\s?((x|xtn|ext|extn|extension)\s?)?\d{1,5})?$/i;
		if (!rExpIntl.test(v)) {
			rExpUS = /^((\([1-9]\d{2}\)\s?)|([1-9]\d{2}(\.|\-|\s)?))([1-9]\d{2})(\.|\-|\s)?(\d{4})(\s?((x|xtn|ext|extn|extension)\s?)?\d{1,5})?$/;
			if (!rExpUS.test(v)) {
				clientHTML = clientHTML + '<p>Phone number not formatted correctly!</p>';
			}
		}
	}
	finishVal(o,clientHTML);
}

function isURL(o,v,r) {
	clearError(o);
	var clientHTML = isRequired(v,r);
	if (clientHTML == '' && v != '') {
		rExpURL = /^(((http(s?))|(ftp))\:\/\/)?(www.|[a-zA-Z].)[a-zA-Z0-9\-\.]+\.(com|edu|gov|mil|net|org|biz|info|name|museum|us|ca|uk|de)(\:[0-9]+)*(\/($|[a-zA-Z0-9\.\,\;\?\'\\\+&%\$#\=~_\-]+))*$/;
		if (!rExpURL.test(v)) {
			clientHTML = clientHTML + '<p>Website URL not formatted correctly!</p>';
		}
	}
	finishVal(o,clientHTML);
}

function isPostalCode(o,v,r) {
	clearError(o);
	var clientHTML = isRequired(v,r);
	if (clientHTML == '' && v != '') {
		o.value = properCase(v);
	}
	finishVal(o,clientHTML);
}

function isCity(o,v,r) {
	clearError(o);
	var clientHTML = isRequired(v,r);
	if (clientHTML == '' && v != '') {
		o.value = properCase(v);
	}
	finishVal(o,clientHTML);
}

function isCountry(o,v,r) {
	clearError(o);
	var clientHTML = isRequired(v,r);
	if (clientHTML == '' && v != '') {
		o.value = properCase(v);
	}
	finishVal(o,clientHTML);
}

function isState(o,v,r) {
	clearError(o);
	var clientHTML = isRequired(v,r);
	if (clientHTML == '' && v != '') {
		if (v.length >= 3) {
			o.value = properCase(v);
		}
		else {
			o.value = v.toUpperCase();
		}
	}
	finishVal(o,clientHTML);
}

function isAcronym(o,v,r) {
	clearError(o);
	var clientHTML = isRequired(v,r);
	if (clientHTML == '' && v != '') {
		o.value = v.toUpperCase();
	}
	finishVal(o,clientHTML);
}

function isAddress(o,v,r) {
	clearError(o);
	var clientHTML = isRequired(v,r);
	if (clientHTML == '' && v != '') {
		o.value = properCase(v);
	}
	finishVal(o,clientHTML);
}

function isCapitalized(o,v,r) {
	clearError(o);
	var clientHTML = isRequired(v,r);
	if (clientHTML == '' && v != '') {
		o.value = properCase(v);
	}
	finishVal(o,clientHTML);
}

function isNumeric(o,v,r) {
	clearError(o);
	var clientHTML = isRequired(v,r);
	if (clientHTML == '' && v != '') {
		rExpNum = /^\d+(\.\d{1,2})?$/;
		if (!rExpNum.test(v)) {
			clientHTML = clientHTML + '<p>Number not formatted correctly!</p>';
		}
	}
	finishVal(o,clientHTML);
}

function isInteger(o,v,r) {
	clearError(o);
	var clientHTML = isRequired(v,r);
	if (clientHTML == '' && v != '') {
		rExpNum = /(^-?\d\d*$)/;
		if (!rExpNum.test(v)) {
			clientHTML = clientHTML + '<p>Integer not formatted correctly!</p>';
		}
	}
	finishVal(o,clientHTML);
}

function isCurrency(o,v,r) {
	clearError(o);
	var clientHTML = isRequired(v,r);
	if (clientHTML == '' && v != '') {
		rExpCurr = /^\d+\.\d\d$/;
		if (!rExpCurr.test(v)) {
			clientHTML = clientHTML + '<p>Currency not formatted correctly!</p>';
		}
	}
	finishVal(o,clientHTML);
}

function isDate(o,v,r) {
	clearError(o);
	var clientHTML = isRequired(v,r);
	if (v != 'REFRESH') {
		if (clientHTML == '' && v != '') {
			rExpNum = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/;
			if (!rExpNum.test(v)) {
				clientHTML = clientHTML + '<p>Date not formatted correctly!</p>';
			}
			else {
				var validDate = false; //assume date value is invalid
				for (i=0; i<v.length; i++) {
					if ((v.charAt(i)>'9') || (v.charAt(i)<'0')) {
						break;
					}
				}
				var sepChar = v.charAt(i);
				var arrayDate = v.split(sepChar); //split date into month, day, year
				var iMo = parseInt(arrayDate[0]);
				var iDay = parseInt(arrayDate[1]);
				var iYr = parseInt(arrayDate[2]);
				if ((iMo == 1) || (iMo == 3) || (iMo == 5) || (iMo == 7) || (iMo == 8) || (iMo == 10) || (iMo == 12)) {
					if (iDay <= 31 && iDay != 0) {
						validDate = true;
					}
				}
				if ((iMo == 4) || (iMo == 6) || (iMo == 9) || (iMo == 11)) {
					if (iDay <= 30 && iDay != 0) {
						validDate = true;
					}
				}
				if (iMo == 2) { 
					if (((iYr % 4 == 0 && iDay <= 29) || (iYr % 4 != 0 && iDay <=28)) && iDay !=0) {
						validDate = true; //Feb. had valid number of days
					}
				}
				if (validDate == false) {
					clientHTML = clientHTML + '<p>Entry is not a valid M-D-Y date!</p>';
				}
				else {
					if (iYr < 1850 || iYr > 2150) {
						clientHTML = clientHTML + '<p>Date is outside expected ranges!</p>';
					}
				}
			}
		}
	}
	finishVal(o,clientHTML);
}

function isTime(o,v,r) {
	clearError(o);
	var clientHTML = isRequired(v,r);
	if (v != 'REFRESH') {
		if (clientHTML == '' && v != '') {
			rExpNum = /^\d{2}\:\d{2}\s(AM|PM)$/;
			if (!rExpNum.test(v)) {
				clientHTML = clientHTML + '<p>Time not formatted correctly!</p>';
			}
		}
	}
	finishVal(o,clientHTML);
}

function jumpToNext(o,max,i,e) {
	if (!e) var e = window.event;
	var keyCode;
	var skipCodes;
	if (e.keyCode) {
		keyCode = e.keyCode;
		skipCodes = [0,8,9,16,17,18,37,38,39,40,46];
	}
	else if (e.which) {
		keyCode = e.which;
		skipCodes = [0,8,9];
	}
	if (document.getElementById) {
		if (o.value.length >= max && !containsElement(skipCodes,keyCode)) {
			targEl = document.getElementById(i);
			if (targEl.focus) { targEl.focus() }
		}
	}
}

function containsElement(arr, ele) {
	var found = false, index = 0;
	while(!found && index < arr.length)
		if(arr[index] == ele)
			found = true;
		else index++;
	return found;
}

function validateForm(frm) {
	if (formSubmitted == true) {
		msg = 'You have already pressed the "Save" button.\nPlease wait...';
		alert(msg);
		return;
	}
	var e = 0;
	for (i=0;i<frm.length;i++) {
		f = frm[i];
		if (f.type == 'text' || f.type == 'password') {
			n = f.name;
			if (document.getElementById) {
				v = document.getElementById(n + 'Validate');
				if (v) {
					e += parseInt(v.value);
				}
			}
		}
	}
	for (i=0;i<frm.length;i++) {
		f = frm[i];
		if (f.type == 'submit' || (f.type == 'button' && f.value == 'fauxSubmit')) {
			var c = f.className;
			rExp = / ButtonDisabled/gi;
			newC = c.replace(rExp,'');
			if (e > 0) {
				f.disabled = true;
				f.className = newC + ' ButtonDisabled';
			}
			else {
				f.disabled = false;
				f.className = newC;
			}
		}
	}
}

function resetForm() {
	if (confirm('Click OK to reset this page.\n\nNOTE: You will lose all unsaved entries.')) {
		window.location.reload(false);
	}
}

function formsNav(t) {
	if (confirm('Click OK to leave this form now.\n\nNOTE: You will lose all unsaved entries.')) {
		document.location = t;
	}
}

function formsPrint(t) {
	if (objPopup && !objPopup.closed && objPopup.location)	{
		objPopup.location.href = t;
		if (objPopup.focus) {
			objPopup.focus();
		}
	}
	else {
		if (tP == 0) {
			if (confirm('It appears popups are blocked so PDF\nwill have to be opened in this window.\n\nClick OK to leave this form now.\n\nNOTE: You will lose all unsaved entries.')) {
				document.location = t;
			}
		}
		else {
			objPopup = window.open(t,'printPDF','toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
			if (objPopup.focus) {
				objPopup.focus();
			}
		}
	}
}

function showFormsHelp(i) {
	if (document.getElementById) {
		document.getElementById('show' + i).style.display = 'none';
		document.getElementById(i).style.display = 'block';
		if (!window.opener) {
			//resizeLayoutLite();
		}
	}
}

function hideFormsHelp(i) {
	if (document.getElementById) {
		document.getElementById(i).style.display = 'none';
		document.getElementById('show' + i).style.display = 'block';
		if (!window.opener) {
			//resizeLayoutLite();
		}
	}
}

function showNavHelp() {
	if (document.getElementById) {
		document.getElementById('showNavHelp').style.display = 'none';
		document.getElementById('formsNavHelp').style.display = 'block';
	}
}

function hideNavHelp() {
	if (document.getElementById) {
		document.getElementById('formsNavHelp').style.display = 'none';
		document.getElementById('showNavHelp').style.display = 'block';
	}
}

function cancelForm() {
	if (confirm('Click OK to leave this form now.\n\nNOTE: You will lose all unsaved entries.')) {
		history.back();
	}
}

function newEnroll() {
	//document.location = '/logon/enroll/intro.asp';
	document.location = '/logon/registration/intro.asp';
	pageWait();
}

function newEnrollSubject(subj) {
	//document.location = '/logon/enroll/intro.asp?subj=' + escape(subj);
	document.location = '/logon/registration/intro.asp?subj=' + escape(subj);
	pageWait();
}

function recoverLogonId() {
	document.frmMisc.action = '/logon/rescue/logon.asp';
	document.frmMisc.submit();
	pageWait();
}

function recoverLogonPwd() {
	document.frmMisc.action = '/logon/rescue/password.asp';
	document.frmMisc.submit();
	pageWait();
}

function toggleTextarea(o,i) {
	var c = o.className;
	if (document.getElementById) {
		fld = document.getElementById(i);
		if (fld) {
			var r = fld.rows;
			if (c == 'expandTextarea') {
				o.className = 'collapseTextarea';
				fld.rows = (r * 5);
			}
			else {
				o.className = 'expandTextarea';
				fld.rows = (r / 5);
			}
			if (!window.opener) {
				//resizeLayoutLite();
			}
			//clearCurrentButton();
		}
	}
}

function charCounter(o,c,max) {
	if (document.getElementById) {
		var v = o.value;
		var vLen = v.length;
		if (vLen >= max) {
			vLen = max;
			o.value = v.substr(0,max);
		}
		var cEl = document.getElementById(c);
		if (cEl) {
			var cTxt = cEl.innerHTML;
			cEl.innerHTML = cTxt.replace(cTxt,vLen);
		}
		return false;
	}
}

function trimTextarea(o,c) {
	if (document.getElementById) {
		var v = o.value;
		v = v.replace(/(\r\n\s*){2,}/g, '\r\n\r\n');
		v = v.replace(/(\n\s*){2,}/g, '\n\n');
		v = trimString(v);
		var vLen = v.length;
		o.value = v;
		var cEl = document.getElementById(c);
		if (cEl) {
			var cTxt = cEl.innerHTML;
			cEl.innerHTML = cTxt.replace(cTxt,vLen);
		}
	}
}

function clearRadios(o,r) {
	if (o.form.elements[r]) {
		el = o.form.elements[r];
		for (var i=0; i<el.length; i++) {
			el[i].checked = false;

		}
		o.checked = false;
		o.blur();
		el[0].focus();
	}
}

function radioCheckbox(o) {
	cbn = o.name + 'Checkbox';
	if (o.form.elements[cbn]) {
		el = o.form.elements[cbn];
	}
}

function select_onkeydown(e) {
	// Prevent IE's annoying habit of mapping Backspace to History.Back()
	if (!e) var e = window.event;
	if (e.keyCode == 8) {  // 'Backspace'
		e.keyCode = 0;
		e.returnValue = false;
		return false;
	}
}


function setFormFocus() {
	if (document.frmAddEdit) {
		var found = false;
		for (i=0; i < document.frmAddEdit.length; i++) {
			if (document.frmAddEdit[i].type != "hidden") {
				if (document.frmAddEdit[i].disabled != true) {
					document.frmAddEdit[i].focus();
					break;
				}
				break;
			}
		}
	}
}

addLoadEvent(setFormFocus);

