// TILT (Table Injection for Layout Technique), by Dimitri Glazkov
// Source: http://dimitrisplace.com/archive/2005/05/02/476.aspx

function LayoutTable(columnCount, rowCount, className)
{
	var table = document.createElement("TABLE");
	table.className = "Layout " + (className != null ? className : "");
	var tbody = table.appendChild(document.createElement("TBODY"));
	for(var i = 0; i < rowCount; i++)
	{
		var row = tbody.appendChild(document.createElement("TR"));
		row.className = "r" + (i + 1);
		row.getColumn = function(column)
		{
			return this.cells.length > column && column >= 0 ? this.cells[column] : null;
		}
		for(var j = 0; j < columnCount; j++)
		{
			var cell = row.appendChild(document.createElement("TD"));
			cell.className = "c" + (j + 1);
		}
	}
	this.node = table;
	
	this.getCell = function(column, row)
	{
		return table.rows.length >= row && row > 0 ? table.rows[row - 1].getColumn(column - 1) : null;
	}
	
	this.appendChild = function(column, row, node)
	{
		var cell = this.getCell(column, row);
		return cell != null ? cell.appendChild(node) : null;
	}
	
}

function ClassNameBag(node)
{
	var child = node.firstChild;
	while(child)
	{
		if (child.nodeType == 1 && child.className && child.className.length > 0)
		{
			this[child.className] = child;				
		}
		child = child.nextSibling;
	}
}

