﻿PublicoScripts.Popup =
{
    conObj: "",
    createHTMLContent: function (url, w, h) {
        var container = document.getElementById("container")
        if (!container) {
            var container = document.createElement('div');
            container.id = "container";
            container.className = "container";
            container.style.width = w + "px";
            container.style.height = h + "px";
            var body = document.getElementsByTagName('body')[0];
            body.appendChild(container);
        } else {
            container.style.width = w + "px";
            container.style.height = h + "px";
        }

        var sText = "<img src=\"/img/loading4.gif\" alt=\"\" style=\"padding-top:" + ((h / 2) - 64) + "px;\" />";
        container.innerHTML = sText;

        var myIframe = document.getElementById("content")
        if (!myIframe) {
            var myIframe = document.createElement("iframe");
            myIframe.id = "content";
            myIframe.style.position = "absolute";
            myIframe.style.left = "-999px";
            myIframe.style.width = "0px";
            myIframe.style.height = "0px";

            var body = document.getElementsByTagName('body')[0];
            PublicoScripts.Methods.eventPush(myIframe, 'load', function () {
               document.getElementById("container").innerHTML = "<a class=\"topright\" href=\"\" title=\"fechar\" onclick=\"PublicoScripts.Popup.closePopup();return false;\">Fechar</a><br clear=\"all\" />" + "<img src='" + unescape(decodeURI(url.split("/pages/capa.aspx?l=")[1])) + "' />";
               try { $get("titleContainer").innerHTML = articleTitle; } catch (e) { }
            });
            body.appendChild(myIframe);
            myIframe.src = url;
        } else {
            myIframe.src = url;
        }

        this.newBloc("container");
        PublicoScripts.Methods.doPageCount("POPUP");
    },
    newBloc: function (containerName) {
        var container = document.getElementById(containerName);
        if (container) {
            var wSize = this.getWindowSize();
            var contWidth = this.getObjectWidth(container);

            container.style.left = (wSize.w / 2) - (parseInt(contWidth.w) / 2) + "px";
            container.style.top = (wSize.h / 2) - (parseInt(contWidth.h) / 2) + "px";

            this.setBackImg();
            container.style.display = "block";
            container.style.zIndex = 100;
            conObj = container;
        }
    },
    getWindowSize: function () {
        var winSize = new Object();
        var wHeigth = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight;
        var wWidth = document.body.clientWidth;
        winSize.h = wHeigth;
        winSize.w = wWidth;
        return winSize;
    },
    getObjectWidth: function (container) {
        var contWidth = new Object();
        if (container.style.width) {
            w = container.style.width;
        } else {
            container.style.left = "-900px";
            container.style.display = "block";
            w = container.offsetWidth;
            container.style.display = "none";
        }

        if (container.style.height) {
            h = container.style.height;
        } else {
            container.style.left = "-900px";
            container.style.display = "block";
            h = container.offsetHeight;
            container.style.display = "none";
        }

        contWidth.w = w;
        contWidth.h = h;
        return contWidth;
    },
    setBackImg: function () {
        var overlay = document.getElementById("overLayer");
        if (!overlay) {
            var overlay = document.createElement('div');
            overlay.id = "overLayer";
            overlay.style.position = "absolute";
            overlay.style.top = 0;
            overlay.style.left = 0;
            overlay.style.opacity = ".5";
            overlay.style.MozOpacity = ".5"
            overlay.style.filter = "alpha(opacity='50')";
            overlay.style.zIndex = 50;

            overlay.style.background = "url(/img/transparent.png)";
            overlay.style.width = "100%";
            overlay.style.height = document.body.clientHeight + "px";
            var body = document.getElementsByTagName('body')[0];
            body.appendChild(overlay);
        } else {
            overlay.style.display = "block";
        }
    },
    closePopup: function () {
        var overlay = document.getElementById("overLayer");
        if (overlay) {
            overlay.style.display = "none";
            conObj.style.display = "none";
            conObj.innerHTML = "";
        }
    }
}
