//RadioButtonGroup.js
//Control structure for radio buttons
//
//Contains an array of radio button objects.  Each radio button in the group
//  has a pointer to the group, and is aware of its index in the array.
//Communication between the group and the buttons is two-directional.  When
//  a button is clicked, it calls the setActive function in the group, with
//  the button's index passed as a parameter.  This information is then used
//  to set the currently active button to its 'inactive' state and to update
//  the active button index in the group.
//The active button is initialized to -1 (an invalid index) since the radio buttons
//  default to an inactive state.
//
//------------------------------------------
//No Dependancies.

RadioButtonGroup = function(newId)
{
  if (arguments.length > 0)
    this.init(newId);
};

RadioButtonGroup.prototype.init = function(newId)
{
  this.buttons = new Array();
  this.activeButton = -1;
  this.id = newId;
  OBJECT_MANAGER.addControl(this,'radioButtonGroup', newId);
};
  
RadioButtonGroup.prototype.setActiveButton = function(buttonIndex)
{
  if (this.activeButton != -1)
  {
    if (this.buttons[this.activeButton].setInactive)
      this.buttons[this.activeButton].setInactive();
    else
      this.buttons[this.activeButton].checked = false;
  }
  this.activeButton = buttonIndex;
  if (buttonIndex != -1)
  {
    if (this.buttons[buttonIndex].setActive)
      this.buttons[buttonIndex].setActive();
    else
      this.buttons[buttonIndex].checked = true;
  }
};

RadioButtonGroup.prototype.getActiveButton = function()
{
  if (this.activeButton != -1)
    return(this.buttons[this.activeButton]);
  else
    return(null);
};

RadioButtonGroup.prototype.addButton = function(button)
{
  this.buttons[this.buttons.length] = button;
  return this.buttons.length-1;
};


