<?php use_helper('UrlFunctions'); ?>
<script>
findControl = function(){
  
  concatValueStr();
  
}

exportFindControl = function(action){
  strFormSerialize = returnQueryStringForm();
  executeFind(strFormSerialize, action);
}

executeFind = function(str, action){
  if(typeof(action) == 'undefined'){
	  url = "<?=buildUrl('pre/grid', "block=".$block)?>";
	}else{
	  switch (action){
	    case 'excel': parent.objMainTab.reqBody('<?=buildUrl('pre/excel')?>','001&'+str); break;
        case 'pdf': parent.objMainTab.reqBody('<?=buildUrl('pre/pdf')?>','001&'+str); break;	    
	  }
	  
	  return;
	}
  //str = str + '&block=001';
  url = "<?=buildUrl('pre/grid', "block=".$block)?>";
	var myAjax  = new Ajax.Updater(
                                	"resultGrtid",
                                	url,
                                	{
                                		asynchronous:	true,
                                		method			: 'get',
                                		parameters	: str,
                                		evalScripts	: true,
                                		onLoading   : cargandoImagenSerch(),
                                		onComplete	: function(){
                                			//objMainTab.showMenu();
                                		}
                                	});
}

concatValueStr = function(){
  strFormSerialize = returnQueryStringForm();
  if(arguments[0]){
    strFormSerialize += '&'+arguments[0];
  }
  executeFind(strFormSerialize);
}

function returnQueryStringForm(){
  cadenaFormulario = $('form1').serialize();
             var posicion = new Array();
             var a_pars = new Array();
             var miArray = new Array();
             posicion=[];
             a_pars=[];
             miArray=[];
             miArray = cadenaFormulario.split('&');
             x=0;
             for (i = 0; i < miArray.length; i++){
            	   posicion[i] = miArray[i].indexOf('=');
            	   if(typeof(miArray[i-1])!='undefined'){
            				if(miArray[i].substring(posicion[i],0)== miArray[i-1].substring(posicion[i-1],0) ){
           					 porcion = miArray[i].substring((1+posicion[i]));
           					 a_pars[x-1]+='@'+porcion;
           				}else{
          					 a_pars[x]= miArray[i];
         					 x++;
          				}
          		}else{
          			 a_pars[x]= miArray[i];
          			  x++;
          		}
           }
  cadenaFormulario = a_pars.join('&');
  cadenaFormulario += '&id_form=frmFindFedu';
  return(cadenaFormulario);
}

function cargandoImagenSerch(){
	//disabledWin.setPathImage('/images/common/progress.gif');
	disabledWin.show(true,true,'resultGrtid');
}

</script>
<script>
findControl = function(){
  
  var pars = $('form1').serialize();
  
	disabledWin.setPathImage('/images/common/progress.gif');
	disabledWin.show(true,true,'resultGrtid');
  
	url = "<?=buildUrl('pre/grid', "block=".$block)?>";
	var myAjax  = new Ajax.Updater(
	"resultGrtid",
	url,
	{
		asynchronous:	true,
		method			: 'get',
		parameters	: pars,
		evalScripts	: true,
		onLoading		: function(){
			//$('contentMenu').innerHTML = $('messageLoadMenu').innerHTML;
		},
		onComplete	: function(){
			//objMainTab.showMenu();
		}
	});
  
}

deleteRegistro = function(id,codigo){
  //buildUrl('pre/delete/id/'block=001'
  if(confirm("�Esta seguro de eliminar la ficha del docente con codigo : "+codigo+ " ?")){
      //objMainTab.reqBody('<? //=buildUrl('pre/add')?>','block=001&delete=1&id='+id);   
      parent.objMainTab.reqBody('<?=buildUrl('pre/delete')?>','&delete=1&cod=jj&id='+id);
  }
  
}

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
//Carga los Mercado
//Carga los Mercado
  $o_ClienteSystemClass = new ClienteSystemClass(new TipoNegocioBean());
  $a_Mercado = $o_ClienteSystemClass->LoadMercadoXRol();

if(myUser::getUser()->getIdPadre() || myUser::getUser()->getRoleId() == "sys.ope"){
	$o_ColaboradorBean_Temp = new ColaboradorBean();
	$o_ColaboradorBean_Temp->setIdColaborador(myUser::getUser()->getIdColaborador()); 
	$o_ColaboradorBL_Temp = new ColaboradorBL();
	$o_ColaboradorBeanResult = $o_ColaboradorBL_Temp->busquedaColaborador($o_ColaboradorBean_Temp);
	$idAdministrador = $o_ColaboradorBeanResult[0]->getIdPadre();
}elseif(myUser::getUser()->getIdPadre() == "A"){ //Todos los Padres Rol actualmente sys.gen y sys.view
	//SIN FILTRO
}else{
	$idAdministrador = myUser::getUser()->getIdColaborador();
}

if($idAdministrador){
	$o_SucursalBean = new SucursalBean();
	$o_SucursalBean->setIdAdministrador($idAdministrador);
	$o_SucursalBL = new SucursalBL();
	$a_o_sucursal = $o_SucursalBL->busquedaSucursal($o_SucursalBean);
	//----------------------------------------------------
	
	$IdSucursal = $a_o_sucursal[0]->getIdSucursal();

}
$o_ClienteSystemClass = new ClienteSystemClass(new TipoNegocioBean());
$a_Mercado = $o_ClienteSystemClass->LoadMercadoXRol();
$o_BalanceDia = new BalanceDiaBean();
$o_BalanceDia->setIdSucursal($IdSucursal);
$o_BalanceDia->setIdAdministrador($idAdministrador);

$o_BalanceDiaDP = new BalanceDiaDP($o_BalanceDia);
$fecha = $o_BalanceDiaDP->ObtenerDiaAbierto();
?>

<img src="/images/common/spacer.gif" width="10">
<table class="cuerpo" style="background: #E3E9E2" width="99%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td valign="top">
      <form name="form1" id="form1" method="POST">
      <table border="0" cellpadding="0" cellspacing="0" width="100%">
        <tr>
          <td class="titleBody"><li>&nbsp;&nbsp;Listado de Prestamos</li></td>
          <td align="right" valign="baseline">
            <!--<img name="add" src="/images/common/buttons/btnAdd.gif" onClick="parent.objMainTab.modalDialog('<?=buildUrl('pre/add')?>','block=001')" style="cursor:pointer">-->
            <img src="/images/common/buttons/btnExcel.gif" title="Exportar a Excel" onClick="exportFindControl('excel');" style="cursor:pointer"/>
            <img src="/images/common/buttons/btnPdf.gif" title="Exportar a PDF" onClick="exportFindControl('pdf');" style="cursor:pointer"/>
          </td>
        </tr>
      </table>
      <table class="marco" width="100%">
        <tr>
          <td align="center" valign="top">
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td width="100%" valign="top" >
                  <table class="SubCabecera" width="100%" border="0" cellpadding="0" cellspacing="0">
                    <tr>
                       <td valign="top" >
                          <table class="SubCabecera"  width="33%" border="0" cellpadding="3" cellspacing="0">
                            <tr>
                               <td width="10%" nowrap="nowrap">
                								  <select name="cboTipoNombre" id="cboTipoNombre" type="text" class="combo">
                								  <option value="AP" > - Apellido Paterno- </option>
                								  <option value="AM" > - Apellido Materno- </option>
                								  <option value="NO" > - Nombres- </option>
                								  <option value="NC" > - Apellidos y Nombres- </option>
  		                            </select>
		                         </td>
		                         <td><input name="txtNombre" id="txtNombre" type="text"  size="25" class="text"/></td>
                            </tr>
                           <tr>
                               <td width="12%" height="26" nowrap="nowrap" class="cabecera"><label class="label" for="txtNombre">Mercado</label></td>
	                            <td width="10%" nowrap="nowrap">
    		                      	 <select name="cboMercado" id="cboMercado" type="text" class="combo"/> 
    								 	            <option value="" > - Seleccionar - </option>
    			                       <?php foreach ($a_Mercado as $iKey => $o_MercadoBean){ ?>
    			                        <option value="<?=$o_MercadoBean->getIdMercado()?>">
    			                          <?=$o_MercadoBean->getDescripcion()?>
    			                        </option>
    			                        <?php } ?> 
    								              </select>
	                         </td>
                            </tr>
                            <tr>
                              <td width="9%" height="26" nowrap="nowrap" class="cabecera"><label class="label" for="txt">F.Cancelacion Desde</label></td>
                              <td nowrap="nowrap"><input class="text" type="text" ondblclick="this.value=''" size="8" maxlength="10" name="txtFechaInicialcan" id="txtFechaInicialcan" value='' /><button type="button" onclick="return false" id="btnFechaInicialcan">...</button></td>
		                         <script type="text/javascript">
		                            document.getElementById("txtFechaInicialcan").disabled = false;
		                            Calendar.setup({
		                              inputField : "txtFechaInicialcan",
		                              ifFormat : "%Y-%m-%d",
		                              daFormat : "%Y-%m-%d",
		                              button   : "btnFechaInicialcan"
		                            });
		                         </script>
                            </tr>
                            
                            <tr>
                              <td width="9%" height="26" nowrap="nowrap" class="cabecera"><label class="label" for="txtDni">F.Cancelacion Hasta</label></td>
                              <td nowrap="nowrap"><input class="text" type="text" ondblclick="this.value=''" size="8" maxlength="10" name="txtFechaFinalcan" id="txtFechaFinalcan" value=''/><button type="button" onclick="return false" id="btnFechaFinalcan">...</button></td>
		                         <script type="text/javascript">
		                            document.getElementById("txtFechaFinalcan").disabled = false;
		                            Calendar.setup({
		                              inputField : "txtFechaFinalcan",
		                              ifFormat : "%Y-%m-%d",
		                              daFormat : "%Y-%m-%d",
		                              button   : "btnFechaFinalcan"
		                            });
		                         </script>
                            </tr>
                             <tr>
                              <td width="9%" height="26" nowrap="nowrap" class="cabecera"><label class="label" for="txtDni">Nro Cliente</label></td>
                              <td width="15%" nowrap="nowrap" align="left"><input name="txtNuemroCliente" id="txtNuemroCliente" size="10" type="text" class="text"/></td>
                            </tr>
                          </table>
                       </td>
                       <td valign="top" >
                          <table class="SubCabecera"  width="34%" border="0" cellpadding="0" cellspacing="0">
                            <tr>
                              <td width="9%" height="26" nowrap="nowrap" class="cabecera"><label class="label" for="txt">F.Incio Desde</label></td>
                              <td nowrap="nowrap"><input class="text" type="text" ondblclick="this.value=''" size="8" maxlength="10" name="txtFechaInicial" id="txtFechaInicial" value='' /><button type="button" onclick="return false" id="btnFechaInicial">...</button></td>
		                         <script type="text/javascript">
		                            document.getElementById("txtFechaInicial").disabled = false;
		                            Calendar.setup({
		                              inputField : "txtFechaInicial",
		                              ifFormat : "%Y-%m-%d",
		                              daFormat : "%Y-%m-%d",
		                              button   : "btnFechaInicial"
		                            });
		                         </script>
                            </tr>
                            <tr>
                              <td width="9%" height="26" nowrap="nowrap" class="cabecera"><label class="label" for="txtDni">F.Incio Hasta</label></td>
                              <td nowrap="nowrap"><input class="text" type="text" ondblclick="this.value=''" size="8" maxlength="10" name="txtFechaFinal" id="txtFechaFinal" value=''/><button type="button" onclick="return false" id="btnFechaFinal">...</button></td>
		                         <script type="text/javascript">
		                            document.getElementById("txtFechaFinal").disabled = false;
		                            Calendar.setup({
		                              inputField : "txtFechaFinal",
		                              ifFormat : "%Y-%m-%d",
		                              daFormat : "%Y-%m-%d",
		                              button   : "btnFechaFinal"
		                            });
		                         </script>
                            </tr>
                            <tr>
                              <td width="9%" height="26" nowrap="nowrap" class="cabecera"><label class="label" for="txt">F.Ven Desde</label></td>
                              <td nowrap="nowrap"><input class="text" type="text" ondblclick="this.value=''" size="8" maxlength="10" name="txtFechaInicialven" id="txtFechaInicialven" value='' /><button type="button" onclick="return false" id="btnFechaInicialven">...</button></td>
		                         <script type="text/javascript">
		                            document.getElementById("txtFechaInicialven").disabled = false;
		                            Calendar.setup({
		                              inputField : "txtFechaInicialven",
		                              ifFormat : "%Y-%m-%d",
		                              daFormat : "%Y-%m-%d",
		                              button   : "btnFechaInicialven"
		                            });
		                         </script>
                            </tr>
                            <tr>
                              <td width="9%" height="26" nowrap="nowrap" class="cabecera"><label class="label" for="txtDni">F.Ven Hasta</label></td>
                              <td nowrap="nowrap"><input class="text" type="text" ondblclick="this.value=''" size="8" maxlength="10" name="txtFechaFinalven" id="txtFechaFinalven" value=''/><button type="button" onclick="return false" id="btnFechaFinalven">...</button></td>
		                         <script type="text/javascript">
		                            document.getElementById("txtFechaFinalven").disabled = false;
		                            Calendar.setup({
		                              inputField : "txtFechaFinalven",
		                              ifFormat : "%Y-%m-%d",
		                              daFormat : "%Y-%m-%d",
		                              button   : "btnFechaFinalven"
		                            });
		                         </script>
                            </tr>
                           <!-- <tr>
                              <td width="9%" height="26" nowrap="nowrap" class="cabecera"><label class="label" for="txtDni">N� Prest</label></td>
                              <td width="15%" nowrap="nowrap" align="left"><input name="txtNuemroPrestamo" id="txtNuemroPrestamo" size="10" type="text" class="text"/></td>
                            </tr>-->
                          </table>
                       </td>
                      <td valign="top" >
                          <table class="SubCabecera"  width="33%" border="0" cellpadding="0" cellspacing="0">
                             <tr>
                                <td width="8%" height="26" nowrap="nowrap" class="cabecera"><label class="label" for="txtNombre">Estado</label></td>
	                              <td width="15%" nowrap="nowrap"> <select name="cboEstadoPrestamo" id="cboEstadoPrestamo" type="text" class="combo"> 
              								   <option value="" > -Seleccione - </option>
              								  <option value="P" > - Pediente - </option>
              								  <option value="C" > - Cancelado - </option>
              								  </select></td>
                            </tr>
                            <tr>
                              <td width="15%" height="26" nowrap="nowrap" class="cabecera"><label class="label" for="txtNombre">Tipo Prest.</label></td>
                              <td width="15%" nowrap="nowrap"><select name="cboOrigen" id="cboOrigen" type="text" class="combo"> 
              							   <option value="" > -Seleccione - </option>
              							  <option value="R" > - Renovado - </option>
              							  <option value="F" > - Refinanciado - </option>
              							  </select>
              				</td>
                            </tr>
                            <tr>
                               <td width="9%" height="26" nowrap="nowrap" class="cabecera"><label class="label" for="txtDni">Nro Prest</label></td>
                              		<td width="15%" nowrap="nowrap" align="left"><input name="txtNuemroPrestamo" id="txtNuemroPrestamo" size="8" type="text" class="text"/>&nbsp;&nbsp;<input type="checkbox" name="vencido" value="V" >&nbsp;<label class="label">Vencido</label></td>
                            </tr>
                            <tr>
                               <td width="15%" nowrap="nowrap" align="left">&nbsp;<input type="checkbox" name="flagreporte" id="flagreporte" value="1" >&nbsp;<label class="label">No mostrar Reporte</label>&nbsp;</td>
                               
							   <td width="15%" nowrap="nowrap" align="left">&nbsp;&nbsp;<input type="checkbox" name="eliminado" value="E" >&nbsp;<label class="label">Eliminado</label></td>
							   
                            </tr>
                          </table>
                       </td>
                        
                    </tr>
                  </table>
                </td>
                </tr>   
			  <tr>
			    <td align="right" style="vertical-align:top"><input class="button" type="button" value="Buscar" onclick="findControl();"/></td>
			  </tr>
            </table>
          </td>
        </tr>
      </table>
       
      </form>
      <div id="resultGrtid">
      </div>
    </td>
  </tr>
</table>


<?php
if(isset($insert)){
  ?>
  <script>
    elementLoad.show(undefined,"Se inserto la ficha satisfactoriamente.");
    setTimeout("elementLoad.hide()",5000);
    $('IdPrestamo').value = "<?=$id?>";
    //$('cboEstadoPrestamo').value = "<?=$cboEstadoPrestamo?>";
    //$('cboMercado').value = "<?=$cboMercado?>";
    
    
    findControl();
  </script>
  <?php
}
if(isset($update)){
  ?>
  <script>
    elementLoad.show(undefined,"Se actualizo la ficha satisfactoriamente.");
    setTimeout("elementLoad.hide()",5000);
    $('IdPrestamo').value = "<?=$id?>";
   
    findControl();
  </script>
  <?php
}
if(isset($delete)){
  ?>
  <script>
    elementLoad.show(undefined,"Se elimino la ficha satisfactoriamente.");
    setTimeout("elementLoad.hide()",5000);
    $('IdPrestamo').value = "<?=$id?>";
    
    findControl();
    
  </script>
  <?php 
  
}
?>