
var popupWindow;

//Opens a popup window to the selected url
//All the popups opened by this method in the same window.
function openFinderPopup(url) {
	if (popupWindow == undefined){
		//First time the popup is created
		popupWindow = openNewWindow(url);
	} else {
		try {			
			//Try to use the previously used window
			popupWindow.location = url;
		} catch (error) {
			//The user closed the popup, a new one in created
			popupWindow = openNewWindow(url);
		}
	}
	popupWindow.focus();
	return false;
}

function openNewWindow(url){
	//let the size of the new window be two thirds of the current one
	if (window.outerWidth != null) {
		var width = ((window.outerWidth) / 3) * 2;
		var height = ((window.outerHeight) / 3) * 2;
	} else {
	    //IE
		var width = ((document.body.clientWidth) / 3) * 2;
		var height = ((document.body.clientHeight) / 3) * 2;
	}
	
	//Now let's display the new window in the center of the screen.
	var left = (screen.width / 2) - (width / 2);
	var top = (screen.height / 2) - (height / 2);

	return window.open(url, "", 
	
	// Size
	"width=" + width + "px," +
	"height=" + height + "px," +
	
	// Position
	"left=" + left + "px," +
	"top=" + top + "px," +
	"screenX=" + left + "px," +
	"screenY=" + top + "px," +

	// Remove bars etc.
	"menubar=no," +
	"location=no," +
	"status=no," +
	"directories=no," +
	"toolbar=no," +

	// Sizing issues
	"scrollbars=yes," +
	"resizable=yes," +
	
	// No minimise/maximise button?
	"dialog=yes"
	);
}