var activeButton = null;

function createTable(rows, cols, width){
	/****************************************************************
	**	name		: createTable						**
	**	type		: private Method						**
	**	function		: creates a table with rows and		**
	**				  columns with a user specified width	**
	**	arguments	: rows, cols, width					**
	****************************************************************/
	var table = new Array();
	var i;
	table["root"] = document.createElement("TABLE");
	table["tbody"] = document.createElement("TBODY");
	table["root"].width = width;
	table["root"].appendChild(table["tbody"]);
	table.cols = cols;
	
	with(table["root"]){
		cellPadding = "0px";
		cellSpacing	= "0px";
		border = "0px";
	}
	
	table.seq = new Array();
	
	table.connect = function(parent){
	/****************************************************************
	**	name		: table.connect						**
	**	type		: private Method						**
	**	function		: connects two tables				**
	**	arguments	: parent								**
	****************************************************************/
		parent.appendChild(this.root);	
	}
	
	table.addCol = function(befCol, colspan){
	/****************************************************************
	**	name		: table.addCol						**
	**	type		: private Method						**
	**	function		: adds a column to an existing table	**
	**	arguments	: betCol, colspan					**
	****************************************************************/
		var col;
		var i;
		for(i=0;i<this.rows.length;i++){
			col = document.createElement("TD");
			if(colspan) col.colspan = colspan;
			if(befCol || befCol == 0){
				this.rows[i].insertBefore(col,this.rows[i].cols[befCol]);
				this.seq[this.rows[i].cols.length] = befCol;
			}
			else{
				this.rows[i].appendChild(col);
				this.seq[this.rows[i].cols.length] = false;
			}
			this.rows[i].cols.push(col);
		}
		
		this.cols++;
		return col;
	}
	
	table["rows"] = new Array();
	
	table.addRow = function(rowspan){
	/****************************************************************
	**	name		: table.addRow						**
	**	type		: private Method						**
	**	function		: adds a row to an existing table		**
	**	arguments	: rowspan							**
	****************************************************************/
		var row, cell;
		var i;
		row = document.createElement("TR");
		this["tbody"].appendChild(row);
		if(rowspan) row.rowspan = rowspan;
		this.rows.push(row);
		this.tbody.appendChild(row);
		row.cols = new Array();
		for(i=0;i<this.cols;i++){
			cell = document.createElement("TD");
			if(!this.seq[i] && this.seq[i] != 0){
				row.appendChild(cell);
			}
			else{
				row.insertBefore(cell, row.cols[this.seq[i]]);
			}
				
			row.cols.push(cell);
		}
		return row;
	}
	
	for(i=0;i<rows;i++){
		table.addRow();
	}
	
	return table;
}


function mTableViewer(){
	this.addTableViewer = function(caption){
		var btn;
		
		btn = new tableViewer;
		btn.caption(caption);
		btn.left(this.buttons.length * 75 + 50);
		if(!this.buttons.length) btn.setActive();
		this.holder.appendChild(btn.button);
		this.holder.appendChild(btn.container);
		btn.container.style.width = "95%";
		this.buttons.push(btn);
		
		return btn;
	}
	
	this.buttons = new Array();
	
	this.holder = document.createElement("DIV");
	this.holder.style.overflow = "hidden";
	this.holder.style.backgroundColor = "white";
	this.holder.style.height=200;
	this.holder.style.padding = "0px 0px 0px 50px";
	
	document.body.appendChild(this.holder);
	
	this.externalObject = this.holder;
	this.internalObject = this.holder;
}

function tableViewer(){
	this.caption = function(caption){
		this.button.innerHTML = "<Center>" + caption + "</Center>";
	}
	
	this.setActive = function(){
		if(activeButton){ 
			activeButton.button.style.backgroundColor = "white";
			activeButton.button.style.color = "black";
			activeButton.enabled = true;
			activeButton.container.style.visibility = "hidden";
		}
		this.button.style.backgroundColor = "#AAAAAA";
		this.button.style.color = "white";
		this.enabled = false;
		activeButton = this;
		activeButton.container.style.visibility = "visible";
	}
	
	this.addCol = function(descript, name, loc){
		row = this.table.addRow();
		row.cols[1].bgColor = "DDDDDD";
		row.cols[0].bgColor = "DDDDDD";
		row.cols[0].innerHTML = "<a href=" + loc + ">" + descript + "</a>";
		row.cols[1].innerHTML = name;
		row.cols[0].vAlign = "top";
		row.cols[1].vAlign = "top";
		row.previousSibling.cols[0].height = 10;
		
		/*row.cols[1].onmouseover = function(){
			this.style.backgroundColor = "#96D5FA";	
		}
		
		row.cols[1].onmouseout = function(){
			this.style.backgroundColor = "DDDDDD";	
		}*/
		
	}
	
	this.left = function(value){
		this.externalObject.style.position = "absolute";
		this.externalObject.style.left = value;
	}
	
	this.top = function(value){
		this.externalObject.style.position = "absolute";
		this.externalObject.style.left = value;
	}
	
	this.button = document.createElement("DIV");
	document.body.appendChild(this.button);
	this.button.style.borderWidth = 1;
	this.button.style.borderStyle = "solid";
	this.button.style.borderColor = "CCCCCC";
	this.button.style.width = 70;
	this.button.style.height = 21;
	this.button.style.padding = "3px 6px 3px 6px";
	this.button.style.fontFamily = "Tahoma";
	this.button.style.position = "absolute";
	this.button.style.cursor = "default";
	this.button.host = this;
	this.button.onmousedown = function(){
		return false;
	}
	
	this.button.onmouseover = function(){
		if(this.host.enabled) this.style.backgroundColor = "DDDDDD";
		return false;
	}
	
	this.button.onmouseout = function(){
		if(this.host.enabled) this.style.backgroundColor = "white";
	}
	
	this.button.onclick = function(){
		this.host.setActive();
	}
	
	this.enabled = true;
	
	this.container = document.createElement("DIV");
	document.body.appendChild(this.container);
	this.container.style.borderWidth = 1;
	this.container.style.borderStyle = "solid";
	this.container.style.borderColor = "CCCCCC";
	this.container.style.width = 540;
	this.container.style.height = 170;
	this.container.style.top = 25;
	this.container.style.position = "absolute";
	this.container.style.padding = "1px 1px 1px 1px";
	this.container.style.overflowY = "scroll";
	this.container.style.overflowX = "hidden";
	
	this.table = createTable(1,2,"100%");
	this.container.appendChild(this.table.root);
	this.table.root.cellSpacing = "1px";
	this.table.root.height = "100%";
	this.table.rows[0].cols[1].bgColor = "#BBBBBB";
	this.table.rows[0].cols[0].bgColor = "#BBBBBB";
	this.table.rows[0].cols[0].height=10;
	this.table.rows[0].cols[0].innerHTML = "<b>Property</b>";
	this.table.rows[0].cols[1].innerHTML = "<b>Description</b>";
	this.table.rows[0].cols[1].width = 92;
	
	this.container.style.visibility = "hidden";
	
	this.externalObject = this.button;
	this.internalObject = this.container;
}

