/* ===================================================================================================
 * radioButtonControl
 * ===================================================================================================
 */
 
/// jsonParameters
/// { fullControlName: <string>,
///   text: <string>,
///   visible: "0" | "1"
///   enabled: "0" | "1"
///   tabstop: "0" | "1"
///   description: <columnDescriptor>
/// }
radioButtonControl_Initialize = function(jsonParameters)
{
	var P = parseParameters(jsonParameters);
	//alert(JSON.stringify(P));
	var c = getControl(P.fullControlName);
	c.description = P.description;
	radioButtonControl_setup(c, P.text);
	radioButtonControl_updateAttributes(c, P);
};

radioButtonControl_Update = function(jsonParameters)
{
	var P = parseParameters(jsonParameters);
	//alert(JSON.stringify(P));
	var c = getControl(P.fullControlName);
	//checkboxControl_setText(c, P.text);
	radioButtonControl_updateAttributes(c, P);
};

radioButtonControl_updateAttributes = function(cell, jsonParameters)
{
	var P = parseParameters(jsonParameters);
	//alert(JSON.stringify(P));
	var chk = document.getElementById(cell.id + "$check");
	var txt = document.getElementById(cell.id + "$text");

	if (typeof P.visible != "undefined")
	{
		cell.style.visibility = parseIntEx(P.visible) ? "inherit" : "hidden";
	}

	if (typeof P.enabled != "undefined")
	{
		if (parseIntEx(P.enabled))
		{
			chk.disabled = false;
			txt.removeAttribute("disabled");
		}
		else
		{
			chk.disabled = true;
			txt.setAttribute("disabled", "true");
		}
	}

	if (typeof P.checked != "undefined")
	{
		chk.checked = parseIntEx(P.checked) != 0;
	}
};

radioButtonControl_setup = function(cell, txt)
{
	//cell.setAttribute("type", "checkbox");
	//addControlEvent(cell, "click", function(event) { checkboxControl_onClick(cell, event); });

	var checker = xmlCreateElement(cell, "input", cell.id + "$check");
	checker.setAttribute("type", "radio");
	addControlEvent(checker, "change", function(event) { radioButtonControl_onClick(cell, event); });

	xmlCreateElement(cell, "span", cell.id + "$space").innerHTML = "&nbsp;&nbsp;";
	xmlCreateElement(cell, "span", cell.id + "$text");

	if ((typeof cell.description.textAtLeft != "undefined") && (parseIntEx(cell.description.textAtLeft)))
	{
		cell.style.justifyContent = "space-between";
		cell.style.flexDirection = "row-reverse";
	}
	radioButtonControl_setText(cell, txt);
};

radioButtonControl_setText = function(cell, txt)
{
	var label = document.getElementById(cell.id + "$text");
	label.innerText = txt;
	cell.title = txt;
};

radioButtonControl_onClick = function(cell, event)
{
	raiseControlEvent({ msg: "onClick", control: cell.id });
};

