// JavaScript Document for style
// Utilities functions
function getElementsByStyle(elemTag, eleClass) {	
	var eleList = document.getElementsByTagName(elemTag);
	var matchList = new Array();
	if (!eleList) { return; }
	for (var i = 0; i < eleList.length; i++) {
		if (eleList[i].className.match(eval(  "/[\w\s ]*" +  eleClass + "[\w\s ]*/") )) {
			matchList[matchList.length] = eleList[i];
		}
	}	
	return matchList;
}

// Table Styles functions
var mouseOverRowColor = "#A3CDE2";
var oddRowColor = "#F3F3F3";
var evenRowColor = "#E3E3E3";
function applyDynamicStrippedTableStyle () {
	var tableList = getElementsByStyle("table", "dynamicStrippedTable");
	if (!tableList && tableList.length > 0) {return;}
	for (var i = 0; i< tableList.length; i++) {
		var table = tableList[i];
		var rows = table.getElementsByTagName("tr");
		if (!rows) { return; }
		
		// skip first row for header
		for (var i = 1; i < rows.length; i++) {
			var row = rows[i];
			var color;			
			if (i%2 == 1)  // odd row
				row.color = oddRowColor;
			else 
				row.color = evenRowColor;
			row.style.backgroundColor=row.color;
			row.style.cursor="pointer";
			row.onmouseover=function mouseOver(row) {
				this.style.backgroundColor=mouseOverRowColor;
			}
			row.onmouseout=function mouseOut(row) {
				this.style.backgroundColor=this.color;
			}
		}
	}
}
function applyStaticStrippedTableStyle () {
	var tableList = getElementsByStyle("table", "staticStrippedTable");
	if (!tableList && tableList.length > 0) {return;}
	for (var i = 0; i< tableList.length; i++) { 
		var table = tableList[i];
		var rows = table.getElementsByTagName("tr");
		if (!rows) { return; }
		// skip first row for header		
		for (var i = 1; i < rows.length; i++) {
			var row = rows[i];
			var color;			
			if (i%2 == 1)  // odd row
				row.color = oddRowColor;
			else 
				row.color = evenRowColor;
			row.style.backgroundColor=row.color;			
		}
	}
}
// Button Style functions
function applyButtonStyle () {
	var buttonList = getElementsByStyle("a", "imgButton");
	for (var i = 0; i < buttonList.length; i++) {
		var button = buttonList[i];
		//insertAdjacentHTML("afterEnd", "right");
	}
}

// Main Style function call
function applyStyle() {
	// check if style javascript 
	if (!(document.getElementById && document.getElementsByTagName)) {
		return;
	}
	applyStaticStrippedTableStyle();
	applyDynamicStrippedTableStyle();
	//applyButtonStyle();
}
