
function fillSelectFromArray(selectCtrl, itemArray, goodPrompt, badPrompt, defaultItem) {
    var i, j;
    var prompt;

    // empty existing items
    for (i = selectCtrl.options.length; i >= 0; i--) {
        selectCtrl.options[i] = null;
    }
    prompt = (itemArray != null) ? goodPrompt : badPrompt;
    if (prompt == null) {
        j = 0;
    } else {
        selectCtrl.options[0] = new Option(prompt);
        j = 1;
    }
    if (itemArray != null) {
        // add new items
        for (i = 0; i < itemArray.length; i++)
        {
            selectCtrl.options[j] = new Option(itemArray[i][0]);
            if (itemArray[i][1] != null) {
                selectCtrl.options[j].value = itemArray[i][1];
            }
            j++;
        }
        // select first item (prompt) for sub list
        selectCtrl.options[0].selected = true;
    }
}

// check which option button is selected and update pulldown accordingly
function update_list(From, Dest)
{

    fillSelectFromArray(Dest, destinations[From.selectedIndex]);

}

function showRepeats(me)
{
    meSelect = document.getElementsByName("repeat" + (me))[0];
    index = meSelect.selectedIndex;

    if (index > 0 && me < 9)      // Repeat was selected, show the rest
    {
        span = document.getElementById("span_repeat" + (me+1));
        span.style.display = "inline";
    }
    else if (index <=0 )
    {
        // Check if the next select box is also 0, if so, hide it
        nextSelect = document.getElementsByName("repeat" + (me+1))[0];
        if (nextSelect.selectedIndex <= 0)
        {
            span = document.getElementById("span_repeat" + (me+1));
            span.style.display = "none";
        }
    }
}
