// CWS April 2006 - lyle [at] cws [dot] net

// Apply a custom CSS class to specific form elements
function stylize_forms() {
	var inputs = document.getElementsByTagName('input');
	if (inputs) {
		for (var i=0; i<inputs.length; i++) {
			with (inputs[i]) {
				switch (type) {
					case "button":
						className = "button";
						break;
					case "submit":
						className = "button";
						break;
					case "reset":
						className = "button";
						break;
				}
			}
		}
	}
}

// Look for tables in the given CSS class and shade alternating rows
function stripe_tables_in_class(target_class,include_headings) {
		
	// Color definitions
	var evenColor = "#fff";
	var oddColor = "#eee";
	var even = true;
	
	var tables = document.getElementsByTagName("table");
	
	if (tables) {
		for (var i=0; i<tables.length; i++) {
			if (tables[i].className == target_class) {
				var tbody = tables[i].firstChild.nodeType == 3 ? tables[i].firstChild.nextSibling : tables[i].firstChild;
				if (tbody.hasChildNodes()) {
					for (j=0; j<tbody.childNodes.length; j++) {
						var tr = tbody.childNodes[j];
						if (tr.nodeName.toLowerCase() == "tr" && !tr.className) {
							for (k=0; k<tr.childNodes.length; k++) {
								var td = tr.childNodes[k];
								if (td.nodeName.toLowerCase() == "td" || (include_headings && td.nodeName.toLowerCase() == "th")) {
									td.style.backgroundColor = even ? evenColor : oddColor;
								}
							}
							even = !even;
						}
					}
				}
			}
		}
	}
}