function mostraPopupCentro(w, h, url, winName) {
	var y = parseInt((screen.availHeight / 2) - (h / 2) - 22);
	var x = parseInt((screen.width / 2) - (w / 2));

	var scroll = (arguments.length == 5 ? (arguments[4] == 1 ? "yes" : "no") : "no");
	var resize = (arguments.length == 6 ? (arguments[5] == 1 ? "yes" : "no") : "no");

	var win = window.open(url, "_blank", "width=" + w + ",height=" + h + ",top=" + y + ",left=" + x + ",scrollbars=" + scroll + ",resizable=" + resize);
	win.focus();
}

function abreVersaoImpressao() {
	var urlImp = window.location.href;
	var ixSl = urlImp.lastIndexOf("/");
	var ixExt = urlImp.lastIndexOf(".");
	urlImp = urlImp.substring(0, ixSl) +
                "/print_" +
                urlImp.substring(ixSl + 1, ixExt) +
                ".html";

	mostraPopupCentro(760, 460, urlImp, "print-page", 1);
}

function abrePopupEnviaPagEmail(url) {
	url = encodeURIComponent(url);
	mostraPopupCentro(414, 370, "/Mailer/EnviarPagina?url=" + url, "enviaPagEmail");
}

function abrePopupEnviaPagAtualEmail() {
	abrePopupEnviaPagEmail(window.location.href);
}

function abrePopupRevista(codCat) {
	var filtro = (arguments.length > 1 ? arguments[1] : "");
	mostraPopupCentro(960, 680, "/Kaza/Ver/" + codCat + (filtro != "" ? "?f=" + filtro + "&popup=true" : "?popup=true"), "popupEmpresaNaKaza");
}

function abrePopupGadget(codCat) {
	var ctl;
	switch (tipoCat) {
		case "C":
			ctl = "Catalogos";
			break;
		case "O":
			ctl = "Obras";
		default:
			ctl = "Kaza";
	}
	var qs = "popup=true&isGadget=true";
	var filtro = (arguments.length > 1 ? arguments[1] : "");
	mostraPopupCentro(960, 600, "/" + ctl + "/Ver/" + codCat + (filtro != "" ? "?f=" + filtro + "&" + qs : "?" + qs), "popupGadget");
}

function abrePopupObrasRealizadas(codCat) {
	mostraPopupCentro(960, 662, "/Obras/Ver/" + codCat + "?popup=true", "popupObras");
}

function abrePopupEnviaPagFlipEmail() {
	var qs = GetStrippedQS(new Array("popup", "p"));
	qs += (qs != "" ? "&p=" : "?p=") + flippingBook.currentPage;

	abrePopupEnviaPagEmail(location.pathname + qs);
}

function abrePopupIncFavorito(idEmp) {
	mostraPopupCentro(700, 420, "/MeuTecto/AdicEmpresaFavorita?idEmp=" + idEmp, "adicEmpFav");
}

function abrePopupIncAoProjeto() {
	var idCat = flippingBook.catId;
	var pagAtual = flippingBook.pagesNum[flippingBook.currentPage - 1];
	mostraPopupCentro(550, 450, "/MeuTecto/AdicPaginaAoProjeto?idCat=" + idCat + "&pg=" + pagAtual, "adicEmpFav");
}

function solicitaInfo(codCat) {
	var pars = GetQSParameter("f");
	pars = (pars != "" ? "&f=" + pars : "");
	pars += "&p=" + flippingBook.currentPage;

	mostraPopupCentro(414, 325, "/Mailer/SolicitarInfo?cat=" + codCat + pars, "solicInfoEmail");
}