﻿// Trata o fim das requisições AJAX
function EndRequestHandler(sender, args) {
    //alert('pn - chegou aqui');
    // Se não deu nenhum erro
    if (args.get_error() == undefined) {
        // Página de Envie um email
        var objSucessoEmail = document.getElementById("hfSucessoEnvioEmailMensagem");
        if (objSucessoEmail != null && objSucessoEmail.value == "sucesso") {
            // ALTERAÇÃO AUNICA - TAGG
            //trackView('Contato - Contato por Email - Confirmado', 'event2', 'Contato');
            trackOmni('Contato - Contato por Email - Confirmado', 'event2');
            
            if (typeof window.parent.trackViewAnalytics != 'undefined') {
                if (tipoBotao != null && tipoBotao != "") {
                    window.parent.trackViewAnalytics("/conversoes/atendimento-por-email/formulario/" + tipoBotao + "/sucesso/" + nomeEmpreendimento);
                }                
            }

        }

        // Página de envie página para um amigo
        var objSucessoAmigo = document.getElementById("hfSucessoEnvioPaginaAmigo");

        if (objSucessoAmigo != null && objSucessoAmigo.value == "sucesso") {
            //alert("nome: " +  nomeEmpreendimento);

            if (nomeEmpreendimento.length > 0) {
                //alert("envio com emp");
                // ALTERAÇÃO AUNICA - TAGG
                //trackView('Imoveis - ' + nomeEmpreendimento + ' - Enviar para amigo - Enviado', 'event8', 'Imoveis');
            }
            else {
                //alert("envio se emp");
                // ALTERAÇÃO AUNICA - TAGG
                //trackView('Institucional - Indique este site - Confirmado', '', 'Institucional');
            }
        }

        // Página de envie página agende um contato
        var objSucessoAgende = document.getElementById("hfSucessoEnvioAgendeContato");
        if (objSucessoAgende != null && objSucessoAgende.value == "sucesso") {
            // ALTERAÇÃO AUNICA - TAGG
            //trackView('Contato - Agende seu Contato - Confirmado', 'event3', 'Contato');
            trackOmni('Contato - Agende seu Contato - Confirmado', 'event3');
        }

        // Página de envie página receba novidades
        var objSucessoNews = document.getElementById("hfSucessoRecebaNews");
        if (objSucessoNews != null && objSucessoNews.value == "sucesso") {
            //trackView('Institucional - Cadastre se - Confirmado', 'event4', 'Institucional');
            // ALTERAÇÃO AUNICA - TAGG
            trackOmni('Institucional - Cadastre se - Confirmado', 'event4');
            var paramAnalyticsEmpreendimento = (nomeEmpreendimento.length == 0) ? "" : nomeEmpreendimento;
            trackViewAnalytics("/receba-novidades/links/topo/formulario/sucesso/" + paramAnalyticsEmpreendimento);
        }

        // Página de produto - form de breves lançamentos
        var objSucessoBL = document.getElementById("hfSucessoBrevesLancamentos");
        if (objSucessoBL != null && objSucessoBL.value == "sucesso") {
            if (nomeEmpreendimento.length > 0) {
                // ALTERAÇÃO AUNICA - TAGG
                //trackView('Imoveis - ' + retira_acentos(nomeEmpreendimento) + ' - Breve Lancamento - Enviado', '', 'Imoveis');
                trackOmni('Imoveis - ' + retira_acentos(nomeEmpreendimento) + ' - Breve Lancamento - Enviado', '');
            }
        }

        var objFornecedorEnvioSucesso = document.getElementById("fornecedorEnvioSucesso");
        if (objFornecedorEnvioSucesso != null) {
            // ALTERAÇÃO AUNICA - TAGG
            //trackView('Institucional - Seja um fornecedor - Confirmado', 'event13', 'Institucional');
        }

        var objFrmEmailMapa = document.getElementById("frmEmailMapa");
        if (objFrmEmailMapa != null && objFrmEmailMapa.value == "emailmapa") {
            // ALTERAÇÃO AUNICA - TAGG
            //trackView('Imoveis - '+ retira_acentos(nomeEmpreendimento) +' - Enviar por Email - Formulario', '', 'Imoveis');
        }

        var objEnvioEmailMapaSucesso = document.getElementById("envioEmailMapaSucesso");
        if (objEnvioEmailMapaSucesso != null && objEnvioEmailMapaSucesso.value == "sucesso") {
            // ALTERAÇÃO AUNICA - TAGG
            //trackView('Imoveis - ' + retira_acentos(nomeEmpreendimento) + ' - Enviar por Email - Enviado', '', 'Imoveis');
            trackOmni('Imoveis - ' + retira_acentos(nomeEmpreendimento) + ' - Enviar por Email - Enviado', '');
        }

        var objFrmGeomaps = document.getElementById("frmGeomapsSucesso");
        if (objFrmGeomaps != null) {
            if (nomeEmpreendimento != null) {
                // ALTERAÇÃO AUNICA - TAGG
                //trackView('mapas - empreendimento - ' + retira_acentos(replace_All(nomeEmpreendimento, '%20', ' ')) + ' - enviarporemail - enviado', 'event2', 'geonavegacao');
            }
        }

        var objFrmGeomapsEnvieEmail = document.getElementById("hfSucessoEnvioEmailMensagemGeomapas");
        if (objFrmGeomapsEnvieEmail != null) {
            // ALTERAÇÃO AUNICA - TAGG
            //trackView('mapas - atendimentoporemail - enviado', 'event2', 'geonavegacao');
        }

    }
}
