
  /**
   * Changes current location to the specified URL.
   */
  function goToPage(newHref) {
    document.location.href=newHref;
  }
  
  /**
   * Shuttles selected items from SELECT idFromList element to
   * SELECT idToList. It removes the selected items and adds
   * them to idToList (thus effectively creating new <option> elements).
   */
  function shuttleToList(idFromList,idToList) {
    var elemFrom = null;
    var elemTo   = null;
    
    elemFrom     = document.getElementById(idFromList);
    elemTo       = document.getElementById(idToList);
    
      //
      // Both must not be null, then shuttle selected item
      // from elemFrom to elemTo. If multiple items
      // are selected in elemFrom, they are shuttled over as well.
      // Checks are done to prevent double entries. Here but also
      // on the server-side.
      //
    if(elemFrom != null && elemTo != null) {
      var selectValue        = null;
        
        // We need to store indices separately, or we get into trouble
        // with our options length if we remove an option right away.
      var elemsToRemoveAvail = new Array();
      var index              = 0;
      
      for(var i = 0; i < elemFrom.options.length; i++) {
        if(elemFrom.options[i].selected) {
          selectValue = elemFrom.options[i].value;
          if(!hasItem_MatchByOptionValue(elemTo,selectValue)) {
            elemTo.appendChild(elemFrom.options[i].cloneNode(true));
          }
          elemsToRemoveAvail[index++] = i;
        }
      }
      
        // Now remove options, if any. In reverse order or we jump out of index!
      for(var i = (index-1); i >= 0; i--) {
        elemFrom.removeChild(elemFrom.options[elemsToRemoveAvail[i]]);
      }
    }
    else {
      alert('One or more selection lists are NULL. [DEVELOPER error]');
    }
  }
  
  /**
   *  Returns true if a value of an option element in specified
   *  select element matches specified value. False otherwise.
   */
  function hasItem_MatchByOptionValue(elemList,value) {
    var retValue = false;
    if(elemList != null) {
      for(var i = 0; i < elemList.options.length; i++) {
        if(elemList.options[i].value == value) {
          retValue = true;
          break;
        }
      }
    }
    else {
      alert('Select element is NULL. [DEVELOPER error]');
    }
    return retValue;
  }
  
  /**
   *  Finds the SELECT element, and selects ALL option elements. Make
   *  sure the SELECT element is set to allow a 'multiple' selection.
   */
  function selectSelectItems(idSelect) {
    var elemSelect = null;
    
    elemSelect = document.getElementById(idSelect);
    if(elemSelect != null) {
      for(var i = 0; i < elemSelect.options.length; i++) {
        elemSelect.options[i].selected = true;
      }
    }
    else {
      alert('Select element is NULL. [DEVELOPER error]');
    }
  }
  
  /**
   * Either display or hide this row.
   * @param idElem The id of the element
   * @param doShow True if the element must be shown, false otherwise.
   */
  function showTableRow(idElem,doShow) {
    var elemRow = null;
    
    elemRow = document.getElementById(idElem);
    if(elemRow != null) {
      if(doShow) {
        if(window.ActiveXObject) {
          elemRow.style.display = 'block';
        }
        else {
          elemRow.style.display = 'table-row';
        }
      }
      else {
        elemRow.style.display = 'none';
      }
    }
    else {
      alert('Failed finding row element [DEVELOPER]');
    }
  }
  
  function showDivElement(idElem,doShow) {
    var elem = null;
    
    elem = document.getElementById(idElem);
    if(elem != null) {
      if(doShow) {
        elem.style.display = 'block';
      }
      else {
        elem.style.display = 'none';
      }
    }
    else {
      alert('Failed finding div element [DEVELOPER]');
    }  
  }
  
  function showItemsForMenu(idMenu) {
    var elem;
    
    elem = document.getElementById(idMenu);
    if(elem != null) {
      currStyle = elem.style.display;
      if(currStyle != null)
        currStyle = currStyle.toLowerCase();
      else
        currStyle = 'none';
      if(currStyle == 'none') {
        elem.style.display = 'block';
      }
      else {
        elem.style.display = 'none';
      }    
    }
    else {
      alert('Failed finding div element [DEVELOPER]');
    }
  }

  function copyToHiddenValue(idOfSpan,val) {
    document.getElementById(idOfSpan).value = val;
  }
  
  function getHiddenValue(idOfSpan) {
    return document.getElementById(idOfSpan).value;
  }  
  
  /**
   * 
   */
  function doSubmitLogin() {
    document.getElementById('j_username_new').value = document.getElementById('j_username').value;
    document.getElementById('j_password_new').value = document.getElementById('j_password').value;
    document.getElementById('verificationCode_new').value = document.getElementById('verificationCode').value;
    document.getElementById('id_form').submit();
  }
  
  /**
   * Opens the menu for given id (of the main menu). If not found
   * simply does not open the menu.
   */
  function openMenuIfNeeded(value) {
    if(value != null && value.length > 0) {
      var elem = document.getElementById(value);
          
      if(elem != null) {
        elem.style.display = 'block';
      }
    }
  }
