﻿function select_options_sort(selectlbx)
{
    arrTexts = new Array();
    arrValues = new Array();
    for(i=0; i<selectlbx.length; i++)
    {
      var lbtxt = selectlbx.options[i].text;
      arrTexts[i] = lbtxt;
      arrValues[lbtxt] = selectlbx.options[i].value;
    }
    arrTexts.sort();
    for(i=0; i<selectlbx.length; i++)
    {
      var lbtxt = arrTexts[i];
      selectlbx.options[i].text = lbtxt;
      selectlbx.options[i].value = arrValues[lbtxt];
      selectlbx.options[i].selected = false;
    }
}

function select_options_swapall(selectlbx_from, selectlbx_to)
{
    // Add options to other select box.
    for (i = 0; i < selectlbx_from.options.length; i++)
    {
        selectlbx_to.options[selectlbx_to.options.length] = new Option(
            selectlbx_from.options[i].text,
            selectlbx_from.options[i].value);
    }

    // Remove options from this select box.
    select_options_removeall(selectlbx_from);
}

function select_options_swapselected(selectlbx_from, selectlbx_to)
{
    // Add selected options to other select box.
    for (i = 0; i < selectlbx_from.options.length; i++)
    {
        if (selectlbx_from.options[i].selected)
        {
            selectlbx_to.options[selectlbx_to.options.length] = new Option(
                selectlbx_from.options[i].text,
                selectlbx_from.options[i].value);
        }
    }

    // Remove selected option from this select box.
    for (i = selectlbx_from.length-1; i >= 0; i--)
    {
        if (selectlbx_from.options[i].selected)
        {
            selectlbx_from.options[i] = null;
        }
    }
}

function select_options_removeall(selectlbx)
{
    // Remove all options from this select box.
    for (i = selectlbx.length-1; i >= 0; i--)
    {
        selectlbx.options[i] = null;
    }
}
