/*
	BBBS scripts
*/


/* --- Popup window functions --- */

// Resizable and scrollable popup window
function popup(URL, width, height) {
	popWin = window.open(URL, "popWin", "width=" + width + ",height=" + height + ",resizable=1,scrollbars=1,location=0,toolbar=0");
	popWin.focus();
	return false;
}

// Fixed popup window
function popupFixed(URL, width, height) {
	popWin = window.open(URL, "popWin", "width=" + width + ",height=" + height + ",resizable=0,scrollbars=0,location=0,toolbar=0");
	popWin.focus();
	return false;
}


/* --- Display enhancements --- */

// Alternate data table row colors
function tablerows() {
	var evenodd, tables, rows, i, j;

	tables = document.getElementsByTagName("table");

	for (i = 0; i < tables.length; i++)
		// If a "data" table
		if (tables[i].className.indexOf("data") >= 0) {
			rows = tables[i].getElementsByTagName("tr");
			evenodd = "even";

			// Traverse each row
			for (j = 0; j < rows.length; j++)

				// Check for at least one data cell in row (skip header rows)
				if (rows[j].getElementsByTagName("td").length > 0) {
					evenodd = (evenodd == "data-even") ? "data-odd" : "data-even";

					// Insert/append new class name; Skip rows with predefined even/odd classes
					rows[j].className += (rows[j].className == null) ? evenodd : (rows[j].className == "data-odd" || rows[j].className == "data-even") ? "" : " " + evenodd;
				}
		}
}


/* --- Generic functions --- */

// Add/remove events
function addEvent(obj, type, fn) {
	if (obj.addEventListener)
		obj.addEventListener(type, fn, false);
	else if (obj.attachEvent) {
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn](window.event); }
		obj.attachEvent("on"+type, obj[type+fn]);
	}
}
function removeEvent(obj, type, fn) {
	if (obj.removeEventListener)
		obj.removeEventListener(type, fn, false);
	else if (obj.detachEvent) {
		obj.detachEvent("on"+type, obj[type+fn]);
		obj[type+fn] = null;
		obj["e"+type+fn] = null;
	}
}

addEvent(window, 'load', tablerows);