////////////////////////////////////////Valida o cpf 
  function ValidaCPF(CPF)
  {
    dig_1 = 0;
    dig_2 = 0;
    controle_1 = 10;
    controle_2 = 11;
    lsucesso = 1;
    numero = CPF;
    
    numero = replace(numero,".","");

		if (
         numero == "000000000-00" ||
         numero == "111111111-11" ||
         numero == "222222222-22" ||
         numero == "333333333-33" ||
         numero == "444444444-44" ||
         numero == "555555555-55" ||
         numero == "666666666-66" ||
         numero == "777777777-77" ||
         numero == "888888888-88" ||
         numero == "99999999-99" 
        )
    {
      return false;
    }    
    if ((numero.length != 12) || (numero.substring(9, 10) != "-"))
    {
      return false;
    }
    else
    {
      for (i=0 ; i < 9 ; i++)
      {
        dig_1 = dig_1 + parseInt(numero.substring(i, i+1) * controle_1);
        controle_1 = controle_1 - 1;
      }
      resto = dig_1 % 11;
      dig_1 = 11 - resto;
      if ((resto == 0) || (resto == 1))
        dig_1 = 0;
      for ( i=0 ; i < 9 ; i++)
      {
        dig_2 = dig_2 + parseInt(numero.substring(i, i + 1) * controle_2);
        controle_2 = controle_2 - 1;
      }
      dig_2 = dig_2 + 2 * dig_1;
      resto = dig_2 % 11;
      dig_2 = 11 - resto;

      if ((resto == 0) || (resto == 1))
        dig_2 = 0;

      dig_ver = (dig_1 * 10) + dig_2;

      if (dig_ver != parseFloat(numero.substring(numero.length-2,numero.length)))
      {
        return false;
      }
    }
    return true;
  }       
////////////////////////////////////////
  function ValidaCNPJ(NroCNPJ) 
  {

    NroCNPJ = replace(NroCNPJ,"/","");
    NroCNPJ = replace(NroCNPJ,".","");
    NroCNPJ = replace(NroCNPJ,"-","");

    var dig1=0;
    var dig2=0;
    var x;
    var Mult1 = '543298765432';
    var Mult2 = '6543298765432';

    for(x=0; x<=11; x++) 
    {
      dig1 = dig1 +(parseInt(NroCNPJ.slice(x,x+1)) * parseInt(Mult1.slice(x,x+1)) ) ;
    }
    for(x=0; x<=12; x++) 
    {
      dig2 = dig2 + (parseInt(NroCNPJ.slice(x, x+1)) * parseInt(Mult2.slice(x,x+1)) );
    }


    dig1 = (dig1 * 10)%11;
    dig2 = (dig2 * 10)%11;

    if (dig1 == 10) {dig1 = 0;}
    if (dig2 == 10) {dig2 = 0;}

    if (dig1 != parseInt(NroCNPJ.slice(12, 13))) 
    {
      return false;
    } 
    else 
    {
      if (dig2 != parseInt(NroCNPJ.slice(13, 14))) 
      {
        return false;
      } 
      else 
      {
        return true;
      }
    }
  }
////////////////////////////////////////  
  function replace(string,text,by) 
  {
    // Replaces text with by in string
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;

    var i = string.indexOf(text);

    if ((!i) && (text != string.substring(0,txtLength))) return string;
        if (i == -1) return string;

    var newstr = string.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += replace(string.substring(i+txtLength,strLength),text,by);

    return newstr;
  }
////////////////////////////////////////
  function verificaPessoa()
  {     
    document.formulario.operacao.value = "Atualizar";
    document.action = "Loja_Dados.asp";
    document.formulario.submit();
  }
////////////////////////////////////////
	function Mascara(formato, keypress, objeto)
	{
	  campo = eval (objeto);
	  if (keypress == 13)
	  {
	    campo.blur();
	    return;
	  }
	  if (formato=='CPF')
		{
		  caracteres = '01234567890';
  		separacoes = 1;
	  	separacao1 = '-';
		  conjuntos = 2;
  		conjunto1 = 9;
	  	conjunto2 = 2;
		  if ((caracteres.indexOf(String.fromCharCode (keypress)) > -1 && caracteres.search(String.fromCharCode (keypress))!=-1) && campo.value.length < 
  		    (conjunto1 + conjunto2 + 1))
	  	{
		  	if (campo.value.length == conjunto1) 
			    campo.value = campo.value + separacao1;
			}
		  else 
			  event.returnValue = false;
	  }
	  if (formato=='CEP')
		{

		  caracteres = '01234567890';
		  separacoes = 1;
		  separacao1 = '-';
		  conjuntos = 2;
		  conjunto1 = 5;
		  conjunto2 = 3;
		  if ((caracteres.indexOf(String.fromCharCode (keypress)) > -1 && caracteres.search(String.fromCharCode (keypress))!=-1) && campo.value.length < 
		      (conjunto1 + conjunto2 + 1))
			{
			  if (campo.value.length == conjunto1) 
			    campo.value = campo.value + separacao1;
			}
		  else 
			  event.returnValue = false;
		}
    if (formato=='CNPJ')
    {
      caracteres = '01234567890';
      separador1 = '.';
      separador2 = '/';
      separador3 = '-';
      conjunto1 = 2;
      conjunto2 = 6;
      conjunto3 = 10;
      conjunto4 = 15;
      if (caracteres.search(String.fromCharCode (keypress))!=-1 && caracteres.indexOf(String.fromCharCode (keypress)) > -1)
      {
        if (campo.value.length == conjunto1)
        {
          campo.value = campo.value + separador1;
        }
        if (campo.value.length == conjunto2)
        {
           campo.value = campo.value + separador1;
        }
        if (campo.value.length == conjunto3)
        {
          campo.value = campo.value + separador2;
        }
        if (campo.value.length == conjunto4)
        {
          campo.value = campo.value + separador3;
        }
      }
      else
      {
        event.returnValue = false;
      }
    }
	  if (formato=='DDD')
		{
		  caracteres = '01234567890';
		  separacoes = 0;
		  separacao1 = '';
		  conjuntos = 1;
		  conjunto1 = 2;
		  conjunto2 = 0;
		  if ((caracteres.indexOf(String.fromCharCode (keypress)) > -1 && caracteres.search(String.fromCharCode (keypress))!=-1) && campo.value.length < 
		      (conjunto1 + conjunto2 + 0))
			{
			  if (campo.value.length == conjunto1) 
			    campo.value = campo.value + separacao1;
			}
		  else 
			  event.returnValue = false;
		}  
	  if (formato=='FONE')
		{
		  caracteres = '01234567890';
		  separacoes = 0;
		  separacao1 = '';
		  conjuntos = 1;
		  conjunto1 = 8;
		  conjunto2 = 0;
		  if ((caracteres.indexOf(String.fromCharCode (keypress)) > -1 && caracteres.search(String.fromCharCode (keypress))!=-1) && campo.value.length < 
		      (conjunto1 + conjunto2 + 0))
			{
			  if (campo.value.length == conjunto1) 
			    campo.value = campo.value + separacao1;
			}
		  else 
			  event.returnValue = false;
		} 		  
	  if (formato=='RG')
		{
		  caracteres = '01234567890';
		  separacoes = 0;
		  separacao1 = '';
		  conjuntos = 1;
		  conjunto1 = 9;
		  conjunto2 = 0;
		  if ((caracteres.indexOf(String.fromCharCode (keypress)) > -1 && caracteres.search(String.fromCharCode (keypress))!=-1) && campo.value.length < 
		      (conjunto1 + conjunto2 + 0))
			{
			  if (campo.value.length == conjunto1) 
			    campo.value = campo.value + separacao1;
			}
		  else 
			  event.returnValue = false;
		} 
	  if (formato=='CCM')
		{
		  caracteres = '01234567890';
		  separacoes = 0;
		  separacao1 = '';
		  conjuntos = 1;
		  conjunto1 = 18;
		  conjunto2 = 0;
		  if ((caracteres.indexOf(String.fromCharCode (keypress)) > -1 && caracteres.search(String.fromCharCode (keypress))!=-1) && campo.value.length < 
		      (conjunto1 + conjunto2 + 0))
			{
			  if (campo.value.length == conjunto1) 
			    campo.value = campo.value + separacao1;
			}
		  else 
			  event.returnValue = false;
		} 
	  if (formato=='IE')
		{
		  caracteres = '01234567890';
		  separacoes = 0;
		  separacao1 = '';
		  conjuntos = 1;
		  conjunto1 = 18;
		  conjunto2 = 0;
		  if ((caracteres.indexOf(String.fromCharCode (keypress)) > -1 && caracteres.search(String.fromCharCode (keypress))!=-1) && campo.value.length < 
		      (conjunto1 + conjunto2 + 0))
			{
			  if (campo.value.length == conjunto1) 
			    campo.value = campo.value + separacao1;
			}
		  else 
			  event.returnValue = false;
		} 		
	  if (formato=='NUMERO')
		{
		  caracteres = '01234567890';
		  separacoes = 0;
		  separacao1 = '';
		  conjuntos = 1;
		  conjunto1 = 11;
		  conjunto2 = 0;
		  if ((caracteres.indexOf(String.fromCharCode (keypress)) > -1 && caracteres.search(String.fromCharCode (keypress))!=-1) && campo.value.length < 
		      (conjunto1 + conjunto2 + 0))
			{
			  if (campo.value.length == conjunto1) 
			    campo.value = campo.value + separacao1;
			}
		  else 
			  event.returnValue = false;
		} 		
		
  }
  
  VerifiqueTAB=true;
  function Mostra(quem, tammax) 
  {
	  if ( (quem.value.length == tammax) && (VerifiqueTAB) ) 
	  {
  		var i=0,j=0, indice=-1;
	  	for (i=0; i<document.forms.length; i++) 
	  	{
			  for (j=0; j<document.forms[i].elements.length; j++) 
			  {
				  if (document.forms[i].elements[j].name == quem.name) 
				  {
					  indice=i;
					  break;
				  }
			  }
			  if (indice != -1)
		         break;
		  }
		  for (i=0; i<=document.forms[indice].elements.length; i++) 
		  {
			  if (document.forms[indice].elements[i].name == quem.name) 
			  {
				  while ( (document.forms[indice].elements[(i+1)].type == "hidden") &&
						(i < document.forms[indice].elements.length) ) 
					{
							i++;
				  }
				  document.forms[indice].elements[(i+1)].focus();
				  VerifiqueTAB=false;
				  break;
			  }
		  }
	  }
  }
  
  function FormataReais(fld, milSep, decSep, e) 
  {
    var sep = 0;
    var key = '';
    var i = j = 0;
    var len = len2 = 0;
    var strCheck = '0123456789';
    var aux = aux2 = '';
    var whichCode = (window.Event) ? e.which : e.keyCode;
    if (whichCode == 13) 
      return true;
    key = String.fromCharCode(whichCode);  // Valor para o código da Chave
    if (strCheck.indexOf(key) == -1) 
      return false;  // Chave inválida
    len = fld.value.length;
    for(i = 0; i < len; i++)
      if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) 
        break;
    aux = '';
    for(; i < len; i++)
      if (strCheck.indexOf(fld.value.charAt(i))!=-1) 
        aux += fld.value.charAt(i);
    aux += key;
    len = aux.length;
    if (len == 0) 
      fld.value = '';
    if (len == 1) 
      fld.value = '0'+ decSep + '0' + aux;
    if (len == 2) 
      fld.value = '0'+ decSep + aux;
    if (len > 2) 
    {
      aux2 = '';
      for (j = 0, i = len - 3; i >= 0; i--) 
      {
        if (j == 3) 
        {
          aux2 += milSep;
          j = 0;
        }
        aux2 += aux.charAt(i);
        j++;
      }
      fld.value = '';
      len2 = aux2.length;
      for (i = len2 - 1; i >= 0; i--)
        fld.value += aux2.charAt(i);
      fld.value += decSep + aux.substr(len - 2, len);
    }
    return false;
  }  

//<!-- -->

  function PararTAB(quem) 
  { 
    VerifiqueTAB=false; 
  } 

//<!-- -->

  function ChecarTAB() 
  { 
    VerifiqueTAB=true; 
  }