function enviar_comentario() {
	
	if (valida_formulario()) {
		$('boton_enviar').style.display = 'none';
		$('loader_comentario').style.display = 'inline';
		new Ajax.Request('enviar_comentario.php', {
			parameters: $('formulario').serialize() + '&noticia_id='+$('noticia_id').value,
			onSuccess: function(transport) {
				if (transport.responseText == 'ok') {
					alert('Tu mensaje se grabo correctamente, antes de publicarse debe ser aprobado por un administrador.');
					$('nombre').value = '';
					$('email').value = '';
					$('mensaje').value = '';
					$('captcha').value = '';
					$('captcha_img').src = 'captcha.php';
				}
				else 
					alert(transport.responseText);
				$('boton_enviar').style.display = 'inline';
				$('loader_comentario').style.display = 'none';
			}
		});		
	}
}

function valida_formulario() {
	var msg = '';
	if ($('nombre').value == '')
		msg += 'Nombre\n';
	if ($('email').value == '')
		msg += 'E-mail\n';
	if ($('mensaje').value == '')
		msg += 'Comentario\n';
	
	if ($('captcha').value == '')
		msg += 'Codigo\n';
	 
	if (msg == '')
		return true;
	else {
		alert('Faltan datos por completar en el formulario:\n'+msg);
		return false;
	}
}



function votar_encuesta() {
	var indice_voto = 0;

	if ($$('#form_encuesta input[type=radio]:checked').length) {
		indice_voto = $$("#form_encuesta input:checked")[0].id.replace('opcion_', '');
	}
	
	if (indice_voto == 0) {
		alert("Debe seleccionar una opcion");
	}
	else {
		$("loader_encuesta").style.display = 'inline';		

		new Ajax.Request('graba_voto.php', {
			parameters: 'indice_voto='+indice_voto+'&encuesta_id='+$('encuesta_id').value,
			onSuccess: function(transport) {
				$("loader_encuesta").style.display = 'none';	
				alert("Gracias por participar en nuestra encuesta.")
				//alert(transport.responseText);
			}
		});		
		
		
		
	}
}
