﻿function ModalBox(block,mensagem) {
    var modal = this;
    this.block;
    this.mensagem;
    this.callbackFechar;
    this.acaoInscreveBolao;
    this.intervaloScroll;

    this.init = function() {
        modal.block = document.getElementById(block);
        modal.mensagem = document.getElementById(mensagem);
        
        new Effect.Opacity(modal.block, { duration: 0, to: 0.0 });
        var tam = modal.getPageSize();

        modal.mensagem.style.left = Math.round((tam[0] / 2) - 193) + "px";
        modal.mensagem.style.top = "100px";//((modal.getWindowHeight() / 2) - 206) + "px";

        modal.block.style.backgroundColor = "#000000";
        modal.block.style.width = tam[0] + "px";
        modal.block.style.height = tam[1] + "px";
        modal.block.style.top = 0;
        modal.block.style.left = 0;
        modal.block.style.position = "absolute";
        modal.block.id = "block";
    }

    this.alert = function(msg, callback) {
        if (document.getElementById("divpoucosplugs") != null)
            document.getElementById("divpoucosplugs").style.display = "none";
        if (document.getElementById("divEsqueciSenha") != null)
            document.getElementById("divEsqueciSenha").style.display = "none";
        if (document.getElementById("confirmarPostagem") != null)
            document.getElementById("confirmarPostagem").style.display = "none";
        if (document.getElementById("regulamentoBolao") != null)
            document.getElementById("regulamentoBolao").style.display = "none";
        if (document.getElementById("popup_aviso") != null)
            document.getElementById("popup_aviso").style.display = "none";
        if (document.getElementById("CancelarConta") != null)
            document.getElementById("CancelarConta").style.display = "none";
        if (document.getElementById("confirmarMsn") != null)
            document.getElementById("confirmarMsn").style.display = "none";

        modal.mensagem.className = "poucosplugsalert";

        document.getElementById("divmensagem").style.display = "block";
        document.getElementById("divmensagem").getElementsByTagName("p")[0].innerHTML = msg;
        modal.mostrarBox(callback);

    }

    this.poucosPlugs = function(callback) {
        modal.mensagem.className = "poucosplugs";
        document.getElementById("divpoucosplugs").style.display = "block";
        document.getElementById("divmensagem").style.display = "none";
        if (document.getElementById("confirmarPostagem") != null)
            document.getElementById("confirmarPostagem").style.display = "none";
        if (document.getElementById("divEsqueciSenha") != null)
            document.getElementById("divEsqueciSenha").style.display = "none";
        if (document.getElementById("regulamentoBolao") != null)
            document.getElementById("regulamentoBolao").style.display = "none";
        if (document.getElementById("popup_aviso") != null)
            document.getElementById("popup_aviso").style.display = "none";
        if (document.getElementById("CancelarConta") != null)
            document.getElementById("CancelarConta").style.display = "none";
        if (document.getElementById("confirmarMsn") != null)
            document.getElementById("confirmarMsn").style.display = "none";
        modal.mostrarBox(callback);
    }

    this.lembrarSenha = function(callback) {
        document.getElementById("divmensagem").style.display = "none";
        document.getElementById("divEsqueciSenha").style.display = "block";
        document.getElementById("formEsqueciSenha").style.display = "block";
        document.getElementById("btvoltar").style.display = "none";
        document.getElementById("mensagemLembrarSenha").innerHTML = "";
        if (document.getElementById("confirmarPostagem") != null)
            document.getElementById("confirmarPostagem").style.display = "none";
        if (document.getElementById("divpoucosplugs") != null)
            document.getElementById("divpoucosplugs").style.display = "none";
        if (document.getElementById("divEsqueciSenha") != null)
            document.getElementById("divEsqueciSenha").style.display = "block";
        if (document.getElementById("popup_aviso") != null)
            document.getElementById("popup_aviso").style.display = "none";
        if (document.getElementById("CancelarConta") != null)
            document.getElementById("CancelarConta").style.display = "none";
       if (document.getElementById("confirmarMsn") != null)
            document.getElementById("confirmarMsn").style.display = "none";
        modal.mensagem.className = "modalbox";
        modal.mostrarBox(callback);
    }

    this.regulamentoBolao = function(lnk, callback) {
        modal.mensagem.className = "poucosplugs";
        if (document.getElementById("confirmarPostagem") != null)
            document.getElementById("confirmarPostagem").style.display = "none";
        if (lnk != undefined && lnk != null) {
            modal.acaoInscreveBolao = lnk.href.replace("javascript:", "");
            document.getElementById("divconcordoregulamento").style.display = "block";
        } else {
            document.getElementById("divconcordoregulamento").style.display = "none";
        }
        document.getElementById("regulamentoBolao").style.display = "block";
        document.getElementById("divpoucosplugs").style.display = "none";
        document.getElementById("divmensagem").style.display = "none";
        if (document.getElementById("popup_aviso") != null)
            document.getElementById("popup_aviso").style.display = "none";
        if (document.getElementById("CancelarConta") != null)
            document.getElementById("CancelarConta").style.display = "none";
        if (document.getElementById("confirmarMsn") != null)
            document.getElementById("confirmarMsn").style.display = "none";
        modal.mostrarBox(callback);
    }
    
    this.Inscrever = function() {
        eval(modal.acaoInscreveBolao);
    }

    this.confirmarPostagem = function(callback) {
        if (document.getElementById("divpoucosplugs") != null)
            document.getElementById("divpoucosplugs").style.display = "none";
        if (document.getElementById("divmensagem") != null)
            document.getElementById("divmensagem").style.display = "none";
        if (document.getElementById("divEsqueciSenha") != null)
            document.getElementById("divEsqueciSenha").style.display = "none";
        if (document.getElementById("regulamentoBolao") != null)
            document.getElementById("regulamentoBolao").style.display = "none";
        if (document.getElementById("popup_aviso") != null)
            document.getElementById("popup_aviso").style.display = "none";
        if (document.getElementById("CancelarConta") != null)
            document.getElementById("CancelarConta").style.display = "none";
       if (document.getElementById("confirmarMsn") != null)
            document.getElementById("confirmarMsn").style.display = "none";
        document.getElementById("confirmarPostagem").style.display = "block";
        modal.mostrarBox(callback);
    }
    
    this.confirmarMsn = function(callback) {
        if (document.getElementById("divpoucosplugs") != null)
            document.getElementById("divpoucosplugs").style.display = "none";
        if (document.getElementById("divmensagem") != null)
            document.getElementById("divmensagem").style.display = "none";
        if (document.getElementById("divEsqueciSenha") != null)
            document.getElementById("divEsqueciSenha").style.display = "none";
        if (document.getElementById("regulamentoBolao") != null)
            document.getElementById("regulamentoBolao").style.display = "none";
        if (document.getElementById("popup_aviso") != null)
            document.getElementById("popup_aviso").style.display = "none";
        if (document.getElementById("CancelarConta") != null)
            document.getElementById("CancelarConta").style.display = "none";
        if (document.getElementById("confirmarPostagem") != null)
            document.getElementById("confirmarPostagem").style.display = "none";
        document.getElementById("confirmarMsn").style.display = "block";
        modal.mostrarBox(callback);
    }

    this.mostrarAviso = function(callback) {
        modal.mensagem.className = "popup_aviso";
        if (document.getElementById("divpoucosplugs") != null)
            document.getElementById("divpoucosplugs").style.display = "none";
        if (document.getElementById("divmensagem") != null)
            document.getElementById("divmensagem").style.display = "none";
        if (document.getElementById("divEsqueciSenha") != null)
            document.getElementById("divEsqueciSenha").style.display = "none";
        if (document.getElementById("regulamentoBolao") != null)
            document.getElementById("regulamentoBolao").style.display = "none";
        if (document.getElementById("confirmarPostagem") != null)
            document.getElementById("confirmarPostagem").style.display = "none";
        if (document.getElementById("CancelarConta") != null)
            document.getElementById("CancelarConta").style.display = "none";
        if (document.getElementById("confirmarMsn") != null)
            document.getElementById("confirmarMsn").style.display = "none";
            document.getElementById("popup_aviso").style.display = "block";
        modal.mostrarBox(callback);
        
        document.getElementById("popup_fechar").style.visibility = 'hidden';
    }

    this.CancelarConta = function(callback) {
        if (document.getElementById("divpoucosplugs") != null)
            document.getElementById("divpoucosplugs").style.display = "none";
        if (document.getElementById("divmensagem") != null)
            document.getElementById("divmensagem").style.display = "none";
        if (document.getElementById("divEsqueciSenha") != null)
            document.getElementById("divEsqueciSenha").style.display = "none";
        if (document.getElementById("regulamentoBolao") != null)
            document.getElementById("regulamentoBolao").style.display = "none";
        if (document.getElementById("confirmarPostagem") != null)
            document.getElementById("confirmarPostagem").style.display = "none";
        if (document.getElementById("popup_aviso") != null)
            document.getElementById("popup_aviso").style.display = "none";
        if (document.getElementById("confirmarMsn") != null)
            document.getElementById("confirmarMsn").style.display = "none";
        document.getElementById("CancelarConta").style.display = "block";
        modal.mostrarBox(callback);
        modal.mensagem.className = "cancelarconta";
    }


    this.mostrarBox = function(callback) {
        modal.block.style.display = "block";
        new Effect.Opacity(this.block, { duration: 1, from: 0.0, to: 0.6, afterFinish: function() { modal.mensagem.style.display = "block"; if (callback != undefined) { callback() } } });
        //modal.mensagem.style.top = pos.toString() + "px";
        intervaloScroll = setInterval(scroll, 200);
    }

    this.ocultarBox = function() {
        modal.mensagem.style.display = "none";
        new Effect.Opacity(modal.block, { duration: 1, from: 0.6, to: 0.0, afterFinish: function() { modal.block.style.display = "none"; if (modal.callbackFechar != undefined) { modal.callbackFechar() } } });
        clearInterval(intervaloScroll);
    }

    var scroll = function() {
        var pos = document.documentElement.scrollTop + 100;
        new Effect.Move(modal.mensagem, {y: pos, x: 439, mode: "absolute"});
    }

    this.getPageSize = function() {
        var xScroll, yScroll;

        if (window.innerHeight && window.scrollMaxY) {
            xScroll = window.innerWidth + window.scrollMaxX;
            yScroll = window.innerHeight + window.scrollMaxY;
        } else if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac
            xScroll = document.body.scrollWidth;
            yScroll = document.body.scrollHeight;
        } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
            xScroll = document.body.offsetWidth;
            yScroll = document.body.offsetHeight;
        }

        var windowWidth, windowHeight;

        if (self.innerHeight) {	// all except Explorer
            if (document.documentElement.clientWidth) {
                windowWidth = document.documentElement.clientWidth;
            } else {
                windowWidth = self.innerWidth;
            }
            windowHeight = self.innerHeight;
        } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
            windowWidth = document.documentElement.clientWidth;
            windowHeight = document.documentElement.clientHeight;
        } else if (document.body) { // other Explorers
            windowWidth = document.body.clientWidth;
            windowHeight = document.body.clientHeight;
        }

        // for small pages with total height less then height of the viewport
        if (yScroll < windowHeight) {
            pageHeight = windowHeight;
        } else {
            pageHeight = yScroll;
        }

        // for small pages with total width less then width of the viewport
        if (xScroll < windowWidth) {
            pageWidth = xScroll;
        } else {
            pageWidth = windowWidth;
        }

        return [pageWidth, pageHeight];
    }

    this.getWindowHeight = function() {
        var janela;

        if (parseInt(navigator.appVersion) > 3) {
            if (navigator.appName == "Netscape") {
                janela = window.innerHeight;
            }
            if (navigator.appName.indexOf("Microsoft") != -1) {
                janela = document.body.offsetHeight;
            }
        }
        return janela;
    }
    
    if (window.addEventListener)
        window.addEventListener("load", this.init, false);
    else
        window.attachEvent("onload", this.init);

}

function fecharDHTML(){
    box.ocultarBox();
}