function removeChildNodes(ctrl){  while (ctrl.childNodes[0])  {    ctrl.removeChild(ctrl.childNodes[0]);  }}

function TextToCheckBox(txtFeldID, AreaID)
{
	oID = document.getElementById( txtFeldID );
	oArea = document.getElementById( AreaID );
	
	tmp = oID.value.split(",");
	arTNZ = new Array();
	for(i=0;i<tmp.length;i++)		arTNZ[ tmp[i] ] = true; 
		
	oChkBoxes = oArea.getElementsByTagName("input");

	iChkBox = 0;
	for(i = 0; i < oChkBoxes.length; i = i + 1 )
	{
		ChildObj = oChkBoxes[i];
		if( ChildObj.type == 'checkbox' )
		{
			iChkBox++;
			
			if( arTNZ[iChkBox] )
				ChildObj.checked = true;
			else
				ChildObj.checked = false;
		}
	}
}

function CheckBoxToText(txtFeldID, AreaID)
{
	oID = document.getElementById( txtFeldID );
	if(!oID)
		alert("TextFeld (id) not available:" + txtFeldID );
	oArea = document.getElementById( AreaID );
	if(!oArea)
		alert("Area (id) not available:" + AreaID );
	
	oChkBoxes = oArea.getElementsByTagName("input");
	sAll = '';
	iChkBox = 0;
	for( i = 0; i < oChkBoxes.length; i = i + 1 )
	{
		ChildObj = oChkBoxes[i];
		if( ChildObj.type == 'checkbox' )
		{
			iChkBox++;
			if( ChildObj.checked == true )
			{
				if( sAll != '' )	sAll += ',';
				sAll += "" + iChkBox;
			}
		}
	}
	oID.value = sAll;
}

function hssTNZ()
{
	this.sAreaID = "";
	this.sTextFeldID = false;

	this.objTbl = false;
	this.Cell_w = "";
	this.Cell_h = "";
	this.Cell_al = "";
	this.Cell_val = "";
	this.Cell_cn = "";
	this.Cell_col = "";
    this.Cell_backcol = "";

    this.useClasses = false;
	
	
	if(navigator.appName == "Microsoft Internet Explorer")
		this.isIE = true;
	else
		this.isIE = false;
	
	this.AddRow = function()
	{
		if( this.isIE == true )
			tr = this.objTbl.insertRow( this.objTbl.rows.length );
		else
		{
			tr = document.createElement("tr"); 
			this.objTbl.appendChild(tr);
		}
		return tr;
	}
	this.AddCell = function(tr, className)
	{
		td = document.createElement('td');
		tr.appendChild( td );

        if (this.useClasses)
        {
            td.className = className;
        }
        else
        {
		    if( this.Cell_w != "" )	td.width = this.Cell_w;
		    if( this.Cell_h != "" )	td.height = this.Cell_h;
		    if( this.Cell_al != "" )	td.align = this.Cell_al;
		    if( this.Cell_val != "" )	td.valign = this.Cell_val;
		    if( this.Cell_cn != "" )	td.className = this.Cell_cn;
		    if( this.Cell_col != "" )	td.style.color = this.Cell_col;
		    if( this.Cell_backcol != "" )	td.style.backgroundColor = this.Cell_backcol;
        }
		return td;
	}
	
	this.SetDefaultCell = function(w,h,al,val,cn,col,backcol)
	{
		this.Cell_w = w;
		this.Cell_h = h;
		this.Cell_al = al;
		this.Cell_val = val;
		this.Cell_cn = cn;
		this.Cell_col = col;
		this.Cell_backcol = backcol;
	}

	this.CreateItems = function( c )
	{
		oArea = document.getElementById(this.sAreaID);
		removeChildNodes(oArea);
		this.objTbl = document.createElement("table");
        oArea.appendChild( this.objTbl );

        if (this.useClasses)
        {
            this.objTbl.className = 'teilnehmerzuordnung_table';
        }
		
		
		tr = this.AddRow();
		for( i = 1; i <= c; ++i )
		{
			td = this.AddCell(tr, 'teilnehmerzuordnung_td_label');
			td.appendChild( document.createTextNode( i ) );
		}
		
		tr = this.AddRow();
		for( i = 1; i <= c; ++i )
		{
			td = this.AddCell(tr, 'teilnehmerzuordnung_td_checkbox');
			
			aCheckBox = document.createElement('INPUT');
			aCheckBox.type = "checkbox";
			aCheckBox.id = "T" + i;
			aCheckBox.name = "T" + i;
			aCheckBox.value = "1";
			
			if( this.sTextFeldID != false)
				aCheckBox.onclick = new Function("CheckBoxToText('" + this.sTextFeldID + "','" + this.sAreaID + "')");
			
			td.appendChild( aCheckBox );
        }

        TextToCheckBox(this.sTextFeldID, this.sAreaID);
        CheckBoxToText(this.sTextFeldID, this.sAreaID);
	}
	
	this.Create = function( sAreaID, sTextFeldID, c )
	{
		this.sTextFeldID = sTextFeldID;
		this.sAreaID = sAreaID;
		this.CreateItems( c );
	}
}

