/*!
**********************************************************************
@file WizardRadioButtonSet1.js

Copyright 2003-2008 Adobe Systems Incorporated.                     
All Rights Reserved.                                                
                                                                    
NOTICE: All information contained herein is the property of Adobe   
Systems Incorporated.                                                                                                                    

***********************************************************************
*/
/*
WizardRadioButtonSet1 widget for handling multiple WizardRatioButton1 Instances
If WRB1,WRB2,WRB3,WRB4,WRB5 are part of a WRBS1,
Then at any point in time(except Initially), only one of WRBi can be checked
Anytime, a toggle happens, only one of WRBi will be checked, based on click source detection, rest all will be unchecked
This is the javascript working of a html simulation of radio buttons set.

IMPORTANT ::
Initially, When each WRBi is being added to a WRBSet, the WRBi's checked state wont be taken into consideration, i.e.,
multiple WRBi's can be in a checked state. This is exactly how a html radio set would behave. It is upto the html writer
to ensure that only one radio button in a radio set is actually checked.

VIRTUO COMPONENTO ::
This Widget Does Not Have Any UI.
*/

function WizardRadioButtonSet1()
{
	this.array=new Array();
}

WizardRadioButtonSet1.prototype.AddWizardRadioButton = function(inWRB)
{
    this.array.push(inWRB);
	var existingonclickfunction = inWRB.GetClickFunction();
    inWRB.WizardRadioButtonSet=this;
    
    // We update the radio button status after calling any existing even handler since we sometimes rely on the current state of the button in the handler
    inWRB.SetClickFunction(
							function()
							{
								if(existingonclickfunction)
									existingonclickfunction();
								this.parentWizard.WizardRadioButtonSet.updateAllRadioButtons();
							}
						);
}

//toggle for a set of radio buttons means, whatever radiobutton was clicked will be checked, rest all will be unchecked.
//theres no toggle defined for a single radiobutton.
//IMPORANT ::
//toggle for a single checkbox is reverse the checked/unchecked state of itself.
//accordingly, theres a toggleR for WizardRadioButtonSet1 and toggleC for WizardCheckBox1
WizardRadioButtonSet1.prototype.updateAllRadioButtons = function(srcElement)
{
	var e;
	
	// If we are passed an element, this is not an event driven click 
	if(srcElement)
		e = srcElement;
	else
		e = event.srcElement.parentWizard;//event source is the radio image
	
	//Set Unchecked to every radio button
	for (var i in this.array)
	{
		this.array[i].SetRadioState(false);
	}
	
	//Then Check only the event source's (source radio button image, which was clicked) checked value to true
	e.SetSrc(kImgRadioButtonOn);
}