// Valida selects
function linkSelect(url){
	if(url != "#"){
		location.href = url;
	}
}

// Abre e fecha DIVs
function abreFecha(obj, classe, efeito){
	if(efeito == 1){
		$("#"+obj).is(":hidden") ? $("#"+obj).slideDown('fast') : $("#"+obj).hide();
	}
	if($("."+classe).is(":visible")){
		$("."+classe).hide();
	}
}

function abreLink(url){
	open(url);
}

// Modal
function abreModal(){
	$(".fundoModal").css("height",$(document).height());
	$(".fundoModal").fadeIn("last");
	setTimeout("$('.modal').fadeIn('last');",200);
}

function fechaModal(){
	$(".fundoModal").fadeOut("last");
	$(".modal").fadeOut("last");
}

$(".fundoModal, .modal .fechar").click(function(){
	fechaModal();
});

$(document).keypress(function (e) {					   
	if(e.which == 27 || e.keyCode == 27){
		fechaModal();
	}
});


// Enquete
var idVoto;
$("input").click(function () { 
	idVoto = $(this).val();
});
	
$("#votar").click(function(){
	var radios = $("input[@type=radio][@name=opcoes][@checked]").val();

	if(radios == null){
		alert("Selecione uma das opções!");
	}else{
		$.post("enquete/contabiliza.php",{id:idVoto},
		function(retorno)
		{
			if(retorno == 1 || retorno == 2){
				abreModal();
				$.ajax({
				url: $("#resultado").attr("href")+"&voto=1",
				cache: false,
				success: function(html){
				$(".modal .conteudo").html(html);
				}
				});
			}
		});
	}	
	return false;
});

$("#resultado").click(function(){
	abreModal();
	$.ajax({
		url: $("#resultado").attr("href"),
		cache: false,
		success: function(html){
		$(".modal .conteudo").html(html);
	}
	});
return false;
});
