﻿var valCookie = '';
var valwidgetesp = '';
$(document).ready(function () {
valCookie = $.cookie('dvoto');
if (valCookie == null)
valCookie = '';
$(".votacao").each(function () {
var valor = this.id.replace('HKVotoPos', '').replace('HKVotoNeg', '');
if (valCookie.indexOf(valor) == -1) {
if (this.id.indexOf('Pos') >= 0) {
$(this).append("<img id='imgvotopos" + valor + "' src='/images/pos.gif' border='0' alt='positivo' class='voto'/>");
}
else {
$(this).append("<img id='imgvotoneg" + valor + "' src='/images/neg.gif' border='0' alt='negativo' class='voto'/>");
}
}
else {
if (this.id.indexOf('Pos') >= 0) {
$(this).append("<img id='imgvotopos" + valor + "' src='/images/dpos.gif' border='0' alt='positivo' class='voto'/>");
}
else {
$(this).append("<img id='imgvotoneg" + valor + "' src='/images/dneg.gif' border='0' alt='negativo' class='voto'/>");
}
}
});

$("#txtpesquisa").focus(function () {
if ($(this).val() == this.defaultValue) {
$(this).val("");
}
}
); $("#txtpesquisa").blur(function () {
if ($.trim($(this).val()) == "") {
$(this).val(this.defaultValue);
}
}
);

$(".imgPost120").lazyload();
$(".imgPost75").lazyload();
$(".thumbnail").lazyload();
$(".thumbnailb").lazyload();
$(".imgvidrelyt").lazyload();

$(".topsocial").empty();
$(".topsocial").append(
"<img onclick=\"bookmarkDigNow()\" style=\"cursor:pointer\" border=\"0\" alt=\"Favorite\" src=\"/images/favorite.gif\">" +
"<a href=\"javascript:abrirjanelasoc('http://twitter.com/share?url=" + codificarinf(window.location.href, 0) + "', 'Twitter', 470, 560);\" rel=\"nofollow\"><img src=\"/images/twitter.gif\" alt=\"Twitter\" class=\"m1\"  border=\"0\"></a>" +
"<a href=\"javascript:abrirjanelasoc('http://promote.orkut.com/preview?nt=orkut.com&tt=" + codificarinf(window.document.title, 1) + "&du=" + codificarinf(window.location.href, 0) + "', 'Orkut', 490, 820);\" rel=\"nofollow\"><img src=\"/images/orkut.gif\" alt=\"Orkut\" class=\"m1\" border=\"0\"></a>" +
"<a href=\"javascript:abrirjanelasoc('http://www.facebook.com/sharer.php?u=" + codificarinf(window.location.href, 0) + "&t=" + codificarinf(window.document.title, 1) + "', 'Facebook', 490, 798);\" rel=\"nofollow\"><img src=\"/images/facebook.gif\" alt=\"Facebook\" class=\"m1\" border=\"0\"></a>" +
"<div style=\"padding-left: 5px; width: 32px; display: inline-block; height: 20px; vertical-align: middle\">" +
"<div class=\"g-plusone\" data-size=\"medium\" data-count=\"false\"></div>" +
"</div>"
);
carregarlistavideos();
carregarcatvotoblog();
carregartopt();

if (window.location.href.toLowerCase().indexOf("www.dignow.org/post/") > -1 && $('#divlnrbox') != null && $('#divlnrbox') != undefined && $('#divlnrbox').length > 0) {
var buttonlnrdisplayed = false;
$('#divlnrbox').empty();
$('#divlnrbox').append("<div id=\"lnrboxrel\"><div class=\"lnrboxx\" onclick=\"lnrclosewindow();\"></div><div class=\"lnrboxtit\">Recomendamos tamb&eacute;m a leitura de:</div><div id=\"lnrboxcontent\"></div></div>");
$('.postmrel').each(function (chave, objeto) {
if (chave == 2) {
var valinfrel = $('a[class!="votacao"]', objeto);
if (valinfrel != null && valinfrel != undefined) {
if (valinfrel.length == 1) {
if (valinfrel[0] != null && valinfrel[0] != undefined) {
$('#lnrboxcontent').empty();
$('#lnrboxcontent').append($(valinfrel[0]).clone());
}
}
}
}
});

$(window).scroll(function () {
var localdisplayed = ($(window).scrollTop() >= 350)
if (buttonlnrdisplayed != localdisplayed) {
if (localdisplayed) {
$('#divlnrbox').stop().animate({ width: "360px" }, 1500);
}
else {
$('#divlnrbox').stop().animate({ width: "0px" }, 1500);
}
buttonlnrdisplayed = localdisplayed;
}
});
}

});
function votar(valor, tipo) {
if (valCookie.indexOf(valor) == -1) {
$.ajax({
type: "POST",
url: "/DigNowWebService.asmx/GetVoto",
data: "{valor:'" + valor + "', tipo:'" + tipo + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (numero) {
valCookie = valCookie + valor + ",";
$.cookie('dvoto', valCookie, { expires: 3 });
$("#HKVotoPos" + valor).empty();
$("#HKVotoPos" + valor).append("<img id='imgvotopos" + valor + "' src='/images/dpos.gif' border='0' alt='positivo' class='voto'/>");
$("#HKVotoNeg" + valor).empty();
$("#HKVotoNeg" + valor).append("<img id='imgvotoneg" + valor + "' src='/images/dneg.gif' border='0' alt='negativo' class='voto'/>");
$("#LblVNumPos" + valor).empty();
$("#LblVNumPos" + valor).append(numero.d.split('-')[0]);
$("#LblVNumNeg" + valor).empty();
$("#LblVNumNeg" + valor).append(numero.d.split('-')[1]);
}
});
}
}
function abrirjanela(valor) {
var pheight = 250;
var pwidth = 500;
var ptitle = "Em Desenvolvimento";
var ppagina = "/construc.aspx"

if (valor == "contato") {
pheight = 400;
pwidth = 600;
ptitle = "Contato";
ppagina = "/contato.aspx?tipo=1";
}
else
if (valor == "reportar-abuso") {
pheight = 550;
pwidth = 600;
ptitle = "Reportar Abuso";
ppagina = "/contato.aspx?tipo=2";
}
else
if (valor == "privacidade") {
pheight = 400;
pwidth = 600;
ptitle = "Pol&iacute;tica de Privacidade";
ppagina = "/politicaprivacidade.aspx";
}
else
if (valor == "termo-uso") {
pheight = 400;
pwidth = 600;
ptitle = "Termo de Uso";
ppagina = "/termouso.aspx";
}
else
if (valor == "registrar") {
pheight = 550;
pwidth = 600;
ptitle = "Cadastrar Blog";
ppagina = "/contato.aspx?tipo=3";
}
else
if (valor == "botoes") {
pheight = 420;
pwidth = 620;
ptitle = "Botoes DigNow";
ppagina = "/botoesdignow.htm";
}
else
if (valor == "widget" || valor == "widgetb") {
if (valor == 'widgetb') {
valwidgetesp = '1';
}
else {
valwidgetesp = '';
}
pheight = 520;
pwidth = 780;
ptitle = "Widget";
ppagina = "/widget/widget.htm";
}

$("#janeladialogo").empty();
$("#janeladialogo").append("<iframe id='modalIframeDigNowId' width='100%' height='100%' marginWidth='0' marginHeight='0' frameBorder='0' scrolling='auto' />");
$("#modalIframeDigNowId").attr("src", ppagina);
$("#janeladialogo").dialog({ height: pheight, width: pwidth, modal: true, resizable: true, title: ptitle });
}
function codificarinf(valor, opcao) {
if (opcao == 0) {
return encodeURIComponent(encodeURI(decodeURI(valor)).replace(/[%]/g, "%25"));
} else
if (opcao == 1) {
return encodeURIComponent(encodeURIComponent(decodeURI(valor.replace(/[%]/g, ""))));
}
}
function abrirjanelasoc(valor, titulo, altura, largura) {
var dleft = (screen.width / 2) - (largura / 2);
var dtop = (screen.height / 2) - (altura / 2);
window.open(valor, titulo, 'height=' + altura + ',Width=' + largura + ',top=' + dtop + ',left=' + dleft + ',location=1,status=1,resizable=1,directories=0,menubar=0,toolbar=0');
}
function carregarlistavideos() {
var pesqvideo = '';
if (window.listaqvyt != null) {
pesqvideo = window.listaqvyt;
}
if (window.location.href.toLowerCase().indexOf("www.dignow.org/post/") > -1 && pesqvideo != null && pesqvideo != undefined && pesqvideo != '') {
$.ajax({
url: "http://gdata.youtube.com/feeds/api/videos?alt=json&vq=" + pesqvideo + "&orderby=relevance&max-results=4&lr=pt",
dataType: "jsonp",
success: function (dados) {
if (dados != null && dados != undefined && dados.feed != null && dados.feed != undefined && dados.feed.entry != null && dados.feed.entry != undefined && dados.feed.entry.length > 0) {
var tempcodvideo = "<div class=\"featured\"><div class=\"titlehead\">V&#237;deos Relacionados:</div></div><br clear=\"all\"><div style=\"margin: 0 20px;\"><div id=\"divvidfull\" style=\"text-align:center;margin: 0 0 15px 0\"></div>";
var firstvideo;
$.each(dados.feed.entry, function (indice, valor) {
if (valor != null && valor != undefined) {
var videotitulo = "";
var videolink = "";
var videoduracao = "";
var videoimagem = "";
if (valor.title != null && valor.title != undefined && valor.title.$t != null && valor.title.$t != undefined) {
videotitulo = valor.title.$t;
if (videotitulo.length > 45) {
videotitulo = videotitulo.substr(0, 42) + '...';
}
}
if (valor.media$group != null && valor.media$group != undefined) {
if (valor.media$group.yt$duration != null && valor.media$group.yt$duration != undefined && valor.media$group.yt$duration.seconds != null && valor.media$group.yt$duration.seconds != undefined) {
var videominutos = Math.floor(valor.media$group.yt$duration.seconds / 60);
var videosegundos = valor.media$group.yt$duration.seconds - (videominutos * 60);
videominutos = String(videominutos);
videosegundos = String(videosegundos);
if (videominutos.length < 2) {
if (videominutos.length == 0) {
videominutos = '00';
}
else {
videominutos = '0' + videominutos;
}
}
if (videosegundos.length < 2) {
if (videosegundos.length == 0) {
videosegundos = '00';
}
else {
videosegundos = '0' + videosegundos;
}
}
videoduracao = videominutos + ':' + videosegundos;
}
if (valor.media$group.media$thumbnail != null && valor.media$group.media$thumbnail != undefined && valor.media$group.media$thumbnail.length > 0) {
var ithumbnail = 0;
if (valor.media$group.media$thumbnail.length >= 3) {
ithumbnail = 2;
}
if (valor.media$group.media$thumbnail[ithumbnail].url != null && valor.media$group.media$thumbnail[ithumbnail].url != undefined) {
videoimagem = valor.media$group.media$thumbnail[ithumbnail].url;
}
}
if (valor.media$group.media$content != null && valor.media$group.media$content != undefined && valor.media$group.media$content.length > 0 && valor.media$group.media$content[0].url != null && valor.media$group.media$content[0].url != undefined) {
videolink = valor.media$group.media$content[0].url;
}
}
tempcodvideo = tempcodvideo + "<div class=\"thumbvid\"><div class=\"thumb\"><a href=\"javascript:carregarvideo('" + videolink + "', 1);\"><img src=\"" + videoimagem + "\" width=\"130\" height=\"97\" class=\"imgvidrelyt\" /><div class=\"text\">" + videoduracao + "</div><div class=\"imgplay\"><img src=\"/images/imgplay.png\" width=\"24\" height=\"24\" /></div></a></div><div class=\"titvid\"><a href=\"javascript:carregarvideo('" + videolink + "', 1);\">" + videotitulo + "</a></div></div>";
if (indice == 0) {
firstvideo = videolink;
}
}
});
tempcodvideo = tempcodvideo + "</div><br clear=\"all\">";
$("#divvidrelac").append(tempcodvideo);
}
}
});
}
}
function carregarvideo(infurl, valstarted) {
if (valstarted != null && valstarted != undefined && valstarted >= 0 && valstarted <= 1) {
$("#divvidfull").empty();
$("#divvidfull").append("<object style=\"height: 390px; width: 640px\"><param name=\"movie\" value=\"" + infurl + "&version=3&autoplay=" + valstarted + "&fs=1&feature=player_embedded\"></param><param name=\"allowFullScreen\" value=\"true\"></param><param name=\"allowScriptAccess\" value=\"always\"></param><embed src=\"" + infurl + "&version=3&autoplay=" + valstarted + "&fs=1&feature=player_embedded\" type=\"application/x-shockwave-flash\" allowfullscreen=\"true\" allowScriptAccess=\"always\" width=\"480\" height=\"415\"></embed></object>");
}
}

function carregarcatvotoblog() {
if ($(".divcatpontostotb") != null && $(".divcatpontostotb") != undefined) {
$(".divcatpontostotb").each(function (chave, objeto) {
var valcatpontosb = "";
if (objeto.innerText != null && objeto.innerText != undefined) {
valcatpontosb = objeto.innerText;
}
else{
valcatpontosb = objeto.textContent;
}
if (valcatpontosb != null && valcatpontosb != undefined && valcatpontosb != "" && valcatpontosb.length > 13) {
objeto.innerHTML = "<img src=\"/images/gostei2.gif\" class=\"catvoto\" alt=\"gostei\" /> <span style=\"color:#37BD18;font-size:10pt;padding-right:5px;font-weight:bold\">" + valcatpontosb.substr(13) + "</span><span class=\"tool\"><img src=\"/images/help.png\" class=\"catvoto\" alt=\"gostei\" /><span class=\"tip\"><span style=\"font-weight:bold;text-decoration:underline\">Widget Voto</span><br />Os votos são utilizados para classificar seu blog no DigNow.<br /><span style=\"font-weight:bold\">Para adicionar este Widget, clique na opção \"RECURSOS PARA SEU BLOG\".</span></span></span>";
}
});        
}
}

function lnrclosewindow() {
$('#divlnrbox').stop().animate({ width: "0px" }, 1500);
}

function carregartopt() {
if ($("#digtopt1dig") != null && $("#digtopt1dig") != undefined &&
window.listArrThtm != null && window.listArrThtm != undefined &&
window.listArrTurl != null && window.listArrTurl != undefined &&
window.listArrThtm.length == window.listArrTurl.length) {
$("#digtopt1dig").empty();
$("#digtopt1dig").append("Assuntos relacionados:");
$(window.listArrThtm).each(function (chave, objeto) {
$("#digtopt1dig").append("&nbsp;<a href=\"http://www.dignow.org/assunto/" + window.listArrTurl[chave].toLowerCase() + ".html\">" + objeto + "</a>&nbsp;|");
});
}
}

function bookmarkDigNow() {
if (window.sidebar && navigator.userAgent.match(/firefox/i)) {
window.sidebar.addPanel(document.title, location.href, "");
}
else if (window.external && !navigator.userAgent.match(/chrome/i)) {
window.external.AddFavorite(location.href, document.title);
}
else if (window.opera && window.print) {
return true;
}
else {
alert('Pressione CTRL+D para salvar o DigNow em seus favoritos');
return false;
}
}

