// Copyright 2005 Google Inc.  All Rights Reserved.

/**
 * removes all items from a select list
 *
 * @param obj is an HTML select list
 */
function removeAllOptions(obj){
  if (obj && obj.options) {
    for (var i = (obj.options.length - 1); i >= 0; i--) {
      obj.options[i] = null;
    }
    obj.selectedIndex = -1;
  }
}

/**
 * adds a new item to the end of a select list
 *
 * @param obj is the HTML select list
 * @param text is the text of the new item
 * @param value is the value of the new item
 * @param selected is whether or not the item should be selected.
 */
function addOption(obj, text, value, selected){
  if (obj && obj.options) {
    obj.options[obj.options.length] = new Option(text, value, false, selected);
  }
}

/**
 * populates an HTML select list from a javascript array.
 *
 * @param selectList is the HTML select list
 * @param values is a javascript array with values.
 * @param selectedItem is the item that should be selected
 */
function populateDropDown(selectList, values, selectedItem) {
  removeAllOptions(selectList);
  for (var i = 0; i < values.length; i++) {
    addOption(selectList, values[i], i, (i == selectedItem));
  }
}

/**
 * used to populate a sub-category drop down list from a primary drop down list.
 * Whenever a user changes which category is selected, or when the page loads,
 * this funciton is called.
 *
 * @param category what category is currently selected. This must be an integer
 *        between 0 and the size of the subindustry array.
 * @param selectedIndex is what item within the sub category list should be
 *        selected. If -1 is provided, no item will be selected.
 * @param subindustries is an array of arrays which must match the size
 *        of the industry drop down list. These values are used to populate
 *        the subindustry drop down list.
 */
function updateSubIndustry(category, selectedIndex, subindustries) {   
  populateDropDown(document.FormPrincipal.formProfEsp,
                   subindustries[category], selectedIndex);
}

function updateSubIndustry1(category, selectedIndex, subindustries) {   
  populateDropDown(document.FormPrincipal.trabalhoatualEsp,
                   subindustries[category], selectedIndex);
}

