// Dependências: (nenhumas);
//
// Rotinas para "popups".
//

var popwnd = null	// Aponta para a última janela aberta.

// Abre uma janela em cima das outras.
// NOTA: A função não retorna nenhum valor, porque isso cria problemas com o useo em "href='javascript:...'".
function raisePopup (url, w, h, optNm, optScroll, optResizable, optMenubar, optStatus, optTitle, optTop, optLeft, optMoreFeatures, optStrict) {
	var sw = screen.width, sh = screen.height
	if (!isNaN (w))
		w = Math.round (w)
	else if (w.substr (w.length - 1) == "%")
		w = Math.round ((parseInt (w.substr (0, w.length - 1)) / 100) * sw)
	if (!isNaN (h))
		h = Math.round (h)
	else if (h.substr (h.length - 1) == "%")
		h = Math.round ((parseInt (h.substr (0, h.length - 1)) / 100) * sh)

	var l = !optLeft && optLeft != 0 ? Math.round (optLeft != undefined || (sw - w) / 2) : optLeft
	var t = !optTop && optTop != 0 ? Math.round (optTop != undefined  || (sh - h) / 2) - 30 : optTop

	optScroll = optScroll ? "yes" : "no"
	optResizable = optResizable ? "yes" : "no"
	optMenubar = optMenubar ? "yes" : "no"
	optStatus = optStatus ? "yes" : "no"
	optTitle = optTitle ? "yes" : "no"
	optMoreFeatures ? (optMoreFeatures = "," + optMoreFeatures) : optMoreFeatures = ""
	optNm || (optNm = "jpop")

	var props = 'height=' + h + ',width=' + w + ',top=' + t + ',left=' + l + ',scrollbars=' + optScroll + ',resizable=' + optResizable + ',menubar=' + optMenubar + ",status=" + optStatus + ",titlebar=" + optTitle + optMoreFeatures
	
	if (url)
		optStrict || (url += (url.lastIndexOf ("?") < 0 ? "?" : "&") + "w=" + w + "&h=" + h)
	else
		url = "about:blank"
	popwnd = window.open (url, optNm, props)
	try {	popwnd.window.focus ()	}	catch (e) {}
}

// Retorna a janela 'nm' ainda que a tenha de fechar (se já existir) e voltar a abrir.
function getWnd (nm, url, w, h, optScroll, optResizable, optMenubar, optStatus, optTitle, optTop, optLeft, optMoreFeatures) {
	for (var i = 0; i < 3; ++i) {
		raisePopup (url, w, h, nm, optScroll, optResizable, optMenubar, optStatus, optTitle, optTop, optLeft, optMoreFeatures)
		try {
			if (popwnd.document.location) return
		}
		catch (e) {
			try {	popwnd.close ()	} catch (e) {}
		}
	}
	if (popwnd) try {	popwnd.close (); popwnd = null	} catch (e) {}
}