var newWindow = null;

function closeWindow() {

	if (newWindow != null){
		if(!newWindow.closed)
			newWindow.close();
	} // end if statement

} // end closeWindow()


function popUpWindow(url, popUpWidth, popUpHeight){
	
	closeWindow();
		
	var settings = "";
	settings = "resizable=yes, directories=no, location=no, menubar=no, toolbar=no, scrollbars=yes, status=no, width="+popUpWidth+", height="+popUpHeight+", left=250, top=50";
	newWindow = window.open(url, 'newWindow', settings);
	newWindow.focus();

} // end popUpWindow()

function openPopUp(e) {

	var w = "850";
	var h = "675";

	attribs = this.rel.split(" ");
	if (attribs[1]!=null) {w = attribs[1];}
	if (attribs[2]!=null) {h = attribs[2];}

	popUpWindow(this.href, w, h);

	if (window.event) {
		window.event.returnValue = false;
		window.event.cancelBubble = true;
	} else if (e) {
		e.stopPropagation();
		e.preventDefault();
	} // end if statement

} // openPopUp()


function findPopUps() {

	var popups = document.getElementsByTagName("a");
	for (i=0; i<popups.length; i++) {
		if (popups[i].rel.indexOf("popup") != -1)	{
			popups[i].onclick = openPopUp;
		} // end if statement
	} // end for loop
		
} // end findPopUps()

addEvent(window, 'load', findPopUps, false);

