$.ajaxSetup({
  cache: false
});

$(document).ready(function() { 
	//limita_selecao();
// Enquete
$(".btEnquete").click(function(){

	var achou = false;
	var idresposta = "input[type=radio]";
	var idenquete = $("#idenquete").val();
	var valResposta;
	
	$(idresposta, "#enquete form").each(function(indice){
	
		if ($(this).attr("checked") == true){
			
			achou = true;
			valResposta = $(this).val();
			
		}
	
	});
	
	if (achou == false){
	
		alert('Marque sua resposta!');
	
	} else {
		
		$.ajax({
			beforeSubmit:  showRequest,  // pre-submit callback 
			success:       showResponse,  // post-submit callback 
			url:       'inc_votacao.php',
			data:	   'idreposta='+ valResposta+'&idenquete='+idenquete, 
			type:      'post'
		});	

	}
	
})

$(".btResultados").click(function(){
	var idenquete = $("#idenquete").val();
	
	jQuery.facebox({ ajax: 'popEnquete.php?status=2&idenquete='+idenquete})
	
})


function showRequest(formData, jqForm, options) {
	
}

function showResponse(responseText, statusText) {
	
	//alert(responseText);
	
	var valor = responseText.split("|");
	
	jQuery.facebox({ ajax: 'popEnquete.php?status='+valor[0]+'&idresposta='+valor[1] })
	//$("#resultado").html(responseText);
	
}	
});

function cadastraNewsLetter(){

var nome = $("#edtNomeNews").val();
var email = $("#edtEmailNews").val();

$.ajax({
type: "POST",
dataType: 'json',
data: {nome: nome, email: email},
url: "newsletter_cad_op.php",
success: function(data){
	$("#respNewsLetter").show();
	exibeResposta(data.elemento,data.fcJQuery,data.texto);
	setTimeout("apagarRespostaNewsLetter()",3000);
}
});

}

function apagarRespostaNewsLetter(){
	$("#respNewsLetter").empty();
	$("#respNewsLetter").hide();
	$("#edtNomeNews").val("");
	$("#edtEmailNews").val("");
}


function exibeResposta(elemento,fcJQuery,texto,editor){
	$(elemento).empty();
	if (fcJQuery == 1){
		$(elemento).append(texto);
	}else{
		$(elemento).load(texto,function(){
			if(editor){
				$('.textarea').fck({path: 'scripts/fckeditor/'});
			}	
		});
	}
}

function enviarContato(){
	var str = $("#contato").serialize();
	
	$("#respostaContato").empty();
	$("#respostaContato").append("Enviando e-mail...");
	//alert(str);
	//return;
	$.ajax({
		type: "POST",
		dataType: 'json',
		data: str,
		url: "action_contato.php",
		success: function(data){
			if (data.status == "ok") {
				$("#respostaContato").html("Contato enviado com sucesso!");
			} else {
				$("#respostaContato").html("Erro ao envia o Contato.");
			}
			//alert(data);
			//exibeResposta(data.elemento,data.fcJQuery,data.texto);
			$("#contato input").each(function(i){ 
				$(this).val(""); 
			});
			$("#contato textarea").val("");
			//setTimeout('$("#respostaContato").empty()',4000);
		}
	});

}

function enviarTrabalheConosco(){
	var str = $("#trabalheConosco").serialize();
	
	$("#respostaTrabalheConosco").empty();
	$("#respostaTrabalheConosco").append("Enviando e-mail...");
	
	$.ajax({
		type: "POST",
		dataType: 'json',
		data: str,
		url: "action_trabalhe_conosco.php",
		success: function(data){
			if (data.status == "ok") {
				$("#respostaTrabalheConosco").html("Contato enviado com sucesso!");
			} else {
				$("#respostaTrabalheConosco").html("Erro ao envia o Contato.");
			}
			
			$("#trabalheConosco input").each(function(i){ 
				$(this).val(""); 
			});
			$("#trabalheConosco textarea").val("");
		}
	});

}