function soEspacos(str) {

	var qtd_espaco = 0

	for (i = 0; i <= str.length; i++) {

		if (str.charCodeAt(i) == 32)
			qtd_espaco++
	
	}

	if (qtd_espaco == str.length)
		return true
	else
		return false

}



function valida_cnpj(cnpj)     {
      var numeros, digitos, soma, i, resultado, pos, tamanho, digitos_iguais;
      digitos_iguais = 1;
      if (cnpj.length < 14 && cnpj.length < 15)
            return false;
      for (i = 0; i < cnpj.length - 1; i++)
            if (cnpj.charAt(i) != cnpj.charAt(i + 1))
                  {
                  digitos_iguais = 0;
                  break;
                  }
      if (!digitos_iguais)
            {
            tamanho = cnpj.length - 2
            numeros = cnpj.substring(0,tamanho);
            digitos = cnpj.substring(tamanho);
            soma = 0;
            pos = tamanho - 7;
            for (i = tamanho; i >= 1; i--)
                  {
                  soma += numeros.charAt(tamanho - i) * pos--;
                  if (pos < 2)
                        pos = 9;
                  }
            resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
            if (resultado != digitos.charAt(0))
                  return false;
            tamanho = tamanho + 1;
            numeros = cnpj.substring(0,tamanho);
            soma = 0;
            pos = tamanho - 7;
            for (i = tamanho; i >= 1; i--)
                  {
                  soma += numeros.charAt(tamanho - i) * pos--;
                  if (pos < 2)
                        pos = 9;
                  }
            resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
            if (resultado != digitos.charAt(1))
                  return false;
            return true;
            }
      else
            return false;
} 


	answer_cpf=0;

	function check_cpf(numcpf)
	{
	     x = 0;
	     soma = 0;
	     dig1 = 0;
	     dig2 = 0;
	     texto = "";
	     numcpf1="";
	
	     len = numcpf.length; x = len -1;
	
	     for (var i=0; i <= len - 3; i++) {
	          y = numcpf.substring(i,i+1);
	          soma = soma + ( y * x);
	          x = x - 1;
	          texto = texto + y;
	     }
	     dig1 = 11 - (soma % 11);
	     if (dig1 == 10) dig1=0 ;
	     if (dig1 == 11) dig1=0 ;
	
	     numcpf1 = numcpf.substring(0,len - 2) + dig1 ;
	     x = 11; soma=0;
	     for (var i=0; i <= len - 2; i++) {
	          soma = soma + (numcpf1.substring(i,i+1) * x);
	          x = x - 1;
	     }
	     dig2= 11 - (soma % 11);
	     if (dig2 == 10) dig2=0;
	     if (dig2 == 11) dig2=0;
	     if ((dig1 + "" + dig2) == numcpf.substring(len,len-2)) {
	          answer_cpf=1;
	     }
	     
	   if (len > 11) answer_cpf = 0
	   if (len < 11 || numcpf == '00000000000' || numcpf == '11111111111' || numcpf == '22222222222' || numcpf == '33333333333' || numcpf == '44444444444' || numcpf == '55555555555' || numcpf == '66666666666' || numcpf == '77777777777' || numcpf == '88888888888' || numcpf == '99999999999' || numcpf == '12345678900' || numcpf == '12345678901'  || numcpf == '12345678902' || numcpf == '12345678903' || numcpf == '12345678904' || numcpf == '12345678905' || numcpf == '12345678906' || numcpf == '12345678907' || numcpf == '12345678908' || numcpf == '12345678909' || numcpf == '01234567890') {answer_cpf = 0 }
  
  		return answer_cpf;
	
	}

