// library for managing pop-up windows; 

var pWin = null;
var sDisablePopupMessage = "You are using a pop-up blocker. Please set your pop-up blocker to allow pop-ups from unseen.tv";
	
function closeModalPopups() {
	if(pWin != null && !pWin.closed){  // to close everything but help window use  && pWin.name.indexOf('help') == -1
		pWin.close();
	}
}

function newWin(winurl, winname, w, h, center, scroll, showMenu, showStatus, showToolbar, showLocation) {
	try {
	    if(!pWin || pWin.closed) {
			pWin = openWin(winurl, winname, w, h, center, scroll, showMenu, showStatus, showToolbar, showLocation) ;
		} else if (pWin.name != winname) {
			pWin.close();
			pWin = openWin(winurl, winname, w, h, center, scroll, showMenu, showStatus, showToolbar, showLocation) ;
		}
		pWin.focus();
	}catch(err){ //suppress Access Denied error when running over SSL
		return;  
	}
}

function openWin(page, winname, w, h, center, scroll, showMenu, showStatus, showToolbar, showLocation){
	var lpos = 125;
	var tpos = 100;
	var centerwin = (center==true)? true : false;
	var scrollwin = (scroll==true || scroll=='yes')? 'yes' : 'no';

	var showMenuBar = (showMenu==true || showMenu=='yes')? 'yes' : 'no';
	var showStatusBar = (showStatus==true || showStatus=='yes')? 'yes' : 'no';
	var showToolBar = (showToolbar==true || showToolbar=='yes')? 'yes' : 'no';
	var showLocBar = (showLocation==true || showLocation=='yes')? 'yes' : 'no';

	if(centerwin){
		var cw = self.screen.availWidth;
		var ch = self.screen.availHeight;
		h = (h > ch * .9)? ch * .9 : h;
		lpos = (cw-w)/2;
		tpos = (ch-h)/6;
	}	
	var oWin = window.open(page, winname,'width='+w+',height='+h+',left='+lpos+',top='+tpos+',menubar='+showMenuBar+',status='+showStatusBar+',location='+showLocBar+',toolbar='+showToolBar+',scrollbars='+scrollwin+',resizable=yes');
	if (oWin == null)
	{
		alert(sDisablePopupMessage);
	}
	return oWin;
}


if (typeof(window.opener) == 'undefined' && typeof(closeModalPopups) == 'function') {  // close popups unless we are in a popup or the popup is help
	window.onunload = closeModalPopups;  
}

function openInMainWindow(url) {
	opener.location=url;
	opener.focus(); 
}