// Customizable popup window
function Popup(url, name, w, h, attribs, returnWin) {
	if(w == "auto") {
		var x = "";
	} else {
		var winX = (screen.availWidth - w) / 2;
		if(winX < 0) winX = 0;
		if(w > screen.width) w = screen.width;
		var x = "width=" + w + ",left=" + winX + ",";
	}
	
	if(h == "auto") {
		var y = "";
	} else {
		var winY = (screen.availHeight - h) / 2;
		if(winY < 0) winY = 0;
		if(h > screen.height) h = screen.height;
		var y = "height=" + h + ",top=" + winY;
	}
	
	// set attributes
	attribs = !attribs ? "" : attribs = "," + attribs;
	
	// popup window
	var win = window.open(
		url, name,
		x + y + attribs
	);
	
	// if popup blocking is on in mozilla, win will be null
	if(!win) return true;
	
	// bring window to front
	win.focus();
	
	if(returnWin) return win; // return pointer to window
	else return false;
}

// Non-customized window (like target="_blank")
Popup.Normal = function(url) {
	var win = open(url);
	return !win;
}

// reusable window (like using the same target)
Popup.Reusable = function(url) {
	var win = open(url, "UrecReusablePopup");
	if(!win) return true;
	win.focus();
	return false;
}

// Fitness description "card"
Popup.FitnessCard = function(url) {
	return Popup(url,'iCard', 640, 300, 'scrollbars=yes,menubar=yes,toolbar=yes');
}

// Frontpage news window
Popup.NewsBox = function(url) {
	window.name = "urec";
	return Popup(url,'newsbox', 420, 260, 'scrollbars=yes,status=yes');
}

// Keep some legacy popup functions for the time being...
function newsBox(url) { return Popup.NewsBox(url); }
function openWin(url,name,w,h,attribs) { return Popup(url,name,w,h,attribs); }
function imWin(url) { return Popup(url,'imPopup',400,300,'scrollbars=yes'); }

