/* *******************************
Multi-Select Control
******************************* */

var Index = new Object;

function CheckForAll(selectId)
{
    if (!document.getElementById) return false;
    var select = document.getElementById(selectId);    
    
    // [0] will be 'All'
    if (select.options[0].selected == true) 
    {
        // short circuit on 'show all'
        select.selectedIndex = -1;       
    }
}

function CompleteTextFromList (txtId,selectId) 
{
    if (!document.getElementById) return;
    var text   = document.getElementById(txtId);
    var select = document.getElementById(selectId);
    if (!Index.populated) BuildIndex(selectId);
    var suburb = text.value.match(/,*([^,]+)$/);

    if (suburb) 
    {
        var name = suburb[1].toUpperCase().replace(/^\s*/, '').replace(/\s*$/, '');
        for (var i = Index[name.charAt(0)]; i < select.options.length; i++) 
        {
            if (select.options[i].text.toUpperCase().indexOf(name) == 0) 
            {
                 select.options[i].selected = true;
                 break;
            }           
        }
    }
}

function BuildIndex (selectId) 
{
    if (!document.getElementById) return;
    var select = document.getElementById(selectId);
    for (var i = select.options.length; i--;) 
    {
        Index[select.options[i].text.toUpperCase().charAt(0)] = i;
    }
    Index.populated = true;
}