function Checkbox(name, value, checked, id)
{
	this.button = null;
	this.button_flag = false;
	if (arguments.length > 1)
	{
		this.initializedComponent();
		this.button.className = 'hidden_component';
		this.button.name = name;
		this.button.value = value;
		this.button.id = id;
		this.checked = checked;
		this.button.defaultChecked = checked;
	}
	if (arguments[0])
	{
		this.button = arguments[0];
		this.button.className = 'hidden_component';
		this.checked = this.button.checked;
		this.disabled = this.button.disabled;
		this.button_flag = true;
	}
	if (arguments.length)
	{
		this.custom_button = document.createElement('a');
		this.custom_button.href = "javascript:"
		this.custom_button.par_button = this.button;
		this.custom_button.className = 'checkbox' + (this.checked ? ' ch_checked' : '') + (this.disabled  ? ' ch_disabled' : '');

		this.custom_button.onclick = function(){this.par_button.click();};
		
		this.button.custom_button = this.custom_button;
		this.changeCheckedListener();
	}
}

Checkbox.prototype.changeCheckedListener = function () {
    this.button.onclick = function () {
        this.custom_button.className = 'checkbox' + (this.checked ? ' ch_checked' : '');
    }
}

Checkbox.prototype.writeComponent = function(id_element)
{
	var obj = document.getElementById(id_element) || id_element;
	if (!this.button_flag) obj.appendChild(this.button);
	obj.insertBefore(this.custom_button, this.button);
}

Checkbox.prototype.initializedComponent = function()
{
	this.button = document.createElement('input');
	this.button.type = 'checkbox';
}

function parseFormElements()
{
	var	obj = document.getElementsByTagName('input');
	for (var i = 0, len = obj.length; i < len; i++)
	{
		if (obj[i].type.toLowerCase() == 'checkbox')
		{
			new Checkbox(obj[i]).writeComponent(obj[i].parentNode);
		}
	}
}

$(window).load(parseFormElements);


