var TCheckListBox = function (self,name,at_line,width,height,collapsing)
{
	this.self = self;
	this.name = name;
	this.varkeys = new Array();
	this.selected = new Array();
	this.at_line = at_line || 1;
	this.width = width || 250;
	this.height = height || 91;
	this.collapsing = collapsing || 'none';
}

TCheckListBox.prototype.draw = function (par)
{
	var parent = document.getElementById(par);
	
	var newdiv = document.createElement("div");
	newdiv.className = 'TCheckListBox_maindiv';
	newdiv.innerHTML = '<input type=hidden name="'+this.name+'" value="null"><input type="checkbox" class="TCheckListBox_box" onclick="'+this.self+'.reselect(this.checked);"><LABEL class="TCheckListBox_label">'+choose_all+'</LABEL>';
	if (this.collapsing != 'none') newdiv.innerHTML += '&nbsp;&nbsp;&nbsp;<a href="javascript:invert_display(\''+this.self+'workdiv\');">'+datailed+'</a>';
	var workdiv = document.createElement("div");
	workdiv.className = 'TCheckListBox_workdiv';
	workdiv.id = this.self+'workdiv';
	if (this.collapsing == 'collapse') workdiv.style.display = 'none';
	workdiv.style.width = this.width;
	workdiv.style.height = this.height;
	var out = new Array();
	out.push("<tr>")
	var pps = 0;
	for (var i=0;i<this.varkeys.length;i++)	
	{
		pps++;
		var checked = '';
		if (this.selected != null)
		{
			for (var key in this.selected)
			{
				if (this.selected[key] == this.varkeys[i][0])
				{
					var checked = ' checked ';
					break;
				}
			}
		}
		var txt = '<td nowrap><input type="checkbox" class="TCheckListBox_box" name="'+this.name+'['+i+']" value="'+this.varkeys[i][0]+'" '+checked+'><LABEL class="TCheckListBox_label" for="'+this.name+'['+i+']">'+this.varkeys[i][1]+'</LABEL></td>';
		if (pps >= this.at_line)
		{
			txt += '</tr><tr>';
			pps = 0;
		}
		out.push(txt);
	}
	out.push("</tr>")
	workdiv.innerHTML = '<table border="0" cellpadding="1" cellspacing="0">'+out.join("\n")+'</table>';
	
	newdiv.appendChild(workdiv);
	parent.appendChild(newdiv);
}

TCheckListBox.prototype.reselect = function (bool)
{
	for (var i=0;i<this.varkeys.length;i++)	
	{
		var el = document.getElementById(this.name+'['+i+']');
		el.checked = bool;
	}
}
