// global variables initialized

	var helpWindow;
	var loadingWindow;

	function openHelp(field_name) {
		var y;

		y = findFormFieldSaveAsValue(field_name, '', '');
		debugLog("openHelp: found field: "+field_name+" help: "+FormFields[y][FormFields_help]);
		helpWindow = window.open('', 'helpWindow', 'height=200,width=400,scrollbars=yes,resizable=yes');
//		helpWindow = window.open('', 'helpWindow', '');
		helpWindow.document.open('text/html', 'replace');
		helpWindow.focus();
		helpWindow.document.write("<HTML><HEAD><TITLE>Help</TITLE>\n");
//		helpWindow.document.write("<script LANGUAGE=\"JavaScript\" src=\"/js/base.js\"></script>\n");
//		helpWindow.document.write("<link rel=stylesheet href=\"/styles/GEN_styles.css\" type=\"text/css\">\n");
		helpWindow.document.write("</HEAD><BODY>");
		helpWindow.document.write("<FONT SIZE='-2' FACE='Verdana'>");
		helpWindow.document.write(FormFields[y][FormFields_help]);
		helpWindow.document.write("<br><br><center><a href='javascript: window.close();'>Close Window</a></center>\n");
		helpWindow.document.write("</FONT></BODY></HTML>\n");
	}

	function enterDebugData(form) {
		InitializeFormElementValue(form, 'c_first_name', 'mike');
		InitializeFormElementValue(form, 'c_confidential_flag', '0');
		InitializeFormElementValue(form, 'c_opt_in_flag', '1');
		form.c_last_name.value = "farley";
		form.c_address_line_1.value = "325";
		form.c_city.value = "lansdale";
		InitializeFormElementValue(form, 'c_state', 'PA');
		form.c_zip_code.value = "19446";
		form.c_email.value = "mike@jobcircle.com";
		form.c_objective.value = "objective";
		form.c_resume_name.value = "mike@jobcircle.com";
		form.c_salary_rate.selectedIndex = 9;
//		saveRetrievedElements(form, 1, "skill_name", "gadzooks", "skill_level", "1");
	}

	function setElementValue(element, newvalue) {
		element.value = newvalue;
	}

	function ShowLoadingWindow() {
		loadingWindow.focus();
	}

	function InitializeDisplayBoxes(){
		var formnum;
		for(formnum=0;formnum<FormChecks.length;formnum++) {
			if (FormChecks[formnum][2]) {
				FormChecks[formnum][2].options[0] = null;
			}
		}
	}

	function eval_me(form, eval_str) {
		if (debug && eval_str.indexOf('[') != -1) {
			var temp = "";
			
			for (z=1; z<eval_me.arguments.length; z++) {
				temp += " "+eval_me.arguments[z];
			}
			alert("evaluating: "+eval_str+temp);
		}
		return eval(eval_str);
	}

	function CacheFormElementsPropagateObject(form, name, objectref) {
		var formnum, i, j, k;
		for(formnum=0;formnum<FormChecks.length;formnum++) {
			for(i=0;i<FormChecks[formnum][FormChecks_BoxArrayNum].length;i++) {
				var start_field = 2;
				if (FormChecks[formnum][FormChecks_BoxArrayNum][i][0] == 'save') start_field = 1;
				for(j=start_field;j<FormChecks[formnum][FormChecks_BoxArrayNum][i].length;j++) {
					objType = typeof FormChecks[formnum][FormChecks_BoxArrayNum][i][j];
					if (objType == 'object') {
						for(k=0;k<FormChecks[formnum][FormChecks_BoxArrayNum][i][j].length;k++) {
							if ((typeof FormChecks[formnum][FormChecks_BoxArrayNum][i][j][k] == 'string') && (FormChecks[formnum][FormChecks_BoxArrayNum][i][j][k] == name)) {
							// then it is a special form of array indicating
							// that it has multiple possibilities, AND, or OR
debugLog("CachePropagateObject: formnum: "+formnum+" i: "+i+" j: "+j+" k: "+k+" objType: "+objType+" name: "+name);
								FormChecks[formnum][FormChecks_BoxArrayNum][i][j][k] = objectref;
							}
						}
					} else {
						if ((objType == 'string') && (FormChecks[formnum][FormChecks_BoxArrayNum][i][j] == name)) {
debugLog("CachePropagateObject: formnum: "+formnum+" i: "+i+" j: "+j+" objType: "+objType+" name: "+name);
							FormChecks[formnum][FormChecks_BoxArrayNum][i][j] = objectref;
						}
					}
				}
			}
		}
	}

	function CacheFormElements(form) {
		var formnum, i, j, k;
		for(formnum=0;formnum<FormChecks.length;formnum++) {
			for(i=2;i<FormChecks_BoxArrayNum;i++) {
				if (FormChecks[formnum][i] != '') {
					FormChecks[formnum][i] = eval_me(form, "form."+FormChecks[formnum][i], i);
				}
			}
			for(i=0;i<FormChecks[formnum][FormChecks_BoxArrayNum].length;i++) {
				var start_field = 2;
				if (FormChecks[formnum][FormChecks_BoxArrayNum][i][0] == 'save') start_field = 1;
				for(j=start_field;j<FormChecks[formnum][FormChecks_BoxArrayNum][i].length;j++) {
					var objType = typeof FormChecks[formnum][FormChecks_BoxArrayNum][i][j];
debugLog("Cache: formnum: "+formnum+" i: "+i+" j: "+j+" objType: "+objType);
					if (objType == 'object') {
						if (FormChecks[formnum][FormChecks_BoxArrayNum][i][j][0] && typeof FormChecks[formnum][FormChecks_BoxArrayNum][i][j][0] == 'string') {
							// then it is a special form of array indicating
							// that it has multiple possibilities, AND, or OR
							for(k=0;k<FormChecks[formnum][FormChecks_BoxArrayNum][i][j].length;k++) {
								if (typeof FormChecks[formnum][FormChecks_BoxArrayNum][i][j][k] == 'object') {
									continue;
								}
								var first_char = FormChecks[formnum][FormChecks_BoxArrayNum][i][j][k].charAt(0);
								if ((first_char == '&') ||
									(first_char == '|') ||
									(first_char == '!') ||
									(first_char == '=')) {
									// skip this entry as it is a special modifier
								} else {
debugLog("Cache: formnum: "+formnum+" i: "+i+" j: "+j+" k: "+k+" objType: "+objType);
									//FormChecks[formnum][FormChecks_BoxArrayNum][i][j][k] = findFormElement(form, FormChecks[formnum][FormChecks_BoxArrayNum][i][j][k]);
debugLog("Cache: formnum: "+formnum+" i: "+i+" j: "+j+" k: "+k+"form."+FormChecks[formnum][FormChecks_BoxArrayNum][i][j][k]);
									CacheFormElementsPropagateObject(form, FormChecks[formnum][FormChecks_BoxArrayNum][i][j][k], eval_me(form, "form."+FormChecks[formnum][FormChecks_BoxArrayNum][i][j][k], i, j, k));
									//FormChecks[formnum][FormChecks_BoxArrayNum][i][j][k] = eval_me(form, "form."+FormChecks[formnum][FormChecks_BoxArrayNum][i][j][k]);
debugLog("Cache: formnum: "+formnum+" i: "+i+" j: "+j+" k: "+k+FormChecks[formnum][FormChecks_BoxArrayNum][i][j][k].name);
								}
							}
						}
					} else if (objType == 'string') {
						var str = "form."+FormChecks[formnum][FormChecks_BoxArrayNum][i][j];
debugLog("Cache: formnum: "+formnum+" i: "+i+" j: "+j+" "+str);
						CacheFormElementsPropagateObject(form, FormChecks[formnum][FormChecks_BoxArrayNum][i][j], eval_me(form, "form."+FormChecks[formnum][FormChecks_BoxArrayNum][i][j], i, j));
//debugLog("Cache[done]: formnum: "+formnum+" i: "+i+" j: "+j+" "+FormChecks[formnum][FormChecks_BoxArrayNum][i][j]);
debugLog("Cache[done]: formnum: "+formnum+" i: "+i+" j: "+j);
					}
				}
			}
		}
	}

	function InitializeFormMaxLengths(form){
		var y;

		for(y=0;y<FormFields.length;y++) {
			FormFields[y][FormFields_object] = findFormElement(form, FormFields[y][FormFields_name]);
			//
			// 10/29/2007 KME
			// Changing  "!= ''" to ">0" so that we don't have unnecessary maxlengths checked.
			//
			if ((FormFields[y] && (FormFields[y][FormFields_maxlength] > 0))) {
debugLog("assigning keyup: "+FormFields[y][FormFields_name]+" onchange");
				if (FormFields[y][FormFields_object]) {
					FormFields[y][FormFields_object].onchange = keyup_event;
					FormFields[y][FormFields_object].onkeyup = keyup_event;
					FormFields[y][FormFields_object].onkeypress = keyup_event;
				}
			}
		}
	}

	function ValidateCheckRequiredOrField(passed_field, dont_alert) {
		var field = this;
		var message = "";
		if (dont_alert && passed_field) field = passed_field;
debugLog("keyp: here "+getName(field));
		var y;
		var found_array = -1;
		for(y=0;found_array==-1 && y<FormFieldsCheckRequiredOr.length;y++) {
			if (FormFieldsCheckRequiredOr[y][0] == 'only-one') {
				for(z=1;found_array==-1 && z<FormFieldsCheckRequiredOr[y].length;z++) {
					if (getName(FormFieldsCheckRequiredOr[y][z]) == getName(field)) {
						found_array = y;
						break;
					}
				}
			}
		}
		if (found_array > -1) {
			y = found_array;
			for(z=1;z<FormFieldsCheckRequiredOr[y].length;z++) {
				if (getName(FormFieldsCheckRequiredOr[y][z]) != getName(field)) {
					clearElement(FormFieldsCheckRequiredOr[y][z]);
				}
			}
		}
	}

	function InitializeFormCheckRequiredOr(form){
		var y,z;

		for(y=0;y<FormFieldsCheckRequiredOr.length;y++) {
			for(z=1;z<FormFieldsCheckRequiredOr[y].length;z++) {
				FormFieldsCheckRequiredOr[y][z] = findFormElement(form, FormFieldsCheckRequiredOr[y][z]);
				if (FormFieldsCheckRequiredOr[y][z]) {
					// this shouldn't conflict with
					FormFieldsCheckRequiredOr[y][z].onchange = ValidateCheckRequiredOrField;
				}
			}
		}
	}

	function InitializeFormElementValue(form, element_name, new_value){
		var c,i,j,y,z;

		var found = 0;
		y = findFormFieldSaveAsValue(element_name, '', '');
		if ((FormFields[y] && (typeof FormFields[y][FormFields_object] == 'object') && (FormFields[y][FormFields_name] == element_name))) {
			found = 1;
			if ((getType(FormFields[y][FormFields_object]) == 'text') || (getType(FormFields[y][FormFields_object]) == 'textarea')) {
				FormFields[y][FormFields_object].value = new_value;
			} else if ((getType(FormFields[y][FormFields_object]) == 'select-one') || (getType(FormFields[y][FormFields_object]) == 'select-multiple')) {
				var save_as_value = 1;
				if (FormFields[y][FormFields_select_data] == 'text') save_as_value = 0;
				for(c=0;c<FormFields[y][FormFields_object].options.length;c++) {
					if (((!save_as_value) && (FormFields[y][FormFields_object].options[c].text == new_value)) || ((save_as_value) && (FormFields[y][FormFields_object].options[c].value == new_value))) {
						FormFields[y][FormFields_object].options[c].selected = true;
						break;
					} else {
						FormFields[y][FormFields_object].options[c].selected = false;
					}
				}
			} else if (getType(FormFields[y][FormFields_object]) == 'checkbox') {
				if ((new_value == 1) || (new_value.toUpperCase() == 'TRUE')) {
					FormFields[y][FormFields_object].checked = true;
				} else {
					FormFields[y][FormFields_object].checked = false;
				}
			} else if (getType(FormFields[y][FormFields_object]) == 'radio') {
				for(c=0;c<FormFields[y][FormFields_object].length;c++) {
					if (FormFields[y][FormFields_object][c].value == new_value) {
						FormFields[y][FormFields_object][c].checked = true;
						break;
					} else {
						FormFields[y][FormFields_object][c].checked = false;
					}
				}
			}
		}
		if (!found) {
			debugLog("InitializeFormElementValue: could not find field: "+element_name+" to set value!");
		}
	}

	function getType(obj) {
		if (obj) {
			if (obj.type) {
				return (obj.type);
			} else if ((typeof obj[0] == 'string') && (obj[0].type)) {
				return (obj[0].type);
			} else if (obj[0] && obj[0].type) {
				return (obj[0].type);
			} else {
				return (obj.type);
			}
/*	-		if ((obj.type == 'checkbox') || (obj.type == 'radio')) {
	-			return (obj.type);
	-		} else {	
				if (obj.type == 'object' && obj[0] && obj[0].type) {
					return (obj[0].type);
				} else {
					return (obj.type);
				}*/
//			}
		} else {
			return null;
		}
	}

	function get2Name(obj) {
		if (obj) {
//			if (obj[0] && obj[0].name) {
			if ((typeof obj[0] == 'string') && (obj[0].name)) {
debugLog("here1");
				return (obj[0].name);
			} else {
debugLog("here2");
				return (obj.name);
			}
		} else {
			return null;
		}
	}
	function getName(obj) {
		if (obj) {
			if (obj.name) {
				return (obj.name);
			} else if ((typeof obj[0] == 'string') && (obj[0].name)) {
				return (obj[0].name);
			} else if (obj[0] && obj[0].name) {
				return (obj[0].name);
			}
		} else {
			return null;
		}
	}

	function InitializeArrays(form){
		if (document.resume_add.education_display) document.resume_add.education_display.options[0] = null;
		if (document.resume_add.skill_display) document.resume_add.skill_display.options[0] = null;
		if (document.resume_add.employer_display) document.resume_add.employer_display.options[0] = null;
		alert("hi");
		 form.education_display.options[0] = null;
		 form.skill_display.options[0] = null;
		 form.employer_display.options[0] = null;
		 form.education_display.options[1] = null;
		 form.skill_display.options[1] = null;
		 form.employer_display.options[1] = null;

		return true;
	}

	function regressFormData(form) {
		// opposite of prepareDataForTransmission

		// loop through lst* arrays and if any data has commas in it
		// then double quote the element

		var i,j,y,z;
		var targetArray;
		var targetList;
		for(i=0;i<form.length;i++) {
			if ((getType(form.elements[i]) == 'checkbox') && (!form.elements[i].checked) && (form.elements[i].value == 0)) {
				form.elements[i].value = 1;
				form.elements[i].checked = false;
			}
		}
	}

	function prepareDataForTransmission(form) {
		// loop through lst* arrays and if any data has commas in it
		// then double quote the element

		var i,j,y,z;
		var targetArray;
		var targetList;
//		for(i=0;i<form.length;i++) {
//			if ((getType(form.elements[i]) == 'checkbox') && (!form.elements[i].checked)) {
//				form.elements[i].value = 0;
//				form.elements[i].checked = true;
//			}
//		}
		for(formnum=0;formnum<FormChecks.length;formnum++) {
			if (!FormChecks[formnum]) continue;
debugLog("prepare: formnum: "+formnum+" name: "+FormChecks[formnum][0]);
			targetArray = FormChecks[formnum][1];
			elemTargetList = FormChecks[formnum][3];
//			elemTargetList = findFormElement(form, targetList);

			for(i=0;i<targetArray.length;i++) {
				for(j=0;j<targetArray[i].length;j++) {
					if (typeof targetArray[i][j] == 'string') {
debugLog("prepare: formnum: "+formnum+" name: "+FormChecks[formnum][0]+" value: "+targetArray[i][j]);
						if (targetArray[i][j].indexOf(',') > -1) {
							// try only comma entries first

							// first attempt to replace double quotes with single
							targetArray[i][j].replace(/"/g, "'");

							// now wrap it with double quotes
							targetArray[i][j] = '"' + targetArray[i][j] + '"';
						}
					} else if (typeof targetArray[i][j] == 'boolean') {
						if (targetArray[i][j]) {
							targetArray[i][j] = 1;
						} else {
							targetArray[i][j] = 0;
						}
					}
				}
			}

			//set form hidden element to array
			elemTargetList.value=targetArray;
		}
	}

	function anySubBoxesPopulated(form, gotErr) {
		// look through subBoxes and find out if any parts are partially filled
		// out, if they are then build the return message for the user

		var message = "";

		var targetArray;
		var targetList;
		var formnum;
		for(formnum=0;formnum<FormChecks.length;formnum++) {
			if (!FormChecks[formnum]) continue;
debugLog("prepare: formnum: "+formnum+" name: "+FormChecks[formnum][0]);
			var formname = FormChecks[formnum][0];
			targetArray = FormChecks[formnum][1];
			elemTargetBox = FormChecks[formnum][2];
			elemTargetList = FormChecks[formnum][3];

			// find form elements
//			elemTargetBox = findFormElement(form, targetBox);
//			elemTargetList = findFormElement(form, targetList);

			var Box = FormChecks[formnum][FormChecks_BoxArrayNum];

			if (!elemTargetBox || !elemTargetList) {
				// this would mean that it is a partial form and some boxes are
				// missing, this is ok
				continue;
			}

			if (populatedElements(Box, !gotErr)) {
				message += "- You have started to enter a new entry into the '"+formname+"' section, but have not added it yet.  Please add the entry or clear it to continue.\n";
				// if it is populated, and we are going to display an error
				// we need to make sure that it is shown on the page
				toggle(formname, 'show');
			}
		}
		return message;
	}

	var notified = 0;
	function checkAllFields(form) {
		var message = "Please correct the following:\n\n";
		var gotErr = 0;

		var dontFormCheck = checkAllFields.arguments[1];

		var i, y, z;

debugLog("in checkAllFields ");

		notified = 0;
		for(i=0;i<form.length;i++) {
			var type = getType(form.elements[i]);
			if ((type != 'hidden') &&
				(type != 'button')) {
				var err = checkInputField(form.elements[i]);
				if (err != '') {
					message = message + err;
					gotErr = 1;
				}
			}
		}

		for(y=0;y<FormFieldsCheckRequiredOr.length;y++) {
debugLog("in checkAllFields: looping through FormFieldsCheckRequiredOr: "+y);
			var found_OR = 0;
			var found_OR_err = 0;
			var err_or = "";
			var check_type = FormFieldsCheckRequiredOr[y][0];
			for(z=1;z<FormFieldsCheckRequiredOr[y].length;z++) {
debugLog("in checkAllFields: looping through FormFieldsCheckRequiredOr: "+y+" z: "+z+" "+FormFieldsCheckRequiredOr[y][z]);
				if (found_OR) {
					if (check_type == '') break;
debugLog("in checkAllFields: looping through FormFieldsCheckRequiredOr: "+y+" z: "+z+" "+FormFieldsCheckRequiredOr[y][z]+" found_OR=1 clearing field");
					clearElement(FormFieldsCheckRequiredOr[y][z]);
				} else {
					var err = checkInputField(FormFieldsCheckRequiredOr[y][z], 0, 1);
					if (err != '') {
debugLog("in checkAllFields: looping through FormFieldsCheckRequiredOr: "+y+" z: "+z+" "+FormFieldsCheckRequiredOr[y][z]+" checkInputField returned an error: "+err);
						if (!found_OR_err) {		// only print the first one
							err_or = err_or + err;
							found_OR_err = 1;
						}
					} else {
debugLog("in checkAllFields: looping through FormFieldsCheckRequiredOr: "+y+" z: "+z+" "+FormFieldsCheckRequiredOr[y][z]+" checkInputField is good");
						found_OR = z;
						break;
					}
				}
			}
			if (!found_OR) {
				message = message + err_or;
				gotErr = 1;
			} else {
				for(z=1;z<FormFieldsCheckRequiredOr[y].length;z++) {
					if (found_OR == z) continue;
					if (check_type == '') break;
					clearElement(FormFieldsCheckRequiredOr[y][z]);
				}
			}
		}

		// special cases where there are dependencies on two or more fields
		if (!dontFormCheck) {
			var temp_message = anySubBoxesPopulated(form, gotErr);
			if (temp_message != "") {
				gotErr = 1;
				message = message + temp_message;
			}
		}

		if (gotErr) {
			alert(message);
			return false;
		} else {
			if (debug) return false;
			return true;
		}
	}

	function keyup_event(passed_field, dont_alert) {
		var field = this;
		var message = "";
		if (dont_alert && passed_field) field = passed_field;
debugLog("keyp: here "+getName(field));
		y = findFormFieldSaveAsValue(getName(field), '', '');
		if (y != null) {
			if (FormFields[y][FormFields_maxlength] != '') {
				FormFields[y][FormFields_magicKeyUp] = field.value.length;
				if (FormFields[y][FormFields_magicKeyUp] > FormFields[y][FormFields_maxlength]) {
debugLog(FormFields[y][FormFields_magicKeyUp]+" > "+FormFields[y][FormFields_maxlength]+" "+FormFields[y][FormFields_magicAlerted]);
				    if (!FormFields[y][FormFields_magicAlerted] || dont_alert) {
						if (!dont_alert) {
							alert('Only '+FormFields[y][FormFields_maxlength]+' characters maximum allowed for "'+FormFields[y][FormFields_display_name]+'"!');
//				    		FormFields[y][FormFields_magicAlerted] = true;
						} else {
							message += '- truncating the field: "'+FormFields[y][FormFields_display_name]+'", only '+FormFields[y][FormFields_maxlength]+' characters maximum allowed - please check your data!\n';
						}
					}
				    field.value = field.value.substring(0,FormFields[y][FormFields_maxlength]); // chop the last typed char
					FormFields[y][FormFields_magicKeyUp] = field.value.length;
				}
			}
			if (!dont_alert) {
				return true;
			} else {
				return message;
			}
		}
	}

	function validateField(y, fieldCheckType) {
		// y = return value from findFormFieldSaveAsValue

		if (y == null) {
			return 0;
		}

		var type = getType(FormFields[y][FormFields_object]);
		if (type != 'text') {
			return 1;	// we only do text fields right now
		}

		var value = FormFields[y][FormFields_object].value;
		switch (fieldCheckType) {
			case 'email':
				return isValidEmail(value);
				break;
			case 'nospaces':
				if (value.match(/\s/)) {
					return 0;
				}
				return 1;
				break;
			case 'alphanumonly':
				if (value.match(/[^a-zA-Z0-9]/)) {
					return 0;
				}
				return 1;
				break;
			case 'alphanum_underscore_only':
				if (value.match(/[^a-zA-Z0-9_]/)) {
					return 0;
				}
				return 1;
				break;
			case 'numonly':
				if (value.match(/[^0-9]/)) {
					return 0;
				}
				return 1;
				break;
			case 'nocommas':
				if (value.match(/,/)) {
					return 0;
				}
				return 1;
				break;

			// now ones that alter the data, but don't validate the data

			case 'trimspaces':
				if (value.match(/^\s*([\S]*.*[\S]*)\s*$/)) {
					if (RegExp.lastParen) {
						FormFields[y][FormFields_object].value = RegExp.lastParen;
					}
				}
				return 1;
				break;
		}
	}

	function isFieldValid(y) {
		// y = return value from findFormFieldSaveAsValue
		var delim = 0;
		var i = 0;
		var offset = 0;

		if (y != null) {
			var fieldChecksCommaDelim = FormFields[y][FormFields_field_checks];
			if (fieldChecksCommaDelim && fieldChecksCommaDelim != null &&
					fieldChecksCommaDelim != '') {
				while ((delim = fieldChecksCommaDelim.indexOf(",",offset)) > -1) {
					var fieldCheckType = fieldChecksCommaDelim.substring(offset, delim);
					offset = delim + 1;
					if (!validateField(y, fieldCheckType)) {
						// if any of them return false then return false
						return 0;
					}
				}
				if (offset < fieldChecksCommaDelim.length) {
					var fieldCheckType = fieldChecksCommaDelim.substring(offset, fieldChecksCommaDelim.length);
					if (!validateField(y, fieldCheckType)) {
						// if any of them return false then return false
						return 0;
					}
				}
			}
			return 1;	// all returned true so return true
		} else {
			// field wasn't found
			// bad data passed in, so return false, force the code to be checked
			return 0;
		}
		return 0;
	}

	function checkInputField(field, notify) {
		var message = "Please correct the following:\n\n";
		var temp_message = "";

		var forceRequiredCheck = checkInputField.arguments[2];
		var y = findFormFieldSaveAsValue(getName(field), '', '');

		if (typeof field != null) {
			if (
				(!isFieldValid(y)) ||
				(!isPopulated(field, 0)) ||
				((temp_message = keyup_event(field, 1)) != "")
			) {
				var errtext = '';
				if (temp_message != "") {
					errtext = temp_message;
				} else {
					if (y != null) {
						if (FormFields[y][FormFields_required] || forceRequiredCheck) {
							errtext = FormFields[y][FormFields_reqerr];
						}
					} else {
debugLog("field unknown: "+field.name);
					}
				}
				if (errtext) {
debugLog("checkInputField: "+field.name+" "+errtext);
					if (!notified) {
						field.focus();
					}
					notified = 1;
					if (notify) {
						alert(message+errtext);
						return false;
					} else {
						return errtext;
					}
				} else {
debugLog("checkInputField: "+field.name+" err is blank");
				}
			}
		}
		if (notify) {
			return true;
		} else {
			return '';
		}
	}
	
	function isNum(passedVal) {
		if (passedVal == ""){
			return false;
		}
		for (i=0; i<passedVal.length; i++){
			if (passedVal.charAt(i) < "0" || passedVal.charAt(i) > "9" ){
				return false;
			}
		}
		return true;
	}
	
//	var education_message = "We are unable to add the education or certification.\n\nYou must either enter a school by:\n    * filling in school name\n    * entering an education type other than Certification\n    * and entering a year of completion\n    * you may also enter a major\n\nor you can enter a certification by:\n    * filling in the Certification\n    * entering an education type of Certification\n    * and entering a year of completion.\n\nPlease Correct.\n";

	function checkElements(form, formname, targetArray, elemTargetBox, elemTargetList, Box, dont_notify) {
		var i,j,k,y,z;
		for(i=0;i<Box.length;i++) {
			var check = Box[i][0];
			if ((check == 'required') || (check == 'required_or')) {
				var all_exist = 1;
				var one_exist = 0;
				var focused = 0;

				var errMsg = Box[i][1];
				for(j=2;j<Box[i].length;j++) {
					if (typeof Box[i][j][0] == 'string') {
						var arrLen = Box[i][j].length;
						var opType = '';
						var nextOp = '';
						var first_char = Box[i][j][0].charAt(0);
						var found_AND = 1;
						var found_OR = 0;
						if (first_char == '&') {
							// this is the only one implemented right now
							opType = '&';
						} else if (first_char == '|') {
							opType = '|';
						}
						for(k=1; found_AND && k<arrLen;k++) {
							var not_equal = 0;
							var not_equal_value = '';
							var equal = 1;
							var equal_value = '';
							if (typeof Box[i][j][k] != 'object') continue;
							if ((k<arrLen-1) && (typeof Box[i][j][k+1] != 'object')) {
								var first_char = Box[i][j][k+1].charAt(0);
								if (first_char == '=') {
									nextOp = '=';
								} else if (first_char == '!') {
									nextOp = '!';
									// perform a not equal
									not_equal = 1;
									equal = 0;
									not_equal_value = Box[i][j][k+1].substr(1);
								} else {
									nextOp = '';
									// perform an equal
									equal = 1;
									not_equal = 0;
									equal_value = Box[i][j][k+1].substr(1);
								}
							} else {
								nextOp = '';
							}
							if (opType == '&') {
								// now perform the AND checks
								if (
									(getType(Box[i][j][k]) == 'text') ||
									(getType(Box[i][j][k]) == 'textarea') 
								) {
									if (equal && (Box[i][j][k].value == equal_value) || (not_equal && (Box[i][j][k].value == not_equal_value))) {
										found_AND = 0;
										if (!focused) {
											Box[i][j][k].focus();
											Box[i][j][k].select();
										}
										focused = 1;
										break;
									}
								} else if (
									(getType(Box[i][j][k]) == 'select-one') ||
									(getType(Box[i][j][k]) == 'select-multiple') 
								) {
									if (equal && (Box[i][j][k].selectedIndex > -1) && (Box[i][j][k].options[Box[i][j][k].selectedIndex].text == equal_value) || (not_equal && (Box[i][j][k].selectedIndex > -1) && (Box[i][j][k].options[Box[i][j][k].selectedIndex].text == not_equal_value))) {
										found_AND = 0;
										if (!focused) {
											Box[i][j][k].focus();
										}
										focused = 1;
										break;
									}
								} else if (getType(Box[i][j][k]) == 'checkbox') {
									if ((equal && !Box[i][j][k].checked) || (not_equal && Box[i][j][k].checked)) {
										found_AND = 0;
										if (!focused) {
											Box[i][j][k].focus();
										}
										focused = 1;
										break;
									}
								} else if (getType(Box[i][j][k]) == 'radio') {
									var found, z;
									for (z=0,found=0; z<Box[i][j][k].length; z++) {
										if (Box[i][j][k][z].checked) {
											found = 1;
											break;
										}
									}
									if (!found) {
										if (!focused) {
											Box[i][j][k][0].focus();
										}
										focused = 1;
										found_AND = 0;
									}
								}
							} else if (opType == '|') {
								// now perform the OR checks
							}
							if (nextOp != '') k++;		// skip next one
						}
						if (found_AND) {
							one_exist = 1;
						} else {
							all_exist = 0;
						}
					} else {	// normal condition
						if (
							(getType(Box[i][j]) == 'text') ||
							(getType(Box[i][j]) == 'textarea') 
						) {
							if ((Box[i][j].value == "") ||
								((Box[i][j].value != Math.round(Box[i][j].value)) && ((FormFields[findFormFieldSaveAsValue(Box[i][j].name, '', '')][FormFields_dbtype] == 'num') || (FormFields[findFormFieldSaveAsValue(Box[i][j].name, '', '')][FormFields_dbtype] == 'num-notnull'))) 
							) {
								all_exist = 0;
								if (!focused) {
									Box[i][j].focus();
									Box[i][j].select();
								}
								focused = 1;
							} else {
								one_exist = 1;
							}
						} else if (
							(getType(Box[i][j]) == 'select-one') ||
							(getType(Box[i][j]) == 'select-multiple') 
						) {
							if ((Box[i][j].selectedIndex > -1) && (Box[i][j].options[Box[i][j].selectedIndex].text == "")) {
								all_exist = 0;
								if (!focused) {
									Box[i][j].focus();
								}
								focused = 1;
							} else {
								one_exist = 1;
							}
						} else if (getType(Box[i][j]) == 'checkbox') {
							if (!Box[i][j].checked) {
								all_exist = 0;
								if (!focused) {
									Box[i][j].focus();
								}
								focused = 1;
							} else {
								one_exist = 1;
							}
						} else if (getType(Box[i][j]) == 'radio') {
							var found, z;
							for (z=0,found=0; z<Box[i][j].length; z++) {
								if (Box[i][j][z].checked) {
									found = 1;
									break;
								}
							}
							if (found) {
								one_exist = 1;
							} else {
								all_exist = 0;
								if (!focused) {
									Box[i][j][0].focus();
								}
								focused = 1;
							}
						}
					}
				}
				if ((!all_exist && (check == 'required')) || (!one_exist && (check == 'required_or'))) {
					if (!dont_notify) alert(errMsg);
					return false;
				}
			} else if (check == 'date range') {
				var valid_date_range = 0;

				var start_month = 0;
				var start_year = 0;
				var end_month = 0;
				var end_year = 0;

				var errMsg = Box[i][1];
				start_month = Box[i][2];
				start_year = Box[i][3];
				end_month = Box[i][4];
				end_year = Box[i][5];
				unless_field = Box[i][6];

				if (unless_field) {
					if (
						(getType(unless_field) == 'text') ||
						(getType(unless_field) == 'textarea') 
					) {
						if (unless_field.value != "") {
							continue;
						}
					} else if (
						(getType(unless_field) == 'select-one') ||
						(getType(unless_field) == 'select-multiple') 
					) {
						if ((unless_field.selectedIndex > -1) && (unless_field.options[unless_field.selectedIndex].text != "")) {
							continue;
						}
					} else if (getType(unless_field) == 'checkbox') {
						if (unless_field.checked) {
							continue;
						}
					}
				}

				if (!start_month || !end_month || !start_year || !end_year) {
					if (!dont_notify) alert("problem with date fields!");
					return false;
				}

				// Check Date Accuracy
				if (end_month.selectedIndex > -1 && end_month.options[end_month.selectedIndex].value != "Present") {
					if (start_year.selectedIndex > -1 && start_year.options[start_year.selectedIndex].value > end_year.options[end_year.selectedIndex].value) {
						// 
						if (!dont_notify) {
							alert("Your start date is after the end date"+errMsg+".  Please Correct.");
							start_year.focus();
						}
						return false;
					}
					if (start_year.selectedIndex > -1 && end_year.selectedIndex > -1 && start_year.options[start_year.selectedIndex].value == end_year.options[end_year.selectedIndex].value) {
						// Check to make sure month is accurate
						if (start_month.selectedIndex > -1 && end_month.selectedIndex > -1 && start_month.options[start_month.selectedIndex].value > end_month.options[end_month.selectedIndex].value) {
							if (!dont_notify) {
								alert("Your start month is after the end month"+errMsg+".  Please Correct.");
								start_month.focus();
							}
							return false;
						}	
					}
				}
			}
		}
		return true;
	}

	function populatedElements(Box, focus) {
		var i,j,y,z;
		for(i=0;i<Box.length;i++) {
			var check = Box[i][0];
			if (check == 'clear') {
				for(j=2;j<Box[i].length;j++) {
					if (isPopulated(Box[i][j], focus)) {
						return true;
					}
				}
			}
		}
		return false;
	}

	function isPopulated(obj, focus) {
		var y,z;

		var type = getType(obj);
		var name = getName(obj);

debugLog("isPopulated: name: "+name+" type: "+type);

		if (
			(type == 'text') ||
			(type == 'textarea') 
		) {
			if (obj.value != "") {
debugLog("isPopulated: text field: "+obj.name+" value: "+obj.value);
				if (focus) obj.focus();
				return true;
			}
		} else if (
			(type == 'select-one') ||
			(type == 'select-multiple') 
		) {
			// need to find out if we want to determine select based on value
			// or text, if value, value = 0 , if text, not empty
			y = findFormFieldSaveAsValue(name, '', '');
			var select_type = '';
			if (y != null) {
				select_type = FormFields[y][FormFields_select_data];
			}

debugLog("isPopulated: select field: "+name+" selected: "+obj.selectedIndex);
			if ((obj.selectedIndex > -1) && ((select_type == 'text' && obj.options[obj.selectedIndex].text != "") || (select_type == 'zero' && obj.options[obj.selectedIndex].value != '') || (select_type == '' && (obj.options[obj.selectedIndex].value != 0 && obj.options[obj.selectedIndex].value != '')))) {
debugLog("isPopulated: select field: "+obj.name+" text: "+obj.options[obj.selectedIndex].text+" value: "+obj.options[obj.selectedIndex].value+" index: "+obj.selectedIndex+" select_type: "+select_type);
				if (focus) obj.focus();
				return true;
			}
		} else if (type == 'checkbox') {
debugLog("isPopulated: checkbox field: "+name+" value: "+obj.checked);
			if (obj.checked) {
				if (focus) obj.focus();
				return true;
			}
		} else if (type == 'radio') {
debugLog("isPopulated: radio field: "+getName(obj)+" value: "+obj.value);
			var z;
			if (obj.value != null) {
				return true;
			} else {
				for (z=0; z<obj.length; z++) {
					if (obj[z].checked) {
						if (focus) obj[z].focus();
						return true;
					}
				}
			}
		} else if (type == 'file') {
			if (obj.value != "") {
debugLog("isPopulated: file field: "+obj.name+" value: "+obj.value);
				if (focus) obj.focus();
				return true;
			}
		}
		return false;
	}

	function saveElements(form, formname, targetArray, elemTargetBox, elemTargetList, Box) {
		var i,j,k,y,z;
		var origBox = elemTargetBox;
		var origList = elemTargetList;
		if (typeof elemTargetBox != 'object') {
			elemTargetBox = findFormElement(form, elemTargetBox);
			if (!elemTargetBox) {
				debugLog("saveElements: couldn't find object called: "+origBox);
				return;
			}
		}
		if (typeof elemTargetList != 'object') {
			elemTargetList = findFormElement(form, elemTargetList);
			if (!elemTargetList) {
				debugLog("saveElements: couldn't find object called: "+origList);
				return;
			}
		}
		for(i=0;i<Box.length;i++) {
			var check = Box[i][0];
			if (check == 'save') {
				var recordName = Box[i][1];
//				var current = targetArray.push([""]) - 1;
				var current = targetArray.length;
				targetArray[current] = new Array();
				targetArray[current][0] = "";
				var targetCount = 0;

				var elemRecordName = findFormElement(form, recordName);
				for(j=2;j<Box[i].length;j++) {
					var save_as_value = 0;
					if (typeof Box[i][j][0] == 'string') {
						var arrLen = Box[i][j].length;
						var opType = '';
						var nextOp = '';
						var first_char = Box[i][j][0].charAt(0);
						var found_AND = 1;
						var found_OR = 0;
						if (first_char == '&') {
							// this is the only one implemented right now
							opType = '&';
						} else if (first_char == '|') {
							opType = '|';
						}
						for(k=1; !found_OR && k<arrLen;k++) {
							var not_equal = 1;
							var not_equal_value = '';
							var equal = 0;
							var equal_value = '';
							if (typeof Box[i][j][k] != 'object') continue;
							if ((k<arrLen-1) && (typeof Box[i][j][k+1] != 'object')) {
								var first_char = Box[i][j][k+1].charAt(0);
								if (first_char == '=') {
									nextOp = '=';
									// perform an equal
									equal = 1;
									not_equal = 0;
									equal_value = Box[i][j][k+1].substr(1);
								} else if (first_char == '!') {
									nextOp = '!';
									// perform a not equal
									not_equal = 1;
									equal = 0;
									not_equal_value = Box[i][j][k+1].substr(1);
								} else {
									nextOp = '';
								}
							} else {
								nextOp = '';
							}
							var field_name = getName(Box[i][j][k]);
							if (FormFields[findFormFieldSaveAsValue(field_name, '', '')][FormFields_select_data] == 'text') {
								save_as_value = 0;
							} else {
								save_as_value = 1;
							}
							if (opType == '|') {
								// now perform the OR checks
								if (
									(getType(Box[i][j][k]) == 'text') ||
									(getType(Box[i][j][k]) == 'textarea') 
								) {
									if (equal && (Box[i][j][k].value == equal_value) || (not_equal && (Box[i][j][k].value != not_equal_value))) {
										targetArray[current][targetCount++] = Box[i][j][k].value;
debugLog(targetArray[current][targetCount-1]+" = "+Box[i][j][k].value);
										found_OR = 1;
//										continue;
									}
								} else if (
									(getType(Box[i][j][k]) == 'select-one') ||
									(getType(Box[i][j][k]) == 'select-multiple') 
								) {
									if (equal && (Box[i][j][k].selectedIndex > -1) && (Box[i][j][k].options[Box[i][j][k].selectedIndex].text == equal_value) || (not_equal && (Box[i][j][k].selectedIndex > -1) && (Box[i][j][k].options[Box[i][j][k].selectedIndex].text != not_equal_value))) {
										if (save_as_value) {
											targetArray[current][targetCount++] = Box[i][j][k].options[Box[i][j][k].selectedIndex].value;
										} else {
											targetArray[current][targetCount++] = Box[i][j][k].options[Box[i][j][k].selectedIndex].text;
										}
										found_OR = 1;
//										continue;
									}
								} else if (getType(Box[i][j][k]) == 'checkbox') {
									if ((equal && !Box[i][j][k].checked) || (not_equal && Box[i][j][k].checked)) {
										targetArray[current][targetCount++] = Box[i][j][k].checked;
debugLog(targetArray[current][targetCount-1]+" = "+Box[i][j][k].checked);
										found_OR = 1;
//										continue;
									}
								} else if (getType(Box[i][j][k]) == 'radio') {
									var z;
									for (z=0; z<Box[i][j][k].length; z++) {
										if (Box[i][j][k][z].checked) {
											targetArray[current][targetCount++] = Box[i][j][k][z].value;
debugLog(targetArray[current][targetCount-1]+" = "+Box[i][j][k][z].value);
											found_OR = 1;
											break;
										}
									}
								}
							}
							if (nextOp != '') k++;		// skip next one
						}
					} else {	// normal condition
						var field_name = getName(Box[i][j]);
						debugLog("saveElements: ["+field_name+"]: findField i: "+i+" j: "+j);
						if (FormFields[findFormFieldSaveAsValue(field_name, '', '')][FormFields_select_data] == 'text') {
							save_as_value = 0;
						} else {
							save_as_value = 1;
						}
						if (
							(getType(Box[i][j]) == 'text') ||
							(getType(Box[i][j]) == 'textarea') 
						) {
							targetArray[current][targetCount++] = Box[i][j].value;
//							continue;
						} else if (
							(getType(Box[i][j]) == 'select-one') ||
							(getType(Box[i][j]) == 'select-multiple') 
						) {
							if (Box[i][j].selectedIndex > -1) 
								if (save_as_value) {
									targetArray[current][targetCount] = Box[i][j].options[Box[i][j].selectedIndex].value;
								} else {
									targetArray[current][targetCount] = Box[i][j].options[Box[i][j].selectedIndex].text;
								}
								targetCount++;
//							continue;
						} else if (getType(Box[i][j]) == 'checkbox') {
							targetArray[current][targetCount++] = Box[i][j].checked;
debugLog(targetArray[current][targetCount-1]+" = "+Box[i][j].checked);
						} else if (getType(Box[i][j]) == 'radio') {
							var z;
							for (z=0; z<Box[i][j].length; z++) {
								if (Box[i][j][z].checked) {
									targetArray[current][targetCount++] = Box[i][j][z].value;
debugLog(targetArray[current][targetCount-1]+" = "+Box[i][j][z].value);
									break;
								}
							}
						}
					}
				}

				//get number of options in select box				
				var cnt = elemTargetBox.length;
		
				//create new option
				var temp_opt = new Option();
				//set option properties
				temp_opt.value= current;
debugLog("saveElement: elemRecordName: "+getName(elemRecordName));
				if (
					(getType(elemRecordName) == 'select-one') ||
					(getType(elemRecordName) == 'select-multiple') 
				) {
					temp_opt.text= elemRecordName.options[elemRecordName.selectedIndex].text;
				} else {
					temp_opt.text= elemRecordName.value;
				}
				//add option to select box
				elemTargetBox.options[cnt] = temp_opt;

				//set form hidden element to array
				elemTargetList.value=targetArray;
				return true;
			}
		}
		return false;
	}

	function doesElemMatchArray(elem, array) {
		var i;
		for(i=0;i<array.length;i++) {
			if (array[i] == elem) {
				return 1;
			}
		}
		return 0;
	}

//call like: saveRetrievedElements(form, formnum, ...
	function saveRetrievedElements(form, formchecknum) {
		var i,j,y,z;
		var elemTargetBox = FormChecks[formchecknum][2];
		if (!elemTargetBox) {
			debugLog("saveRetrievedElements: couldn't find object called: "+FormChecks[formchecknum][2]);
			return;
		}
		var elemTargetList = FormChecks[formchecknum][3];
		if (!elemTargetList) {
			debugLog("saveRetrievedElements: couldn't find object called: "+FormChecks[formchecknum][3]);
			return;
		}
		var targetArray = FormChecks[formchecknum][1];
		var Box = FormChecks[formchecknum][FormChecks_BoxArrayNum];
		for(i=0;i<Box.length;i++) {
			var check = Box[i][0];
debugLog("saveRetrievedElements: check: "+check+" i: "+i);
			if (check == 'save') {
				var recordName = Box[i][1];
				//var current = targetArray.push([""]) - 1;
				var current = targetArray.length;
				targetArray[current] = new Array();
				targetArray[current][0] = "";
				var targetCount = 0;
				var tempBoxName = "undefined";

				if ((elemTargetBox == null) || (elemTargetList == null)) {
//					alert("Script Error!");
					debugLog("elemTargetBox: "+elemTargetBox);
					debugLog("elemTargetList: "+elemTargetList);
					return;
				}
				for (z=saveRetrievedElements.length; !found_OR && (z+1)<saveRetrievedElements.arguments.length; z+=2) {
debugLog("saveRet(TOP): arg "+z+": "+saveRetrievedElements.arguments[z]+" arg "+(z+1)+": "+saveRetrievedElements.arguments[z+1]);
				}
				for(j=1;j<Box[i].length;j++) {
					var save_as_value = 0;
					if (typeof Box[i][j][0] == 'string') {
						var arrLen = Box[i][j].length;
						var opType = '';
						var nextOp = '';
						var first_char = Box[i][j][0].charAt(0);
						var found_AND = 1;
						var found_OR = 0;
						if (first_char == '&') {
							// this is the only one implemented right now
							opType = '&';
						} else if (first_char == '|') {
							opType = '|';
						}
						for (z=saveRetrievedElements.length; !found_OR && (z+1)<saveRetrievedElements.arguments.length; z+=2) {
debugLog("saveRet(OR): "+saveRetrievedElements.arguments[z]+" "+saveRetrievedElements.arguments[z+1]+" count: "+targetCount+" j: "+j);
							// args will be sent in as pairs of two, 
							// first is field_name, second is field_value
							for(k=1; !found_OR && k<arrLen;k++) {
								var not_equal = 1;
								var not_equal_value = '';
								var equal = 0;
								var equal_value = '';
								if (typeof Box[i][j][k] != 'object') {
debugLog("saveRet(OR): "+saveRetrievedElements.arguments[z]+" "+saveRetrievedElements.arguments[z+1]+" count: "+targetCount+" i: "+i+" j: "+j+" k: "+k+" box item not an object reference");
									continue;
								}
								if ((k<arrLen-1) && (typeof Box[i][j][k+1] != 'object')) {
									var first_char = Box[i][j][k+1].charAt(0);
									if (first_char == '=') {
										nextOp = '=';
										// perform an equal
										equal = 1;
										not_equal = 0;
										equal_value = Box[i][j][k+1].substr(1);
									} else if (first_char == '!') {
										nextOp = '!';
										// perform a not equal
										not_equal = 1;
										equal = 0;
										not_equal_value = Box[i][j][k+1].substr(1);
									} else {
										nextOp = '';
									}
								} else {
									nextOp = '';
								}
								if (opType == '|') {
									// now perform the OR checks
debugLog("saveRet(OR): checks "+saveRetrievedElements.arguments[z]+" == "+getName(Box[i][j][k])+" i: "+i+" j: "+j+" k: "+k+" name: "+Box[i][j][k].name);
									if (saveRetrievedElements.arguments[z] == getName(Box[i][j][k])) {
										if (j == 1) {
debugLog("saveRet(OR): "+saveRetrievedElements.arguments[z]+" "+saveRetrievedElements.arguments[z+1]+" count: "+targetCount+" j: "+j+" BoxName: "+tempBoxName);
											if ((tempBoxName == 'undefined') && (saveRetrievedElements.arguments[z+1] != '')) {
												tempBoxName = saveRetrievedElements.arguments[z+1];
debugLog("saveRet(OR): "+saveRetrievedElements.arguments[z]+" "+saveRetrievedElements.arguments[z+1]+" count: "+targetCount+" j: "+j+" BoxName: "+tempBoxName);
											}
										} else {
											targetArray[current][targetCount++] = saveRetrievedElements.arguments[z+1];
											found_OR = 1;
										}
										break;
									}
								}
								if (nextOp != '') k++;		// skip next one
							}
						}
					} else {	// normal condition
						for (z=saveRetrievedElements.length; (z+1)<saveRetrievedElements.arguments.length; z+=2) {
debugLog("saveRet[normal]: "+saveRetrievedElements.arguments[z]+" "+saveRetrievedElements.arguments[z+1]+" count: "+targetCount+" j: "+j);
							if (saveRetrievedElements.arguments[z] == getName(Box[i][j])) {
debugLog("saveRet[normal]: "+saveRetrievedElements.arguments[z]+" "+saveRetrievedElements.arguments[z+1]+" count: "+targetCount+" j: "+j+" BoxName: "+tempBoxName);
								if (j == 1) {
									if ((tempBoxName == 'undefined') && (saveRetrievedElements.arguments[z+1] != '')) {
										if ((getType(Box[i][j]) == 'select-one') && (FormFields[findFormFieldSaveAsValue(getName(Box[i][j]), '', '')][FormFields_select_data] == '')) {
											found = findSelectOptionHardWay(Box[i][j], 1, saveRetrievedElements.arguments[z+1]);
											if (found != null) {
												tempBoxName = Box[i][j].options[found].text;
											} else {
												tempBoxName = saveRetrievedElements.arguments[z+1];
											}
										} else {
											tempBoxName = saveRetrievedElements.arguments[z+1];
										}
debugLog("saveRet[normal]: "+saveRetrievedElements.arguments[z]+" "+saveRetrievedElements.arguments[z+1]+" count: "+targetCount+" j: "+j+" BoxName: "+tempBoxName);
									}
								} else {
									targetArray[current][targetCount++] = saveRetrievedElements.arguments[z+1];
								}
								break;
							}
						}
					}
				}

				//get number of options in select box				
				var cnt = elemTargetBox.length;
		
				//create new option
				var temp_opt = new Option();
				//set option properties
				temp_opt.value= current;
				temp_opt.text= tempBoxName;
				//add option to select box
				elemTargetBox.options[cnt] = temp_opt;

				//set form hidden element to array
				elemTargetList.value=targetArray;

				if (elemTargetBox.length == 0) {
//					var editButton = findFormElement(form, FormChecks[formchecknum][4]);
					var editButton = FormChecks[formchecknum][4];
					if (editButton) editButton.disabled = true;
//					var removeButton = findFormElement(form, FormChecks[formcheknum][5]);
					var removeButton = FormChecks[formchecknum][5];
					if (removeButton) removeButton.disabled = true;

					var moveUpButton = FormChecks[formchecknum][6];
					if (moveUpButton) moveUpButton.disabled = true;

					var moveDownButton = FormChecks[formchecknum][7];
					if (moveDownButton) moveDownButton.disabled = true;
				} else if (elemTargetBox.length > 0) {
//					var editButton = findFormElement(form, FormChecks[formchecknum][4]);
					var editButton = FormChecks[formchecknum][4];
					if (editButton) editButton.disabled = false;
//					var removeButton = findFormElement(form, FormChecks[formchecknum][5]);
					var removeButton = FormChecks[formchecknum][5];
					if (removeButton) removeButton.disabled = false;

					if (elemTargetBox.length > 1) {
						var moveUpButton = FormChecks[formchecknum][6];
						if (moveUpButton) moveUpButton.disabled = false;

						var moveDownButton = FormChecks[formchecknum][7];
						if (moveDownButton) moveDownButton.disabled = false;
					}
				}
				return true;
			}
		}
		return false;
	}

	function findSelectOptionHardWay(Select, save_as_value, equal_to) {
		var c;
		var found;
		for(c=0;c<Select.options.length;c++) {
			if (((!save_as_value) && (Select.options[c].text == equal_to) || ((save_as_value) && (Select.options[c].value == equal_to)))) {

debugLog("found it called: "+Select.name+" with element: "+equal_to+" field value: "+Select.options[c].value+" text: "+Select.options[c].text);
				found = c;
				break;
			}
		}
		return found;
	}

	function findSelectOption(Select, save_as_value, equal_to, start, end) {

		if (start > end) return null;

		if ((start == '') && (end == '')) {
			// need to start off
			start = 0;
			end = Select.options.length-1;
		}
		var mid = Math.round((end + start)/2);
debugLog("findSelectOption start: "+start+" end: "+end+" mid: "+mid);
		var midValue;
		if (save_as_value) {
			midValue = Select.options[mid].value;
		} else {
			midValue = Select.options[mid].text;
		}
debugLog("findSelectOption start: "+start+" end: "+end+" mid: "+mid+" midValue: "+midValue+" equal: "+equal_to);

		if (equal_to == midValue) {
			// found it, so return the num
			debugLog("findSelectOption found it: "+mid);
			return mid;
		} else {
			if ((start == end) && (start == mid)) {
				return null;
			} else {
				if (equal_to.toLowerCase() < midValue.toLowerCase()) {
					debugLog("findSelectOption equal: "+equal_to+" < mid: "+midValue);
					return findSelectOption(Select, save_as_value, equal_to, start, mid-1);
				} else if (equal_to.toLowerCase() > midValue.toLowerCase()) {
					debugLog("findSelectOption equal: "+equal_to+" > mid: "+midValue);
					return findSelectOption(Select, save_as_value, equal_to, mid+1, end);
				}
			}
		}
		return null;
	}

	function findFormFieldSaveAsValue(field_name, start, end) {
		if (FormFields_Index2 != '') {
			return FormFields_Index2[field_name];
		}
		if (start > end) return null;
		if ((start == 0) && (end == 1)) return null;  //attempt to stop endless loop.10/29/2007 KME

		if ((start == '') && (end == '')) {
			// need to start off
			start = 0;
			end = FormFields_Index.length-1;
		}
		var mid = Math.round((end + start)/2);


        // test...  This is the legendary "Stack overflow at line 1455", reached this
        // conclusion through a process of elimination and inserting additional lines before
        // and after this line to change the line number in the error.  KME 10/29/2007
 
        //alert("field: "+field_name + " start: " + start + " end: " + end + " mid: " + mid);

		//debugLog("findFormFieldSaveAsValue ["+field_name+"]: start: "+start+" end: "+end+" mid: "+mid);

		if (!FormFields[FormFields_Index[mid]]) return null;
		if (field_name == FormFields[FormFields_Index[mid]][FormFields_name]) {
			// found it, so return the num
		//debugLog("findFormFieldSaveAsValue: found it: "+FormFields_Index[mid]);
			return FormFields_Index[mid];
		} else {
			if ((mid == end && start+1 == end) && (field_name == FormFields[FormFields_Index[start]][FormFields_name])) {
				// found it, so return the num
		//debugLog("findFormFieldSaveAsValue: found it: "+FormFields_Index[start]);
				return FormFields_Index[start];
			}
			if ((start == end) && (start == mid)) {
				return null;
			} else {
				if (field_name < FormFields[FormFields_Index[mid]][FormFields_name]) {
					return findFormFieldSaveAsValue(field_name, start, mid-1);
				} else if (field_name > FormFields[FormFields_Index[mid]][FormFields_name]) {
					return findFormFieldSaveAsValue(field_name, mid+1, end);
				}
			}
		}
		return null;
	}

	function spliceArray(targetArray, startElem, deleteCount) {
		var i;

		// remove the elements from the array and move the elements down
		for (i=startElem; i+deleteCount<targetArray.length; i++) {
			targetArray[i] = targetArray[i+deleteCount];
		}
		// now set the length less the deleteCount
		targetArray.length = targetArray.length - deleteCount;
	}

	function retrieveElements(form, formname, targetArray, elemTargetBox, elemTargetList, Box, formnum) {
		var c,i,j,y,z;
		if (elemTargetBox.length == 0) {
			alert("There are no entries in the Previous '"+formname+"' list!");
			return false;
		}
		var current = elemTargetBox.selectedIndex;
		if (current == -1) {
			alert("Please select an entry from the Previous '"+formname+"' list!");
			return false;
		}
		for(i=0;i<Box.length;i++) {
			var check = Box[i][0];
			if (check == 'save') {
				var recordName = Box[i][1];
				var targetCount = 0;

				if ((elemTargetBox == null) || (elemTargetList == null)) {
					alert("Script Error!");
					debugLog("elemTargetBox: "+elemTargetBox);
					debugLog("elemTargetList: "+elemTargetList);
					return;
				}
				for(j=2;j<Box[i].length;j++) {
					var save_as_value = 0;
					if (typeof Box[i][j][0] == 'string') {
debugLog("retrieveElem(OR)");
						var arrLen = Box[i][j].length;
						var opType = '';
						var nextOp = '';
						var first_char = Box[i][j][0].charAt(0);
						var found_AND = 1;
						var found_OR = 0;
						if (first_char == '&') {
							// this is the only one implemented right now
							opType = '&';
						} else if (first_char == '|') {
							opType = '|';
						}
						// args will be sent in as pairs of two, 
						// first is field_name, second is field_value
						for(k=1; !found_OR && k<arrLen;k++) {
debugLog("retrieveElem(OR): "+getName(Box[i][j][k]));
							var not_equal = 1;
							var not_equal_value = '';
							var equal = 0;
							var equal_value = '';
							if (typeof Box[i][j][k] != 'object') continue;
							if ((k<arrLen-1) && (typeof Box[i][j][k+1] != 'object')) {
								var first_char = Box[i][j][k+1].charAt(0);
								if (first_char == '=') {
									nextOp = '=';
									// perform an equal
									equal = 1;
									not_equal = 0;
									equal_value = Box[i][j][k+1].substr(1);
								} else if (first_char == '!') {
									nextOp = '!';
									// perform a not equal
									not_equal = 1;
									equal = 0;
									not_equal_value = Box[i][j][k+1].substr(1);
								} else {
									nextOp = '';
								}
							} else {
								nextOp = '';
							}
							var FormField = findFormFieldSaveAsValue(getName(Box[i][j][k]), '', '');
							if (FormFields[FormField][FormFields_select_data] == 'text') {
								save_as_value = 0;
							} else {
								save_as_value = 1;
							}
							if (opType == '|') {
								// now perform the OR checks
								if (
									(getType(Box[i][j][k]) == 'text') ||
									(getType(Box[i][j][k]) == 'textarea') 
								) {
debugLog("found text called(OR): "+Box[i][j][k].name+" with element: "+targetArray[current][targetCount]+" current: "+current+" targetCount: "+targetCount);
									Box[i][j][k].value = targetArray[current][targetCount++];
									found_OR = 1;
									continue;
								} else if (
									(getType(Box[i][j][k]) == 'select-one') ||
									(getType(Box[i][j][k]) == 'select-multiple') 
								) {
									var found;
debugLog("looking for select called(OR): "+Box[i][j][k].name+" with element: "+targetArray[current][targetCount]+" current: "+current+" targetCount: "+targetCount);
									if (!save_as_value) {
										found = findSelectOption(Box[i][j][k], save_as_value, targetArray[current][targetCount], '', '');
									} else {
										found = findSelectOptionHardWay(Box[i][j][k], save_as_value, targetArray[current][targetCount]);
									}
									if (found != null) {
										Box[i][j][k].options[found].selected = true;
										found_OR = 1;
										targetCount++;
									} else {
										Box[i][j][k].selectedIndex = 0;
									}
									continue;
								} else if (getType(Box[i][j][k]) == 'checkbox') {
									if ((targetArray[current][targetCount] == 1) || (targetArray[current][targetCount] == true)) {
										Box[i][j][k].checked = true;
debugLog("retrieveElem: checkbox: "+Box[i][j][k].name+" checked: true");
									} else {
										Box[i][j][k].checked = false;
debugLog("retrieveElem: checkbox: "+Box[i][j][k].name+" checked: false");
									}
									targetCount++;
									found_OR = 1;
									continue;
								} else if (getType(Box[i][j][k]) == 'radio') {
									var z;
									for (z=0; z<Box[i][j][k].length; z++) {
										if (targetArray[current][targetCount] == Box[i][j][k][z].value) {
											Box[i][j][k][z].checked = true;
debugLog("retrieveElem: radio: "+Box[i][j][k][z].name+" value: "+Box[i][j][k][z].value+" checked: true");
										} else {
											Box[i][j][k][z].checked = false;
debugLog("retrieveElem: radio: "+Box[i][j][k][z].name+" value: "+Box[i][j][k][z].value+" checked: false");
										}
									}
									targetCount++;
									found_OR = 1;
									continue;
								}
								if (nextOp != '') k++;		// skip next one
							}
						}
					} else {	// normal condition
debugLog("retrieveElem: "+getName(Box[i][j]));
						y = findFormFieldSaveAsValue(getName(Box[i][j]), '', '');
						if (FormFields[y][FormFields_select_data] == 'text') {
							save_as_value = 0;
						} else {
							save_as_value = 1;
						}
						if (
							(getType(Box[i][j]) == 'text') ||
							(getType(Box[i][j]) == 'textarea') 
							) {
							Box[i][j].value = targetArray[current][targetCount++];
debugLog("retrieveElem: text: "+Box[i][j].name+" value: "+Box[i][j].value);
						} else if (
							(getType(Box[i][j]) == 'select-one') ||
							(getType(Box[i][j]) == 'select-multiple') 
						) {
							var found = null;
debugLog("looking for select called: "+Box[i][j].name+" with element: "+targetArray[current][targetCount]);
							if (!save_as_value) {
								found = findSelectOption(Box[i][j], save_as_value, targetArray[current][targetCount], '', '');
							} else {
								found = findSelectOptionHardWay(Box[i][j], save_as_value, targetArray[current][targetCount]);
							}
							if (found != null) {
								Box[i][j].options[found].selected = true;
							} else {
								Box[i][j].selectedIndex = 0;
							}
							targetCount++;
						} else if (getType(Box[i][j]) == 'checkbox') {
							if ((targetArray[current][targetCount] == 1) || (targetArray[current][targetCount] == true)) {
								Box[i][j].checked = true;
debugLog("retrieveElem: checkbox: "+Box[i][j].name+" checked: true");
							} else {
								Box[i][j].checked = false;
debugLog("retrieveElem: checkbox: "+Box[i][j].name+" checked: false");
							}
							targetCount++;
						} else if (getType(Box[i][j]) == 'radio') {
							var z;
							for (z=0; z<Box[i][j].length; z++) {
								if (targetArray[current][targetCount] == Box[i][j][z].value) {
									Box[i][j][z].checked = true;
debugLog("retrieveElem: radio: "+Box[i][j][z].name+" value: "+Box[i][j][z].value+" checked: true");
								} else {
									Box[i][j][z].checked = false;
debugLog("retrieveElem: radio: "+Box[i][j][z].name+" value: "+Box[i][j][z].value+" checked: false");
								}
							}
							targetCount++;
						}
					}
				}

				elemTargetBox.options[current] = null;
				//targetArray.splice(current, 1)
				spliceArray(targetArray, current, 1);

				if (elemTargetBox.length == 0) {
//					var editButton = findFormElement(form, FormChecks[formnum][4]);
					var editButton = FormChecks[formnum][4];
					if (editButton) editButton.disabled = true;
//					var removeButton = findFormElement(form, FormChecks[formnum][5]);
					var removeButton = FormChecks[formnum][5];
					if (removeButton) removeButton.disabled = true;

					var moveUpButton = FormChecks[formnum][6];
					if (moveUpButton) moveUpButton.disabled = true;

					var moveDownButton = FormChecks[formnum][7];
					if (moveDownButton) moveDownButton.disabled = true;
				}
				return true;
			}
		}
		return false;
	}

	function removeElements(form, formname, targetArray, elemTargetBox, elemTargetList, Box, formnum) {
		var c,i,j,y,z;
		if (elemTargetBox.length == 0) {
			alert("There are no entries in the Previous '"+formname+"' list!");
			return false;
		}
		var current = elemTargetBox.selectedIndex;
		if (current == -1) {
			alert("Please select an entry from the Previous '"+formname+"' list!");
			return false;
		}
		for(i=0;i<Box.length;i++) {
			var check = Box[i][0];
			if (check == 'save') {
				var targetCount = 0;

				if ((elemTargetBox == null) || (elemTargetList == null)) {
					alert("Script Error!");
					debugLog("elemTargetBox: "+elemTargetBox);
					debugLog("elemTargetList: "+elemTargetList);
					return;
				}

				if (!confirm("Are you sure you want to delete the entry called '"+elemTargetBox.options[current].text+"' from the Previous '"+formname+"' list?")) {
					return false;
				}

				elemTargetBox.options[current] = null;
				//targetArray.splice(current, 1)
				spliceArray(targetArray, current, 1);

				if (elemTargetBox.length == 0) {
					var editButton = FormChecks[formnum][4];
					if (editButton) editButton.disabled = true;
					var removeButton = FormChecks[formnum][5];
					if (removeButton) removeButton.disabled = true;

					var moveUpButton = FormChecks[formnum][6];
					if (moveUpButton) moveUpButton.disabled = true;

					var moveDownButton = FormChecks[formnum][7];
					if (moveDownButton) moveDownButton.disabled = true;
				}
				return true;
			}
		}
		return false;
	}

	function clearElement(elem) {
		var type = getType(elem);
		var name = getName(elem);
debugLog("clearing field: "+name);
		if (
			(type == 'text') ||
			(type == 'textarea') 
		) {
			elem.value="";
		} else if (
			(type == 'select-one') ||
			(type == 'select-multiple') 
		) {
			elem.selectedIndex=-1;
		} else if (type == 'checkbox') {
			elem.checked = false;
		} else if (type == 'radio') {
			var z;
			elem.value = null;
			for (z=0; z<elem.length; z++) {
				elem[z].checked = false;
			}
		}
	}

	function clearElements(form, Box) {
		var i,j;
		for(i=0;i<Box.length;i++) {
			var check = Box[i][0];
			if (check == 'clear') {		// on script clear out fields
				for(j=2;j<Box[i].length;j++) {
					clearElement(Box[i][j]);
				}
			}
		}
		return true;
	}

	function focusElements(form, Box) {
		var c,i,j,y,z;
		for(i=0;i<Box.length;i++) {
			var check = Box[i][0];
			if (check == 'focus') {
				var errMsg = Box[i][1];
				for(j=2;j<Box[i].length;j++) {
					Box[i][j].focus();
				}
			}
		}
		return true;
	}

	function findFormElement(form, recordName) {
		var c,i,j,y,z;
		var elemRecordName;
		if (recordName == "") {
			return elemRecordName;
		}
		if (typeof recordName == 'string') {	// normal condition
debugLog("findFormElement: looking for string "+recordName);
			return eval_me(form, "form."+recordName);
			for (z=0; z<form.elements.length; z++) {
				if (form.elements[z].name == recordName) {
debugLog("findFormElement: matched "+recordName+" field: "+form.elements[z].name);
					elemRecordName = form.elements[z];
					return elemRecordName;
				}
			}
		} else if (typeof recordName[0] == 'string') {	// it is an array
debugLog("findFormElement: looking for array "+recordName);
			var arrLen = recordName.length;
			var opType = '';
			var nextOp = '';
			var first_char = recordName[0].charAt(0);
			var found_AND = 1;
			var found_OR = 0;
			if (first_char == '&') {
				// this is the only one implemented right now
				opType = '&';
			} else if (first_char == '|') {
				opType = '|';
			}
			for(k=1; !found_OR && k<arrLen;k++) {
				var not_equal = 1;
				var not_equal_value = '';
				var equal = 0;
				var equal_value = '';
				if (typeof recordName[k] != 'object') continue;
				if ((k<arrLen-1) && (typeof recordName[k+1] != 'object')) {
					var first_char = recordName[k+1].charAt(0);
					if (first_char == '=') {
						nextOp = '=';
						// perform an equal
						equal = 1;
						not_equal = 0;
						equal_value = recordName[k+1].substr(1);
					} else if (first_char == '!') {
						nextOp = '!';
						// perform a not equal
						not_equal = 1;
						equal = 0;
						not_equal_value = recordName[k+1].substr(1);
					} else {
						nextOp = '';
					}
				} else {
					nextOp = '';
				}
				if (opType == '|') {
					// now perform the OR checks
					if (
						(getType(recordName[k]) == 'text') ||
						(getType(recordName[k]) == 'textarea') 
					) {
						if (equal && (recordName[k].value == equal_value) || (not_equal && (recordName[k].value != not_equal_value))) {
debugLog("findFormElement: found text field: "+recordName[k].name);
							elemRecordName = recordName[k];
							found_OR = 1;
							break;
						}
					} else if (
						(getType(recordName[k]) == 'select-one') ||
						(getType(recordName[k]) == 'select-multiple') 
					) {
						if (equal && (recordName[k].selectedIndex > -1) && (recordName[k].options[recordName[k].selectedIndex].text == equal_value) || (not_equal && (recordName[k].selectedIndex > -1) && (recordName[k].options[recordName[k].selectedIndex].text != not_equal_value))) {
debugLog("findFormElement: found select field: "+recordName[k].name);
							elemRecordName = recordName[k];
							found_OR = 1;
							break;
						}
					} else if (getType(recordName[k]) == 'radio') {
						var z;
						for (z=0; z<recordName[k].length; z++) {
							if (equal && (recordName[k][z].value == equal_value) || (not_equal && (recordName[k][z].value != not_equal_value))) {
								elemRecordName = recordName[k];
								found_OR = 1;
								break;
							}
						}
						if (found_OR) break;
					}
				}
				if (nextOp != '') k++;		// skip next one
			}
			if (!found_OR) {
				// uh oh, didn't find it, log it
				debugLog("findFormElement: didn't find OR element for: "+recordName);
			}
		} else if (typeof recordName == 'object') {	// it is already mapped
debugLog("findFormElement: found object "+recordName);
			return recordName;
		}
		return elemRecordName;
	}
	
	//function to create an array of elements
	function addElement(form, formname){
		var targetArray;
		var targetBox;
		var targetList;
		var formnum;
debugLog("addElem: start");
		for(formnum=0;formnum<FormChecks.length;formnum++) {
			if (FormChecks[formnum] && FormChecks[formnum][0] == formname) {
				targetArray = FormChecks[formnum][1];
				elemTargetBox = FormChecks[formnum][2];
				elemTargetList = FormChecks[formnum][3];

				// find form elements
//				elemTargetBox = findFormElement(form, targetBox);
//				elemTargetList = findFormElement(form, targetList);
				var editButton = FormChecks[formnum][4];
				var removeButton = FormChecks[formnum][5];
				var moveUpButton = FormChecks[formnum][6];
				var moveDownButton = FormChecks[formnum][7];

				var Box = FormChecks[formnum][FormChecks_BoxArrayNum];
				if (!checkElements(form, formname, targetArray, elemTargetBox, elemTargetList, Box, 0)) {
					return false;
				}
				if (!saveElements(form, formname, targetArray, elemTargetBox, elemTargetList, Box)) {
					return false;
				}
				if (!clearElements(form, Box)) {
					return false;
				}
				if (!focusElements(form, Box)) {
					return false;
				}
				if (elemTargetBox.length > 0) {
					if (editButton) editButton.disabled = false;
					if (removeButton) removeButton.disabled = false;
					if (elemTargetBox.length > 1) {
						if (moveUpButton) moveUpButton.disabled = false;
						if (moveDownButton) moveDownButton.disabled = false;
					}
				}
debugLog("addElem: end");
				return true;
			}	// if formname
		}	// for formchecks
	}

	//function to edit an array of elements
	function editElement(form, formname, remove){
		var targetArray;
		var targetBox;
		var targetList;
		var formnum;
debugLog("editElem: start");
		for(formnum=0;formnum<FormChecks.length;formnum++) {
			if (FormChecks[formnum] && FormChecks[formnum][0] == formname) {
				targetArray = FormChecks[formnum][1];
				elemTargetBox = FormChecks[formnum][2];
				elemTargetList = FormChecks[formnum][3];

				// find form elements
//				elemTargetBox = findFormElement(form, targetBox);
//				elemTargetList = findFormElement(form, targetList);

				var Box = FormChecks[formnum][FormChecks_BoxArrayNum];

				if (elemTargetBox.length == 0) {
					alert("There are no entries in the Previous '"+formname+"' list!");
					return false;
				}
				if (!remove) {
					if (populatedElements(Box, 1)) {
						// now ask them what they want to do
						if (!confirm("You have started to enter a new entry into the '"+formname+"' section, but have not added it yet.  Continuing, will delete the unfinished entry.  Are you sure you want to delete the unfinished entry?")) {
							return false;
						}
					}
				}
				var current = elemTargetBox.selectedIndex;
				if (current == -1) {
					alert("Please select an entry from the Previous '"+formname+"' list!");
					return false;
				}
				if (!remove) {
					if (!clearElements(form, Box)) {
						return false;
					}
debugLog("retrieving elements");
					if (!retrieveElements(form, formname, targetArray, elemTargetBox, elemTargetList, Box, formnum)) {
						return false;
					}
					if (!focusElements(form, Box)) {
						return false;
					}
				} else {
					if (!removeElements(form, formname, targetArray, elemTargetBox, elemTargetList, Box, formnum)) {
						return false;
					}
				}
debugLog("editElem: end");
				return true;
			}	// if formname
		}	// for formchecks
		return true;
	}

	//function to reorder an array of elements
	function reorderElement(form, formname, movedown){
		var targetArray;
		var targetBox;
		var targetList;
		var formnum;
debugLog("reorderElem: start");
		for(formnum=0;formnum<FormChecks.length;formnum++) {
			if (FormChecks[formnum] && FormChecks[formnum][0] == formname) {
				targetArray = FormChecks[formnum][1];
				elemTargetBox = FormChecks[formnum][2];
				elemTargetList = FormChecks[formnum][3];

				if (elemTargetBox.length <= 0) {
					alert("There are no entries in the Previous '"+formname+"' list!");
					return false;
				}
				if (elemTargetBox.options.length == 1) {
					alert("This is only one entry in the Previous '"+formname+"' list!");
					return false;
				}
				var current = elemTargetBox.selectedIndex;
				if (current == -1) {
					alert("Please select an entry from the Previous '"+formname+"' list!");
					return false;
				}

				if (movedown) {		// movedown
					if (current == elemTargetBox.options.length-1) {
						alert("This entry is already at the bottom of the Previous '"+formname+"' list!");
						return false;
					}

					var next = elemTargetBox.options[current+1].text;
					elemTargetBox.options[current+1].value = current;
					elemTargetBox.options[current+1].text = elemTargetBox.options[current].text;
					elemTargetBox.options[current+1].selected = true;

					elemTargetBox.options[current].value = current+1;
					elemTargetBox.options[current].text = next;
					elemTargetBox.options[current].selected = false;

					var tANext = targetArray[current+1];
					targetArray[current+1] = targetArray[current];
					targetArray[current] = tANext;
				} else {			// moveup
					if (current == 0) {
						alert("This entry is already at the top of the Previous '"+formname+"' list!");
						return false;
					}

					var prev = elemTargetBox.options[current-1].text;
					elemTargetBox.options[current-1].value = current;
					elemTargetBox.options[current-1].text = elemTargetBox.options[current].text;
					elemTargetBox.options[current-1].selected = true;

					elemTargetBox.options[current].value = current-1;
					elemTargetBox.options[current].text = prev;
					elemTargetBox.options[current].selected = false;

					var tAPrev = targetArray[current-1];
					targetArray[current-1] = targetArray[current];
					targetArray[current] = tAPrev;
				}

debugLog("reorderElem: end");
				return true;
			}	// if formname
		}	// for formchecks
		return true;
	}

	function isValidEmail(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 mould of a valid e-mail address. */

			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) {
				return false;
			}
		}
		for (i=0; i<domain.length; i++) {
			if (domain.charCodeAt(i)>127) {
				return false;
			}
		}

		// See if "user" is valid 

		if (user.match(userPat)==null) {
			// user is not valid

			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) {
					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++) {
			if (domArr[i].search(atomPat)==-1) {
				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 (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) {
			return false;
		}

		// Make sure there's a host name preceding the domain.

		if (len<2) {
			return false;
		}

		// If we've gotten this far, everything's valid!
		return true;
	}

