/* -----------------------------------------------------------------------------
 * addRow			: <table>¿¡ <tr><td>¸¦ Ãß°¡
 * Parameter
	- table			: [object] ´ë»ó Å×ÀÌºí
	- cells			: [Number] Ãß°¡ÇÒ TDÀÇ °¹¼ö
	- bgcolor		: [String] ¹è°æ»ö
	- overcolor		: [String] Over½Ã ¹è°æ»ö
	- align			: [String] CellÀÇ Align
	- width			: [Number] Cell ³Êºñ
	- height		: [Number] Row ³ôÀÌ
	- row_func		: [String] Row Å¬¸¯½Ã ¼öÇà ÇÔ¼ö¸í
	- cell_func		: [String] Cell Å¬¸¯½Ã ¼öÇà ÇÔ¼ö¸í
 * return			: [NULL]
 ------------------------------------------------------------------------------ */
function addRow(table, cells, bgcolor, overcolor, align, width, height, row_func, cell_func){
	if(isNaN(cells)) return;

	if(bgcolor == "" || bgcolor == null || typeof(bgcolor) == "undefined")		
		bgcolor = "#FFFFFF"
	if(overcolor == "" || overcolor == null || typeof(overcolor) == "undefined") 
		overcolor = "#FFFFFF"

	if(typeof(width) == "number") {
	} else if(typeof(width) == "object"){
		if(width.length < cells){
			for(var i=width.length; i<cells; i++){
				width[i] = -1;
			}
		}
	} else {
		width = -1;
	}
	if(isNaN(height) || height < 0) height = 25;

	var oRow = table.insertRow();

	oRow.style.background = bgcolor;
	if(row_func != null)
		oRow.onclick=function(){eval(row_func + "(this.rowIndex);")}

	oRow.onmouseover=function(){this.style.background = overcolor;};
	oRow.onmouseout=function(){this.style.background = bgcolor;};

	for(i=0; i<cells; i++){
		var viewCell = oRow.insertCell();
		viewCell.innerText=' ';
		if(align != null)		viewCell.style.textAlign = align;
		if(typeof(width) == "number"){
			if(width > -1)			viewCell.style.width = width;
		} else {
			if(width[i] > -1)		viewCell.style.width = width[i];
		}
		viewCell.style.height = height;
		if(cell_func != null)	viewCell.onclick=function(){eval(cell_func + "(oRow.rowIndex, this.cellIndex);")}
	}
}

function deleteRow(table, count, header){
	if(isNaN(count)) return;

	if(header == "undefined")
		header = true;

	if(count < 1) count = table.rows.length;

	var rows = table.rows.length;

	var alive = rows - count;

	while(rows > alive){
		if(rows == 1 && header) return;
		table.deleteRow(rows-1);
		rows--;
	}
}

function drawText(table, row, cell, text, color, className){
	if(table.rows(row).cells(cell) != null){
		table.rows(row).cells(cell).innerText = text;
		table.rows(row).cells(cell).style.color = color;
		table.rows(row).cells(cell).className = className;
	}
}
