/**
 * @class This static class implements manipulation of <input type="radio"> html elements
 * @author erik 2/15/2009
 * @uses lib/Sureflix/Sureflix.js
 * @uses lib/Prototype/Prototype.js
 * @uses lib/Sureflix/Utilities/Utils.js
 * @using Sureflix.Error
 * @using Sureflix.Error.ErrorHandler
 */

Sureflix.UI.Form = {};


/**
* Return the value of the current selected radio in a radio button group
* @param {string} radioGroupName name of radio gropu
* @param {boolean} defaultToFirst If true, the first radio button's value is returned if none are selected
* @returns {String} value
*/
Sureflix.UI.Form.getRadioValue = function(radioGroupName, defaultToFirst) {
	var form = document.forms[0];
	var value = null;
	var radioGroup = form.elements[radioGroupName];
	for (i = 0; i < radioGroup.length; i++) {
		if (defaultToFirst && value == null) value = radioGroup[i].value;
		if (radioGroup[i].checked) {
			value = radioGroup[i].value;
			break;
		}
	}
	return value;
}


/**
* Set the the currently selected radio in a radio button group
* @param {string} radioGroupName name of radio gropu
* @param {string} newValue Value of desired radio
*/
Sureflix.UI.Form.setRadioValue = function(radioGroupName, value) {
	var form = document.forms[0];
	var radioGroup = form.elements[radioGroupName];
	for (i = 0; i < radioGroup.length; i++) {
		if (radioGroup[i].value == value) {
			radioGroup[i].checked = true;
		} else {
			radioGroup[i].checked = false;
		}
	}
}