// popup.js
// Copyright 2005, emlab
// krudd, 21/01/05

// Makes any links with the word "popup" in their "target name" open in a new window.
// Also takes the dimensions from the "target name" in the form "WWWxHHH".

function addOnLoad( newOnload )
{
	var prevOnload = window.onload;
	if ( window.onload == null )
		window.onload = newOnload;
	else
		window.onload = function() { prevOnload(); newOnload(); };
}

//-------------

function popUpLink()
{
	// grab any dimensions from target name
	var width = 0, height = 0;
	var result = /(\d+)[Xx](\d+)/.exec( this.target );
	if ( result != null ) {
		width = result[ 1 ];
		height = result[ 2 ];
	}

	// open window
	var size = ( width > 0 || height > 0 ) ? ( ',width=' + width + ',height=' + height ) : '';
	var popup = window.open( this.href, this.target, 'toolbar=no,locationbar=no,status=yes,scrollbars=yes,resizable=yes' + size );
	popup.window.focus();
	return false;
}

function setupPopUps( )
{
	var links = document.links;
	for ( i = 0; i < links.length; i++ ) {
		if ( links[ i ].target.search( /popup/i ) > -1 ) {
			links[ i ].onclick = popUpLink;
			links[ i ].onkeypress = popUpLink;
		}
	}
}

addOnLoad( setupPopUps );
