<?php use_helper('UrlFunctions'); ?>
<script>

acutalizarEspecialidad = function(destino,elm){
  $(destino).options.length = 1;
  var url = '<?=buildUrl('ajax/request')?>';
  var pars = 'type=getEspecialidad&nombreElm='+destino+'&value='+elm.value;
  
	var myAjax = new Ajax.Request(
                            		url, 
                            		{
                            			method: 'get', 
                            			parameters: pars, 
                            			onComplete: actualizaJSON
                            		});
}

</script>
<script>
actualizaJSON = function(request, json){
  var numeroElementos = json.length;
  for (var i = 0; i < numeroElementos; i++){
    if($(json[i][0])){
  	  switch ($(json[i][0]).tagName){
  	    case 'TD'      : Element.update(json[i][0], json[i][1]); break;
  	    case 'INPUT'   : $(json[i][0]).value=json[i][1]; break;
  	    case 'SELECT'  : 
  	      var objDDL = $(json[i][0]);
  	      if(typeof(cont) == 'undefined'){
  	        var cont = 0;
  	        objDDL.options.length = 1;
  	      }
  	      var a_contentValues = json[i][1].split("_;_");
      		var value	= a_contentValues[0];
      		var text	= a_contentValues[1];
  	      var option	= new Option(text,value);
      		try{
      			objDDL.add(option,null);
      		}catch (e){
      			objDDL.add(option,-1);
      		}
  	      cont++;
  	    break;
  	  }
    }else{
      if(json[i][0].indexOf("function") > -1){
        eval("scriptEval = "+json[i][0]);
        scriptEval();
      }
    }
  }
}
</script>
<?php

if(isset($control)){
  
  $o_ClienteBean = new ClienteBean();
  
  $o_ClienteBean->setIdCliente($id);
  $o_ClienteBean->setIdMercado($IdMercado);
  $o_ClienteBean->setIdTipoNegocio($IdTipoNegocio);
  $o_ClienteBean->setDni($Dni);
  $o_ClienteBean->setNombres($Nombres);
  $o_ClienteBean->setApellidoPaterno($ApellidoPaterno);
  $o_ClienteBean->setApellidoMaterno($ApellidoMaterno);
  $o_ClienteBean->setTelefono($Telefono);
  $o_ClienteBean->setDireccion($Direccion);
  $o_ClienteBean->setCelular($Celular);
  $o_ClienteBean->setFechaNacimiento($FechaNacimiento);
  $o_ClienteBean->setSexo($cboSexo); 
  $o_ClienteBean->setEstadoCivil($cboEstadoCivil);
  $o_ClienteBean->setEstado($cboEstado);   
  $o_ClienteBean->setFechaModificacion(date("Y-m-d"));
  $o_ClienteBean->setUsuarioModificacion(myUser::getUser()->getUserId());
  $o_ClienteSystemClass = new ClienteSystemClass($o_ClienteBean);
  $bResult = $o_ClienteSystemClass->actualizarCliente();
  
   
  if($bResult){

    ?>
    <script language="JavaScript">
    parent.objMainTab.reqBody('<?=buildUrl('pre/list')?>','&block=001&insert=1&id=<?=$o_PrestamoBean->getIdPrestamo()?>');
    parent.objMainTab.windowsCloseAll();
    </script>
    <?
  }
  exit;
}

$o_PrestamoBean = new PrestamoBean();
$o_PrestamoBean->setIdPrestamo($id);
$o_class = new PrestamoBL();
$a_ObjectBean = $o_class->busquedaPrestamo($o_PrestamoBean);

if(is_array($a_ObjectBean)){
  while(list($key,$o_ObjectBean) = each($a_ObjectBean)){
?>

<script>

function cacularTotal(){
	monto = $('txtCapital').value;
	if( monto != ""){
		monto = parseFloat(monto);
	}else{
		monto = 0;
	}
	if($('cboInteres').selectedIndex > 0){
		interes = parseFloat($('cboInteres').value);
	}else{
		interes = 0;
	}
	
	if ($('cboFormaPago').selectedIndex > -1){
		
		switch ($('cboFormaPago').value){
			 
	    	case "D" : 
	    	
	    	      if ($('cboDuracion').selectedIndex > -1){
	    	      	  
		    	       if (parseFloat($('cboDuracion').value)=='15'){	
						Duracion = 13;
						}
						if (parseFloat($('cboDuracion').value)=='30'){	
							Duracion = 26;
						}
						if (parseFloat($('cboDuracion').value)=='45'){	
							Duracion = 39;
						}
						if (parseFloat($('cboDuracion').value)=='60'){	
							Duracion = 52;
						}
						if (parseFloat($('cboDuracion').value)=='75'){	
							Duracion = 65;
						}
						if (parseFloat($('cboDuracion').value)=='90'){	
							Duracion =82;
						}
	    	       }
	    			break;
	    	case "S":
	    	
	    		 if ($('cboDuracion').selectedIndex > -1){
	    	      	  
		    	       if (parseFloat($('cboDuracion').value)=='15'){	
							Duracion = 2;
						}
						if (parseFloat($('cboDuracion').value)=='30'){	
							Duracion = 4;
						}
						if (parseFloat($('cboDuracion').value)=='45'){	
							Duracion = 6;
						}
						if (parseFloat($('cboDuracion').value)=='60'){	
							Duracion = 8;
						}
						if (parseFloat($('cboDuracion').value)=='75'){	
							Duracion = 10;
						}
						if (parseFloat($('cboDuracion').value)=='90'){	
							Duracion = 12;
						}
		    		}

	    			break;
	    	case "Q":
	    	        
	    	        if ($('cboDuracion').selectedIndex > -1){
	    	      	  
		    	       if (parseFloat($('cboDuracion').value)=='15'){	
							Duracion = 1;
						}
						if (parseFloat($('cboDuracion').value)=='30'){	
							Duracion = 2;
						}
						if (parseFloat($('cboDuracion').value)=='45'){	
							Duracion = 3;
						}
						if (parseFloat($('cboDuracion').value)=='60'){	
							Duracion = 4;
						}
						if (parseFloat($('cboDuracion').value)=='75'){	
							Duracion = 5;
						}
						if (parseFloat($('cboDuracion').value)=='90'){	
							Duracion = 6;
						}
		    		}
	    	      
	    			break;
	    	case "M":
	    			
	    			 if ($('cboDuracion').selectedIndex > -1){
	    	      	  
		    	       if (parseFloat($('cboDuracion').value)=='30'){	
							Duracion = 1;
						}
						if (parseFloat($('cboDuracion').value)=='60'){	
							Duracion = 2;
						}
						if (parseFloat($('cboDuracion').value)=='90'){	
							Duracion = 3;
						}
		    		}
	    			
	    			break;
	    }
	}else{
		Duracion = 0;
	}
	$('txtMontoTotal').value = (monto*(interes/100 + 1)).toFixed('2') ;
	$('txtCuotaPago').value = ((monto*(interes/100 + 1))/Duracion).toFixed('2') ;
}

validateControls = function(){
  var errOutput               = { error:false, msg:"" };
   
 
  var valueTipo               = $('cboTipoTesis'); 
  //var valueTitulo             = $('txtTitulo');
    
  //var valueFechaPublicacion   = $('FechaPublicacion');
  //var valueFin      = $('txtFecFin');
  
 /* if(valueTitulo.value == ""){
    errOutput.error = true;
    errOutput.msg   += "Debe de digitar el titulo.\n";
  }*/
  if(valueTipo.value == ""){
    errOutput.error = true;
    errOutput.msg   += "Debe de seleccionar el tipo.\n";
  }
  return errOutput;
}

acutalizarEspecialidad = function(destino,elm){
  $(destino).options.length = 1;
  var url = '<?=buildUrlComplet('mnt.php/ajax/request')?>';
  var pars = 'type=getEspecialidad&nombreElm='+destino+'&value='+elm.value;
  
	var myAjax = new Ajax.Request(
                            		url, 
                            		{
                            			method: 'get', 
                            			parameters: pars, 
                            			onComplete: actualizaJSON
                            		});
}


</script>

<script type="text/javascript" src="<?php echo Constantes::ROOT_DIR_APP?>/web/js/objectForm.js"></script>

<script type="text/javascript">
  validatePass = function(){
    valid.onSubmit = false;
  }
</script>
<!--
<script>
validateControls = function(){
  var errOutput         = { error:false, msg:"" };

  return errOutput;
}
</script>-->

<script>
actualizarElementos = function(elmValue, elmDestino,type){
  var url = '<?=buildUrl('ajax/request')?>';
  var pars = 'type=name&typeFind='+type+'&nombreElm='+elmDestino+'&value='+elmValue;
  
	var myAjax = new Ajax.Request(
                            		url, 
                            		{
                            			method: 'get', 
                            			parameters: pars, 
                            			onComplete: actualizaJSON
                            		});
}
</script>
<script>
actualizaJSON = function(request, json){
  var numeroElementos = json.length;
  for (var i = 0; i < numeroElementos; i++){
    if($(json[i][0])){
  	  switch ($(json[i][0]).tagName){
  	    case 'TD'      : Element.update(json[i][0], json[i][1]); break;
  	    case 'INPUT'   : $(json[i][0]).value=json[i][1]; break;
  	    case 'SELECT'  : 
  	      var objDDL = $(json[i][0]);
  	      if(typeof(cont) == 'undefined'){
  	        var cont = 0;
  	        objDDL.options.length = 1;
  	      }
  	      var a_contentValues = json[i][1].split("_;_");
      		var value	= a_contentValues[0];
      		var text	= a_contentValues[1];
  	      var option	= new Option(text,value);
      		try{
      			objDDL.add(option,null);
      		}catch (e){
      			objDDL.add(option,-1);
      		}
  	      cont++;
  	    break;
  	  }
    }else{
      if(json[i][0].indexOf("function") > -1){
        eval("scriptEval = "+json[i][0]);
        scriptEval();
      }
    }
  }
}
</script>


<script>
insertOptionDefault = function(){
  
  var table = $('tableContent');
  var countRows = table.rows.length;
  
  var tr = table.rows[countRows-1];
  var td = tr.cells[1];
  var idSelect = td.firstChild.id;
  
  values = [[idSelect,'alm_;_Alumno']];
  
  
  actualizaJSON('', values);
  
}
</script>

<script>
events = function(type){
  oReturn = validateControls();
  if(!oReturn.error){
    switch (type){
      case 'submit':
        if(grid.getCountRows() > 1){
          if(grid.validateRows()){
            disabledWin.show(true,true,'idGrid')
            $('form1').submit();
          }else{
            alert("Verifique el formulario.");
          }
        }else{
          elementLoad.show(undefined,'&nbsp;&nbsp;&nbsp;Tiene que Ingresar detalles.'); setTimeout('elementLoad.hide()',3000);
        }
      break;
      case 'insert':
        grid.insert();
        insertOptionDefault();
      break;
      case 'delete':
        grid.deletes();
      break;
    }
  }else{
    alert(oReturn.msg);
    return false;
  }
}
</script>

<script>
buscaDetalle = function(e,elm){
  var charCode;
  if (navigator.appName == "Mozilla" || navigator.appName == "Netscape"){
    charCode = e.keyCode;
  }else{
    charCode = event.keyCode;
  }
  if (charCode == 114){
    
    var parentTr      = elm.parentNode.parentNode.id;
    var valueSelect   = $(parentTr + "_td_1_tipo[]").value;
    var url           = "";
    
    if(valueSelect != ""){
      switch (valueSelect){
        case 'doc':
          url = '<?=buildUrlComplet('mnt.php/doc/listFind')?>iframe/contentResultxx/nameElm/'+elm.id+'/value/'+elm.value;
          tit = 'Docente';
        break;
        case 'alm':
          url = '<?=buildUrlComplet('mnt.php/alm/listFind')?>iframe/contentResultxx/nameElm/'+elm.id+'/value/'+elm.value;
          tit = 'Alumno';
        break;
        case 'ext':
          url = '<?=buildUrlComplet('mnt.php/ext/listFind')?>iframe/contentResultxx/nameElm/'+elm.id+'/value/'+elm.value;
          tit = 'Externo';
        break;
      }
      parent.objMainTab.modalDialog(url,{title:'Busqueda de '+ tit,width:600,height:420});
    }else{
      elementLoad.show(undefined,'&nbsp;&nbsp;&nbsp;Seleccione el tipo para el ListFind.'); setTimeout('elementLoad.hide()', 1000);
    }
  }
}
</script>

<script>
actionSelect = function(elm){
  
  var parentTr      = elm.parentNode.parentNode.id;
  
  $(parentTr + "_td_2_codigo[]").value = "";
  $(parentTr + "_td_3").innerHTML = "&nbsp;";
  $(parentTr + "_td_4_part[]").value = "";
  
}

actionCod = function(elm){

  elm       = $(elm);
  elm.value = elm.value.trim();
  var elmValue = elm.value;
  
  parentTr = elm.parentNode.parentNode.id;
  
  elmDestino = parentTr + "_td_3";
  
  if(elmValue != ""){
    
    if(!grid.validateByColumn(1, elm, 'INPUT')){
    
      var parentTr      = elm.parentNode.parentNode.id;
      var valueSelect   = $(parentTr + "_td_1_tipo[]").value;
      
      $(elmDestino).innerHTML = "&nbsp;";
      formItem.loadProcess(parentTr + "_td_3");
      actualizarElementos(elmValue, elmDestino, valueSelect);
      
    }else{
      
      elm.value = "";
      elementLoad.show(undefined,'&nbsp;&nbsp;&nbsp;El Código ya fue Ingresado'); setTimeout('elementLoad.hide()', 1000);
      $(elmDestino).innerHTML = "&nbsp;";
      
    }
    
  }
  
}
</script>


<img src="/images/common/spacer.gif" width="10">
 <table class="cuerpo" width="98%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td height="0">
      <table border="0" cellpadding="0" cellspacing="0" width="100%">
        <tr>
          <td class="titleBody">
            <li>Prestamo</li>
            <span class="subtitle"><I>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:::&nbsp;Editar Prestamo</I></span></td>
          <td align="right" valign="baseline">&nbsp;</td>
        </tr>
      </table>
    </td>
  </tr>
  <tr>
    <td valign="top">
      <form id="form1" name="form1" method="POST">
      <input type="hidden" name="control" value="1">
        <table hspace="20px" class="marco" width="99%" style="background: #E3E9E2">
          <tr>
            <td valign="top">
              <table width="100%" border="0" cellpadding="5" cellspacing="0">
			    <tr>
    				  <td height="0">
    				  <fieldset>
    					<legend class="fielsettex"><I>Datos del Cliente</I></legend>
    					 <table width="100%" border="0" cellspacing="4" cellpadding="0">
							   <tr>
								<td nowrap="nowrap" class="cabecera"><label class="label req" for="txtRev" >Nombre </label></td>
								<td nowrap="nowrap"  align="left">&nbsp;:&nbsp;<label class="label"><?php echo $Nombre?></label></td>
								<td nowrap="nowrap" width="20%" class="cabecera">&nbsp;</td>
								<td nowrap="nowrap"  class="cabecera"><label class="label req" for="txtRev" >Mercado</label></td>
								<td nowrap="nowrap" align="left">&nbsp;:&nbsp;<label class="label"><?php echo strtoupper($NombreMercado)?></label></td>
								<td nowrap="nowrap" width="20%" class="cabecera">&nbsp;</td>
							  </tr>
						</table>
    					</fieldset>				
    				</td>
                </tr>
          		<tr>
    				  <td height="0">
    				  <fieldset>
    					<legend class="fielsettex"><I>Datos del Prestamo</I></legend>
    					 <table width="100%" border="0" cellspacing="6" cellpadding="0">
							  <tr>
								<td nowrap="nowrap" width="12%" class="cabecera"><label class="label req" for="FechaInicial" >Fecha Inicial</label></td>
								<td nowrap="nowrap" width="38%">&nbsp;:&nbsp;<label class="label"><b><?php echo date('d-m-Y')?></b></label></td>
								 <td nowrap="nowrap" width="12%" class="cabecera">&nbsp;</td>
								 <td nowrap="nowrap" width="12%" class="cabecera">&nbsp;</td>
								<td nowrap="nowrap" width="38%">&nbsp;</td>
							   </tr>
							   <tr>
								<td nowrap="nowrap" class="cabecera"><label class="label req" for="txtRev" >Capital</label></td>
								<td nowrap="nowrap">&nbsp;:&nbsp;<input class="text required" type="text" name="txtCapital" id="txtCapital" size="15" maxlength="20" onkeyup="cacularTotal()" style="text-align:right;"/></td>
								<td nowrap="nowrap" width="12%" class="cabecera">&nbsp;</td>
								<td nowrap="nowrap" class="cabecera"><label class="label req" for="txtRev" >Intres(%)</label></td>
								<td nowrap="nowrap">&nbsp;:&nbsp;
									<select name="cboInteres" id="cboInteres" class="combo required" onchange="cacularTotal();">
										<option value="">-Seleccione-</option>
										<?php 
										for($i=7;$i<=20;$i++){?>
										<option value="<?php echo $i?>" style="text-align:right;"><?php echo $i."%"?></option>
										<?php	
										}
										?>
									</select>
								</td>
							  </tr>
							  <tr>
								<td nowrap="nowrap" class="cabecera"><label class="label req" for="txtRev" >Monto Total</label></td>
								<td width="38%" nowrap="nowrap"><input class="text required" id="txtMontoTotal" name="txtMontoTotal" size="15" type="text" class="text" value="<?php echo $o_ObjectBean->getMontoTotal();?>" readonly='readonly' style="text-align:right;" /></td>
								<td nowrap="nowrap" width="12%" class="cabecera">&nbsp;</td>
								<td nowrap="nowrap" class="cabecera"><label class="label req" for="txtRev" >Gasto Admin.</label></td>
								<td nowrap="nowrap">&nbsp;:&nbsp;<input class="text" type="text" name="txtGastoAdministrativo" id="txtGastoAdministrativo" size="15" maxlength="20" /></td>
							  </tr>
							   <tr>
							     <td nowrap="nowrap" class="cabecera"><label class="label req" for="txtRev" >Cuota Pago</label></td>
								<td nowrap="nowrap">&nbsp;:&nbsp;<input class="text" type="text" name="txtCuotaPago" id="txtCuotaPago" size="15" maxlength="20" readonly='readonly' style="text-align:right;" /></td>
								<td nowrap="nowrap" width="12%" class="cabecera">&nbsp;</td>
							   </tr>
							   <tr>
								<td nowrap="nowrap" class="cabecera"><label class="label req" for="txtRev" >Forma Pago</label></td>
								 <td nowrap="nowrap" >&nbsp;:&nbsp;
								   <select name="cboFormaPago" id="cboFormaPago" type="text" class="combo required" onchange="cacularTotal();"/> 
									  
									  <option value="D">Diario</option>
									  <option value="S">Semanal</option>
									  <option value="Q">Quincenal</option>
									  <option value="M">Mensual</option>
							  		</select>
								</td>
								<td nowrap="nowrap" width="12%" class="cabecera">&nbsp;</td>
								<td nowrap="nowrap" class="cabecera"><label class="label req" for="txtRev" >Duraci&oacute;n </label></td>
								 <td nowrap="nowrap" >&nbsp;:&nbsp;
								   <select name="cboDuracion" id="cboDuracion" type="text" class="combo required" onchange="cacularTotal();"/> 
									 
									  <?php for($i=1;$i<=6;$i++){?>
									  		<option value="<?php echo $i*15?>"><?php echo ($i*15)."d&iacute;as"?></option>>
									  <?php }?>
							  		</select>
								</td>
							  </tr>
							  <!--<tr>
								<td nowrap="nowrap" width="12%" class="cabecera"><label class="label" for="txtObservacion">Comentario</label></td>
								<td nowrap="nowrap" colspan="3" >&nbsp;&nbsp;<textarea  name="txtObservacion" id="txtObservacion" cols="60" rows="3" ></textarea></td>
							  </tr>-->
						</table>
						 <table width="100%" border="0" cellspacing="0" cellpadding="0">
				  <tr>
					 <td><img src="/images/common/spacer.gif" width="10"></td>
				  </tr>
				  <tr>
					<td align="center">
					  <input type="hidden" name="typeSubmit" id="typeSubmit">
					  <input type="hidden" name="IdMercado" id="IdMercado" value="<?php echo $IdMercado?>">
					  <input type="hidden" name="IdCliente" id="IdCliente" value="<?php echo $idCliente?>">
					  <!--<input class="button" type="submit" value="Grabar y Nuevo" onclick="$('typeSubmit').value='add';"/>-->
					  <input class="button" type="submit" value="Grabar" onclick="$('typeSubmit').value='list';">
					  <input class="button" type="button" value="Cancelar" onclick="parent.objMainTab.windowsCloseAll();"/>
					</td>
				  </tr>
				  <tr>
					<td height="10">&nbsp;</td>
				  </tr>
				</table>
    					</fieldset>				
    		    </td>
               </tr>
    	     </table>
         </form>
			<script type="text/javascript">
				var valid = new Validation('form1', {immediate : true});
			</script>
    </td>
  </tr>
</table>
<?php
  }
}
?>
