﻿


function Table(container)
{
	this.Container = container;
	this.Parent = null;
	if (container.Parent != null)
		this.Parent = container.Parent;
	this.Rows = Rows.Get(container);
	this.Container.Rows = this.Rows;
}

function Tables()
{
}

function Row(container)
{
	this.Container = container;
	this.Parent = null;
	if (container.Parent != null)
		this.Parent = container.Parent;
	this.Cells = Cells.Get(container);
	this.Container.Cells = this.Cells;
}

function Rows()
{

}

function Cell(container)
{
	this.Container = container;
	this.Parent = null;
	if (container.Parent != null)
		this.Parent = container.Parent;
}

function Cells()
{

}

Table.AttachTo = function (index, parent)
{
	/*	var table = parent.getElementsByTagName("table")[index];
	parent.Tables = new Array();
	table.Parent = parent;
	parent.Tables[index] = new Table(table);
	*/
}

Tables.AttachTo = function (parent)
{
	var items = parent.childNodes;
	var tables = new Array();
	for (var i = 0; i < items.length; i++)
		if (items[i].tagName.toLowerCase() == "table")
		{
			items[i].Parent = parent;
			items[i].prototype = new Table(items[i]);
			tables.push(items[i]);
		}
	parent.Tables = tables;
}

Rows.Get = function (table)
{
	var rows = new Array();
	var tableChilds = table.childNodes;

	if (tableChilds[0].tagName.toLowerCase() != "tr")
		tableChilds = table.childNodes[0].childNodes;

	for (var i = 0; i < tableChilds.length; i++)
	{
		tableChilds[i].Parent = table;
		tableChilds[i].prototype = new Row(tableChilds[i]);
		rows.push(tableChilds[i]);
	}
	return rows;
}

Cells.Get = function (row)
{
	var cells = new Array();
	var rowChilds = row.childNodes;

	for (var i = 0; i < rowChilds.length; i++)
	{
		rowChilds[i].Parent = row;
		rowChilds[i].prototype = new Cell(rowChilds[i]);
		cells.push(rowChilds[i]);
	}
	return cells;
}
