﻿var App = {};
var Canal = {};
var result;
Canal.Gastronomia = 2; Canal.Shows = 3; Canal.Passeios = 4; Canal.Servicos = 7; Canal.Noite = 8; Canal.Artes_e_Teatro = 9; Canal.Cinema = 11;
Canal.Filhos = 12; Canal.Noite_e_Gastronomia = 13; Canal.Musica_e_Artes = 14; Canal.Mulher = 15; Canal.Teen = 16; Canal.Especiais = 17;
Canal.Estilo = 18; Canal.Em_Casa = 19; Canal.Viagem = 23; Canal.Feito_Para_Você = 25; Canal.Videos = 26; Canal.Arena_Digital = 34; Canal.Minhas_Acoes = 35;
Canal.VerificaCanalAtual = function( idCanal1, idCanal2, idCanal3, idCanal4  ) { return Canal.CanalAtual() == idCanal1 || Canal.CanalAtual() == idCanal2 || Canal.CanalAtual() == idCanal3 || Canal.CanalAtual() == idCanal4; }
Canal.CanalAtual = function() { return window.canalAtual; }
Canal.RetornaBackground = function(){ var r = document.getElementById('LOGO'); return r.childNodes[0].bgColor || r.childNodes[1].bgColor; }

var TipoExibicao = {}; TipoExibicao.Conteudo = 0; TipoExibicao.BuscaFiltroCinema = 1; TipoExibicao.BuscaFiltroGenerico = 2; TipoExibicao.BuscaFiltro = 3; TipoExibicao.BuscaTexto = 4;TipoExibicao.BuscaFiltroCinema2 = 5;TipoExibicao.BuscaFiltroCinema3 = 6;
var ParticipacaoUsuarioResenha = false; 

function Cidade(){}
Cidade.Sao_Paulo = 1; Cidade.Rio_de_Janeiro = 36; Cidade.Salvador = 37; Cidade.Brasília = 38; 
Cidade.Belo_Horizonte = 39; Cidade.Curitiba = 40; Cidade.Porto_Alegre = 41; Cidade.Florianopolis = 43;
Cidade.VerificaCidadeAtual = function( idCidade ) { return Cidade.CidadeAtual() == idCidade; }
Cidade.CidadeAtual = function() { return window.cidadeAtual; }
window.waitBodyList = new Array();
window.waitBodyCallerInterval = null;


function WaitBody(func, inst, args)
{
    if (Tesla.Events.Loaded)
    {
        Exec(func, inst, args);
    }
    else
    {
    
        var chamada = {};
        chamada.func = func;
        chamada.inst = inst;
        chamada.args = args;
        waitBodyList[waitBodyList.length] = chamada;
        if (!waitBodyCallerInterval)
            waitBodyCallerInterval = setInterval(WaitBodyCaller, 500);
    }
}
function Exec(func, inst, args)
{
    if (!args && !inst)
        func.apply();
    else if (!args)
        func.apply(inst);
    else if (!inst)
        func.apply(this, args);
    else
        func.apply(inst, args);
}
function WaitBodyCaller()
{
    if (!Tesla.Events.Loaded) 
        return;
        
    clearInterval(window.waitBodyCallerInterval);
    for (var i=0; i<window.waitBodyList.length; i++)
    {
        var chamada = window.waitBodyList[i];
        Exec(chamada.func, chamada.inst, chamada.args);
    }
}

function FormataNome(nome)
{
	nome = (nome||'').RemoveAcentuacao();
	var rt = '';
	var oldC = null;
	for(var i=0; i<nome.length; i++)
	{
		var c = nome.charAt(i);
		if( (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') )
		{
			rt += c;
			oldC = c;
			continue;
		}
		
		if( oldC != '_' )
			rt += '_';
		oldC = '_';
	}
	
	return rt;
}
function BuscarEndereco(endereco,paramOAS)
{
    var url='';
    if(paramOAS!=null)
        url = '../Mapa/Mapas.aspx?endereco=' + endereco + '&OAS_Query=' + paramOAS;
    else
        url = '../Mapa/Mapas.aspx?endereco=' + endereco;
    location.href = url;
}

function RetornaLink(cidade, canal, funcionalidade, nome, id)
{
	canal = FormataNome((canal||'').RemoveAcentuacao());
	funcionalidade = FormataNome((funcionalidade||'').RemoveAcentuacao().Capitalize());
	
	if( cidade )
		return String.Format("../../../{0}/{1}/{2}/{3}.aspx?id={4}", cidade.Capitalize(), canal, funcionalidade, FormataNome(nome), id);
	if( canal )
		return String.Format("../../{0}/{1}/{2}.aspx?id={3}", canal, funcionalidade, FormataNome(nome), id);
	if( funcionalidade.length )
		return String.Format("../{0}/{1}.aspx?id={2}", funcionalidade, FormataNome(nome), id);
		
	return String.Format("{0}.aspx?id={1}", FormataNome(nome), id);
}

function CarregaControlesBusca()
{
	var p = 'ctl00_AjaxResultadoBusca1_';
	CarregaControle(p, 'ltTituloFilme');
	CarregaControle(p, 'ltGeneroFilme');
	CarregaControle(p, 'ltDescricaoFilme');
	CarregaControle(p, 'imgFilme');
	CarregaControle(p, 'lnkFilme');
	CarregaControle(p, 'dropCanalBuscaTexto');
}
function CarregaControle( prefixo, id )
{
	window[id] = document.getElementById(prefixo+id);
}
function RetornaImage( url, img )
{
	if( String.IsNullOrEmpty( (img||'').Trim() ) )
		return '../../../images/transp.gif';
	return url + img;
}

function ExibeFiltroCanal()
{
	document.getElementById('spanBuscaTextoFiltro').style.display = '';
}

function MudaExibicao( tipoExibicao )
{
	if( !TipoExibicao.Elementos )
	{
		TipoExibicao.Elementos = {};
		TipoExibicao.Elementos.Conteudo = document.getElementById('trConteudo');
		TipoExibicao.Elementos.BuscaFiltroCinema = document.getElementById('trBuscaFiltroCinema1');
		TipoExibicao.Elementos.BuscaFiltroCinema2 = document.getElementById('trBuscaFiltroCinema2');
		TipoExibicao.Elementos.BuscaFiltroCinema3 = document.getElementById('trBuscaFiltroCinema3');
		TipoExibicao.Elementos.BuscaFiltroGenerico = document.getElementById('trBuscaFiltroGenerico'); 
		TipoExibicao.Elementos.BuscaFiltro = document.getElementById('trBuscaFiltro');
		TipoExibicao.Elementos.BuscaEventoData = document.getElementById('trBuscaEventoData');
		TipoExibicao.Elementos.BuscaTexto = document.getElementById('trBuscaTexto');
	}
	
	TipoExibicao.Elementos.Conteudo.style.display = (tipoExibicao==TipoExibicao.Conteudo?'':'none');
	TipoExibicao.Elementos.BuscaFiltroCinema.style.display = (tipoExibicao==TipoExibicao.BuscaFiltroCinema?'':'none');
	TipoExibicao.Elementos.BuscaFiltroCinema2.style.display = (tipoExibicao==TipoExibicao.BuscaFiltroCinema2?'':'none');
	TipoExibicao.Elementos.BuscaFiltroCinema3.style.display = (tipoExibicao==TipoExibicao.BuscaFiltroCinema3?'':'none');
	TipoExibicao.Elementos.BuscaFiltroGenerico.style.display = (tipoExibicao==TipoExibicao.BuscaFiltroGenerico?'':'none');
	TipoExibicao.Elementos.BuscaFiltro.style.display = (tipoExibicao==TipoExibicao.BuscaFiltro?'':'none');
	TipoExibicao.Elementos.BuscaEventoData.style.display = (tipoExibicao==TipoExibicao.BuscaEventoData?'':'none');
	TipoExibicao.Elementos.BuscaTexto.style.display = (tipoExibicao==TipoExibicao.BuscaTexto?'':'none');
}

function AvaliarComentarioCallBack(loginSucesso, parametros)
{
	if( loginSucesso )
	{
		alert( fnVotarComentario( parametros[0], parametros[1], null, true ) );
		var urlsite3 = window.location;
		location.href=urlsite3;
		urlsite3='';
        
	}	
	else
		return;
		
	EscondeLogin();
	
}

function DesabilitaTela()
{
    WaitBody(__DesabilitaTela, null,null);
}

function __DesabilitaTela()
{
//	var divEscondeTela = document.getElementById('divEscondeTela');
//	divEscondeTela.style.width = document.body.scrollWidth;
//	divEscondeTela.style.height = document.body.scrollHeight;
//	divEscondeTela.style.display = '';
    var divEscondeTela = document.getElementById('divEscondeTela');
	divEscondeTela.style.width = document.body.scrollWidth;
	divEscondeTela.style.height = document.body.scrollHeight;
	divEscondeTela.style.display = '';
	if(document.getElementById('ctl01_dropFiltro1')!=null) document.getElementById('ctl01_dropFiltro1').style.display = 'none';
	if(document.getElementById('ctl01_dropFiltro2')!=null) document.getElementById('ctl01_dropFiltro2').style.display = 'none';
	if(document.getElementById('ctl01_dropFiltro3')!=null) document.getElementById('ctl01_dropFiltro3').style.display = 'none';
	document.getElementById('ctl00_BoxMapas1_st_classificacao_imovel').style.display = 'none';
	document.getElementById('ctl00_BoxMapas1_nm_area_util_imovel').style.display = 'none';
	document.getElementById('ctl00_BoxMapas1_nm_quartos_imovel').style.display = 'none';
	if(document.getElementById('bannerTop')!=null) document.getElementById('bannerTop').style.display = 'none';
	if(document.getElementById('bannerx06')!=null) document.getElementById('bannerx06').style.display = 'none';
	if(document.getElementById('bannerRight')!=null) document.getElementById('bannerRight').style.display = 'none';
	if(document.getElementById('bannerBottom')!=null) document.getElementById('bannerBottom').style.display = 'none';
}
function ReabilitaTela()
{
    WaitBody(__ReabilitaTela,null,null);
}
function __ReabilitaTela()
{
	var divEscondeTela = document.getElementById('divEscondeTela');
	divEscondeTela.style.display = 'none';
	if(document.getElementById('ctl01_dropFiltro1')!=null) document.getElementById('ctl01_dropFiltro1').style.display = '';
	if(document.getElementById('ctl01_dropFiltro2')!=null) document.getElementById('ctl01_dropFiltro2').style.display = '';
	if(document.getElementById('ctl01_dropFiltro3')!=null) document.getElementById('ctl01_dropFiltro3').style.display = '';
	document.getElementById('ctl00_BoxMapas1_st_classificacao_imovel').style.display = '';
	document.getElementById('ctl00_BoxMapas1_nm_area_util_imovel').style.display = '';
	document.getElementById('ctl00_BoxMapas1_nm_quartos_imovel').style.display = '';
	if(document.getElementById('bannerTop')!=null) document.getElementById('bannerTop').style.display = '';
	if(document.getElementById('bannerx06')!=null) document.getElementById('bannerx06').style.display = '';
	if(document.getElementById('bannerRight')!=null) document.getElementById('bannerRight').style.display = '';
	if(document.getElementById('bannerBottom')!=null) document.getElementById('bannerBottom').style.display = '';
}

var loginRedirect = null;
var loginCallBack = null;
var loginExibeMsgErro = null;
var FuncionalidadesRestritas = { };
FuncionalidadesRestritas.MeuGuia = 1;
FuncionalidadesRestritas.VouNaoVou = 2;
FuncionalidadesRestritas.Comentario = 3;
FuncionalidadesRestritas.Promocao = 4;
FuncionalidadesRestritas.VotacaoResenhas = 5;
FuncionalidadesRestritas.InsercaoConvite = 6;
FuncionalidadesRestritas.ListagemConvites = 7;

FuncionalidadesRestritas.SetProximaFuncionalidade = function(func)
{
    Tesla.CookieManager.Set('ProximaFuncionalidade',func, false,'/');
}
FuncionalidadesRestritas.GetProximaFuncionalidade = function()
{
    return Tesla.CookieManager.Get('ProximaFuncionalidade');
}
FuncionalidadesRestritas.ClearProximaFuncionalidade = function()
{
    Tesla.CookieManager.Set('ProximaFuncionalidade',null,false,'/');
}
FuncionalidadesRestritas.IrParaProximaFuncionalidade = function()
{
    WaitBody(FuncionalidadesRestritas._IrParaProximaFuncionalidade, this, arguments);
}
FuncionalidadesRestritas._IrParaProximaFuncionalidade = function()
{

    var func = FuncionalidadesRestritas.GetProximaFuncionalidade();
    if (!func) FuncionalidadesRestritas.MostrarMeuGuia();
    else
    {
        FuncionalidadesRestritas.ClearProximaFuncionalidade();
        switch (parseInt(func,10))
        {
            case FuncionalidadesRestritas.MeuGuia:
                FuncionalidadesRestritas.IrParaMeuGuia.CallBackFunction(true,null);
                break;
            case FuncionalidadesRestritas.VouNaoVou:
                var idEvento = Tesla.CookieManager.Get('VouNaoVou_IdEvento');
                var indicacao = Tesla.CookieManager.Get('VouNaoVou_indicacao');
                FuncionalidadesRestritas.IndicaVouEvento(idEvento, indicacao, false );
                break;
            case FuncionalidadesRestritas.Comentario:
                var tipoEntidade = Tesla.CookieManager.Get('InsereComentario_tipoEntidade');
                var id = Tesla.CookieManager.Get('InsereComentario_id');
                var titulo = Tesla.CookieManager.Get('InsereComentario_titulo');
                var texto = Tesla.CookieManager.Get('InsereComentario_texto');
                var idCategoria = Tesla.CookieManager.Get('InsereComentario_idCategoria');
                var tags = Tesla.CookieManager.Get('InsereComentario_tags');
                FuncionalidadesRestritas.InsereComentario(tipoEntidade, id, titulo, texto, idCategoria, tags,false);
                break;
            case FuncionalidadesRestritas.VotacaoResenhas:
                var id = Tesla.CookieManager.Get('VotacaoResenhas_id');
                var voto = Tesla.CookieManager.Get('VotacaoResenhas_voto');
                var razao = Tesla.CookieManager.Get('VotacaoResenhas_razao');
                var aprovacao = Tesla.CookieManager.Get('VotacaoResenhas_aprovacao');
                FuncionalidadesRestritas.VotarResenha( id, voto, razao, aprovacao, false);
                break;
            case FuncionalidadesRestritas.InsercaoConvite:
                FuncionalidadesRestritas.InsereConvite();
                break;
            case FuncionalidadesRestritas.ListagemConvites:
                FuncionalidadesRestritas.ExibeListaConvites();
                break;
            case FuncionalidadesRestritas.Promocao:
                var resposta = Tesla.CookieManager.Get('ParticipaPromocao_resposta');
                var idProm = Tesla.CookieManager.Get('ParticipaPromocao_idProm');
                FuncionalidadesRestritas.ParticipaPromocao(idProm, resposta, false);
                break;
        }
    }
    
}
FuncionalidadesRestritas.MostrarMeuGuia = function()
{
    if( !fnVerificaLogin() ) 
    {
        FuncionalidadesRestritas.SetProximaFuncionalidade(FuncionalidadesRestritas.MeuGuia);
        ExibeLogin(true, '', FuncionalidadesRestritas.IrParaMeuGuia);
        return false; 
    }
    else
    {
        FuncionalidadesRestritas.IrParaMeuGuia.CallBackFunction(true,null);
    }
}
var DeConvite=false;
var MeusConvites=false;
FuncionalidadesRestritas.IrParaMeuGuia = {}; FuncionalidadesRestritas.IrParaMeuGuia.CallBackFunction = function(r,p)
{
    if(!ParticipacaoUsuarioResenha)
    {
          if(DeConvite)
          {
            if(MeusConvites)
            {
            if(r){
                EscondeLogin();
                alert('teste');
                FuncionalidadesRestritas.ExibeListaConvites();
                }
            
            }
            else
            {
                if(r) {
                        EscondeLogin();
                        wz1.Next();
                        void(0);
                        document.getElementById('ctl00_Body_ctl00_botoes').style.display='';
                        document.getElementById('ctl00_Body_ctl00_primeirosbotoes').style.display='none'; 
                        return false; 
                       }
            }
          }
         else
         {
            if (r) location.href = '../../MeuGuia/PerfilUsuario/PerfilUsuario.aspx';
         }
    }
   else 
   {
           if(ParticipacaoUsuarioResenha)
           {
           EscondeLogin();
           var urlsite2 = window.location;
           alert(urlsite2);
           location.href = urlsite2;  
           urlsite2='';
           }
          
    }
   
}


var jaVotou = false;
FuncionalidadesRestritas.IndicaVouEvento = function(idEvento, indicacao, permanecerNaTela)
{
    var rt;

    if (!window.jaVotou) 
    {
        if( !fnVerificaLogin() )
        {
            FuncionalidadesRestritas.SetProximaFuncionalidade(FuncionalidadesRestritas.VouNaoVou);
            Tesla.CookieManager.Set('VouNaoVou_IdEvento',idEvento,false,'/');
            Tesla.CookieManager.Set('VouNaoVou_indicacao',indicacao,false,'/');
            ExibeLogin(true, '', FuncionalidadesRestritas.IrParaMeuGuia);
            return;
        }

        if (permanecerNaTela) EscondeLogin();
        ExibeMensagem('<b>Lendo informações</b>', 'Por favor aguarde...', true, '../../../images/carrega_busca.gif');	
        rt = fnIndicaVouEvento( idEvento, indicacao);
        EscondeMensagem();
        if( String.IsNullOrEmpty(rt) )
        {
            window.jaVotou = true;
            ExibeMensagem('<b>Guia da Semana</b>', 'Voto registrado!', false);
            if (permanecerNaTela)
            {
                var total = hidTotalVotos.value;
                var totalVouPerc = lblVou.innerText;
                var totalNaoVouPerc = lblNaoVou.innerText;

                var totalVou = totalVouPerc*total/100;

                total++;

                if (indicacao == true) // votou "Vou"
                    totalVou++;

                lblVou.innerText = Math.ceil(totalVou/total*100);
                lblNaoVou.innerText = 100 - lblVou.innerText;

                tdPercentualVou.style.width = lblVou.innerText + "%";
                tdPercentualNaoVou.style.width = lblNaoVou.innerText + "%";
            }
            return;
        }
    } 
    else
    {
        rt = "Você já indicou sua preferência anteriormente!";
    }

    ExibeMensagem('<b>Guia da Semana</b>', rt, false);	
    return;
}
FuncionalidadesRestritas.InsereComentario = function(tipoEntidade, id, titulo, texto, idCategoria, tags, permanecerNaTela)
{
    if( !fnVerificaLogin() )
    {
        FuncionalidadesRestritas.SetProximaFuncionalidade(FuncionalidadesRestritas.Comentario);
        Tesla.CookieManager.Set('InsereComentario_tipoEntidade',tipoEntidade,false,'/');
        Tesla.CookieManager.Set('InsereComentario_id',id,false,'/');
        Tesla.CookieManager.Set('InsereComentario_titulo',titulo,false,'/');
        Tesla.CookieManager.Set('InsereComentario_texto',texto,false,'/');
        Tesla.CookieManager.Set('InsereComentario_idCategoria',idCategoria,false,'/');
        Tesla.CookieManager.Set('InsereComentario_tags',tags,false,'/');
        ExibeLogin(true, '', FuncionalidadesRestritas.IrParaMeuGuia);
        return;
    }
    if (permanecerNaTela) EscondeLogin();
    ExibeMensagem('<b>Lendo informações</b>', 'Por favor aguarde...', true, '../../../images/carrega_busca.gif');	
    rt = fnInsereComentario(tipoEntidade, id, titulo, texto, idCategoria, tags, permanecerNaTela);
    EscondeMensagem();
    ExibeMensagem('<b>Guia da Semana</b>', 'Comentário registrado!', false);
}
FuncionalidadesRestritas.VotarResenha = function( id, voto, razao, aprovacao, permanecerNaTela)
{
    if (permanecerNaTela)
    {
        if( !confirm('Tem certeza de que deseja votar neste comentário?') ) return;
    }

	if( aprovacao )
	{
		//ExibeLogin( true, null, { 'CallBackFunction': AvaliarComentarioCallBack, 'Parameters':[id, voto] } );
		if( !fnVerificaLogin() )
		{
            FuncionalidadesRestritas.SetProximaFuncionalidade(FuncionalidadesRestritas.VotacaoResenhas);
            Tesla.CookieManager.Set('VotacaoResenhas_id',id,false,'/');
            Tesla.CookieManager.Set('VotacaoResenhas_voto',voto,false,'/');
            Tesla.CookieManager.Set('VotacaoResenhas_razao',razao,false,'/');
            Tesla.CookieManager.Set('VotacaoResenhas_aprovacao',aprovacao,false,'/');
            ExibeLogin(true, '', { 'CallBackFunction': AvaliarComentarioCallBack, 'Parameters':[id, voto] });
            ParticipacaoUsuarioResenha = true;
            
		}
		else
		{
			alert( fnVotarComentario( id, voto, null, true ) );
			var urlsite=window.location;
			location.href=urlsite;
			urlsite='';
			
		return;
		}
	}
		
	var rt = fnVotarComentario( id, voto, razao, false );
	if (permanecerNaTela)
	{
	    if( String.IsNullOrEmpty(rt) )
	    {
		    var spn = document.getElementById('voto'+(voto==2?'Nao':'Sim')+id);
		    spn.innerHTML = parseInt(spn.innerHTML)+1;
		    alert( 'Obrigado pela participação.' );
	    }
	    else
	    {
		    alert( rt );
	    }
	}
	else
	{
        //ExibeMensagem('<b>Guia da Semana</b>', 'Obrigado pela participação.', false);
	}
}
FuncionalidadesRestritas.InsereConvite = function()
{
    if ( !fnVerificaLogin() )
    {
        FuncionalidadesRestritas.SetProximaFuncionalidade(FuncionalidadesRestritas.InsercaoConvite);
        ExibeLogin(true, '', FuncionalidadesRestritas.IrParaMeuGuia);
        return;
    }
    else
    {
        var convite = Tesla.CookieManager.LoadObject('convite_dadosConvite');
        ExibeMensagem('<b>Gravando informações</b>', 'Por favor aguarde...', true, '../../../images/carrega_busca.gif');	
        window.IdConviteAtual = fnInsereConvite(convite);
        EscondeMensagem();
        ExibeMensagem('<b>Gravando informações</b>', 'Por favor aguarde...', true, '../../../images/carrega_busca.gif');	
        fnInsereEmails( window.IdConviteAtual, convite.emails );
        EscondeMensagem();
	    fnEnviaEmails( Cidade.CidadeAtual(), window.IdConviteAtual, function(rt){ alert( 'Convite cadastrado com sucesso!' ); } );
    }
}

FuncionalidadesRestritas.ExibeListaConvites = function()
{
    if ( !fnVerificaLogin() )
    {
        FuncionalidadesRestritas.SetProximaFuncionalidade(FuncionalidadesRestritas.ListagemConvites);
        ExibeLogin(true, '', FuncionalidadesRestritas.IrParaMeuGuia);
        return;
    }
    else
    {   
        location.href = '../Funcionalidade/Convite.aspx?ListaConvites=1';
        document.getElementById('ctl00_Body_ctl00_primeirosbotoes').style.display='none';
    }
}
FuncionalidadesRestritas.ParticipaPromocao = function(idProm, resposta, permanecerNaTela)
{
    if( !fnVerificaLogin() )
    {
        FuncionalidadesRestritas.SetProximaFuncionalidade(FuncionalidadesRestritas.Promocao);
        Tesla.CookieManager.Set('ParticipaPromocao_resposta',resposta,false,'/');
        Tesla.CookieManager.Set('ParticipaPromocao_idProm',idProm,false,'/');
        ExibeLogin(true, '', FuncionalidadesRestritas.IrParaMeuGuia);
        return;
    }
    if (permanecerNaTela) EscondeLogin();
    ExibeMensagem('<b>Lendo informações</b>', 'Por favor aguarde...', true, '../../../images/carrega_busca.gif');
    fnInserePromocao(idProm, resposta);
    EscondeMensagem();
    ExibeMensagem('<b>Guia da Semana</b>', 'Sua inscrição foi realizada com sucesso! Boa sorte!', false);
}

function ExibeLogin(exibeMsgErro, pageRedirect, callBack)
{
    WaitBody(__ExibeLogin, this, arguments);
}

function __ExibeLogin(exibeMsgErro, pageRedirect, callBack)
{
	if( pageRedirect != null && pageRedirect.length > 0 )
		loginRedirect = pageRedirect.Replace( '&', '_and_' );
	
	loginCallBack = callBack;
	loginExibeMsgErro = exibeMsgErro;
	
	DesabilitaTela();
	var divLogin = document.getElementById('divLogin');
	divLogin.style.top = document.body.scrollTop + 50;
	divLogin.style.left = (retorna_clientWidth()/2) - 200;
	divLogin.style.display = '';
	document.getElementById('txtEmailLogin').focus();
	
	document.getElementById('ctl01_dropFiltro1').style.display = 'none';
	document.getElementById('ctl01_dropFiltro2').style.display = 'none';
	document.getElementById('ctl01_dropFiltro3').style.display = 'none';
}
function EscondeLogin(naoReabilitaTela)
{
	document.getElementById('txtEmailLogin').value = '';
	document.getElementById('txtSenhaLogin').value = '';
	if( !naoReabilitaTela )
		ReabilitaTela();
	document.getElementById('divLogin').style.display = 'none';
	document.getElementById('ctl01_dropFiltro1').style.display = '';
	document.getElementById('ctl01_dropFiltro2').style.display = '';
	document.getElementById('ctl01_dropFiltro3').style.display = '';
}
function EfetuaLogin()
{
	if( fnEfetuaLogin( document.getElementById('txtEmailLogin').value, document.getElementById('txtSenhaLogin').value ) )
	{
		if( loginCallBack != null )
			loginCallBack.CallBackFunction(true, loginCallBack.Parameters);
		else if( loginRedirect != null && loginRedirect.length > 0  )
			window.location = loginRedirect.Replace( '_and_', '&' );
	}
	else
	{
		if( loginCallBack != null )
			loginCallBack.CallBackFunction(false, loginCallBack.Parameters);
		if( loginExibeMsgErro )
			alert( 'Nome de usuário, ou senha, invalidos.' );
	}
}

function PesquisaFiltroCinema(semMensagem)
{
	window.EscondeFiltros = false;
	var dropFiltro1 = GetListControl('ctl01_dropFiltro1');
	var dropFiltro2 = GetListControl('ctl01_dropFiltro2');
	var dropFiltro3 = GetListControl('ctl01_dropFiltro3');

	var filme = null;
	var genero = null;
	var regiao = null;
	var cinema = null;
	var horario = null;
	
	if( dropFiltro1.GetSelectedItemAttribute('grupo') == 1 )
		filme = dropFiltro1.SelectedValue();
	if( dropFiltro1.GetSelectedItemAttribute('grupo') == 2 )
		genero = dropFiltro1.SelectedValue();
	if( dropFiltro2.GetSelectedItemAttribute('grupo') == 1 )
		regiao = dropFiltro2.SelectedValue();
	if( dropFiltro2.GetSelectedItemAttribute('grupo') == 2 )
		cinema = dropFiltro2.SelectedValue();
	if( dropFiltro3.GetSelectedItemAttribute('grupo') == 1 )
		horario = dropFiltro3.SelectedValue();
		
	if( filme == null && genero == null && regiao == null && cinema == null && horario == null )
	{
		alert( 'Você deve selecionar um dos critérios de busca' );
		return;
	}

	if( filme != null && dropFiltro2.selectedIndex == 0 && dropFiltro3.selectedIndex == 0 )
		window.location.href = String.Format('../Filme/{0}.aspx?id={1}', FormataNome(dropFiltro1.SelectedText()), filme );
	else if( filme == null && dropFiltro2.GetSelectedItemAttribute('grupo') == 2 )
		window.location.href = String.Format('../Sala/{0}.aspx?id={1}&genero={2}&horario={3}', FormataNome(dropFiltro2.SelectedText()), cinema, genero, horario );
	else
	{
		if(!semMensagem)
			ExibeMensagem('<b>Realizando a busca</b>', 'Por favor aguarde...', true, '../../../images/carrega_busca.gif');
		if( filme )
			fnBuscaSessoes( Cidade.CidadeAtual(), filme, cinema, regiao, horario, TerminaPesquisaFiltroCinema1, TrataErro);
		else if( genero )
			fnBuscaFilmes( Cidade.CidadeAtual(), genero, regiao, horario, TerminaPesquisaFiltroCinema2, TrataErro );
		else if( regiao )
			fnBuscaCinemas( Cidade.CidadeAtual(), regiao, horario, TerminaPesquisaFiltroCinema3, TrataErro );
		else
			fnBuscaFilmesPorHorario( Cidade.CidadeAtual(), genero, regiao, horario, TerminaPesquisaFiltroCinema2, TrataErro );
	}
}

function PesquisaFiltroTeens(semMensagem)
{
	var dropFiltro1 = GetListControl('ctl01_dropFiltro1');
	var dropFiltro2 = GetListControl('ctl01_dropFiltro2');
	var dropFiltro3 = GetListControl('ctl01_dropFiltro3');
	
	var evento = null;
	var local = null;
	var regiao = null;
	var prop = null;
	
	if (dropFiltro1.GetSelectedItemAttribute('grupo') == 1)
	    evento = dropFiltro1.SelectedValue();
	if (dropFiltro2.GetSelectedItemAttribute('grupo') == 1)
	    local = dropFiltro2.SelectedValue();
	if (dropFiltro2.GetSelectedItemAttribute('grupo') == 2)
	    regiao = dropFiltro2.SelectedValue();
	if (dropFiltro3.GetSelectedItemAttribute('grupo') == 1)
	    prop = dropFiltro3.SelectedValue();
	    
	if (!evento && !local && !regiao && !prop)
	{
		alert('Você deve selecionar um filtro.');
		return;
	}
	    
	if (evento)
		window.location.href = String.Format( '../Evento/{0}.aspx?id={1}', FormataNome(dropFiltro1.SelectedText()), evento );
	else if (local)
		window.location.href = String.Format( '../Evento/{0}.aspx?id={1}', FormataNome(dropFiltro2.SelectedText()), local );
	else
        fnBuscaEventos(cidadeAtual, 16, null, regiao, prop, TerminaPesquisaFiltro);
}

function PesquisaFiltroVideos()
{
    var dropFiltro1 = GetListControl('ctl01_dropFiltro1');
	var dropFiltro2 = GetListControl('ctl01_dropFiltro2');
	/*var dropFiltro3 = GetListControl('ctl01_dropFiltro3');*/
	var p1 = dropFiltro1.SelectedValue();
	var p2 = dropFiltro2.SelectedValue();
	/*var p3 = dropFiltro3.SelectedValue();*/
	if(p1)
	    window.location.href = String.Format( '../ListaFilmes/ListaFilmes.aspx?letra={0}', p1 );
	if(p2)
	    window.location.href = String.Format( '../ListaVideos/ListaVideos.aspx?letra={0}', p2 );
}

function PesquisaFiltro(semMensagem)
{
    if( Canal.VerificaCanalAtual( Canal.Videos ) )
    {
        PesquisaFiltroVideos();
        return;
    }
    
	if( Canal.VerificaCanalAtual( Canal.Cinema ) )
	{
		PesquisaFiltroCinema(semMensagem);				
		return;
	} 

	var dropFiltro1 = GetListControl('ctl01_dropFiltro1');
	var dropFiltro2 = GetListControl('ctl01_dropFiltro2');
	var dropFiltro3 = GetListControl('ctl01_dropFiltro3');
	
	if ( Canal.CanalAtual() == Canal.Teen )
	{
	    PesquisaFiltroTeens();
	    return;
	}
	
	if ( Canal.CanalAtual() == Canal.Viagem )
	{
		if( dropFiltro2.selectedIndex == 0 )
		{
			alert('Você deve selecionar um filtro.')
			return;
		}
		PesquisaFiltroNoticia( dropFiltro2.SelectedValue(), semMensagem );
		return;
	}

	var p1 = dropFiltro1.SelectedValue();
	var p2 = dropFiltro2.SelectedValue();
	var p3 = dropFiltro3.SelectedValue();

	if( (Canal.VerificaCanalAtual( Canal.Filhos ) ||Canal.VerificaCanalAtual( Canal.Shows ) || Canal.VerificaCanalAtual( Canal.Artes_e_Teatro ) || Canal.VerificaCanalAtual( Canal.Musica_e_Artes )) && dropFiltro1.GetSelectedItemAttribute('grupo') == 1 )
		window.location.href = String.Format( '../Evento/{0}.aspx?id={1}', FormataNome(dropFiltro1.SelectedText()), p1 );
	else if( (Canal.VerificaCanalAtual( Canal.Shows ) || Canal.VerificaCanalAtual( Canal.Artes_e_Teatro ) || Canal.VerificaCanalAtual( Canal.Musica_e_Artes )) && dropFiltro2.GetSelectedItemAttribute('grupo') == 1 )
		window.location.href = String.Format( '../Estabelecimento/{0}.aspx?id={1}', FormataNome(dropFiltro2.SelectedText()), p2 );
//	else if( canalAtual == Canal.Música_e_Artes && dropFiltro2.GetSelectedItemAttribute('grupo') == 1)
//	    window.location.href = String.Format( '../Estabelecimento/{0}.aspx?id={1}', FormataNome(dropFiltro2.SelectedText()), p2 );
//	else if( canalAtual == Canal.Música_e_Artes && !dropFiltro1.disabled )
//	    window.location.href = String.Format( '../Evento/{0}.aspx?id={1}', FormataNome(dropFiltro1.SelectedText()), p1 );
	else
	{
		if(!semMensagem)
		    ExibeMensagem('<b>Realizando a busca</b>', 'Por favor aguarde...', true, '../../../images/carrega_busca.gif');
		if ( Canal.VerificaCanalAtual(Canal.Mulher) && (dropFiltro1.selectedIndex > 0) )
			fnBuscaEstabelecimentosPorTipo( cidadeAtual, canalAtual, p1, p3, null, TerminaPesquisaFiltro )
		else if ( Canal.VerificaCanalAtual(Canal.Mulher) && (dropFiltro2.selectedIndex > 0) )
			fnBuscaEstabelecimentosPorTipo( cidadeAtual, canalAtual, p2, p3, null, TerminaPesquisaFiltro )
		else if ( Canal.VerificaCanalAtual(Canal.Mulher) && (dropFiltro2 != null && dropFiltro2.selectedIndex > 0) )
		    fnBuscaEstabelecimentosPorTipo( cidadeAtual, canalAtual, p2, p1, p3, TerminaPesquisaFiltro )
		else if( Canal.VerificaCanalAtual(Canal.Filhos))
		{
			fnBuscaEventosPorTipo( cidadeAtual, canalAtual, p1, p3, p2, TerminaPesquisaFiltro )
		}
		else if( dropFiltro1.selectedIndex > 0 && ( Canal.VerificaCanalAtual( Canal.Passeios, Canal.Filhos ) ) )
			fnBuscaEstabelecimentosPorTipo( cidadeAtual, canalAtual, p1, p2, dropFiltro1.GetSelectedItemAttribute('tag'), TerminaPesquisaFiltro );
		else if( dropFiltro3.selectedIndex > 0 && ( Canal.VerificaCanalAtual( Canal.Estilo ) ) )
		    fnBuscaEventosPorTipo( cidadeAtual, canalAtual, 10, null,null, TerminaPesquisaFiltro );
		else
			fnBuscaFiltros(cidadeAtual, canalAtual, p1, p2, p3, TerminaPesquisaFiltro);
	}
}

function PesquisaFiltroNoticia(propriedade, semMensagem)
{
	if(!semMensagem)
		ExibeMensagem('<b>Realizando a busca</b>', 'Por favor aguarde...', true, '../../../images/carrega_busca.gif');
	fnBuscaNoticias( Cidade.CidadeAtual(), Canal.CanalAtual(), propriedade, TerminaPesquisaFiltroGenerico);
}
function VerificaPesquisa()
{
	//var cookie = GetCookie('ckPesquisaFiltro');
	//if( cookie == null || cookie.length == 0 || window.idPagina != cookie.Split('|')[0] )
		return;

	var filtros = cookie.Split('|')[1].Split(':');
	var dropFiltro1 = GetListControl('ctl01_dropFiltro1');
	var dropFiltro2 = GetListControl('ctl01_dropFiltro2');
	var dropFiltro3 = GetListControl('ctl01_dropFiltro3');

	dropFiltro1.SetSelectedValue( filtros[0] );
	dropFiltro2.SetSelectedValue( filtros[1] );
	dropFiltro3.SetSelectedValue( filtros[2] );

	PesquisaFiltro(true);
}

function TerminaPesquisaFiltroGenerico(pesquisa)
{
	if( pesquisa == null || pesquisa.length == 0 )
	{
		EscondeMensagem();
		alert( 'Não foi encontrado nenhum registro com o filtro escolhido' );
		return;
	}

	rptBuscaFiltroGenerico.Bind(pesquisa);
	MudaExibicao( TipoExibicao.BuscaFiltroGenerico );
	EscondeMensagem();
	setTimeout('AtualizaBanners();',10);
}
function TerminaPesquisaFiltroCinema2(pesquisa)
{
    if( pesquisa == null || pesquisa.length == 0 )
	{
		EscondeMensagem();
		alert( 'Não foi encontrado nenhum registro com o filtro escolhido' );
		return;
	}
	BindRepeaterAsync( rptBuscaFiltroCinema2, pesquisa );
	MudaExibicao( TipoExibicao.BuscaFiltroCinema2 );
	EscondeMensagem();
	setTimeout('AtualizaBanners();',10);
}
function TerminaPesquisaFiltroCinema3(pesquisa)
{
	if( pesquisa == null || pesquisa.length == 0 )
	{
		EscondeMensagem();
		alert( 'Não foi encontrado nenhum registro com o filtro escolhido' );
		return;
	}
	BindRepeaterAsync( rptBuscaFiltroCinema3, pesquisa );
	MudaExibicao( TipoExibicao.BuscaFiltroCinema3 );
	EscondeMensagem();
	setTimeout('AtualizaBanners();',10);
}
function TerminaPesquisaFiltroCinema1(pesquisa)
{
	if( pesquisa == null )
	{
		EscondeMensagem();
		alert( 'Não foi encontrado nenhum registro com o filtro escolhido' );
	}

	imgFilme.src = pesquisa.Filme.Foto;
	lnkFilme.href = pesquisa.Filme.Link;
	ltTituloFilme.innerHTML = pesquisa.Filme.Titulo;
	ltDescricaoFilme.innerHTML = pesquisa.Filme.Subtitulo;
	ltGeneroFilme.innerHTML = pesquisa.Filme.Genero;
	rptBuscaFiltroCinema1.Bind( pesquisa.Sessoes );
	EscondeMensagem();
	MudaExibicao( TipoExibicao.BuscaFiltroCinema );
	setTimeout('AtualizaBanners();',10);
}

function TrataErro(ex)
{
	EscondeMensagem();
	alert( 'Ocorreu um erro inesperado.' );
}
function TerminaPesquisaFiltro( rt )
{
	if( rt == null || rt.length == 0 )
	{
		EscondeMensagem();
		alert( 'Não foi encontrado nenhum estabelecimento, ou evento, com o filtro escolhido' );
		return false;
	}
	rptBuscaFiltro.Bind( rt, 10, AjaxRepeater.BindMethod.Async );
	EscondeMensagem();
	MudaExibicao( TipoExibicao.BuscaFiltro );
	setTimeout('AtualizaBanners();',10);
}
function TerminaPesquisaEventoData( rt )
{
	if( rt == null || rt.length == 0 )
	{
		EscondeMensagem();
		alert( 'Não foi encontrado nenhum evento ativo neste canal' );
		return false;
	}
	rptBuscaEventoData.Bind( rt, 10, AjaxRepeater.BindMethod.Async );
	EscondeMensagem();
	MudaExibicao( TipoExibicao.BuscaEventoData );
	setTimeout('AtualizaBanners();',10);
}

function TerminaPesquisaPorTipo( rt )
{
	if( rt == null || rt.length == 0 )
	{
		EscondeMensagem();
		alert( 'Não foi encontrado nenhum item do tipo escolhido' );
		return false;
	}
	rptBuscaFiltro.Bind( rt );
	EscondeMensagem();
	MudaExibicao( TipoExibicao.BuscaFiltro );
	setTimeout('AtualizaBanners();',10);
}

function VerificaMudanca(idx, drop)
{
    if( Cidade.CidadeAtual() == Cidade.Belo_Horizonte && Canal.CanalAtual() == Canal.Musica_e_Artes )
    {
       	ListControlFunctions.BindFunctions(drop);
       	if(drop.id == 'ctl01_dropFiltro1' && drop.selectedIndex > 0)
       	{
       	    GetListControl('ctl01_dropFiltro2').disabled = true;
       	    GetListControl('ctl01_dropFiltro3').disabled = true;
       	}
       	else if(drop.id == 'ctl01_dropFiltro1' && drop.selectedIndex == 0)
       	{
       	    GetListControl('ctl01_dropFiltro2').disabled = false;
       	    GetListControl('ctl01_dropFiltro3').disabled = false;
       	}
       	if(drop.id == 'ctl01_dropFiltro2' && drop.selectedIndex > 0)
       	{
       	    GetListControl('ctl01_dropFiltro1').disabled = true;
       	    GetListControl('ctl01_dropFiltro3').disabled = true;
       	}
       	else if(drop.id == 'ctl01_dropFiltro2' && drop.selectedIndex == 0)
       	{
       	    GetListControl('ctl01_dropFiltro1').disabled = false;
       	    GetListControl('ctl01_dropFiltro3').disabled = false;
       	}
       	if(drop.id == 'ctl01_dropFiltro3' && drop.selectedIndex > 0)
       	{
       	    GetListControl('ctl01_dropFiltro2').disabled = true;
       	    GetListControl('ctl01_dropFiltro1').disabled = true;
       	}
       	else if(drop.id == 'ctl01_dropFiltro3' && drop.selectedIndex == 0)
       	{
       	    GetListControl('ctl01_dropFiltro2').disabled = false;
       	    GetListControl('ctl01_dropFiltro1').disabled = false;
       	}       	
       	return;
    }
    if( Cidade.CidadeAtual() == Cidade.Belo_Horizonte )
    {
    	ListControlFunctions.BindFunctions(drop);
	    if(drop.id == 'ctl01_dropFiltro1' && drop.selectedIndex > 0)
	        GetListControl('ctl01_dropFiltro2').disabled = true;
	    if(drop.id == 'ctl01_dropFiltro1' && drop.selectedIndex == 0)
	        GetListControl('ctl01_dropFiltro2').disabled = false;
	    if(drop.id == 'ctl01_dropFiltro2' && drop.selectedIndex > 0)
	        GetListControl('ctl01_dropFiltro1').disabled = true;
	    if(drop.id == 'ctl01_dropFiltro2' && drop.selectedIndex == 0)
	        GetListControl('ctl01_dropFiltro1').disabled = false;    
    }
	if( Canal.CanalAtual() == Canal.Viagem )
	{
		if( idx != 1 )
			return;
		
		ListControlFunctions.BindFunctions(drop);
		if( String.IsNullOrEmpty(drop.SelectedValue()) )
		{
		    GetListControl('ctl01_dropFiltro2').disabled = true; //document.getElementById('ctl01_trFiltro2').style.display = 'none';
			return;
		}			
		
		var dropFiltro2 = GetListControl('ctl01_dropFiltro2');
		dropFiltro2.Bind( fnListaPropriedades(drop.SelectedValue()), 'Value', 'Text', 'Destinos' ); //dropFiltro2.Bind( fnListaPropriedades(drop.SelectedValue()), 'ID', 'Nome', 'Destinos' );
		dropFiltro2.AddAt(1, '', '');
		for(var i=2; i<dropFiltro2.length; i++)
			dropFiltro2.options[i].style.backgroundColor = '#e7e7e7';
		dropFiltro2.disabled = false; //document.getElementById('ctl01_trFiltro2').style.display = '';
		return;
	}
	
	if( Canal.CanalAtual() == Canal.Mulher )
	{
	    ListControlFunctions.BindFunctions(drop);
	    if(drop.id == 'ctl01_dropFiltro1' && drop.selectedIndex > 0)
	        GetListControl('ctl01_dropFiltro2').disabled = true;
	    if(drop.id == 'ctl01_dropFiltro1' && drop.selectedIndex == 0)
	        GetListControl('ctl01_dropFiltro2').disabled = false;
	    if(drop.id == 'ctl01_dropFiltro2' && drop.selectedIndex > 0)
	        GetListControl('ctl01_dropFiltro1').disabled = true;
	    if(drop.id == 'ctl01_dropFiltro2' && drop.selectedIndex == 0)
	        GetListControl('ctl01_dropFiltro1').disabled = false;
    }

	if( Canal.CanalAtual() == Canal.Videos )
	{
	    ListControlFunctions.BindFunctions(drop);
	    if(drop.id == 'ctl01_dropFiltro1' && drop.selectedIndex > 0)
	        GetListControl('ctl01_dropFiltro2').disabled = true;
	    if(drop.id == 'ctl01_dropFiltro1' && drop.selectedIndex == 0)
	        GetListControl('ctl01_dropFiltro2').disabled = false;
	    if(drop.id == 'ctl01_dropFiltro2' && drop.selectedIndex > 0)
	        GetListControl('ctl01_dropFiltro1').disabled = true;
	    if(drop.id == 'ctl01_dropFiltro2' && drop.selectedIndex == 0)
	        GetListControl('ctl01_dropFiltro1').disabled = false;
    }

	//if( !Canal.VerificaCanalAtual( Canal.Shows, Canal.Artes_e_Teatro, Canal.Estilo ) )
	if( !Canal.VerificaCanalAtual( Canal.Estilo ) )
		return;
		
	ListControlFunctions.BindFunctions(drop);
	var value = drop.SelectedValue();		
	var exclusivo = drop.GetSelectedItemAttribute('grupo')=='1' && (idx == 1 || idx == 2 );
	exclusivo |= ( Canal.VerificaCanalAtual( Canal.Mulher, Canal.Estilo ) && drop.selectedIndex > 0 );
	
	for(var i=1; i<=3; i++)
	{
		var ctrl = document.getElementById('ctl01_dropFiltro'+i);
		if( idx != i && exclusivo)
		{
			ctrl.selectedIndex = 0;
			ctrl.disabled = true;
		}
		else
			ctrl.disabled = false;
	}
}

function PesquisaEventoPorGenero(genero)
{
	fnBuscaFiltros(Cidade.CidadeAtual(), Canal.CanalAtual(), genero, null, null, TerminaPesquisaFiltro);
	window.scrollTo(0,0);
}


function SobeTela()
{
	document.body.scrollTop = 0;
	document.body.scrollLeft = 0;
}
function IncluiFan()
{
	if( !fnVerificaLogin() )
	{
		ExibeLogin( true, window.location.href, { 'CallBackFunction': IncluiFan } );
		return;
	}
	EscondeLogin();
	ExibeMensagem('<b>Lendo informações</b>', 'Por favor aguarde...', true, '../../../images/carrega_busca.gif');	
	fnIncluiFan( window.IdItem, TerminaInclusaoFan);
}

function TerminaInclusaoFan(rt)
{
	EscondeMensagem();
	if( String.IsNullOrEmpty(rt) )
	{
		alert( 'Agora voce é fã deste local' );
		window.location = window.location;
		return;
	}
	alert( rt );
}


function AtualizaBanners()
{
    if (posicoesAtualizaveis && posicoesAtualizaveis.length > 0)
    {
        if (!window.reloadTime) window.reloadTime = 1; else window.reloadTime += 1;
        if ((OAS_keyword || '') != '') return;
        document.atualizarTodos = 1;
        document.proximaPosicao = 1;
        AtualizaBanner(posicoesAtualizaveis[0]);
    }
}

//function AtualizaBanner(posicao)
//{
//    if (!window.reloadTime) window.reloadTime = 1;
//    var oasQuery = '';
//    if (!window.OAS_query || window.OAS_query == '')
//	   oasQuery = '?PV=' + window.reloadTime;
//    else
//	   oasQuery = window.OAS_query +'&PV=' + window.reloadTime;

//    fnRetornaBanner(OAS_sitepage + '/reload/' + parseInt(window.reloadTime).toString(), OAS_listpos, posicao, URLEncode(oasQuery), EndAtualizaBanner);
//    if (window.alertarDocumentWrite) 
//        document.getElementById('divStringBanner').innerHTML = 'Page:' + OAS_sitepage + '/reload/' + parseInt(window.reloadTime).toString() + '<br' + '>' 
//                                                             + 'OAS_QUERY:' + OAS_query + '<br' + '>'
//                                                             + 'OAS_LISTPOS:' + OAS_listpos + '<br' + '>';
//}

function AtualizaBanner(posicao)
{
    if (!window.reloadTime) window.reloadTime = 1;
    var oasQuery = '';
    oasQuery = 'PV=' + window.reloadTime;

    fnRetornaBanner(OAS_sitepage + '/reload/' + parseInt(window.reloadTime).toString(), OAS_listpos, posicao, URLEncode(oasQuery), EndAtualizaBanner);
    if (window.alertarDocumentWrite) 
        document.getElementById('divStringBanner').innerHTML = 'Page:' + OAS_sitepage + '/reload/' + parseInt(window.reloadTime).toString() + '<br' + '>' 
                                                             + 'OAS_QUERY:' + OAS_query + '<br' + '>'
                                                             + 'OAS_LISTPOS:' + OAS_listpos + '<br' + '>';
}

function URLEncode (clearString) {
  var output = '';
  var x = 0;
  clearString = clearString.toString();
  var regex = /(^[a-zA-Z0-9_.]*)/;
  while (x < clearString.length) {
    var match = regex.exec(clearString.substr(x));
    if (match != null && match.length > 1 && match[1] != '') {
    	output += match[1];
      x += match[1].length;
    } else {
      if (clearString[x] == ' ')
        output += '+';
      else {
        var charCode = clearString.charCodeAt(x);
        var hexVal = charCode.toString(16);
        output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
      }
      x++;
    }
  }
  return output;
}


function EndAtualizaBanner(rt)
{
    var posicao = rt.Posicao;
    var content = rt.Banner;
    var str = new String(content);
    if (!str) return;
    if (str.toLowerCase().indexOf('<script') >= 0)
    {
        if (window.alertarDocumentWrite)
        {
            alert('Banner com script');
            alert(str);
        }
    }
    else
    {
	var spanBanner = document.getElementById('banner'+posicao);
	if( spanBanner != null )
	{
		document.bannerAtual = posicao;
    		ApplyContentToElement(spanBanner, '<div'+'>'+content+'</'+'div>');
	}
    }
    if (document.atualizarTodos)
    {
        if (document.proximaPosicao < posicoesAtualizaveis.length)
        {
            document.proximaPosicao += 1;
            AtualizaBanner(posicoesAtualizaveis[document.proximaPosicao-1]);
        }
        else
        {
            document.atualizarTodos = null;
        }
    }
}


function ApplyContentToElement(divContainer, content)
{
    if (content == '') return;
	if (divContainer.innerHTML) divContainer.innerHTML = '';
	var dxx = document.createElement('div'); dxx.innerHTML = content;
	while (dxx.childNodes.length > 0)
	{
		var node = dxx.childNodes[0];
		node.parentNode.removeChild(node);
		if (FindScriptNode(node)) continue;
		divContainer.appendChild(node);
	}
}


function TestScriptNode(node)
{
	if (((node.nodeType || 0) != 1) || ((node.tagName || '').toUpperCase() != 'SCRIPT')) return false;

	var headID = document.getElementsByTagName('head')[0];
	var ns = document.createElement('script');
	ns.type = 'text/javascript';
	ns.language = 'javascript';
    	if (node.src) ns.src = node.src;
	ns.text = node.innerHTML;
    	if (node.parentNode) node.parentNode.removeChild(node);
    
	return true;
}
function FindScriptNode(node)
{
	if (TestScriptNode(node)) return true; 
	if (node.childNodes) for (var i=0; i<node.childNodes.length; i++) if (FindScriptNode(node.childNodes[i])) i--;
	return false;
}
var temperaturaDia = 0;
function MudaTemperatura(tipo)
{
	//if( tipo == 1 )
}

function ExibeVideo(url)
{
	DesabilitaTela();
	var divVideo = document.getElementById('divVideo');
	divVideo.innerHTML = '<table border="1"><tr><td align="right"><a href="javascript: FechaVideo();"><img src="../../../images/bt_fechar.gif" border="0"></a><br/><EMBED SRC="'+url+'" WIDTH="400" HEIGHT="300" style="background-color:Black;"></EMBED></td></tr></table>'
	divVideo.style.top = document.body.scrollTop + 110;
	divVideo.style.left = document.body.scrollLeft + 240;
	divVideo.style.display = '';
}
function FechaVideo()
{
	ReabilitaTela();
	var div = document.getElementById('divVideo');
	div.innerHTML = '';
	div.style.display = 'none';
}
function ListaEstreias()
{
    //TerminaPesquisaFiltroCinema2
	SobeTela();
	window.EscondeFiltros = true;
	//fnListaEstreias( Cidade.CidadeAtual(), TerminaPesquisaFiltroGenerico, TrataErro );
	fnListaEstreias( Cidade.CidadeAtual(), TerminaPesquisaFiltroCinema2, TrataErro );
}
function ListaPreEstreias()
{
	SobeTela();
	window.EscondeFiltros = true;
	//fnListaPreEstreias( Cidade.CidadeAtual(), TerminaPesquisaFiltroGenerico, TrataErro );
	fnListaPreEstreias( Cidade.CidadeAtual(), TerminaPesquisaFiltroCinema2, TrataErro );
}
function ListaCartaz()
{
	SobeTela();
	window.EscondeFiltros = true;
	//fnListaFilmesCartaz( Cidade.CidadeAtual(), TerminaPesquisaFiltroGenerico, TrataErro );
	fnListaFilmesCartaz( Cidade.CidadeAtual(), TerminaPesquisaFiltroCinema2, TrataErro );
}

function BuscaTexto( texto, tipoBuscaTextual, canal )
{
	if(texto.length >= 3)
	{
	    window.UltimoTipoBuscaTextual = tipoBuscaTextual;
	    tipoBuscaTextual = (tipoBuscaTextual||0);
	    ExibeMensagem('<b>Realizando a busca</b>', 'Por favor aguarde...', true, '../../../images/carrega_busca.gif');
	    document.getElementById('txtTexto').innerHTML = texto;
	    window.ExibeMostrarTodosResultado = tipoBuscaTextual==0;
	    fnBuscaTexto( texto, Cidade.CidadeAtual(), canal||0, tipoBuscaTextual||0, EndBuscaTexto );
	}
	else
	{
	    alert('A chave de pesquisa precisa conter pelo menos 3 caracteres.');
	}
}
function BuscaTextoPriorizada( texto, tipoBuscaTextual, canal )
{
	if(texto.length >= 3)
	{
	    window.UltimoTipoBuscaTextual = tipoBuscaTextual;
	    tipoBuscaTextual = (tipoBuscaTextual||0);
	    ExibeMensagem('<b>Realizando a busca</b>', 'Por favor aguarde...', true, '../../../images/carrega_busca.gif');
	    document.getElementById('txtTexto').innerHTML = texto.toUpperCase();
	    window.ExibeMostrarTodosResultado = tipoBuscaTextual==0;
	    fnBuscaTextoPriorizada( texto, Cidade.CidadeAtual(), canal||0, tipoBuscaTextual||0, window.canalAtual||0, EndBuscaTexto );
	}
	else
	{
	    alert('A chave de pesquisa precisa conter pelo menos 3 caracteres.');
	}
}

function BuscaTextoPriorizadaExterno( texto, tipoBuscaTextual, canal )
{
	if(texto.length >= 3)
	{
	    window.UltimoTipoBuscaTextual = tipoBuscaTextual;
	    tipoBuscaTextual = (tipoBuscaTextual||0);
	    ExibeMensagem('<b>Realizando a busca</b>', 'Por favor aguarde...', true, '../../../images/carrega_busca.gif');
	    document.getElementById('txtTexto').innerHTML = texto.toUpperCase();
	    window.ExibeMostrarTodosResultado = tipoBuscaTextual==0;
	    fnBuscaTextoPriorizada( texto, Cidade.CidadeAtual(), canal||0, tipoBuscaTextual||0, window.canalAtual||0, EndBuscaTextoExterno );
	}
	else
	{
	    alert('A chave de pesquisa precisa conter pelo menos 3 caracteres.');
	}
}

function EndBuscaTexto( resultado )
{
	var total = (resultado.Noticias ? resultado.Noticias.length : 0)
	    + (resultado.Eventos ? resultado.Eventos.length : 0)
	    + (resultado.Estabelecimentos ? resultado.Estabelecimentos.length : 0)
	    + (resultado.Filmes ? resultado.Filmes.length : 0)
	    + (resultado.Biografias ? resultado.Biografias.length : 0)
	    + (resultado.Videos ? resultado.Videos.length : 0)
	    + (resultado.Livros ? resultado.Livros.length : 0);

	if (total == 1)
	{
	    if ((resultado.Noticias ? resultado.Noticias.length : 0)==1)
	    {
	        var DataItem = resultado.Noticias[0];
	        location.href = '../../' + DataItem.Canal +'/Noticia/' + FormataNome(DataItem.Titulo) + '.aspx?ID=' + DataItem.ID;
	        return;
	    }
	    if ((resultado.Eventos ? resultado.Eventos.length : 0)==1)
	    {
	        var DataItem = resultado.Eventos[0];
	        location.href = '../../' + DataItem.Canal +'/Evento/' + FormataNome(DataItem.Titulo) + '.aspx?ID=' + DataItem.ID;
	        return;
	    }
	    if ((resultado.Estabelecimentos ? resultado.Estabelecimentos.length : 0)==1)
	    {
	        var DataItem = resultado.Estabelecimentos[0];
	        location.href = '../../' + DataItem.Canal +'/Estabelecimento/' + FormataNome(DataItem.Nome) + '.aspx?ID=' + DataItem.ID;
	        return;
	    }
	    if ((resultado.Filmes ? resultado.Filmes.length : 0)==1)
	    {
	        var DataItem = resultado.Filmes[0];
	        location.href = '../../Cinema/Filme/' + FormataNome(DataItem.Titulo) + '.aspx?ID=' + DataItem.ID;
	        return;
	    }
	    if ((resultado.Biografias ? resultado.Biografias.length : 0)==1)
	    {
	        var DataItem = resultado.Biografias[0];
	        location.href = '../Biografia/' + FormataNome(DataItem.Nome) + '.aspx?ID=' + DataItem.ID;
	        return;
	    }
	    if ((resultado.Videos ? resultado.Videos.length : 0)==1)
	    {
	        var DataItem = resultado.Videos[0];
	        ExibeVideo(DataItem.URL);
	        return;
	    }
	    if ((resultado.Livros ? resultado.Livros.length : 0)==1)
	    {
	        var DataItem = resultado.Livros[0];
	        location.href = '../../Artes_e_Teatro/Livro/' + FormataNome(DataItem.Titulo) + '.aspx?ID=' + DataItem.ID;
	        return;
	    }
	}
	MudaExibicao( TipoExibicao.BuscaTexto );
	EscondeMensagem();
	BindRepeaterAsync( rbtNoticias, resultado.Noticias );
	BindRepeaterAsync( rbtEventos, resultado.Eventos );
	BindRepeaterAsync( rbtEstabelecimentos, resultado.Estabelecimentos );
	BindRepeaterAsync( rbtFilmes, resultado.Filmes );
	BindRepeaterAsync( rbtBiografias, resultado.Biografias );
	BindRepeaterAsync( rbtVideos, resultado.Videos );
	BindRepeaterAsync( rbtLivros, resultado.Livros );
	AtualizaBanners();
}

function EndBuscaTextoExterno( resultado )
{
	var total = (resultado.Noticias ? resultado.Noticias.length : 0)
	    + (resultado.Eventos ? resultado.Eventos.length : 0)
	    + (resultado.Estabelecimentos ? resultado.Estabelecimentos.length : 0)
	    + (resultado.Filmes ? resultado.Filmes.length : 0)
	    + (resultado.Biografias ? resultado.Biografias.length : 0)
	    + (resultado.Videos ? resultado.Videos.length : 0)
	    + (resultado.Livros ? resultado.Livros.length : 0);

	MudaExibicao( TipoExibicao.BuscaTexto );
	EscondeMensagem();
	BindRepeaterAsync( rbtNoticias, resultado.Noticias );
	BindRepeaterAsync( rbtEventos, resultado.Eventos );
	BindRepeaterAsync( rbtEstabelecimentos, resultado.Estabelecimentos );
	BindRepeaterAsync( rbtFilmes, resultado.Filmes );
	BindRepeaterAsync( rbtBiografias, resultado.Biografias );
	BindRepeaterAsync( rbtVideos, resultado.Videos );
	BindRepeaterAsync( rbtLivros, resultado.Livros );
	AtualizaBanners();
}

function BindRepeaterAsync( rpt, collection )
{
	if( collection && collection.length )
		rpt.Bind( collection, 10, AjaxRepeater.BindMethod.Async );
	else
		rpt.ClearContent();
}



function RetornaFiltros(collection, indice)
{
	if( (!collection || collection.length == 0) || (indice > 0 && collection[indice].SearchPoints == collection[indice-1].SearchPoints) )
		return '';
		 
	var dropFiltro1 = GetListControl('ctl01_dropFiltro1');
	var dropFiltro2 = GetListControl('ctl01_dropFiltro2');
	var dropFiltro3 = GetListControl('ctl01_dropFiltro3');
	
	var f1 = dropFiltro1.SelectedText();
	var f2 = dropFiltro2.SelectedText();
	var f3 = dropFiltro3.SelectedText();
	var divisor = indice > 0 ?'<hr />':'';
	var item = collection[indice];
	if( dropFiltro1.selectedIndex > 0 ) 
	{
		if( item.SearchPoints == 3 )
			return divisor + String.Format( '<font face="verdana" size="-1" color="#000000">Resultados para <b><i>{0} </i> + <i>{1} </i> + <i>{2} </i></b><br/>&nbsp;</font>', f1, f2, f3 );
		if( item.SearchPoints == 2 )
			return divisor + String.Format( '<font face="verdana" size="-1" color="#000000">Resultados para <b><i>{0} </i> + <i>{1} </i></b><br/>&nbsp;</font>', f1, f2 );
		if( item.SearchPoints == 1 )
			return divisor + String.Format( '<font face="verdana" size="-1" color="#000000">Resultados para <b><i>{0} </i> + <i>{1} </i></b><br/>&nbsp;</font>', f1, f3 );
		if( item.IdCinema != null )
		    return divisor + String.Format( '<font face="verdana" size="-1" color="#000000">Resultados para <b><i>{0} </i></b><br/>&nbsp;</font>', f1 );
		return divisor + String.Format( '<font face="verdana" size="-1" color="#000000">Não foram encontrados resultados para <b><i>{0} </i></b><br/>&nbsp;</font>', FormataFiltros(f1) );		
	}
	else
	{
		if( item.SearchPoints == 1 )
			return divisor + String.Format( '<font face="verdana" size="-1" color="#000000">Resultados para <b><i>{0} </i> + <i>{1} </i></b><br/>&nbsp;</font>', f2, f3 );
		return divisor + String.Format( '<font face="verdana" size="-1" color="#000000">Resultados para <b><i>{0}</i></b><br/>&nbsp;</font>', FormataFiltros(f2) );
	}
}
function FormataFiltros(str)
{
    var ret = str.RTrim();
    if (ret.charAt(ret.length-1) == ',') ret = ret.substr(0,ret.length-1);
    return ret.Replace(", "," + ");
}

function RetornaErroFiltro(rt)
{
	var dropFiltro1 = GetListControl('ctl01_dropFiltro1');
	var dropFiltro2 = GetListControl('ctl01_dropFiltro2');
	var dropFiltro3 = GetListControl('ctl01_dropFiltro3');

	//if( dropFiltro1 && dropFiltro2 && dropFiltro3 )
	//	return 'Não foram encontrados resultados para o filtro atual.';

	var selectedSearch = ((parseInt(dropFiltro1.value)||0)&&1&&!dropFiltro1.disabled) + ((parseInt(dropFiltro2.value)||0)&&1&&!dropFiltro2.disabled) + ((parseInt(dropFiltro3.value)||0)&&1&&!dropFiltro3.disabled);
    var searchPoints = 0;
    if (rt && rt.length)
    {
        searchPoints = rt[0].SearchPoints;
	    if(!searchPoints)
	    {
		    searchPoints = 0;
		    for(var i=0; rt[0].PropriedadesFiltro&&i<rt[0].PropriedadesFiltro.length; i++)
			    if( rt[0].PropriedadesFiltro.charAt(i) == ',' )
				    searchPoints++;
	    }
	}
	var f1,f2,f3;
	if (!dropFiltro1.disabled && dropFiltro1.selectedIndex) f1 = dropFiltro1.SelectedText();
	if (!dropFiltro2.disabled && dropFiltro2.selectedIndex) f2 = dropFiltro2.SelectedText();
	if (!dropFiltro3.disabled && dropFiltro3.selectedIndex) f3 = dropFiltro3.SelectedText();
	
	if (f1 == null) { f1 = f2; f2 = f3; }
	if (f2 == null) { f2 = f3; }

	if( selectedSearch == 3 && selectedSearch != searchPoints )
		return String.Format( 'Não foram encontrados resultados para <b><i>{0}</i> + <i>{1}</i> + <i>{2}</i></b>&nbsp;<hr />', f1,f2,f3);

	if( selectedSearch == 2 && selectedSearch != searchPoints )
		return String.Format( 'Não foram encontrados resultados para <b><i>{0}</i> + <i>{1}</i></b>&nbsp;<hr />', f1, f2 );
	
	if( selectedSearch == 1 && selectedSearch != searchPoints )
		return String.Format( 'Não foram encontrados resultados para <b><i>{0}</i></b>&nbsp;<hr />', f1 );
	
	if(rt[0].Entidade == 'EVENTO')
	{
		var result = null;
		
		if( parseInt(dropFiltro1.value) )
			result = dropFiltro1.SelectedText();
		else if( parseInt(dropFiltro2.value) )
			result = dropFiltro2.SelectedText();
		else if(parseInt(dropFiltro3.value))
			result = dropFiltro3.SelectedText();
			
	    return String.Format( 'Resultados para <b><i>{0}</i></b>&nbsp;<hr />', result );
	}
	return '';
}


/*NOSTUB*/function __LazyLoadFunction( functionName )
{
	//var url = 'http://'+window.location.host+'{0}/AjaxMethod/LazyLoadFunction.ashx?functionName=' + functionName;
	var url = 'http://localhost/tesla.guiadasemana.web/AjaxMethod/LazyLoadFunction2.ashx?c=5&functionName=' + functionName;
	var xhr = null;
	if(window.XMLHttpRequest)
		xhr = new XMLHttpRequest();
	else if(window.ActiveXObject)
		xhr = new ActiveXObject('Microsoft.XMLHTTP');

	if(!xhr)
	{
		if( !window.__LazyLoadFunctionError )
		{
			alert('Ocorreu um erro inesperado.');
			window.__LazyLoadFunctionError = 1;
		}
		return;
	}

	xhr.open( 'GET', url, false )
	xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8');
	xhr.setRequestHeader('charset', 'utf-8');
	xhr.send(null);

	var rt = {};
	rt.A = xhr.responseText.split('##');
	rt.P  = rt.A[0];
	rt.A[0] = '';
	rt.F = rt.A.join('##').substring( 2, rt.length );
	rt.A = null;
	return rt;
	//return eval( '(' + xhr.responseText + ')' );
}
App.BuscaEstabServicoPorTipo = function(tipo, propObrigatoria, propOpcional, usarPropDefault)
{
	App.UsarPropriedadePadraoBusca = usarPropDefault;
	ExibeMensagem('<b>Realizando a busca</b>', 'Por favor aguarde...', true, '../../../images/carrega_busca.gif');
	DesabilitaTela();
	fnBuscaEstabelecimentosPorTipo(Cidade.CidadeAtual(), Canal.Servicos, tipo, propOpcional, propObrigatoria, TerminaPesquisaPorTipo);
}
App.BuscaPorTipo = function(tipoEntidade, tipo, propObrigatoria, propOpcional, usarPropDefault)
{
	App.UsarPropriedadePadraoBusca = usarPropDefault;
	ExibeMensagem('<b>Realizando a busca</b>', 'Por favor aguarde...', true, '../../../images/carrega_busca.gif');
	DesabilitaTela();
	if( tipoEntidade == 'P' )
		fnBuscaEstabelecimentosPorTipo(Cidade.CidadeAtual(), Canal.CanalAtual(), tipo, propOpcional, propObrigatoria, TerminaPesquisaPorTipo);
	else
		fnBuscaEventosPorTipo(Cidade.CidadeAtual(), Canal.CanalAtual(), tipo, propOpcional, propObrigatoria, TerminaPesquisaPorTipo);
}
App.BuscaPorPropriedade = function(p1, p2, p3, usarPropDefault)
{
	App.UsarPropriedadePadraoBusca = usarPropDefault;
	ExibeMensagem('<b>Realizando a busca</b>', 'Por favor aguarde...', true, '../../../images/carrega_busca.gif');
	DesabilitaTela();
	fnBuscaFiltros(Cidade.CidadeAtual(), Canal.CanalAtual(), p1, p2, p3, TerminaPesquisaFiltro);
}
App.BuscaPorTipos = function(tipos, p1, p2, usarPropDefault)
{
	App.UsarPropriedadePadraoBusca = usarPropDefault;
	ExibeMensagem('<b>Realizando a busca</b>', 'Por favor aguarde...', true, '../../../images/carrega_busca.gif');
	DesabilitaTela();
	fnBuscaEstabelecimentosPorVariosTipos(Cidade.CidadeAtual(), Canal.CanalAtual(), tipos, p1, p2, TerminaPesquisaPorTipo)
}
App.RetornaDescricaoTipo = function( item )
{
	return (App.UsarPropriedadePadraoBusca&&item.PropriedadePadrao) ? item.PropriedadePadrao : item.Tipo;
}
function RetornaTextoResultado(dataItem)
{
    if (!dataItem || !dataItem.PropriedadesFiltro)
        return '';
    var ret = dataItem.PropriedadesFiltro.RTrim();
    if (ret.charAt(ret.length-1) == ',') ret = ret.substr(0,ret.length-1);
    ret.Replace(", "," + ");
    return ret.toUpperCase();
}
//setTimeout('document.body.style.display = \'\';',300);
//setTimeout('document.getElementById(\'aspnetForm\').style.display = \'\';',300);
//setTimeout('document.getElementById(\'divBranca\').style.display = \'none\';',100);


function ShowEsqueciMinhaSenha()
{
    document.getElementById('TrLogin').style.display = 'none';
    document.getElementById('TrEsqueciMinhaSenha').style.display = '';
}

function EsqueciMinhaSenha()
{
    var email = document.getElementById('txtRecuperaSenha').value;
    
    document.getElementById('TrLogin').style.display = '';
    document.getElementById('TrEsqueciMinhaSenha').style.display = 'none';
    document.getElementById('txtRecuperaSenha').value = '';
    EscondeLogin();
    if(fnRecuperaSenha(email))
    {
        alert('Sua senha foi enviada para sua caixa de email!');
    }
    else
    {
        alert('Ocorreu um erro, verifique se digitou o email corretamente!');
        ShowEsqueciMinhaSenha();
        FuncionalidadesRestritas.MostrarMeuGuia();
    }
}

function SetBackGroundAgenda(imagePosition,dayPosition)
{
    if(imagePosition == 0)
    {
        if(document.getElementById("ctl00_BoxAgenda1_td1").style.backgroundImage != 'url(../../../images/bg_ac.gif)')
            document.getElementById("ctl00_BoxAgenda1_td1").style.backgroundImage='url(../../../images/bg_ac.gif)';
        if(document.getElementById("ctl00_BoxAgenda1_td2").style.backgroundImage != 'url(../../../images/bg_ap.gif)')
            document.getElementById("ctl00_BoxAgenda1_td2").style.backgroundImage= 'url(../../../images/bg_ap.gif)';
        if(document.getElementById("ctl00_BoxAgenda1_td3").style.backgroundImage != 'url(../../../images/bg_ap.gif)')
            document.getElementById("ctl00_BoxAgenda1_td3").style.backgroundImage= 'url(../../../images/bg_ap.gif)';
        if(document.getElementById("ctl00_BoxAgenda1_td4").style.backgroundImage != 'url(../../../images/bg_ap.gif)')
            document.getElementById("ctl00_BoxAgenda1_td4").style.backgroundImage= 'url(../../../images/bg_ap.gif)';
        if(document.getElementById("ctl00_BoxAgenda1_td5").style.backgroundImage != 'url(../../../images/bg_ap.gif)')
            document.getElementById("ctl00_BoxAgenda1_td5").style.backgroundImage= 'url(../../../images/bg_ap.gif)';
        if(document.getElementById("ctl00_BoxAgenda1_td6").style.backgroundImage != 'url(../../../images/bg_ap.gif)')
            document.getElementById("ctl00_BoxAgenda1_td6").style.backgroundImage= 'url(../../../images/bg_ap.gif)';
        if(document.getElementById("ctl00_BoxAgenda1_td7").style.backgroundImage != 'url(../../../images/bg_ap.gif)')
            document.getElementById("ctl00_BoxAgenda1_td7").style.backgroundImage= 'url(../../../images/bg_ap.gif)';
        
        document.getElementById("ctl00_BoxAgenda1_font1").color= '#ffffff';
        document.getElementById("ctl00_BoxAgenda1_font2").color= '#616161';
        document.getElementById("ctl00_BoxAgenda1_font3").color= '#616161';
        document.getElementById("ctl00_BoxAgenda1_font4").color= '#616161';
        document.getElementById("ctl00_BoxAgenda1_font5").color= '#616161';
        document.getElementById("ctl00_BoxAgenda1_font6").color= '#616161';
        document.getElementById("ctl00_BoxAgenda1_font7").color= '#616161';
        
    }else
    if(imagePosition == 1)
    {
        if(document.getElementById("ctl00_BoxAgenda1_td1").style.backgroundImage != "url(../../../images/bg_ap.gif)")
            document.getElementById("ctl00_BoxAgenda1_td1").style.backgroundImage="url(../../../images/bg_ap.gif)";
        if(document.getElementById("ctl00_BoxAgenda1_td2").style.backgroundImage != "url(../../../images/bg_ac.gif)")
            document.getElementById("ctl00_BoxAgenda1_td2").style.backgroundImage= "url(../../../images/bg_ac.gif)";
        if(document.getElementById("ctl00_BoxAgenda1_td3").style.backgroundImage != "url(../../../images/bg_ap.gif)")
            document.getElementById("ctl00_BoxAgenda1_td3").style.backgroundImage= "url(../../../images/bg_ap.gif)";
        if(document.getElementById("ctl00_BoxAgenda1_td4").style.backgroundImage != "url(../../../images/bg_ap.gif)")
            document.getElementById("ctl00_BoxAgenda1_td4").style.backgroundImage= "url(../../../images/bg_ap.gif)";
        if(document.getElementById("ctl00_BoxAgenda1_td5").style.backgroundImage != "url(../../../images/bg_ap.gif)")
            document.getElementById("ctl00_BoxAgenda1_td5").style.backgroundImage= "url(../../../images/bg_ap.gif)";
        if(document.getElementById("ctl00_BoxAgenda1_td6").style.backgroundImage != "url(../../../images/bg_ap.gif)")
            document.getElementById("ctl00_BoxAgenda1_td6").style.backgroundImage= "url(../../../images/bg_ap.gif)";
        if(document.getElementById("ctl00_BoxAgenda1_td7").style.backgroundImage != "url(../../../images/bg_ap.gif)")
            document.getElementById("ctl00_BoxAgenda1_td7").style.backgroundImage= "url(../../../images/bg_ap.gif)";
        
        document.getElementById("ctl00_BoxAgenda1_font1").color= '#616161';
        document.getElementById("ctl00_BoxAgenda1_font2").color= '#ffffff';
        document.getElementById("ctl00_BoxAgenda1_font3").color= '#616161';
        document.getElementById("ctl00_BoxAgenda1_font4").color= '#616161';
        document.getElementById("ctl00_BoxAgenda1_font5").color= '#616161';
        document.getElementById("ctl00_BoxAgenda1_font6").color= '#616161';
        document.getElementById("ctl00_BoxAgenda1_font7").color= '#616161';
    }else
    if(imagePosition == 2)
    {
        if(document.getElementById("ctl00_BoxAgenda1_td1").style.backgroundImage != 'url(../../../images/bg_ap.gif)')
            document.getElementById("ctl00_BoxAgenda1_td1").style.backgroundImage='url(../../../images/bg_ap.gif)';
        if(document.getElementById("ctl00_BoxAgenda1_td2").style.backgroundImage != 'url(../../../images/bg_ap.gif)')
            document.getElementById("ctl00_BoxAgenda1_td2").style.backgroundImage= 'url(../../../images/bg_ap.gif)';
        if(document.getElementById("ctl00_BoxAgenda1_td3").style.backgroundImage != 'url(../../../images/bg_ac.gif)')
            document.getElementById("ctl00_BoxAgenda1_td3").style.backgroundImage= 'url(../../../images/bg_ac.gif)';
        if(document.getElementById("ctl00_BoxAgenda1_td4").style.backgroundImage != 'url(../../../images/bg_ap.gif)')
            document.getElementById("ctl00_BoxAgenda1_td4").style.backgroundImage= 'url(../../../images/bg_ap.gif)';
        if(document.getElementById("ctl00_BoxAgenda1_td5").style.backgroundImage != 'url(../../../images/bg_ap.gif)')
            document.getElementById("ctl00_BoxAgenda1_td5").style.backgroundImage= 'url(../../../images/bg_ap.gif)';
        if(document.getElementById("ctl00_BoxAgenda1_td6").style.backgroundImage != 'url(../../../images/bg_ap.gif)')
            document.getElementById("ctl00_BoxAgenda1_td6").style.backgroundImage= 'url(../../../images/bg_ap.gif)';
        if(document.getElementById("ctl00_BoxAgenda1_td7").style.backgroundImage != 'url(../../../images/bg_ap.gif)')
            document.getElementById("ctl00_BoxAgenda1_td7").style.backgroundImage= 'url(../../../images/bg_ap.gif)';
        
        document.getElementById("ctl00_BoxAgenda1_font1").color= '#616161';
        document.getElementById("ctl00_BoxAgenda1_font2").color= '#616161';
        document.getElementById("ctl00_BoxAgenda1_font3").color= '#ffffff';
        document.getElementById("ctl00_BoxAgenda1_font4").color= '#616161';
        document.getElementById("ctl00_BoxAgenda1_font5").color= '#616161';
        document.getElementById("ctl00_BoxAgenda1_font6").color= '#616161';
        document.getElementById("ctl00_BoxAgenda1_font7").color= '#616161';
    }else
    if(imagePosition == 3)
    {
        if(document.getElementById("ctl00_BoxAgenda1_td1").style.backgroundImage != 'url(../../../images/bg_ap.gif)')
            document.getElementById("ctl00_BoxAgenda1_td1").style.backgroundImage='url(../../../images/bg_ap.gif)';
        if(document.getElementById("ctl00_BoxAgenda1_td2").style.backgroundImage != 'url(../../../images/bg_ap.gif)')
            document.getElementById("ctl00_BoxAgenda1_td2").style.backgroundImage= 'url(../../../images/bg_ap.gif)';
        if(document.getElementById("ctl00_BoxAgenda1_td3").style.backgroundImage != 'url(../../../images/bg_ap.gif)')
            document.getElementById("ctl00_BoxAgenda1_td3").style.backgroundImage= 'url(../../../images/bg_ap.gif)';
        if(document.getElementById("ctl00_BoxAgenda1_td4").style.backgroundImage != 'url(../../../images/bg_ac.gif)')
            document.getElementById("ctl00_BoxAgenda1_td4").style.backgroundImage= 'url(../../../images/bg_ac.gif)';
        if(document.getElementById("ctl00_BoxAgenda1_td5").style.backgroundImage != 'url(../../../images/bg_ap.gif)')
            document.getElementById("ctl00_BoxAgenda1_td5").style.backgroundImage= 'url(../../../images/bg_ap.gif)';
        if(document.getElementById("ctl00_BoxAgenda1_td6").style.backgroundImage != 'url(../../../images/bg_ap.gif)')
            document.getElementById("ctl00_BoxAgenda1_td6").style.backgroundImage= 'url(../../../images/bg_ap.gif)';
        if(document.getElementById("ctl00_BoxAgenda1_td7").style.backgroundImage != 'url(../../../images/bg_ap.gif)')
            document.getElementById("ctl00_BoxAgenda1_td7").style.backgroundImage= 'url(../../../images/bg_ap.gif)';
        
        document.getElementById("ctl00_BoxAgenda1_font1").color= '#616161';
        document.getElementById("ctl00_BoxAgenda1_font2").color= '#616161';
        document.getElementById("ctl00_BoxAgenda1_font3").color= '#616161';
        document.getElementById("ctl00_BoxAgenda1_font4").color= '#ffffff';
        document.getElementById("ctl00_BoxAgenda1_font5").color= '#616161';
        document.getElementById("ctl00_BoxAgenda1_font6").color= '#616161';
        document.getElementById("ctl00_BoxAgenda1_font7").color= '#616161';
    }else
    if(imagePosition == 4)
    {
        if(document.getElementById("ctl00_BoxAgenda1_td1").style.backgroundImage != 'url(../../../images/bg_ap.gif)')
            document.getElementById("ctl00_BoxAgenda1_td1").style.backgroundImage='url(../../../images/bg_ap.gif)';
        if(document.getElementById("ctl00_BoxAgenda1_td2").style.backgroundImage != 'url(../../../images/bg_ap.gif)')
            document.getElementById("ctl00_BoxAgenda1_td2").style.backgroundImage= 'url(../../../images/bg_ap.gif)';
        if(document.getElementById("ctl00_BoxAgenda1_td3").style.backgroundImage != 'url(../../../images/bg_ap.gif)')
            document.getElementById("ctl00_BoxAgenda1_td3").style.backgroundImage= 'url(../../../images/bg_ap.gif)';
        if(document.getElementById("ctl00_BoxAgenda1_td4").style.backgroundImage != 'url(../../../images/bg_ap.gif)')
            document.getElementById("ctl00_BoxAgenda1_td4").style.backgroundImage= 'url(../../../images/bg_ap.gif)';
        if(document.getElementById("ctl00_BoxAgenda1_td5").style.backgroundImage != 'url(../../../images/bg_ac.gif)')
            document.getElementById("ctl00_BoxAgenda1_td5").style.backgroundImage= 'url(../../../images/bg_ac.gif)';
        if(document.getElementById("ctl00_BoxAgenda1_td6").style.backgroundImage != 'url(../../../images/bg_ap.gif)')
            document.getElementById("ctl00_BoxAgenda1_td6").style.backgroundImage= 'url(../../../images/bg_ap.gif)';
        if(document.getElementById("ctl00_BoxAgenda1_td7").style.backgroundImage != 'url(../../../images/bg_ap.gif)')
            document.getElementById("ctl00_BoxAgenda1_td7").style.backgroundImage= 'url(../../../images/bg_ap.gif)';
        
        document.getElementById("ctl00_BoxAgenda1_font1").color= '#616161';
        document.getElementById("ctl00_BoxAgenda1_font2").color= '#616161';
        document.getElementById("ctl00_BoxAgenda1_font3").color= '#616161';
        document.getElementById("ctl00_BoxAgenda1_font4").color= '#616161';
        document.getElementById("ctl00_BoxAgenda1_font5").color= '#ffffff';
        document.getElementById("ctl00_BoxAgenda1_font6").color= '#616161';
        document.getElementById("ctl00_BoxAgenda1_font7").color= '#616161';
    }else
    if(imagePosition == 5)
    {
        if(document.getElementById("ctl00_BoxAgenda1_td1").style.backgroundImage != 'url(../../../images/bg_ap.gif)')
            document.getElementById("ctl00_BoxAgenda1_td1").style.backgroundImage='url(../../../images/bg_ap.gif)';
        if(document.getElementById("ctl00_BoxAgenda1_td2").style.backgroundImage != 'url(../../../images/bg_ap.gif)')
            document.getElementById("ctl00_BoxAgenda1_td2").style.backgroundImage= 'url(../../../images/bg_ap.gif)';
        if(document.getElementById("ctl00_BoxAgenda1_td3").style.backgroundImage != 'url(../../../images/bg_ap.gif)')
            document.getElementById("ctl00_BoxAgenda1_td3").style.backgroundImage= 'url(../../../images/bg_ap.gif)';
        if(document.getElementById("ctl00_BoxAgenda1_td4").style.backgroundImage != 'url(../../../images/bg_ap.gif)')
            document.getElementById("ctl00_BoxAgenda1_td4").style.backgroundImage= 'url(../../../images/bg_ap.gif)';
        if(document.getElementById("ctl00_BoxAgenda1_td5").style.backgroundImage != 'url(../../../images/bg_ap.gif)')
            document.getElementById("ctl00_BoxAgenda1_td5").style.backgroundImage= 'url(../../../images/bg_ap.gif)';
        if(document.getElementById("ctl00_BoxAgenda1_td6").style.backgroundImage != 'url(../../../images/bg_ac.gif)')
            document.getElementById("ctl00_BoxAgenda1_td6").style.backgroundImage= 'url(../../../images/bg_ac.gif)';
        if(document.getElementById("ctl00_BoxAgenda1_td7").style.backgroundImage != 'url(../../../images/bg_ap.gif)')
            document.getElementById("ctl00_BoxAgenda1_td7").style.backgroundImage= 'url(../../../images/bg_ap.gif)';
        
        document.getElementById("ctl00_BoxAgenda1_font1").color= '#616161';
        document.getElementById("ctl00_BoxAgenda1_font2").color= '#616161';
        document.getElementById("ctl00_BoxAgenda1_font3").color= '#616161';
        document.getElementById("ctl00_BoxAgenda1_font4").color= '#616161';
        document.getElementById("ctl00_BoxAgenda1_font5").color= '#616161';
        document.getElementById("ctl00_BoxAgenda1_font6").color= '#ffffff';
        document.getElementById("ctl00_BoxAgenda1_font7").color= '#616161';
    }else
    if(imagePosition == 6)
    {
        if(document.getElementById("ctl00_BoxAgenda1_td1").style.backgroundImage != 'url(../../../images/bg_ap.gif)')
            document.getElementById("ctl00_BoxAgenda1_td1").style.backgroundImage='url(../../../images/bg_ap.gif)';
        if(document.getElementById("ctl00_BoxAgenda1_td2").style.backgroundImage != 'url(../../../images/bg_ap.gif)')
            document.getElementById("ctl00_BoxAgenda1_td2").style.backgroundImage= 'url(../../../images/bg_ap.gif)';
        if(document.getElementById("ctl00_BoxAgenda1_td3").style.backgroundImage != 'url(../../../images/bg_ap.gif)')
            document.getElementById("ctl00_BoxAgenda1_td3").style.backgroundImage= 'url(../../../images/bg_ap.gif)';
        if(document.getElementById("ctl00_BoxAgenda1_td4").style.backgroundImage != 'url(../../../images/bg_ap.gif)')
            document.getElementById("ctl00_BoxAgenda1_td4").style.backgroundImage= 'url(../../../images/bg_ap.gif)';
        if(document.getElementById("ctl00_BoxAgenda1_td5").style.backgroundImage != 'url(../../../images/bg_ap.gif)')
            document.getElementById("ctl00_BoxAgenda1_td5").style.backgroundImage= 'url(../../../images/bg_ap.gif)';
        if(document.getElementById("ctl00_BoxAgenda1_td6").style.backgroundImage != 'url(../../../images/bg_ap.gif)')
            document.getElementById("ctl00_BoxAgenda1_td6").style.backgroundImage= 'url(../../../images/bg_ap.gif)';
        if(document.getElementById("ctl00_BoxAgenda1_td7").style.backgroundImage != 'url(../../../images/bg_ac.gif)')
            document.getElementById("ctl00_BoxAgenda1_td7").style.backgroundImage= 'url(../../../images/bg_ac.gif)';
            
        document.getElementById("ctl00_BoxAgenda1_font1").color= '#616161';
        document.getElementById("ctl00_BoxAgenda1_font2").color= '#616161';
        document.getElementById("ctl00_BoxAgenda1_font3").color= '#616161';
        document.getElementById("ctl00_BoxAgenda1_font4").color= '#616161';
        document.getElementById("ctl00_BoxAgenda1_font5").color= '#616161';
        document.getElementById("ctl00_BoxAgenda1_font6").color= '#616161';
        document.getElementById("ctl00_BoxAgenda1_font7").color= '#ffffff';
    }
    ResultAgenda(dayPosition);
}

function ResultAgenda(day)
{
    var divAgenda = document.getElementById('ctl00_BoxAgenda1_divAgenda');
    divAgenda.innerHTML = fnListaAgenda(day, Cidade.CidadeAtual(), Canal.CanalAtual() );
    AtualizaBanners();
}

function SwitchDivPromotion(idpromotionActive, idpromotionDesactive, idpromotionDesactive1, idpromotionDesactive2, positionActive)
{
    document.getElementById('DivPromo'+idpromotionActive).style.display = '';
    document.getElementById('DivPromo'+idpromotionDesactive).style.display = 'none';
    document.getElementById('DivPromo'+idpromotionDesactive1).style.display = 'none';
    document.getElementById('DivPromo'+idpromotionDesactive2).style.display = 'none';
    if(positionActive==1)
    {
        document.getElementById('ctl00_Body_ctl00_lblPromotion').innerHTML = '<a href="javascript:SwitchDivPromotion('+idpromotionActive+','+ idpromotionDesactive+','+ idpromotionDesactive1+','+ idpromotionDesactive2+',1);" class="agenda"><b>'+'1'+'</b></a> | '+
                                                                             '<a href="javascript:SwitchDivPromotion('+idpromotionDesactive+','+ idpromotionActive+','+ idpromotionDesactive1+','+ idpromotionDesactive2+',2);" class="agenda">'+'2'+'</a> | '+
                                                                             '<a href="javascript:SwitchDivPromotion('+idpromotionDesactive1+','+ idpromotionActive+','+ idpromotionDesactive+','+ idpromotionDesactive2+',3);" class="agenda">'+'3'+'</a> | '+
                                                                             '<a href="javascript:SwitchDivPromotion('+idpromotionDesactive2+','+ idpromotionActive+','+ idpromotionDesactive+','+ idpromotionDesactive1+',4);" class="agenda">'+'4'+'</a>';
            AtualizaBanners();                                                                             
    }
    else
        if(positionActive==2)
        {
            document.getElementById('ctl00_Body_ctl00_lblPromotion').innerHTML = '<a href="javascript:SwitchDivPromotion('+idpromotionDesactive+','+ idpromotionActive+','+ idpromotionDesactive1+','+ idpromotionDesactive2+',1);" class="agenda">'+'1'+'</a> | '+
                                                                                 '<a href="javascript:SwitchDivPromotion('+idpromotionActive+','+ idpromotionDesactive+','+ idpromotionDesactive1+','+ idpromotionDesactive2+',2);" class="agenda"><b>'+'2'+'</b></a> | '+
                                                                                 '<a href="javascript:SwitchDivPromotion('+idpromotionDesactive1+','+ idpromotionDesactive+','+ idpromotionActive+','+ idpromotionDesactive2+',3);" class="agenda">'+'3'+'</a> | '+
                                                                                 '<a href="javascript:SwitchDivPromotion('+idpromotionDesactive2+','+ idpromotionDesactive+','+ idpromotionActive+','+ idpromotionDesactive1+',4);" class="agenda">'+'4'+'</a>';
            AtualizaBanners();                                                                                 
        }
        else
        if(positionActive==3)
        {
            document.getElementById('ctl00_Body_ctl00_lblPromotion').innerHTML = '<a href="javascript:SwitchDivPromotion('+idpromotionDesactive+','+ idpromotionDesactive1+','+ idpromotionActive+','+ idpromotionDesactive2+',1);" class="agenda">'+'1'+'</a> | '+
                                                                                 '<a href="javascript:SwitchDivPromotion('+idpromotionDesactive1+','+ idpromotionDesactive+','+ idpromotionActive+','+ idpromotionDesactive2+',2);" class="agenda">'+'2'+'</a> | '+
                                                                                 '<a href="javascript:SwitchDivPromotion('+idpromotionActive+','+ idpromotionDesactive+','+ idpromotionDesactive1+','+ idpromotionDesactive2+',3);" class="agenda"><b>'+'3'+'</b></a> | '+
                                                                                 '<a href="javascript:SwitchDivPromotion('+idpromotionDesactive2+','+ idpromotionDesactive+','+ idpromotionDesactive1+','+ idpromotionActive+',4);" class="agenda">'+'4'+'</a>';
            AtualizaBanners();                                                                                 
        }
        else
        if(positionActive==4)
        {
            document.getElementById('ctl00_Body_ctl00_lblPromotion').innerHTML = '<a href="javascript:SwitchDivPromotion('+idpromotionDesactive+','+ idpromotionDesactive1+','+ idpromotionDesactive2+','+ idpromotionActive+',1);" class="agenda">'+'1'+'</a> | '+
                                                                                 '<a href="javascript:SwitchDivPromotion('+idpromotionDesactive1+','+ idpromotionDesactive+','+ idpromotionDesactive2+','+ idpromotionActive+',2);" class="agenda">'+'2'+'</a> | '+
                                                                                 '<a href="javascript:SwitchDivPromotion('+idpromotionDesactive2+','+ idpromotionDesactive+','+ idpromotionDesactive1+','+ idpromotionActive+',3);" class="agenda">'+'3'+'</a> | '+
                                                                                 '<a href="javascript:SwitchDivPromotion('+idpromotionActive+','+ idpromotionDesactive+','+ idpromotionDesactive1+','+ idpromotionDesactive2+',4);" class="agenda"><b>'+'4'+'</b></a>';
            AtualizaBanners();
        }
    }



    //Trecho para trocar banners automaticamente
    setTimeout('InicioBanners()', 10 * 1000); //Espera 10s para começar a trocar automaticamente
    function InicioBanners() {
        setInterval('AtualizaBanners()', 90 * 1000); //Troca o banner de 90s em 90s
    }
    
 function SearchGOM()
{
    var drop1GOM = document.getElementById("ctl00_BoxMapas1_st_classificacao_imovel");
    var drop2GOM = document.getElementById("ctl00_BoxMapas1_nm_area_util_imovel");
    var drop3GOM = document.getElementById("ctl00_BoxMapas1_nm_quartos_imovel");
    var url='';
    url = 'http://www.guiaondemorar.com.br/search.asp?st_classificacao_imovel='+drop1GOM.options[drop1GOM.selectedIndex].value+'&nm_area_util_imovel='+drop2GOM.options[drop2GOM.selectedIndex].value+'&nm_quartos_imovel='+drop3GOM.options[drop3GOM.selectedIndex].value;
    window.open(url);
    AtualizaBanners();
}

function SearchBuscape()
{
    var urlBuscape='';
    urlBuscape = 'http://busca.buscape.com.br/cprocura/?pr=2450&produto='+document.getElementById('txtProdutoBuscapeGuia').value;
    window.open(urlBuscape);
}

var radioMailSelectedValue = 0;
var radioMailSelectedText = "Enviar sugestões ou críticas";

function SetaValorRadioButtonEmail(valorTipoEmail, textoTipoEmail)
{
    radioMailSelectedValue = valorTipoEmail;
    radioMailSelectedText = textoTipoEmail;
}
function EnviaEmail()
{
    var resultMensagem = fnEnviaEmail(radioMailSelectedValue, radioMailSelectedText, document.getElementById('ctl00_Body_ctl00_nome').value, document.getElementById('ctl00_Body_ctl00_email').value, document.getElementById('ctl00_Body_ctl00_empresa').value, document.getElementById('ctl00_Body_ctl00_cargo').value, document.getElementById('ctl00_Body_ctl00_url').value, document.getElementById('ctl00_Body_ctl00_tel1').value, document.getElementById('ctl00_Body_ctl00_tel2').value, document.getElementById('ctl00_Body_ctl00_assunto').value, document.getElementById('ctl00_Body_ctl00_descricao').value, Cidade.CidadeAtual() );
    AtualizaBanners();
    alert( resultMensagem );
    document.forms[0].reset();
}

function ResetLogin()
{
    document.getElementById('TrLogin').style.display = '';
    document.getElementById('TrEsqueciMinhaSenha').style.display = 'none';
}
function InsertForum(cdForum,stNome,stCidade,stOpiniao)
{
    fnInsereOpiniaoForum(cdForum, stNome, stCidade, stOpiniao );
    AtualizaBanners();
}

function GetUltimoComentario(recomendado)
{
    if(recomendado == 0)
    {
        var divUltCom = document.getElementById('ctl00_BoxUltimosComentarios_div_Ult_Coments')
        divUltCom.innerHTML = fnGetUltimosComentarios(Cidade.CidadeAtual(), Canal.CanalAtual() );
        document.getElementById('btnUltimosComentarios').src= '../../../images/bt_comentarios_ac.gif';
        document.getElementById('btnRecomendamos').src= '../../../images/bt_comentados_ap.gif';
        document.getElementById('divTitUltComent').innerHTML = "&Uacute;LTIMOS COMENT&Aacute;RIOS";
    }
    else
    {
        var divUltComRec = document.getElementById('ctl00_BoxUltimosComentarios_div_Ult_Coments')
        divUltComRec.innerHTML = fnGetUltimosComentariosRecomendados(Cidade.CidadeAtual(), Canal.CanalAtual() );
        document.getElementById('btnUltimosComentarios').src= '../../../images/bt_comentarios_ap.gif';
        document.getElementById('btnRecomendamos').src= '../../../images/bt_comentados_ac.gif';
        document.getElementById('divTitUltComent').innerHTML = "COMENT&Aacute;RIOS RECOMENDADOS";
    }
}

function PesquisaEventoPorData(data)
{
	if(data!=false)
	{
	    ExibeMensagem('<b>Realizando a busca</b>', 'Por favor aguarde...', true, '../../../images/carrega_busca.gif');
	    DesabilitaTela();
	    fnBuscaEventoByDate(Cidade.CidadeAtual(), Canal.CanalAtual(), data, TerminaPesquisaEventoData);
	    if(document.getElementById('txtDateSearch').value=='') document.getElementById('txtDateSearch').value = data.substr(8,2)+'/'+data.substr(5,2)+'/'+data.substr(0,4);
	}
}
function dateMask(inputData, e)
{
    if(document.all) // Internet Explorer
    var tecla = event.keyCode;
    else //Outros Browsers
    var tecla = e.which;

    if(tecla >= 47 && tecla < 58){ // numeros de 0 a 9 e "/"
    var data = inputData.value;
    if (data.length == 2 || data.length == 5){
    data += '/';
    inputData.value = data;
    }
    }else if(tecla == 8 || tecla == 0) // Backspace, Delete e setas direcionais(para mover o cursor, apenas para FF)
    return true;
    else
    return false;
}
function retornaDataConfigurada(dataDesconfigurada)
{
    if(!VerificaDataValidaGDS(dataDesconfigurada))
    {
        alert('Data em formato inválido.');
        document.getElementById('txtDateSearch').value='';
        document.getElementById('txtDateSearch').focus();
        return false;
    }
    else
    {
        return dataDesconfigurada.substr(6,4)+'-'+dataDesconfigurada.substr(3,2)+'-'+dataDesconfigurada.substr(0,2)
    }
}
function VerificaDataValidaGDS(digData) 
{
        var bissexto = 0;
        var data = digData; 
        var tam = data.length;
        if (tam == 10) 
        {
                var dia = data.substr(0,2)
                var mes = data.substr(3,2)
                var ano = data.substr(6,4)
                if ((ano > 1900)||(ano < 2100))
                {
                        switch (mes) 
                        {
                                case '01':
                                case '03':
                                case '05':
                                case '07':
                                case '08':
                                case '10':
                                case '12':
                                        if  (dia <= 31) 
                                        {
                                                return true;
                                        }
                                        break
                                
                                case '04':              
                                case '06':
                                case '09':
                                case '11':
                                        if  (dia <= 30) 
                                        {
                                                return true;
                                        }
                                        break
                                case '02':
                                        /* Validando ano Bissexto / fevereiro / dia */ 
                                        if ((ano % 4 == 0) || (ano % 100 == 0) || (ano % 400 == 0)) 
                                        { 
                                                bissexto = 1; 
                                        } 
                                        if ((bissexto == 1) && (dia <= 29)) 
                                        { 
                                                return true;                             
                                        } 
                                        if ((bissexto != 1) && (dia <= 28)) 
                                        { 
                                                return true; 
                                        }                       
                                        break                                           
                        }
                }
        }       
        return false;
}
function RetornaDataAtualGDS()
{
    var hoje=new Date();
    var dia=hoje.getDate();
    var mes=hoje.getMonth();
    var ano=hoje.getFullYear();
    if(dia<10) dia = '0'+dia;
    if(mes<10) mes = '0'+mes;
    return ano+'-'+mes+'-'+dia;
}
function retorna_clientWidth() {
    return f_filterResults (
        window.innerWidth ? window.innerWidth : 0,
        document.documentElement ? document.documentElement.clientWidth : 0,
        document.body ? document.body.clientWidth : 0
    );
}
function retorna_clientHeight() {
    return f_filterResults (
        window.innerHeight ? window.innerHeight : 0,
        document.documentElement ? document.documentElement.clientHeight : 0,
        document.body ? document.body.clientHeight : 0
    );
}
function f_filterResults(n_win, n_docel, n_body) {
    var n_result = n_win ? n_win : 0;
    if (n_docel && (!n_result || (n_result > n_docel)))
        n_result = n_docel;
    return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}