
		var Disp;//global que controla se o field vai aparecer ou nao  =)
	 
	    	
   		function showF(ac)
		{		
			if(!ac){Disp = '';}else{Disp = 'none'}
			
			var vetForm = document.getElementById('form1');
			
			var nome = vetForm[1].value;
			
			if(nome == ''){alert('Preencha o Nome');return false;}
			
			if(nome.length <= 4){alert('Nome Muito Curto.');return false;}
						
			if(vetForm[2].id == 'txtCpf')
			{
			
				if(nome.match(" ") == null){alert('Nome Simples.\nFavor Insira Um Nome Composto.\n\n Ex: Danilo Lopes');return false;}
			
				if(this.validacpf())
				{		
					this.displ();
				}
				
			}
			else if(this.validacnpj())
			{
				this.displ();
			}
			
		}// fim showF()
		
		function displ()
		{
			var vetForm = document.getElementById('form1');
			
			vetForm[1].disabled = "disabled";
			vetForm[2].disabled = "disabled";
					
			document.getElementById('pBtn').style.display='none';
		
			document.getElementById('sprytextfield9').style.display = Disp;
			document.getElementById('sprytextfield10').style.display = Disp;
			document.getElementById('sprytextfield4').style.display = Disp;
			document.getElementById('sprytextfield5').style.display = Disp;
			document.getElementById('sprytextfield6').style.display = Disp;
			document.getElementById('sprytextfield8').style.display = Disp;
			document.getElementById('sprytextfield11').style.display = Disp;
			document.getElementById('sprytextfield13').style.display = Disp;
			document.getElementById('sp6').style.display = Disp;
			document.getElementById('sprytextfield7').style.display = Disp
			document.getElementById('sparea1').style.display = Disp;
			document.getElementById('btnCadastrar').style.display = Disp;
			document.getElementById('divAtualiza').style.display = Disp;
			
			if(control == 1){
				document.getElementById('sprytextfield14').style.display = Disp;
			}else{
				document.getElementById('sp72').style.display = Disp;
			}
			
			Disp = '';	
			
			
		}
		
		function validacpf()
		{
			var i;
			 
			s = document.form1.txtCpf.value;
			
			var erro = "Preencha corretamente o CPF! \n\nCPF INVALIDO.";
			
			if(isNaN(s))
			{
				alert(erro)
				return false;
			}
			
			var c = s.substr(0,9);
			 
			var dv = s.substr(9,2);
			 
			var d1 = 0;
			 
			for (i = 0; i < 9; i++)
			 
			{
			 
			d1 += c.charAt(i)*(10-i);
			 
			}
			 
			if (d1 == 0){
			 
			alert(erro)
			
			return false;
			 
			}
			 
			d1 = 11 - (d1 % 11);
			 
			if (d1 > 9) d1 = 0;
			 
			if (dv.charAt(0) != d1)
			 
			{
			 
			alert(erro)
			
			return false;
			 
			}
			 
			 
			d1 *= 2;
			 
			for (i = 0; i < 9; i++)
			 
			{
			 
			d1 += c.charAt(i)*(11-i);
			 
			}
			 
			d1 = 11 - (d1 % 11);
			 
			if (d1 > 9) d1 = 0;
			 
			if (dv.charAt(1) != d1)
			 
			{
			 
			alert("CPF Invalido")
			
			return false;
			 
			}
			 
			return true;
		 
		}
		
		function validacnpj()
		{
			CNPJ = document.form1.txtCnpj.value;
    	    erro = new String;
			
            if (CNPJ.length < 14) erro += "Preencha corretamente o CNPJ! \n\n";
			
            /*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! \n\n";
            }*/
                //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 += "Digite CNPJ apenas com os numeros! \n\n";
            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 +="Digito verificador com problema!";
             }
             if (erro.length > 0)
			 {
                 alert(erro);
                  return false;
             }
			 /*else
			 {
                  alert("CNPJ valido!");
             }*/
             return true;
			 
       }// fim validacnpj
	   
	   
	   function alteraNome()
	   {
	   		Disp = 'none';
			this.displ();
			
			document.getElementById('pBtn').style.display=Disp;
			
			var vetForm = document.getElementById('form1');
		
			vetForm[1].disabled = "";
			vetForm[2].disabled = "";
			
			vetForm[1].focus;
	   }
