

/* tables.js */
function tables() {
	if (!document.getElementsByTagName) {
		return;
	}
	
	// Get the table
	var tables = document.getElementsByTagName("table");
	
	// Iterate through the tables
	for (var i = 0; i < tables.length; i++) {
		// The table
		var table = tables[i];
		
		// Only continue if the table is data
		if (tables_findElementInArray(table.className.split(" "),"data") >= 0) {
			// Get the tbodys
			var tbodys = table.getElementsByTagName("tbody");
			
			if (tbodys.length == 0) {
				continue;
			}
			
			// Get the child nodes
			var childNodes = tbodys[0].childNodes;
			// var trs = tbodys[0].getElementsByTagName("tr");
			
			// Get the first and last trs
			var firstTr = null;
			var lastTr = null;
			
			for (var j = 0; j < childNodes.length; j++) {
				var node = childNodes.item(j);
				
				if (node.nodeName == "TR") {
					if (firstTr == null) {
						firstTr = node;
					}
					
					lastTr = node;
				}
			}
			
			// var firstTr = trs[0];
			// var lastTr = trs[trs.length - 1];
			
			// alert("firstTr.className: " + firstTr.className);
			// alert("lastTr.className: " + lastTr.className);
			
			// Check to see if the first class is specified
			if (tables_findElementInArray(firstTr.className.split(" "),"first") < 0) {
				if (firstTr.className.length <= 0) {
					firstTr.className = "first";
				}
				else {
					firstTr.className = firstTr.className + " first";
				}
			}
			
			// Check to see if the last class is specified
			if (tables_findElementInArray(lastTr.className.split(" "),"last") < 0) {
				if (lastTr.className.length <= 0) {
					lastTr.className = "last";
				}
				else {
					lastTr.className = "last " + lastTr.className;
				}
			}
			
			// alert("firstTr.className: " + firstTr.className);
			// alert("lastTr.className: " + lastTr.className);
		}
	}
}

function tables_findElementInArray(array,element) {
	for (var i = 0; i < array.length; i++) {
		if (array[i] == element) {
			return i;
		}
	}
	
	return -1;
}

/* mvnt.jsp */
window.onload = function() {
	tables();
}