Ir para conteúdo
Fórum Script Brasil
  • 0

Ajuda Com Formulário Juridico


Lothar

Pergunta

Ae Pessoal, estou quebrando a cabeça já tem um certo tempo...

e não consigo implementar um código que verifica o CNPJ

meu .js ta com verificador de cgc_cpf como faço pra alterar ele pra não aceitar o CPF somente o CNPJ

cadastrox.php

<?
include("./cadedo.php");

if ( $empresa )
{
    $body  = "<html>\n";
    $body .= "<body background='http://www.cadedo.com.br/image/back.gif' bgcolor=#C5EFF6>\n";
    $body .= "<table width=80% cellspacing=0 cellpadding=0 align=center border=1 bordercolor=#005DBA>\n";
    $body .= "    <tr>\n";
    $body .= "        <td bgcolor=#005DBA align=center><font color=white size=2><b>SOLICITACAO DE CADASTRO</b></font></td>\n";
    $body .= "    </tr>\n";
    $body .= "    <tr>\n";
    $body .= "        <td>\n";
    $body .= "            <table>\n";
    $body .= "                <tr>\n";
    $body .= "                    <td width=17% valign=top align='right'><font face=verdana color=#005DBA size=2><b>CATEGORIA :   </b></font></td>\n";
    $body .= "                    <td valign=top><font face=verdana color=#005DBA size=2><b>$categoria</b></font></td>\n";
    $body .= "                </tr>\n";
    $body .= "            </table>\n";
    $body .= "        </td>\n";
    $body .= "    </tr>\n";

    $body .= "    <tr>\n";
    $body .= "        <td>\n";
    $body .= "            <table>\n";
    $body .= "                <tr>\n";
    $body .= "                    <td width=17% valign=top align='right'><font face=verdana color=#005DBA size=2><b>Razao Social :  </b></font></td>\n";
    $body .= "                    <td valign=top><font face=verdana color=#005DBA size=2><b>$empresa</b></font></td>\n";
    $body .= "                </tr>\n";
    $body .= "                <tr>\n";
    $body .= "                    <td width=17% valign=top align='right'><font face=verdana color=#005DBA size=2><b>Endereco / N°-Complemento :  </b></font></td>
    \n";
    $body .= "                    <td valign=top><font face=verdana color=#005DBA size=2><b>$endereco / $numero </b></font></td>
    \n";
    $body .= "                </tr>\n";
    $body .= "                <tr>\n";
    $body .= "                    <td width=17% valign=top align='right'><font face=verdana color=#005DBA size=2><b>Bairro :  </b></font></td>\n";
    $body .= "                    <td valign=top><font face=verdana color=#005DBA size=2><b>$bairro</b></font></td>\n";
    $body .= "                </tr>\n";
    $body .= "                <tr>\n";
    $body .= "                    <td width=17% valign=top align='right'><font face=verdana color=#005DBA size=2><b>Cidade/Estado/Cep :  </b></font></td>
    \n";
    $body .= "                    <td valign=top><font face=verdana color=#005DBA size=2><b>$cidade / $estado / $cep1 - $cep2 </b></font></td>
    \n";
    $body .= "                </tr>\n";
    $body .= "                
    <tr>
      <td valign=top align='right'> </td>
      <td valign=top> </td>
      </tr>
    <tr>\n";
    $body .= "                    <td width=17% valign=top align='right'><font face=verdana color=#005DBA size=2><b>Telefone :  </b></font></td>\n";
    $body .= "                    <td valign=top><font face=verdana color=#005DBA size=2><b>($ddd) $telefone</b></font></td>\n";
    $body .= "                </tr>\n";
    $body .= "\n";
    $body .= "                <tr>\n";
    $body .= "                    <td width=17% valign=top align='right'><font face=verdana color=#005DBA size=2><b>CNPJ :  </b></font></td>\n";
    $body .= "                    <td valign=top><font face=verdana color=#005DBA size=2><b>$cgc_cpf</b></font></td>
    \n";
    $body .= "                </tr>\n";
    $body .= "                <tr>\n";
    $body .= "                    <td width=17% valign=top align='right'><font face=verdana color=#005DBA size=2><b>IE :  </b></font></td>\n";
    $body .= "                    <td valign=top><font face=verdana color=#005DBA size=2><b>$ie_rg</b></font></td>\n";
    $body .= "                </tr>\n";
    $body .= "                <tr>\n";
    $body .= "                    <td width=17% valign=top align='right'><font face=verdana color=#005DBA size=2><b>Titular :  </b></font></td>\n";
    $body .= "                    <td valign=top><font face=verdana color=#005DBA size=2><b>$titular</b></font></td>\n";
    $body .= "                </tr>\n";
    $body .= "                <tr>\n";
    $body .= "                    <td width=17% valign=top align='right'><font face=verdana color=#005DBA size=2><b>Comprador :  </b></font></td>\n";
    $body .= "                    <td valign=top><font face=verdana color=#005DBA size=2><b>$comprador</b></font></td>\n";
    $body .= "                </tr>\n";
    $body .= "                <tr>\n";
    $body .= "                    <td width=17% valign=top align='right'><font face=verdana color=#005DBA size=2><b>E-Mail :  </b></font></td>\n";
    $body .= "                    <td valign=top><font face=verdana color=#005DBA size=2><b>$email</b></font></td>\n";
    $body .= "                </tr>\n";
    $body .= "            </table>
    \n";
    $body .= "        </td>\n";
    $body .= "    </tr>\n";

    $body .= "    <tr>\n";
    $body .= "        <td bgcolor='#005DBA' align='center'><font color='white' size=2><b>OBSERVACOES</b></font></td>\n";
    $body .= "    </tr>\n";
    $body .= "    <tr>\n";
    $body .= "        <td>\n";
    $body .= "            <table width=100%>\n";
    $body .= "                <td>\n";
    $body .= "                    <font face=verdana color=#005DBA size=2><b>\n";
    $body .= "                    ".$mensagem;
    $body .= "                    </b></font>\n";
    $body .= "                </td>\n";
    $body .= "            </table>\n";
    $body .= "        </td>\n";
    $body .= "    </tr>\n";

    $body .= "</table>\n";
    $body .= "</body>\n";
    $body .= "</html>\n";

    mail( "cadedo@cadedo.com.br" , "SOLICITACAO DE CADASTRO","$body","From: Site ($email)\nContent-Type: text/html;");
}

?>

<html>

<head>
<meta http-equiv="Pragma" content="no-cache">
<meta name="Ruan A. Cadedo" content="rcadedo@hotmail.com">
<title>Cadedo Peças e Máquinas de Costura Ltda</title>

<link rel=stylesheet type="text/css" href="cadedo.css">
<style type="text/css">
<!--
.style1 {
    color: #990000;
    font-style: italic;
}
a:link {
    color: #990000;
}
a:visited {
    color: #990000;
}
a:hover {
    color: #FF0000;
}
a:active {
    color: #990000;
}
.style3 {
    font-size: 8px;
    font-family: Arial, Helvetica, sans-serif;
}
.style4 {
    color: #FFFFFF;
    font-weight: bold;
}
.style5 {
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: 9px;
}
-->
</style>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head>

&lt;script Language="JavaScript" src="cadedox.js"></script>


<body leftmargin=0 topmargin=0 marginwidth=0 marginheight=0 background="image/back.gif" bgproperties="fixed">

    <table width=1024 cellspacing=0 cellpadding=0 bgcolor="white" border=0 align="center">

        <tr><td><? parte_superior(); ?></td></tr>

        <tr><td><? barra_menu_reduzido("N","S"); ?></td></tr>

        <tr>
          <td align="center"><img src='barras_pa/barra_cadastro.gif' height=30 width=1024 ></td>
      </tr>
        <tr>
          <td><center>
            <table width="100%" border="0">
              <tr>
                <td align="center"> </td>
              </tr>
              <tr>
                <th align="center">Se você revendedor ou confeccionista ainda não é cliente da <span class="style1">Cadedo Peças</span> faça seu cadastro<br>
                e receba gratuitamente catálogos de nossa linha de peças, acessórios e máquinas de costura. </th>
              </tr>
            </table>
          </center>
                   <br><br>

                <?
                if ( $empresa )
                {?>
                    <center><img src="image/emailenviado2.gif"></center>
                    <br><br> 
                <?}
                ?>


                <?
                if ( !$empresa )
                {
                ?>

                     <form method="post" name="cadastro" action="cadastro.php">

                     
        <table width="91%" align="center" cellspacing="0" cellpadding="0">
          <tr> 
            <td width="17%" height=28 align="right"> </td>
            <td width="83%">
          </tr>
          <tr>
            <td height="23" colspan="2" align="center"><table width="620" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#005DBA">
              <tr>
                <td width="560" height="20" align="center" valign="middle" bgcolor="#005DBA"><span class="style4">*Categoria   </span>
                  <select name="categoria" onChange='java script:document.cadastro.categoria.value=document.cadastro.categoria.options[selectedIndex].value'>
                  <option value="Revenda">Revenda                 
                    <option value="Armarinho">Armarinho
                      <option value="Confecção">Confecção 
                  </select></td>
              </tr>
            </table>
              <table width="620" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#EEEEEE">
                <tr>
                  <td height="15" colspan="3" valign="bottom" class="TxSubTilCad">*Razão Social: </td>
                </tr>
                <tr>
                  <td height="15" colspan="3" class="TxSubTilCad"><input type="text" maxlength="60" size="40" name="empresa" value="<? echo $empresa; ?>" /></td>
                </tr>
                <tr>
                  <td width="130" height="20" valign="bottom" class="TxSubTilCad">*CNPJ:</td>
                  <td width="183" valign="bottom" class="TxSubTilCad">*Inscrição Estadual:</td>
                  <td width="307" valign="bottom" class="TxSubTilCad">*Titular da Empresa: </td>
                </tr>
                <tr>
                  <td height="15" class="TxSubTilCad"><p>
                    <input name="cgc_cpf" type="text" class="bginputbox_1" id="cgc_cpf" onKeyPress=SomenteNumeros(this) onKeyUp=FormataValor(this,18,event) value="<? echo $cgc_cpf; ?>" size="20" maxlength="18">
                  </p></td>
                  <td class="TxSubTilCad"><input type="text" maxlength="14" size="14" name="ie_rg" value="<? echo $ie_rg; ?>" /></td>
                  <td class="TxSubTilCad"><input type="text" maxlength="50" size="40" name="titular" value="<? echo $titular; ?>" /></td>
                </tr>
              </table>
              <table width="620" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#EEEEEE">
                <tr>
                  <td width="247" height="20" valign="bottom" class="TxSubTilCad">*Endereço: </td>
                  <td width="214" valign="bottom" class="TxSubTilCad">*Numero/Complemento: </td>
                  <td width="159" valign="bottom" class="TxSubTilCad">*Bairro:</td>
                </tr>
                <tr>
                  <td height="15" class="TxSubTilCad"><input type="text" maxlength="60" size="35" name="endereco" value="<? echo $endereco; ?>" /></td>
                  <td class="TxSubTilCad"><input type="text" maxlength="30" size="25" name="numero" value="<? echo $numero; ?>" />                    <label></label></td>
  
                <td class="TxSubTilCad"><input type="text" maxlength="40" size="20" name="bairro" value="<? echo $bairro; ?>" /></td>
                </tr>
              </table>
              <table width="620" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#EEEEEE">
                <tr>
                  <td width="34%" height="20" valign="bottom" class="TxSubTilCad">*Cidade:</td>
                  <td width="9%" valign="bottom" class="TxSubTilCad">*Estado:</td>
                  <td width="36%" valign="bottom" class="TxSubTilCad">*Cep:</td>
                  <td width="21%" valign="bottom" class="TxSubTilCad">*DDD/Fone:</td>
                </tr>
                <tr>
                  <td height="15" class="TxSubTilCad"><input type="text" maxlength="40" size="30" name="cidade" value="<? echo $cidade; ?>" /></td>
                  <td class="TxSubTilCad"><select name="estado" onchange='java script:document.cadastro.estado.value=document.cadastro.estado.options[selectedIndex].value'>
                      <option value="AC" selected="selected">AC </option>
                      <option value="AL">AL </option>
                      <option value="AM">AM </option>
                      <option value="AP">AP </option>
                      <option value="BA">BA </option>
                      <option value="CE">CE </option>
                      <option value="DF">DF </option>
                      <option value="ES">ES </option>
                      <option value="GO">GO </option>
                      <option value="MA">MA </option>
                      <option value="MG">MG </option>
                      <option value="MS">MS </option>
                      <option value="muito">muito </option>
                      <option value="PA">PA </option>
                      <option value="PB">PB </option>
                      <option value="PE">PE </option>
                      <option value="PI">PI </option>
                      <option value="PR">PR </option>
                      <option value="RJ">RJ </option>
                      <option value="RN">RN </option>
                      <option value="RO">RO </option>
                      <option value="RR">RR </option>
                      <option value="RS">RS </option>
                      <option value="SC">SC </option>
                      <option value="SE">SE </option>
                      <option value="SP">SP </option>
                      <option value="TO">TO </option>
                  </select></td>
                  <td class="TxSubTilCad"><input name="cep1" type="text" id="cep1" value="<? echo $cep1; ?>" size="5" maxlength="5" />
                    -
                    <input name="cep2" type="text" id="cep2" value="<? echo $cep2; ?>" size="3" maxlength="3" /> 
                    <a href="http://www.correios.com.br/servicos/dnec/menuAction.do?Metodo=menuLogradouro" title="Correios - Encontre seu CEP" target="_blank" class="style3 style5">ENCONTRE SEU CEP</a></td>
                  <td class="TxSubTilCad"><input name="ddd" type="text" id="ddd" value="<? echo $ddd; ?>" size="2" maxlength="2" />
                      <input type="text" maxlength="9" size="9" name="telefone" value="<? echo $telefone; ?>" /></td>
                </tr>
              </table>
              <table width="620" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#EEEEEE">
                <tr>
                  <td width="238" height="20">*E-mail:                  </td>
                  <td width="382">*Comprador:                  </td>
                </tr>
                <tr>
                  <td height="20"><input type="text" maxlength="50" size="30" name="email" value="<? echo $email; ?>"></td>
                  <td height="20"><input type="text" maxlength="50" size="40" name="comprador" value="<? echo $comprador; ?>"></td>
                </tr>
                <tr>
                  <td height="20" colspan="2"> </td>
                </tr>
                <tr>
                  <td height="20" colspan="2" align="center" valign="middle" bgcolor="#005DBA"><b><font color="white">Observações</font></b></td>
                </tr>
                <tr>
                  <td height="20" colspan="2" align="center" valign="middle"><div align="center">
              &lt;script language="JavaScript">
                                if ( navigator.appName == "Netscape" )
                                    {
                                      document.write( "<textarea name='mensagem' rows='7' cols='70'></textarea>");
                                    }
                                else
                                    {
                                      document.write( "<textarea name='mensagem' rows='7' cols='70'></textarea>");
                                    }
                                </script>
            </div></td>
                </tr>
              </table></td>
          </tr>
          <tr> 
            <td colspan="2"></td>
          </tr>
          <tr>
            <td colspan="2"></td>
          </tr>
          <tr> 
            <td colspan="2" align="center"><br> <a href='java script:checa_dados()'><img src="image/botao_confirmar.jpg" border=0></a>            </td>
          </tr>
          <tr> 
            <td align="right"> </td>
            <td valign="middle">* Preenchimento obrigatório.<br>  </td>
          </tr>
        </table>
                 </form>

          <?
                }
                ?>            </td>
        </tr>

        <tr><td align='center'> </td>
        </tr>
        <tr><td> </td>
        </tr>
        <tr><td><? rodape(); ?></td></tr>
</table>

    &lt;script language="Javascript">
        <?
        if ( !$empresa ) echo "document.cadastro.empresa.focus();";
        ?>
        
        function checa_dados()
        {
            achou = 0;
            for(x=0; x <= document.cadastro.elements.length-1; x=x+1 )
            {
                if ( document.cadastro.elements[x].value == "" ) 
                { achou = 1; }
            }

            if ( achou == 1 )
            {
                alert("Todos os campos são obrigatórios, favor checar as informações informadas !");
                return;
            }

            cgc_cpf = document.cadastro.cgc_cpf.value;
            //
            //        Checa CGC/CPF
            //
            if ( cgc_cpf.length == 11 )
            {
                if ( checa_cpf( cgc_cpf ) == 0 )
                {
                    document.cadastro.cgc_cpf.focus();
                    return;
                }
            }
            else
            {
                if ( checa_cgc( cgc_cpf ) == 0 )
                {
                    document.cadastro.cgc_cpf.focus();
                    return;
                }
            }
            document.cadastro.submit();
        }

    </script>

</body>
</html>
cadedo.js
Atual     = 0;
    wString = "";
    wColuna = 0;
    wTamanho= 0;

    function foto( wproduto )
        { janela = window.open( "foto.php?item="+wproduto , "newwin" , "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=440,height=320" ) }

    function download( wProduto )
        { janela = window.open( "download.asp?item="+wProduto , "newwin" , "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=450,height=500" ) }

    function exibe_string()
        {

        if ( wString.length == 0 )
            { 
                wString = Mensagens[Atual]; 
                for ( wFor = 1; wFor <= 65; ++wFor )
                 { wString = wString + " "; }
            }

        wSize = wString.length;

        wTamanho   = wTamanho + 1;
        wNewString = "";
        for ( wfor = 1; wfor <= (65-wTamanho); ++wfor )
            { wNewString = wNewString + " "; }
           if (wTamanho >= 65) 
               { wColuna = wColuna + 1; }
           if ( wTamanho >= wSize )
               { wTamanho = wTamanho - 1; }
           wNewString = wNewString + wString.substring( wColuna , wTamanho );
           document.formDisplay.botao.value = wNewString;
           if ( wColuna == wSize-65 )
               {
                wColuna  = 0;
                  wTamanho = 0;
                  Atual     = Atual + 1;
                  wString  = "";
                if ( Atual >= Mensagens.length )
                     { Atual = 0; }
             }

        setTimeout("exibe_string()", 100);
           }

    function change_color( objeto , cor )
        { objeto.bgColor = cor; }

    function change_color_2( objeto , cor1 , cor2 )
        { 
            objeto.fontcolor = cor2;
            objeto.bgColor = cor1; 
        }

    
    
    function checa_cgc(vcgc)
      {

         if ( vcgc.length < 11 ) { alert( "Número do CNPJ inválido !" ); return ( 0 ) }

         d=new Array(12);
         i=0;
         df2=0;
         df3=0;
         resto1=0;
         resto2=0;
         temp=0;
         for( i=0; i < 12; i++ )
            { 
               temp = vcgc.substr(i,1);
               temp = parseInt(temp);
               d[i] = temp;
            }

         df1  = 5 * d [0];
         df1 += 4 * d [1];
         df1 += 3 * d [2];
         df1 += 2 * d [3];
         df1 += 9 * d [4];
         df1 += 8 * d [5];
         df1 += 7 * d [6];
         df1 += 6 * d [7];
         df1 += 5 * d [8];
         df1 += 4 * d [9];
         df1 += 3 * d [10];
         df1 += 2 * d [11];

         df2 = df1 / 11;
         df2 = inteiro( df2 );
         df3 = df2 * 11;
         resto1 = df1 - df3;

         if ( resto1 == 1 || resto1 == 0 ) pridig = 0;
         else                              pridig = 11 - resto1;

        df1  = 6 * d [0];
        df1 += 5 * d [1];
        df1 += 4 * d [2];
        df1 += 3 * d [3];
        df1 += 2 * d [4];
        df1 += 9 * d [5];
        df1 += 8 * d [6];
        df1 += 7 * d [7];
        df1 += 6 * d [8];
        df1 += 5 * d [9];
        df1 += 4 * d [10];
        df1 += 3 * d [11];
        df1 += 2 * pridig;

        df2 = df1 / 11;
        df2 = inteiro( df2 );
        df3 = df2 * 11;
        resto2 = df1 - df3;

        if (resto2 == 0 || resto2 == 1) segdig = 0;
        else                            segdig = 11 - resto2;

        resto1 = parseInt(vcgc.substr(12,1));
        resto2 = parseInt(vcgc.substr(13,1));

        if (pridig == resto1 && segdig == resto2 ) { return (1); }
        else { alert( "O número do CNPJ é inválido"); return (0); }
      }

    function checa_cpf(vcpf)
      {

          if ( vcpf.length < 11 ) { alert( "Número do CNPJ inválido !" ); return ( 0 ) }

         wSx1 = 0;
         wCpfDigit = 0;
         y = 0;
         temp = 0;
         temp2= 0;

         wCpfCalc = vcpf.substr(0,9);
         wSomaCpf = 0;

         for( wsx1 = 1; wsx1 < 10; wsx1++ )
             {
                temp = vcpf.substr(wsx1-1,1);
                temp = parseInt(temp);
                temp = temp * ( 11 - wsx1 );
                wSomaCpf += temp;
             }

         temp = wSomaCpf%11;
         wCpfDigit = 11 - temp;

         if ( wCpfDigit == 10 || wCpfDigit == 11 )
              wCpfCalc += "0";
         else
              wCpfCalc += wCpfDigit;

         wSomaCpf = 0;
         for ( wsx1=1; wsx1 < 11; wsx1++ )
            {
                temp = vcpf.substr(wsx1-1,1);
                temp = parseInt(temp);
                temp = temp * ( 12-wsx1 );
                wSomaCpf += temp;
            }

         temp = wSomaCpf%11;
         wCpfDigit = 11 - temp;

         if ( wCpfDigit == 10 || wCpfDigit == 11 ) 
             wCpfCalc += "0";
         else
             wCpfCalc += wCpfDigit;

         if ( vcpf != wCpfCalc ) { alert("O numero do CNPJ e invalido !"); return (0); }
         else { return ( 1 ); }
      }

    function inteiro( wValor )
        {
           wResult = "";
           wString = ""+wValor;
           for ( wfor = 0; wfor < wString.length; ++wfor )
              {
                  if (wString.substr(wfor,1) == "." )
                     wfor = wString.length + 1;
                  else
                     wResult += wString.substr(wfor,1);
              }
           return parseInt( wResult );
        }

        function envia_pesquisa()
        {
            location = "itens.php?palavra="+document.itens.palavra.value+"&o=P";
        }

    function isValidDate (myDate,sep) 
        {
            if (myDate.length == 10) 
            {
                if (myDate.substring(2,3) == sep && myDate.substring(5,6) == sep)
                {
                    var date  = myDate.substring(0,2);
                    var month = myDate.substring(3,5);
                    var year  = myDate.substring(6,10);

                    var test = new Date(year,month-1,date);

                    ano = test.getYear();
                    ano = ano + 1900;

                    if ( (year == ano ) && (month-1 == test.getMonth()) && (date == test.getDate()))
                    {
                        return true;
                    }
                    else 
                    {
                        alert("Favor informar a data no formato DD/MM/AAAA - 03");
                        return false;
                    }
                }
                else 
                {
                    alert("Favor informar a data no formato DD/MM/AAAA - 02");
                    return false;
                }
            }
            else 
            {
                alert("Favor informar a data no formato DD/MM/AAAA - 01");
                return false;
            }
        }

Link para o comentário
Compartilhar em outros sites

1 resposta a esta questão

Posts Recomendados

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,3k
    • Posts
      652,5k
×
×
  • Criar Novo...