// JavaScript Document

function TextboxObject()
{
	var table = document.createElement('table');
	table.className = 'textbox';
	var tbody = document.createElement('tbody');
	table.appendChild(tbody);
	
	var topRow = document.createElement('tr');
	topRow.className = 'top';
	tbody.appendChild(topRow);
	
	var topLeft = document.createElement('td');
	topLeft.className = 'top_left';
	topRow.appendChild(topLeft);
	var topMiddle = document.createElement('td');
	topMiddle.className = 'top_middle';
	topRow.appendChild(topMiddle);
	var topRight = document.createElement('td');
	topRight.className = 'top_right';
	topRow.appendChild(topRight);
	
	var middleRow = document.createElement('tr');
	middleRow.className = 'middle';
	tbody.appendChild(middleRow);
	
	var middleLeft = document.createElement('td');
	middleLeft.className = 'middle_left';
	middleRow.appendChild(middleLeft);
	
	var middleMiddle = document.createElement('td');
	middleMiddle.className = 'middle_middle';
	middleRow.appendChild(middleMiddle);
	
	var replacement = document.createElement('div');
	replacement.className = 'replacement';
	middleMiddle.appendChild(replacement);
	
	var middleRight = document.createElement('td');
	middleRight.className = 'middle_right';
	middleRow.appendChild(middleRight);
	
	var bottomRow = document.createElement('tr');
	bottomRow.className = 'bottom';
	tbody.appendChild(bottomRow);
	
	var bottomLeft = document.createElement('td');
	bottomLeft.className = 'bottom_left';
	bottomRow.appendChild(bottomLeft);
	var bottomMiddle = document.createElement('td');
	bottomMiddle.className = 'bottom_middle';
	bottomRow.appendChild(bottomMiddle);
	var bottomRight = document.createElement('td');
	bottomRight.className = 'bottom_right';
	bottomRow.appendChild(bottomRight);
	
	this.replace = function(div)
	{
		removeChildren(middleMiddle);
		
		var classes = div.className.split(' ');
		div.className = 'replacement';
		for(var i = 0; i < classes.length; ++i)
		{
			if(classes[i] != 'textbox')
			{
				if(classes[i] == 'auto_width')
				{
					table.className += ' '+classes[i];
				}
				else
				{
					div.className += ' '+classes[i];
				}
			}
		}
		
		// remove div from document
		div.parentNode.replaceChild(table, div);
		// place div inside table
		middleMiddle.appendChild(div);
	};
	
	this.appendChild = function(element)
	{
		middleMiddle.firstChild.appendChild(element);
	};
	
	this.appendTo = function(parent)
	{
		parent.appendChild(table);
	};
}