/// <reference name="MicrosoftAjax.js"/>
/// <reference name="jquery-1.3.2.min.js"/>

// Função que faz o track no Google Analytics com o caminho passado
function gaTrack(caminho)
{	

	try 
	{ 
		var pageTrackerInterna = _gat._getTracker("UA-9192744-1"); 
		pageTrackerInterna._initData();
		pageTrackerInterna._trackPageview(caminho);
	}
	catch (err) 
	{ 
	}
}

function cadastroComSucesso() {
    gaTrack('/cadastro/efetuado_sucesso.html');
}

function cadastroComSucesso() {
    gaTrack('/cadastro/efetuado_sucesso.html');
}

$(document).ready(function() {

    

    /* Antigo	
	if ($(".boxCadastroTudo .btnEnviar").lenght > 0) {
        var eventoCadastro = $(".boxCadastroTudo .btnEnviar")[0].href + ";";
        $(".boxCadastroTudo .btnEnviar")[0].href = 'javascript:void(0);';
        $('.boxCadastroTudo .btnEnviar').click(function() {
            if (eventoCadastro.toLowerCase().indexOf('javascript:') != -1)
                eventoCadastro = eventoCadastro.substring(11);
            eventoCadastro = eventoCadastro.replace(/%20/g, ' ').replace(/\"/g, "'");
            eval(eventoCadastro);
            if (Page_IsValid)
                gaTrack('/cadastro/enviar.html');
        });
    }*/

    /* Antigo
	$('.botaoEnviar').click(function() {
        if (Page_IsValid) {
            var url = '';
            if (window.location.href.indexOf('noticias') != -1) {
                url = '/noticias/NAME/envie_amigo/enviar.html';
            } else if (window.location.href.indexOf('boletim') != -1) {
                url = '/boletim/NAME/envie_amigo/enviar.html';
            }
            url = url.replace(/NAME/, $('.noticias1Titulo').text().replace(/ /g, '+'));
            gaTrack(url);
        }
    });*/

    /* Antigo
	$('#ctl00_ctl00_ctl00_ctl00_ContentPlaceHolderDefault_ContentPlaceHolderDefault_ContentMiolo_CadastroNewsletter_5_ibtnEnvia').click(function() {
        if (Page_IsValid)
            gaTrack('/boletim/assine_newsletter/assinado.html');
    });*/

	/* Antigo
    $('.downloadBullet').click(function() {
        var url = '';
        if (window.location.href.indexOf('informativo') != -1) {
            url = '/boletim/NAME/download.html';
        } else if (window.location.href.indexOf('mercado') != -1) {
            url = '/servicos/boletim_mercado/NAME/download.html';
        }
        url = url.replace(/NAME/, $('.noticias1Titulo').text().replace(/ /g, '+'));
        gaTrack(url);
    });
	*/

	/* Antigo
    $('.PdfListFISPQ > ul > li > a').click(function() {
        var nome = $(this)[0].href;
        nome = nome.substring(nome.indexOf('='));
        nome = nome.substring(nome.lastIndexOf('/') + 1);
        gaTrack('/produtos/fispq/' + unescape(nome) + '.html');
    });
	*/

	/* Antigo
    $('.accordionIntConteudo > li > a').click(function() {
        var nome = $(this)[0].href;
        nome = nome.substring(nome.indexOf('='));
        nome = nome.substring(nome.lastIndexOf('/') + 1);
        gaTrack('/servicos/agricultura_precisao/' + unescape(nome) + '/download.html');
    });
	*/	
		
	// Home > Fale Conosco > Botão enviar
	// Home > Fale Conosco > Mensagem de sucesso
	$('.boxFormulario .btEnviar').click(function() {	
		if (Page_IsValid) 
		{		
			if (window.location.href.indexOf('fale-conosco') != -1) 
			{
				gaTrack('/fale_conosco/enviar.html');
				gaTrack('/fale_conosco/enviado_sucesso.html');
	        }		
		}
		else {
			gaTrack('/fale_conosco/enviar.html');
		}		
    });
	
	// Busca Aviso > Botão: Entre em contato conosco
	// Busca Aviso > Botão: Quero receber um contato com meu representante
	
	// Produtos > FISPQ > Download dos arquivos
	$(".contSuperiorBoletimLista a:contains('DOWNLOAD DO ARQUIVO')").click(function(){		
		var download = new String(this.href);
		gaTrack('/produtos/fispq/dowloads' + download.split('=')[1]);
	});
	
	// Serviços > Agricultura de precisão > Download dos arquivos
	$('.accordionIntConteudo a').click(function() {
		var download = new String(this.href);
		gaTrack('/servicos/agricultura_precisao/' + download.split('=')[1]);
	});

	// Boletim de Mercado > Download dos arquivos
	$(".listaDownload a:contains('DOWNLOAD DO ARQUIVO')").click(function() {
		var download = new String(this.href);																  
		gaTrack('/servicos/boletim_mercado/' + download.split('=')[1]);		   
	});
	
	// Evento > Nome do Evento > Botão: Envie para um amigo
	// Obs: Não encontrado
	
	// Evento > Nome do Evento > Botão: Enviar
	// Obs: Não encontrado
	
	// Evento > Nome do Evento > Mensagem de enviado com sucesso
	// Obs: Não encontrado
	
	// Boletim Informativo > Informativo > Download do informativo
	$(".downloadBullet a:contains('DOWNLOAD DO ARQUIVO')").click(function() {
		var nomeInformativo = $('h4').html();	
		gaTrack('/boletim/' + nomeInformativo);	   
	});
	
	// Boletim Informativo > Informativo > Botão enviar
	$('input.botaoEnviar').click(function() {
		var nomeInformativo = $('h4').html();
		gaTrack('/boletim/' + nomeInformativo + '/envie_amigo/enviar.html');
	});
	
	// Boletim Informativo > Assine a Newsletter > Botão ok
	$('.boxDestaqueInferior input.btOk').click(function() {
		if(Page_IsValid) {
			gaTrack('/boletim/assine_newsletter/assinado.html');
		}		
	});
	
	// Boletim Informativo > Assine a Newsletter > Mensagem de Sucesso
	$('.boxDestaqueInferior .btOk').click(function() {
		if(Page_IsValid) {
			gaTrack('/boletim/assine_newsletter/assinado.html');
			gaTrack('/boletim/assine_newsletter/assinado_sucesso.html');
		}					 
	});
	
	// Notícias > Botão: envie para um amigo
	$('input.botaoEnviar, input[type=image]').click(function() {
		if(Page_IsValid) {
			gaTrack('/noticias/(nome_da_noticia)/envie_amigo/enviar.html');
		}
	});
	
	// Cadastro > Botão enviar
	// Cadastro > Mensagem de Cadastro efetuado com sucesso
	$('.boxCadastroTudo a.btnEnviar').click(function() {
		if(Page_isValid) {
			gaTrack('/cadastro/enviar.html');
			gaTrack('/cadastro/efetuado_sucesso.html');	
		}
    });

	// Identificação > Botão ok
	$('a input[type=image]').click(function() {
		if(Page_isValid) {
			gaTrack('/identificacao/botao_ok.html');	
		}
	});
		
});




