﻿function PhTable( rows, cols, cell_padding, cell_spacing )
{
	this.m_iRows	= rows;
	this.m_iCols	= cols;
	this.m_iPadding	= cell_padding;
	this.m_iSpacing	= cell_spacing;
	
	this.m_oBody	= null;
	
	this.Table	= null;
	this.Cells	= null;
	
	this.InitObject();
}

PhTable.prototype.InitObject = function()
{
	this.Table	= document.createElement( 'table' );
	this.Cells	= new Array( this.m_iRows );

	var tbody	= document.createElement( 'tbody' );
	var tr		= null;
	var td		= null;
	
	var i		= 0;
	var j		= 0;
	
	this.Table.style.width	= '100%';
	//this.Table.style.height	= '100%';
	this.Table.cellPadding	= ''+this.m_iPadding;
	this.Table.cellSpacing	= ''+this.m_iSpacing;
	this.Table.border		= '0';
	
	for( i = 0; i < this.m_iRows; i++ )
	{
		this.Cells[i] = new Array( this.m_iCols )
		tr = document.createElement( 'tr' );
		
		for( j = 0; j < this.m_iCols; j++ )
		{
			this.Cells[i][j] = document.createElement( 'td' );
			tr.appendChild( this.Cells[i][j] );	
		}
		
		tbody.appendChild( tr );
	}
	
	this.m_oBody = tbody;
	this.Table.appendChild( tbody );
}

PhTable.prototype.AddRow = function()
{
	var i	= 0;
	var tr	= document.createElement( 'tr' );
	var td	= null;

	this.Cells[this.m_iRows] = new Array( this.m_iCols );
	
	for( i = 0; i < this.m_iCols; i++ )
	{
		this.Cells[this.m_iRows][i] = document.createElement( 'td' );
		tr.appendChild( this.Cells[this.m_iRows][i] );
	}
	
	this.m_oBody.appendChild( tr );
	return this.m_iRows++;
}