// 08/10/2001

// ##################################################################
// # CheckFormExample()                                             #
// # 05/21/2001                                                     #
// ##################################################################
// #----------------------------------------------------------------#
// # DESCRIPTION:                                                   #
// #----------------------------------------------------------------#
// # CheckFormExample() makes sure that a form has been properly    #
// # completed by performing the following 5 checks:                #
// # >>  DOES THE PHONE # MATCH THE GIVEN MASK?                     #
// # >>  DOES THE PHONE EXT. INCLUDE ONLY NUMBERS?                  #
// # >>  IS THE E-MAIL ADDRESS IN THE CORRECT FORMAT?               #
// # >>  IS THE DATE IN THE CORRECT FORMAT?                         #
// # >>  DO ALL REQUIRED FIELDS HAVE A VALUE?                       #
// #----------------------------------------------------------------#
// # USAGE:                                                         #
// #----------------------------------------------------------------#
// # Copy this function into any page containing forms that require #
// # any of the checks listed above.  Read over all functions to be #
// # called in order to properly format you page.  Return the value #
// # of this function onsubmit of the form to be checked.           #
// #----------------------------------------------------------------#
// ##################################################################

function CheckFormExample() {

	var formName  = "frmReport";	              // FORM NAME
	var phoneName = "Phone";                      // PHONE# FIELD
	var phoneMask = "###-###-####";               // PHONE# FORMAT
	var extName   = "Ext.";                       // PHONE EXT. FIELD 
	var emailName = "E-mail";                     // E-MAIL FIELD
	var emailSamp = "your_name@your_email.com";   // SAMPLE E-MAIL 
	var dateName  = "Needed by Date";             // DATE FIELD

	// DOES THE PHONE# MATCH THE GIVEN MASK?...
 	if (CheckMask(formName, phoneName, phoneMask) == false) {
 		document.forms[formName].elements[phoneName].focus();
 		document.forms[formName].elements[phoneName].select();
 		//alert("Please enter a valid " + phoneName + ".\n(i.e., xxx-xxx-xxxx)");
 		return false;
 	}

	// DOES THE PHONE EXT. INCLUDE ONLY NUMBERS?...
	if (CheckExt(formName, extName) == false) {
		document.forms[formName].elements[extName].focus();
		document.forms[formName].elements[extName].select();
		alert("Please enter a valid Phone Extension.");
		return false;
 	}

 	// IS THE E-MAIL ADDRESS IN THE CORRECT FORMAT?...
 	// IS THE E-MAIL ADDRESS THE SAME AS THE SAMPLE E-MAIL?...
 	if (CheckEmail(formName, emailName) == false ||
    document.forms[formName].elements[emailName].value == emailSamp) {
 		document.forms[formName].elements[emailName].focus();
 		document.forms[formName].elements[emailName].select();
 		//alert('Please enter a valid E-mail Address.\n(i.e., your_name@your_email.com)');
 		return false;
	}

 	// IS THE DATE IN THE CORRECT FORMAT?...
	if (CheckDate(formName, dateName) == false) {
		document.forms[formName].elements[dateName].focus();
		document.forms[formName].elements[dateName].select();
		alert("Please enter a valid " + dateName + ".\n(i.e., mm/dd/yyyy)");
		return false;
	}

	// DO ALL REQUIRED FIELDS HAVE A VALUE?...
	if (ReqField(formName) == false) return false;

	return true;
	// IF IT GETS THIS FAR, SUBMIT!

} // END FUNCTION

// ##################################################################
// # ReqField()                                                     #
// # 06/27/2001                                                     #
// ##################################################################
// #----------------------------------------------------------------#
// # DESCRIPTION:                                                   #
// #----------------------------------------------------------------#
// # ReqField() makes sure that all required fields in a Form have  #
// # a value.  If a required field is blank, the cursor is taken to #
// # that field, and returns FALSE.  Returns TRUE if there is a     # 
// # value.                                                         #
// #----------------------------------------------------------------#
// # USAGE:                                                         #
// #----------------------------------------------------------------#
// # Set any required field's ID attribute to "req".  Also set the  #
// # field's NAME attribute to match the field's label, because it  #
// # uses that attribute to generate an alert to the user (i.e.,    #
// # <input id="req" name="Contact Name"...> would generate the     #
// # error, "Contact Name is a required field.").  This function is #
// # called from CheckFormExample(); so if you are not using that   #
// # function, then return the value of this function onsubmit of   #
// # the form to be checked.                                        #
// #----------------------------------------------------------------#
// ##################################################################

function ReqField(formName)  {
// formName: FORM NAME

	var count = 0
	// CURRENT FORM ELEMENT
	
	while ((count < document.forms[formName].elements.length))  {   
	// LOOP THROUGH ALL FORM ELEMENTS
		if (document.forms[formName].elements[count].value == '' &&
	    document.forms[formName].elements[count].id == 'req')  {
		// IF THE FIELD IS EMPTY AND IF THE FIELD IS REQUIRED...
			//MOVE CURSOR, HIGHLIGHT FIELD, & GENERATE ERROR...
 			document.forms[formName].elements[count].focus();
 			document.forms[formName].elements[count].select();
			alert(document.forms[formName].elements[count].name + " is a required field.");
			return false;
		}

		count ++;
		// INCREMENT TO NEXT FORM ELEMENT

	}

	return true;
	//return false;

} // END FUNCTION

// ##################################################################
// # CheckMask()                                                    #
// # 05/21/2001                                                     #
// ##################################################################
// #----------------------------------------------------------------#
// # DESCRIPTION:                                                   #
// #----------------------------------------------------------------#
// # CheckMask() makes sure a number matches a given mask.  Returns #
// # FALSE if the given field does not match the correct number     #
// # format.  This works with many standard number masks ("$##.##", #
// # "###-##-####", etc.).                                          #
// #----------------------------------------------------------------#
// # USAGE:                                                         #
// #----------------------------------------------------------------#
// # Use the following characters in the mask to designate its      #
// # usage:                                                         #
// # >> "#" = ANY NUMBER                                            #
// # >> "?" = ANY LETTER                                            #
// # >> "!" = ANY NUMBER OR LETTER                                  #
// # >> "*" = ANY CHARACTER WHATSOEVER                              #
// # >> ANY OTHER CHARACTERS INCLUDED IN THE MASK MUST BE MATCHED   #
// #    EXACTLY.                                                    #
// #----------------------------------------------------------------#
// ##################################################################

function CheckMask(formName, elemName, mask)  {
// formName: FORM NAME
// elemName: FIELD TO BE CHECKED
// mask: MASK TO CHECK FIELD AGAINST
//
//alert(formName);
//alert(elemName);
//alert(mask);

	var inString = document.forms[formName].elements[elemName].value;  
	// FIELD VALUE
	var lenStr = inString.length; // VALUE LENGTH
	var lenMsk = mask.length;     // MASK LENGTH
 	
 	//alert(lenMsk);
 	//alert(lenStr);
	if (inString == "" &&                                              
    document.forms[formName].elements[elemName].id != 'req')  { 
	// IF THE FIELD IS EMPTY AND IF IT IS NOT REQUIRED THEN STOP...
		return true;
	}
	
	if (lenStr != lenMsk) {
		//alert("here3");
		alert(elemName + " has the following format: " + mask);
		document.forms[formName].elements[elemName].focus();
	 return false;
	 }
	// FIELD LENGTH MUST MATCH THE MASK

	for (count = 0; count <= inString.length; count ++)  { 
	// LOOP THROUGH ALL CHARACTERS...

		var strChar = inString.substring(count, count + 1); 
		// CURRENT FIELD CHARACTER
		var mskChar = mask.substring(count, count + 1);
		// CURRENT MASK CHARACTER

		if (mskChar == '#') {          // "#" FOR A NUMBER
			if(!IsNumberChar(strChar)) return false;
 		} else if (mskChar == '?') {   // "?" FOR A LETTER
			if(!IsAlphabeticChar(strChar)) return false;
		} else if (mskChar == '!') {   // "!" FOR A NUMBER OR LETTER
			if(!IsNumOrChar(strChar)) return false;
		} else if (mskChar == '*') {   // "*" FOR ANYTHING
		} else {
			if (mskChar != strChar) return false;
			// OTHERWISE, CHARACTERS MUST MATCH EXACTLY
		}

	}

 	return true;
 	//return false;

} // END FUNCTION

// ##################################################################
// # IsAlphabeticChar()                                             #
// # 05/21/2001                                                     #
// ##################################################################
// #----------------------------------------------------------------#
// # DESCRIPTION:                                                   #
// #----------------------------------------------------------------#
// # IsAlphabeticChar() makes sure a given string contains only     #
// # letters.  Returns FALSE if the given string contains any       #
// # non-letter characters.  Returns TRUE if it contains only       #
// # letters.                                                       #
// #----------------------------------------------------------------#
// # USAGE:                                                         #
// #----------------------------------------------------------------#
// # Designed to be used in conjunction with CheckMask() to check a #
// # string against a given mask.  The designation in CheckMask()   #
// # for an alphabetic character is '?'.                            #
// #----------------------------------------------------------------#
// ##################################################################

function IsAlphabeticChar(inString)  {
// inString: STRING TO BE CHECKED

 	var refString = "abcdefghijklmnopqrstuvwxyz";
 	inString = inString.toLowerCase();

 	if(inString.length != 1) return false;
 	if(refString.indexOf(inString.toLowerCase(), 0) == -1) return false;

	return true;

} // END FUNCTION

// ##################################################################
// # IsNumberChar()                                                 #
// # 05/21/2001                                                     #
// ##################################################################
// #----------------------------------------------------------------#
// # DESCRIPTION:                                                   #
// #----------------------------------------------------------------#
// # IsNumberChar() makes sure a given string contains only nums.   # 
// # Returns FALSE if the given string contains any non-number      #
// # characters.  Returns TRUE if it contains only numbers.         #
// #----------------------------------------------------------------#
// # USAGE:                                                         #
// #----------------------------------------------------------------#
// # Designed to be used in conjuction with CheckMask() to check a  #
// # string against a given mask.  The designation in CheckMask()   #
// # for a numeric character is '#'.  Also used by CheckExt() to    #
// # check whether a given string could be a valid phone            #
// # extenstion.                                                    #
// #----------------------------------------------------------------#
// ##################################################################

function IsNumberChar(inString)  {
// inString: STRING TO BE CHECKED

	var refString = "1234567890";

	if(inString.length != 1) return false;
	if(refString.indexOf(inString, 0) == -1) return false;

	return true;

} // END FUNCTION

// ##################################################################
// # IsNumOrChar()                                                  #
// # 05/21/2001                                                     #
// ##################################################################
// #----------------------------------------------------------------#
// # DESCRIPTION:                                                   #
// #----------------------------------------------------------------#
// # IsNumOrChar() makes sure a given string contains only letters  #
// # or numbers.  Returns FALSE if the given string contains any    # 
// # non-letter or non-number characters.                           #
// #----------------------------------------------------------------#
// # USAGE:                                                         #
// #----------------------------------------------------------------#
// # Designed to be used in conjuction with CheckMask() to check a  #
// # string against a given mask.  The designation in CheckMask()   #
// # for any alphbetic or numeric character is '*'.                 #
// #----------------------------------------------------------------#
// ##################################################################

function IsNumOrChar(inString) {
// inString: STRING TO BE CHECKED

	var refString = "1234567890abcdefghijklmnopqrstuvwxyz";
 	inString = inString.toLowerCase();

 	if(inString.length != 1) return false;
 	if(refString.indexOf(inString, 0) == -1) return false;

 	return true;

} // END FUNCTION

// ##################################################################
// # CheckExt()                                                     #
// # 05/21/2001                                                     #
// ##################################################################
// #----------------------------------------------------------------#
// # DESCRIPTION:                                                   #
// #----------------------------------------------------------------#
// # CheckExt() makes sure a given Phone Extension is valid.        #
// # Returns FALSE if the string contains any non-number chars.     #
// #----------------------------------------------------------------#
// # USAGE:                                                         #
// #----------------------------------------------------------------#
// # Designed to be used in conjunction with CheckFormExample().    #
// # If the user does input a number, then this will pick it up; if #
// # it is  left blank, the field is ignored.  Do NOT require the   #
// # phone ext. field using ReqField() unless absolutely sure that  #
// # EVERY user will have an extension.  By requiring this field,   #
// # if the field is left blank, returns FALSE for error.           #
// #----------------------------------------------------------------#
// ##################################################################

function CheckExt(formName, elemName) {
// formName: FORM NAME
// elemName: ELEMENT TO BE CHECKED

 	var inString = document.forms[formName].elements[elemName].value;  
 	// FIELD VALUE
 	var lenStr = inString.length;  // VALUE LENGTH

 	if (inString == "" &&              
    document.forms[formName].elements[elemName].id != 'req') {
	// IF THE FIELD IS EMPTY AND IF IT IS NOT REQUIRED THEN...
 		return true;
 	}
 	
 	for (count = 0; count < lenStr; count ++) { 
 	// LOOP THROUGH EACH CHARACTER...
 		var strChar = inString.substring(count, count + 1);  
 		// CURRENT CHARACTER
 		if(!IsNumberChar(strChar)) return false;             
 	}

 	return true;

} // END FUNCTION

// ##################################################################
// # CheckEmail()                                                   #
// # 05/21/2001                                                     #
// ##################################################################
// #----------------------------------------------------------------#
// # DESCRIPTION:                                                   #
// #----------------------------------------------------------------#
// # CheckEmail() makes sure a given e-mail address matches the     #
// # correct format.  Checks for "@" & ".", and verifies proper     #
// # spacing.  This will not actually verify whether the e-mail     #
// # address actually exists, but it rather checks whether it COULD #
// # actually exist.  If the e-mail address does not check out,     #
// # returns FALSE.  Returns TRUE if it is OK.                      #
// #----------------------------------------------------------------#
// # USAGE:                                                         #
// #----------------------------------------------------------------#
// # If you provide an example of an e-mail address, you may want   #
// # to trap for that e-mail address.  For example, if you put      #
// # john_doe@anywhere.com as an example for this field, you may    #
// # want to show an error message if the user copies that example. #
// # CheckFormExample() includes a sample e-mail check.             #
// #----------------------------------------------------------------#
// ##################################################################

function CheckEmail(formName, elemName) {
// formName: FORM NAME
// elemName: ELEMENT TO BE CHECKED

 	var inString = document.forms[formName].elements[elemName].value; 
 	// FIELD VALUE
 	var atSymbol = inString.indexOf('@');    // AN AT SYMBOL ("@")
 	var period = inString.lastIndexOf('.');  // A PERIOD (".")
 	var space = inString.indexOf(' ');       // A SPACE ("_")
 	var lenStr = inString.length;            // VALUE LENGTH

	if (inString == "" && 
    document.forms[formName].elements[elemName].id != 'req') {  
	// IF THE FIELD IS EMPTY AND IF IT IS NOT REQUIRED THEN...
		return true;
	}

 	if ((atSymbol < 1) ||        // "@" CANNOT BE IN THE 1ST POSITION
    (period <= atSymbol + 1) ||  // AT LEAST ONE VALID CHARACTER BETWEEN "@" & "."
    (period == lenStr - 1) ||    // MUST BE AT LEAST ONE VALID CHARACTER AFTER "."
    (space != -1)) {             // NO EMPTY SPACES ARE PERMITTED
    alert(elemName + " has the following format: Email@Domain.com");
		document.forms[formName].elements[elemName].focus();
 		return false;
	}

 	return true;

} // END FUNCTION

// ##################################################################
// # CheckDate()                                                    #
// # 05/21/2001                                                     #
// ##################################################################
// #----------------------------------------------------------------#
// # DESCRIPTION:                                                   #
// #----------------------------------------------------------------#
// # CheckDate() verifies and formats a date to MM/DD/YYYY.         #
// # Verifies a string as a legal date, including leap year.        #
// # Formats the date to MM-DD-YYYY if the original is a            #
// # decipherable date.  If the date is not an actual date or if    # 
// # the date is prior than today's date, returns FALSE.  Returns   #
// # TRUE if the date is legitimate or if it is today or            #
// # afterwards.                                                    #
// #----------------------------------------------------------------#
// # USAGE:                                                         #
// #----------------------------------------------------------------#
// # Use CheckDate() rather than CheckMask() to check any           #
// # user-defined dates.  CheckMask() will check the numbers        #
// # against a given mask, but will not check whether those numbers #
// # actually equate to an actual date.                             #
// #----------------------------------------------------------------#
// ##################################################################

function CheckDate(formName, elemName) {
// formName: FORM NAME
// elemName: ELEMENT TO BE CHECKED

	var strDate;
	var strDateArray;
	var strDay;
	var strMonth;
	var strYear;
	var intday;
	var intMonth;
	var intYear;
	var dateFound = false;
	var datefield = document.forms[formName].elements[elemName];
	var strSeparatorArray = new Array("-"," ","/",".");
	var intElementNr;
	var err = 0;

	strDate = datefield.value;
	

	if (strDate.length < 1 &&
    datefield.id != "req") {
		return true;
	}
	
	for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) {
	
		if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) {
		
			strDateArray = strDate.split(strSeparatorArray[intElementNr]);
	
			if (strDateArray.length != 3) {
				err = 1;
				return false;
			} else {
				strMonth = strDateArray[0];
				strDay = strDateArray[1];
				strYear = strDateArray[2];
			}

			dateFound = true;
   		}
	}

	if (dateFound == false) return false;
	if (strYear.length == 2) strYear = '20' + strYear;
	
	intday = parseInt(strDay, 10);

	if (isNaN(intday)) return false;
	
	intMonth = parseInt(strMonth, 10);

	if (isNaN(intMonth)) return false;
		
	intYear = parseInt(strYear, 10);

	if (isNaN(intYear)) return false;
	if (intMonth > 12 || intMonth<1) return false;

	if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) {
		return false;
	}

	if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) {
		return false;
	}

	if (intMonth == 2) {

		if (intday < 1) return false;
		
		if (LeapYear(intYear) == true) {
			if (intday > 29) return false;
		} else {
			if (intday > 28) return false;
		}
	}
	
	now = new Date();
	nowMonth = now.getMonth() + 1;
	nowDay = now.getDate();
	nowYear = now.getYear();
	
	document.forms[formName].elements[elemName].value = "";
	if (intMonth < 10) document.forms[formName].elements[elemName].value = "0";
	document.forms[formName].elements[elemName].value += intMonth + "/";
	if (intday < 10) document.forms[formName].elements[elemName].value += "0"; 
	document.forms[formName].elements[elemName].value += intday + "/" + strYear;

	if (nowYear > intYear) return false;
	if ((nowYear == intYear) && (nowMonth > intMonth)) return false;
	if ((nowYear == intYear) && (nowMonth == intMonth) && (nowDay > intday)) return false;
	
	return true;


} // END FUNCTION

// ##################################################################
// # LeapYear()                                                     #
// # 05/21/2001                                                     #
// ##################################################################
// #----------------------------------------------------------------#
// # DESCRIPTION:                                                   #
// #----------------------------------------------------------------#
// # LeapYear() checks to see if a given year is a leap year.       #
// # Returns TRUE if the given year is a leap year.  Returns FALSE  #
// # if it is not a leap year.                                      #
// #----------------------------------------------------------------#
// # USAGE:                                                         #
// #----------------------------------------------------------------#
// # Designed to be used in conjunction with CheckDate().  If       #
// # LeapYear() returns TRUE to CheckDate() AND if the date being   #
// # checked is February 29+, then CheckDate() returns FALSE.  If   #
// # it returns FALSE, OR if it returns TRUE AND the date is prior  #
// # than February 29, then CheckDate() returns TRUE.               #
// #----------------------------------------------------------------#
// ##################################################################

function LeapYear(intYear) {
// intYear: INTEGER TO BE CHECKED

	if (intYear % 100 == 0) {
		if (intYear % 400 == 0) return true;
	} else if ((intYear % 4) == 0) return true;

	return false;

} // END FUNCTION



// ##################################################################
// # CheckButton()                                                  #
// # 05/21/2001                                                     #
// ##################################################################
// #----------------------------------------------------------------#
// # DESCRIPTION:                                                   #
// #----------------------------------------------------------------#
// # CheckButton() is used to coordinate radio buttons with a       #
// # textfield, so that when a given button is chosen, the          #
// # textfield is enabled and required.  If a different radio       #
// # button is chosen, the textfield is cleared, disabled, and not  #
// # required.                                                      #
// #----------------------------------------------------------------#
// # USAGE:                                                         #
// #----------------------------------------------------------------#
// # Call this function on the "onclick" event of the radio         #  
// # buttons.  To require this field, preset one of the buttons to  #
// # "checked".  If the button associated with the textfield is     #
// # defaulted as checked, then make sure you preset <id=req> if    #
// # you want to require the textfield if the button is checked.    #
// # Otherwise, do not use <id=req> & begin with the textbox        #
// # disabled.                                                      #
// #----------------------------------------------------------------#
// ##################################################################

function CheckButton(obj, onVal, textfield)  {
// obj: OBJECT THAT CALLED FUNCTION - USE this AS obj
// onVal: VALUE OF RADIO BUTTON THAT ENABLES THE TEXTFIELD
// textfield: NAME OF TEXTFIELD TO BE ASSOCIATED WITH onVal 

	var formName  = obj.form.name; // FORM NAME
	var elemName  = obj.name;      // OBJECT NAME
	var elemVal   = obj.value;     // OBJECT VALUE

	if (elemVal == onVal) { 
	// IF "ON" BUTTON WAS CLICKED THEN...
		document.forms[formName].elements[textfield].disabled = false; // Enable the textfield
		document.forms[formName].elements[textfield].focus();          // Focus on the textfield
		document.forms[formName].elements[textfield].id = "req";       // The textfield is required
	} else {           
	// IF ANOTHER BUTTON WAS CLICKED THEN...
		document.forms[formName].elements[textfield].disabled = true;  // Disable the textfield
		document.forms[formName].elements[textfield].value = "";       // Clear the textfield
		document.forms[formName].elements[textfield].id = "";          // Textfield is not required
	}

	return true;
	
} // END FUNCTION

// ################################################################## 
// # Disable()                                                      #
// # 08/09/2001                                                     #
// ##################################################################
// #----------------------------------------------------------------#
// # DESCRIPTION:                                                   #
// #----------------------------------------------------------------#
// # Disable() disables a field if it does not contain a value.  If #
// # it does contain a value, then it enables it.                   #
// #----------------------------------------------------------------#
// # USAGE:                                                         #
// #----------------------------------------------------------------#
// # Designed to be used in conjunction with CheckButton().  If you #  
// # load a page with the textfield disabled, and then the user     #
// # clicks the appropriate radio button to enable that field and   #
// # submits the form to the next page; then if the user hits the   #
// # browser's BACK button to change something, the field would     #
// # have a value, the appropriate button would be checked, but the #
// # field would be disabled again.  Use this function on the       #
// # onload event to prevent this bug.                              #            \\
// #----------------------------------------------------------------#
// ##################################################################

function Disable(formName,textfield) {
// formName: FORM NAME
// textfield: FIELD TO BE ENABLED OR DISABLED

	if (document.forms[formName].elements[textfield].value=='') {
		document.forms[formName].elements[textfield].disabled = true
	} else {
		document.forms[formName].elements[textfield].disabled = false
	}

} // END FUNCTION



// ##################################################################
// # CarriageReturnToTab()                                          #
// # 05/21/2001                                                     #
// ##################################################################
// #----------------------------------------------------------------#
// # DESCRIPTION:                                                   #
// #----------------------------------------------------------------#
// # CarriageReturnToTab() converts a "CARRIAGE RETURN" keypress to #
// # a "TAB" by converting the ascii code of the delivered event.   #
// #----------------------------------------------------------------#
// # USAGE:                                                         #
// #----------------------------------------------------------------#
// # Call this from the "onkeydown" event of any input box to       #
// # prevent an auto-submit.  Instead of submitting the form when   #
// # the user presses "ENTER", a "TAB" is generated, taking the     #
// # focus to the next item.  Consider using this in text fields    #
// # that the user might be tempted to press "ENTER" for a carriage #
// # return.  This will prevent the submission of the form in such  #
// # an event.                                                      #
// #----------------------------------------------------------------#
// ##################################################################

function CarriageReturnToTab(event) {
// event: KEY THAT WAS PRESSED - USE event AS event

	if (event.keyCode == 13) event.keyCode=9;
	// IF "ENTER" (13) WAS PRESSED, RETURN A "TAB" (9) INSTEAD

} // END FUNCTION



// ##################################################################
// # Stamp()                                                        #
// # 05/21/2001                                                     #
// ##################################################################
// #----------------------------------------------------------------#
// # DESCRIPTION:                                                   #
// #----------------------------------------------------------------#
// # Stamp() puts a date/time stamp into a field.  The stamp is     #
// # MM/DD/YYYY, compatable with Oracle (MM/DD/YYYY).               #
// #----------------------------------------------------------------#
// # USAGE:                                                         #
// #----------------------------------------------------------------#
// # Call Stamp() from onclick of the submit button to put a        #
// # date/time stamp in a hidden field to pass the submission date  #
// # along with the form.                                           #
// #----------------------------------------------------------------#
// ##################################################################

function Stamp(obj, targetName) {
// obj: OBJECT THAT CALLED FUNCTION - USE this AS obj
// targetName: FIELD TO BE RECEIVE DATE/TIME STAMP

	var formName = obj.form.name;
	var ampm;
	var date = new Date();
	var m = date.getMonth() + 1;
	var month = (m < 10) ? '0' + m : m;
	var d  = date.getDate();
	var day = (d < 10) ? '0' + d : d;
	var y = date.getYear();
	var year = (y < 1000) ? y + 1900 : y;
	var h = date.getHours();
	
	if (h == 12) {

		ampm = "PM"

	} else if (h == 0) {
	
		h = 12;
		ampm = "AM"
	
	} else if (h < 12) {
	
		ampm = "AM"
	
	} else if (h > 12) {
	
		h = h - 12;
		ampm = "PM"
	
	}
		
	var hours = (h < 10) ? '0' + h : h;
	var m = date.getMinutes();
	var minutes = (m < 10) ? '0' + m : m;
	var now = (month + "/" + day + "/" + year + " " + hours + ":" + minutes + " " + ampm);

	document.forms[formName].elements[targetName].value = now
	
	return true;

} // END FUNCTION



// ##################################################################
// # NoSpace()                                                      #
// # 05/21/2001                                                     #
// ##################################################################
// #----------------------------------------------------------------#
// # DESCRIPTION:                                                   #
// #----------------------------------------------------------------#
// # NoSpace() makes sure that a given field in a form contains no  #
// # spaces.  If a space is found, returns cursor to that field &   #
// # an error is generated.                                         #
// #----------------------------------------------------------------#
// # USAGE:                                                         #
// #----------------------------------------------------------------#
// # In the <form> tag: onsubmit="return NoSpace(name, 'element     #
// # name')".  (name) will send the NAME of the form to be checked. # 
// # 'element name' should be the NAME of the element to be         #
// # checked.                                                       #
// #----------------------------------------------------------------#
// ##################################################################

function NoSpace(formName, elemName)  {
// formName: FORM TO BE CHECKED
// elemName: FIELD TO BE CHECKED

	var inString = document.forms[formName].elements[elemName].value;  
	// ELEMENT VALUE

	if (inString.indexOf(" ") > -1) {
	// IF ELEMENT CONTAINS ANY SPACES...
		// MOVE CURSOR, GENERATE ERROR...
		document.forms[formName].elements[elemName].focus();
		alert("Please remove spaces and resubmit form.");
		return false;
	}
		
	return true;
 	
} // END FUNCTION



// ##################################################################
// # Add()                                                          #
// # 07/09/2001                                                     #
// ##################################################################
// #----------------------------------------------------------------#
// # DESCRIPTION:                                                   #
// #----------------------------------------------------------------#
// # Add() adds the value of a text field to the bottom of a select #
// # list.                                                          #
// #----------------------------------------------------------------#
// # USAGE:                                                         #
// #----------------------------------------------------------------#
// # 8 buttons may be used with the dynamic select list.  ADD,      #
// # REMOVE, UP, DOWN, FIRST, LAST, EDIT, & ASCEND/DESCEND buttons  #
// # may be used.  Call this function on click of the ADD button.   #
// #----------------------------------------------------------------#
// ##################################################################

function Add(obj, addName, listName) {
// obj: OBJECT THAT CALLED FUNCTION - USE this AS obj
// addName: FIELD TO BE ADDED TO LIST
// listName: DYNAMIC SELECT LIST

	var formName = obj.form.name;
	var addBox = document.forms[formName].elements[addName];
	var listBox = document.forms[formName].elements[listName];
	var addText = addBox.value; 	// TEXT TO BE ADDED
	var count = listBox.length;     // # OF ITEMS

	if (addText != "") {  // IF ADDED TEXT IS NOT BLANK...
	
		for (i = 0; i < count ; i++) {
		// SCROLL THROUGH EACH ITEM IN LIST

			if (listBox.options[i].text.toLowerCase() == addText.toLowerCase()) {
				// ERROR MESSAGE IF ALREADY THERE
				alert("Please enter a valid item to add.");
				addBox.focus();
				return false;
			}

		}
		
		listBox.options[count] = new Option(addText, count);  // add text
		listBox.selectedIndex = count;
		addBox.value = "";
		addBox.focus();
		return true;

	} 
	
	// THE TEXT WAS BLANK: ERROR...
	alert("Please enter an item to add.");
	document.forms[formName].elements[addName].focus();
	return false;
	
} // END FUNCTION

// ##################################################################
// # AddList()                                                      #
// # 07/09/2001                                                     #
// ##################################################################
// #----------------------------------------------------------------#
// # DESCRIPTION:                                                   #
// #----------------------------------------------------------------#
// # AddList() adds the value of a select list to the bottom of a   #
// # different select list.  It also appends the default            #
// # " (Ascending)" to the item and checks to see if that item      #
// # already exists whether ascending or descending.                #
// #----------------------------------------------------------------#
// # USAGE:                                                         #
// #----------------------------------------------------------------#
// # 8 buttons may be used with the dynamic select list.  ADD,      #
// # REMOVE, UP, DOWN, FIRST, LAST, EDIT, & ASCEND/DESCEND buttons  #
// # may be used.  Call this function on click of the ADD button.   #
// #----------------------------------------------------------------#
// ##################################################################

function AddList(obj, addName, listName) {
// obj: OBJECT THAT CALLED FUNCTION - USE this AS obj
// addName: FIELD TO BE ADDED TO LIST
// listName: DYNAMIC SELECT LIST

	var formName = obj.form.name;
	var addBox = document.forms[formName].elements[addName];
	var listBox = document.forms[formName].elements[listName];
	var selected = addBox.selectedIndex
	var count = listBox.length;  // # OF ITEMS

	if (selected > 0) {  // IF A VALUE IS SELECTED...
	
		var addText = addBox.options[addBox.selectedIndex].text;
		// TEXT TO BE ADDED
	
		for (i = 0; i < count ; i++) {
		// SCROLL THROUGH EACH ITEM IN LIST

			if ((listBox.options[i].text == addText + " (Ascending)") |
		    (listBox.options[i].text == addText + " (Descending)")) {
				// IF TEXT IS ALREADY THERE: ERROR...
				alert("Please select a valid item to add.");
				return false;
			}
			
		}
		
		listBox.options[count] = new Option(addText+" (Ascending)", count);
		listBox.selectedIndex = count;
		addBox.selectedIndex = 0;
		listBox.focus();
		return true;

	} 
	
	// THE TEXT WAS BLANK: ERROR...
	alert("Please select an item to add.");
	return false;
	
} // END FUNCTION

// ##################################################################
// # AddMulti()                                                     #
// # 07/09/2001                                                     #
// ##################################################################
// #----------------------------------------------------------------#
// # DESCRIPTION:                                                   #
// #----------------------------------------------------------------#
// # AddMulti() appends together the values of two select lists and #
// # adds them to the bottom of a third select list.                #
// #----------------------------------------------------------------#
// # USAGE:                                                         #
// #----------------------------------------------------------------#
// # 8 buttons may be used with the dynamic select list.  ADD,      #
// # REMOVE, UP, DOWN, FIRST, LAST, EDIT, & ASCEND/DESCEND buttons  #
// # may be used.  Call this function on click of the ADD button.   #
// #----------------------------------------------------------------#
// ##################################################################

function AddMulti(obj, add1Name, add2Name, listName) {
// obj: OBJECT THAT CALLED FUNCTION - USE this AS obj
// add1Name: FIRST FIELD TO BE ADDED TO LIST
// add2Name: SECOND FIELD TO BE ADDED TO LIST
// listName: DYNAMIC SELECT LIST

	var formName = obj.form.name;
	var add1Box = document.forms[formName].elements[add1Name];
	var add2Box = document.forms[formName].elements[add2Name];
	var listBox = document.forms[formName].elements[listName];
	var add1Selected = add1Box.selectedIndex;
	var add2Selected = add2Box.selectedIndex;
	var count = listBox.length;  // # OF ITEMS

	if ((add1Selected > 0) && (add2Selected > 0)) {  // IF a value is selected...
	
		var addText = add1Box.options[add1Selected].text + " " + add2Box.options[add2Selected].text;
		// TEXT TO BE ADDED
	
		for (i = 0; i < count ; i++) {
		// SCROLL THROUGH EACH ITEM IN LIST

			if (listBox.options[i].text == addText) {
				// ERROR MESSAGE IF ALREADY THERE
				alert("Please select a valid item to add.");
				return false;
			}
		}

		listBox.options[count] = new Option(addText, count);
		listBox.selectedIndex = count;
		add1Box.selectedIndex = 0;
		add2Box.selectedIndex = 0;
		listBox.focus();
		return true;

	} 
	
	// THE TEXT WAS BLANK: ERROR...
	alert("Please select an item to add.");
	return false;
	
} // END FUNCTION

// ##################################################################
// # Sort()                                                         #
// # 07/09/2001                                                     #
// ##################################################################
// #----------------------------------------------------------------#
// # DESCRIPTION:                                                   #
// #----------------------------------------------------------------#
// # Sort() changes the Ascending/Descending flag of an item to the #
// # next value--either ascending or descending.                    #
// #----------------------------------------------------------------#
// # USAGE:                                                         #
// #----------------------------------------------------------------#
// # 8 buttons may be used with the dynamic select list.  ADD,      #
// # REMOVE, UP, DOWN, FIRST, LAST, EDIT, & ASCEND/DESCEND buttons  #
// # may be used.  Call this function on click of the ASCEND/       #
// # DESCEND button.                                                #
// #----------------------------------------------------------------#
// ##################################################################

function Sort(obj, addName, listName) {
// obj: OBJECT THAT CALLED FUNCTION - USE this AS obj
// addName: FIELD TO BE ADDED TO LIST
// listName: DYNAMIC SELECT LIST

	var formName = obj.form.name;
	var addBox = document.forms[formName].elements[addName];
	var listBox = document.forms[formName].elements[listName];
	var selected = listBox.selectedIndex;

	if (selected > -1) {  // IF A VALUE IS SELECTED...
	
		var sortText = listBox.options(selected).text;
		var txtLength = listBox.options(selected).text.length;

		if (obj.value == "Ascend...") {
			listBox.options[selected].text = sortText.substring(0, txtLength-13) + " (Ascending)";
			obj.value = "Descend..."
		} else {
			listBox.options[selected].text = sortText.substring(0, txtLength-12) + " (Descending)"; 
			obj.value = "Ascend..."
		}
		
		addBox.selectedIndex = 0;
		return true;
			
	}
		
	// THE TEXT WAS BLANK: ERROR...
	alert("Please select an item to edit.");
	return false;
	
} // END FUNCTION

// ##################################################################
// # ChangeButton()                                                 #
// # 07/09/2001                                                     #
// ##################################################################
// #----------------------------------------------------------------#
// # DESCRIPTION:                                                   #
// #----------------------------------------------------------------#
// # ChangeButton() changes the Ascend/Descend flag of a button to  #
// # the appropriate value depending on the selected value in a     #
// # list.                                                          #
// #----------------------------------------------------------------#
// # USAGE:                                                         #
// #----------------------------------------------------------------#
// # Designed to be used in conjunction with Sort(), which adds an  # 
// # item to a select list and appends either ASCENDING or          #
// # DESCENDING to that item in the list.  This function changes    #
// # the value of the button whenever the user selects an item in   #
// # the list.                                                      #
// #----------------------------------------------------------------#
// ##################################################################

function ChangeButton(obj, buttonName) {
// obj: OBJECT THAT CALLED FUNCTION - USE this AS obj
// buttonName: BUTTON TO BE CHANGED

	var formName = obj.form.name;
	var button = document.forms[formName].elements[buttonName];
	var selected = obj.selectedIndex;

	if (selected > -1) {  // IF a value is selected...
	
		var editText = obj.options(selected).text;
		var txtLength = editText.length;
	
		if (editText.substring(txtLength - 13, txtLength) == " (Descending)") {
			button.value = "Ascend...";
		} else {
			button.value = "Descend..."
		}
		
		return;
			
	}
		
	return;
	
} // END FUNCTION

// ##################################################################
// # Edit()                                                         #
// # 07/09/2001                                                     #
// ##################################################################
// #----------------------------------------------------------------#
// # DESCRIPTION:                                                   #
// #----------------------------------------------------------------#
// # Edit() deletes the selected value of a list & adds that value  #
// # to a text box.                                                 #
// #----------------------------------------------------------------#
// # USAGE:                                                         #
// #----------------------------------------------------------------#
// # 8 buttons may be used with the dynamic select list.  ADD,      #
// # REMOVE, UP, DOWN, FIRST, LAST, EDIT, & ASCEND/DESCEND buttons  #
// # may be used.  Call this function on click of the EDIT button.  #
// #----------------------------------------------------------------#
// ##################################################################

function Edit(obj, addName, listName) {
// obj: OBJECT THAT CALLED FUNCTION - USE this AS obj
// addName: TEXTBOX TO RECEIVE SELECTED VALUE
// listName: DYNAMIC SELECT LIST

	var formName = obj.form.name;
	var addBox = document.forms[formName].elements[addName];	
	var listBox = document.forms[formName].elements[listName];
	var editItem = listBox.selectedIndex;  // SELECTED ITEM
	var count = listBox.length;            // # OF ITEMS

	if (editItem > -1) {
		var editText = listBox.options[editItem].text  // SELECTED TEXT
		if (!Delete(obj, addName, listName)) return false;
		addBox.value = editText;
		return true;
	}
	
	// NO ITEM WAS SELECTED 
	alert("Please select an item to edit.");
	addBox.focus();
	return false;
	
} // END FUNCTION

// ##################################################################
// # Delete()                                                       #
// # 07/09/2001                                                     #
// ##################################################################
// #----------------------------------------------------------------#
// # DESCRIPTION:                                                   #
// #----------------------------------------------------------------#
// # Delete() deletes a selected item from a select list, shifting  #
// # all other items up accordingly.                                #
// #----------------------------------------------------------------#
// # USAGE:                                                         #
// #----------------------------------------------------------------#
// # 8 buttons may be used with the dynamic select list.  ADD,      #
// # REMOVE, UP, DOWN, FIRST, LAST, EDIT, & ASCEND/DESCEND buttons  #
// # may be used.  Call this function on click of the REMOVE        #
// # button.                                                        #
// #----------------------------------------------------------------#
// ##################################################################

function Delete(obj, addName, listName) {
// obj: OBJECT THAT CALLED FUNCTION - USE this AS obj
// addName: MOVES CURSOR TO THIS TEXTBOX
// listName: DYNAMIC SELECT LIST

	var formName = obj.form.name;
	var addBox = document.forms[formName].elements[addName];	
	var listBox = document.forms[formName].elements[listName];
	var delItem = listBox.selectedIndex;  // SELECTED ITEM
	var count = listBox.length;           // # OF ITEMS

	if (delItem > -1) {
	// IF AN ITEM IS SELECTED
	
		listBox.options[delItem] = null;  // REMOVE SELECTED
		
		if (delItem == count-1) {
			listBox.selectedIndex = count-2;
		} else {
			listBox.selectedIndex = delItem;
		}
		
		return true;

	} 
	
	// ERROR MESSAGE IF NOT SELECTED
	alert("Please select an item to remove.");
	if (addBox.type == "text") addBox.focus();
	return false;
	
} // END FUNCTION

// ##################################################################
// # Up()                                                           #
// # 07/09/2001                                                     #
// ##################################################################
// #----------------------------------------------------------------#
// # DESCRIPTION:                                                   #
// #----------------------------------------------------------------#
// # Up() moves the selected item in a select list up one and       #
// # shifts the replaced item down one.                             #
// #----------------------------------------------------------------#
// # USAGE:                                                         #
// #----------------------------------------------------------------#
// # 8 buttons may be used with the dynamic select list.  ADD,      #
// # REMOVE, UP, DOWN, FIRST, LAST, EDIT, & ASCEND/DESCEND buttons  #
// # may be used.  Call this function on click of the UP button.    #
// #----------------------------------------------------------------#
// ##################################################################

function Up(obj, addName, listName) {
// obj: OBJECT THAT CALLED FUNCTION - USE this AS obj
// addName: MOVES CURSOR TO THIS TEXTBOX
// listName: DYNAMIC SELECT LIST

	var formName = obj.form.name;
	var addBox = document.forms[formName].elements[addName];	
	var listBox = document.forms[formName].elements[listName];
	// select list
	var moveVal = listBox.selectedIndex;  // SELECTED ITEM
	var count = listBox.length;           // # OF ITEMS

	if (moveVal > 0) {
	// IF AT LEAST THE SECOND ITEM IS SELECTED
	
		var switchItem = listBox.options[moveVal-1].text;
		// STORE PREVIOUS TEXT

		listBox.options[moveVal-1].text = listBox.options[moveVal].text;
		// MOVE SELECTED TEXT
		listBox.options[moveVal].text = switchItem;
		// MOVE PREVIOUS TEXT
		listBox.selectedIndex = moveVal-1;  // MOVE SELECTION
		return true;

	} 
	
	if (moveVal == 0) return false;
	// IF THE LAST ITEM WAS SELECTED, DO NOTHING

	// ERROR IF NOT SELECTED
	alert("Please select an item to move.");
	if (addBox.type == "text") addBox.focus();
	return false;
	
} // END FUNCTION

// ##################################################################
// # Down()                                                         #
// # 07/09/2001                                                     #
// ##################################################################
// #----------------------------------------------------------------#
// # DESCRIPTION:                                                   #
// #----------------------------------------------------------------#
// # Down() moves the selected item in a select list down one and   #
// # shifts the replaced up one.                                    #
// #----------------------------------------------------------------#
// # USAGE:                                                         #
// #----------------------------------------------------------------#
// # 8 buttons may be used with the dynamic select list.  ADD,      #
// # REMOVE, UP, DOWN, FIRST, LAST, EDIT, & ASCEND/DESCEND buttons  #
// # may be used.  Call this function on click of the DOWN button.  #
// #----------------------------------------------------------------#
// ##################################################################

function Down(obj, addName, listName) {
// obj: OBJECT THAT CALLED FUNCTION - USE this AS obj
// addName: MOVES CURSOR TO THIS TEXTBOX
// listName: DYNAMIC SELECT LIST

	var formName = obj.form.name;
	var addBox = document.forms[formName].elements[addName];	
	var listBox = document.forms[formName].elements[listName];
	// SELECT LIST
	var moveVal = listBox.selectedIndex;  // SELECTED ITEM
	var count = listBox.length;           // # OF ITEMS

	if ((moveVal > -1) && (moveVal < count-1)) {
	// IF AN ITEM IS SELECTED AND
	// THAT ITEM IS NOT THE LAST ITEM
	
		var switchItem = listBox.options[moveVal+1].text;
		// STORE NEXT TEXT

		listBox.options[moveVal + 1].text = listBox.options[moveVal].text;
		// MOVE SELECTED
		listBox.options[moveVal].text = switchItem;
		// MOVE NEXT
		listBox.selectedIndex = moveVal + 1;  // move selection
		return true;

	} 
	
	if (moveVal == count-1) return false;
	// IF THE FIRST ITEM WAS SELECTED, DO NOTHING

	// ERROR IF NOT SELECTED
	alert("Please select an item to move.");
	if (addBox.type == "text") addBox.focus();
	return false;
	
} // END FUNCTION

// ##################################################################
// # First()                                                        #
// # 07/09/2001                                                     #
// ##################################################################
// #----------------------------------------------------------------#
// # DESCRIPTION:                                                   #
// #----------------------------------------------------------------#
// # First() moves the selected item in a select list to the top,   #
// # shifting all other items down one accordingly.                 #
// #----------------------------------------------------------------#
// # USAGE:                                                         #
// #----------------------------------------------------------------#
// # 8 buttons may be used with the dynamic select list.  ADD,      #
// # REMOVE, UP, DOWN, FIRST, LAST, EDIT, & ASCEND/DESCEND buttons  #
// # may be used.  Call this function on click of the FIRST button. #
// #----------------------------------------------------------------#
// ##################################################################

function First(obj, addName, listName) {
// obj: OBJECT THAT CALLED FUNCTION - USE this AS obj
// addName: MOVES CURSOR TO THIS TEXTBOX
// listName: DYNAMIC SELECT LIST

	var formName = obj.form.name;
	var addBox = document.forms[formName].elements[addName];	
	var listBox = document.forms[formName].elements[listName];
	// SELECT LIST
	var moveVal = listBox.selectedIndex;  // SELECTED ITEM
	var count = listBox.length;           // # OF ITEMS
	

	if (moveVal > 0) {
	// IF AT LEAST THE SECOND ITEM IS SELECTED 

		var moveText = listBox.options[moveVal].text;
		// STORE TEXT TO BE MOVED

		for (i = moveVal - 1; i > -1 ; i--) {
		// SCROLL THROUGH EACH ITEM IN LIST AFTER SELECTED
			listBox.options[i + 1].text = listBox.options[i].text;
			// MOVE EACH ITEM DOWN ONE
		}
		
		listBox.options[0].text = moveText;  // MOVE TEXT
		listBox.selectedIndex = 0;           // MOVE SELECTION
		return true;
		
	}
	
	if (moveVal == 0) return true;
	// IF THE FIRST ITEM IS ALREADY SELECTED, DO NOTHING.
	
	// ERROR IF NOT SELECTED
	alert("Please select an item to move.");
	if (addBox.type == "text") addBox.focus();
	return false;
		
} // END FUNCTION

// ##################################################################
// # Last()                                                         #
// # 07/09/2001                                                     #
// ##################################################################
// #----------------------------------------------------------------#
// # DESCRIPTION:                                                   #
// #----------------------------------------------------------------#
// # Last() moves the selected item in a select list to the bottom, #
// # shifting all other items up one accordingly.                   #
// #----------------------------------------------------------------#
// # USAGE:                                                         #
// #----------------------------------------------------------------#
// # 8 buttons may be used with the dynamic select list.  ADD,      #
// # REMOVE, UP, DOWN, FIRST, LAST, EDIT, & ASCEND/DESCEND buttons  #
// # may be used.  Call this function on click of the LAST button.  #
// #----------------------------------------------------------------#
// ##################################################################

function Last(obj, addName, listName) {
// obj: OBJECT THAT CALLED FUNCTION - USE this AS obj
// addName: MOVES CURSOR TO THIS TEXTBOX
// listName: DYNAMIC SELECT LIST

	var formName = obj.form.name;
	var addBox = document.forms[formName].elements[addName];	
	var listBox = document.forms[formName].elements[listName];
	var moveVal = listBox.selectedIndex;  // SELECTED ITEM
	var count = listBox.length;           // # OF ITEMS

	// IF AN ITEM IS SELECTED AND
	// IF THAT ITEM IS NOT ALREADY LAST 
	if ((moveVal > -1) && (moveVal < count-1)) {

		var moveText = listBox.options[moveVal].text;
		// STORE TEXT TO BE MOVED

		for (i = moveVal + 1; i < count; i++) {
		// SCROLL THROUGH ALL ITEMS IN LIST AFTER SELECTED
			listBox.options[i - 1].text = listBox.options[i].text;
			// MOVE EACH ITEM UP ONE
		}
		
		listBox.options[count - 1].text = moveText; 
		// MOVE TEXT
		listBox.selectedIndex = count - 1;  // MOVE SELECTED
		return true;
		
	} 
	
	// IF LAST ITEM IS ALREADY SELECTED, DO NOTHING
	if (moveVal == count-1) {
		if (addBox.type == "text") addBox.focus();
		return false;
	}
	
	// ERROR IF NOT SELECTED
	alert("Please select an item to move.");
	if (addBox.type == "text") addBox.focus();
	return false;
	
} // END FUNCTION

// ##################################################################
// # ResetList()                                                    #
// # 07/09/2001                                                     #
// ##################################################################
// #----------------------------------------------------------------#
// # DESCRIPTION:                                                   #
// #----------------------------------------------------------------#
// # ResetList() is used in a dynamic select list to reset all vals #
// # back to the default blank list.                                #
// #----------------------------------------------------------------#
// # USAGE:                                                         #
// #----------------------------------------------------------------#
// # Since the list is dynamically created, clicking the RESET      #
// # does not clear the list.  Call this function on the onclick    #
// # event of the RESET button to fix this bug.                     #
// #----------------------------------------------------------------#
// ##################################################################

function ResetList(obj, listName) {
// obj: OBJECT THAT CALLED FUNCTION - USE this AS obj
// listName: DYNAMIC SELECT LIST

	var formName = obj.form.name;
	document.forms[formName].elements[listName].length = 0;

} // END FUNCTION

// ##################################################################
// # Commas()                                                       #
// # 06/26/2001                                                     #
// ##################################################################
// #----------------------------------------------------------------#
// # DESCRIPTION:                                                   #
// #----------------------------------------------------------------#
// # Commas() takes items in a form-array (such as a select list)   #
// # and converts them to comma-delimited string.  If a val in the  #
// # array contains a comma, then a double-comma is generated.      #
// #----------------------------------------------------------------#
// # USAGE:                                                         #
// #----------------------------------------------------------------#
// # Designed to be used in a user-populated select list on to pass #
// # all of the values onto the next page of a form.  This is       #
// # necessary because a select list only submits the selected val  #
// # to the next page.  This function pastes the comma-delimited    #
// # string into a hidden field.  Call Commas() from the 'onClick'  #
// # event of the submit button.                                    #
// #----------------------------------------------------------------#
// ##################################################################

function Commas(obj, listName, elemName) {
// obj: OBJECT THAT CALLED FUNCTION - USE this AS obj
// listName: DYNAMIC SELECT LIST
// elemName: ELEMENT TO RECEIVE COMMA-DELIMITED LIST

	var formName = obj.form.name // FORM NAME
	var listBox = document.forms[formName].elements[listName];
	// SELECT LIST
	var count = listBox.length;  // # OF ITEMS
	var list = "";               // COMMA-DELIMITED LIST
	
	// LOOP THROUGH ALL ITEMS IN LIST
	for (i = 0; i < count; i++) {
		var inString = listBox.options[i].text;
		inString = FindReplace(inString, ",", ",,");
		list = list + inString;
		if (i < count - 1) list = list + ", ";
	}

	document.forms[formName].elements[elemName].value = list;
	
} // END FUNCTION

// ##################################################################
// # FindReplace()                                                  #
// # 06/26/2001                                                     #
// ##################################################################
// #----------------------------------------------------------------#
// # DESCRIPTION:                                                   #
// #----------------------------------------------------------------#
// # FindReplace() replaces all occurences of a given character     # 
// # with another in a string.                                      #
// #----------------------------------------------------------------#
// # USAGE:                                                         #
// #----------------------------------------------------------------#
// # Used in conjunction with Commas() to generate a double-comma   #
// # anywhere a user has placed commas within the selectl list.     #
// # The commas can then be deciphered on the other side.  This     #
// # function can have many other uses as well.                     #
// #----------------------------------------------------------------#
// ##################################################################

function FindReplace(string,find,replace) {
// REPLACES find WITH replace IN string
    
	var lenStr = string.length
	var lenFind = find.length;
    
	if ((lenStr == 0) || (lenFind == 0)) return string;

	var i = string.indexOf(find);

	if ((!i) && (find != string.substring(0,lenFind))) return string;
	if (i == -1) return string;

	var newStr = string.substring(0,i) + replace;

	if (i+lenFind < lenStr)	newStr += FindReplace(string.substring(i + lenFind,lenStr),find,replace);

    return newStr;
    
} // END FUNCTION

// ##################################################################
// # ReqList()                                                      #
// # 06/29/2001                                                     #
// ##################################################################
// #----------------------------------------------------------------#
// # DESCRIPTION:                                                   #
// #----------------------------------------------------------------#
// # ReqList() checks to make sure that the user has populated the  #
// # Dynamic List.                                                  #
// #----------------------------------------------------------------#
// # USAGE:                                                         #
// #----------------------------------------------------------------#
// # Designed to be used in a dynamically created select list in    #
// # conjunction with Commas() to check to make sure that the field #
// # with the comma-delimited list has a value in it.  If it does   #
// # not then an error is generated and the cursor is taken back to #
// # the add text field.                                            #
// #----------------------------------------------------------------#
// ##################################################################

function ReqList(formName, addName, listName, commaName) {
// formName: FORM NAME
// addName: MOVES CURSOR TO THIS TEXTBOX
// listName: DYNAMIC SELECT LIST
// commaName: COMMA-DELIMITED FIELD

	addBox = document.forms[formName].elements[addName];
	listBox = document.forms[formName].elements[listName];
    
	if (!document.forms[formName].elements[commaName].value) {
 		addBox.focus();
		alert(listName + " is a required field.");
		return false;
	}
	
	return true;

} // END FUNCTION

// ##################################################################
// # ParseCommas()                                                  #
// # 06/29/2001                                                     #
// ##################################################################
// #----------------------------------------------------------------#
// # DESCRIPTION:                                                   #
// #----------------------------------------------------------------#
// # ParseCommas() takes items in a comma-delimited string and      #
// # parses them into a select list.                                #
// #----------------------------------------------------------------#
// # USAGE:                                                         #
// #----------------------------------------------------------------#
// # Designed to be used in conjunction with Commas() to parse      #
// # information from a user-populated select list that has been    #
// # merged into a comma-delimited string for submission.  The      #
// # comma-delimited string is parsed into another select list.  It #
// # also checks for any item that is to be skipped.                #
// #----------------------------------------------------------------#
// ##################################################################

function ParseCommas(formName, commaName, listName, skipItem) {
// formName: FORM NAME
// commaName: COMMA-DELIMITED FIELD
// listName: DYNAMIC SELECT LIST
// skipItem: TEXT TO BE SKIPPED - LEAVE BLANK IF NONE

	var listBox = document.forms[formName].elements[listName];
	var commaList = document.forms[formName].elements[commaName].value;
	var parseList = "";
	var strLength = commaList.length;
	var item = listBox.length;
	var char1, char2;

	for (i = 0; i < strLength; i++) {

		char1 = commaList.substring(i, i+1);
		char2 = commaList.substring(i+1, i+2);
		
		if ((char1 == ",") && (char2 == " ")) {
			commaList = commaList.substring(i+2, strLength);
			parseList = "";
			strLength = commaList.length;
			item++;
			i = 0;
			char1 = commaList.substring(i, i+1);
		}

		parseList = parseList + char1;
		listBox.options[item] = new Option(parseList, item);

		if ((char1 == ",") && (char2 == ",")) {
			commaList = commaList.substring(0, i) + commaList.substring(i+1, strLength);
			strLength = commaList.length;
		}
	}

	var count = listBox.length
	
	for (i = 0; i < count; i++) {

		var inString = listBox.options[i].text;
		if (inString == skipItem) {
			listBox.options[i] = null;
			i = count;
		}
	}

} // END FUNCTION



// ##################################################################
// # NoSubmit()                                                     #
// # 08/08/2001                                                     #
// ##################################################################
// #----------------------------------------------------------------#
// # DESCRIPTION:                                                   #
// #----------------------------------------------------------------#
// # NoSubmit() nulls the name of a given field so that field is    #
// # not submitted along with the rest of the form.                 #
// #----------------------------------------------------------------#
// # USAGE:                                                         #
// #----------------------------------------------------------------#
// # Many fields are simply used by the backend to generate another #
// # value.  Since element names are important to ReqField(), this  #
// # function allows every field to begin with a name, and that     #
// # name can be nulled on the onclick event of the submit button   #
// # so that it is not submitted with the final form.               #
// #----------------------------------------------------------------#
// ##################################################################

function NoSubmit(obj, elemName) {
// obj: OBJECT THAT CALLED FUNCTION - USE this AS obj
// elemName: ELEMENT NAME TO BE NULLED FROM SUBMISSION

	formName = obj.form.name;
	document.forms[formName].elements[elemName].name = "";

} // END FUNCTION