var credWin = null;
var faqWin = null;
var rpqWin = null;
var cnqWin = null;
var popWin = null;
var queWin = null;
var trustWin = null;

function launchCenter(url, name, width, height, fromPopup) {
	var str = "location=no,menubar=no,resizable=no,"
	str += "height=" + height;
	str += ",width=" + width;

	if (window.screen) {
		var ah = screen.availHeight - 30;
		var aw = screen.availWidth - 10;

		var xc = (aw - width) / 2;
		var yc = (ah - height) / 2;

		if(fromPopup) { xc+=20; yc+=20; }

		str += ",left=" + xc + ",screenX=" + xc;
		str += ",top=" + yc + ",screenY=" + yc;
  	}
	return window.open(url, name, str);
}

var WIDTH_FIXUP = 0;
var HEIGHT_FIXUP = 0;

function showFAQ(faq) {
	if(!faq) faq = 0;
	if(!(faqWin && !faqWin.closed))
		faqWin = launchCenter("faq/index.php?faq=" + faq, "", 700 - WIDTH_FIXUP , 376 - HEIGHT_FIXUP);
}

function showTrustPopup(trustCtx) {
	if(!(trustWin && !trustWin.closed))
		trustWin = launchCenter("trust/index.php?trustCtx=" + trustCtx, "", 700 - WIDTH_FIXUP , 376 - HEIGHT_FIXUP);
}


function showCNQ(fromPopup) {
	if(!(cnqWin && !cnqWin.closed))
		faqWin = launchCenter( (fromPopup ? "../" : "") + "cnq/index.php", "", 700 - WIDTH_FIXUP , 376 - HEIGHT_FIXUP, fromPopup);
}

function showCredentials(fromPopup) {
	if(!(credWin && !credWin.closed))
		credWin = launchCenter( (fromPopup ? "../" : "") + "cred/index.php", "", 586 - WIDTH_FIXUP , 376 - HEIGHT_FIXUP, fromPopup);
}

function showRPQ(brand) {
	if(brand!='') 
		rpq_src="rpq/index.php?brand="+brand;
	else
		rpq_src="rpq/index.php";

	if(!(rpqWin && !rpqWin.closed))
		rpqWin = launchCenter(rpq_src , "", 626 - WIDTH_FIXUP, 376 - HEIGHT_FIXUP);
	else
		rpqWin.location.href = rpq_src;
}

function showQuest() {
	if(!(queWin && !queWin.closed))
		queWin = launchCenter("quest/index.php", "", 488 - WIDTH_FIXUP , 342 - HEIGHT_FIXUP);
}

function showPOP(context, fromPopup) {
	var u = fromPopup ? "../popup/index.php?ctx=" : "popup/index.php?ctx=";
	if(!(popWin && !popWin.closed))
		popWin = launchCenter(u + context, "", 586 - WIDTH_FIXUP , 376 - HEIGHT_FIXUP);
}
