/**
 * popup.js
 *
 * @example popUp('url','winName','500','400','','');
 * @desc Opens popup with no top/left settings (default)
 *
 * @example popUp('url','winName','500','400','','screen');
 * @desc Opens popup and centers against the screen
 *
 * @example popUp('url','winName','500','400','','browser');
 * @desc Opens popup and centers against the browser window
 */
// http://stackoverflow.com/questions/57652/how-do-i-get-javascript-to-open-a-popup-window-on-the-current-monitor/57684#57684
function popUp(page,name,w,h,features,against){
	if (against == 'screen') {
		// center against screen
		var winl = (window.screen.width - w) / 2;
		var wint = (window.screen.height - h) / 2;
		if (winl < 0) winl = 0;
		if (wint < 0) wint = 0;
		var settings = 'width=' + w + ',' + 'height=' + h + ',' + 'left=' + winl + ',' + 'top=' + wint + ',' + features;
	} else if (against == 'browser') {
		// center against browser
		// set defaults incase none of the below are found (very old browser)
		var winW = 800, winH = 600;
		if (document.body && document.body.offsetWidth) {
			// IE backward-compatibility mode
			winW = document.body.offsetWidth;
			winH = document.body.offsetHeight;
		}
		if (document.compatMode=='CSS1Compat' && document.documentElement && document.documentElement.offsetWidth ) {
			// IE standards mode, document.compatMode=='CSS1Compat'
			winW = document.documentElement.offsetWidth;
			winH = document.documentElement.offsetHeight;
		}
		if (window.innerWidth && window.innerHeight) {
			// Non IE 
			winW = window.innerWidth;
			winH = window.innerHeight;
		}
		var winl = (winW - w) / 2;
		var wint = (winH - h) / 2;
		var settings = 'width=' + w + ',' + 'height=' + h + ',' + 'left=' + winl + ',' + 'top=' + wint + ',' + features;
	} else {
		// default no centering
		var settings = 'width=' + w + ',' + 'height=' + h + ',' + features;
	}
	var name = window.open(page,name,settings);
	name.window.focus();
}
