// function to change the values of the listfield
function changeValue( field, set) {
    // the fields
    FromField  = document.getElementById( field + (set?"_available":"_selected") );
    ToField    = document.getElementById( field + (set?"_selected":"_available") );
    SelField   = document.getElementById( field + "_available");
    ValueField = document.getElementById( field );
    
    // remove empty value from the from and to field ( <option /> tag's)
    for( i = 0; i < ToField.options.length; i++ ) {
        if( ToField.options[i].text == "" && ToField.options[i].value == "") {
            ToField.options[i] = null;
        }
    }              

    // is something selected ?
    while(FromField.value != "") {
        // get the number of options of the "new" field
        var len = ToField.options.length;

        // add the option
        ToField.options[len] = new Option(FromField.options[FromField.selectedIndex].text);
        ToField.options[len].value = FromField.options[FromField.selectedIndex].value;
        
        // remove the option from the old list
        FromField.options[FromField.selectedIndex] = null;
    }
    
    // set the focus and select the top item if there is one.
    FromField.focus();
    if( FromField.options.length > 0 ) {
        FromField.options[0].selected = true;
    }

    // put the selected value's in the hidden field
    SelectedVars = new Array();
    for(i = 0; i < SelField.options.length; i++)
      SelectedVars[i] = SelField.options[i].value;

    ValueField.value = SelectedVars.join(", ");
}

// function to move all values..
function moveAll( field, set ) {
    FromField  = document.getElementById( field + (set?"_available":"_selected") );

    for( i = 0; i < FromField.options.length; i++ ) {
        FromField.options[i].selected = true;
    }
    changeValue( field, set );
}
