<?php

//$aQuadrosAds['CADFOR'] = 10; 

//If ( EMPTY($sSubModulo) ) {
    // Criar objeto Janela
	$oJanelaPrinc = New R_Janela();
	$oJanelaPrinc->sIdObj  = "iJan_LstCadFor"; 
	$oJanelaPrinc->nTop    = 5;
	$oJanelaPrinc->nLeft   = 20;
	$oJanelaPrinc->nWidth  = 600;   // Largura
    $oJanelaPrinc->nHeight = 0;     // Altura
	$oJanelaPrinc->nLeft  += ($nTela_W/2)-($oJanelaPrinc->nWidth/2);
	$oJanelaPrinc->sTitulo = 'Fornecedor';
	$oJanelaPrinc->sJavKeyDown = "return Car_".$sNomeAcesso.$nQdrNomeAcs.".Teclas_F(this,event);";
	//
	$sJavaTravarJ = "parent.document.getElementById('".$oJanelaPrinc->sIdObj."_Travar').style.visibility='visible'; parent.Disabled_In_Elems('".$oJanelaPrinc->sIdObj."',true);";
    $oJanelaPrinc->sJavOnClickF = 
	    $sJavaTravarJ.
		"parent.document.forms.fmPCadFor.acao.value='FECHAR'; ".
		"parent.document.forms.fmPCadFor.For_PChave.value=''; ".
		"parent.document.forms.fmPCadFor.For_NumCam.value=''; ".
		"parent.document.forms.fmPCadFor.submit();".
	"";
    //
	//
	// Criar objeto GRID
	$oTabelaRegs = New Pad_GridPesq();
	$oTabelaRegs->sNomeTabela  = 'cad_fornecedor';
	$oTabelaRegs->sIdObjTabela = 'iQdr_ListaFor';
    $oTabelaRegs->GLstCampos( 'FOR_CODIGO,Codigo,46px,STRZERO=4;'.
	                          'FOR_FANTAS,Fantasia;'.
							  'FOR_CPJCPF,CNPJ ou CPF,130px,PFJ;'
							 );
	$oTabelaRegs->sCampoIndice = 'FOR_CODIGO';
	$oTabelaRegs->nWidth  = $oJanelaPrinc->nWidth;
    $oTabelaRegs->nHeight = 350;    // Altura
	$oTabelaRegs->sCampoOnClick  = "Car_".$sNomeAcesso.$nQdrNomeAcs.".P_Sel(<NUMCAM>); Car_".$sNomeAcesso.$nQdrNomeAcs.".P_Atu();";
	$oTabelaRegs->sLinhaOnClick  = "Car_".$sNomeAcesso.$nQdrNomeAcs.".PRow_Sel(<QTDCOL>,<SELLIN>);";
	$oTabelaRegs->sLinhaOnDblClk = "Car_".$sNomeAcesso.$nQdrNomeAcs.".Pesq_Seleciona();";
	$oTabelaRegs->sJavSelectReg = "sSelIndiceC = S_Indice;".
		                          "if (parseInt(sSelIndiceC)>0) {".
		                              "parent.document.getElementById('CadCFor_BT_Sel').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;
		  $nTip_Busca = @$_REQUEST['Tip_Busca'];
		  // quando digitar exe: /joao na tela de consulta cliente 
		  If ( ISSET($aSessao['Pesq_Chave']) ){
	         $sP_PChave = $aSessao['Pesq_Chave'];
             UNSET($aSessao['Pesq_Chave']);
	      }
		  // Montar condição para a pesquisa
	      $sWhereSQL = '';
		  $sOrderSQL = '';
	      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 ($nTip_Busca == 1) {
				   $sWhereSQL .= 'AND '.$aLstCampo[0].' LIKE "'.$sP_PChave.'%" ';
    			}
				If ($nTip_Busca == 2) {
				   $sWhereSQL .= 'AND '.$aLstCampo[0].' LIKE "%'.$sP_PChave.'%" ';
				}				
		        
				If (STRLEN($sWhereSQL)>0) { $sWhereSQL .= ' OR ';} 
    		    $sWhereSQL .= ' FOR_RAZAOS LIKE "%'.$sP_PChave.'%" ';
	         }
			 $sOrderSQL = 'ORDER BY '.$aLstCampo[0].' ASC ';
	      }
		  //
		  $oTabelaRegs->sBDQuery =
			 "SELECT FOR_CODIGO, FOR_FANTAS, FOR_RAZAOS, FOR_CPJCPF ".
         "FROM cad_fornecedor ".
         "WHERE 1 = 1 ".$sWhereSQL.
         $sOrderSQL.
         ";";
    	  //
	      // 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.$nQdrNomeAcs.'.'.$oTabelaRegs->sNomeTabela.'_Rowsel = 1;'.
	         'parent.Car_'.$sNomeAcesso.$nQdrNomeAcs.'.P_Sel('.$nP_NumCam.');'.
    	     '';
	      $sRet_TelaJ_HTML = '';
	   }
    	//
		// FECHAR
	} ElseIf ( $sAcao=="FECHAR" ) {
		   $sRet_Javs .=
		  "parent.document.getElementById('".$sNomeIdJ_Ant."_Travar').style.visibility='hidden';".
		  "parent.Disabled_In_Elems('".$sNomeIdJ_Ant."',false);".
    	  $sJavaExePos.
		  'parent.document.getElementById("'.$sNomeIdCampo.'").focus();'.
	      "parent.RmElem('".$oJanelaPrinc->sIdObj."');";
    	//
		// JANELA TELA PRINCIPAL
	} Else {
	       
		   //
		   $oJanelaPrinc->aIdsObjList = ARRAY( 'iCadFor_PChave', 'iTip_Busca' );
		   
		   // Tela HTML
    	   $sRet_TelaJ_HTML =
			  $oJanelaPrinc->MontaJanHTML(True).
		      '<form name="fmPCadFor" accept-charset="utf-8" method="post" action="./car_js.php" target="car_'.$sNomeAcesso.($nQdrNomeAcs+1).'">'.
		         '<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="For_PChave" type="hidden" value="">'.
			     '<input name="For_NumCam" type="hidden" value="">'.
			     '<input name="For_Codigo" type="hidden" value="">'.
    		     '<input name="Tip_Busca" type="hidden" value="">'.
		      '</form>'.
			  '<form name="fmPCadForL" accept-charset="utf-8" method="post" action="./car_js.php" target="car_'.$sNomeAcesso.($nQdrNomeAcs+2).'">'.
                 '<input name="mod" type="hidden" value="'.$sModulo.'">'.
                 '<input name="submod" type="hidden" value="">'.
                 '<input name="opcao_mod" type="hidden" value="">'.
                 '<input name="acao" type="hidden" value="">'.
    	         '<input name="nomeacs" type="hidden" value="'.$sNomeAcesso.'">'.
			     '<input name="IdObj_Rec_For_Codigo" type="hidden" value="'.$sNomeIdCampo.'">'.
    		'</form>'.                     
			'<table width="100%"><tr>'.
	   	       '<td width="4px" height="10px" align="left">&nbsp;</td>'.
	   	       '<td align="left" valign="middle" width="70px">'.
	   	          'Procurar por: '.
       	       '</td>'.
	   	   '<td align="left" valign="middle">'.
	   	    '<input id="iCadFor_PChave" type="text" maxlength="30" style="width:99%; height:24px; background:#FFFBEC; border-width: 1px; border-style: solid; border-color: #0099FF;">'.
		   '</td>'.
		   '<td align="right" valign="middle" width="70px">'.
			'Tipo Busca:'.
		   '</td>'.
    	   '<td align="left" valign="middle" width="105px">'.
			'<select id="iTip_Busca" onchange="Car_'.$sNomeAcesso.$nQdrNomeAcs.'.P_Atu();" style="width:99%; border-width:1px; border-style:solid; border-color:#0099FF; height:20px;">'.
		     '<option value="1">Normal</option>'.
		     '<option value="2" selected>Contida</option>'.
			'</select>'.
	   	   '</td>'.
       	   '<td align="right" valign="middle" width="140px">'.
	   	   HTML_Botao( 3, 'CadFor_BT_Pro'  , 'Car_'.$sNomeAcesso.$nQdrNomeAcs.'.P_Atu();'
		                , 'Procurar (F10)' ,'images/btimg_lupa.png',120).
	   	   '</td>'.
	   	   '<td width="4px" align="left">&nbsp;</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_Sel',   'Car_'.$sNomeAcesso.$nQdrNomeAcs.'.Pesq_Seleciona();'
			             , 'Seleciona (ENTER)','images/btimg_ativar.png').'&nbsp;&nbsp;'.
       	   '</td>'.
		   '<td>'.
	   	      HTML_Botao( 3, 'CadCFor_BT_Nov',  $sJavaTravarJ.
			                                 "sTargetAnt = document.forms.fmPCadForL.target;".
                                             "document.forms.fmPCadForL.target='car_CADFOR2'; ".
                                             "document.forms.fmPCadForL.mod.value='cad_fornecedor'; ".
                                             "document.forms.fmPCadForL.nomeacs.value='CADFOR'; ".
                                             "document.forms.fmPCadForL.acao.value='NV'; ".
											 "document.forms.fmPCadForL.submod.value='EDT'; ".
		                                     "document.forms.fmPCadForL.submit();".
			                                 "document.forms.fmPCadForL.target = sTargetAnt;".
                                             "document.forms.fmPCadForL.mod.value='".$sModulo."'; ".
                                             "document.forms.fmPCadForL.nomeacs.value='".$sNomeAcesso."'; ".
											 ""
							 , 'Novo (F6)'   ,'images/btimg_novo.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('".$sNomeIdJ_Ant."_Travar').style.visibility='visible';".
	     	  "parent.Disabled_In_Elems('".$sNomeIdJ_Ant."',true);".
	 		  'parent.document.getElementById("dv_MenuL_Barra").style.visibility="hidden";'.
     	     "var sSelIndiceC='';".
	 	     "function P_Atu() {".
	 	       "sSelIndiceC='';".
	 		    $oTabelaRegs->MontaJavaAgu().
	     	    "parent.document.getElementById('CadCFor_BT_Sel').style.display='none';".
	 	    	"parent.document.forms.fmPCadFor.acao.value='LISTAR'; ".
     	    	"parent.document.forms.fmPCadFor.For_PChave.value=parent.document.getElementById('iCadFor_PChave').value; ".
	 	    	"parent.document.forms.fmPCadFor.For_NumCam.value=nPesq_CampoSel+''; ".
	 			"parent.document.forms.fmPCadFor.Tip_Busca.value = parent.document.getElementById('iTip_Busca').value;".
	 	    	"setTimeout( function() { parent.document.forms.fmPCadFor.submit(); }, 100);".
	 	     '}'.
		  'function Pesq_Seleciona() {'.
		    'parent.document.getElementById("'.$sNomeIdCampo.'").value = sSelIndiceC;'.
	        $oJanelaPrinc->sJavOnClickF.
		  '}'.
    	  $oTabelaRegs->MontaJavaPri();
    	  '';
    	   // Java posterior
		   $sRet_JavsPos .=
	    	  "P_Atu();".
			  'parent.document.getElementById("iCadFor_PChave").focus();'.
			  //
			  "function Teclas_F( Objeto, Evento ) {".
    	         "vNumTecla = parent.Tecla_Apertada(Evento);".
			     "if ( vNumTecla==116) { ".        //  ** [F5] **         Não atualizar
				 
				 "} else if ( vNumTecla==117) { ".  //  ** [F6] **        (Novo Fornecedor)
    	              "setTimeout( parent.document.getElementById('CadCFor_BT_Nov').onclick , 100);".
	                 //
			     "} else if ( vNumTecla==121) { ". //  ** [F10] **        Procurar
			         "P_Atu();".
			     "} else if ( vNumTecla==27) { ".  //  ** [ESC] **        (SAIR)
    	              "setTimeout( parent.document.getElementById('CadCFor_BT_Fch').onclick , 100);".
			     "} else if ( vNumTecla==13) { ". //   ** [ENTER] **      Selecionar
		              "if ( parent.document.getElementById('CadCFor_BT_Sel').style.display == 'none') {".
				     "P_Atu();". 
	                 "parent.document.getElementById('iCadFor_PChave').value='';".
				  "} else {".
	                   "setTimeout( parent.document.getElementById('CadCFor_BT_Sel').onclick , 100);".
			  "}".
		 "} else {".
	         "P_TeclasPress_fm(Evento);".
		     "return true;".
		 "}".
		 "return false;".
	     '}'.
	     //
	     "";
	}
//  ** CONSULTA AO CADASTRO DE FORNECEDORES **
   //If ( $sSubModulo=="INC_NOVFOR" ) {
   //  $bDir_Consult = True;
     
   //  $sNomeIdJ_Ant = $aSessao[$sNomeAcesso.'_Vars']['Ant_Jan_Id'];
   //  $sNomeIdCampo = $aSessao[$sNomeAcesso.'_Vars']['Ant_Inp_Id'];
   //  $sJavaExePos  = $aSessao[$sNomeAcesso.'_Vars']['JavaExec_P'];
   //  REQUIRE "./modulos/cad_fornecedor.inc";
   //
   //}
?>