/*
unobtrusive popup script v1.0
2008 reimar servas

HOW TO USE:
Add a script-tag pointing to this script to your html-document.
Then call “initPopUp()” (e.g. via body-onload). To prepare a link
to open a popup-window, add “popUp” to it’s class-attribute and
define some parameters via a rel-attribute.

EXAMPLE:
<a href="http://www.google.com" class="popUp" rel="900,700,kiosk,center">
“900” = popup-window width,
“700” = popup-window height,
“kiosk” = popup-window mode (“kiosk” = without any toolbars and scrollbars, “full” = full features),
“center” = position, centers popup-window to screen

CALL POPUP SCRIPT FROM FLASH:
If you like to open a popup window from flash, just call the oenPopUp-function and add
another parameter (url):
openPopUp(width,height,mode,position,url)
*/

function initPopUp() {
	// get all popUp links
	var documentLinks = document.getElementsByTagName('a');
	for (var i=0; i < documentLinks.length; i++) {
		if (documentLinks[i].className == 'popUp') {
			documentLinks[i].onclick = function() {
				// open popup
				openPopUp(this);
				// stop default action
				return false;
			}
		}
	};
}

// generate popUp window
function openPopUp(elem) {
	// get parameters
	var popOptions = elem.getAttribute('rel');
	var popUrl = elem.getAttribute('href');
	// analize parameters
	parameters = popOptions.split(",");
	popWidth = parameters[0];
	popHeight = parameters[1];
	popMode = parameters[2];
	popPosition = parameters[3];
	if (parameters[4]) popUrl = parameters[4];
	// calculate coordinates for centering
	if (popPosition == 'center') {
		posX = (screen.width / 2) - (popWidth / 2);
		posY = (screen.height / 2) - (popHeight / 2);
	} else if (popPosition == 'loose') {
		posX = '';
		posY = '';
	}
	// open in kiosk mode
	if (popMode == 'kiosk') {
		// open window
		popWindow = open(
			popUrl,'popUpWindow', // url & name
			'width=' + popWidth + ',height=' + popHeight + ',' + // dimensions
			'top=' + posY + ',left=' + posX + ',' + // position
			'scrollbars' // window attributes
		);
	}
	// open in full mode
	if (popMode == 'full') {
		// open window
		popWindow = open(
			popUrl,'popUpWindow', // url & name
			'width=' + popWidth + ',height=' + popHeight + ',' + // dimensions
			'top=' + posY + ',left=' + posX + ',' + // position
			'location,menubar' + // decoration
			'resizable,scrollbars,status,toolbar' // window attributes
		);
	}
	// set focus
	popWindow.focus();
}