
  function atualizaTransmissoes(){
	var txtCodigo  = $("#option2").val();
	
	$.post("_global/ajax/RetornaTransmissoes.php", {txtCodigo: txtCodigo}, 
		function(xml){
			$("#option2Trans").removeAttr('disabled');
			$("#option2Trans").find('option').remove();
			$(xml).find("transmissao").each(function(){
				$("#option2Trans").append(
		   			'<option value='+$(this).find('idtransmissao').text()+
		   			'>'+$(this).find('txtCodigo').text()+
		   			'</option>'
				);
			});
		});
  }
  
  function atualizaLista(){
		var txtCodigo = $("#option3").val();
		$("#cabecalho tr").remove();
		$("#cabecalho").after(
	   			'<tr id="carregando" style="background-color: #E6E7E9"><td align="center" colspan="5">Carregando...</td></tr>'
		);
		$.post("_global/ajax/RetornaTransmissoesLista.php", {txtCodigo: txtCodigo}, 
			function(xml){
				teste = $(xml).find("transmissao").find("motor").text();
				if(!teste){
					$("#cabecalho").append(
				   			'<tr id="lista" style="background-color: #E6E7E9"><td align="center" colspan="5">Este fabricante n&atilde;o possui nenhuma transmiss&atilde;o.</td></tr>'
					); 
				}else{
					$(xml).find("transmissao").each(function(){
						$("#cabecalho").append(
				   			'<tr><td class="tabela-coluna0">'+$(this).find('txtNome').text()+
							'</td><td class="tabela-coluna1">'+$(this).find('anoInicial').text()+$(this).find('anoFinal').text()+
							'</td><td class="tabela-coluna2">'+$(this).find('motor').text()+
							'</td><td class="tabela-coluna3">'+$(this).find('velocidade').text()+
							'</td><td class="tabela-coluna4">'+$(this).find('txtCodigo').text()+
				   			'</td></tr>'
						);
					});
				}
				$("#carregando").remove();
			});
	  }
  
  $(document).ready(function() {
  
	  $(function ($) {
		  
	  $("#formContato").submit(function() {
	  
	   if (ValidateThis(this) == true) {
	  
		  $(".botaoEnvia").attr("disabled", true);
	   
		  $.post("_global/ajax/insereContato.php", $("#formContato").serialize(),
		  function(resposta) { 
		    
		  var json = $.parseJSON(resposta);
	    
	      // função que aplica decodeURIComponent para strings (necessária utilizando CustomJson)
	      decodeData(json);
	      
	      alert(json.str);
	  
	      //$("#avisoContato").html(json.str);
	    
	      // Se a resposta for falsa
	      if (json.ok == true) {
	    	  $(".botaoEnvia").attr("disabled", false); // Habilita novamente o botão submit
	          resetForm("formContato");	
	      }
	    });
	  }
	});
   });
  });
  
  function decodeData(data) {
	    for(var item in data) {
	        var type = typeof data[item];
	        if(type === 'object') decodeData(data[item]);
	        else if(type === 'string') data[item] = decodeURIComponent(data[item]);
	    }
  }
  
  function resetForm(id) {
		$('#'+id).each(function(){
		        this.reset();
		});
	}
  function habilitaBotao(idBotao) {
	  $("#"+idBotao).attr("disabled", false); // Habilita novamente o botão submit
  }
  
  function exibeImagem(img,alt) {
	  tagImg = '<img src="'+img+'" alt="Imagem '+alt+'" />';
	  $(".exibeImg").hide();
	  $(".exibeImg").html(tagImg);
	  $(".exibeImg").fadeIn(500);
  }

  
  //Google Analytics
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-22613350-1']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

