
function focusBranch(event)
{
  var clickedElement = Event.element(event);

  operateOnThis = Element.down( $(Event.element(event)).up('.caseselector-float-left').next(), 'select', 0);

  if (clickedElement.value == 0)
  {
    operateOnThis.selectedIndex = 0;
    clickedElement.focus();
    return;
  }

  operateOnThis.focus();
  return;

}

// predefined variables can be found in MultipleSDelectsHelper
function addCombination(event)
{
  // if the user entered more than maxAllowedDisciplines deny the right to add more
  if ( start+1 >= maxAllowedDisciplines)
  {
    alert(alertMaxSelectionsReached);
    return false;
  }

  if ( $('discipline_0').selectedIndex == 0 )
  {
    alert(alertSelectDiscipline);
    $('discipline_0').focus();
    return false;
  }
  if ( $('branch_0').selectedIndex == 0 )
  {
    alert(alertSelectBranch);
    $('branch_0').focus();
    return false;
  }

  ++start;

  var myTemplate = new Template('<div id="selection' + start + '">#{disciplineName} - #{branchName} <input type="hidden" name="discipline[' + start + ']" value="#{disciplineValue}" /><input type="hidden" name="branch[' + start + ']" value="#{branchValue}" /> &nbsp; &nbsp; <a href="#" onclick="removeSelection(event);"><img src="/backend/img/plesk/remove-selected-bkg.gif" /></a></div>');
  var show = {
    disciplineName:   $('discipline_0').options[$('discipline_0').selectedIndex].innerHTML,
    branchName:       $('branch_0').options[$('branch_0').selectedIndex].innerHTML,
    disciplineValue:  $F('discipline_0'),
    branchValue:      $F('branch_0')
  };

  var y = new Insertion.Bottom( $('selCombinationContainer'), myTemplate.evaluate(show) );
  if ('object' == typeof y)
  {
    $('discipline_0').selectedIndex = 0;
    $('branch_0').selectedIndex = 0;
  }

  return false;
}

function removeSelection(event)
{
  var divToRemove = Event.findElement(event, 'DIV');
  divToRemove.parentNode.removeChild(divToRemove);

  --start;

  return false;
}

