﻿function validaContato(){

	d = document.FormContato;
	if (d.nome2.value == "")
	{
		alert("Preencha o campo Nome!");
		d.nome2.focus();
		return false;	
	}
    
    if (d.ddd.value == "")
	{
		alert("Preencha o campo DDD!");
		d.ddd.focus();
		return false;	
	}
    
	if (d.telefone.value == "")
	{
		alert("Preencha o campo Telefone!");
		d.telefone.focus();
		return false;	
	}
	
	if (d.endereco.value == "")
	{
		alert("Preencha o campo Endereço!");
		d.endereco.focus();
		return false;	
	}
	
	if (d.cep.value == "")
	{
		alert("Preencha o campo CEP!");
		d.cep.focus();
		return false;	
	}
	
    	if (d.estado.value == "" || d.estado.value == "Escolher")
	{
		alert("Escolha um dos Estados!");
		d.estado.focus();
		return false;	
	}
	
	
		var str = d.email2.value;
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		
		if (str.indexOf(at)==-1){
		   alert("Email Inválido!")
       	   d.email2.focus();
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Email Inválido!")
       	   d.email2.focus();
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		   alert("Email Inválido!")
       	   d.email2.focus();
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		   alert("Email Inválido!")
       	   d.email2.focus();
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		   alert("Email Inválido!")
       	   d.email2.focus();
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		   alert("Email Inválido!")
       	   d.email2.focus();
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		   alert("Email Inválido!")
       	   d.email2.focus();
		    return false
		 }
		 
		 
    if (d.cidade.value == "")
	{
		alert("Preencha o campo Cidade!");
		d.cidade.focus();
		return false;	
	}
	

	if (d.assunto.value == "" || d.assunto.value == "Escolher")
	{
		alert("Escolha um dos Assuntos!");
		d.assunto.focus();
		return false;	
	}

	if (d.mensagem.value == "")
	{
		alert("Preencha o campo Mensagem!");
		d.mensagem.focus();
		return false;	
	}

	else
		return true;
	
}
