﻿function SetUniqueRadioButton(nameregex, current, checkedColor)
{
	re = new RegExp(nameregex);
	
	for (formIndex = 0; formIndex < document.forms.length; formIndex ++)
	{
		for (elementIndex = 0; elementIndex < document.forms[formIndex].elements.length; elementIndex++)
		{
			elm = document.forms[formIndex].elements[elementIndex]
			if (elm.type == 'radio')
			{
				if (re.test(elm.name))
					SetChecked(elm, false);
			}
		}
	}
	
	SetChecked(current, true, checkedColor);
}

function SetChecked(element, checked, checkedColor)
{
	element.checked = checked;
	
	var labelElement = element.nextSibling;
	if (labelElement != null)
	{
		var showCheckedColor = (checked && (checkedColor != null));
		var color = showCheckedColor ? checkedColor : '';
		SetColor(labelElement, color);
	}
}

function SetColor(element, color)
{
	element.style.color = color;
	for (childIndex = 0; childIndex < element.childNodes.length; childIndex ++)
	{
		var childElement = element.childNodes[childIndex];
		if ((childElement.tagName == 'SPAN') && (childElement.style != null))
			SetColor(childElement, color);
	}	
}

