﻿// JScript File

    //*******************************************************************************
    // Function:     appendOptionLast
    // Author:       Michael Chu
    // Project:      iMove Build 0.3
    // Date:         Sep 11 2006
    //
    // Description:  Add a new option an existing HTML Select control.
    //
    // Parameters:   selectId - id of the HTML Select control
    //               text - the text of the new option to be added
    //               value - the value of the new option to be added
    // Returns:
    // Called By:    
    //
    // Revision History:
    //
    //   Name        Date        Description
    //  ------       ------      ------------------------------------------------
    //
    //*******************************************************************************
    function appendOptionLast(selectId, text, value)
    {
      var elOptNew = document.createElement('option');
      elOptNew.text = text;
      elOptNew.value = value;

      var elSel = document.getElementById(selectId);

      // add it by assigning to index array
      //elSel.options[elSel.options.length] = elOptNew;
      
// The following code does not work in IE 6.0
      try {
        elSel.add(elOptNew, null); // standards compliant; doesn't work in IE
      }
      catch(ex) {
        elSel.add(elOptNew); // IE only
      }
      elOptNew = null;
      elSel = null;
    }
    
var count1 = 0;
var count2 = 0;

function insertOptionBefore(num)
{
  var elSel = document.getElementById('selectX');
  if (elSel.selectedIndex >= 0) {
    var elOptNew = document.createElement('option');
    elOptNew.text = 'Insert' + num;
    elOptNew.value = 'insert' + num;
    var elOptOld = elSel.options[elSel.selectedIndex];  
    try {
      elSel.add(elOptNew, elOptOld); // standards compliant; doesn't work in IE
    }
    catch(ex) {
      elSel.add(elOptNew, elSel.selectedIndex); // IE only
    }
    elOptNew = null;
    elOptOld = null;
  }
  elSel = null;
}

function removeOptionSelected()
{
  var elSel = document.getElementById('selectX');
  var i;
  for (i = elSel.length - 1; i>=0; i--) {
    if (elSel.options[i].selected) {
      elSel.remove(i);
    }
  }
  elSel = null;
}
    
    

function removeOptionLast()
{
  var elSel = document.getElementById('selectX');
  if (elSel.length > 0)
  {
    elSel.remove(elSel.length - 1);
  }
}

