function ajaxRequestInternal(url,postValues,returnFunction) {
    this.url = url;
    this.postValues = postValues;
    this.xmlhttp = false;

    this.create = function() {
        try {
            this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP.4.0");
        } catch(e) {
            try {
                this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP.3.0");
            } catch(e) {
                try {
                    this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
                } catch(e) {
                    try {
                        this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                    } catch(e) {
                        this.xmlhttp = false;
                    }
                }
            }
        }

        if (!this.xmlhttp && typeof XMLHttpRequest!='undefined') {
            try {
                this.xmlhttp = new XMLHttpRequest();
            } catch (e) {
                this.xmlhttp = false;
            }
        }
        if (!this.xmlhttp && window.createRequest) {
            try {
                this.xmlhttp = window.createRequest();
            } catch (e) {
                this.xmlhttp=false;
            }
        }
    }

    this.send = function() {
        var sendData = '';
        sendData += this.postValues;
        var xh = this.xmlhttp;
        xh.open("POST",this.url,true);
        xh.onreadystatechange = function() {
            if (xh.readyState == 4) {
                if (true || xh.status == 200 || xh.status == 304)	{
                    returnFunction(xh.responseText, true);
                } else {
                    returnFunction(undefined, false);
                }
            }
        };

        xh.setRequestHeader("Content-Type", "text/html; charset=UTF-8");
        xh.setRequestHeader("encoding","UTF-8");
        //        xh.setRequestHeader("Content-length", sendData.length );
        xh.send(sendData);
    }

    this.create();

    if (this.xmlhttp) {
        this.send();
    } else {
        alert('Este browser não suporta requisições por AJAX');
    }
}

function votarEnquete(id){
    ajaxRequestInternal("enquetePersistence.jsp?id=" + id ,'', function(retorno,sucesso) {
        if(sucesso) {
            document.getElementById('enquetediv').innerHTML = retorno.replace(execScript(retorno),eval(execScript(retorno)));
        }
    });
}

function EnviarEmail( emailDestino, nome, emailRemetente, telefone, cidade, uf, diaEvento, mesEvento, anoEvento, qtdeAdulto, qtdeCrianca, informacao, contato, receberNewsletter, linkRetorno ){
    if (emailRemetente.length < 8 || telefone.length < 8){
      alert('Os campos * sao obrigatorios!');
    }else{ 
    ajaxRequestInternal("../../enviaemail.jsp?emailDestino=" + emailDestino +"&nome="+ nome +"&emailRemetente="+ emailRemetente + '&telefone='+ telefone + '&cidade='+ cidade +'&uf='+ uf +'&diaEvento='+ diaEvento + '&mesEvento='+ mesEvento +'&anoEvento='+ anoEvento +'&qtdeAdulto='+ qtdeAdulto +'&qtdeCrianca='+ qtdeCrianca +'&informacao=' + informacao + '&contato=' + contato + '&receberNewsletter=' + receberNewsletter + '&linkRetorno=' + linkRetorno,' ',function(retorno,sucesso) {
        if(sucesso) {
            document.getElementById('divOrcamento[numerodoanunciante]').innerHTML = retorno.replace(execScript(retorno),eval(execScript(retorno)));
        }
    });
  }
}
        
function ImageServlet( id, tipo ){
    alert( id +" - "+ tipo );
    ajaxRequestInternal('../../../DownloadFileServlet?alias='+ tipo +'&id='+ id ,' ',function(retorno,sucesso) {
        if(sucesso) {
            alert(retorno);
        }else{
            alert('nada');
        }
    });
}
     

function enviarEmailNosIndique( nosIndiqueSeuNome , nosIndiqueSeuEmail, nosIndiqueNomeAmigo, nosIndiqueEmailAmigo, informacaoAdicional ){
    if (nosIndiqueSeuEmail.length < 8 || nosIndiqueEmailAmigo.length < 8){
       alert('Os campos * sao obrigatorios!');
    }else{
    ajaxRequestInternal("../../enviaEmailNosIndique.jsp?nosIndiqueSeuNome=" + nosIndiqueSeuNome +"&nosIndiqueSeuEmail="+ nosIndiqueSeuEmail +"&nosIndiqueNomeAmigo="
        + nosIndiqueNomeAmigo + '&nosIndiqueEmailAmigo='+ nosIndiqueEmailAmigo + '&informacaoAdicional=' + informacaoAdicional,' ',function(retorno,sucesso) {
            if(sucesso) {
                document.getElementById('nosIndiqueDiv').innerHTML = retorno.replace(execScript(retorno),eval(execScript(retorno)));
            }
        });
    }
}

function enviaEmailMeIndique( meIndiqueSeuNome , meIndiqueSeuEmail, meIndiqueNomeAmigo, meIndiqueEmailAmigo, informacaoAdicional , nomeAnunciante, linkRetorno){
    if(meIndiqueSeuEmail.length < 8 || meIndiqueEmailAmigo.length < 8){
       alert('Os campos * sao obrigatorios!');
    }
    else{
      ajaxRequestInternal("../../enviaEmailMeIndique.jsp?meIndiqueSeuNome=" + meIndiqueSeuNome +"&meIndiqueSeuEmail="+ meIndiqueSeuEmail +"&meIndiqueNomeAmigo="
        + meIndiqueNomeAmigo + '&meIndiqueEmailAmigo='+ meIndiqueEmailAmigo + '&informacaoAdicional=' + informacaoAdicional + '&nomeAnunciante=' + nomeAnunciante + '&linkRetorno=' + linkRetorno,' ',function(retorno,sucesso) {
            if(sucesso) {
                document.getElementById('meIndiqueDiv').innerHTML = retorno.replace(execScript(retorno),eval(execScript(retorno)));
            }
        });
    }
}

function enviarEmailFaleConosco( emailDestino, nome , emailRemetente, telefoneDDD, telefone, cidade, uf, informacao){
    ajaxRequestInternal("../../enviaEmailFaleConosco.jsp?emailDestino=" + emailDestino +"&nome="+ nome +"&emailRemetente="+
        emailRemetente + '&telefoneDDD='+ telefoneDDD + '&telefone='+ telefone +"&cidade="+ cidade +"&uf="+ uf +"&informacao="+ informacao,' ',function(retorno,sucesso) {
            if(sucesso) {
                document.getElementById('faleConoscoDiv').innerHTML = retorno.replace(execScript(retorno),eval(execScript(retorno)));
            }
        });
}




function showConteudoCombo( idSegmento ) {
    ajaxRequestInternal('buscaAnuncio.jsp?id=' + idSegmento,'', function(retorno,sucesso) {
        if(sucesso) {
            if(navigator.appName == "Microsoft Internet Explorer"){
                document.getElementById("idComboPOG").innerHTML = '<select style="width:100%;" id="anunciantescombo"  onchange="javascript: showAnuncioSeguimento(this.value);">'+ retorno +'</select>';
            }else
                document.getElementById('anunciantescombo').innerHTML = retorno;
        }
    });
}



function newsletterPersistence(nome, email)  {
    ajaxRequestInternal("newsletter.jsp?nome=" + nome + "&email=" + email,'', function(retorno,sucesso) {
        if(sucesso) {
            document.getElementById('newsdiv').innerHTML = retorno.replace(execScript(retorno),eval(execScript(retorno)));
        }
    });
}

function barShowConteudo( param ){
    showConteudo( param + ".jsp" );
}

function showAnuncioSeguimento( id ) {
    var pog = id.split(",");
    var idAnuncio = pog[0];
    var idSeguimento = pog[1];
    showConteudo("anuncioSeguimento.jsp?idAnuncio=" + idAnuncio + "&idSeguimento="+ idSeguimento);
}

function showAnuncioSeguimentoOrcamento(idAnuncio, idSeguimento) {
    showConteudo("anuncioSeguimentoOrcamento.jsp?idAnuncio=" + idAnuncio + "&idSeguimento="+ idSeguimento);
}

function showHotsite(idAnuncio, idSeguimento) {
    showConteudo("hotsite.jsp?idAnuncio=" + idAnuncio + "&idSeguimento="+ idSeguimento);
}

function showAnuncioSeguimentoOrcamento(idAnuncio, idSeguimento) {
    showConteudo("anuncioSeguimentoOrcamento.jsp?idAnuncio=" + idAnuncio + "&idSeguimento="+ idSeguimento);
}

function showMeIndique(idAnuncio, idSeguimento) {
    showConteudo("meIndique.jsp?idAnuncio=" + idAnuncio + "&idSeguimento="+ idSeguimento);
}

function showSeguimento(id) {
    showConteudo("segmento.jsp?id=" + id);
}



function showAgendaEventos(id){
    showConteudo("agendaEventos.jsp?id="+id);
}

function showDica(id) {
    showConteudo("dica.jsp?id="+id);
}

function showClick(id) {
    showConteudo("click.jsp?id="+id);
}

function showColuna(id) {
    showConteudo("coluna.jsp?id="+id);
}

function showCalendario(id) {
    showConteudo("calendario.jsp?id="+id);
}

function showPromocao( id ) {
    showConteudo("promocao.jsp?id="+id);
}

function showPromocaoRegulamento( id ) {
    showConteudo("promocao_regulamento.jsp?id="+id);
}

function showCat(id) {
    document.getElementById("scat_"+id).style.display = 'none';
    document.getElementById("hcat_"+id).style.display = '';
    document.getElementById("icat_"+id).style.display = '';
}

function hideCat(id) {
    document.getElementById("scat_"+id).style.display = '';
    document.getElementById("hcat_"+id).style.display = 'none';
    document.getElementById("icat_"+id).style.display = 'none';
}

function searchTools ( elem, tipo ) {
    if ( tipo == 1 ){
        if( elem.value == 'Digite o segmento' ){
            elem.value = '';
        }
    }else if( tipo == 2 ){
        if( elem.value == '' ){
            elem.value = 'Digite o segmento';
        }
    }
}

function newsNomeTools ( elem, tipo ) {
    if ( tipo == 1 ){
        if( elem.value == 'Nome completo' ){
            elem.value = '';
        }
    }else if( tipo == 2 ){
        if( elem.value == '' ){
            elem.value = 'Nome completo';
        }
    }
}

function newsEmailTools ( elem, tipo ) {
    if ( tipo == 1 ){
        if( elem.value == 'nome@provedor.ext' ){
            elem.value = '';
        }
    }else if( tipo == 2 ){
        if( elem.value == '' ){
            elem.value = 'nome@provedor.ext';
        }
    }
}

var timeExec;
var timeLoop;
var fotos;

function changeImage( imagem, local , url, texto, tipoEstatistica, tipoEstatisticaAcesso, tipo, h, w ){
    
    if( document.getElementById( local ) != null ){
  
        if(tipo == "img"){
//            var imgtag = "<img src='../../DownloadFileServlet?alias=ban&id=" + imagem + "'/>";
//            if(local == "sliderFullBanner"){
              imgtag = "<img src='../../DownloadFileServlet?alias=ban&id=" + imagem + "'  height='"+ h +"' width='"+w+"'  style='margin: 1px;'/>";
//            }
            document.getElementById(local).innerHTML = imgtag;
//            document.getElementById( local ).src =  '../../DownloadFileServlet?alias=ban&id=' + imagem;
        }else if(tipo == "swf"){
            var swftag = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" align="l" width="'+w+'" height="'+h+'">';
            swftag += '<param name="movie" value="../../DownloadFileServlet?alias=ban&id='+imagem+'" />';
            swftag += '<param name="quality" value="high" />';
            swftag += '<param name="WMODE" value="transparent" />';
            swftag += '<embed src=../../DownloadFileServlet?alias=ban&id='+imagem+' width="'+w+'" height="'+h+'" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" wmode="transparent"></embed>'
            swftag += '</object>';
            document.getElementById(local).innerHTML = swftag;
        }
        if( url != null || url != "" || url != "null" ){
//            document.getElementById( local ).setAttribute("onclick", "javascript: window.open('"+ url +"', '_blank' );");
	    if(tipoEstatistica != undefined && tipoEstatisticaAcesso != undefined)
              registraEstatistica(imagem, tipoEstatistica, tipoEstatisticaAcesso, false, '1');//adicionar aki o segmentoId do segmento Pai
            document.getElementById( local ).onclick=function(){
              window.open( url );
              registraEstatistica(imagem, tipoEstatistica, "CLIQUE", false, '1');//adicionar aki o segmentoId do segmento Pai
            }
//	    document.getElementById( local ).onclick = url;
            document.getElementById( local ).style.cursor = 'pointer';
            if( local == 'sliderDestaque' )
                document.getElementById( local +"TXT" ).innerHTML = texto;
        }else{
            document.getElementById( local ).setAttribute("onclick", "");
            document.getElementById( local ).style.cursor = '';
        }
    }
}

function setSlider( fotos, delay , local , url , tipoEstatistica, tipoEstatisticaAcesso, tipos, h, w  )
{

    var texto = new Array();
    var temp;
   

    if( fotos[0] == "[" ) {
        fotos = fotos.substr(1, fotos.length - 1);
        fotos = fotos.split(",");
    }
    if( tipos && tipos[0] == "[" ) {
        tipos = tipos.substr(1, tipos.length - 1);
        tipos = tipos.split(",");
    }
    if( url[0] == "[" ) {

        url = url.substr(1, url.length - 1);
        temp = url.split("***");
        url   = temp[0].split(",");
        texto = temp[1].split(",");

    }else {
        for( i=0; i < url.length; i++ ){
            temp     = url[i].split("***");
            url[i]   = temp[0];
            texto[i] = temp[1];
           
        }
    }

    for(i = 0; i < fotos.length; i++ ){
        var tipo = "img";
        if(tipos && tipos[i] == "swf"){
            tipo = "swf";
        }
        timeExec = setTimeout( "changeImage('"+ fotos[i] +"' , '"+ local +"' , '" + url[i] +"' , '"+ texto[i] +"', '"+tipoEstatistica+"' , '"+tipoEstatisticaAcesso+"', '" + tipo + "', "+h+", "+w+" )", i * delay );
    }
    timeLoop = setTimeout( "setSlider('["+ fotos +"',"+ delay +",'"+ local +"' , '[" + url +"***"+ texto +"', '"+tipoEstatistica+"' , '"+tipoEstatisticaAcesso+"', '["+tipos + "]', "+h+", "+w+" )", (i+1) * delay );
}

function changeBackground(){
    var horarioAtual = new Date();
    var time = horarioAtual.getHours(); // +":"+ horarioAtual.getMinutes();

    if( time >= 0 && time <= 5 ){
        //document.getElementById('body').style.background = 'url(background01.jpg) left top no-repeat #000000';
        document.getElementById('body').style.background = 'url(background03.jpg) left top no-repeat #1D002C';
    }else if( time >= 6 && time <= 11 ) {
        //document.getElementById('body').style.background = 'url(background02.jpg) left top no-repeat #014284';
        document.getElementById('body').style.background = 'url(background03.jpg) left top no-repeat #1D002C';
    }else if( time >= 12 && time <= 17 ){
        //document.getElementById('body').style.background = 'url(background04.jpg) left top no-repeat #FFFF33';
        document.getElementById('body').style.background = 'url(background03.jpg) left top no-repeat #1D002C';
    } else if ( time >= 18 && time <= 23 ){
        document.getElementById('body').style.background = 'url(background03.jpg) left top no-repeat #1D002C';
    }

}

function returnEnquete(){
    document.getElementById('divEnquete').style.display = '';
    setTimeout( "document.location.href = 'index.jsp'", 1000 );
}

function execReturnEnquete(){
    setTimeout( "returnEnquete()", 3000 );
}

function returnNewsletterEmail(){
    document.getElementById('newsdiv').style.display = '';
    setTimeout( "document.location.href = 'index.jsp'", 1000 );
}

function execReturnEnquete(){
    setTimeout( "returnNewsletterEmail()", 3000 );
}







var delayb4scroll=1000 //Especifique o tempo de espera antes de iniciar a rolagem da pagina(2000=2 segundos)
var marqueespeed=1 //especificique a velocidade da rolagem(larger is faster 1-10)
var pauseit=1 //Pausar rolarem com onMousever (0=não. 1=Sim)?

////NÃO PRECISA EDITAR ABAIXO DESSA LINHA////////////

var copyspeed=marqueespeed
var pausespeed=(pauseit==0)? copyspeed: 0
var actualheight=''

function scrollmarquee(){
  if (parseInt(cross_marquee.style.top)>(actualheight*(-1)+8))
    cross_marquee.style.top=parseInt(cross_marquee.style.top)-copyspeed+"px"
  else
    cross_marquee.style.top=parseInt(marqueeheight)+8+"px"
}

function initializemarquee(){
  cross_marquee=document.getElementById("vmarquee")
  cross_marquee.style.top=0
  marqueeheight=document.getElementById("marqueecontainer").offsetHeight
  actualheight=cross_marquee.offsetHeight
  if (window.opera || navigator.userAgent.indexOf("Netscape/7")!=-1){
    cross_marquee.style.height=marqueeheight+"px"
    cross_marquee.style.overflow="scroll"
    return
  }
  setTimeout('lefttime=setInterval("scrollmarquee()",30)', delayb4scroll)
}

if (window.addEventListener)
  window.addEventListener("load", initializemarquee, false)
else if (window.attachEvent)
  window.attachEvent("onload", initializemarquee)
else if (document.getElementById)
  window.onload=initializemarquee





function promocaoFichaInscricao(nome, email, ddd, telefone, ddd2, celular, sexo, promocao)  {
    if( nome == '' || email == '' || ddd == '' || telefone == '' ){
        document.getElementById('botaoPromocao').value = 'Inscrever-se na Promoção';
        alert('Preencha todos os campos do formulário de Promoção.');
        return false;
    }else{
        ajaxRequestInternal("promocaoPersistence.jsp?nome=" + nome + "&email=" + email + "&ddd=" + ddd + "&telefone=" + telefone + "&ddd2=" + ddd2 + "&celular=" + celular + "&sexo=" + sexo + "&promocao=" + promocao,'', function(retorno,sucesso) {
        if(sucesso) {
            alert('Cadastro efetuado com sucesso na promoção vigente. Aguarde o sorteio.');
            document.location.href = "index.jsp";
            //document.getElementById('newsdiv').innerHTML = retorno;
        }
      });
    }
}







function showConteudo(page) {
    ajaxRequestInternal(page,'', function(retorno,sucesso) {
        if(sucesso) {
            document.getElementById('tdConteudo').innerHTML = retorno.replace( execScript( retorno ), eval( execScript( retorno ) ) );
        }
    });

}
        
        
function execScript(codigoHTMLcomScript)
{
    if ( codigoHTMLcomScript.search('<script>') != -1 ){
        // Cria elemento de script
        var scriptObj = document.createElement('script');

        // Divide o responseText em 2 partes, sendo a segunda a parte onde irá iniciar o script
        // então desconsidera a primeira parte.
        tmpScriptCode = codigoHTMLcomScript.split('<script>');

        // divide a parte relevante novamente em 2 partes, sendo que agora a primeira
        // parte conterá o script, a segunda parte é descartada.
        scriptCode = tmpScriptCode[1].split('</script>');

        // Define parâmetro language=javascript para o objeto de script
        scriptObj.setAttribute('language', 'javascript');

        // Atribui o código-fonte do script ao obj de script
        scriptObj.text = scriptCode[0];

        //retornando as funcoes JS
        return scriptObj.text;
    }
}

function paginacao(idsOK, todosIds, div){

    todosIds = todosIds.substr(0, todosIds.length - 3).split("***");
    idsOK = idsOK.substr(0, idsOK.length - 3).split("***");

    for (i = 0; i < todosIds.length; i++){
        document.getElementById(div + todosIds[i]).style.display = 'none';
    }

    for (i = 0; i < idsOK.length; i++){
        document.getElementById(div + idsOK[i]).style.display = '';
    }
}



function openHotSite( chave ){

//	alert( chave );

	document.getElementById("botaoHotSite["+ chave  +"]").onclick = function(){ alert( chave );  }
//botaoHotSite[]
//	window.open('popupHotsite.jsp?idHotsite="'+ chave +'"','Guia de Festas Cuiaba','height = 400, width = 600, scrollbars = yes');

}

function validaFormEmail(){
 if(document.getElementById('emailRemetente').value.length < 5){
   alert('O campo email e obrigatorio!');
   return false;
 }else{
   if (document.getElementById('telefone').value.length < 8 && document.getElementById('telefoneDDD').value.length < 2){
     alert('O campo telefone e obrigatorio!');
     return false;
   }else{
     return true; 
   }
 }
}

function registraEstatistica(objectId, tipoEstatistica, tipoEstatisticaAcesso, getAnuncios, segmentoId){
     var seg = '';
     if(segmentoId != undefined)
         seg = '&segmentoId='+segmentoId;     
     ajaxRequestInternal("registraEstatistica.jsp?objectId="+objectId+"&tipoEstatistica="+tipoEstatistica
     +"&tipoEstatisticaAcesso="+tipoEstatisticaAcesso + "&getAnuncios="+getAnuncios + seg,'', function(retorno,sucesso) {
        if(sucesso) {            
            //document.location.href = "index.jsp";
            //document.getElementById('newsdiv').innerHTML = retorno;
        }
      });
}

/*function click() {
       if (event.button==2||event.button==3) {
               oncontextmenu='return false';
       }
}
document.onmousedown=click
document.oncontextmenu = new Function("return false;")*/
