<?php
ini_set("session.cookie_lifetime",60*60*10);
ini_set("session.gc_maxlifetime", 60*60*10);
	session_start();
	include("cls_conexion.php");$CNN=new ClsMySQL();include("conexion23.php");
	if(strlen($_SESSION['SYS_USER_ID'])==0){JsDir("login.php");	return;}
//
if(vbval($_SESSION['SYS_USER_GI'])!=USU_GET_GI($_SESSION['SYS_USER_ID'])){
	JsDir("cerrar.php");	
	return;
}
//++++
$Z=V($_POST['Z']);
if(strlen($Z)==0)$Z=V($_GET['Z']);
//++++	
$W=V($_GET['W']);	
if(strlen(V($_POST['TxtW']))>0){
	$W=V($_POST['TxtW']);
}
$StrId=V($_POST['TxtId']);
$StrCmd=V($_POST['TxtAc']);
$StrNom=V($_POST['TxtNom']);		
$StrCon=V($_POST['TxtCon']);		
$StrRuc=V($_POST['TxtRuc']);
$StrDni=V($_POST['TxtDni']);		
//-------------------------
if($StrCmd=="F"){
	$StrPag="0";
}
//-------------------------
$StrNomT=$StrNom."%";
$StrConT=$StrCon."%";
$StrRucT=$StrRuc."%";
$StrDniT=$StrDni."%";
//-------------------------
$WW="ID>0 AND NOMBRE LIKE '$StrNomT' AND CONTACTO ".
    "LIKE '$StrConT' AND RUC LIKE '$StrRucT' AND DNI LIKE '$StrDniT' ";
//-------------------------
$LStrTR=gn("count(*)","vclientes",$WW);
//-------------------------
$LStrPag=V($_POST['TxtPag']);	
if($StrCmd=="F"){$LStrPag="1";}
$VP_RegXPag=20;
$LStrPag=PagGet($LStrPag,$StrCmd,$LStrTR,$VP_RegXPag);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Ventas - Clientes - Seleccionar</title>
<script type="text/javascript" src="fe/funcionez.js"></script>
<script type="text/javascript" src="fe/leo.js"></script>
<script>
function Z(IdCli,Cli,Ruc,Dir,Ema,Dni,TipDoc,Con){
	var W=gv("TxtW");
	if(W=="V"){
		window.opener.document.Frm.TxtIdCliente.value=IdCli;
		window.opener.document.Frm.TxtCliente.value=Cli;
		window.opener.document.Frm.TxtRuc.value=Ruc;
		window.opener.document.Frm.TxtDIR.value=Dir;
		window.opener.document.Frm.TxtDni.value=Dni;	
		window.opener.document.Frm.TxtEma.value=Ema;		
		window.opener.document.Frm.SUN_TIP_DOC.value=TipDoc;			  
		window.opener.document.Frm.TxtCod.focus();
		window.close();
		return;
	}
	if(W=="G"){
		window.opener.document.Frm.TxtDesRs.value=Cli;
		window.opener.document.Frm.TxtDesRuc.value=Ruc;
		window.opener.document.Frm.TxtDesDNI.value=Dni;
		window.opener.document.Frm.TxtDesDir.value=Dir;
		window.close();
		return;
	}
	if(W=="C"){
		window.opener.document.Frm.TxtCli.value=Cli;
		window.opener.document.Frm.TxtTot.focus();
		window.close();
	}else{
		 window.opener.document.Frm.TxtIdCliente.value=IdCli;
		 window.opener.document.Frm.TxtCliente.value=Cli;
		 if(jL(Ruc)>0){
		 	window.opener.document.Frm.TxtRuc.value=Ruc;
		 }else{
			 window.opener.document.Frm.TxtRuc.value=Dni;
		 }
		 window.opener.document.Frm.TxtCon.value=Con;
		 window.opener.document.Frm.TxtCod.focus();
		 window.close();
	}
	
}
</script>
<style type="text/css">
<!--
body {
	background-color: #666;
}
#Layer1 {
	position:absolute;
	left:345px;
	top:115px;
	width:123px;
	height:35px;
	z-index:1;
}
.centrarFrm{
	width:800px;
	height:600px;
	position:absolute;
	left:50%;
	top:0px;
	background-color:#999999;
	margin:0 0 0 -400px;
}
#Layer2 {
	position:absolute;
	left:409px;
	top:205px;
	width:82px;
	height:24px;
	z-index:1;
}
.Estilo1 {
	font-family: Arial, Helvetica, sans-serif;
	font-weight: bold;
	color: #FFFFFF;
}
.f2 {font-family: Arial, Helvetica, sans-serif; font-weight: bold; color: #FFFFFF; font-size: 12px; }
.Estilo3 {color: #FFFFFF; font-size: 12px; font-family: Arial, Helvetica, sans-serif;}
.x4 {color: #000099}
.Estilo5 {color: #000000}

-->
</style>

</head>
<body  onload="document.getElementById('TxtNom').focus();" >
<form id="Frm" name="Frm" method="post" action="ventas_clientes_buscar.php">
<input name="L_USU" type="hidden" id="L_USU" value="<?php echo vbval(V($_SESSION['SYS_USER_ID']))?>">
<input name="Z" type="hidden" id="Z" value="<?php echo $Z?>" />
<center> 
  <div Id="DivFRM"  class="centrarFrm" >

    <div id="layer3" style="position:absolute; left: 16px; top: 138px; width: 761px; height: 200px;">
      <div align="left" class="f2">
        <table width="758" border="1" cellpadding="0" cellspacing="0">
            <tr>
            <td colspan="6" bgcolor="#666666" align="center" height="20px">
            <?php echo PagBtn($LStrTR,$VP_RegXPag,$LStrPag);?>
            </td>
            </tr>
          <tr>
            <td width="279" bgcolor="#999999"><span class="x4">NOMBRE</span></td>
            <td width="114" bgcolor="#999999"><span class="x4">EMAIL</span></td>
            <td width="111" bgcolor="#999999"><span class="x4">RUC</span></td>
            <td width="98" bgcolor="#999999"><span class="x4">N° DOC IDENT..</span></td>
            <td width="105" bgcolor="#999999"><span class="x4">CELULAR</span></td>
            <td width="37" bgcolor="#999999">&nbsp;</td>
          </tr>
		  <?php		
				$s="SELECT ID,SUBSTRING(NOMBRE,1,31) as NOM,CONTACTO,RUC,TEL,CEL,
					DIRECCION,DNI,NOMBRE,EMAIL,CONTACTO,SUN_DOC_TIP
					FROM vclientes 
					WHERE $WW ORDER BY NOMBRE ";
				$X1="<td bgcolor=\"#FFFFFF\"><span class=\"Estilo5\">";
				$X2="</span></td>";
				$s=PagSql($s,$LStrPag,$VP_RegXPag,$LStrTR);
				$result = grs($s);				
				while ($row = $result->fetch_assoc()){					
					echo "<tr ondblclick=\"Z($row[ID],'$row[NOMBRE]','$row[RUC]','$row[DIRECCION]','$row[EMAIL]','$row[DNI]','$row[SUN_DOC_TIP]','$row[CONTACTO]');\" >";					
					echo $X1.VV($row['NOM']).$X2;
					echo $X1.VV($row['EMAIL']).$X2;
					echo $X1.VV($row['RUC']).$X2;
					echo $X1.VV($row['DNI']).$X2;
					echo $X1.VV($row['CEL']).$X2;					
					echo "<td bgcolor=\"#FFFFFF\" align=\"center\">
						 <a href=\"javascript:void(null)\"
						 onclick=\"Z($row[ID],'$row[NOMBRE]','$row[RUC]','$row[DIRECCION]','$row[EMAIL]','$row[DNI]','$row[SUN_DOC_TIP]','$row[CONTACTO]');\">
						 <img src=\"img/b_edit.png\"  border=\"0\"/>
						 </a>
						 </td>";
					echo "</tr>";
					
				}
		  ?>		            
        </table>
      </div>
</div>
<div id="layer" style="position:absolute; left: 116px; top: 30px; width: 412px; height: 24px;">
<div align="left" class="Estilo1">CLIENTES - SELECCIONAR
<input name="TxtId" type="hidden" id="TxtId" value="<?php echo $StrId;?>"/>
<input name="TxtW" type="hidden" id="TxtW" value="<?php echo $W;?>"/>
<input name="TxtPag" type="hidden" id="TxtPag" value="<?php echo $LStrPag; ?>" />
<input name="TxtAc" type="hidden" id="TxtAc" value="" />
</div>
</div>

<div style="position:absolute; left: 18px; top: 86px; width: 168px;">
<div align="left" class="f2">NOMBRE / RAZON SOCIAL</div>
</div>
<input name="TxtNom" type="text" id="TxtNom" 
style="position:absolute; left: 17px; top: 109px; width: 175px;" 
value="<?php echo $StrNom;?>"  
onkeydown="return SoloTextoExF(event,'TxtCon');"  
tabindex="1" />

<div style="position:absolute; left: 208px; top: 86px; width: 100px;">
<div align="left" class="f2">CONTACTO</div>
</div>
<input name="TxtCon" type="text" id="TxtCon" 
style="position:absolute; left: 205px; top: 109px; width: 169px;" 
value="<?php echo $StrCon;?>"  
onkeydown="return SoloTextoExF(event,'TxtRuc');"  
tabindex="2" />

<div style="position:absolute; left: 389px; top: 86px; width: 100px;">
<div align="left" class="f2">RUC</div>
</div>
<input name="TxtRuc" type="text" id="TxtRuc" style="position:absolute; left: 388px; top: 109px; width: 149px;"
value="<?php echo $StrRuc;?>"  onkeydown="return SoloTextoExF(event,'TxtDni');"  tabindex="3" />

<div style="position:absolute; left:563px; top: 86px; width: 132px;">
<div align="left" class="f2">DNI</div>
</div>
<input name="TxtDni" type="text" id="TxtDni" style="position:absolute; left: 559px; top: 109px; width: 140px;"
value="<?php echo $StrDni;?>"  onkeydown="return SoloTextoExF(event,'CmdB');"  tabindex="3" />


<div id="LblTit" style="position:absolute; left: 57px; top: 12px; width: 64px;">
<div align="left" class="Estilo1"><img src="img/buscar.png" width="57" height="60" /></div>
</div>
<input name="CmdB" type="button" id="CmdB" 
style="position:absolute; left: 713px; top: 109px; width: 57px;" 
value="Filtrar" onclick="fFiltrar();"  tabindex="4"/>

</div>
</center>	
</form>
</body>
</html>
