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

checkBoxControl_Update = function(jsonParameters)
{
	var P = parseParameters(jsonParameters);
	//alert(JSON.stringify(P));
	var c = getControl(P.fullControlName);
	//checkBoxControl_setText(c, P.text);
	checkBoxControl_updateAttributes(c, P);
};

checkBoxControl_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;
	}
};

checkBoxControl_setup = function(cell, txt)
{
	var checker = xmlCreateElement(cell, "input", cell.id + "$check");
	checker.setAttribute("type", "checkbox");
	addControlEvent(checker, "change", function(event) { checkBoxControl_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";
	}
	checkBoxControl_setText(cell, txt);
};

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

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

