function addToList(listField, newText, newValue) {
   if ( ( newValue == "" ) || ( newText == "" ) ) {
		alert("You cannot add blank values!");
	} else {
		var len = listField.length++;
		// Increase the size of list and return the size
		listField.options[len].value = newValue;
		listField.options[len].text = newText;
		listField.selectedIndex = len; // Highlight the one just entered (shows the user that it was entered)
	}
	// Ends the check to see if the value entered on the form is empty
}

function removeFromList(listField) {
	if ( listField.length == -1) {  // If the list is empty
		alert("There are no values which can be removed!");
	} else {
		var selected = listField.selectedIndex;
		if (selected == -1) {
			alert("You must select an entry to be removed!");
		} else {  // Build arrays with the text and values to remain
			var replaceTextArray = new Array(listField.length-1);
			var replaceValueArray = new Array(listField.length-1);
			for ( var i = 0; i < listField.length; i++ ) {
			// Put everything except the selected one into the array
			if ( i < selected) { replaceTextArray[i] = listField.options[i].text; }
			if ( i > selected ) { replaceTextArray[i-1] = listField.options[i].text; }
			if ( i < selected) { replaceValueArray[i] = listField.options[i].value; }
			if ( i > selected ) { replaceValueArray[i-1] = listField.options[i].value; }
			}
			listField.length = replaceTextArray.length;  // Shorten the input list
			for (i = 0; i < replaceTextArray.length; i++) { // Put the array back into the list
			listField.options[i].value = replaceValueArray[i];
			listField.options[i].text = replaceTextArray[i];
			}
		} // Ends the check to make sure something was selected
	} // Ends the check for there being none in the list
}

function addItem() {
  formItem = document.forms['searchform'];
  if (formItem.c1.value > '') {
	selectedForm = formItem.c1;
  } else if (formItem.c2.value > '') {
	selectedForm = formItem.c2;
  } else if (formItem.c3.value > '') {
	selectedForm = formItem.c3;
  } else if (formItem.c4.value > '') {
	selectedForm = formItem.c4;
  } else if (formItem.c5.value > '') {
	selectedForm = formItem.c5;
  }
  if (selectedForm.value > '') {
	addToList(document.forms['searchform'].criteria, selectedForm.options[selectedForm.selectedIndex].text, selectedForm.value);
  }
  selectedForm.selectedIndex = 0;
}

function createList() { // updates hidden field containing all criteria that will be submitted for processing
  var criteriaList = '';
  for (var x=0;x<document.forms['searchform'].criteria.length;x++) {
	criteriaText = document.forms['searchform'].criteria[x].text;
	criteriaValue = document.forms['searchform'].criteria[x].value;
	criteriaList += criteriaValue + ";" + criteriaText + "|";
  }
  criteriaList = criteriaList.substring(0,(criteriaList,0,criteriaList.length-1));
  document.forms['searchform'].criteria_list.value = criteriaList;
}

function clearList(listField) {
	var srcLength = listField.options.length; 
	for ( var i=srcLength; i>=0; i-- ) {
		listField.options[i] = null;
	}
}

function sendSearch(e) {
	if (window.event) {
		// IE
		if (window.event.keyCode == 13) {
			document.forms['searchform'].submit();
		}
	} else {
		// Firefox
		key = e.which;
		if (key == 13) {
			document.forms['searchform'].submit();
		}
	}
}
