(function(j){var k={},y={formatacao:{"var":function(C,D,B){if(C>0){B.addClass("alta")}else{if(C<0){B.addClass("baixa")}else{B.addClass("estavel")}}return q(C,2)},varpct:function(B){return B.toFixed(2).replace(".",",")+" %"},vol:function(B){return q(B)},price:function(B){return q(B,2)},high:function(B){return q(B,2)},low:function(B){return q(B,2)}}},r={mostraValor:function(E,D,C,B,F){D=new Date(D);if(typeof C!="undefined"){j("#valor_do_grafico").html(s("d.m.Y",D)+" - <em>fechamento:</em> "+q(E,2)+" - <em>abertura:</em> "+q(C,2)+" - <em>mín.:</em> "+q(B,2)+" - <em>máx.:</em> "+q(F,2))}else{j("#valor_do_grafico").text(s(window.interday?"d.m.Y":"H:i",D)+" - "+q(E,2))}}},A={"FSW-0001":"Este período não é válido.","FSW-0002":"Este período não é válido; insira uma data inicial menor que a data final.","FSW-0003":"A data inicial não é válida; insira uma data menor que a data de hoje.","FSW-0004":"A data final não é válida; insira uma data menor ou igual a data atual.","FSW-0101":"Parâmetro size menor que 1","FSW-0102":"Parâmetro page menor que 1","FSW-0103":"Parâmetro fields inválido","FSW-0104":"Parâmetro idt menor que 1","FSW-0201":"Parâmetro inválido","FSW-0202":"Campo IDT inválido","FSW-0401":"Não há informação disponível para esta ação/índice.","FSW-0402":"Campo target inválido","FSW-0404":"URL não encontrada","FSW-0500":"Internal Server Error","FSW-0400":"Bad Request"},g,n,m,o,u;j.each(location.href.split("?").splice(1,50).join("?").split("#").splice(0,1).join("#").split("&"),function(B,C){C=C.split("=");k[C[0]]=C[1]});function v(C,B){for(var D in k){if(C==D){return k[D]}}return B}function i(D,E){try{console.error(D,A[D.error],E)}catch(C){}var B=j("#main");B.parent().find("div.msg.error").remove();if(E){B.before(j.create("div").addClass("msg error").text(E))}else{B.before(j.create("div").addClass("msg error").text(A[D.error]))}}j.create=function(B){return j(document.createElement(B))};function q(C,G){var F=C<0,B=parseInt(Math.abs(C),10)+"";C=Math.abs(C).toFixed(G);var D=B.length>3?B.length%3:0,E="";if(F){E+="-"}if(D){E+=B.substr(0,D)+"."}E+=B.substr(D).replace(/(\d{3})(?=\d)/g,"$1.");if(G){E+=","+(C-Math.abs(B)).toFixed(G).slice(2)}return E}function s(M,F,N){var E,H,I,G,K,B,D,L,J={d:function(P){var O=P[E]();return O<10?"0"+O:O},m:function(O){var P=O[D]()+1;return P<10?"0"+P:P},Y:function(O){return O[I]()},H:function(P){var O=P[G]();return O<10?"0"+O:O},i:function(O){var P=O[B]();return P<10?"0"+P:P},s:function(O){var P=O[L]();return P<10?"0"+P:P}};if(N){E="getDate";H="getDay";I="getFullYear";G="getHours";K="getMilliseconds";B="getMinutes";D="getMonth";L="getSeconds"}else{E="getUTCDate";H="getUTCDay";I="getUTCFullYear";G="getUTCHours";K="geUTCtMilliseconds";B="getUTCMinutes";D="getUTCMonth";L="getUTCSeconds"}if(typeof F.getMonth=="undefined"){F=new Date(F)}for(var C in J){M=M.replace(new RegExp("(^|[^\\\\])"+C),"$1"+J[C](F))}return M.replace(/\\/g,"")}function a(D,B){var F=j(B||"#main div:first select");if(!F.length){return setTimeout(function(){a(D,B)},500)}for(var C=0,B=j(B||"#main div:first select")[0],G=B.options.length;C<G;C++){var E=B.options[C];if(E.value.indexOf("size="+D)!=-1){B.options.selectedIndex=C;break}}}function x(M,B,D,C){var F=Math.ceil(M/B),B=j.create("div").addClass("paginacao clear-box").append(j.create("span").text("Páginas")),K=j.create("ul").addClass("paginas").appendTo(B),I=j.create("ul").appendTo(B),J=j.create("li").attr("id","lnk-anterior").appendTo(I),O=j.create("li").attr("id","lnk-proxima").appendTo(I),N=[],L;D=parseInt(D,10);if(F>5){if(D>3){if(D>=(F-2)){do{N.unshift(F-N.length)}while(N.length<5)}else{do{N.push(N.length+(D-2))}while(N.length<5)}}else{do{N.push(N.length+1)}while(N.length<5)}}else{do{N.push(N.length+1)}while(N.length<F)}function E(Q,P,R){return Q.append(j.create("a").text(P).attr("href",C.replace("%pagina",R)))}for(var G=0,H=N.length;G<H;G++){L=N[G];if(L==D){j.create("li").append(j.create("strong").text(L)).appendTo(K)}else{E(j.create("li"),L,L).appendTo(K)}}if(D!=1){E(J,"Anterior",D-1)}else{J.addClass("inativo").text("Anterior")}if(D==F){O.addClass("inativo").text("Próxima")}else{E(O,"Próxima",D+1)}y.insertPaginacao(B[0])}function h(G,B,F){var D=j.create("table"),E=j.create("tr").appendTo(j.create("thead").appendTo(D)),C=j.create("tbody").appendTo(D);if(F){j.create("tfoot").appendTo(D)}j.each(G,function(H,J){var I=j.create("th").text(J).appendTo(E);if(B&&B[H]){I.addClass(B[H])}});return C}function w(){var B=j("#begin, #end");if(B.length){B.datePicker({clickInput:true,createButton:false,startDate:"01/01/1996"}).bind("dpDisplayed dpMonthChanged",function(D){var G=j("#dp-popup"),E=j("h2",G).text().split(" "),C=j("#dp-popup");if(D.type=="dpDisplayed"){var F=this;j(G).append(j.create("input").addClass("button2").attr({type:"button",id:"c"}).click(function(){j(D.target).val("");j(F).dpClose()}).val("LIMPAR"))}j("th",G).each(function(H){this.innerHTML=Date.abbrDayNames[H]});if(C.find(".ano").length){C.find(".ano span").text(E[1]);C.find(".mes span").text(E[0])}else{j.create("div").addClass("mes").append(j(".dp-nav-prev-month")).append(j.create("span").text(E[0])).append(j(".dp-nav-next-month")).prependTo(G);j.create("div").addClass("ano").append(j(".dp-nav-prev-year")).append(j.create("span").text(E[1])).append(j(".dp-nav-next-year")).prependTo(G)}this.focus()});B.attr("autocomplete","off")}}function f(D,B,C,E){j(".linhas option").each(function(F,G){var H=this.value;if(H.indexOf("begin=")!=-1){this.value=H.replace(/\&begin=\d+/,"&begin="+D).replace(/\&end=\d+/,"&end="+B)}else{this.value=H+"&begin="+D+"&end="+B}this.value=C?(this.value+"&type="+C):this.value.replace(/&type=[atms]{1,2}/,"")});if(y.urlPaginacao.indexOf("begin")!=-1){y.urlPaginacao=y.urlPaginacao.replace(/begin=\d+/,"begin="+D)}else{y.urlPaginacao+="&begin="+D}if(y.urlPaginacao.indexOf("end")!=-1){y.urlPaginacao=y.urlPaginacao.replace(/end=\d+/,"end="+B)}else{y.urlPaginacao+="&end="+B}if(y.urlPaginacao.indexOf("type=")!=-1){y.urlPaginacao=y.urlPaginacao.replace(/(\&?)type=[dsmta]{1,2}/,C?("$1type="+C):"")}else{if(C){y.urlPaginacao+="&type="+E.parentNode.className.split("_")[1]}}}function c(){j(".periodo form").eq(0).submit(function(D){var E=j("#begin").val().split("/"),C=j("#end").val().split("/"),B=window.servico;try{E=(new Date(E[2],E[1]-1,E[0])).getTime()}catch(F){i("","Data inicial inválida; o formato válido é dd/mm/aaaa.");return}try{C=(new Date(C[2],C[1]-1,C[0])).getTime()}catch(F){i("","Data final inválida; o formato válido é dd/mm/aaaa.");return}j.extend(B.parametros,{begin:E,end:C,page:1});if(B.parametros.fields&&B.parametros.fields=="date,price"){B.parametros.fields="date,price,open,low,high"}f(E,C,false,this);j(".periodo .atalhos").removeClass("periodo_d periodo_s periodo_m periodo_tm periodo_a");api.interday(j.extend({},B.parametros));return false})}function z(){j(".periodo .atalhos a").click(function(D){var F,C,H=this.parentNode,E=H.className.split("_")[1],G={s:604800000,m:2592000000,tm:7776000000,a:31536000000},B=window.servico;if(H.className=="periodo_d"){B.urlPaginacao=B.urlPaginacao.replace(/&?type=[dsmta]{1,2}/,"").replace(/&?begin=\d+/,"").replace(/&?end=\d+/,"");delete B.parametros.begin;delete B.parametros.end;j(".tipos-grafico ul.candlestick, .tipos-grafico ul.ohlc").removeClass("ohlc candlestick").addClass("line");B.parametros.fields="date,price";api.intraday(j.extend({},B.parametros));j("#begin, #end").val("");H.parentNode.className="atalhos periodo_d";return false}C=B.parametros.end=B.hoje;F=B.parametros.begin=B.hoje-G[E];H.parentNode.className="atalhos periodo_"+E;if(B.parametros.fields&&B.parametros.fields=="date,price"){B.parametros.fields="date,price,open,low,high"}f(F,C,E,this);B.parametros.page=1;api.interday(j.extend({},B.parametros));j("#begin, #end").val("");return false})}function l(){var B=function(D,E){var C=j("#flashGraphic")[0];C[D]&&C[D]();if(D!="showLINE"&&j(".periodo ul.atalhos.periodo_d").length){return false}E.parentNode.parentNode.className=E.parentNode.className;return false};j("li.line a").click(function(){return B("showLINE",this)});j("li.ohlc a").click(function(){return B("showOHLC",this)});j("li.candlestick a").click(function(){return B("showCANDLESTICK",this)})}function b(C){!!u&&clearInterval(u);window.servico.hoje=C.today;j("#valor_do_grafico").empty();var B=[{RangeY:{value:0.15},timeOffSet:{value:C.timeOffSet},Background:{color:16185078},AnoNovoStyle:{line:{width:1,color:52224,dashlength:10,gaplength:5},text:{font:"Verdana",color:16711680,size:10,underline:true}},GridStyle:{lineSize:".5",lineColor:16777215},LineErrorStyle:{width:1,color:16711680,dashlength:5,gaplength:2},TextErrorStyle:{font:"Verdana",color:16711680,size:10,underline:true},TextLinhaStyle:{font:"Verdana",color:10066329,size:11,underline:false},TextColunaStyle:{font:"Verdana",color:3355443,size:11,underline:false},GraficoStyle:{color:8563908,upcolor:39168,downcolor:10027008},LineStyle:{thickness:1,color:0,upcolor:39168,downcolor:10027008},PontoStyle:{size:4,color:16685312,lineSize:1,lineColor:0},APPMsgError:{value:"Não há dados suficientes para exibir o gráfico"},IntradayMsgError:{value:'<a href="event:showLINE()">Não é possível exibir o gráfico Clandestick/OHLC no período de 1 dia.\nVeja o gráfico no formato linha.</a>'}}];if(C.data){B.push(C.data)}interday=false;if(C.error){d();window.flash.onload=function(){i(C);if(C.error=="FSW-0401"&&u&&document.getElementById("flashGraphic").addERROR){document.getElementById("flashGraphic").addERROR("A busca não retornou valores.");clearInterval(u);window.flash.onload=undefined;u=undefined}}}else{if(window.servico.parametros.begin){window.interday=true;B[0].timeOffSet.value=0;window.flash.onload=function(){j("div.cinza div.msg.error").hide();if(u&&document.getElementById("flashGraphic").addJSON_INTERDAY){document.getElementById("flashGraphic").addJSON_INTERDAY(B,j("div.tipos-grafico ul")[0].className.toUpperCase());clearInterval(u);window.flash.onload=undefined;u=undefined}}}else{if(!window.servico.hoje){window.servico.hoje=C.today}d();window.flash.onload=function(){j("div.cinza div.msg.error").hide();if(u&&document.getElementById("flashGraphic").addJSON_INTRADAY){document.getElementById("flashGraphic").addJSON_INTRADAY(B);clearInterval(u);window.flash.onload=undefined;u=undefined}}}}u=setInterval(window.flash.onload,2000);swfobject.embedSWF("http://cotacoes.economia.uol.com.br/stc/s/bolsas.swf","flashGraphic","560","305","10.0.0",false,false,{wmode:"transparent",allowscriptaccess:"always"})}function d(F,G,D,C){if(j(".infoTable table").length){return}if(F){if(!C){y.hoje=F.date}var B=h(n),E=j.create("tr");j.each(g,function(H,J){var K=j.create("td").addClass(J),I=m[J];if(C){I=null}else{if(y.intraday&&J=="date"){I=function(N,M,L,O){return s("H:i",N+O)}}else{if(J=="date"){I=function(N,M,L,O){return s("d/m/Y",N+O)}}}}if(I){K.text(I(F[J],F,E,G))}else{K.text(F[J])}K.appendTo(E)});if(C){E.find("td.date").remove()}else{if(!y.intraday){E.find("td.date").text(s("H:i",F.date+G))}}E.appendTo(B);if(!C){j.create("th").prependTo(B.prev().find(":first"))}else{B.prev().find("th:first").text("")}j.create("th").append(j.create("span").text(E[0].className).addClass("tick")).prependTo(E);j(".infoTable").append(B.parent()).find("strong").append(s("d.m.Y",D+G));if(navigator.userAgent.indexOf("MSIE 7")!=-1){j(".abas").css("bottom",0)}}else{api.intraday({type:"asset",size:1,idt:o.idt,callback:function(H){if(H.error&&H.error=="FSW-0401"){return api.interday({type:"asset",size:1,idt:o.idt,begin:1136080800000,end:H.today,callback:function(I){if(I.error){return i(I)}else{j("#main").parent().find("div.msg.error").remove()}d(I.data[0],I.timeOffSet,I.lastUpdate,true)}})}else{if(H.error){return i(H)}else{j("#main").parent().find("div.msg.error").remove()}}d(H.data[0],H.timeOffSet,H.lastUpdate)}})}}function t(H){y=window.servico;g=y.colunas;n=y.traducao;m=y.formatacao;o=y.parametros;y.hoje=H.today;if(H.error){d();return i(H)}else{j("#main").parent().find("div.msg.error").remove()}var E=h(n,g),G=H.data.concat(),B=G.length,F,D;if(!y.hoje){y.hoje=H.data[0].date}if(j(".periodo").next().length&&j(".periodo").next()[0].tagName.toLowerCase()=="table"){j(".periodo").next().remove();j("#main .paginacao").remove()}function C(){var J=j.create("tr").appendTo(E),I=G.shift();j.each(g,function(L,K){var N=j.create("td").addClass(K).appendTo(J),M=m[K];if(y.intraday&&K=="date"){M=function(Q,P,O,R){return s("H:i",Q+R)}}else{if(K=="date"){M=function(Q,P,O,R){return s("d/m/Y",Q)}}}if(M){N.text(M(I[K],I,J,H.timeOffSet))}else{N.text(I[K])}})}D=B%8;if(D>0){do{C()}while(--D)}D=parseInt(B/8,10);if(D>0){do{C();C();C();C();C();C();C();C()}while(--D)}y.insertTabela(E.parent()[0]);if(y.intraday&&o.page===1){d(H.data[0],H.timeOffSet,H.lastUpdate)}else{if(!j(".infoTable table").length){d()}}x(H.total,o.size,o.page,y.urlPaginacao);typeof(reequalize)!="undefined"&&reequalize()}var p={popular:t,informacoesGerais:d,selectSize:a,plotGraphic:b,servico:y,getParam:v,flash:r};for(var e in p){window[e]=p[e]}j(function(){g=y.colunas;n=y.traducao;m=y.formatacao;o=y.parametros;l();if(!window.buscaAcoes&&window.addCompleter&&j("#campoAcao").length){window.buscaAcoes=window.addCompleter("#campoAcao");window.buscaAcoes.url="http://economia.uol.com.br/cotacoes/bolsas/acoes/bvsp-bovespa/";j(":submit",j("#campoAcao")[0].form).click(function(){var B=j(".autoCompleteList ul li");if(j("#campoAcao").val()!=""&&B.length===1){location.href="http://economia.uol.com.br/cotacoes/bolsas/acoes/bvsp-bovespa/"+B.eq(0).find(".code").text().toLowerCase().replace(".","-");return false}})}j("#buscaNoticias :submit").click(function(){if(j("#buscaNoticias_js input").get(0).checked&&j("#q").val()!=""){var B=j("#busca-noticias .autoCompleteList ul li");if(B.length===1){location.href="http://economia.uol.com.br/cotacoes/bolsas/acoes/bvsp-bovespa/"+B.eq(0).find(".code").text().toLowerCase().replace(".","-");return false}}});if(window.autoCompleter){window.autoCompleter.url="http://economia.uol.com.br/cotacoes/bolsas/acoes/bvsp-bovespa/"}});if(!window.autoCompleter&&window.addCompleter&&j("#q").length&&j("#busca-noticias").length){window.autoCompleter=window.addCompleter("#q",j("#busca-noticias"));window.autoCompleter.url="http://economia.uol.com.br/cotacoes/bolsas/acoes/bvsp-bovespa/";window.delCompleter(window.autoCompleter)}w();c();z()})(jQuery.noConflict());