//class BooleanCheckbox
BooleanCheckbox = function ()
{
	this.element = null;
	this.text = null;
	this.value = null;
	this.trueText = "";
	this.falseText = "";
}

BooleanCheckbox.prototype = new Control();

BooleanCheckbox.prototype.getDocumentElement = function ()
{
	return this.element;
}

BooleanCheckbox.prototype.setDocumentElement = function (newElement)
{
	this.element = newElement;
}

BooleanCheckbox.prototype.getText = function ()
{
	return this.text;
}

BooleanCheckbox.prototype.setText = function (newText)
{
	this.text = newText;
}

BooleanCheckbox.prototype.getValue = function ()
{
	return this.value;
}

BooleanCheckbox.prototype.setValue = function (newValue)
{
	this.value = newValue;
}

BooleanCheckbox.prototype.select = function ()
{
	var input = document.getElementById(this.element.id + "_value");
	input.focus();
	try
	{
		input.select();
	}
	catch (ex) { }
}

BooleanCheckbox.prototype.deselect = function ()
{
	var input = document.getElementById(this.element.id + "_value");
	input.blur();
}

BooleanCheckbox.prototype.setView = function ()
{
	var input = document.getElementById(this.element.id + "_value");
	input.checked = this.value == "1"; // was input.checked = this.value == "1"; Apparently, checked was changed between here and showing checkbox	
}

BooleanCheckbox.prototype.setModel = function ()
{
	var input = document.getElementById(this.element.id + "_value");
	this.value = (input.checked)? "1" : "0";
	this.text = (input.checked)? this.trueText : this.falseText;
}

BooleanCheckbox.prototype.getTrueText = function ()
{
	return this.trueText;
}

BooleanCheckbox.prototype.setTrueText = function (newText)
{
	this.trueText = newText;
}

BooleanCheckbox.prototype.getFalseText = function ()
{
	return this.falseText;
}

BooleanCheckbox.prototype.setFalseText = function (newText)
{
	this.falseText = newText;
}

//static variables and methods
BooleanCheckbox.existent = new Array();

BooleanCheckbox.create = function (checkboxId, editable)
{
	BooleanCheckbox.existent[checkboxId] = new BooleanCheckbox();
	BooleanCheckbox.existent[checkboxId].setDocumentElement(
		document.getElementById(checkboxId));
	BooleanCheckbox.existent[checkboxId].setEditable(editable);
	Control.register(checkboxId, BooleanCheckbox.existent[checkboxId]);
	return BooleanCheckbox.existent[checkboxId];
}

BooleanCheckbox.get = function (checkboxId)
{
	return BooleanCheckbox.existent[checkboxId];
}

BooleanCheckbox.changeListener = function (e)
{
	var evt = W3C.getEvent(e);
	var target = W3C.Event.getTarget(evt);
	
	var cboxId = target.id.substring(0, target.id.lastIndexOf("_"));
	var cbox = BooleanCheckbox.get(cboxId);
	cbox.setValue(target.checked);
}

