/*
	popstuff 
	function to automatically add popup window calls to each link
	with a target, and add close window links to the popups.
	credits: http://icant.co.uk/forreview/popstuff/popstuff.html
*/

function initpop()
{
	var closeElementId='closewindow';
	var closeLinkText='Close window';
	var windowAttributes='width=500,height=500,left=0,top=0,location=no,resizable=yes,scrollbars=yes';

	if(!window.opener)
	{
		var as,i,popfun
		as=document.getElementsByTagName('a');
		for (i=0;i<as.length;i++)
		{
			if(as[i].target)
			{
				popfun=function(){window.open(this.href,'',windowAttributes);return false;};
				as[i].onclick=popfun;
				as[i].onkeypress=popfun;
			}
		}
	} else {
		var closep,closelink,closetext;
		closelink=document.createElement('a');
		closetext=document.createTextNode(closeLinkText);
		closelink.href='#';
		closelink.appendChild(closetext);
		closelink.onclick=function(){self.close();};
		if(document.getElementById(closeElementId))
		{
			document.getElementById(closeElementId).appendChild(closelink);	
		} else {
			closep=document.createElement('p');
			closep.id=closeElementId;
			closep.appendChild(closelink);
			document.body.insertBefore(closep,document.body.firstChild);	
		}
	}
}

//http://surfmind.com/musings/gems/alternaterowcolors.js
function alternateRowColors() {
	var className = 'data-table';
	var rowcolor = '#FFFAF0';
	var rows, arow;
	var tables = document.getElementsByTagName("table");
	var rowCount = 0;
	for(var i=0;i<tables.length;i++) {
		//dump(tables.item(i).className + " " + tables.item(i).nodeName + "\n");
		if(tables.item(i).className == className) {
			atable = tables.item(i);
			rows = atable.getElementsByTagName("tr");
			for(var j=0;j<rows.length;j++) {
				arow = rows.item(j);
				if(arow.nodeName == "TR") {
					if(rowCount % 2) {
						arow.style.backgroundColor = rowcolor;
					} else {
						// default case
					}
					rowCount++;
				}
			}
			rowCount = 0;
		}
	}
}
if(document.getElementById && document.getElementsByTagName)
{
	window.onload = function()
	{
		alternateRowColors();
		initpop();
	}
}
