// JavaScript Document

function getId(id)
{
	return document.getElementById(id);
}

function mostraId(id)
{
	$("#"+id).show("fast");
}

function escondeId(id)
{
	$("#"+id).hide("fast");
}

function mostraEscondeId(id)
{
	if(getId(id).style.display=='none')
	{
		$("#"+id).show("fast");
	}
	else
	{
		$("#"+id).hide("fast");
	}
}

function checkMail(mail){
	var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
	if(typeof(mail) == "string"){
			if(er.test(mail)){ return true; }
	}else if(typeof(mail) == "object"){
			if(er.test(mail.value)){
									return true;
							}
	}else{
			return false;
			}
}


//===========================================================
// ENQUETE
//===========================================================

function votaEnquete(id_enquete)
{
	var elementos = document.getElementsByTagName('input');
	var marcado = '';
	for(var i=0;i<elementos.length;i++)
	{
		if(elementos[i].className=='opcaoEnquete'+id_enquete)
		{
			if(elementos[i].checked)
				marcado = elementos[i].value;
		}
	}
	if(marcado=='')
	{
		alert('Selecione alguma alternativa para votar.');
		return false;
	}
	mostraId('enviandoVoto'+id_enquete);
	getId('enviandoVoto'+id_enquete).innerHTML = 'Enviando...';
	xajax_votaEnquete(marcado);
}

function resultadoEnquete(id_enquete)
{
	mostraId('carregandoEnquete'+id_enquete);
	getId('carregandoEnquete'+id_enquete).innerHTML = 'Carregando...';
	xajax_resultadoEnquete(id_enquete);
}

function mostraEnquete(id_enquete)
{
	mostraId('carregandoEnquete'+id_enquete);
	getId('carregandoEnquete'+id_enquete).innerHTML = 'Carregando...';
	xajax_mostraEnquete(id_enquete);
}


//=============================================================
//	COMENTARIOS
//=============================================================

function enviaComentario(){
	nome = document.getElementById('nomeComent').value;
	email = document.getElementById('emailComent').value;
	mensagem = document.getElementById('mensagemComent').value;
	id_noticia = document.getElementById('id_noticiaComent').value;
	if(nome==''){
		alert('Preencha o campo nome corretamente!');
		return false;
	}
	if(email.indexOf('@')==-1){
		alert('Preencha o campo email corretamente!');
		return false;
	}
	if(mensagem==''){
		alert('Preencha sua mensagem!');
		return false;
	}
	mostraId('enviandoComent');
	xajax_enviaComentario(id_noticia, nome, email, mensagem);
}

function limpaCampos(){
	document.getElementById('nomeComent').value = '';
	document.getElementById('emailComent').value = '';
	document.getElementById('mensagemComent').value = '';
	mostraId('enviadoComent');
	setTimeout("escondeId('enviandoComent');", 2000);
	setTimeout("escondeId('enviadoComent');", 2500);
	setTimeout("escondeId('enviaComentario');", 3000);
}

function limpaIndicacao(){
	document.getElementById('nomeIndique').value = '';
	document.getElementById('emailIndique').value = '';
	document.getElementById('amigoIndique').value = '';
	mostraId('enviadoIndique');
	setTimeout("escondeId('enviandoIndique');", 2000);
	setTimeout("escondeId('enviadoIndique');", 2500);
	setTimeout("escondeId('enviaAmigo');", 3000);
}

function enviaAmigo(){
	nome = document.getElementById('nomeIndique').value;
	email = document.getElementById('emailIndique').value;
	amigo = document.getElementById('amigoIndique').value;
	id_noticia = document.getElementById('id_noticiaIndique').value;
	if(nome==''){
		alert('Preencha o campo nome corretamente!');
		return false;
	}
	if(email.indexOf('@')==-1){
		alert('Preencha seu email corretamente!');
		return false;
	}
	if(amigo.indexOf('@')==-1){
		alert('Preencha o email do seu amigo corretamente!');
		return false;
	}
	mostraId('enviandoIndique');
	xajax_enviaEmail(nome, email, amigo, id_noticia);
}


function enviaGaleriaAmigo(){
	nome  = document.getElementById('seuNome').value;
	email = document.getElementById('seuEmail').value;
	amigo = document.getElementById('emailAmigo').value;
	id_galeria = document.getElementById('id_galeria').value;
	if(nome==''){
		alert('Preencha o campo nome corretamente!');
		return false;
	}
	if(email.indexOf('@')==-1){
		alert('Preencha seu email corretamente!');
		return false;
	}
	if(amigo.indexOf('@')==-1){
		alert('Preencha o email do seu amigo corretamente!');
		return false;
	}
	mostraId('enviandoIndique');
	xajax_enviaEmailGaleria(nome, email, amigo, id_galeria);
}

function limpaIndicacaoAlbum(){
	document.getElementById('seuNome').value = '';
	document.getElementById('seuEmail').value = '';
	document.getElementById('emailAmigo').value = '';
	mostraId('enviadoIndique');
	setTimeout("escondeId('enviandoIndique');", 2000);
	setTimeout("escondeId('enviadoIndique');", 2500);
	setTimeout("escondeId('enviaAmigo');", 3000);
}

function enviaRecado(){
	nome = document.getElementById('nome').value;
	email = document.getElementById('email').value;
	recado = document.getElementById('recado').value;
	if(nome==''){
		alert('Preencha o campo nome corretamente!');
		return false;
	}
	if(email.indexOf('@')==-1){
		alert('Preencha o campo email corretamente!');
		return false;
	}
	if(recado==''){
		alert('Preencha sua mensagem!');
		return false;
	}
	mostraId('enviandoRecado');
	xajax_enviaRecado(nome, email, recado);
}

function limpaCamposRecado(){
	document.getElementById('nome').value = '';
	document.getElementById('email').value = '';
	document.getElementById('recado').value = '';
	mostraId('enviadoRecado');
	setTimeout("escondeId('enviandoRecado');", 2000);
	setTimeout("escondeId('enviadoRecado');", 2500);
	//setTimeout("escondeId('enviaRecado');", 3000);
}

function enviaContato()
{
	nome = document.getElementById('nome').value;
	email = document.getElementById('email').value;
	telefone = document.getElementById('telefone').value;
	cidade = document.getElementById('cidade').value;
	assunto = document.getElementById('assunto').value;
	mensagem = document.getElementById('mensagem').value;
	if(nome==''){
		alert('Preencha o campo nome corretamente!');
		return false;
	}
	if(email.indexOf('@')==-1){
		alert('Preencha o campo email corretamente!');
		return false;
	}
	if(cidade==''){
		alert('Preencha o campo cidade!');
		return false;
	}
	if(assunto==''){
		alert('Preencha o campo assunto!');
		return false;
	}
	if(mensagem==''){
		alert('Preencha o campo com sua mensagem!');
		return false;
	}
	mostraId('enviando');
	xajax_enviaContato(nome, email, telefone, cidade, assunto, mensagem);
}

function limpaCampoContato(){
	document.getElementById('nome').value = '';
	document.getElementById('email').value = '';
	document.getElementById('telefone').value = '';
	document.getElementById('cidade').value = '';
	document.getElementById('assunto').value = '';
	document.getElementById('mensagem').value = '';
	mostraId('sucesso');
	setTimeout("escondeId('enviando');", 2000);
	setTimeout("escondeId('sucesso');", 2500);
}
