function Checkbox( sName )
{
	this.init( sName );
};

Checkbox.prototype.init = function( sName )
{
	this._checkboxName = sName;
	this._checkboxFieldset = document.getElementById( this._checkboxName );
	this._checkboxInput = this._checkboxFieldset.getElementsByTagName( "input" );
	this._checkboxHeight = "20px";
	
	for ( var i = 0 ; i < this._checkboxInput.length; i++ )
	{		
		this._checkboxInput[ i ]._checkboxImage = document.getElementById( "button_" + this._checkboxInput[ i ].id );

		if ( typeof this._checkboxInput[ i ]._checkboxImage != "undefined" && this._checkboxInput[ i ].type == "checkbox" )
		{
			this._checkboxInput[ i ]._checkboxImage._checkboxParent = this;
			this._checkboxInput[ i ]._checkboxImage._checkboxIndex = i;
			//this._checkboxInput[ i ]._checkboxImage.onmouseover = this.__onmouseover;
			this._checkboxInput[ i ]._checkboxImage.onmouseout = this.__onmouseout;
			this._checkboxInput[ i ]._checkboxImage.onclick = this.__onclickImage;
			
			this._checkboxInput[ i ]._checkboxParent = this;
			this._checkboxInput[ i ]._checkboxIndex = i;
			this._checkboxInput[ i ].onclick = this.__onclick;
			this._checkboxInput[ i ].onchange = this.__onchange;
			this._checkboxInput[ i ].onblur = this.__onblur;
			
			if ( this._checkboxInput[ i ].checked )
				this.select( i );
		}
	}
};

Checkbox.prototype.select = function( nIndex )
{
	this._checkboxInput[ nIndex ]._checkboxImage.style.backgroundPosition = "0px -" + (2*parseInt(this._checkboxHeight)) + "px";
};

Checkbox.prototype.deselect = function( nIndex )
{
	this._checkboxInput[ nIndex ]._checkboxImage.style.backgroundPosition = "0px 0px";
};

Checkbox.prototype.onmouseover = function( nIndex )
{
	this.select( nIndex );
};

Checkbox.prototype.onmouseout = function( nIndex )
{
	if ( !this._checkboxInput[ nIndex ].checked )
		this.deselect( nIndex );
};
	
Checkbox.prototype.onclick = function( nIndex )
{
	if ( this._checkboxInput[ nIndex ].checked )
		this.select( nIndex );
	else
		this.deselect( nIndex );
	
	this._checkboxInput[ nIndex ].focus();
};
	
Checkbox.prototype.onchange = function( nIndex )
{
	if ( this._checkboxInput[ nIndex ].checked )
		this.select( nIndex );
	else
		this.deselect( nIndex );
	
	this._checkboxInput[ nIndex ].focus();
};
	
Checkbox.prototype.onblur = function( nIndex )
{
	if ( this._checkboxInput[ nIndex ].checked )
		this.select( nIndex );
	else
		this.deselect( nIndex );
};

Checkbox.prototype.__onmouseover = function()
{
	this._checkboxParent.onmouseover( this._checkboxIndex );
};

Checkbox.prototype.__onmouseout = function()
{
	this._checkboxParent.onmouseout( this._checkboxIndex );
}

Checkbox.prototype.__onclickImage = function()
{
	// only handle event in IE, hence the input event will not be triggered
	if ( window.ActiveXObject )
	{
		this._checkboxParent._checkboxInput[ this._checkboxIndex ].checked = !this._checkboxParent._checkboxInput[ this._checkboxIndex ].checked;
		this._checkboxParent.onclick( this._checkboxIndex );
	}
};

Checkbox.prototype.__onclick = function()
{
	this._checkboxParent.onclick( this._checkboxIndex );
};

Checkbox.prototype.__onchange = function()
{
	this._checkboxParent.onchange( this._checkboxIndex );
};

Checkbox.prototype.__onblur = function()
{
	this._checkboxParent.onblur( this._checkboxIndex );
}; 
