/*
 * Collects options into the hidden fields and submits
 */
function checkSubmit() {
  list = document.sel_f.sel_o;
  document.sel_f.sel_1.value = list.options[0].value;
  document.sel_f.sel_2.value = list.options[1].value;
  document.sel_f.sel_3.value = list.options[2].value;
  document.sel_f.sel_4.value = list.options[3].value;
  document.sel_f.submit();
}

/*
 * Moves the selected option up
 */
function moveUp() {
  list = document.sel_f.sel_o;
  si = list.selectedIndex;
  if (si > 0) {
    a = emptyList(list);
    so = a[si];
    so.defaultSelected = true;
    so.selected = true;
    a[si] = a[si - 1];
    a[si - 1] = so;
    fillList(list, a);
  }
}

/*
 * Moves the selected option up
 */
function moveDown() {
  list = document.sel_f.sel_o;
  si = list.selectedIndex;
  if ((si >= 0) && (si < (list.options.length -1))) {
    a = emptyList(list);
    so = a[si];
    so.defaultSelected = true;
    so.selected = true;
    a[si] = a[si + 1];
    a[si + 1] = so;
    fillList(list, a);
  }
}

/*
 * Fill the list with the given options
 */
function fillList(list, a) {
  for (i = 0; i < a.length; i++) {
    list.options[i] = a[i];
    /*
    list.options[i] = new Option(a[i].text,
				 a[i].value,
				 a[i].defaultSelected,
				 a[i].selected);
    */
  }
}

/*
 * Empties a list and returns the options previously contained
 */
function emptyList(list) {
  i = 0;
  a = new Array();
  while (list.options.length > 0) {    
    a[i] = new Option(list.options[0].text,
		      list.options[0].value,
		      list.options[0].defaultSelected,
		      list.options[0].selected);
    list.options[0] = null;
    i++;
  }
  return a;
}
