 /* Contato */

function validar_contato() {

var nome = document.form.nome.value
if (nome == ""){
	alert("Nome é um campo obrigatorio!!!");
	document.form.nome.focus()
	return false
	}
	
//TESTE EMAIL
	  var email = document.form.email.value;
	  var suportado = 0;

	  //Testa se o browser suporta expressões regulares

	  if (window.RegExp) {
	    var tempReg = /a/;
	    if (tempReg.test("a")){
	      suportado = 1;
	    }
	  }

	  //Se o browser não suporta expressões regulares,
	  //verifica apenas a posição do ponto e da arroba

	  if (!suportado){
	    if(((email.indexOf(".") <= 0) || (email.indexOf("@") <= 0)) || ((email.lastIndexOf(".") == (email.length - 1)) || (email.lastIndexOf("@") == (email.length -1)))){
			 alert("Por favor confira o campo e-mail!");
			 document.form.email.focus();
	         return false;
	    }

	  //Se o browser suporta expressões regulares,
	  //faz a verificação completa

	  }else{
	    var tmp1 = /(@.*@)|(\.\.)|(@\.)|(^\.)/;
	    var tmp2 = /^.+@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;

        if(tmp1.test(email) || !tmp2.test(email)){
		  alert("Confira o campo e-mail");
		  document.form.email.focus();
		  return false;
	   }

		if (document.form.email.value == ""){
		    alert("Você deve preencher o campo E-mail");
			document.form.email.focus();
			return false;
		}

	  }

	if (document.form.email.value != document.form.redigemail.value){
		alert("Confirme seu e-mail");
		document.form.redigemail.value="";
		document.form.redigemail.focus();
		return false;
	}	
	
var data_nascimento = document.form.data_nascimento.value
if (data_nascimento == ""){
	alert("Data Nascimento é um campo obrigatorio!!!");
	document.form.data_nascimento.focus()
	return false
	}

var profissao = document.form.profissao.value
if (profissao == "0"){
	alert("Profissao é um campo obrigatorio!!!");
	document.form.profissao.focus()
	return false
	}

var pais = document.form.pais.value
if (pais == "0"){
	alert("País é um obrigatorio!!!");
	document.form.pais.focus()
	return false
	}
	
var cep = document.form.cep.value
if (cep == ""){
	alert("Cep é um obrigatorio!!!");
	document.form.cep.focus()
	return false
	}
	
var endereco = document.form.endereco.value
if (endereco == ""){
	alert("Endereço é um obrigatorio!!!");
	document.form.endereco.focus()
	return false
	}
	
var numero = document.form.numero.value
if (numero == ""){
	alert("Número é um obrigatorio!!!");
	document.form.numero.focus()
	return false
	}	
	
var bairro = document.form.bairro.value
if (bairro == ""){
	alert("Bairro é um obrigatorio!!!");
	document.form.bairro.focus()
	return false
	}
	
var cidade = document.form.cidade.value
if (cidade == ""){
	alert("Cidade é um obrigatorio!!!");
	document.form.cidade.focus()
	return false
	}	

var uf = document.form.uf.value
if (uf == "0"){
	alert("Uf é um obrigatorio!!!");
	document.form.uf.focus()
	return false
	}	
	
var telefone_res = document.form.telefone_res.value
if (telefone_res == ""){
	alert("Telefone Contato é um obrigatorio!!!");
	document.form.telefone_res.focus()
	return false
	}	
 }
 

/*-----------------------------------------------------------------------
Máscara para o campo Telefone
-----------------------------------------------------------------------*/

function Telefone(evento, objeto){
	var keypress=(window.event)?event.keyCode:evento.which;
	campo = eval (objeto);
	if (campo.value == '(00)00000000')
	{
		campo.value=""
	}

	caracteres = '0123456789';
	separacao1 = '(';
	separacao2 = ')';
	conjunto1 = 0;
	conjunto2 = 3;

	if ((caracteres.search(String.fromCharCode (keypress))!=-1) && campo.value.length < (25))
	{
		if (campo.value.length == conjunto1 )
		campo.value = campo.value + separacao1;
		else if (campo.value.length == conjunto2)
		campo.value = campo.value + separacao2		
	}
	else
		event.returnValue = false;
}

/*-----------------------------------------------------------------------
Formata número tipo moeda usando o evento onKeyDown
-----------------------------------------------------------------------*/

function Limpar(valor, validos) {
// retira caracteres invalidos da string
var result = "";
var aux;
for (var i=0; i < valor.length; i++) {
aux = validos.indexOf(valor.substring(i, i+1));
if (aux>=0) {
result += aux;
}
}
return result;
}

//Formata número tipo moeda usando o evento onKeyDown

function Formata(campo,tammax,teclapres,decimal) {
var tecla = teclapres.keyCode;
vr = Limpar(campo.value,"0123456789");
tam = vr.length;
dec=decimal

if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }

if (tecla == 8 )
{ tam = tam - 1 ; }

if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 )
{

if ( tam <= dec )
{ campo.value = vr ; }

if ( (tam > dec) && (tam <= 5) ){
campo.value = vr.substr( 0, tam - 2 ) + "," + vr.substr( tam - dec, tam ) ; }
if ( (tam >= 6) && (tam <= 8) ){
campo.value = vr.substr( 0, tam - 5 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; 
}
if ( (tam >= 9) && (tam <= 11) ){
campo.value = vr.substr( 0, tam - 8 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; }
if ( (tam >= 12) && (tam <= 14) ){
campo.value = vr.substr( 0, tam - 11 ) + "." + vr.substr( tam - 11, 3 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; }
if ( (tam >= 15) && (tam <= 17) ){
campo.value = vr.substr( 0, tam - 14 ) + "." + vr.substr( tam - 14, 3 ) + "." + vr.substr( tam - 11, 3 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - 2, tam ) ;}
} 

}

/*-----------------------------------------------------------------------
Máscara para o campo Cnpj
-------------------------*/

function Cnpj(evento, objeto){
	var keypress=(window.event)?event.keyCode:evento.which;
	campo = eval (objeto);
	if (campo.value == '000.000.000/0000-00')
	{
		campo.value=""
	}

	caracteres = '0123456789';
	separacao1 = '.';
	separacao2 = '-';
	separacao3 = '/';
	conjunto1 = 3;
	conjunto3 = 7;
	conjunto4 = 11;
	conjunto5 = 16;

	if ((caracteres.search(String.fromCharCode (keypress))!=-1) && campo.value.length < (25))
	{
		if (campo.value.length == conjunto1 )
		campo.value = campo.value + separacao1;
		else if (campo.value.length == conjunto3)
		campo.value = campo.value + separacao1;
		else if (campo.value.length == conjunto4)
		campo.value = campo.value + separacao3;
		else if (campo.value.length == conjunto5)
		campo.value = campo.value + separacao2;
	}
	else
		event.returnValue = false;
}

/*-----------------------------------------------------------------------
Máscara para o campo Data
-----------------------------------------------------------------------*/

function Data(evento, objeto){
	var keypress=(window.event)?event.keyCode:evento.which;
	campo = eval (objeto);
	if (campo.value == '00/00/0000')
	{
		campo.value=""
	}

	caracteres = '0123456789';
	separacao1 = '/';
	conjunto1 = 2;
	conjunto2 = 5;

	if ((caracteres.search(String.fromCharCode (keypress))!=-1) && campo.value.length < (19))
	{
		if (campo.value.length == conjunto1 )
		campo.value = campo.value + separacao1;
		else if (campo.value.length == conjunto2)
		campo.value = campo.value + separacao1;
	}
	else
		event.returnValue = false;
}

/*-----------------------------------------------------------------------
Máscara para o campo CEP
-----------------------------------------------------------------------*/
function Cep(evento, objeto){
	var keypress=(window.event)?event.keyCode:evento.which;
	campo = eval (objeto);
	if (campo.value == '00000-000')
	{
		campo.value=""
	}

	caracteres = '0123456789';
	separacao = '-';
	conjunto1 = 5;

	if ((caracteres.search(String.fromCharCode (keypress))!=-1) && campo.value.length < (19))
	{
			
		if (campo.value.length == conjunto1)
		campo.value = campo.value + separacao;
	}
	else
		event.returnValue = false;
}
/*-----------------------------------------------------------------------
Máscara para o campo CPF
-----------------------------------------------------------------------*/

function Cpf(evento, objeto){
	var keypress=(window.event)?event.keyCode:evento.which;
	campo = eval (objeto);
	if (campo.value == '000.000.000-00')
	{
		campo.value=""
	}

	caracteres = '0123456789';
	separacao1 = '.';
	separacao2 = '-';
	conjunto1 = 3;
	conjunto2 = 4;
	conjunto3 = 7;
	conjunto4 = 11;

	if ((caracteres.search(String.fromCharCode (keypress))!=-1) && campo.value.length < (25))
	{
		if (campo.value.length == conjunto1 )
		campo.value = campo.value + separacao1;
		else if (campo.value.length == conjunto2)
		campo.value = campo.value + separacao1;		
		else if (campo.value.length == conjunto3)
		campo.value = campo.value + separacao1;
		else if (campo.value.length == conjunto4)
		campo.value = campo.value + separacao2;
	}
	else
		event.returnValue = false;
}
