
window.onload = function(){
	findTablesToStyle();
}

// Special method for styling of the share data tables from Cision
function styleTable(table){
	var tableRows = table.getElementsByTagName("tr");
	for (var i = 0, n = tableRows.length; i < n; i++){
		if (i > 0){
			if (i % 2 > 0){
				tableRows[i].style.backgroundColor = "#EEEBE6";
			}
		}
	}
}

// Looks for tables to style
function findTablesToStyle(){
	var tables = document.getElementsByTagName("table");
	for (var tableIndex = 0, n = tables.length; tableIndex < n; tableIndex++){
		if (tables[tableIndex].className === "infoTable"){
			styleInfoTable(tables[tableIndex]);
        }
		if (tables[tableIndex].className === "financialTable"){
			styleFinancialTable(tables[tableIndex]);
		}
	}
}

// Loops the rows of an infotable and set CSS-classes.
function styleInfoTable(table){
	var tableRows = table.getElementsByTagName("tr"),
		firstRow = 1,
		rowIndex = 0;
	if (tableRows.length === 0){
		return;
    }  
	if (tableRows[0].getElementsByTagName("th").length === 0){
		firstRow = 0;
	}
	for (var i = firstRow, n = tableRows.length; i < n; i++){
		if (rowIndex % 2 === 0){
			tableRows[i].className = tableRows[i].className + " evenRow";
		}
		rowIndex ++;
	}        
}

// Loops the rows and cells of a financial table and set CSS-classes.
function styleFinancialTable(table){
	var tableRows = table.getElementsByTagName("tr");
	for (var i = 0, n = tableRows.length; i < n; i++){
		var tableCells = tableRows[i].getElementsByTagName("td");
		if (tableCells.length === 0){
			tableCells = tableRows[i].getElementsByTagName("th");
        }        
		for (var j = 0, z = tableCells.length; j < z; j++){
			if (j === 0){
			}else{
				if (j % 2 > 0){
					tableCells[j].className = tableCells[j].className + " highlight";    
				}else{
					tableCells[j].className = tableCells[j].className + " normal";
				}
			}
		}       
	}
}
