function ds_expand_all(expand)
{
  $$('table.ds-table tbody').each( function(e) {
    (expand || expand===undefined) ? e.removeClassName('rolled-up') : e.addClassName('rolled-up');
  } );
  return false;
}

function ds_toggle(section_id)
{
  var section = $(section_id);
  $w(section.className).include('rolled-up') ? section.removeClassName('rolled-up') : section.addClassName('rolled-up');
  return false;
}

// This is called by an "auto_options" <SELECT> element (i.e. what is effectively a "combo box"),
// to show or hide the "other option" input text box as required.
function ds_select_change(select)
{
  // Get the index of the selected item.
  var index = select.selectedIndex;

  // Generate the ID that belongs to our associated "other" input text box.
  var other_id = select.name.replace(/\[existing\]$/i, '[other]');

  // Try to find the "other" text box;
  var other = $(other_id);

  if (-1==index || !$w(select[index].className).include('ds-other'))
  {
    // "other:" is not selected; hide "other" input text box.
    other.hide();
    // Make sure the "other" input text box doesn't get used by the form.
    other.name = 'dummy';
  }
  else
  {
    // "other:" IS selected; show the "other" input text box.
    other.show();
    // Enable submission of the "other" input text box.
    other.name = other_id;
  }
  return true;
}

function ds_project_link_change(e)
{
  var ev = window.event || e;
  if (!ev.target)
  {
    ev.target = ev.srcElement;
  }
  $(ev.target.id + '-link').href = '/projects/' + ev.target.value + '/issues';
  return true;
}

