/*
	common.js - CopyLeft 2011 Greg Macdonald, greg@ggmac.com
*/

if (typeof Array.isArray !== 'function') {
	Array.isArray = function (value) {
		return Array.prototype.toString.apply(value) === '[object Array]';
	};
}

if (typeof String.prototype.trim !== 'function') {
	String.prototype.trim = function () {
		return this.replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1");	// /^\s*(\S*(\s+\S+)*)\s*$/
	};
}

if (typeof String.prototype.supplant !== 'function') {
	String.prototype.supplant = function (o) {
		return this.replace(/{([^{}]*)}/g,	// /{([^{}]*)}/g
			function (a, b) {
				var r = o[b];
				return typeof r === 'string' ? r : a;
			});
	};
}

function setStyleById(id, prop, value) {
	var n = document.getElementById(id);
	n.style[prop] = value;
}

function getWindowHeight() {
	var windowHeight = 0;
	if (typeof window.innerHeight === 'number') {
		windowHeight = window.innerHeight;
	} else {
		if (document.documentElement && document.documentElement.clientHeight) {
			windowHeight = document.documentElement.clientHeight;
		} else {
			if (document.body && document.body.clientHeight) {
				windowHeight = document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}

function highlightTableRows(table, color) {
	var rows, bgColor = color || "#F0FCFF";
	
	if (!table) {throw "Invalid param 'table'";}
	
	rows = table.getElementsByTagName('tr');
	for (iRow = 0; iRow < rows.length; iRow += 1) {
		if (!(iRow % 2) && rows[iRow].className !== "footer") {
			rows[iRow].style.backgroundColor = bgColor;
		}
	}
}

function highlightAllTableRows(doc, color) {
	tables = doc.getElementsByTagName('table');
	for (iTable = 0; iTable < tables.length; iTable += 1) {
		highlightTableRows(tables[iTable], color);
	}
}


