/* Copyright (c) 2006 N2N Consulting Pte Ltd. All rights reserved. */

/**
* @author Antonius Ng
* 
* $Id: Table.js,v 1.1 2007/05/30 09:10:42 antonius Exp $
*/

/**
* @class A Table object. This table object will be drawn at the call of the constructor method
* This object inherits all the method from table DOM API
* Usage:
* var o = new n2n.Table("table_id"); //Draw a table with id table_id
*
* // add row to table
* o.insertRow();
*
*/

dojo.provide("n2n.Table");
dojo.require("dojo.lang.*");
dojo.require("dojo.render.*");

n2n.Table = Class.create();

n2n.Table.prototype= {
	
	initialize: function(id, container) {
		this.id = id;
		if (!container) {
			container = document;
		}
		this.container = container;
		
	},	
	
	toHTML: function() {
		return "<table id=\""+this.id+"\"></table>";
	},
	
	paint: function() {
		if (!this.getTable()) { 
			this.container.write(this.toHTML());
		}
		this.HTMLObject = document.getElementById(this.id);
	},
	getTable: function() {
		return document.getElementById(this.id);
	},
	clear: function() {
		if (dojo.render.html.ie) {
			var tab = this.getTable();
			var i;
			var n = tab.rows.length;
			for (i=0;i<n;i++) {
				tab.deleteRow(0);
			}
			return;
		}
		this.getTable().innerHTML = "";
	}
}