// Initialize global variables to track popup windows
var glossaryWindow = null;
var expWindow = '';

// Pop up glossary in new window, or bring it to the front if already open
function popUpGlossary() {
	if ((glossaryWindow == null) || glossaryWindow.closed) {
		var winFeatures='width=500,height=450,scrollbars=no';
		winFeatures += windowCenteringInfo(500, 450);
		glossaryWindow = window.open('glossary.php', 'glossary', winFeatures);
		// Make sure that opener is defined for use by popup window 
		if (!glossaryWindow.opener) glossaryWindow.opener = this.window;
	} else {
		if (window.focus) glossaryWindow.focus();
	}
}

// Function to pop up an explanation
// Can't simply bring to front if already open because they may be bringing up a different question
function popExp(id) {
	var winFeatures = "toolbar=0" + ",location=0" + ",directories=0"
		+ ",status=0" + ",menubar=0" + ",scrollbars=1"
		+ ",resizable=1"  + ",width=550" + ",height=400";
	winFeatures += windowCenteringInfo(550, 400);
	//	Safari (case-insensitive regexp for it) doesn't support window.focus(), so close window first
	if ( (/safari/i.test(navigator.userAgent)) && (!expWindow.closed && expWindow.location) ) {
		expWindow.close();
		// "+Math.random()" in window name because Safari won't reopen the same named window after closing it
		// (so one would have to click again to open the next window)
		expWindow = window.open('explanation.php?id=' + id, 'Explanation'+Math.random(), winFeatures);
	} else {
		// Adding the Math.random() value would cause error in MSIE
		expWindow = window.open('explanation.php?id=' + id, 'Explanation', winFeatures);		
	}
	if (window.focus) expWindow.focus();
}

// Show or hide a table row
function showHideRow(rowID){
	var row = document.getElementById(rowID);
	// If intially hidden by CSS, value will be '' at that point
	var val = (row.style.display != 'none') ? 'none' : ((document.all && !window.opera) ? 'inline' : 'table-row');
	row.style.display = val;
}

// Hide explanation rows
function hideRows(tableId) {
	var t = document.getElementById(tableId);
	for(var i=0, limit=t.rows.length; i < limit; ++i) {
		if (t.rows[i].className == 'explanation') {
		   t.rows[i].style.display='none';
		}
	}
}

// Toggle text in a given element
function toggleText(id, text_1, text_2) {
	if (document.getElementById) {
		var theElement = document.getElementById(id);
		if (theElement.innerHTML==text_1) {
			theElement.innerHTML = text_2;
		} else {
			theElement.innerHTML = text_1;
		}
	}
	return false;
}



