<!-- Begin HTML comment that hides the script ---------------------------------------------
function AutoAdvance(inField, nxtField) {
	if (inField.value.length == inField.maxLength) {
		nxtField.focus();
		try { nxtField.select() } catch (e) {};
	}
}
//-----------------------------------------------------------------------------------------
function mysqlTimeStampToDate(timestamp) {
//function parses mysql datetime string and returns javascript Date object
//input has to be in this format: 2007-06-05 15:26:02
	var regex=/^([0-9]{2,4})-([0-1][0-9])-([0-3][0-9]) (?:([0-2][0-9]):([0-5][0-9]):([0-5][0-9]))?$/;
	var parts=timestamp.replace(regex,"$1 $2 $3 $4 $5 $6").split(' ');
	return new Date(parts[0],parts[1]-1,parts[2],parts[3],parts[4],parts[5]);
}
//-----------------------------------------------------------------------------------------
function DisableButtons(frmName, bolSetting) {
	for (var count = 0 ; count < frmName.elements.length ; count++) {
		if (frmName.elements[count].type == "button" ||
			frmName.elements[count].type == "submit" ||
			frmName.elements[count].type == "reset") {
			frmName.elements[count].disabled = bolSetting;
		}
	}
}
//-----------------------------------------------------------------------------------------
function selectContents(szField) {
	szField.select();
}
//-----------------------------------------------------------------------------------------
function DisableAllFieldsBut(szField, frmName) {
	var bolSetting = false;

	if (szField.value.length > 0) {
		bolSetting = true;
	}
	for (var count = 0 ; count < frmName.elements.length ; count++) {
		if (frmName.elements[count].type == "text" && frmName.elements[count].name != szField.name) {
			frmName.elements[count].value = "";
			frmName.elements[count].disabled = bolSetting;
		}
	}
}
//-----------------------------------------------------------------------------------------
function trimLeadSpace(inField) {
	while (''+inField.value.charAt(0)==' ') {
		inField.value = inField.value.substring(1,inField.textLength);
	}
}
//-----------------------------------------------------------------------------------------
function toggle_onchange(elementId, who) {
// Popup display of additional input fields based on other select box choices on same page
	var whoId;
	var element = document.getElementById(elementId);
	if (typeof  who.options != 'undefined') {
		for (var count = 0 ; count < who.options.length ; count++) {
			whoId = who.options[count].value;
			if (whoId == 'All') whoId = 'DistAll';
			if (elementId != whoId && whoId != 0) {
				if (document.getElementById(whoId)) {
					document.getElementById(whoId).style.display = 'none';
				}
			}
		}
	} else {
		try {
			document.getElementById('DistAll').style.display = 'none';
		} catch (e) {
		}
	}
	if (elementId != 0) {
		if (element) {
			element.style.display = 'block';
			element.focus();
		}	
	}
}
//-----------------------------------------------------------------------------------------
function SSNValid(inField) {
// Strip all non-digit characters from string and then verify.
	var chrSpace	= new String(" ");
	var regxNumOnly	= /^[0-9]$/;
	var regxWhtSpce	= /^\s$/;
	var retValue	= new String();
	var val			= new String(inField.value);
	var bolError	= false;

	for (var count = 0 ; count < val.length ; count++) {
		if ((regxNumOnly.test(Number(val.substring(count, count+1)))) && (!regxWhtSpce.test(val.substring(count, count+1)))) {
			retValue = retValue + val.substring(count, count+1);
		}
	}
	if ((retValue.length > 0 && retValue.length != 9) || isNaN(Number(retValue))) {
		alert("SSN must contain exactly 9 digits");
		bolError = true;
	}
	if (retValue.length > 0) {
		var ssn1 = retValue.substring(0,3);
		var ssn2 = retValue.substring(3,5);
		var ssn3 = retValue.substring(5,9);
//		if (ssn1.substring(0,1) > 7) {
//			alert("The SSN must begin with a number less than 8");
//			bolError = true;
//		}
// Case 186181 - RWH - Removed dashes when populating SSN (07/20/2007)
//		if (ssn2 != "") {
//			ssn2 = "-" + ssn2;
//		}
//		if (ssn3 != "") {
//			ssn3 = "-" + ssn3;
//		}
		val = ssn1 + ssn2 + ssn3;
	} else {
		val = "";
	}
	inField.value = val;
	if (bolError == true) {
		inField.focus();
		return false;
	} else {
		return true;
	}
}
//-----------------------------------------------------------------------------------------
function ssn_onkeypress(inField, inEvt) {
// Only accept digits, backspace, tab, and space.
// If the key was not a number 0-9, the keypress is canceled.
// Automatically add the dashes after 3 and 6 digits.
	var chrBackSp	= 8;
	var chrTab		= 9;
	var chrSpace	= 32;
	var chrDelete	= 46;
	var regxNumOnly	= /^[0-9]$/;
	var inputChar = document.all ? inEvt.keyCode : inEvt.which ? inEvt.which : inEvt.keyCode ? inEvt.keyCode : inEvt.charCode;

	if (!(regxNumOnly.test(Number(String.fromCharCode(inputChar)))) || (inputChar == chrSpace)) {
		if (inputChar != chrBackSp && inputChar != chrTab && inputChar != chrDelete) {
			return false;
		}
	}
//	if (inField.value.length == inField.maxLength) {
//		if (inputChar != chrBackSp && inputChar != chrTab && inputChar != chrDelete) {
//			return false;
//		}
//	}
	if ((inField.value.length == 3 || inField.value.length == 6) && inputChar != chrBackSp) {
		inField.value += "-";
	}
// IE won't capture the Tab key press here.  Leave this in for cross-platform compatibility.
// Don't let them leave a partially completed field.
	if (inputChar == chrTab) {
		return SSNValid(inField);
	}
	return true;
}
//-----------------------------------------------------------------------------------------
function PhoneValid(inField) {
// Strip all non-digit characters from string and then verify.
	var chrSpace	= new String(" ");
	var regxNumOnly	= /^[0-9]$/;
	var regxWhtSpce	= /^\s$/;
	var retValue	= new String();
	var val			= new String(inField.value);
	var bolError	= false;

	for (var count = 0 ; count < val.length ; count++) {
		if ((regxNumOnly.test(Number(val.substring(count, count+1)))) && (!regxWhtSpce.test(val.substring(count, count+1)))) {
			retValue = retValue + val.substring(count, count+1);
		}
	}
	if ((retValue.length > 0 && retValue.length != 10) || isNaN(Number(retValue))) {
		alert("Domestic telephone numbers must contain exactly 10 digits");
		bolError = true;
	}
	if (retValue.length > 0) {
		var ssn1 = retValue.substring(0,3);
		var ssn2 = retValue.substring(3,6);
		var ssn3 = retValue.substring(6,10);
		if (ssn1.substring(0,1) == 0) {
			alert("The telephone number must begin with a number other than 0");
			bolError = true;
		}
		if (ssn2 != "") {
			ssn2 = ")" + ssn2;
		}
		if (ssn3 != "") {
			ssn3 = "-" + ssn3;
		}
		val = "(" + ssn1 + ssn2 + ssn3;
	} else {
		val = "";
	}
	inField.value = val;
	if (bolError == true) {
		inField.focus();
		return false;
	} else {
		return true;
	}
}
//-----------------------------------------------------------------------------------------
function phone_onkeypress(inField, inEvt) {
// Only accept digits, backspace, tab, and space.
// If the key was not a number 0-9, the keypress is canceled.
// Automatically add the parens and dashes after 0, 3 and 6 digits.
	var chrBackSp	= 8;
	var chrTab		= 9;
	var chrSpace	= 32;
	var chrDelete	= 46;
	var regxNumOnly	= /^[0-9]$/;
	var inputChar = document.all ? inEvt.keyCode : inEvt.which ? inEvt.which : inEvt.keyCode ? inEvt.keyCode : inEvt.charCode;

	if (!(regxNumOnly.test(Number(String.fromCharCode(inputChar)))) || (inputChar == chrSpace)) {
		if (inputChar != chrBackSp && inputChar != chrTab && inputChar != chrDelete) {
			return false;
		}
	}
//	if (inField.value.length == inField.maxLength) {
//		if (inputChar != chrBackSp && inputChar != chrTab && inputChar != chrDelete) {
//			return false;
//		}
//	}
	if ((inField.value.length == 0) && inputChar != chrBackSp) {
		inField.value = "(" + inField.value;
	}
	if ((inField.value.length == 4) && inputChar != chrBackSp) {
		inField.value += ")";
	}
	if ((inField.value.length == 8) && inputChar != chrBackSp) {
		inField.value += "-";
	}
// IE won't capture the Tab key press here.  Leave this in for cross-platform compatibility.
// Don't let them leave a partially completed field.
	if (inputChar == chrTab) {
		return PhoneValid(inField);
	}
	return true;
}
//-----------------------------------------------------------------------------------------
function text_onkeypress(inField, inEvt) {
// Only accepts alphabetic characters numbers, commas, hyphens, periods, spaces and apostrophes.
// If the key was not alphabetic, the keypress is canceled.
	var chrBackSp	= 8;
	var chrTab		= 9;
	var chrSpace	= 32;
	var chrEnd		= 35;
	var chrHome		= 36;
	var chrLArrow	= 37;
	var chrRArrow	= 39;
	var chrDelete	= 46;
	var regxNumOnly	= /^[-A-Z0-9\.,' ]$/i;
	var inputChar = document.all ? inEvt.keyCode : inEvt.which ? inEvt.which : inEvt.keyCode ? inEvt.keyCode : inEvt.charCode;

	if (!regxNumOnly.test(String.fromCharCode(inputChar))) {
		if (inputChar != chrBackSp && inputChar != chrTab && inputChar != chrEnd && inputChar != chrHome &&
			inputChar != chrLArrow && inputChar != chrRArrow && inputChar != chrDelete) {
			return false;
		}
	}
// Restrict .,' to only one occurence
	if (String.fromCharCode(inputChar) == ".") {
		try {
			if (szintPeriodCount == 1) {
				return false;
			}
		} catch (e) {
			szintPeriodCount = 1;
		}
	} else if (String.fromCharCode(inputChar) == ",") {
		try {
			if (szintCommaCount == 1) {
				return false;
			}
		} catch (e) {
			szintCommaCount = 1;
		}
	} else if (String.fromCharCode(inputChar) == "'") {
		try {
			if (szintApostCount == 1) {
				return false;
			}
		} catch (e) {
			szintApostCount = 1;
		}
	}
// If field maximum reached, discard any more characters (except backspace, tab, or delete).
//	if (inField.value.length == inField.maxLength) {
//		if (inputChar != chrBackSp && inputChar != chrTab && inputChar != chrDelete) {
//			return false;
//		}
//	}
	return true;
}
//-----------------------------------------------------------------------------------------
// This function formats numbers by adding commas
function numberFormat(nStr){
  nStr += '';
  x = nStr.split('.');
  x1 = x[0];
  x2 = x.length > 1 ? '.' + x[1] : '';
  var rgx = /(\d+)(\d{3})/;
  while (rgx.test(x1))
    x1 = x1.replace(rgx, '$1' + ',' + '$2');
  return x1 + x2;
}
//-----------------------------------------------------------------------------------------
// This function removes non-numeric characters
function stripNonNumeric( str ){
  str += '';
  var rgx = /^\d|\.|-$/;
  var out = '';
  for( var i = 0; i < str.length; i++ ){
    if( rgx.test( str.charAt(i) ) ){
      if( !( ( str.charAt(i) == '.' && out.indexOf( '.' ) != -1 ) ||
             ( str.charAt(i) == '-' && out.length != 0 ) ) ){
        out += str.charAt(i);
      }
    }
  }
  return out;
}
//-----------------------------------------------------------------------------------------
//	This function verifies the data in the field is valid (or empty).
function validateField(inExp, inField, inReqLen) {
	if (inField.value.length > 0) {
		if (!(inExp.test(inField.value))) {
			alert("The field must contain " + inReqLen + " digits.");
			inField.focus();
			inField.select();
			return false;
		} else {
			return true;
		}
	} else {
		return true;
	}
}
//-----------------------------------------------------------------------------------------
function digits_onkeypress(inField, inEvt) {
// Only accept digits, backspace, and tab.
// If the key was not a number 0-9, the keypress is canceled.
	var chrBackSp	= 8;
	var chrTab		= 9;
	var chrSpace	= 32;
	var chrDelete	= 46;
	var regxNumOnly	= /^[0-9]$/;
	var inputChar = document.all ? inEvt.keyCode : inEvt.which ? inEvt.which : inEvt.keyCode ? inEvt.keyCode : inEvt.charCode;

	if (!(regxNumOnly.test(Number(String.fromCharCode(inputChar)))) || (inputChar == chrSpace)) {
		if (inputChar != chrBackSp && inputChar != chrTab && inputChar != chrDelete) {
			return false;
		}
	}
//	if (inField.value.length == inField.maxLength) {
//		if (inputChar != chrBackSp && inputChar != chrTab && inputChar != chrDelete) {
//			return false;
//		}
//	}
}
//-----------------------------------------------------------------------------------------
function emailCheck(field) {
	field.value = field.value.toLowerCase();
	var emailStr = field.value;
	if (emailStr != "") {
/*	The following variable tells the rest of the function whether or not
	to verify that the address ends in a two-letter country or well-known
	TLD.  1 means check it, 0 means don't. */
		var checkTLD=1;
/*	The following is the list of known TLDs that an e-mail address must end with. */
		var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
/*	The following pattern is used to check if the entered e-mail address fits the
	user@domain format.  It also is used to separate the username from the domain. */
		var emailPat=/^(.+)@(.+)$/;
/*	The following string represents the pattern for matching all special characters.
	We don't want to allow special characters in the address.  These characters
	include ( ) < > @ , ; : \ " . [ ] */
		var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
/*	The following string represents the range of characters allowed in a username or
	domainname.  It really states which chars aren't allowed.*/
		var validChars="\[^\\s" + specialChars + "\]";
/*	The following pattern applies if the "user" is a quoted string (in which case,
	there are no rules about which characters are allowed and which aren't; anything
	goes).  E.g. "jiminy cricket"@disney.com is a legal e-mail address. */
		var quotedUser="(\"[^\"]*\")";
/*	The following pattern applies for domains that are IP addresses, rather than
	symbolic names.  E.g. joe@[123.124.233.4] is a legal e-mail address.  NOTE: The
	square brackets are required. */
		var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
/*	The following string represents an atom (basically a series of non-special characters.) */
		var atom=validChars + '+';
/*	The following string represents one word in the typical username.  For example, in
	john.doe@somewhere.com, john and doe are words.  Basically, a word is either an atom
	or quoted string. */
		var word="(" + atom + "|" + quotedUser + ")";
/*	The following pattern describes the structure of the user */
		var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
/*	The following pattern describes the structure of a normal symbolic domain, as
	opposed to ipDomainPat, shown above. */
		var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
/*	Finally, let's start trying to figure out if the supplied address is valid.
	Begin with the coarse pattern to simply break up user@domain into different pieces
	that are easy to analyze. */
		var matchArray=emailStr.match(emailPat);
		if (matchArray==null) {
/*	Too many/few @'s or something; basically, this address doesn't even fit the general
	mold of a valid e-mail address. */
			alert("Email address seems incorrect (check @ and .'s)");
			field.focus();
			field.select();
			return false;
		}
		var user=matchArray[1];
		var domain=matchArray[2];
/*	Start by checking that only basic ASCII characters are in the strings (0-127). */
		for (i=0; i < user.length; i++) {
			if (user.charCodeAt(i)>127) {
				alert("The username contains invalid characters.");
				field.focus();
				field.select();
				return false;
			}
		}
		for (i=0; i < domain.length; i++) {
			if (domain.charCodeAt(i)>127) {
				alert("The domain name contains invalid characters.");
				field.focus();
				field.select();
				return false;
			}
		}
/*	See if "user" is valid */
		if (user.match(userPat)==null) {
//	User is not valid
			alert("The username doesn't seem to be valid.");
			field.focus();
			field.select();
			return false;
		}
/*	If the e-mail address is at an IP address (as opposed to a symbolic	host name)
	make sure the IP address is valid. */
		var IPArray=domain.match(ipDomainPat);
		if (IPArray!=null) {
//	this is an IP address
			for (var i=1;i<=4;i++) {
				if (IPArray[i]>255) {
					alert("Destination IP address is invalid!");
					field.focus();
					field.select();
					return false;
				}
			}
			return true;
		}
//	Domain is symbolic name.  Check if it's valid.
		var atomPat=new RegExp("^" + atom + "$");
		var domArr=domain.split(".");
		var len=domArr.length;
		for (i=0;i < len;i++) {
			domArr[i]=funLenTrim(domArr[i])
			if (domArr[i].search(atomPat)==-1) {
				alert("The domain name does not seem to be valid.");
				field.focus();
				field.select();
				return false;
			}
		}
/*	domain name seems valid, but now make sure that it ends in a known top-level domain
	(like com, edu, gov) or a two-letter word, representing country (us, jp, uk, nl), and
	that there's a hostname preceding the domain or country. */
		if (checkTLD && domArr[domArr.length-1].length!=2 && domArr[domArr.length-1].search(knownDomsPat)==-1) {
			alert("The address must end in a well-known domain or two letter " + "country.");
			field.focus();
			field.select();
			return false;
		}
//	Make sure there's a host name preceding the domain.
		if (len<2) {
			alert("This address is missing a hostname!");
			field.focus();
			field.select();
			return false;
		}
	}
//	If we've gotten this far, everything's valid!
	return true;
}
//-----------------------------------------------------------------------------------------
function funLenTrim(sIn) {
	var sOut = "";
	if (!sIn) {
	} else {
		for (intI=0; intI < sIn.length; intI++) {
			if (sIn.charAt(intI) != " ") {
				sOut = sOut + sIn.charAt(intI);
			}
		}
	}
	return sOut;
}
//-----------------------------------------------------------------------------------------
function showModalUpload(szPage) {
//Display modal dialog for link
	var WindowObjectReference;
	var strValue = szPage;
	if (strValue != "") {
		WindowObjectReference = window.open(strValue,"","status=no,toolbar=no,menubar=no,location=no,titlebar=no,resizable=yes,scrollbars=yes,width=400,height=200,left=25,top=25");
	}
}
//-----------------------------------------------------------------------------------------
function showModalDialog(szDoc) {
//Display modal dialog for link
	var WindowObjectReference;
	var strValue = szDoc.form.ImageURL.value;
	if (strValue != "") {
		WindowObjectReference = window.open(strValue,"","status=no,toolbar=no,menubar=no,location=no,titlebar=no,resizable=yes,scrollbars=yes,width=200,height=200,left=20,top=20");
	} else {
		alert("Please specify a graphic.");
	}
}
//-------------------------------------------------------------------- End HTML Comment -->
