<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!-- #include file="Conexion.asp" -->
<%
Dim sql
Dim rsDpto
Dim rsProvincia
Dim rsDistrito
Dim rsLocal
Dim rsNroTarjeta
Dim GestionTipo

GestionTipo = Request.QueryString("GestionTipo")

sql = "sp_GranjaVilla_0003"
Set rsDpto	= Conex.Execute(sql)
sql = "sp_GranjaVilla_0004"
Set rsProvincia	= Conex.Execute(sql)
sql = "sp_GranjaVilla_0005"
Set rsDistrito	= Conex.Execute(sql)
sql = "sp_GranjaVilla_0006"
set rsLocal = Conex.Execute(sql)
sql = "sp_GranjaVilla_0007"
set rsTipoClte = Conex.Execute(sql)

if (GestionTipo=1) then
sql = "sp_GranjaVilla_0008"
set rsNroTarjeta = Conex.Execute(sql)
end if


if (GestionTipo<>1) then
sql = "sp_GranjaVilla_0012 '"+Session("SesCodclte")+"','"+Session("sesCodLocal")+"'"
set rsDatosClientes = Conex.Execute(sql)
end if
x = 0



%>

<script language="javascript">
function Trim(s) 
{
  while ((s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
  {
    s = s.substring(1,s.length);
  }
  while ((s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
  {
    s = s.substring(0,s.length-1);
  }
  return s;
}

<!--Opcion permite llenar el 2do combo Dependiente : Provincia-->
function sublist(inform, selecteditem)
{
	var primero=0;
	inform.txtProv.length = 0;
	inform.txtDist.length = 0;
<%
	count=0
	y=0

do while not rsProvincia.eof
%>

x = <%= trim(y) %>;

subcat = new Array();
subcatagorys = "<%=(rsProvincia("sLocaName")) %>";
subcatagoryof = "<%=(rsProvincia("cDepaCode"))%>";
subcatagoryid = "<%=(rsProvincia("cProvCode"))%>";
subcat[x,0] = subcatagorys;
subcat[x,1] = subcatagoryof;
subcat[x,2] = subcatagoryid;

if (subcat[x,1] == selecteditem) 
{
	if (primero==0)
	{
	primero=subcat[x,2];
	}	
var option<%= trim(count) %> = new Option(subcat[x,0], subcat[x,2]);
inform.txtProv.options[inform.txtProv.length]=option<%= trim(count)%>;
}
<%
count = count + 1
y = y + 1
rsProvincia.movenext
loop

%>

subsublist(inform,primero)
}

<!--Opcion permite llenar el 3do combo Dependiente : Distrito-->
function subsublist(inform, selecteditem)
{
inform.txtDist.length = 0
subcat = new Array();
<%
	count=0
	y=0
	conta=0

do while not rsDistrito.eof
%>
x = <%= trim(y) %>;

subcatagorys = Trim("<%=(rsDistrito("sLocaName")) %>");
subcatagoryof = "<%=(rsDistrito("cProvCode"))%>";
subcatagoryid = "<%=(rsDistrito("cDistCode"))%>";

subcat[x,0] = subcatagorys;
subcat[x,1] = subcatagoryof;
subcat[x,2] = subcatagoryid;

if (subcat[x,1] == selecteditem) 
{
var option<%= trim(count) %> = new Option(subcat[x,0], subcat[x,2]);
inform.txtDist.options[inform.txtDist.length]=option<%= trim(count)%>;
}
<%
count = count + 1
y = y + 1
rsDistrito.movenext
loop

%>
}

function val01(inform){
	if (inform.chkFNac.checked)
	{
		inform.btnFNac.disabled=false
	}
	else
	{
		inform.btnFNac.disabled=true
		inform.dc.value=""
	}
}

function Grabar(){
	if (document.frmCliente.txtApellidos.value=="")
	{
		alert ("Debe Ingresar Apellidos")
		document.frmCliente.txtApellidos.focus()
		return 0;
	}	
	if (document.frmCliente.txtNombres.value=="")
	{
		alert ("Debe Ingresar Nombres")
		document.frmCliente.txtNombres.focus()
		return 0;
	}	
	if (document.frmCliente.txtDpto.selectedIndex==0)
	{
		alert ("Debe Seleccionar Departamento")
		document.frmCliente.txtDpto.focus()
		return 0;
	}	
	if (document.frmCliente.txtProv.selectedIndex==-1)
	{
		alert ("Debe Seleccionar Provincia")
		document.frmCliente.txtProv.focus()
		return 0;
	}
	if (document.frmCliente.txtDist.selectedIndex==-1)
	{
		alert ("Debe Seleccionar Distrito");
		document.frmCliente.txtDist.focus();
		return 0;
	}		
	
	document.frmCliente.method = "post";
	document.frmCliente.action = "Validacion.asp"; 
	document.frmCliente.submit();  
}

function CodTarjetaNueva(){
<% if GestionTipo=1 then  %>	
	var Cod
	Cod = document.frmCliente.cbLocal.value;
	document.frmCliente.txtCodLocal.value = Cod;
	document.frmCliente.txtNroTarjeta.value=+<%=rsNroTarjeta.Fields("nume").value %>
<% end if%>
<% if GestionTipo=2 then  %>	
<% end if%>

<% if GestionTipo=3 then  %>	
<% end if%>

<% if GestionTipo=4 then  %>	
	document.frmCliente.txtApellidos.disabled=true;
	document.frmCliente.txtNombres.disabled=true;
	document.frmCliente.txtDpto.disabled=true;
	document.frmCliente.txtProv.disabled=true;
	document.frmCliente.txtDist.disabled=true;
	document.frmCliente.txaDireccion.disabled=true;
	document.frmCliente.txtTelefono.disabled=true;
	document.frmCliente.txtEmail.disabled=true;
	document.frmCliente.txtTipoC.disabled=true;
	document.frmCliente.btnFNac.disabled=true;
	document.frmCliente.chkFNac.disabled=true;
	
	document.frmCliente.txtDpto.selectedIndex= <%=rsDatosClientes.Fields("cDistCode").value%>
	document.frmCliente.txtProv.selectedIndex= <%=rsDatosClientes.Fields("cProvCode").value%>
	document.frmCliente.txtDist.selectedIndex= <%=rsDatosClientes.Fields("cDepaCode").value%>
<% end if%>

}




</script>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<style>
 .combos01{
 font-size:12px;
 font-family:"Times New Roman", Times, serif
 }
 
 .OmniClient{
 font-size:35px;
 font-family:serif;
 font-style:italic
 }
 
 .BotonFotografiar{
 width:180px;
 height:25px;
 font-family:Geneva, Arial, Helvetica, sans-serif
 }
 
  .BotonPiePag{
 width:120px;
 height:25px;
 font-family:Geneva, Arial, Helvetica, sans-serif
 }
</style>
</head>

<body onLoad="CodTarjetaNueva()">
<DIV id=popCal 
style="BORDER-RIGHT: 2px ridge; BORDER-TOP: 2px ridge; Z-INDEX: 100; VISIBILITY: hidden; BORDER-LEFT: 2px ridge; WIDTH: 10px; BORDER-BOTTOM: 2px ridge; POSITION: absolute" 
onclick=event.cancelBubble=true><IFRAME name=popFrame 
src= "popcjs.htm" 
frameBorder=0 width=183 scrolling=no height=188></IFRAME></DIV>
<FORM  name="frmCliente">
<table align="center" cellpadding="0" cellspacing="0">
<tr>
	<td>
		<table cellpadding="0" cellspacing="0">
		<!-- validar esta parte ya que existen 3 casos : nuevo, actualizar y vista-->
		<% if GestionTipo="1" then  %>
		<tr>
			<td width="150">Nuevo Nro. tarjeta</td>
			<td><input type="text" style="width:100px" name="txtNroTarjeta">-<input type="text" style="width:20px; text-align:center" name="txtCodLocal"></td>
		</tr>
		<% else %>
		<tr>
			<td width="150"></td>
			<td></td>
		</tr>		
		<% end if %>
		<tr>
			<td>Apellidos</td>
			<td><input type="text" style="width:340px" name="txtApellidos" value="<%if GestionTipo<>1 then %><%=rsDatosClientes.Fields("sClieApel").value%><%end if%>"></td>
		</tr>
		<tr>
			<td>Nombres</td>
			<td><input type="text" style="width:340px" name="txtNombres" value="<%if GestionTipo<>1 then %><%=rsDatosClientes.Fields("sClieName").value%><%end if%>"></td>
		</tr>
		<tr>
			<td>Departamento</td>
			<td>
			<!--Combo Departamento-->
				<select name="txtDpto" style="width:220px" id="txtDpto" onChange = "javascript:sublist(this.form, txtDpto.value);" class="combos01">				
				<option value="0">Seleccionar</option>
				<%				
				do while not rsDpto.EOF	
				%>
				<option value="<%=rsDpto.Fields("cDepaCode").value %>"><%=rsDpto.Fields("sLocaName").value%></option>
				<% 
				rsDpto.MoveNext
				Loop 
				rsDpto.close
				%>
				</select>
				<input type="text" style="width:115px" name="txtDptoOtro">			</td>
		</tr>
		<tr>
			<td>Provincia</td>
			<td>
				<!--Combo Provincia-->
				<SELECT name="txtProv" size="1" id="txtProv" style="width:220px" onChange = "javascript:subsublist(this.form, txtProv.value);" class="combos01">		
				</SELECT>																		
				<input type="text" style="width:115px" name="txtProvOtro">			</td>
		</tr>
		<tr>
			<td>Distrito</td>
			<td>
				<!--Combo Distrito-->
				<SELECT name="txtDist" size="1" style="width:220px" id="txtDist" class="combos01">
				</SELECT>
				<input type="text" style="width:115px" name="txtDistOtro">			</td>
		</tr>
		<tr>
			<td>Direcci&oacute;n</td>
			<td><textarea style=" width:340px; height:40" name="txaDireccion"><%if GestionTipo<>1 then %><%=rsDatosClientes.Fields("sClieAddr").value%><%end if%></textarea></td>
		</tr>
		<tr>
			<td>Tel&eacute;fonos</td>
			<td><input type="text" style="width:160px" name="txtTelefono" value="<%if GestionTipo<>1 then %><%=rsDatosClientes.Fields("sClieTelf").value%><%end if%>">
			Local
			  <select style="width:140px" class="combos01" disabled="disabled" name="cbLocal">
                <% do while not rsLocal.EOF %>
                <option value="<%=rsLocal.Fields("idLocal").value %>" selected="selected"><%=rsLocal.Fields("DscLocal").value%></option>
                <% 
				rsLocal.MoveNext
				Loop 
				rsLocal.Close
				%>
              </select></td>
		</tr>
		<tr>
			<td>E-Mail</td>
			<td><input type="text" style="width:340px" name="txtEmail" value="<%if GestionTipo=4 then %><%=rsDatosClientes.Fields("sClieMail").value%><%end if%>"></td>
		</tr>
		<tr>
			<td>Tipo</td>
			<td>
			<select style="width:80px" class="combos01" name="txtTipoC">			
				<% do while not rsTipoClte.EOF %>
				<option value="<%=rsTipoClte.Fields("cliente_tipo_id").value %>"><%=rsTipoClte.Fields("cliente_tipo_desc").value%></option>
				<% 
				rsTipoClte.MoveNext
				Loop 
				rsTipoClte.Close
				%>
			</select>
			<input type="checkbox" name="chkFNac" onClick="javascript:val01(this.form);" checked="checked" >F. Nacimiento
			<input style="TEXT-ALIGN: center; width:130px" readonly name=dc value="<%if GestionTipo=4 then %><%=rsDatosClientes.Fields("dNacmDate").value%><%end if%>">
			<INPUT onClick="popFrame.fPopCalendar(dc,dc,popCal);return false" type=button value=V name="btnFNac">			</td>
		</tr>
		</table>
	</td>		
	<td>
		<table>
		<tr>
			<td align="center" class="OmniClient"><b>OmniClient</b></td>
		</tr>
		<tr>
			<td>
				<fieldset style="width:200px;height:180px"></fieldset>
			</td>
		</tr>
		<tr>
			<td align="center"><input type="button" name="btnFotografiar" value="Fotografiar" class="BotonFotografiar"></td>
		</tr>
		</table>		
	</td>
</tr>
<tr>
	<td><input type="hidden" name="tipo" value="3"></td>
</tr>
</table>

<table align="center" width="710"  border="0" cellpadding="0" cellspacing="0">
<tr>
	<td><fieldset style="width:710px;height:210px"></fieldset></td>
</tr>
<tr>
	<td align="right"><br><input type="button" name="btnAceptar" value="Aceptar" class="BotonPiePag" onClick="JavaScript:Grabar()">  <input type="button" name="btnCancelar" value="Cancelar" class="BotonPiePag"></td>
</tr>
</table>
</FORM>
</body>
</html>
