function ValidarCodigo()
{	

		if(document.Validar.validacaoCodigo.value == "")
		{
			document.getElementById('validarcodigo').innerHTML='<font color=red >Codigo de segurança:</font>';
			alert('Entre com o codigo de segurança');
			document.Validar.validacaoCodigo.focus();
			return false;
		}
}



function ValidaSenha()
{	

	if(document.Cadastro.tipoPessoa[0].checked)
	{
		if(document.Cadastro.usuarioCpf.value == "")
		{
			document.getElementById('tipo').innerHTML='<font color=red >CPF:</font>';
			alert('Digite seu CPF');
			document.Cadastro.usuarioCpf.focus();
			return false;
		}
	}
	else
	{
		if(document.Cadastro.usuarioCnpj.value == "")
		{
			document.getElementById('tipo').innerHTML='<font color=red >CNPJ:</font>';
			alert('Digite seu CNPJ');
			document.Cadastro.usuarioCnpj.focus();
			return false;
		}
		
	}
	
	
	if(document.Cadastro.usuarioEmail.value == "")
	{
		document.getElementById('email2').innerHTML='<font color=red >E-mail:</font>';
		alert('Digite E-mail');
		document.Cadastro.usuarioEmail.focus();
		return false;
	}	
	else
	{
		
		if(!valida_EMAIL(document.Cadastro.usuarioEmail.value))
		{
			document.getElementById('email2').innerHTML='<font color=red >E-mail:</font>';
			alert('Digite E-mail Válido');
			document.Cadastro.usuarioEmail.focus();
			return false;	
		}
		
	
	
	}
}


function Valida()
{	

	if(document.Cadastro.tipoPessoa[0].checked)
	{
		/*if(document.Cadastro.usuarioCpf.value == "")
		{
			document.getElementById('tipo').innerHTML='<font color=red >CPF:</font>';
			alert('Digite seu CPF');
			document.Cadastro.usuarioCpf.focus();
			return false;
		}
		
		else*/ if(document.Cadastro.usuarioNome.value == "")
		{
		document.getElementById('tipo2').innerHTML='<font color=red >Nome:</font>';
		alert('Digite campo nome de usuário');
		document.Cadastro.usuarioNome.focus();
		return false;
		}
	
		

	}
	
	else
	{
		/*if(document.Cadastro.usuarioCnpj.value == "")
		{
			document.getElementById('tipo').innerHTML='<font color=red >CNPJ:</font>';
			alert('Digite seu CNPJ');
			document.Cadastro.usuarioCnpj.focus();
			return false;
		}
		
		else*/ if(document.Cadastro.usuarioRazaoSocial.value == "")
		{
		document.getElementById('tipo2').innerHTML='<font color=red >Razão Social:</font>';
		alert('Digite campo razão social');
		document.Cadastro.usuarioRazaoSocial.focus();
		return false;
		}
		
	}
	
	
		
	
	if(document.Cadastro.usuarioEmail.value == "")
	{
		document.getElementById('email2').innerHTML='<font color=red >E-mail:</font>';
		alert('Digite E-mail');
		document.Cadastro.usuarioEmail.focus();
		return false;
	}	
	else
	{
		
		if(!valida_EMAIL(document.Cadastro.usuarioEmail.value))
		{
			document.getElementById('email2').innerHTML='<font color=red >E-mail:</font>';
			alert('Digite E-mail Válido');
			document.Cadastro.usuarioEmail.focus();
			return false;	
		}
		
		var email_ig = document.Cadastro.usuarioEmail.value.indexOf("@ig");
		
		if (email_ig > -1)
		{
			document.getElementById('email2').innerHTML='<font color=red >E-mail:</font>';
			alert('Infelizmente o IG tem bloqueado emails deste guia, favor indicar um outro e-mail para validar o seu cadastro.');
			document.Cadastro.usuarioEmail.value = "";
			document.Cadastro.usuarioEmail.focus();
			return false;	
		}
		
		
	
	
	}
	
	
	if(document.Cadastro.usuarioSenha.value == "")
	{
		document.getElementById('senha2').innerHTML='<font color=red >Senha:</font>';
		alert('Digite Senha');
		document.Cadastro.usuarioSenha.focus();
		return false;
	}	
	
	if(document.Cadastro.usuarioConfirmaSenha.value == "")
	{
		document.getElementById('senhaconfirma').innerHTML='<font color=red >Confirma Senha:</font>';
		alert('Digite a Confirmação da Senha');
		document.Cadastro.usuarioConfirmaSenha.focus();
		return false;
	}	
	
	if(document.Cadastro.usuarioSenha.value != document.Cadastro.usuarioConfirmaSenha.value)
	{
		//document.getElementById('senhaconfirma').innerHTML='<font color=red >Confirma Senha:</font>';
		alert('Senha não confere, digite novamente!');
		document.Cadastro.usuarioConfirmaSenha.focus();
		return false;
	}
	

	
}


function keysAddress ()
{
	var ctrl=window.event.ctrlKey;
	var tecla=window.event.keyCode; 
	
   if ( navigator.appName != "Netscape" ) 
   {
      if ( ( window.event.keyCode >= 48 && window.event.keyCode <= 57 ))
	  {
         window.event.keyCode = window.event.keyCode;
      } 
	  else 
	  {
         window.event.keyCode = "";
      }
   }
}

function valida_EMAIL(campo) {
      var goodEmail = campo.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
      if (goodEmail) {
         return true;
      } else {
         return false;
      }
   }
   


function Confere()
{
// Confere se o CPF dado esta' OK
  if (document.Cadastro.usuarioCpf == "")
  {
    alert("Digite um valor para o campo \"CPF\".");
    document.Cadastro.usuarioCpf.focus();
  }	
   else
    {
	var result = "";
	var OK = false;
	var temp = Limpa(document.Cadastro.usuarioCpf.value);
    if (temp.length>10){
       var work=temp.substring(0,(temp.length)-2)
       var resto = Resto(work);
       OK = (resto==eval(temp.charAt((temp.length)-2)));
       if (OK){
          work=work+resto;
          resto= Resto(work);
          OK = (resto==eval(temp.charAt((temp.length)-1)));
       }
    }
    if (OK){
		result="CPF válido";
		}else{
			result="CPF inválido";
		}    
	if (OK)
		{
			document.getElementById('tipo').innerHTML='CPF:';
		}
		else
		{
		alert (result);
    	document.Cadastro.usuarioCpf.value = "";
		document.getElementById('tipo').innerHTML='<font color=red >CPF:</font>';
		document.Cadastro.usuarioCpf.focus();
		}
   }	
}

function Limpa(S){
//
// Deixa so' os digitos no numero
//
var Digitos = "0123456789";
var temp = "";
var digito = "";
    for (var i=0; i<S.length; i++){
      digito = S.charAt(i);
      if (Digitos.indexOf(digito)>=0){temp=temp+digito}
      }
   	  return temp
	  }
	  
	  
	  function Inverte(S){
//
// Inverte o string S
//
var temp="";
    for (var i=0; i<S.length; i++){
        temp=S.charAt(i)+temp
    }
    return temp
}

function Resto(S){
//
// Retorna o digito verificador (entrar com S "limpo")
//
var invertido = Inverte(Limpa(S));
var soma = 0;
    for (var i=0; i<invertido.length; i++){
        soma=soma+(i+2)*eval(invertido.charAt(i))
    }
    soma*=10;
// document.CPF.cpf.value=""; tirei para passar o cpf
    return ((soma % 11) % 10)
}


	


function validaCNPJ() {
                 CNPJ = document.Cadastro.usuarioCNPJ.value;
                 erro = new String;
                 if (CNPJ.length < 18) erro += "É necessario preencher corretamente o número do CNPJ! "; 
                 if ((CNPJ.charAt(2) != ".") || (CNPJ.charAt(6) != ".") || (CNPJ.charAt(10) != "/") || (CNPJ.charAt(15) != "-")){
                 if (erro.length == 0) erro += "É necessário preencher corretamente o número do CNPJ! ";
                 }
                 //substituir os caracteres que não são números
               if(document.layers && parseInt(navigator.appVersion) == 4){
                       x = CNPJ.substring(0,2);
                       x += CNPJ. substring (3,6);
                       x += CNPJ. substring (7,10);
                       x += CNPJ. substring (11,15);
                       x += CNPJ. substring (16,18);
                       CNPJ = x; 
               } else {
                       CNPJ = CNPJ. replace (".","");
                       CNPJ = CNPJ. replace (".","");
                       CNPJ = CNPJ. replace ("-","");
                       CNPJ = CNPJ. replace ("/","");
               }
               var nonNumbers = /\D/;
               if (nonNumbers.test(CNPJ)) erro += "A verificação de CNPJ suporta apenas números! "; 
               var a = [];
               var b = new Number;
               var c = [6,5,4,3,2,9,8,7,6,5,4,3,2];
               for (i=0; i<12; i++){
                       a[i] = CNPJ.charAt(i);
                       b += a[i] * c[i+1];
 }
               if ((x = b % 11) < 2) { a[12] = 0 } else { a[12] = 11-x }
               b = 0;
               for (y=0; y<13; y++) {
                       b += (a[y] * c[y]); 
               }
               if ((x = b % 11) < 2) { a[13] = 0; } else { a[13] = 11-x; }
               if ((CNPJ.charAt(12) != a[12]) || (CNPJ.charAt(13) != a[13])){
                       erro +="Dígito verificador com problema!";
               }
               if (erro.length > 0){
                      alert(erro);
					  document.Cadastro.usuarioCNPJ.value = "";
					  document.Cadastro.usuarioCNPJ.focus();
				      document.getElementById('tipo').innerHTML='<font color=red >CNPJ:</font>';
                       return false;
               } else {
					   document.Cadastro.usuarioRazaoSocial.focus();
               }
               return true;
       }





function MenuAnuncio(op)
	{
			document.getElementById('menuanuncio').innerHTML='<div style=\'width:145px; height:20px;\' align=\'right\'><div style=\'width:115px; height:20px;\' align=\'left\'><a href=anuncio.php?ir=meusanuncios>Meus An&uacute;ncios</a></div></div><div style=\'width:145px; height:20px;\' align=\'right\'><div style=\'width:115px; height:20px;\' align=\'left\'><a href=anuncio.php?ir=novoanuncio>Novo Anúncio</a></div></div><div style=\'width:145px; height:20px;\' align=\'right\'><div style=\'width:115px; height:20px;\' align=\'left\'><a href=anuncio.php?ir=estatisticas>Estatísticas</a></div></div><div style=\'width:145px; height:20px;\' align=\'right\'><div style=\'width:115px; height:20px;\' align=\'left\'><a href=anuncio.php?ir=fotos>Fotos</a></div></div>';
	
	}
	
	
function VoltaNormal(id,op)
{
	var texto;
	
	if(op == 1)
	texto = "Nova Sub Categoria:";
	if(op == 2)
	texto = "Telefone 2:";
	if(op == 3)
	texto = "Telefone Fax:";
	if(op == 4)
	texto = "Confirma Senha:";
	if(op == 5)
	texto = "Nova Categoria:";
	
	document.getElementById(id).innerHTML=texto;
}

function checkName(nome){
	var nome_u;
	var nome_valido;
	if (nome.value != ''){
	nome_u = nome.value.search(new RegExp("^[a-záéíóúçãõüêîôûÁÉÍÓÚÃÔÊÔÛA-Z0-9]+([ ]+[a-záéíóúçãõüêîôûÁÉÍÓÚÃÔÊÔÛA-Z0-9]+)+"));
		if (nome_u < 0){
		alert("Nome inválido. Altere usando no mínimo um nome e um sobrenome.");
		nome_valido = false;
		document.Cadastro.usuarioNome.focus();
		} else {
		nome_valido = true;
		}
	}
}