function SomenteNumeros(e)
{
	if (window.event)
		key = event.keyCode
	else
		key = e.which

	// 47 ao 58 - Números // 95 ao 106 - Números // 8 - backspace // 39 - tab //... Shift, alt, crtl
	if (key > 47 && key < 58 || key == 8 || key == 0 || key == 9 || key == 37 || key == 39 || key == 16)
	   return; //caso alguma das teclas acima seja pressionada, então a função é encerrada.
	else //senão o evento é cancelado
	if (window.event) //IE
		window.event.returnValue = null;
	else //Firefox
		e.preventDefault();
}

function retiracaracteres(campotel, e)
{
 campotel.value = campotel.value.replace(/-/g, "");
 campotel.value = campotel.value.replace(/ /g, "");
campotel.value = campotel.value.substring(0,2) + " " + campotel.value.substring(2,10);
 
}

function VerificaData(dia, mes, ano) 
{
        var bissexto = 0;
        var data = dia + "/" + mes + "/" + ano; 
        var tam = data.length;
        if (tam == 10) 
        {
                var dia = data.substr(0,2)
                var mes = data.substr(3,2)
                var ano = data.substr(6,4)
                if ((ano > 1900)||(ano < 2100))
                {
                	if( dia != 00) {
                        switch (mes) 
                        {
                                case '01':
                                case '03':
                                case '05':
                                case '07':
                                case '08':
                                case '10':
                                case '12':
                                        if  (dia <= 31) 
                                        {
                                                return true;
                                        }
                                        break
                                
                                case '04':              
                                case '06':
                                case '09':
                                case '11':
                                        if  (dia <= 30) 
                                        {
                                                return true;
                                        }
                                        break
                                case '02':
                                        /* Validando ano Bissexto / fevereiro / dia */ 
                                        if ((ano % 4 == 0) || (ano % 100 == 0) || (ano % 400 == 0)) 
                                        { 
                                                bissexto = 1; 
                                        } 
                                        if ((bissexto == 1) && (dia <= 29)) 
                                        { 
                                                return true;                             
                                        } 
                                        if ((bissexto != 1) && (dia <= 28)) 
                                        { 
                                                return true; 
                                        }                       
                                        break                                           
                       }
                	} else { return false; };
                }
        }       
        return false;
}
			
function MascaraTelefone(campotel, e)
{
	
	if (window.event)
		key = event.keyCode
	else
		key = e.which

	// 47 ao 58 - Números // 95 ao 106 - Números // 8 - backspace // 39 - tab //... Shift, alt, crtl
	if (key != 8 && key != 0)
	{
		//verifica se o campo possui 4 digitos.
		if(campotel.value.length == 2)
		{
			//Atribui o caractere '-' ao campo.
			campotel.value = campotel.value + " ";
		}
	}
}				

function trocarcor_erro(campo)
{
	document.getElementById(campo).style.background = '#eeeeee';
	document.getElementById(campo).focus();
}

function trocarcor_ok(campo)
{
	document.getElementById(campo).style.background = '#FFFFFF';
}

function EnviarDados()
{
	var re = new RegExp("\\|"); 
	document.getElementById("txt_texto").value = document.getElementById("txt_texto").value.replace(/[|]/g, ' ');
	
	if(document.getElementById("txt_nome").value == "")
	{
		alert("Preencha corretamente o campo nome");
		trocarcor_erro("txt_nome");
		return false;
	}


	if(! ValidaEmail(document.getElementById("txt_email")))
	{
		alert("Preencha corretamente o campo e-mail");
		trocarcor_erro("txt_email");						
		return false;
	}

	if(document.getElementById("txt_telefone").value.length < 11)
	{
		alert("Preencha corretamente o campo Telefone");
		trocarcor_erro("txt_telefone");
		return false;
	}

	if((document.enviaDados.txt_sexo[0].checked == false) && (document.enviaDados.txt_sexo[1].checked == false))
	{
		alert("Selecione o sexo");
		return false;
	}

	
	if(document.getElementById("txt_dia_aniversario").value=="")
	{
		alert("Preencha corretamente o dia do aniversário");
		trocarcor_erro("txt_dia_aniversario");	
		return false;
	}


	if(document.getElementById("txt_mes_aniversario").value=="")
	{
		alert("Preencha corretamente o mês do aniversário");
		trocarcor_erro("txt_mes_aniversario");	
		return false;
	}
					
	if((document.getElementById("txt_ano_aniversario").value=="")||(parseInt(document.getElementById("txt_ano_aniversario").value)<1910)||(parseInt(document.getElementById("txt_ano_aniversario").value)>2010))
	{
		alert("Preencha corretamente o ano do aniversário");
		trocarcor_erro("txt_ano_aniversario");	
		return false;
	}
	
	
	
	if(!VerificaData(document.getElementById("txt_dia_aniversario").value, document.getElementById("txt_mes_aniversario").value, document.getElementById("txt_ano_aniversario").value)){
		alert("Preencha corretamente a data");
		trocarcor_erro("txt_dia_aniversario");
		return false;	
	}
	
	
	
	
	

	if(document.getElementById("txt_cidade").value=="")
	{
		alert("Preencha corretamente o campo cidade");
		trocarcor_erro("txt_cidade");	
		return false;
	}

	if(document.getElementById("txt_estado").value=="")
	{
		alert("Selecione o estado");
		trocarcor_erro("txt_estado");	
		return false;
	}
	
	
	if(document.getElementById("txt_texto").value=="")
	{
		alert("Preencha corretamente a Mensagem");
		trocarcor_erro("txt_texto");	
		return false;
	}
	
	
	if(document.getElementById("txt_falar_sobre").value=="")
	{
		alert("Selecione o assunto");
		trocarcor_erro("txt_falar_sobre");	
		return false;
	}
					
	if(document.getElementById("txt_texto").value.length > 5000)
	{
		alert("Limite de tamanho da mensagem é de 5000 caracteres, sua mensagem possui " + document.getElementById("txt_texto").value.length + " caracteres.");
		trocarcor_erro("txt_texto");	
		return false;
	}


	if((document.form_ctt.txt_news[0].checked == false)&&(document.form_ctt.txt_news[1].checked == false))
	{
		alert("Selecione uma opção para receber ou não Newsletter");
		return false;
	}


	if((document.form_ctt.txt_pesquisa[0].checked == false)&&(document.form_ctt.txt_pesquisa[1].checked == false))
	{
		alert("Selecione uma opção para responder ou não Pesquisas")
		return false;
	}


}

function ValidaEmail(email)
{
	//Verifica se o conteudo do campo é nulo.
	if(email.value=='')
	{	
		return false;
	}
	//inicializa Variáveis
	var checkcliEmail = "@.";
	var checkStr = email.value;
	var cliEmailValid = false;
	var cliEmailAt = false;
	var cliEmailPeriod = false;

	//Verifica cada caractere do campo.
	for (i = 0;  i < checkStr.length;  i++)
	{
		//Pega a letra indexada.
		ch = checkStr.charAt(i);
		
		//Verifica se o caractere é igual ao exigido.
		for (j = 0;  j < checkcliEmail.length;  j++)
		{
			//Verifica se o caractere é igual ao '@'
			if (ch == checkcliEmail.charAt(j) && ch == "@")
			cliEmailAt = true;
			//Verifica se o caractere é igual ao '.'
			if (ch == checkcliEmail.charAt(j) && ch == ".")
			cliEmailPeriod = true;
			
			//Sai do loop caso a string contenha '@' e '.'
			if (cliEmailAt && cliEmailPeriod)
			break;
			
			//Sai do loop caso a  verificação da string.
			if (j == checkcliEmail.length)
			break;
		}
		
		//Verifica se a string possui '@' e '.'
		if (cliEmailAt && cliEmailPeriod)
		{
			//Valida a String
			cliEmailValid = true
			break;
		}
	}
	
	//Verifica se a string é válida.
	if (!cliEmailValid)
	{
		return false;
	}
	else
	{
		return true;
	}
}




