/*
 * Constrcutor for RadioElements object.  It initialize and internal unbound
 * array structure and defines prototype defintions of callable methods.  This
 * object will represent all of the radio button groups for a specified form
 * or some other type of logical structure.
 */
function RadioElements()
{
	// Object attributes
	this.objRadioBtns = Array();

	// Method declarations
	this.addRadioButton = RadioElements_addRadioButton;
	this.checkList = RadioElements_checkList;
	this.checkSet = RadioElements_checkSet;
	this.getLength = RadioElements_getLength;
	this.markSet = RadioElements_markSet;
}

/*
 * Takes the passed in instance name and then checks the current list.  If it
 * is not in the list, the name is appended to the current list.  Note:  the
 * name represents a radio button group on some form.
 */
function RadioElements_addRadioButton(strRadioBtnName)
{
	// Create a new radio button object
	var rb = new RadioElement(strRadioBtnName);

	// Add to list if currently not there
	if (this.checkList(strRadioBtnName) < 0)
	{
		// Now add to list
		this.objRadioBtns[this.objRadioBtns.length] = rb;
	}
}

/*
 * Mainly used internally by RadioElements_addRadioButton but can be used
 * externally.  This method takes the passed in widget instance name of the
 * radio button group and checks the current list and returns true if it
 * has been found, otherwises returns false.
 */
function RadioElements_checkList(strRadioBtnName)
{
	var intInList = -1;	//	Assume it is not in the list
	var i; // Counter

	// Loop through list until match is found or at end of list.
	for(i = 0; i < this.objRadioBtns.length; i++)
	{
		// Does this radio button, in the list, match the passed in name?
		if (this.objRadioBtns[i].getName() == strRadioBtnName)
		{
			// Match found, mark it found and break out of loop
			intInList = i;
			i = this.objRadioBtns.length;
		}
	}

	// Return the final result
	return (intInList);
}

/*
 * Returns a list of radio button groups that does not have any value selected.
 */
function RadioElements_checkSet()
{
	var strBadSetList = ""; // Uncheck radio buttons
	var i; // Counter

	// Go though the list and return a list of unchecked radio buttons
	for (i = 0; i < this.objRadioBtns.length; i++)
	{
		// Add to checked list if current radio button set has nothing cheecked.
		if (this.objRadioBtns[i].getIsSet() == false)
			strBadSetList += "\n          " + this.objRadioBtns[i].getName();
	}

	return (strBadSetList);
}

/*
 * Returns the number of radio group elements in the current list.
 */
function RadioElements_getLength()
{
	return (this.objRadioBtns.length);
}

/*
 * Flag the specified radio button group as set/unset and the value of the
 * selected radio button in the group.  This is based off of the passed in
 * string name of the radio group and the value of the radio button selected
 * within the radio button group.
 */
function RadioElements_markSet(strRadioBtnName, strRadioBtnValue)
{
	// First off check to see if name is in the list
	var intPos = this.checkList(strRadioBtnName);

	// Is it in the list
	if (intPos >= 0)
	{
		// Yes, it is in the system so mark it set and get the value also
		this.objRadioBtns[intPos].setIsSet(true);
		this.objRadioBtns[intPos].setValue(strRadioBtnValue);
	}
}