﻿    function clearListBox(listBox)
    {
        for (var i = listBox.childNodes.length - 1; i > -1; i--)
        {
            listBox.removeChild(listBox.childNodes[i]);
        }
    }

    function addListBoxItem(listBox, text, value)
    {
        var opt = document.createElement('option');

        listBox.appendChild(opt);

        setText(opt, text);

        if (value != null)
        {
            opt.value = value;
        }
    }

    function selectListBoxByValue(listBox, value)
    {
        listBox.selectedIndex = 0;

        var length = listBox.options.length;

        for (var i = 0; i < length; i++)
        {
            if (listBox.options[i].value == value)
            {
                listBox.selectedIndex = i;
                break;
            }
        }
    }

    function setText(element, text)
    {
        if (typeof element.innerText != 'undefined')
        {
            element.innerText = text;
        }
        else if (typeof element.textContent != 'undefined')
        {
            element.textContent = text;
        }
    }

