//
// admin.js: Contains javascript needed in the Back Office, (work and admin area).
//           Named "admin.js" to match file admin.css which has the same requirements.
//

// ---------------------------------------
// Functions for select element (<select><option>)
// Used by doEditFriendlyURLs.jsp
// ---------------------------------------
  
  // Select all element in the given select form input
  function selectAllInSelectElement(elSel)
  {
    for (var i = 0; i < elSel.length; i++) {
      if (elSel.options[i] != null) {
        elSel.options[i].selected = true;
      }
    }
  }
  
  // Add new option to the given select form element, from the input element
  function addInputToSelectElement(elInput, elSel)
  {
    var elOptNew = document.createElement('option');
    elOptNew.text = elInput.value;
    elOptNew.value = elInput.value;
    
    for (var i = 0; i < elSel.length; i++) {
      if (elSel.options[i] != null && elSel.options[i].value == elOptNew.value) {
        return; // do not add anything if value already there
      }
    }  
    try {
      elSel.add(elOptNew, null); // standards compliant; doesn't work in IE
    }
    catch(ex) {
      elSel.add(elOptNew); // IE only
    }
  }
  
  // Remove the selected option of the given select form element
  function removeSelectedOptionFromSelectElement(elSel)
  {
    for (var i = elSel.length - 1; i >= 0; i--) {
      if (elSel.options[i] != null && elSel.options[i].selected) {
        elSel.remove(i);
      }
    }
  }
  
// ---------------------------------------
