if (!Bs_Objects)
{
	var Bs_Objects = [];
	//alert(Bs_Objects.length);
};

function Bs_Checkbox()
{
	this._id;
	this._tagId;
	this.checkboxName;
	this.checkboxValue; //Added by dubf on 2004/04/19
	this.value = 0;
	this.noPartly = false;
	this.disabled = false;
	this.guiNochange = false;
	this.caption;
	this.imgDir;// = '../image/checkbox/win2k/';
	this.imgWidth;//  = 13;
	this.imgHeight;// = 13;
	this.imgStyle = '';
	this.useMouseover = true;
	this.eventOnClick;
	this.eventOnChange;

	this._constructor = function()
	{
		this._id = Bs_Objects.length;
		//alert(this._id);
		Bs_Objects[this._id] = this;
		this._tagId = "Bs_Checkbox_"+this._id+"_";
	}

	this.render = function(tagId)
	{
		if (this.noPartly && (this.value == 1)) this.value = 2;
		if (!bs_isEmpty(tagId))
		{
			this._tagId = tagId;
		}
		var out  = new Array();
		var outI = 0;
		var img = '';
		 img += (this.disabled) ? 'disabled' : 'enabled';
		 img += '_' + this.value;
		 if (!this.disabled)
		 {
			out[outI++] = '<span';
			if (!this.guiNochange)
			{
				out[outI++] = ' onClick="Bs_Objects['+this._id+'].onClick(\'' + this._tagId + '\');"';
			}

			out[outI++] = ' style="cursor:hand;"';

			if (this.useMouseover && !this.guiNochange)
			{
				out[outI++] = ' onMouseOver="Bs_Objects['+this._id+'].onMouseOver(\'' + this._tagId + '\');"';
				out[outI++] = ' onMouseOut="Bs_Objects['+this._id+'].onMouseOut(\'' + this._tagId + '\');"';
			}
			out[outI++] = '>';
		 }

		if (!this.imgWidth)
		{
			if (this.imgDir.indexOf("win2000")>0)
			{
				this.imgWidth =13;
				this.imgHeight=13;
				//alert(this.imgDir);
			} else
			{
				this.imgWidth =11;
				this.imgHeight=11;
			}			
		}
		 out[outI++] = '<img id="' + this._tagId + 'icon" src="' + this.imgDir + img + '.gif" border="0" width="' + this.imgWidth + '" height="' + this.imgHeight + '"';
		 if (!bs_isEmpty(this.imgStyle))
			 out[outI++] = ' style="' + this.imgStyle + '"';
		 out[outI++] = '>';

		if (this.caption)
		{
			out[outI++] = '&nbsp;' + this.caption;
		}

		if (!this.disabled)
		{
			out[outI++] = '</span>';
		}

		if (!this.checkboxName)
		{
			this.checkboxName = 'checkbox' + this._tagId;
		}

		out[outI++] = '<input value="' + this.value + '" checkboxValue="'+this.checkboxValue+'" type=checkbox name="' + this.checkboxName + '" id="' + this.checkboxName + '" style="display:none; visibility:hidden;"';//Modied by dubf on 2004/4/19
		//alert(this.checkboxValue);
		if (this.value) out[outI++] = ' checked';
		out[outI++] = '>';

		return out.join('');
	}

	this.drawInto = function(tagId)
	{
		if (!bs_isEmpty(tagId))
		{
			this._tagId = tagId;
		}
		document.getElementById(this._tagId).innerHTML = this.render(this._tagId);
	}

	this.draw = function(tagId)
	{
		this.drawInto(tagId);
	}

	this.write = function()
	{
		document.write(this.render(this._tagId));
	}

	this.convertField = function(fieldId)
	{
		document.getElementById(fieldId).outerHTML = this.render(this._tagId);
	}

	this.onMouseOver = function()
	{
		var img = document.getElementById(this._tagId + 'icon');
		if (!img.swapOver0)
		{
			img.swapOver0 = new Image();
			img.swapOver0.src = this.imgDir + 'enabled_0_over.gif';
			img.swapOver1 = new Image();
			img.swapOver1.src = this.imgDir + 'enabled_1_over.gif';
			img.swapOver2 = new Image();
			img.swapOver2.src = this.imgDir + 'enabled_2_over.gif';
			img.swapOut0 = new Image();
			img.swapOut0.src = this.imgDir + 'enabled_0.gif';
			img.swapOut1 = new Image();
			img.swapOut1.src = this.imgDir + 'enabled_1.gif';
			img.swapOut2 = new Image();
			img.swapOut2.src = this.imgDir + 'enabled_2.gif';
		}
		img.src = img['swapOver' + this.value].src;
	}

	this.onMouseOut = function()
	{
		var img = document.getElementById(this._tagId + 'icon');
		img.src = img['swapOut' + this.value].src;
	}

	this.onClick = function()
	{
		//alert(this.value);
		switch (this.value)
		{
			case 0:
			this.value = 2;
			break;
			case 1:
			case 2:
			this.value = 0;
			this.value = 0;
			break;
			default:
			this.value = 0;
		}
		this._updateHiddenField();
		this._updateIcon();
		if (this.eventOnClick)
			this._fireEvent(this.eventOnClick);
		if (this.eventOnChange)
			this._fireEvent(this.eventOnChange);
		//alert(this.value);
	}

	this.setTo = function(value, cancelEventOnChange)
	{
		this.value = value;
		this._updateHiddenField();
		this._updateIcon();
		if (!cancelEventOnChange)
		{
			if (this.eventOnChange) this._fireEvent(this.eventOnChange);
		}
	}

	this.attachOnClick = function(globalFunctionName)
	{
		this.eventOnClick = globalFunctionName;
	}

	this.attachOnChange = function(globalFunctionName)
	{
		this.eventOnChange = globalFunctionName;
	}

	this._fireEvent = function(e)
	{
		if (e)
		{
			if (typeof(e) != 'array')
			{
				e = new Array(e);
			}
			for (var i=0; i<e.length; i++)
			{
				if (typeof(e[i]) == 'function')
				{
					e[i](this);
				} else if (typeof(e[i]) == 'string')
				{
					eval(e[i]);
				}
			}
		}
	}

	this._updateIcon = function()
	{
		var iconElm = document.getElementById(this._tagId + 'icon');
		if (iconElm != null)
		{
			var img = '';
			img += (this.disabled) ? 'disabled' : 'enabled';
			img += '_' + this.value;
			iconElm.src = this.imgDir + img + '.gif';
		}
	}

	this._updateHiddenField = function()
	{
		var elm = document.getElementById(this.checkboxName);
		elm.value = this.value;
		elm.checked = (this.value);
	}

	this._constructor();
}

