﻿$(function () {
    var url = document.URL;
    if (url == "http://www.diretoriabarretos.pro.br/") {
        AbrePop();
    }
});
function AbrePop() {
    var maskH = $(document).height();
    var maskW = $(window).width();

    $("#mask").css({ 'width': maskW, 'height': maskH });
    $("#mask").fadeIn(1000);
    $('#mask').fadeTo("slow", 0.8);

    var winH = $(window).height();
    var winW = $(window).width();

    $("#JanelaPop").css('top', winH / 2 - $("#JanelaPop").height() / 2);
    $("#JanelaPop").css('left', winW / 2 - $("#JanelaPop").width() / 2);

    $("#JanelaPop").fadeIn(1000);
}
function FecharPop() {
    $("#JanelaPop").hide();
    $("#mask").hide();
}
function CarregaConteudoLinks(Atual, Local) {

    $("#lCom").attr("class", "LinkCategoria");
    $("#lNot").attr("class", "LinkCategoria");

    $(Atual).attr("class", "LinkCategoriaAtivo");

    $("#ConteudoLinks").html("<center><img src='/Content/ajax-loader.gif' style='width:16px; height:11px;' /><br />Carregando</center>");

    if (Local == "1")
        CarregaComunicados();
    else if (Local == "2")
        CarregaNoticias();
}

function CarregaNoticias() {
    var url = "/Principal/GetNoticias";
    $.post(url,
            null,
            function (data) {
                if (data != "null") {

                    $("#ConteudoLinks").html("");

                    var html = "";
                    html += "<table width='100%' border='0'>";
                    html += "<tr>";
                    html += "<th style='border-bottom: solid 2px black; width: 10%; border-right: solid 2px black;text-align: left'>";
                    html += "Data";
                    html += "</th>";
                    html += "<th style='border-bottom: solid 2px black; width: 90%; text-align:left;'>";
                    html += "Titulo";
                    html += "</th>";
                    html += "</tr>";

                    $(data).each(function () {
                        html += "<tr>";
                        html += "<td style='border-bottom: solid 1px black; border-right: solid 1px black; text-align: center'>";
                        html += this.Data;
                        html += "</td>";
                        html += "<td style='border-bottom: solid 1px black;'>";
                        if (this.Tipo == 0)
                            html += "<a class='LinkPost' href='/Uploads/Publicacoes/" + this.ArquivoNome + "'>" + this.Titulo + "</a>";
                        else
                            html += "<a class='LinkPost' href='/Publicacoes/Exibir/" + this.ID + "'>" + this.Titulo + "</a>";
                        html += "</td>";
                        html += "</tr>";
                    });
                    html += "</table>";
                    html += "<br /><div style='width:100%; text-align:right'><a href='/Publicacoes/Lista/1'>Mais Notícias e Reportagens</a></div>";
                    $("#ConteudoLinks").append(html);
                }
                else {
                    $("#ConteudoLinks").html("<center>Nenhuma Notícia ou Reportagem Cadastrada</center>");
                }
            },
            "json"
            );
}

function CarregaComunicados() {
    var url = "/Principal/GetComunicados";
    $.post(url,
            null,
            function (data) {
                if (data != "null") {

                    $("#ConteudoLinks").html("");

                    var html = "";
                    html += "<table width='100%' border='0'>";
                    html += "<tr>";
                    html += "<th style='border-bottom: solid 2px black; width: 10%; border-right: solid 2px black; text-align: left'>";
                    html += "Data";
                    html += "</th>";
                    html += "<th style='border-bottom: solid 2px black; width: 90%; text-align:left;'>";
                    html += "Titulo";
                    html += "</th>";
                    html += "</tr>";

                    $(data).each(function () {
                        html += "<tr>";
                        html += "<td style='border-bottom: solid 1px black; border-right: solid 1px black; text-align: center'>";
                        html += this.Data;
                        html += "</td>";
                        html += "<td style='border-bottom: solid 1px black;'>";
                        if (this.Tipo == 0)
                            html += "<a class='LinkPost' href='/Uploads/Publicacoes/" + this.ArquivoNome + "'>" + this.Titulo + "</a>";
                        else
                            html += "<a class='LinkPost' href='/Publicacoes/Exibir/" + this.ID + "'>" + this.Titulo + "</a>";
                        html += "</td>";
                        html += "</tr>";


                    });
                    html += "</table>";
                    html += "<br /><div style='width:100%; text-align:right'><a href='/Publicacoes/Lista/2'>Mais Comunicados e Editais</a></div>";
                    $("#ConteudoLinks").append(html);
                }
                else {
                    $("#ConteudoLinks").html("<center>Nenhum Comunicado ou Edital Cadastrada</center>");
                }
            },
            "json"
            );
}
function AbrirPop(ID, W, H, tipo) {
    if (tipo == "i") {
        newwindow = window.open('/Banners/PopImagem/' + ID, 'Diretoria Barretos', 'height=' + H + ',width=' + W);
        if (window.focus) { newwindow.focus(); }
    } else if (tipo == "t") {
        newwindow = window.open('/Banners/PopTexto/' + ID, 'Diretoria Barretos', 'height=' + H + ',width=' + W);
        if (window.focus) { newwindow.focus(); }
    }
}
