// JavaScript Document
function validaContato()
{
	var destino = document.frmContato.destino;
	var nome = document.frmContato.nome;
    var email = document.frmContato.email;
	var assunto = document.frmContato.assunto;
	var mensagem = document.frmContato.mensagem;
    var BadChars = "*|,\":<>[]{}`\'';()&$#% ";
	var GoodChars = "@.";
	var posarroba = email.value.indexOf ('@',0);
    
	if(destino.value == "selecione")
	{
		alert("\nSelecione o 'DESTINO'");
   		destino.focus();
		return false;
	}
	if(nome.value == "")
	{
		alert("\nPreencha o campo 'NOME'");
		nome.focus();
		return false;
	}
	if (email.value == "")
	{
    	alert("\nPreencha o campo 'E-mail'");
		email.focus();
		return false;
    }
	else
	{
		if (email.value.length < 3) //o e-mail é menor que 3 caracteres - caractesristica do grupo milla
		{
			alert("\nE-mail inválido!");
			email.focus();
			return false;
		}
		for (var i = 0; i < email.value.length; i++)
		{
			if (BadChars.indexOf(email.value.charAt(i)) != -1) //Contém caracteres inválidos, famosos BadChars
			{
				alert("\nO e-mail contém caracteres inválidos");
				email.focus();
				return false;
			}
		}
		for (var i = 0; i < GoodChars.length; i++)
		{
			if (email.value.indexOf(GoodChars.charAt(i)) == -1) //não tem goodchars
			{
				alert("\nE-mail inválido!");
				email.focus();
				return false;
			}
			if (email.value.indexOf(GoodChars.charAt(i),0) == 0) //começou com goodchars(. ou @)
			{
				alert("\nE-mail inválido!");
				email.focus();
				return false;
			}
			if (email.value.lastIndexOf(GoodChars.charAt(i)) > email.value.length-3)//existe menos de dois caracteres apos o ultimo goodchar
			{
				alert("\nE-mail inválido! Seu email não deve terminar com @.");
				email.focus();
				return false;
			}
		}
		if (email.value.lastIndexOf('@') > email.value.lastIndexOf('.')) //não tem ponto depois do arroba
		{
			alert("\nE-mail inválido!");
			email.focus();
			return false;
		}
		if (email.value.indexOf('@.',0) != -1 || email.value.indexOf ('.@',0) != -1) //. e @ colados
		{
			alert("\nE-mail inválido!");
			email.focus();
			return false;
		}
		if (email.value.indexOf ('@',posarroba + 1) != -1) //Contém mais de um @
		{
			alert("\nE-mail inválido!");
			email.focus();
			return false;
		}
	}
	if(assunto.value == "")
	{
		alert("\nPreencha o campo 'ASSUNTO'");
		assunto.focus();
		return false;
	}
	if(mensagem.value == "")
	{
		alert("\nPreencha o campo 'MENSAGEM'");
		mensagem.focus();
		return false;
	}
	return true;
}
