function Table_getSelectedIndex(id) {
	var table = document.getElementById(id);
	if (table != null) {
		var selIndex = table.getAttribute("selIndex");
		if (selIndex == null) {
			table.setAttribute("selIndex", -1);
			selIndex = -1;
		}
		return parseInt(selIndex);
	} else {
		return -1;
	}
}

function Table_setSelectedIndex(id, index) {
	var table = document.getElementById(id);
	if (table != null) {
		var oldIndex = Table_getSelectedIndex(id);
		table.setAttribute("selIndex", index);
		var tableBody = document.getElementById(id + "_Body");
		if (tableBody != null) {
			var hasHeader = table.getAttribute("hasHeader");
			var altRowBase = (hasHeader == "true") ? 0 : 1;
			var disabledClass = Table_isDisabled(id) ? " " + id + "_Disabled" : "";
			for (i = 0; i < tableBody.rows.length; i ++) {
				for (j = 0; j < tableBody.rows[i].cells.length; j ++) {
					var selectedClass = (i == index - 1) ? " " + id + "_Row_Sel" : "";
					if (i % 2 == altRowBase) {
						tableBody.rows[i].cells[j].className = id + "_Body_Cell " + id + "_Row_Alt" + selectedClass + disabledClass;
					} else {
						tableBody.rows[i].cells[j].className = id + "_Body_Cell " + id + "_Row" + selectedClass + disabledClass;
					}
				}
			}
		}
		if (oldIndex != index) {
			try {
				eval(id + "_onSelectionChanged(" + index + ");");
			} catch (err){}
		}
	}
}

function Table_changeState(id, state) {
	var table = document.getElementById(id);
	if (table != null) {
		table.setAttribute("state", state);
		var disabledClass = Table_isDisabled(id) ? " " + id + "_Disabled" : "";
		var tableHeader = document.getElementById(id + "_Header");
		if (tableHeader != null) {
			tableHeader.className = id + "_Header_Frame" + disabledClass;
			for (i = 0; i < tableHeader.rows[0].cells.length; i ++) {
				tableHeader.rows[0].cells[i].className = id + "_Header_Cell" + disabledClass;
			}
		}
		var tableBody = document.getElementById(id + "_Body");
		if (tableBody != null) {
			tableBody.className = id + "_Body_Frame " + disabledClass;
		}
		Table_setSelectedIndex(id, Table_getSelectedIndex(id));
	}
	return true;
}

function Table_isDisabled(id) {
	var table = document.getElementById(id);
	if (table != null) {
		var state = parseInt(table.getAttribute("state"));
		return ((state & 64) > 0);
	}
	return false;
}

function Table_setCellValue(id, row, col, value) {
	var table = document.getElementById(id);
	if (table != null) {
		var tableBody = document.getElementById(id + "_Body");
		if (tableBody != null) {
			if (row > 0 && row <= tableBody.rows.length && col > 0 && col <= tableBody.rows[row - 1].cells.length) {
				tableBody.rows[row - 1].cells[col - 1].innerHTML = "<nobr>" + value + "</nobr>";
			}
		}
	}
}

function Table_getCellValues(id) {
	var table = document.getElementById(id);
	if (table != null) {
		var tableBody = document.getElementById(id + "_Body");
		if (tableBody != null) {
			var cellValues = new Array();
			for (i = 0; i < tableBody.rows.length; i ++) {
				cellValues[i + 1] = new Array();
				for (j = 0; j < tableBody.rows[i].cells.length; j ++) {
					var cellValue = tableBody.rows[i].cells[j].innerHTML;
					cellValues[i + 1][j + 1] = cellValue.substring(6, cellValue.length - 7);
				}
			}
			return cellValues;
		}
	}
	return null;
}
