<!--


// Control flags for list selection and sort sequence

// Sequence is on option value (first 2 chars - can be stripped off in form processing)

// It is assumed that the select list is in sort sequence initially

var singleSelect = true;  // Allows an item to be selected once only

var sortSelect = true;  // Only effective if above flag set to true

var sortPick = true;  // Will order the prolist in sort sequence



// Initialise - invoked on load

function initIt() {

  var thirdlevel = document.getElementById("thirdlevel");

  var prolist = document.getElementById("prolist");

  var pickOptions = prolist.options;

  pickOptions[0] = null;  // Remove initial entry from prolist (was only used to set default width)

  thirdlevel.focus();  // Set focus on the thirdlevel

}



// Adds a selected item into the prolist

function addIt() {

  var thirdlevel = document.getElementById("thirdlevel");

  var selectIndex = thirdlevel.selectedIndex;

  var selectOptions = thirdlevel.options;

  var prolist = document.getElementById("prolist");

  var pickOptions = prolist.options;

  var pickOLength = pickOptions.length;

  // An item must be selected

  if (selectIndex > -1) {

    pickOptions[pickOLength] = new Option(thirdlevel[selectIndex].text);

    pickOptions[pickOLength].value = thirdlevel[selectIndex].value;

    // If single selection, remove the item from the select list

    if (singleSelect) {

      selectOptions[selectIndex] = null;

    }

    if (sortPick) {

      var tempText;

      var tempValue;

      // Sort the pick list

      while (pickOLength > 0 && pickOptions[pickOLength].value < pickOptions[pickOLength-1].value) {

        tempText = pickOptions[pickOLength-1].text;

        tempValue = pickOptions[pickOLength-1].value;

        pickOptions[pickOLength-1].text = pickOptions[pickOLength].text;

        pickOptions[pickOLength-1].value = pickOptions[pickOLength].value;

        pickOptions[pickOLength].text = tempText;

        pickOptions[pickOLength].value = tempValue;

        pickOLength = pickOLength - 1;

      }

    }

  }

}



// Deletes an item from the prolist

function delIt() {

  var thirdlevel = document.getElementById("thirdlevel");

  var selectOptions = thirdlevel.options;

  var selectOLength = selectOptions.length;

  var prolist = document.getElementById("prolist");

  var pickIndex = prolist.selectedIndex;

  var pickOptions = prolist.options;

  if (pickIndex > -1) {

    // If single selection, replace the item in the select list

    if (singleSelect) {

      selectOptions[selectOLength] = new Option(prolist[pickIndex].text);

      selectOptions[selectOLength].value = prolist[pickIndex].value;

    }

    pickOptions[pickIndex] = null;

    if (singleSelect && sortSelect) {

      var tempText;

      var tempValue;

      // Re-sort the select list

      while (selectOLength > 0 && selectOptions[selectOLength].value < selectOptions[selectOLength-1].value) {

        tempText = selectOptions[selectOLength-1].text;

        tempValue = selectOptions[selectOLength-1].value;

        selectOptions[selectOLength-1].text = selectOptions[selectOLength].text;

        selectOptions[selectOLength-1].value = selectOptions[selectOLength].value;

        selectOptions[selectOLength].text = tempText;

        selectOptions[selectOLength].value = tempValue;

        selectOLength = selectOLength - 1;

      }

    }

  }

}



-->

