﻿/** ABOS Javascript file
  *
  * Contains definitions for reusable Javascript functions for manipulating HTML Tag objects
  *
  * By: Mbonisi Masilela (9/14/2008)
  *
  */
  
function SELECT_AddItemToList(select_obj,text)
{
    var select = document.getElementById(select_obj);
    var newOption = document.createElement("OPTION");
        
    newOption.text = text;
    newOption.value = text;
    select.options.add(newOption);
}

function SELECT_ClearList(select_obj)
{
    var select = document.getElementById(select_obj);
    var newOption = document.createElement("OPTION");            
    select.length = 0;
    newOption.text = "";
    newOption.value = "";
    //A SELECT with 0 elements is invalid in JS, just add a blank option
    select.options.add(newOption);             
}

function SELECT_RemoveDuplicateOptions(select_obj)
{
    var select = document.getElementById(select_obj);
    
    for(i = 0; i < select.length; i++)
    {
        var matches = 0;
        for(j = i + 1; j < select.length; j++)
        {
            if(select.options[i].text == select.options[j].text)
                matches++;
        }
        
        if(matches > 0)
        {
            select.options[i] = null;
            i--;
        }
    }
}

