var CheckboxField = function ()
{
	this.dom_label = createElement ('div', 'label');
	this.dom_root = createElement ('div', 'CheckboxField');
	this.dom_input = createElement ('input'); // not used - but kept as form checks for this fhen submitting data
	this.dom_image = createElement('img', 'checkbox');
	this.dom_description = createElement ('div', 'description');
	this.value;
	
	this.checkbox_false_src = "/res/javascript/library/checkbox_false.gif";
	this.checkbox_true_src = "/res/javascript/library/checkbox_true.gif";
	
	this.VALUE_TRUE = 1;
	this.VALUE_FALSE = 0;
	
	// If this is set to true, then the field's label will be clickable as well as the checkbox itself.
	// If it is false, then the label will not be clickable.
	this._clickableLabel = true;
	
	this.getClickableLabel = function()
	{
		return this._clickableLabel;
	}	
	
  this.setError = function(message)
	{
    ref.dom_input.className = 'error';
	}
	
  this.setClickableLabel = function(clickableLabel)
	{
		this._clickableLabel = clickableLabel;
	}
	
	this.hook_change = function(value)
	{
		// This function is required, even though it is empty. Do not remove it.
	}
	var ref = this;
	this.draw = function ()
	{
		if(this.getHidden())
		{
			return createElement('div', 'hiddenControl');
		}

		this.dom_label.innerHTML = this.label;

		if(this.value == 0)
		{
			this.dom_image.src = this.checkbox_false_src;
		}
		else
		{
			this.dom_image.src = this.checkbox_true_src;
		}
		
		this.dom_image.onclick = function ()
		{
			if (ref.value == 0)
			{
				ref.setValue(1);
			}
			else
			{
				ref.setValue(0);
			}
			ref.hook_change(ref.value);
			return false;
		}
		
		if(this.getClickableLabel())
		{
			this.dom_label.onclick = this.dom_image.onclick;
		}

		removeAllChildren(this.dom_description);
		if (this.description)
		{
			this.dom_description.appendChild (document.createTextNode (this.description));
		}
		this.dom_root.appendChild (this.dom_label);
		this.dom_root.appendChild (this.dom_image);
		this.dom_root.appendChild (this.dom_description);
		
		return this.dom_root;
	}
	
	this.getValue = function ()
	{
		return this.value;
	}
	
	this.setValue = function (value)
	{
		this.value = value;
		if (value != 0)
		{
			this.dom_image.src = this.checkbox_true_src;
		}
		else
		{
			this.dom_image.src = this.checkbox_false_src;
		}
	}
}

CheckboxField.prototype = new FormField ();
