﻿var rootUrl = "/Mercado/"; var twitterJs = "http://twitter.com/statuses/user_timeline/bastter.json?callback=twitterCallback2&count=5"; var isAuthenticatedCache = undefined; var usuarioID = 0; var t, x; $(function () { isAuthenticated(function () { ChecharNotificacoes() }); AtualizarNovidades(); AtualizarPerfis(); AtualizarGrupos(); AcoesDestaque(); AtualizarEventosGrupos(); $("#txtprocura").unbind("keypress").keypress(function (a) { if (a.keyCode == "13") { Procurar() } }); $("#txtgrupopesquisa").unbind("keypress").keypress(function (a) { if (a.keyCode == "13") { PesquisarGrupos(1) } }); setTimeout("AtualizarTwitter()", 5000); $.preloadImages("icon-alerttop-ok.png", "icon-alerttop-erro.png"); $(document).click(function (a) { if ($(a.target).is("#logo, #logo *")) { return } $("#notificacoes-lista").hide() }) }); function ChangeMenu(a) { $(function () { $menusup = $("#menusuperior"); $menusup.find("li.sfHover").hideSuperfishUl(); $menusup.find("> li").eq(a).showSuperfishUl() }) } function isAuthenticated(a) { ajaxProxy("WsUsuario", "IsAuthenticated", "{}", function (b) { if (b.Error) { } else { isAuthenticatedCache = b.IsAuthenticated; var c = $("#areameuperfil #semperfil"), d = $("#areameuperfil #perfil"), e = $("#acessorapido #links a.icon-sair"); if (isAuthenticatedCache) { usuarioID = b.UsuarioID; c.hide("slow"); d.show("slow"); d.find("div a img").attr("src", b.Imagem); d.children("span#login").html(b.Login); d.children("span#email").html(b.Email); e.show() } else { d.hide("slow"); c.show("slow"); c.children("#txtsenha").unbind("keypress").keypress(function (f) { if (f.keyCode == "13") { Login() } }); e.hide() } return a(isAuthenticatedCache) } }) } function Login() { var e = $("#areameuperfil"); var b = e.children("#semperfil"); var a = b.children("#txtlogin").val(); var c = b.children("#txtsenha").val(); var d = "{login: '" + a + "',password: '" + c + "'}"; b.hide("slow"); $.wait(e.children("#aguarde")); ajaxProxy("WsUsuario", "Login", d, function (f) { $.unwait(e.children("div#aguarde")); if (f.Error) { alert(f.Error) } else { if (f.Return) { alert(f.Return); b.show("slow") } } isAuthenticated(function (g) { }) }) } function Logout() { ajaxProxy("WsUsuario", "Logout", "{}", function (a) { if (a.Error) { alert(a.Error) } else { isAuthenticated(function (b) { }) } }) } function ValidateSession(b, a) { isAuthenticated(function (c) { if (!c) { alertBox("alert", "É necessário fazer login para " + a + "."); $("#txtlogin").focus(); $("#txtlogin").css("border", "solid 1px red"); return } else { b(c) } }) } function AtualizarNovidades() { ajaxProxy("WsSite", "ObterInformacoesSite", "{}", function (a) { if (a.Error) { } else { $("#usuariosonline").html(a.Contadores); if (a.Novidades == "") { $("#novidades").hide() } else { $("#novidades ul").html(a.Novidades); today = new Date(); $("#novidades ul").addClass("bg-" + today.getDay()); blinkIn("#novidades ul") } } }) } function AtualizarPerfis() { var a = $("#areaperfil #perfis"); $.wait(a); ajaxProxy("WsUsuario", "GetPerfisByUltimoAcesso", "{}", function (b) { if (b.Error) { } else { $.unwait(a); for (var c in b) { a.append('<a href="javascript:;" title="' + b[c].Login + "," + b[c].UsuarioID + '" class="perfil"><img src="' + b[c].Imagem + '" /></a>') } $.perfil(a.children("a.perfil")) } setTimeout("AtualizarPerfis()", 300000) }) } function AtualizarGrupos() { $.wait($("#areagrupos #ultimosgrupos")); ajaxProxy("WS_Grupos", "GetDestaques", "{}", function (a) { if (a.Error) { } else { $.unwait($("#areagrupos #ultimosgrupos")); for (var b in a) { $("#areagrupos #ultimosgrupos").append('<div class="ultimosgrupo"><a href=/Mercado/Grupos/Grupo.aspx?g=' + a[b].GrupoID + ' target="_blank"><div><img src="/Mercado/Arquivos/Grupos/Grupo/' + a[b].GrupoID + '.gif" /></div><span>' + a[b].Titulo + "</span></a></div>") } } }) } function AcoesDestaque() { var a = $("#areaacoes #acoesemdestaque"); $.wait(a); ajaxProxy("WS_Empresa", "GetDestaques", "{}", function (b) { if (b.Error) { } else { $.unwait(a); for (var c in b) { $("#areaacoes #acoesemdestaque").append('<div class="acaoevento"><a href="/Mercado/Acao/' + b[c].CodBolsa + '.aspx" target="_blank"><img src="' + b[c].Logo + '" /><span><strong>' + b[c].Usuario.value + "</strong> " + b[c].Descricao + "<strong>" + b[c].Empresa + " </strong> há " + b[c].Tempo + "</span></a></div>") } } }) } function AtualizarEventosGrupos() { $.wait($("#areagruposeventos #eventosgrupos")); ajaxProxy("WS_Grupos", "GetEventos", "{}", function (a) { if (a.Error) { } else { $.unwait($("#areagruposeventos #eventosgrupos")); for (var b in a) { $("#areagruposeventos #eventosgrupos").append('<a href="/Mercado/Grupos/Grupo.aspx?g=' + a[b].Grupo.GrupoID + '" class="' + GetIcon(a[b].Acao) + '" target="_blank"><strong>' + a[b].Usuario.Login + "</strong> " + a[b].Acao + " <strong>" + a[b].Grupo.Titulo + "</strong></a>") } } setTimeout("AtualizarEventosGrupos()", 300000) }) } function PesquisarGrupos(d) { var b = $("#areagrupos"), e = b.children("#ultimosgrupos"), a = "", c = $.trim(b.children("#ultimosgrupos-menu").children("#txtgrupopesquisa").val()); if (c.length < 3) { alertBox("alert", "Digite pelo menos 3 caracteres para pesquisa."); return } $.wait(e); ajaxProxy("WS_Grupos", "GetGrupoByTexto", "{texto: '" + c + "', pagina: " + d + "}", function (j) { if (j.Error) { a = "Erro ao pesquisar." } else { $.unwait(e); if (j.GruposCount > 5) { for (var f = 1; f <= Math.ceil(j.GruposCount / 5); f++) { a += '<a href="javascript:;" onclick="PesquisarGrupos(' + f + ')" ' + (d == f ? 'class="atual"' : "") + ">" + f + "</a>" } } for (var h in j.Grupos) { e.append('<div class="ultimosgrupo"><a href=/Mercado/Grupos/Grupo.aspx?g=' + j.Grupos[h].GrupoID + ' target="_blank"><div><img src="/Mercado/Arquivos/Grupos/Grupo/' + j.Grupos[h].GrupoID + '.gif" /></div><span>' + j.Grupos[h].Titulo + "</span></a></div>") } e.append('<div class="indice">' + (j.GruposCount == 0 ? "Nenhum" : j.GruposCount) + " grupo(s) encontrado(s). " + a + '<a href="javascript:;" onclick="AtualizarGrupos()" title="Fechar pesquisa" class="option icon-fechar">&nbsp;</a></div>') } }) } function PesquisarAcoes(c, f) { var b = $("#areaacoes"), d = b.children("#acoesemdestaque"), e = ""; if (c == "") { return } if (f == 1) { $.wait(d) } ajaxProxy("WS_Empresa", "Pesquisar", "{ativo: '" + c + "', pagina: " + f + "}", function (h) { if (h.Error) { e = "Erro ao pesquisar." } else { if (f == 1) { $.unwait(d) } if (f > 1) { e += '<a href="javascript:;" onclick="PesquisarAcoes(\'' + c + "'," + (f - 1) + ')" class="anterior">&nbsp;</a>' } if (h.Count > 5 && f < Math.ceil(h.Count / 5)) { e += '<a href="javascript:;" onclick="PesquisarAcoes(\'' + c + "'," + (f + 1) + ')" class="proximo">&nbsp;</a>' } d.html(""); for (var a in h.Items) { d.append('<div class="acaoevento"><a href="/Mercado/Acao/' + h.Items[a].CodBolsa + '.aspx" target="_blank"><img src="' + h.Items[a].Logo + '" /><span><strong>' + h.Items[a].CodBolsa + "<br />" + h.Items[a].Nome + "</strong></span></a></div>") } d.append('<div class="indice">' + (h.Count == 0 ? "Nenhuma" : h.Count) + " aç" + (h.Count <= 1 ? "ão" : "ões") + " encontrada" + (h.Count <= 1 ? "" : "s") + ". " + e + '<a href="javascript:;" onclick="AcoesDestaque()" title="Fechar pesquisa" class="option icon-fechar">&nbsp;</a></div>') } }) } function ChecharNotificacoes() { t = setTimeout("ChecharNotificacoes()", 60000); if (!isAuthenticatedCache || usuarioID == 0) { return } ajaxProxy("WsUsuario", "GetNotificacoes", "{usuarioID: " + usuarioID + "}", function (e) { if (e.Error) { } else { var f = 0, d = "", c = "", a = $("#temNotificacao").hide(); if (e.length > 0) { for (var b in e) { d += '<div class="notificacao ' + (e[b].Status == 1 ? "nova" : "") + '"><img src="' + e[b].Imagem + '" /><div><a href="' + e[b].Link + '" target="_blank">' + e[b].Texto + "</a> há " + e[b].Tempo + "</div></div>"; if (e[b].Status == 1) { f++ } } if (f > 0) { c = f + " Notificaç" + (f > 1 ? "ões" : "ão") + " Nova" + (f > 1 ? "s!" : "!"); a.show().find("span").html(f) } else { c = "Últimas Notificações" } } else { c = "Sem Notificações" } $("#notificacoes-lista").html("<span>" + c + '<a href="javascript:;" onclick="ToggleNotificacoes()" class="option icon-fechar" title="Fechar Notificações">&nbsp;</a></span><div id="items">' + d + "</div>"); $("#logo").attr("title", c) } }) } function ToggleNotificacoes() { if (!isAuthenticatedCache || usuarioID == 0) { alertBox("alert", "Faça o login para visualizar suas notificações."); blinkIn($("#areameuperfil")); return } var a = $("#notificacoes-lista"), b = "Últimas Notificações"; if (!a.is(":visible")) { clearTimeout(t); $("#temNotificacao").hide(); $("#logo").attr("title", b); ajaxProxy("WsUsuario", "DeleteNotificacoes", "{usuarioID: " + usuarioID + "}", function (c) { }) } else { t = setTimeout("ChecharNotificacoes()", 10000) } a.toggle() } function NovoRecado(a, c, b) { ValidateSession(function (d) { if (d) { $.get("/Mercado/Controls/EditorRecado.aspx", { titulo: a }, function (e) { $.facebox(e); $("#btnEnviar").unbind("click").click(function () { SalvarRecado(c, b) }) }) } }, "enviar recado") } function SalvarRecado(c, a) { var b = { Destinatario: "", Texto: "" }; b.Texto = $.truncateText($.jsonText($("#txttexto").val()), 300); b.Destinatario = { UsuarioID: c }; if ($.clearText($.trim(b.Texto)) == "") { alert("Preencha o recado."); return } ajaxProxy("WsUsuario", "SaveRecado", JSON.stringify({ recado: b }), function (d) { if (d.Error) { $.alertTop(d.Error, "erro"); $("#btnEnviar").show() } else { $(document).trigger("close.facebox"); if (a) { location.reload() } else { $.alertTop("Recado enviado!", "ok") } } }) } function GetIcon(a) { if (a.indexOf("grupo") > 0) { return "icon-grupo-todos" } if (a.indexOf("tópico") > 0) { return "icon-forum-topico" } if (a.indexOf("documento") > 0) { return "icon-documento" } if (a.indexOf("imagem") > 0) { return "icon-imagem" } if (a.indexOf("link") > 0) { return "icon-link" } if (a.indexOf("video") > 0) { return "icon-video" } if (a.indexOf("livro") > 0) { return "icon-livro" } } function AtualizarTwitter() { if (typeof twitterCallback2 == "undefined") { $.getScript("http://twitter.com/javascripts/blogger.js", function () { $.getScript(twitterJs) }) } else { $.getScript(twitterJs) } x = setTimeout("AtualizarTwitter()", 600000) } function AbrirGraficoEUA() { var a = "http://finviz.com/fut_chart.ashx?t=YM&p=d1"; $.facebox(function () { $.facebox('<h3>Gráfico diário de DJIA</h3><img src="' + a + '" />') }) } function Procurar() { var a = $("#txtprocura").val(); $("#conteudo").html('<h1>Procurando por "' + a + '"</h1><div id="cse" style="display:none;"></div><div id="wait" />'); $.wait($("#wait")); var b = new google.search.CustomSearchControl("010224872326794031961:ud4t-rldveq"); b.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET); b.setSearchCompleteCallback(this, ProcurarComplete); b.draw("cse"); b.execute(a + " -bastter.com/mercado/forum") } function ProcurarComplete(a) { scrollToTop(); $(".gsc-search-box, .gsc-resultsHeader").remove(); $("#wait").remove(); $("#cse").show() } function PromocaoPerfil(b, a) { if (b.indexOf("avatar-default") > 0) { $.alertTop("O perfil selecionado não tem avatar e não pode participar da promoção.", "erro"); return } ValidateSession(function (c) { if (c) { $.get("/Mercado/Controls/EditorPromocaoPerfil.aspx", { usuarioID: b, login: a }, function (d) { $.facebox(d); $("#btnEnviar").unbind("click").click(function () { EnviarPromocaoPerfil(b, a) }) }) } }, "participar da promoção") } function EnviarPromocaoPerfil(b, a) { var c = {}; c.frase = $.jsonText($("#txttexto").val()); c.usuarioID = b; c.login = a; ajaxProxy("WsUsuario", "EnviarPromocaoPerfil", JSON.stringify(c), function (d) { if (d.Error) { $.alertTop(d.Error, "erro"); $("#btnEnviar").show() } else { $(document).trigger("close.facebox"); $.alertTop(d.Return, "ok") } }) } function Blue() { window.open("http://bastter.com/b", "Blue", "width=350,height=460,status=no,toolbar=no,menubar=no,location=no,scrollbars=yes") } function LoginGoogle() { window.open("/mercado/oauth.aspx", "GoogleLogin", "width=550,height=460,status=no,toolbar=no,menubar=no,location=no,scrollbars=yes") } function VerEventosAcao() { $.cookie("acao_default_abas", "#ultimas"); window.location = "/mercado/acao/default.aspx#ultimasacoes" };
