<?php
REQUIRE_ONCE("./global/funcoes_cad_telefones.inc");
$sNomeIdJConsulta = 'iJan_LstCadFor';
$sNomeIdJEdt_Cad = 'iJan_EdtCadFor';
$nTmpFrmEnv = 300;
$bDir_Consult = CondPrivilegio(@$s_DireitosLst, $sNomeAcesso, 'C');
$bDir_Alterar = CondPrivilegio(@$s_DireitosLst, $sNomeAcesso, 'A');
$bDir_Incluir = CondPrivilegio(@$s_DireitosLst, $sNomeAcesso, 'I');
//
$sFor_Codigo = @$_REQUEST['For_Codigo'];
If ( ISSET($_REQUEST['Cad_Codigo']) ) {
   $sFor_Codigo = @$_REQUEST['Cad_Codigo']+0;
}
//
//  ** CADASTRO (NOVO/EDITA) **
If ( $sSubModulo=="EDT" ) {
    // Criar objeto Janela
    $oJanelaPrinc = New R_Janela();
    $oJanelaPrinc->sIdObj  = $sNomeIdJEdt_Cad; 
    $oJanelaPrinc->nTop    = 40;
    $oJanelaPrinc->nLeft   = 25;
    $oJanelaPrinc->nWidth  = 660;   // Largura
    $oJanelaPrinc->nHeight = 0;     // Altura
	$oJanelaPrinc->nLeft  += ($nTela_W/2)-($oJanelaPrinc->nWidth/2);
    $oJanelaPrinc->sTitulo = 'Cadastro do Fornecedor';
	//
	$oJanelaPrinc->sJavKeyDown = "return Car_".$sNomeAcesso."2.Teclas_F(this,event);";
    $sJavaTravarJ = "parent.document.getElementById('".$oJanelaPrinc->sIdObj."_Travar').style.visibility='visible'; parent.Disabled_In_Elems('".$oJanelaPrinc->sIdObj."',true);";
	$oJanelaPrinc->sJavOnClickF =
	      $sJavaTravarJ.
		  "document.forms.fmECadFor.acao.value='FECHAR'; ".
		  "document.forms.fmECadFor.submit();".
		  "";
	//
	$bMontarJanela = true;
	//
	// SALVAR
    If ( $sAcao=="SALVAR" ) {
	   $bGravarReg = False;
	   If ($bDir_Alterar) {
          $bGravarReg = True;
	   } Else {
          $sRet_Javs .=
            Info_Evento('ALERTA: Você não tem previlégio para alterar este fornecedor.').
            "";
	   }
	   //
	   If ($bGravarReg) {
	      If ( STRLEN(@$_REQUEST['For_RazaoS'])<2 ) {
	         $sRet_Javs .= Info_Evento('Alguns campos estão incompletos.');
	         $bGravarReg = False;
	      }
	   }
	   //
	   If ($bGravarReg) {
	      If ( $sFor_Codigo=="NOVO" ) {
	         $nFor_Codigo = SQLVarConfig(STRTOUPPER($sModulo)."_SEQCOD")+0;
	         $Row_CadFor = MYSQL_QUERY("SELECT * FROM cad_fornecedor WHERE FOR_CODIGO=".($nFor_Codigo)." ;") or die(MYSQL_ERROR());
             If ($Row_CadFor = MYSQL_FETCH_ARRAY($Row_CadFor)) {
	            $sRet_Javs .= Info_Evento('Não posso gravar, codigo sequencial já existe ('.Str_Zero($nFor_Codigo,6).') .',1);
				$bGravarReg = False;
			 }
		  }
	   }
	   //
	   If ($bGravarReg) {
	      If ( $sFor_Codigo=="NOVO" ) {
	         $nFor_Codigo = SQLVarConfig(STRTOUPPER($sModulo)."_SEQCOD")+0;
             SQLVarConfigG(STRTOUPPER($sModulo)."_SEQCOD", $nFor_Codigo+1 );
             MYSQL_QUERY(   // Cria um novo registro
               "INSERT INTO cad_fornecedor(FOR_CODIGO,FOR_ATIVO_,FOR_DTACAD) VALUES (".$nFor_Codigo.",1,'".DATE("Y-m-d H:i:s")."'); "
			 ) Or Die(MYSQL_ERROR());
	      } Else {
	         $nFor_Codigo = $sFor_Codigo+0;
	      }
	      $Row_CadFor = MYSQL_QUERY("SELECT * FROM cad_fornecedor WHERE FOR_CODIGO=".($nFor_Codigo)." ;") or die(MYSQL_ERROR());
          If ($Row_CadFor = MYSQL_FETCH_ARRAY($Row_CadFor)) {
             MYSQL_QUERY(   // Cria um novo registro
               "UPDATE cad_fornecedor SET ".
                 'FOR_RAZAOS=' .SQL_Bin(UTF8_DECODE(@$_POST['For_RazaoS'])).','.
				 'FOR_FANTAS=' .SQL_Bin(UTF8_DECODE(@$_POST['For_Fantas'])).','.
                 'FOR_ENDLOG=' .SQL_Bin(UTF8_DECODE(@$_POST['For_EndLog'])).','.
                 'FOR_ENDNUM=' .SQL_Bin(UTF8_DECODE(@$_POST['For_EndNum'])).','.
                 'FOR_ENDCPL=' .SQL_Bin(UTF8_DECODE(@$_POST['For_EndCpl'])).','.
                 'FOR_BAIRRO=' .SQL_Bin(UTF8_DECODE(@$_POST['For_Bairro'])).','.
                 'FOR_C_E_P_="'.Somente_Numeros(@$_POST['For_EndCEP']).'",'.
                 'FOR_CODCID="'.Somente_Numeros(@$_POST['For_CodCid']).'",'.
				 'FOR_CPJCPF="'.Somente_Numeros(@$_POST['For_CPJCPF']).'",'.
				 'FOR_IES_RG="'.Somente_Numeros(@$_POST['For_IES_RG']).'",'.
				 'FOR_CODCUS="'.Somente_Numeros(@$_POST['For_CodCus']).'",'.
				 'FOR_NUMCPF="'.Somente_Numeros(@$_POST['For_NUMCPF']).'",'.
				 'FOR_NUMRG_="'.Somente_Numeros(@$_POST['For_NUMRG_']).'",'.
				 'FOR_CONTAT=' .SQL_Bin(UTF8_DECODE(@$_POST['For_Contat'])).','.
                 'FOR_OBS_01=' .SQL_Bin(UTF8_DECODE(@$_POST['For_Obs_01'])).','.
				 'FOR_E_MAIL=' .SQL_Bin(UTF8_DECODE(@$_POST['For_E_Mail'])).','.
				 'FOR_HOMEPA=' .SQL_Bin(UTF8_DECODE(@$_POST['For_HomePa'])).' '.
               "WHERE FOR_CODIGO=".($nFor_Codigo)."; ") or die(MYSQL_ERROR());
	         // Gravar Telefones
			 If ( ISSET($aSessao['CADTEL_LISTA']) ) {
			    //GravarTelefones(2, $sFor_Codigo+0, $aSessao['CADTEL_LISTA']);
				GravarTelefones(2, $nFor_Codigo, $aSessao['CADTEL_LISTA']);
		     }
			 //
	      } Else {
             // Erro: registro não existe
			 $sRet_Javs .= Info_Evento('Registro não existe.',1);
	      }
          $sRet_Javs .=
		    ( EMPTY($aSessao['CADFOR_IDOBJ']) ? "" :
		      "parent.document.getElementById('".$aSessao['CADFOR_IDOBJ']."').value='".$nFor_Codigo."';"
			).
		    "document.location.href = './car_js.php?mod=".$sModulo."&submod=".$sSubModulo."&acao=FECHAR&nomeacs=".$sNomeAcesso."&acaoAnt=".$sAcao."';".
			"";
       }
	   $bMontarJanela = false;
    //
    // ATUALIZA LISTA DE TELEFONES
    } ElseIf ( $sAcao=="ALT_LSTTEL" ) {
	   $sRet_TelaJ_HTML = '';
	   If ( ISSET($aSessao['CADTEL_LISTA']) ) {
	      $a_ListaTel = $aSessao['CADTEL_LISTA'];
		  $nContar_ = 0;
          ForEach ( $a_ListaTel As $aTel ) {
		     $nContar_++;
			 If ( $nContar_==6 ) { BREAK; }
	         If ( STRLEN($sRet_TelaJ_HTML)>0 ) {
		        $sRet_TelaJ_HTML .= ', ';
		     }
	         $sRet_TelaJ_HTML .= FormataTelefone($aTel['TEL_NUMERO']);
		  }
	   } Else {
	      If (($sFor_Codigo+0)>0 ) {
		  	$sSQLQuery =
	            "SELECT * FROM cad_telefones, cad_tipo_telefone ".
	            "WHERE ".
		  	        "TEL_TIPCAD=2 AND TEL_CODCAD='".($sFor_Codigo+0)."' AND ".
		  	        "(TEL_TRAREG=0 OR TEL_TRAREG=2) AND TEL_CODCTT=CTT_CODIGO ".
		  	    "ORDER BY TEL_NUMERO ASC LIMIT 6;";
	        $RowsT = MYSQL_QUERY($sSQLQuery) Or Die($sSQLQuery.'<br>'.MYSQL_ERROR());
            While ($RowT = MYSQL_FETCH_OBJECT($RowsT)) {
	           If ( STRLEN($sRet_TelaJ_HTML)>0 ) {
		  	      $sRet_TelaJ_HTML .= ', ';
		  	   }
	             $sRet_TelaJ_HTML .= FormataTelefone($RowT->TEL_NUMERO);
	        }
		  }
	   }
       // Java
       $sRet_Javs .=
         "parent.document.getElementById('sp_CadEFor_Telefones').innerHTML = ".JAVA_CharCode_Mini($sRet_TelaJ_HTML).";";
         '';
       $sRet_TelaJ_HTML = '';
	   $bMontarJanela = false;
    //
    // PUXAR CIDADE PELO CODIGO DO IBGE
    } ElseIf ( $sAcao=="PUXAR_CIDADE" ) {
	   $sFor_CodCid = @$_POST['For_CodCid'];
	   // Consulta
	   If ( $sFor_CodCid=='/' ) {
          $sRet_Javs .= 
	           "parent.document.getElementById('sCadEFor_Cidade').innerHTML = '( Consulta )';".
	           "parent.document.getElementById('iCadEFor_CodCid').value = '';".
	           $sJavaTravarJ.
		       "setTimeout( function () { ".
		          "parent.document.forms.fmECadFor.acao.value=''; ".
		          "parent.document.forms.fmECadFor.submod.value='CID'; ".
		          "parent.document.forms.fmECadFor.submit();".
		          "parent.document.forms.fmECadFor.submod.value='".$sSubModulo."'; ".
		       "} , 100);".
		       "";
	   // Exibir nome da cidade
	   } Else {
	      $sNomeCidade = '';
	      $Row = MYSQL_QUERY("SELECT * FROM cad_cidade WHERE CID_CODIGO='".$sFor_CodCid."' ;") or die(MYSQL_ERROR());
          If ($Row = MYSQL_FETCH_OBJECT($Row)) {
		     $sNomeCidade = $Row->CID_NOMECD.' - '.$Row->CID_ESTADO;
		  }
          $sRet_Javs .= 
	           "parent.document.getElementById('sCadEFor_Cidade').innerHTML = '".$sNomeCidade."';".
		       "";
	   }
	   //
	   $bMontarJanela = false;	
	   
	} ElseIf ( $sAcao=="V_CPF_CNPJ" ) {   
       $nP_NumCPF = @$_REQUEST['CPF_'];
	   $nP_NumCNPJ = @$_REQUEST['CNPJ_'];
	   $cpf = @ereg_replace('[^0-9]', '', $nP_NumCPF);
	   $cnpj = @ereg_replace('[^0-9]', '', $nP_NumCNPJ);
	   
	   
	   If (STRLEN($cpf)==11){
	      If (STRLEN($cpf)> 0 && (! validaCPF($nP_NumCPF))) {
             $sRet_Javs .= Info_Evento('CPF Inválido',1);
          }
	   } Else {
	      If (STRLEN($cnpj)> 0 && (! validar_cnpj($nP_NumCNPJ))) {
             $sRet_Javs .= Info_Evento('CNPJ Inválido',1);
          }
	   }
	
	
	$bMontarJanela = false;
	//
    // FECHAR
    } ElseIf ( $sAcao=="FECHAR" ) {
	   //
       $sRet_Javs .= 
	      "parent.RmElem('".$oJanelaPrinc->sIdObj."'); ".
		   "parent.Disabled_In_Elems('".$sNomeIdJConsulta."',false);".
		   "parent.document.getElementById('".$sNomeIdJConsulta."_Travar').style.visibility='hidden';".
	       'parent.document.getElementById("iCadFor_PChave").focus();'.
		   (  @$_REQUEST['acaoAnt']=='SALVAR' ? 
		      ( EMPTY($aSessao['CADFOR_IDOBJ']) ?
		        "parent.Car_".$sNomeAcesso."1.P_Atu();"
			  :
		        "setTimeout( parent.document.getElementById('CadCFor_BT_Fch').onclick , 1);"
			  )
		    : '').
		    "";
	      
	   $bMontarJanela = false;
       //
	   UNSET($aSessao['CADTEL_LISTA']);
	   UNSET($aSessao['CADFOR_IDOBJ']);
	   //
	   
	//
	// NOVO REGISTRO
	} ElseIf ( $sAcao=="NV" ) {
	   $sFor_Codigo = 'NOVO';
	//
	// PUXAR REGISTRO
	} Else {
	   If (STRLEN($sFor_Codigo)==0) {
	      $bMontarJanela = False;
	      $sAcao = 'FECHAR';
          $sRet_Javs .=
		     "parent.document.getElementById('".$sNomeIdJConsulta."_Travar').style.visibility='hidden';".
	         Info_Evento('Selecione um fornecedor na lista.');
	   } Else {
          $Row_CadFor = MYSQL_QUERY("SELECT * FROM cad_fornecedor WHERE FOR_CODIGO=".($sFor_Codigo+0)." ;") or die(MYSQL_ERROR());
          If (! $Row_CadFor = MYSQL_FETCH_ARRAY($Row_CadFor)) {
	         $Row_CadFor = ARRAY();
	      }
	   }
	   //
	}
	If ($bMontarJanela) {
	   $aSessao['CADFOR_IDOBJ'] = @$_REQUEST['IdObj_Rec_For_Codigo'];
	   // Montagem nos itens do cadastro de centro de custo para a combobox
       $sHTML_Combo_CodCUS = '<option value="0">* Centro de custo *</option>';
       $Rows = MYSQL_QUERY("SELECT * FROM cad_centro_custo WHERE CUS_ATIVO_ AND CUS_CREDEB=0 ORDER BY CUS_CODIGO ASC;") or die(MYSQL_ERROR());
       While ($Row = MYSQL_FETCH_OBJECT($Rows)) {
          $sHTML_Combo_CodCUS .=
	         '<option value="'.$Row->CUS_CODIGOI.'" '.($Row->CUS_CODIGOI==@$Row_CadFor['FOR_CODCUS'] ? "selected" : "" ).'>'.
	            ( ( Somente_Numeros(SUBSTR($Row->CUS_CODIGO,4,3))+0==0 ) ? "" : "&nbsp;&nbsp;" ).
	            $Row->CUS_CODIGO.'-'.$Row->CUS_DESCRI.
	         '</option>';
       }
	   //
	   $oJanelaPrinc->aIdsObjList =
	      ARRAY(
		    'iCadEFor_Fantas', 'iCadEFor_RazaoS', 
			'iCadEFor_CPJCPF', 'iCadEFor_IES_RG',
			'iCadEFor_NUMCPF', 'iCadEFor_NUMRG_', //CRIADO DEPOIS CICERO 24/06/2016
			'iCadEFor_EndLog', 'iCadEFor_EndNum', 'iCadEFor_EndCpl',
			'iCadEFor_Bairro', 'iCadEFor_CodCid', 'iCadEFor_EndCEP',
			'iCadEFor_CodCus',
			'iCadEFor_Telef1', 'iCadEFor_Telef2', 'iCadEFor_Contat',
			'iCadEFor_E_Mail', 'iCadEFor_HomePa',
			'iCadEFor_Obs001'
		  );
	   //
	   If ( STRLEN(@$Row_CadFor['FOR_RAZAOS'])>0 ) {
          $sFor_Codigo = Str_Zero($sFor_Codigo, 6);
	   }
	   //
       // Tela HTML
	   //
       $sRet_TelaJ_HTML =
    	  $oJanelaPrinc->MontaJanHTML(True).
          '<form name="fmECadFor2" accept-charset="utf-8" method="post" action="./car_js.php" target="car_'.$sNomeAcesso.'4">'.
           '<input name="mod" type="hidden" value="'.$sModulo.'">'.
           '<input name="submod" type="hidden" value="'.$sSubModulo.'">'.
           '<input name="acao" type="hidden" value="">'.
    	   '<input name="nomeacs" type="hidden" value="'.$sNomeAcesso.'">'.
           '<input name="Tel_Numero" type="hidden" value="">'.
		   '<input name="Tel_TipCtt" type="hidden" value="">'.
		   '<input name="Tel_Observ" type="hidden" value="">'.
		   '<input name="Cad_Codigo" type="hidden" value="'.$sFor_Codigo.'">'.
		  '</form>'.
          '<form name="fmECadFor" accept-charset="utf-8" method="post" action="./car_js.php" target="car_'.$sNomeAcesso.'3">'.
           '<input name="mod" type="hidden" value="'.$sModulo.'">'.
           '<input name="submod" type="hidden" value="'.$sSubModulo.'">'.
           '<input name="acao" type="hidden" value="">'.
    	   '<input name="nomeacs" type="hidden" value="'.$sNomeAcesso.'">'.
		   '<input name="CPF_" type="hidden" value="">'.
		   '<input name="CNPJ_" type="hidden" value="">'.
		  '<table width="100%"><tr>'.
       	   '<td width="70px" height="24px" align="right">'.
		    'Código:'.
		   '</td>'.
       	   '<td align="left" width="90px">'.
			'<input id="iCadEFor_Codigo" name="For_Codigo" type="text" value="'.$sFor_Codigo.'" readonly="readonly" style="width:60px; height:22px; background:#FFFBEC; border-width: 1px; border-style: solid; border-color:#0099FF;">'.
       	   '</td>'.
       	   '<td align="right">'.
		    'Nome fantasia:'.
			'<input id="iCadEFor_Fantas" name="For_Fantas" type="text" value="'.@$Row_CadFor['FOR_FANTAS'].'" maxlength="60" style="width:80%; height:22px; background:#FFFBEC; border-width:1px; border-style:solid; border-color:#0099FF;">'.
       	   '</td>'.
       	   '<td width="4px">&nbsp;</td>'.
       	  '</tr></table>'.
       	  '<table width="100%"><tr>'.
       	   '<td width="70px" height="24px" align="right">'.
		    'Razão Social:'.
       	   '</td>'.
       	   '<td align="left" width="400px">'.
			'<input id="iCadEFor_RazaoS" name="For_RazaoS" type="text" value="'.@$Row_CadFor['FOR_RAZAOS'].'" maxlength="60" style="width:80%; height:22px; background:#FFFBEC; border-width:1px; border-style:solid; border-color:#0099FF;">'.
       	   '</td>'.
       	   '<td align="right">'.
		    ( ConvertDataSTR(@$Row_CadFor['FOR_DTACAD'])>0 ?
		      'Data do cadastro: <span style="font-weight:bold;">'.ConvertDataUSBR(@$Row_CadFor['FOR_DTACAD']).'</span>' : ''
			).
       	   '</td>'.
       	   '<td width="4px">&nbsp;</td>'.
       	  '</tr></table>'.
		  //
       	  '<table width="100%">'.
		     '<tr>'.
       	        '<td width="70px" height="24px" align="right">'.
		           'CNPJ:'.
       	        '</td>'.
       	        '<td align="left" width="160px">'.
			    /*   ( STRLEN(@$Row_CadFor['FOR_CPJCPF'])==11 ?
			          '<input id="iCadEFor_CPJCPF" class="For_CPJCPF" name="For_CPJCPF" type="text" value="'.@$Row_CadFor['FOR_CPJCPF'].'" OnBlur=parent.Car_'.$sNomeAcesso.'2.Valida_Cpf_Cnpj() maxlength="20" style="width:80%; height:22px; background:#FFFBEC; border-width:1px; border-style:solid; border-color:#0099FF;">'
       	           :
			          ( STRLEN(@$Row_CadFor['FOR_CPJCPF'])>11 ?
				        '<input id="iCadEFor_CPJCPF" class="For_CPJCPF_" name="For_CPJCPF" type="text" value="'.@$Row_CadFor['FOR_CPJCPF'].'" OnBlur=parent.Car_'.$sNomeAcesso.'2.Valida_Cpf_Cnpj() maxlength="20" style="width:80%; height:22px; background:#FFFBEC; border-width:1px; border-style:solid; border-color:#0099FF;">'
			          :
				        '<input id="iCadEFor_CPJCPF" class="For_CPJCPF_N" name="For_CPJCPF" type="text" value="'.@$Row_CadFor['FOR_CPJCPF'].'" OnBlur=parent.Car_'.$sNomeAcesso.'2.mascara(this.value)  maxlength="20" style="width:80%; height:22px; background:#FFFBEC; border-width:1px; border-style:solid; border-color:#0099FF;">'
				      )
			  
			       ).*/
				  '<input id="iCadEFor_CPJCPF" class="For_CPJCPF_" name="For_CPJCPF" type="text" value="'.@$Row_CadFor['FOR_CPJCPF'].'" OnBlur=parent.Car_'.$sNomeAcesso.'2.Valida_Cpf_Cnpj() maxlength="20" style="width:80%; height:22px; background:#FFFBEC; border-width:1px; border-style:solid; border-color:#0099FF;">'.
		   '</td>'.
       	   '<td width="90px" height="24px" align="right">'.
		      'IES:'.
       	   '</td>'.
       	   '<td align="left" width="160px">'.
			  '<input id="iCadEFor_IES_RG" name="For_IES_RG" type="text" value="'.@$Row_CadFor['FOR_IES_RG'].'" maxlength="15" style="width:80%; height:22px; background:#FFFBEC; border-width:1px; border-style:solid; border-color:#0099FF;">'.
       	   '</td>'.
       	   '<td align="right">'.
       	   '</td>'.
       	   '<td width="4px">&nbsp;</td>'.
       	  '</tr>'.
		  
		  '<tr>'.
		     '<td width="70px" height="24px" align="right">'.
		        'CPF:'.
       	     '</td>'.
       	     '<td align="left" width="160px">'.
		        '<input id="iCadEFor_NUMCPF" class="For_NUMCPF" name="For_NUMCPF" type="text" value="'.@$Row_CadFor['FOR_NUMCPF'].'" OnBlur=parent.Car_'.$sNomeAcesso.'2.Valida_Cpf_Cnpj() maxlength="11" style="width:80%; height:22px; background:#FFFBEC; border-width:1px; border-style:solid; border-color:#0099FF;">'.
       	     '</td>'.
		     '<td width="90px" height="24px" align="right">'.
		      'RG.:'.
       	   '</td>'.
       	   '<td align="left" width="160px">'.
			  '<input id="iCadEFor_NUMRG_" name="For_NUMRG_" type="text" value="'.@$Row_CadFor['FOR_NUMRG_'].'" maxlength="15" style="width:80%; height:22px; background:#FFFBEC; border-width:1px; border-style:solid; border-color:#0099FF;">'.
       	   '</td>'.
			 
			 
			 '<td align="right">'.
       	     '</td>'.
       	     '<td width="4px">&nbsp;</td>'.
		  '</tr>'.
		  
		  
		  '</table>'.
		  //
       	  '<table width="100%"><tr>'.
       	   '<td width="70px" height="24px" align="right">'.
		    'Logradouro:'.
       	   '</td>'.
       	   '<td align="left" width="210px">'.
			'<input id="iCadEFor_EndLog" name="For_EndLog" type="text" value="'.@$Row_CadFor['FOR_ENDLOG'].'" maxlength="50" style="width:200px; height:22px; background:#FFFBEC; border-width: 1px; border-style:solid; border-color:#0099FF;">'.
       	   '</td>'.
       	   '<td align="right" width="36px">'.
		    'Número:'.
       	   '</td>'.
       	   '<td align="left" width="50px">'.
			'<input id="iCadEFor_EndNum" name="For_EndNum" type="text" value="'.@$Row_CadFor['FOR_ENDNUM'].'" maxlength="10" style="width:44px; height:22px; background:#FFFBEC; border-width: 1px; border-style:solid; border-color:#0099FF;">'.
       	   '</td>'.
       	   '<td align="right" width="30px">'.
		    'Comp:'.
       	   '</td>'.
       	   '<td align="left">'.
			'<input id="iCadEFor_EndCpl" name="For_EndCpl" type="text" value="'.@$Row_CadFor['FOR_ENDCPL'].'" maxlength="15" style="width:110px; height:22px; background:#FFFBEC; border-width: 1px; border-style:solid; border-color:#0099FF;">'.
       	   '</td>'.
       	  '</tr></table>'.
		  //
       	  '<table width="100%"><tr>'.
       	   '<td width="70px" height="24px" align="right">'.
		    'Bairro:'.
       	   '</td>'.
       	   '<td align="left" width="211px">'.
			'<input id="iCadEFor_Bairro" name="For_Bairro" type="text" value="'.@$Row_CadFor['FOR_BAIRRO'].'" maxlength="30" style="width:95%; height:22px; background:#FFFBEC; border-width: 1px; border-style:solid; border-color:#0099FF;">'.
       	   '</td>'.
       	   '<td align="right">'.
       	   '</td>'.
		   '<td width="4px">&nbsp;</td>'.
       	  '</tr></table>'.
		  //
       	  '<table width="100%"><tr>'.
       	   '<td width="70px" height="24px" align="right">'.
		    'Cidade:'.
       	   '</td>'.
       	   '<td align="left" width="65px" valign="middle">'.
			'<input id="iCadEFor_CodCid" name="For_CodCid" type="text" value="'.@$Row_CadFor['FOR_CODCID'].'" maxlength="7" style="width:95%; height:22px; background:#FFFBEC; border-width: 1px; border-style: solid; border-color: #0099FF;" onchange="parent.Car_'.$sNomeAcesso.'2.Puxar_Cidade();">'.
       	   '</td>'.
       	   '<td align="left" id="sCadEFor_Cidade" style="font-size:12px;">'.
		    '(Aguarde...)'.
       	   '</td>'.
       	   '<td width="65px" height="24px" align="right">'.
		    'CEP:'.
       	   '</td>'.
       	   '<td align="right" width="70px" valign="middle">'.
			'<input id="iCadEFor_EndCEP" name="For_EndCEP" type="text" value="'.@$Row_CadFor['FOR_C_E_P_'].'" maxlength="8" style="width:95%; height:22px; background:#FFFBEC; border-width: 1px; border-style: solid; border-color: #0099FF;">'.
       	   '</td>'.
		   '<td width="4px">&nbsp;</td>'.
       	  '</tr></table>'.
		  '<div style="width:100%; height:1px; background-color:#91D8F8;"></div>'.
		  // Centro de custo padrão
       	  '<table width="100%"><tr>'.
       	   '<td width="100px" height="24px" align="right">'.
		    'Centro de Custo:'.
       	   '</td>'.
       	   '<td align="left" width="350px" valign="middle">'.
		    '<select id="iCadEFor_CodCus" name="For_CodCus" style="width:100%;">'.
			  $sHTML_Combo_CodCUS.
		    '</select>'.
       	   '</td>'.
		   '<td>'.
       	   '</td>'.
       	  '</tr></table>'.
		  // Lista de telefones
		  '<div style="width:100%; height:1px; background-color:#91D8F8;"></div>'.
       	  '<table width="100%"><tr>'.
		   '<td height="40px" width="4px">&nbsp;</td>'.
       	   '<td width="140px" align="left" valign="middle">'.
       	    HTML_Botao( 3, 'CadEFor_BT_Tel', //$sJavaTravarJ.
			                                 "sAntMod = document.forms.fmECadFor2.submod.value;".
			                                 "document.forms.fmECadFor2.submod.value = 'CAD_TELEFONES';".
			                                 "document.forms.fmECadFor2.acao.value=''; ".
    	                                     "document.forms.fmECadFor2.submit();".
			                                 "document.forms.fmECadFor2.acao.value=''; ".
											 "document.forms.fmECadFor2.submod.value = sAntMod;".
											 ""
			             , 'Telefones (F3)','./images/btimg_telefone.png',120).
       	   '</td>'.
       	   '<td align="left" valign="middle">'.
		    '<span id="sp_CadEFor_Telefones"></span>'.
       	   '</td>'.
       	   '<td height="24px" align="center">'.
		   '<td width="4px">&nbsp;</td>'.
       	  '</tr></table>'.
		  //
		  '<div style="width:100%; height:1px; background-color:#91D8F8;"></div>'.
		  //
       	  '<table width="100%"><tr>'.
       	   '<td width="70px" height="24px" align="right">'.
		    'E-Mail:'.
       	   '</td>'.
       	   '<td width="229px" align="left">'.
			'<input id="iCadEFor_E_Mail" name="For_E_Mail" type="text" value="'.@$Row_CadFor['FOR_E_MAIL'].'" maxlength="60" style="width:100%; height:22px; background:#FFFBEC; border-width:1px; border-style:solid; border-color:#0099FF;">'.
       	   '</td>'.
       	   '<td width="70px" height="24px" align="right">'.
		    'Home Page:'.
       	   '</td>'.
       	   '<td align="right">'.
			'<input id="iCadEFor_HomePa" name="For_HomePa" type="text" value="'.@$Row_CadFor['FOR_HOMEPA'].'" maxlength="60" style="width:100%; height:22px; background:#FFFBEC; border-width:1px; border-style:solid; border-color:#0099FF;">'.
       	   '</td>'.
		   '<td width="4px">&nbsp;</td>'.
       	  '</tr></table>'.
		  '<table width="100%" border="0"><tr>'.
		   '<td width="375px" height="24px" align="right">'.
		      'Contato:'.
       	   '</td>'.
       	   '<td align="left" >'.
			  '<input id="iCadEFor_Contat" name="For_Contat" type="text" value="'.@$Row_CadFor['FOR_CONTAT'].'" maxlength="30" style="width:100%; height:22px; background:#FFFBEC; border-width:1px; border-style:solid; border-color:#0099FF;">'.
       	   '</td>'.
		   
		   '<td width="4px">&nbsp;</td>'.
       	  '</tr></table>'.
		  //
       	  '<table width="100%"></tr>'.
		   '<td width="4px" height="24px">&nbsp;</td>'.
       	   '<td align="left">'.
		    'Observações:'.
			'<textarea id="iCadEFor_Obs001" name="For_Obs_01" style="width:100%; height:60px; background:#FFFBEC; border-width:1px; border-style:solid; border-color:#0099FF;">'.
			 @$Row_CadFor['FOR_OBS_01'].
			'</textarea>'.
       	   '</td>'.
		   '<td width="4px">&nbsp;</td>'.
       	  '</tr></table>'.
		  //
          '</form>'.
       	  '<table width="100%"></tr>'.
       	   '<td width="4px" height="40px" align="left">&nbsp;</td>'.
       	   '</td>'.
       	   '<td>'.
       	    HTML_Botao( 3, 'CadEFor_BT_Svl', "document.forms.fmECadFor.acao.value='SALVAR'; ".
    	                                     "document.forms.fmECadFor.submit();"
			             , 'Salvar (F10)','images/btimg_salvar.png').'&nbsp;&nbsp;'.
       	   '</td>'.
       	   '<td width="114px" align="left">'.
       	    HTML_Botao( 3, 'CadEFor_BT_Fec', $oJanelaPrinc->sJavOnClickF
                         , 'Sair (ESC)' ,'images/btimg_fechar.png').
       	   '</td>'.
       	  '</tr></table>'.
    	  $oJanelaPrinc->MontaJanHTML(False);
       //
       $sRet_JavsPos .=
    	  'parent.document.getElementById("iCadEFor_Fantas").focus();'.
		  ($bDir_Alterar ? '' :
		    "parent.document.getElementById('CadEFor_BT_Svl').style.display='none';"
		  ).
		  'parent.$(document).ready(function(){'.
	         'parent.$("input.For_NUMCPF").mask("999.999.999-99");'.
			 'parent.$("input.For_CPJCPF_").mask("99.999.999/9999-99");'.
          '});'.
		  //
		  "function Puxar_Cidade() {".
		      "parent.document.forms.fmECadFor.acao.value='PUXAR_CIDADE'; ".
		      "parent.document.forms.fmECadFor.submit();".
		  "}".
		  //
		  "function AtualizarTels() {".
	          "parent.document.forms.fmECadFor2.acao.value='ALT_LSTTEL';".
	          "parent.document.forms.fmECadFor2.submit();".
		  "}".
		  //
		  "AtualizarTels();".
		  "function Valida_Cpf_Cnpj() {".
		     "var _fm = parent.document.forms.fmECadFor;".
            "_fm.acao.value='V_CPF_CNPJ';".
            "_fm.CPF_.value=parent.document.getElementById('iCadEFor_NUMCPF').value;".
			"_fm.CNPJ_.value=parent.document.getElementById('iCadEFor_CPJCPF').value;".
            "_fm.submit();".
		  '}'.
		  "Valida_Cpf_Cnpj();".
          "Puxar_Cidade();".		  
		  //
		  //"function mascara(doc) {".
		  //   "doc = doc.replace('.', '');".
          //   "doc = doc.replace('-', '');".
          //   "doc = doc.replace('/', '');".
		  //  "if (doc.length>11){".
		//	  'parent.$(document).ready(function(){'.
	     //        'parent.$("input.For_CPJCPF_N").mask("99.999.999/9999-99");'.
	//		  '});'.
		//	"} else if(doc.length==11) {".
		//	  'parent.$(document).ready(function(){'.
		//	     'parent.$("input.For_CPJCPF_N").mask("999.999.999-99");'.
		//	  '});'.
			
		//	"}".			
		//	"Valida_Cpf_Cnpj();".
		 // "}".		  
		  //
		  "function Teclas_F( Objeto, Evento ) {".
             "vNumTecla = parent.Tecla_Apertada(Evento);".
             "if ( vNumTecla==121) { ".        //  ** [F10] **         // (Gravar)
			     "if ( parent.document.getElementById('CadEFor_BT_Svl').style.display != 'none' ) {".
                     "setTimeout( parent.document.getElementById('CadEFor_BT_Svl').onclick , 100);".
				 "}".
		     "} else if ( vNumTecla==116) { ".  // ** [F5] **         Não atualizar
                 //
		     "} else if ( vNumTecla==114) { ".  // ** [F3] **         Telefones
			     "if ( parent.document.getElementById('CadEFor_BT_Tel').style.display != 'none' ) {".
                     "setTimeout( parent.document.getElementById('CadEFor_BT_Tel').onclick , 100);".
				 "}".
		     "} else if ( vNumTecla==27) { ".   // ** [ESC] **         // (SAIR)
                 "setTimeout( parent.document.getElementById('CadEFor_BT_Fec').onclick , 100);".
		     "} else if ( vNumTecla==13) { ".   // ** [ENTER] **
				 "sTempId = parent.Proximo_TabObj(parent.document.getElementById('".$oJanelaPrinc->sIdObj."'),parent.sIdHasFocus);".
				 "if ( sTempId.length>0 ) {".
				     "parent.document.getElementById(sTempId).focus();".
				 "} else {".
    	             'parent.document.getElementById("iCadEFor_NomeCP").focus();'.
				 "}".
			     //
			 "} else {".
			     "return true;".
			 "}".
			 "return false;".
		  '}'.
		  //
    	 "";
       //
	}
//
//  ** CADASTRO DE TELEFONES **
} ElseIf ( $sSubModulo=="CAD_TELEFONES" ) {
   $n_TipCad = 2;
 	  
   $sNomeIdJ_Ant = $sNomeIdJEdt_Cad;
   $sNomeIdCampo = "iCadEFor_E_Mail";
   $sJavaExePos  = "parent.Car_".$sNomeAcesso."2.AtualizarTels();";
 
   REQUIRE "./modulos/cad_telefones.inc";
   
//
//  ** CONSULTA AO CADASTRO DE CIDADES **
} ElseIf ( $sSubModulo=="CID" ) {
   $sNomeIdJ_Ant = $sNomeIdJEdt_Cad;
   $sNomeIdCampo = "iCadEFor_CodCid";
   $sJavaExePos  = "parent.Car_".$sNomeAcesso."2.Puxar_Cidade();";
   REQUIRE "./modulos/consulta_cidade.inc";
//
//  ** CONSULTA **
} Else {
    // Criar objeto Janela
    $oJanelaPrinc = New R_Janela();
    $oJanelaPrinc->sIdObj  = $sNomeIdJConsulta; 
    $oJanelaPrinc->nTop    = 5;
    $oJanelaPrinc->nLeft   = 20;
    $oJanelaPrinc->nWidth  = 700;   // Largura
    $oJanelaPrinc->nHeight = 0;     // Altura
  	$oJanelaPrinc->nLeft  += ($nTela_W/2)-($oJanelaPrinc->nWidth/2);
    $oJanelaPrinc->sTitulo = 'Fornecedores';
	//$oJanelaPrinc->sJavOnClick = "document.getElementById('iCadFor_PChave').focus();";
	$oJanelaPrinc->sJavKeyDown = "return Car_".$sNomeAcesso."1.Teclas_F(this,event);";
    //
	$sJavaTravarJ = "document.getElementById('".$oJanelaPrinc->sIdObj."_Travar').style.visibility='visible'; parent.Disabled_In_Elems('".$oJanelaPrinc->sIdObj."',true);";
	$oJanelaPrinc->sJavOnClickF = 
	    $sJavaTravarJ.
		"document.forms.fmPCadFor.acao.value='FECHAR'; ".
		"document.forms.fmPCadFor.submod.value=''; ".
		"document.forms.fmPCadFor.For_PChave.value=''; ".
		"document.forms.fmPCadFor.For_NumCam.value=''; ".
		"document.forms.fmPCadFor.submit();".
		"";
	//
	//
    // Criar objeto GRID
    $oTabelaRegs = New Pad_GridPesq();
    $oTabelaRegs->sNomeTabela  = 'cad_fornecedor';
    $oTabelaRegs->sIdObjTabela = 'iQdr_ListaFor';
    $oTabelaRegs->GLstCampos( 'FOR_CODIGO,Código,75px,STRZERO=8;'.
	                           'FOR_FANTAS,Nome fantasia;'.
    			              //'FOR_FONE01,Telefone 1,85px,TEL;'.
    			              //'FOR_FONE02,Telefone 2,85px,TEL;'.
	                          'FOR_CONTAT,Contato;' );
    $oTabelaRegs->sCampoIndice = 'FOR_CODIGO';
    $oTabelaRegs->nWidth  = $oJanelaPrinc->nWidth;
    $oTabelaRegs->nHeight = 340;    // Altura
    $oTabelaRegs->sCampoOnClick  = "Car_".$sNomeAcesso."1.P_Sel(<NUMCAM>); Car_".$sNomeAcesso."1.P_Atu();";
    $oTabelaRegs->sLinhaOnClick  = "Car_".$sNomeAcesso."1.PRow_Sel(<QTDCOL>,<SELLIN>);";
    $oTabelaRegs->sLinhaOnDblClk = $sJavaTravarJ.
	                               "Car_".$sNomeAcesso."1.Pesq_Editar();";
    $oTabelaRegs->sJavSelectReg = "sSelIndice = S_Indice;".
	                              "if (parseInt(sSelIndice)>0) {".
								      "if (parent.document.forms.fmPCadFor.For_Ativos.value=='0') {".
									      ($bDir_Alterar ?
				                             "parent.document.getElementById('CadCFor_BT_Itv').style.display='inline-block';"
										  : '').
				                          "parent.document.getElementById('CadCFor_BT_Atv').style.display='none';".
									  "} else if (parent.document.forms.fmPCadFor.For_Ativos.value=='1') {".
									  //"} else {".
				                          "parent.document.getElementById('CadCFor_BT_Itv').style.display='none';".
									      ($bDir_Alterar ?
                                             "parent.document.getElementById('CadCFor_BT_Atv').style.display='inline-block';"
										  : '').
								       "}".
		                               "parent.document.getElementById('CadCFor_BT_Edt').style.display='inline-block';".
								   "} ".
	                              'parent.document.getElementById("iCadFor_PChave").focus();';
    //
    // MONTAR LISTA DE CADASTROS
    If ( $sAcao=="LISTAR" ) {
	   If ($bDir_Consult) {
          $sP_PChave = @$_REQUEST['For_PChave'];
          $nP_NumCam = @$_REQUEST['For_NumCam']+0;
	      //$bP_Ativos = (@$_REQUEST['For_Ativos']+0)>0;
          $nP_Ativos  = @$_REQUEST['For_Ativos']+0; 
		  $nIniReg = 0;
          $nQtdReg = 10000;
          // Montar condição para a pesquisa
		  $sParamSQL = '';
		  $sWhereSQL = '';
		  If ($nP_Ativos == 0) { // ativos
		     $sWhereSQL =' FOR_ATIVO_ ';
		  } ElseIf ($nP_Ativos == 1) { //inativos
		     $sWhereSQL =' FOR_ATIVO_=0 ';
		  } 
		  
	      //$sWhereSQL = 'FOR_ATIVO_='.($bP_Ativos+0).' ';
          If ( $nP_NumCam==0 ) { $nP_NumCam=2; }
    	  $aLstCampo = EXPLODE(',',@$oTabelaRegs->aLstCampos[$nP_NumCam-1]);
   	      If ( STRLEN(@$aLstCampo[0])>0 ) {
             If ( STRLEN($sP_PChave)>0 ) {
			    If (STRLEN($sWhereSQL)>0) { $sWhereSQL .= ' AND ';}
    	        //$sWhereSQL .= 'AND '.$aLstCampo[0].' LIKE "%'.$sP_PChave.'%" ';
				$sWhereSQL .= '('.$aLstCampo[0].' LIKE "%'.$sP_PChave.'%" ';
    	     }
			 $sParamSQL .= ' ORDER BY '.$aLstCampo[0].' ASC ';
          }
		  //
		  If ( STRLEN($sP_PChave)>0 ) {
		     If (STRLEN($sWhereSQL)>0) { $sWhereSQL .= ' OR ';} 
		     $sWhereSQL .= 'FOR_RAZAOS LIKE "%'.$sP_PChave.'%" )';
		  }
		  
		   
		  If (STRLEN($sWhereSQL)>0) { $sWhereSQL = ' WHERE '.$sWhereSQL; }
          //die($sWhereSQL.$sParamSQL.'LIMIT '.$nIniReg.','.$nQtdReg);
		  
		  $oTabelaRegs->sBDParametros = $sWhereSQL.$sParamSQL.'LIMIT '.$nIniReg.','.$nQtdReg;
          // Tabela
          $sRet_TelaJ_HTML = $oTabelaRegs->MontaTabelaHTML();
          // Java
          $sRet_Javs .=
             "var iQdr_ListaFor = parent.document.getElementById('".$oTabelaRegs->sIdObjTabela."');".
    	     'iQdr_ListaFor.innerHTML = '.JAVA_CharCode($sRet_TelaJ_HTML).';'.
    	     '';
          // Java posterior
          $sRet_JavsPos .=
             'parent.Car_'.$sNomeAcesso.'1.'.$oTabelaRegs->sNomeTabela.'_Rowsel = 1;'.
             'parent.Car_'.$sNomeAcesso.'1.P_Sel('.$nP_NumCam.');'.
    	     '';
          $sRet_TelaJ_HTML = '';
	   }
    //
    // FECHAR
    } ElseIf ( $sAcao=="FECHAR" ) {
       $sRet_Javs .=
		  'parent.document.getElementById("dv_MenuL_Barra").style.visibility="visible";'.
	      "parent.RmElem('".$oJanelaPrinc->sIdObj."');";
		  
    //
    // ATIVAR REGISTRO
    } ElseIf ( $sAcao=="ATIVAR" ) {
	   $sRet_Javs .=
	      'parent.JanEspera(false);'.
		  '';
	   If ($bDir_Alterar) {
	      If ((@$_REQUEST['For_Codigo']+0)>0) {
             MYSQL_QUERY("UPDATE cad_fornecedor SET FOR_ATIVO_=1 WHERE FOR_CODIGO=".(@$_REQUEST['For_Codigo']+0)." ;") or die(MYSQL_ERROR());
	         $sRet_Javs .=
		        'parent.Car_'.$sNomeAcesso.'1.PRow_Sel('.($oTabelaRegs->nQtdCampos-1).',1);'.
		   	    'parent.Car_'.$sNomeAcesso.'1.P_Atu();';
	      }
	   } Else {
	      $sRet_Javs .= Info_Evento('ALERTA: Sem previlégio de alteração para ativar.');
	   }
    //
    // INATIVAR REGISTRO
    } ElseIf ( $sAcao=="INATIVAR" ) {
	   $sRet_Javs .=
	      'parent.JanEspera(false);'.
		  '';
	   If ($bDir_Alterar) {
	      If ((@$_REQUEST['For_Codigo']+0)>0) {
             MYSQL_QUERY("UPDATE cad_fornecedor SET FOR_ATIVO_=0 WHERE FOR_CODIGO=".(@$_REQUEST['For_Codigo']+0)." ;") or die(MYSQL_ERROR());
	         $sRet_Javs .= 
		        'parent.Car_'.$sNomeAcesso.'1.PRow_Sel('.($oTabelaRegs->nQtdCampos-1).',1);'.
		        'parent.Car_'.$sNomeAcesso.'1.P_Atu();'.
                '';
	      }
	   } Else {
	      $sRet_Javs .= Info_Evento('ALERTA: Sem previlégio de alteração para inativar.');
	   }
    //
    // JANELA TELA PRINCIPAL
    } Else {
	   //
	   $sJavClkAtiv =
          "JanEspera(true, 'Ativando registro... Aguarde...');".
          "setTimeout( function() { ".
             "document.forms.fmPCadFor.acao.value='ATIVAR'; ".
			 "document.forms.fmPCadFor.submod.value=''; ".
             "document.forms.fmPCadFor.For_Codigo.value=Car_".$sNomeAcesso."1.sSelIndice;".
    	     "document.forms.fmPCadFor.submit();".
          "}, ".$nTmpFrmEnv.");".
		  "";
	   //
	   // Confirma a inativação do registro
	   $sJavClkInat =
		  JAVA_CharCode(
		     "if (_NUM_BOT_==1) { ".
                 "JanEspera(true, 'Inativando registro... Aguarde...');".
                 "setTimeout( function() { ".
                    "document.forms.fmPCadFor.acao.value='INATIVAR'; ".
                    "document.forms.fmPCadFor.submod.value=''; ".
                    "document.forms.fmPCadFor.For_Codigo.value=Car_".$sNomeAcesso."1.sSelIndice;".
                    "document.forms.fmPCadFor.submit();".
                 "}, ".$nTmpFrmEnv.");".
		  	 "}"
		   );
	   $sJavClkInat =
		  "sIdHasFocus='iCadFor_PChave';".
	      "Qdr_Prompt_H(true,'Tem certeza que deseja INATIVAR este fornecedor?',".$sJavClkInat.",['Sim','Não']); ";
	   //
	   
	   //$oJanelaPrinc->aIdsObjList = ARRAY( 'iCadFor_PChave', 'sl_CadFor_Ativos' );
	   
       // Tela HTML
       $sRet_TelaJ_HTML =
    	  $oJanelaPrinc->MontaJanHTML(True).
          '<form name="fmPCadFor" accept-charset="utf-8" method="post" action="./car_js.php" target="car_'.$sNomeAcesso.'2">'.
             '<input name="mod" type="hidden" value="'.$sModulo.'">'.
             '<input name="submod" type="hidden" value="">'.
             '<input name="acao" type="hidden" value="">'.
    	     '<input name="nomeacs" type="hidden" value="'.$sNomeAcesso.'">'.
    	     '<input name="For_PChave" type="hidden" value="">'.
             '<input name="For_Ativos" type="hidden" value="0">'.
    	     '<input name="For_NumCam" type="hidden" value="">'.
    	     '<input name="For_Codigo" type="hidden" value="">'.
          '</form>'.
		  '<table width="100%">'.
		    '</tr>'.
       	       '<td width="4px" height="10px" align="left">'.
			      '&nbsp;'.
			   '</td>'.
			   '<td align="left" width="70px" style="font-size:14px;">'.
       	          'Procurar por: '.
       	       '</td>'.
       	       '<td align="left" style="font-size:14px;">'.
		          'Mostrar'.
			   '</td>'.
       	    '</tr>'.
			'<tr>'.
			   '<td width="4px" height="10px" align="left">'.
				  '&nbsp;'.
			   '</td>'.
			   '<td align="left" width="300px">'.
       	          '<input id="iCadFor_PChave" type="text" maxlength="30" style="width:98%; height:24px; background:#FFFBEC; border-width: 1px; border-style: solid; border-color: #0099FF;">'.
       	       '</td>'.
       	       '<td align="left">'.
			       '<select id="sl_CadFor_Ativos" onchange="Car_'.$sNomeAcesso.'1.P_Atu();" style="font-size:14px;border-width: 1px; border-style: solid; border-color: #0099FF;margin-top:-1px;height:20px;">'.			
				      '<option value="0">Ativos&nbsp;&nbsp;&nbsp;</option>'.
				      '<option value="1">Inativos&nbsp;&nbsp;&nbsp;</option>'.
					  '<option value="2">Todos&nbsp;&nbsp;&nbsp;</option>'.				  
			       '</select>'.	
				'</td>'.
				
			   
			   '<td align="right" width="70px">'.
       	          HTML_Botao( 3, 'CadFor_BT_Pro', 'Car_'.$sNomeAcesso.'1.P_Atu();'
		                       , 'Procurar'     ,'images/btimg_lupa.png').
       	       '</td>'.
		    '</tr>'.
		  '</table>'.
		  //'<table width="100%"></tr>'.
       	  // '<td width="4px" height="10px" align="left">&nbsp;</td>'.
       	  // '<td align="left" width="70px">'.
       	  //  'Procurar por: '.
       	  // '</td>'.
       	  // '<td align="left" width="300px">'.
       	  //  '<input id="iCadFor_PChave" type="text" maxlength="30" style="width:98%; height:24px; background:#FFFBEC; border-width: 1px; border-style: solid; border-color: #0099FF;">'.
       	  // '</td>'.
       	  // '<td align="center">'.
		  //  '<span onclick="Car_'.$sNomeAcesso.'1.P_Ativos();" style="cursor:pointer; font-weight:bold; font-size:13px; text-decoration:underline;">'.
		  //  'Mostrar somente os <span id="PCadFor_Ativos">inativos</span>'.
		  //	'</span>'.
       	  // '</td>'.
       	  // '<td align="right" width="70px">'.
       	  // HTML_Botao( 3, 'CadFor_BT_Pro', 'Car_'.$sNomeAcesso.'1.P_Atu();'
		  //              , 'Procurar'     ,'images/btimg_lupa.png').
       	  // '</td>'.
       	  //'</tr></table>'.
    	  $oTabelaRegs->MontaDivHtml().
       	  '<table width="100%"></tr>'.
       	   '<td width="4px" height="40px" align="left">&nbsp;</td>'.
       	   '</td>'.
       	   '<td>'.
       	    HTML_Botao( 3, 'CadCFor_BT_Nov', $sJavaTravarJ.
			                                 "document.forms.fmPCadFor.acao.value='NV'; ".
			                                 "document.forms.fmPCadFor.submod.value='EDT'; ".
    	                                     "document.forms.fmPCadFor.submit();"
			             , 'Novo (F6)'   ,'images/btimg_novo.png').'&nbsp;&nbsp;'.
       	    HTML_Botao( 3, 'CadCFor_BT_Edt', $sJavaTravarJ.
			                                 "Car_".$sNomeAcesso."1.Pesq_Editar();"
			             , ($bDir_Alterar ? 'Editar' : 'Visualizar').' (F7)' ,'images/btimg_editar.png',130).'&nbsp;&nbsp;'.
       	    HTML_Botao( 3, 'CadCFor_BT_Itv', $sJavClkInat
			             , 'Inativar (F8)','images/btimg_remover.png',110).
       	    HTML_Botao( 3, 'CadCFor_BT_Atv', $sJavClkAtiv
			             , 'Ativar (F8)','images/btimg_ativar.png').'&nbsp;&nbsp;'.
       	   '</td>'.
       	   '<td width="120px" align="left">'.
       	    HTML_Botao( 3, 'CadCFor_BT_Fch', $oJanelaPrinc->sJavOnClickF
                         , 'Sair (ESC)' ,'images/btimg_fechar.png').
       	   '</td>'.
       	  '</tr></table>'.
    	  $oJanelaPrinc->MontaJanHTML(False);
       //
       $sRet_Javs .=
		  'parent.document.getElementById("dv_MenuL_Barra").style.visibility="hidden";'.
	      "var sSelIndice='';".
          "function P_Atu() {".
		    "sSelIndice='0';".
		    $oTabelaRegs->MontaJavaAgu().
		    "parent.document.getElementById('CadCFor_BT_Edt').style.display='none';".
		    "parent.document.getElementById('CadCFor_BT_Itv').style.display='none';".
		    "parent.document.getElementById('CadCFor_BT_Atv').style.display='none';".
         	"parent.document.forms.fmPCadFor.acao.value='LISTAR'; ".
            "parent.document.forms.fmPCadFor.submod.value=''; ".
         	"parent.document.forms.fmPCadFor.For_PChave.value=parent.document.getElementById('iCadFor_PChave').value; ".
         	"parent.document.forms.fmPCadFor.For_Ativos.value=parent.document.getElementById('sl_CadFor_Ativos').value;".
			"parent.document.forms.fmPCadFor.For_NumCam.value=nPesq_CampoSel+''; ".
         	"setTimeout( function() { parent.document.forms.fmPCadFor.submit(); }, 100);".
          '}'.
		  'function Pesq_Editar() {'.
            "parent.document.forms.fmPCadFor.acao.value='';".
            "parent.document.forms.fmPCadFor.submod.value='EDT';".
            "parent.document.forms.fmPCadFor.For_Codigo.value=sSelIndice;".
            "parent.document.forms.fmPCadFor.submit();".
		  '}'.
		  "var bExbAtivos=true;".
		  //'function P_Ativos() {'.
		  //  "var obj = parent.document.getElementById('PCadFor_Ativos');".
			//"if (bExbAtivos) {".
             //   "parent.document.forms.fmPCadFor.For_Ativos.value='0'; ".
			 //   "obj.innerHTML = 'ativos';".
			//	"bExbAtivos = false;".
			//"} else {".
            //    "parent.document.forms.fmPCadFor.For_Ativos.value='1'; ".
			//    "obj.innerHTML = 'inativos';".
			//	"bExbAtivos = true;".
			//"}".
			//"P_Atu();".
		  //'}'.
          $oTabelaRegs->MontaJavaPri();
          '';
       // Java posterior
       $sRet_JavsPos .=
		  "parent.document.getElementById('CadCFor_BT_Atv').style.display='none';".
          ($bDir_Incluir ? '' :
		     "parent.document.getElementById('CadCFor_BT_Nov').style.display='none';"
		  ).
		  ($bDir_Consult ?
		    "P_Atu();"
		  :
		    Info_Evento('ALERTA: Sem previlégio para consulta neste modulo.').
         	"parent.document.forms.fmPCadFor.acao.value='FECHAR'; ".
            "parent.document.forms.fmPCadFor.submod.value=''; ".
         	"parent.document.forms.fmPCadFor.submit();"
		  ).
    	  'parent.document.getElementById("iCadFor_PChave").focus();'.
		  //
		  "function Teclas_F( Objeto, Evento ) {".
             "vNumTecla = parent.Tecla_Apertada(Evento);".
             "if ( vNumTecla==117) { ".        //  ** [F6] **          // (Novo)
                 "if ( parent.document.getElementById('CadCFor_BT_Nov').style.display != 'none') {".
                     "setTimeout( parent.document.getElementById('CadCFor_BT_Nov').onclick , 100);".
				 "}".
		     "} else if ( vNumTecla==116) { ".  // ** [F5] **         Não atualizar
                 //
		     "} else if ( vNumTecla==118) { ". //  ** [F7] **          // (Editar)
                 "if ( parent.document.getElementById('CadCFor_BT_Edt').style.display != 'none') {".
                      "setTimeout( parent.document.getElementById('CadCFor_BT_Edt').onclick , 100);".
				 "}".
		     "} else if ( vNumTecla==119) { ". //  ** [F8] **          // (Inativar)
                 "if ( parent.document.getElementById('CadCFor_BT_Itv').style.display != 'none') {".
                      "setTimeout( parent.document.getElementById('CadCFor_BT_Itv').onclick , 100);".
					                                                   // (Ativar)
                 "} else if ( parent.document.getElementById('CadCFor_BT_Atv').style.display != 'none') {".
                      "setTimeout( parent.document.getElementById('CadCFor_BT_Atv').onclick , 100);".
				 "}".
		     "} else if ( vNumTecla==27) { ".  //  ** [ESC] **         // (SAIR)
                  "setTimeout( parent.document.getElementById('CadCFor_BT_Fch').onclick , 100);".
			 "} else {".
		          "P_TeclasPress_fm(Evento);".
			      "return true;".
			 "}".
			 "return false;".
		  '}'.
		  //
    	  "";
    }
}
?>