﻿
var vetBanner=Array();var vetBannerPks=Array();var vetFilaBanner=Array();addLoadEvent(acionaBanners);function AbreBanner(janela,codigo){if(janela=="true"||janela=="True"||janela==true)
{window.open('http://bbel.uol.com.br/inc_banner.aspx?pk='+codigo);}
else
{location='http://bbel.uol.com.br/inc_banner.aspx?pk='+codigo;}}
function reloadBanner(divs,canal_referencia,local,tempo,pk,posicaoVetor)
{if(pk==undefined){pk="";}
if(tempo>0)
setTimeout("vetFilaBanner[vetFilaBanner.length] = new addVetor('"+divs+"','"+canal_referencia+"','"+local+"','"+pk+"','"+posicaoVetor+"','displayBanner')",parseInt(tempo)*1000);}
function addVetor(div,canal_referencia,local,pk,posicaoVetor,callback_function)
{this.div=div;this.canal_referencia=canal_referencia;this.local=local;this.pk=pk;this.posicaoVetor=posicaoVetor;this.callback_function=callback_function;}
function trataVetor(vetor){if(vetor.length<=0)
return null;else{var result=vetor[0];for(var i=0;i<vetor.length-1;i++)
vetor[i]=vetor[i+1];vetor.length--;return result;}}
function criaPksRestricao(pkAtual)
{var _pks=new String();for(i=0;i<vetBannerPks.length;i++)
{if(vetBannerPks[i]!="0"&&parseInt(vetBannerPks[i])!=parseInt(pkAtual))
{_pks+=((_pks!=null&&_pks!="")?";":"")+vetBannerPks[i];}}
return _pks;}
function acionaBanners()
{if(typeof document.body.style.maxHeight=="undefined")
{}
var obj;var locais;for(i=0;i<vetBanner.length;i++)
{obj=vetBanner[i];locais=obj.divs.split(';');for(y=0;y<locais.length;y++)
{vetBannerPks[i+y]=0;vetFilaBanner[vetFilaBanner.length]=new addVetor(locais[y],obj.canal_referencia,obj.local,'',(i+y),'displayBanner');}}
makeRequest("all");}
function callBanner(divs,canal_referencia,local)
{this.divs=divs;this.canal_referencia=canal_referencia;this.local=local;}
function makeRequest(todos){var newVetor=trataVetor(vetFilaBanner);if(newVetor!=null){this.url='http://bbel.uol.com.br/inc_banner.aspx?div='+newVetor.div+'&canal_referencia='+newVetor.canal_referencia+'&local='+encodeURIComponentNew(newVetor.local)+'&banner_atual='+newVetor.pk+'&remove='+criaPksRestricao(newVetor.pk);var metodo='GET';var modo=true;xmlhttp=new XMLHttpRequest();if(metodo=="GET"){xmlhttp.open("GET",url,modo);}
else{xmlhttp.open("POST",url,modo);xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=iso-8859-1");xmlhttp.setRequestHeader("Cache-Control","no-store, no-cache, must-revalidate");xmlhttp.setRequestHeader("Cache-Control","post-check=0, pre-check=0");xmlhttp.setRequestHeader("Pragma","no-cache");}
xmlhttp.onreadystatechange=function()
{if(xmlhttp.readyState==4)
{eval(newVetor.callback_function+'(xmlhttp.responseXML, newVetor.div, newVetor.canal_referencia, newVetor.local, newVetor.posicaoVetor)');}}
if(metodo=="GET")
{xmlhttp.send(null);}else{xmlhttp.send(parametros);}}
if(todos=="all")
setTimeout("makeRequest('all')",1000);else
setTimeout("makeRequest()",10000);}
var campoAtualFocusBanner=null;function exibe(div,text){if(typeof document.body.style.maxHeight=="undefined"&&text.indexOf('.swf')>-1){$(div).innerHTML=text;if(campoAtualFocusBanner!=null){$(campoAtualFocusBanner).focus();}}else{$(div).innerHTML=text;}}
function procuraFocus()
{var obj=document.getElementsByTagName('input');for(var i=0;i<obj.length;i++){if(obj[i].type=='text'||obj[i].type=='password'){var getFunctions=$(obj[i].id).getAttribute("onkeypress");if(new String(getFunctions).indexOf('WBR_Formata')==-1){if(new String(getFunctions).indexOf('campoAtualFocusBanner')==-1){if(getFunctions!=null){extendEvent(obj[i],'onkeypress',"setacampoAtualFocusBanner('"+obj[i].id+"')");}else{$(obj[i].id)['onkeypress']=function(){campoAtualFocusBanner=obj[i].id;};}}}}}}
function setacampoAtualFocusBanner(obj){campoAtualFocusBanner=obj;}
function extendEvent(oElement,sEvent,fnNew){oElement=oElement||window;sEvent=/^on/.test(sEvent)?sEvent:'on'+sEvent;var fnOld=oElement[sEvent]||function(){};return(oElement[sEvent]=function(){var res=[fnOld(),eval(fnNew)];return(res[0]&&res[1]);});}
function displayBanner(xml,div,canal_referencia,local,posicaoVetor){if(document.all){var nodes=xml.documentElement.childNodes;if(nodes.item(2).text!=""&&nodes.item(2).text!="0"){exibe(div,nodes.item(2).text);vetBannerPks[posicaoVetor]=nodes.item(0).text;reloadBanner(div,canal_referencia,local,parseInt(nodes.item(1).text),nodes.item(0).text,posicaoVetor);}}else{if(xml.childNodes[0].childNodes[5].data!=""&&xml.childNodes[0].childNodes[5].data!="0"){exibe(div,xml.childNodes[0].childNodes[5].data);vetBannerPks[posicaoVetor]=xml.getElementsByTagName('pk')[0].firstChild.data;reloadBanner(div,canal_referencia,local,parseInt(xml.getElementsByTagName('reload')[0].firstChild.data),xml.getElementsByTagName('pk')[0].firstChild.data,posicaoVetor);}}}