

//<script>

function CHtmlAttribute(attrList)
{
	var i;
	this.data = [];
	if (attrList instanceof CHtmlAttribute)
	{
		for (i in attrList.data)
			this.data[i] = attrList.data[i];
	}
	else if (attrList != null)
	{
		for (i=0; i<attrList.length; i++)
			this.data[attrList[i][0]] = attrList[i][1];
	}
}
CHtmlAttribute.prototype.assign = function(attr, value){this.data[attr] = value };
CHtmlAttribute.prototype.prefix = function(attr, value){this.data[attr] == null ? this.data[attr] = value : this.data[attr] = value +" "+ this.data[attr]};
CHtmlAttribute.prototype.append = function(attr, value){this.data[attr] += " "+ value};
CHtmlAttribute.prototype.remove = function(attr){ if(this.data[attr] !== null) delete this.data[attr] };

function CHtmlElement(tag, attrList, innerHTML, outerHTML)
{
	this.tag = tag == null ? "" : tag;
	this.attribute = new CHtmlAttribute(attrList);
	this.innerHTML = innerHTML == null ? "" : innerHTML;
	this.outerHTML = outerHTML == null ? null : outerHTML;
}
CHtmlElement.prototype.clone = function ()
{
	var result = new CHtmlElement(this.tag, this.attribute, this.innerHTML, this.outerHTML);	
	return result;
}
CHtmlElement.prototype.openHTML = function ()
{
	if (this.outerHTML != null && this.outerHTML.charAt(0) == '<')
		return this.outerHTML;
	var html = '<'+ this.tag;
	for (var i in this.attribute.data)
		//html += ' '+ i + (this.attribute.data[i] == null ? '' : '="'+ this.attribute.data[i] +'"');
		html += ' '+ i +'="'+ this.attribute.data[i] +'"';
	if (this.outerHTML != null)
		html += ' '+ this.outerHTML;
	return html +'>';
}
CHtmlElement.prototype.closeHTML = function ()
{
	return '</'+ this.tag + '>';
}
CHtmlElement.prototype.HTML = function ()
{
	return this.openHTML() + this.innerHTML + this.closeHTML();
}

function CHtmlElementArray(htmlElement)
{
	this.htmlElement = htmlElement.clone();
	this.data = [];
}
CHtmlElementArray.prototype.count = function(){ return this.data.length }
CHtmlElementArray.prototype.item = function(index)
{
	for (var i=this.data.length; i<=index; i++)
		if (this.data[i] == null)
			this.data[i] = this.htmlElement.clone();
	return this.data[index];
}

function CHtmlElementMatrix(htmlElement)
{
	this.htmlElement = htmlElement .clone();
	this.data = [];
}
CHtmlElementMatrix.prototype.rowCount = function(){ return this.data.length }
CHtmlElementMatrix.prototype.colCount = function()
{ 
	var result = 0;
	for (var i=0; i<this.data.length; i++)
		if (this.data[i][0] != null && this.data[i].length > result)
			result = this.data[i].length;
	return result;
}
CHtmlElementMatrix.prototype.item = function(row, col)
{
	var i, j;
	for (i=this.data.length; i<=row; i++)
		if (this.data[i] == null)
			this.data[i] = [];
	for (j=this.data[row].length; j<=col; j++)
		if (this.data[row][j] == null)
			this.data[row][j] = this.htmlElement.clone();
	return this.data[row][col];
}

function CHtmlTable(id, cls)
{
	this.id = id;
	this.cls = cls == null ? "CHtmlTable" : cls;
	
	this.html = new Object();
	this.html.table = new CHtmlElement("TABLE", [["ID","#id#_TABLE"],["CLASS","#cls#-TABLE"]], null, "CELLSPACING=0 CELLPADDING=0");
	this.html.caption = new CHtmlElement("CAPTION", [["ID","#id#_CAPTION"],["CLASS","#cls#-CAPTION"]]);
	this.html.col = new CHtmlElement("COL", [["ID","#id#_COL_#col#"],["CLASS","#cls#-COL"]]);
	this.html.thead = new CHtmlElement("THEAD", [["ID","#id#_THEAD"],["CLASS","#cls#-THEAD"]]);
	this.html.th = new CHtmlElement("TH", [["ID","#id#_TH_#col#"],["CLASS","#cls#-TH"]]);
	this.html.tr = new CHtmlElement("TR", [["ID","#id#_TR_#row#"],["CLASS","#cls#-TR-normal-out"],["onmouseover","#id#.onmouseoverRow(this, event, #row#)"],["onmouseout","#id#.onmouseoutRow(this, event, #row#)"],["ondblclick","#id#.ondblclickRow(this, event, #row#)"],["onclick","#id#.onclickRow(this, event, #row#)"],["onmousedown","#id#.onmousedownRow(this, event, #row#)"]]);
	this.html.td = new CHtmlElement("TD", [["ID","#id#_TD_#row#_#col#"],["CLASS","#cls#-TD-normal-out"],["onmouseover","#id#.onmouseoverCell(this, event, #row#, #col#)"],["onmouseout","#id#.onmouseoutCell(this, event, #row#, #col#)"],["ondblclick","#id#.ondblclickCell(this, event, #row#, #col#)"],["onclick","#id#.onclickCell(this, event, #row#, #col#)"],["onmousedown","#id#.onmousedownCell(this, event, #row#, #col#)"]], "&nbsp;");
	
	this.table = this.html.table.clone();
	this.caption = this.html.caption.clone();
	this.col = new CHtmlElementArray(this.html.col);
	this.header = new CHtmlElementArray(this.html.th);
	this.row = new CHtmlElementArray(this.html.tr);
	this.cell = new CHtmlElementMatrix(this.html.td);
}
CHtmlTable.prototype.clearRow = function ()
{
	this.row = new CHtmlElementArray(this.html.tr);
	this.cell = new CHtmlElementMatrix(this.html.td);
}
CHtmlTable.prototype.rowCount = function ()
{
	var result = this.row.count();
	var tmp = this.cell.rowCount();
	if (tmp > result)
		result = tmp;
	return result;
}
CHtmlTable.prototype.colCount = function (td, e, row)
{
	var result = this.col.count();
	var tmp = this.header.count();
	if (tmp > result)
		result = tmp;
	tmp = this.cell.colCount();
	if (tmp > result)
		result = tmp;
	return result;
}
CHtmlTable.prototype.onmouseoverRow = function (td, e, row)
{
	//window.defaultStatus = "onmouseoverRow "+ row;
}
CHtmlTable.prototype.onmouseoutRow = function (td, e, row)
{
	//window.defaultStatus = "onmouseoutRow "+ row;
}
CHtmlTable.prototype.ondblclickRow = function (td, e, row)
{
	//window.defaultStatus = "ondblclickRow "+ row;
}
CHtmlTable.prototype.onclickRow = function (td, e, row)
{
	//window.defaultStatus = "onclickRow "+ row;
}
CHtmlTable.prototype.onmousedownRow = function (td, e, row)
{
	//window.defaultStatus = "onmousedownRow "+ row;
}
CHtmlTable.prototype.onmouseoverCell = function (td, e, row, col)
{
	//window.defaultStatus = "onmouseoverCell "+ row +" "+ col;
}
CHtmlTable.prototype.onmouseoutCell = function (td, e, row, col)
{
	//window.defaultStatus = "onmouseoutCell "+ row +" "+ col;
}
CHtmlTable.prototype.ondblclickCell = function (td, e, row, col)
{
	//window.defaultStatus = "ondblclickCell "+ row +" "+ col;
}
CHtmlTable.prototype.onclickCell = function (td, e, row, col)
{
	//window.defaultStatus = "onclickCell "+ row +" "+ col;
}
CHtmlTable.prototype.onmousedownCell = function (td, e, row, col)
{
	//window.defaultStatus = "onmousedownCell "+ row +" "+ col;
}

//CHtmlTable.prototype.reHtml = /(#id#)|(#cls#)|(#col#)|(#row#)/gm;
//CHtmlTable.prototype.reHtmlFunction = function($0){switch($0){case '#id': return id; case '#cls#': return cls; case '#col#': return col; case '#row#': return row; default: return $0;}}
CHtmlTable.prototype.HTML = function ()
{
	var id = this.id;
	var cls = this.cls;
	var c, r, tmp1, tmp2, nRow, nCol;
	var result = this.table.openHTML();
	if (this.caption.innerHTML != "")
		result += this.caption.HTML();
	for (c=0; c<this.col.data.length; c++)
		result += this.col.data[c].HTML().replace(/#col#/g, c);
	result += this.html.thead.openHTML();
	for (c=0; c<this.header.data.length; c++)
		result += this.header.item(c).HTML().replace(/#col#/g, c);
	result += this.html.thead.closeHTML();
	nRow = this.rowCount();
	nCol = this.colCount();
	for (r=0; r<nRow; r++)
	{
		tmp1 = this.row.item(r).openHTML();
		tmp2 = "";
		for (c=0; c<nCol; c++)
			tmp2 += this.cell.item(r, c).HTML().replace(/#col#/g, c);
		tmp1 += tmp2 + this.row.data[r].closeHTML();
		result += tmp1.replace(/#row#/g, r);
	}
	result += this.html.table.closeHTML();
	result = result.replace(/(#id#)|(#cls#)/gm, function($0){switch($0){case '#id#': return id; case '#cls#': return cls; default: return $0;}});
	return result;
}

//</script>
 

