// JavaScript Document

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

function enviaContato()
{
	var email = getId('email');
	var nome = getId('nome');
	var cidade = getId('cidade');
	var assunto = getId('assunto');
	var mensagem = getId('mensagem');
	
	if(nome.value=='')
	{
		alert('Preencha seu nome corretamente!');
		nome.focus();
		return false;
	}
	
	if(!checkMail(email.value))
	{
		alert('Preencha seu email corretamente!');
		email.focus();
		return false;
	}
	
	if(mensagem.value=='')
	{
		alert("Preencha o campo 'Mensagem'!");
		mensagem.focus();
		return false;
	}
	
	xajax_enviaContato(nome.value, email.value, cidade.value, assunto.value, mensagem.value);
	
}

function enviaAutografo()
{
	var email = getId('email');
	var nome = getId('nome');
	var recado = getId('recado');
	var branco = getId('branco');
	
	if(nome.value=='')
	{
		alert('Preencha seu nome corretamente!');
		nome.focus();
		return false;
	}
	
	if(!checkMail(email.value))
	{
		alert('Preencha seu email corretamente!');
		email.focus();
		return false;
	}
	
	if(recado.value=='')
	{
		alert("Preencha o campo 'Recado'!");
		recado.focus();
		return false;
	}
	
	xajax_enviaAutografo(nome.value, email.value, recado.value, branco.value);
	
}

function postComentario(id_noticia)
{
	var email = getId('email');
	var nome = document.getElementById('nomeComentario');
	var comentario = getId('comment');
	var site = getId('url');
	
	if(nome.value=='')
	{
		alert('Preencha seu nome corretamente!');
		nome.focus();
		return false;
	}

	if(!checkMail(email.value))
	{
		alert('Preencha seu email corretamente!');
		email.focus();
		return false;
	}
	if(comentario.value=='')
	{
		alert("Preencha o campo 'Comentario'!");
		comentario.focus();
		return false;
	}
	
	xajax_postComentario(id_noticia, nome.value, email.value, comentario.value, site.value);
	
}

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;
        }
}