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

comboBoxControl_Update = function(jsonParameters)
{
	var P = parseParameters(jsonParameters);
	//alert(JSON.stringify(P));
	var c = getControl(P.fullControlName);
	comboBoxControl_updateAttributes(c, P);
};

comboBoxControl_setup = function(cell)
{
	addControlEvent(cell, "change", function(event) { comboBoxControl_onChange(cell, event); });
	addControlEvent(cell, "click", function(event) { comboBoxControl_onClick(cell, event); });
};

comboBoxControl_updateAttributes = function(cell, P)
{
	// alert("comboBoxControl_updateAttributes\r\n" + JSON.stringify(P));

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

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

	var opts = P.options;
	if (typeof opts != "undefined")
	{
		cell.innerHTML = "";  // remove exiting options
		for (var i = 0; i < opts.length; i++)
		{
			var htmlOpt = xmlCreateElement(cell, "option");
			htmlOpt.value = opts[i];
			htmlOpt.innerText = opts[i];
		}
	}
	
	cell.value = P.text;
};

comboBoxControl_onChange = function(cell, event)
{
	raiseControlEvent({ msg: "onChange", control: cell.id, text: cell.value });
};

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