
function valida_email(email){
     if (email==''){
	  document.getElementById("email_err").innerHTML= "<div style='float:left; width:495px; margin:0 0 5px 0;'><span style='float:left;'><img src='img/icon_alert.gif' border='0' alt='Alerta!' /></span><span style='float:left; color:#a64249; padding:8px 0 0 5px;'>Atenção! O campo <span style='font-weight:bold; font-style:italic; color:#333;'>E-mail</span> não pode permanecer VAZIO.</span></div>"
	  
	  document.getElementById("EMail").style.backgroundColor="#dfc2c6"
	  document.getElementById("email_err_titulo").style.color="#c20714"
	  document.thisform.nome.focus();
	  return false;  
	}
	if ((email=='')||(email.indexOf("@")==-1)||(email.indexOf(".")==-1)){
		  document.getElementById("email_err").innerHTML= "<div style='float:left; width:495px; margin:0 0 5px 0;'><span style='float:left;'><img src='img/icon_alert.gif' border='0' alt='Alerta!' /></span><span style='float:left; color:#a64249; padding:8px 0 0 5px;'>Atenção! Preencha corretamente o campo <span style='font-weight:bold; font-style:italic; color:#333;'>E-mail</span> para enviar o formulário.</span></div>"		
	  
	  document.getElementById("EMail").style.backgroundColor="#dfc2c6"
	  document.getElementById("email_err_titulo").style.color="#c20714"
	  document.thisform.nome.focus();
	  return false;      
	}
	  document.getElementById("EMail").style.backgroundColor="#fff"
	  document.getElementById("email_err_titulo").style.color="#000"
	  document.getElementById("email_err").innerHTML="<span id='email_err'></span>"
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


function txtBoxFormat(objeto, sMask, evtKeyPress) {
    var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;


if(document.all) { // Internet Explorer
    nTecla = evtKeyPress.keyCode;
} else if(document.layers) { // Nestcape
    nTecla = evtKeyPress.which;
} else {
    nTecla = evtKeyPress.which;
    if (nTecla == 8) {
        return true;
    }
}

    sValue = objeto.value;

    // Limpa todos os caracteres de formatação que
    // já estiverem no campo.
    sValue = sValue.toString().replace( "-", "" );
    sValue = sValue.toString().replace( "-", "" );
    sValue = sValue.toString().replace( ".", "" );
    sValue = sValue.toString().replace( ".", "" );
    sValue = sValue.toString().replace( "/", "" );
    sValue = sValue.toString().replace( "/", "" );
    sValue = sValue.toString().replace( ":", "" );
    sValue = sValue.toString().replace( ":", "" );
    sValue = sValue.toString().replace( "(", "" );
    sValue = sValue.toString().replace( "(", "" );
    sValue = sValue.toString().replace( ")", "" );
    sValue = sValue.toString().replace( ")", "" );
    sValue = sValue.toString().replace( " ", "" );
    sValue = sValue.toString().replace( " ", "" );
    fldLen = sValue.length;
    mskLen = sMask.length;

    i = 0;
    nCount = 0;
    sCod = "";
    mskLen = fldLen;

    while (i <= mskLen) {
      bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/") || (sMask.charAt(i) == ":"))
      bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))

      if (bolMask) {
        sCod += sMask.charAt(i);
        mskLen++; }
      else {
        sCod += sValue.charAt(nCount);
        nCount++;
      }

      i++;
    }

    objeto.value = sCod;

    if (nTecla != 8) { // backspace
      if (sMask.charAt(i-1) == "9") { // apenas números...
        return ((nTecla > 47) && (nTecla < 58)); } 
      else { // qualquer caracter...
        return true;
      } 
    }
    else {
      return true;
    }
  }


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


function valida_nascimento(){
  d=document.thisform;
  erro=0;
  hoje = new Date();
  anoAtual = hoje.getFullYear();
  barras = d.nasce.value.split("/");

	 if (barras.length == 3){
			   dia = barras[0];
			   mes = barras[1];
			   ano = barras[2];
			   resultado = (!isNaN(dia) && (dia > 0) && (dia < 32)) && (!isNaN(mes) && (mes > 0) && (mes < 13)) && (!isNaN(ano) && (ano.length == 4) && (ano <= anoAtual-1 && ano >= 1900));
			   if (!resultado) {
						 document.getElementById("data_err").innerHTML="<label style='color:#993333'>*</label>"
						 d.nasce.focus();
						 return false;
			   }
	 } else {
			   document.getElementById("data_err").innerHTML="<label style='color:#993333'>*</label>"
			   d.nasce.focus();
			   return false;
	}
	document.getElementById("data_err").innerHTML="<span id='email_err'></span>"
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function valida_nome(nome){
     if (nome==''){
	  document.getElementById("nome_err").innerHTML= "<div style='float:left; width:495px; margin:0 0 5px 0;'><span style='float:left;'><img src='img/icon_alert.gif' border='0' alt='Alerta!' /></span><span style='float:left; color:#a64249; padding:8px 0 0 5px;'>Atenção! O campo <span style='font-weight:bold; font-style:italic; color:#333;'>Nome</span> não pode permanecer VAZIO.</span></div>"
	  
	  document.getElementById("Nome").style.backgroundColor="#dfc2c6"
	  document.getElementById("nome_err_titulo").style.color="#c20714"
	  document.thisform.nome.focus();
	  return false;  
	}
	if (!isNaN(nome)) {
		  document.getElementById("nome_err").innerHTML= "<div style='float:left; width:495px; margin:0 0 5px 0;'><span style='float:left;'><img src='img/icon_alert.gif' border='0' alt='Alerta!' /></span><span style='float:left; color:#a64249; padding:8px 0 0 5px;'>Atenção! Preencha corretamente o campo <span style='font-weight:bold; font-style:italic; color:#333;'>Nome</span> para enviar o formulário.</span></div>"		
	  
	  document.getElementById("Nome").style.backgroundColor="#dfc2c6"
	  document.getElementById("nome_err_titulo").style.color="#c20714"
	  document.thisform.nome.focus();
	  return false;      
	}
	
	 document.getElementById("nome_err").innerHTML="<label style='color:#993333'></label>"
	  document.getElementById("nome_err_titulo").style.color="#000"
     document.getElementById("Nome").style.backgroundColor="#fff"
}

function valida_select(selecao){
     if (selecao==''){
	  document.getElementById("select_err").innerHTML= "<div style='float:left; width:495px; margin:0 0 5px 0;'><span style='float:left;'><img src='img/icon_alert.gif' border='0' alt='Alerta!' /></span><span style='float:left; color:#a64249; padding:8px 0 0 5px;'>Atenção! É necessário especificar <span style='font-weight:bold; font-style:italic; color:#333;'>Como nos conheceu</span>...</span></div>"
	  
	  document.getElementById("Conheceu").style.backgroundColor="#dfc2c6"
	  document.getElementById("select_err_titulo").style.color="#c20714"
	  document.thisform.nome.focus();
	  return false;  
	}
	 document.getElementById("select_err").innerHTML="<label style='color:#993333'></label>"
	  document.getElementById("select_err_titulo").style.color="#000"
     document.getElementById("Conheceu").style.backgroundColor="#fff"
}

function valida_comentario(comentario){
     if (comentario==''){
	  document.getElementById("comentario_err").innerHTML= "<div style='float:left; width:495px; margin:0 0 5px 0;'><span style='float:left;'><img src='img/icon_alert.gif' border='0' alt='Alerta!' /></span><span style='float:left; color:#a64249; padding:8px 0 0 5px;'>Atenção! O campo <span style='font-weight:bold; font-style:italic; color:#333;'>Comentário</span> não pode permanecer VAZIO.</span></div>"
	  
	  document.getElementById("Texto").style.backgroundColor="#dfc2c6"
	  document.getElementById("comentario_err_titulo").style.color="#c20714"
	  document.thisform.nome.focus();
	  return false;  
	}
	 document.getElementById("comentario_err").innerHTML="<label style='color:#993333'></label>"
	  document.getElementById("comentario_err_titulo").style.color="#000"
     document.getElementById("Texto").style.backgroundColor="#fff"
}

function valida_login(login){
     if (login==''){
	  document.getElementById("login_err").innerHTML="<label style='color:#993333'>*Preencha</label>"
	  document.thisform.login.focus();
	  return false;
	}
	 document.getElementById("login_err").innerHTML="<label style='color:#993333'></label>"
}
function valida_senha(conf){
    var senha=document.getElementById("senha").value;
	if (senha==''){
	  document.getElementById("senha_err").innerHTML="<label style='color:#993333'>*Preencha</label>"
	  document.thisform.con_senha.focus();
	  return false;
	}
	if (senha!=conf){
	  document.getElementById("senha_err").innerHTML="<label style='color:#993333'>*Senha diferente</label>"
	  document.thisform.con_senha.focus();
	  return false;
	}	
	 document.getElementById("senha_err").innerHTML="<label style='color:#993333'></label>"
}


function valida_contato(contato){
     if ((contato=='')||(!isNaN(contato))){
	  document.getElementById("contato_err").innerHTML="<label style='color:#993333'>*Preencha corretamente </label>"
	  document.thisform.contato.focus();
	  return false;
	}
	 document.getElementById("contato_err").innerHTML="<label style='color:#993333'></label>"
}
function valida_empresa(empresa){
     if (empresa==''){
	  document.getElementById("empresa_err").innerHTML="<label style='color:#993333'>*Preencha corretamente </label>"
	  document.thisform.empresa.focus();
	  return false;
	}
	 document.getElementById("empresa_err").innerHTML="<label style='color:#993333'></label>"
}


function FormataCpf(campo, teclapres)
			{
				var tecla = teclapres.keyCode;
				var vr = new String(campo.value);
				vr = vr.replace(".", "");
				vr = vr.replace("/", "");
				vr = vr.replace("-", "");
				tam = vr.length + 1;
				if (tecla != 14)
				{
					if (tam == 4)
						campo.value = vr.substr(0, 3) + '.';
					if (tam == 7)
						campo.value = vr.substr(0, 3) + '.' + vr.substr(3, 6) + '.';
					if (tam == 11)
						campo.value = vr.substr(0, 3) + '.' + vr.substr(3, 3) + '.' + vr.substr(7, 3) + '-' + vr.substr(11, 2);
				}
			}




function FormataCnpj(campo, teclapres)
			{
				var tecla = teclapres.keyCode;
				var vr = new String(campo.value);
				vr = vr.replace(".", "");
				vr = vr.replace("/", "");
				vr = vr.replace("-", "");
				tam = vr.length + 1;
				if (tecla != 14)
				{
					if (tam == 3)
						campo.value = vr.substr(0, 2) + '.';
					if (tam == 6)
						campo.value = vr.substr(0, 2) + '.' + vr.substr(2, 5) + '.';
					if (tam == 10)
						campo.value = vr.substr(0, 2) + '.' + vr.substr(2, 3) + '.' + vr.substr(6, 3) + '/';
					if (tam == 15)
						campo.value = vr.substr(0, 2) + '.' + vr.substr(2, 3) + '.' + vr.substr(6, 3) + '/' + vr.substr(9, 4) + '-' + vr.substr(13, 2);
				}
			}

		
		
		function valida(){
			
			 tipo=document.MainReg.tipo.value; 
			  if (tipo=='J'){
				             pri = eval("document.MainReg.cnpj.value.substring(0,2)");
							 seg = eval("document.MainReg.cnpj.value.substring(3,6)");
							 ter = eval("document.MainReg.cnpj.value.substring(7,10)");
							 qua = eval("document.MainReg.cnpj.value.substring(11,15)");
							 qui = eval("document.MainReg.cnpj.value.substring(16,18)");
					
							 var i;
							 var numero;
							 var situacao = '';
					
							 numero = (pri+seg+ter+qua+qui);
					
							 s = numero;
					
							 c = s.substr(0,12);
							 var dv = s.substr(12,2);
							 var d1 = 0;
					
							 for (i = 0; i < 12; i++){
								d1 += c.charAt(11-i)*(2+(i % 8));
							 }
					
							 if (d1 == 0){
								var result = "falso";
							 }
								d1 = 11 - (d1 % 11);
					
							 if (d1 > 9) d1 = 0;
					
								if (dv.charAt(0) != d1){
								   var result = "falso";
								}
					
							 d1 *= 2;
							 for (i = 0; i < 12; i++){
								d1 += c.charAt(11-i)*(2+((i+1) % 8));
							 }
					
							 d1 = 11 - (d1 % 11);
							 if (d1 > 9) d1 = 0;
					
								if (dv.charAt(1) != d1){
								   var result = "falso";
								}
					
					
							 if (result == "falso") {
								alert("CNPJ inválido!");
								document.MainReg.cnpj.focus();
								return false;
							 }
 

			  } 
			  if (tipo=='F'){
				      cpf=document.MainReg.cpf.value;
					  
			
			  }
			   
			   nome=document.MainReg.nome_razao.value;
			   if (nome==''){
				   alert('Preencha o Nome/Razão corretamente');
				   document.MainReg.nome_razao.focus();
				   return false;
				   }
			    endereco=document.MainReg.endereco.value;   
				if (endereco==''){
				   alert('Preencha o endereço corretamente');
				   document.MainReg.endereco.focus();
				   return false;
				 }
				telefone=document.MainReg.telefone.value;   
				if (telefone==''){
				   alert('Preencha o telefone corretamente.');
				   document.MainReg.telefone.focus();
				   return false;
				 }
				
				email=document.MainReg.email.value;    
			    if ((email=='')||(email.indexOf("@")==-1)||(email.indexOf(".")==-1)){
				   alert('Preencha o e-mail corretamente.');
				   document.MainReg.email.focus();
				   return false;
				 }

				 senha=document.MainReg.senha.value;   
				if (senha==''){
				   alert('Preencha a senha corretamente');
				   document.MainReg.senha.focus();
				   return false;
				 }
				 conf_senha=document.MainReg.conf_senha.value;   
				if (conf_senha==''){
				   alert('Preencha a confirmação senha corretamente');
				   document.MainReg.conf_senha.focus();
				   return false;
				 }
				 if (senha!=conf_senha){
					   alert('A senha e a confirmação senha não estão iguais');
					   document.MainReg.conf_senha.focus();
					   return false;
					 }
				document.MainReg.submit();	 
			   
			}
	
	
	
	
		function valida_alt(){
		
			   
			   nome=document.MainReg.nome_razao.value;
			   if (nome==''){
				   alert('Preencha o Nome/Razão corretamente');
				   document.MainReg.nome_razao.focus();
				   return false;
				   }
			    endereco=document.MainReg.endereco.value;   
				if (endereco==''){
				   alert('Preencha o endereço corretamente');
				   document.MainReg.endereco.focus();
				   return false;
				 }
				telefone=document.MainReg.telefone.value;   
				if (telefone==''){
				   alert('Preencha o telefone corretamente.');
				   document.MainReg.telefone.focus();
				   return false;
				 }
				
				email=document.MainReg.email.value;    
			    if ((email=='')||(email.indexOf("@")==-1)||(email.indexOf(".")==-1)){
				   alert('Preencha o e-mail corretamente.');
				   document.MainReg.email.focus();
				   return false;
				 }

				 senha=document.MainReg.senha.value;   
				 conf_senha=document.MainReg.conf_senha.value;   

				 if (senha!=conf_senha){
					   alert('A senha e a confirmação senha não estão iguais');
					   document.MainReg.conf_senha.focus();
					   return false;
					 }
				document.MainReg.submit();	 
			   
			}
		
