<?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('creniec/grid', "block=".$block)?>";
	}else{
	  switch (action){
	    case 'excel': parent.objMainTab.reqBody('<?=buildUrl('creniec/excel')?>','001&'+str); break;
	    case 'pdf': parent.objMainTab.reqBody('<?=buildUrl('creniec/pdf')?>','001&'+str); break;	    
	  }
	  
	  return;
	}
  
  //str = str + '&block=001';
  //url = "<?//=buildUrl('/creniec/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);
}
showTesis= function(id){
  parent.objMainTab.modalDialog('<?=buildUrl('/creniec/show',"block=001")?>/id/'+id,{title:'Detalle Tesis',width:800,height:450});
}
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('/creniec/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('doc/dele/creniec/id/'block=001'
  if(confirm("�Esta seguro de eliminar la ficha de la tesis de posicion " + codigo+ "?")){
      //objMainTab.reqBody('<? //=buildUrl('doc/add')?>','block=001&delete=1&id='+id);   
      parent.objMainTab.reqBody('<?=buildUrl('/creniec/delete')?>','001&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>


<img src="/images/common/spacer.gif" width="10">
<table class="cuerpo" style="background:#FFFFFF" width="99%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td valign="top">
      
      <table border="0" cellpadding="0" cellspacing="0" width="100%">
        <tr>
          <td class="titleBody"><li>&nbsp;&nbsp;Historial de Reniec</li></td>
          <td align="right" valign="baseline">
            
          </td>
        </tr>
      </table>
      <table class="marco" width="100%">
        <tr>
          <td align="center" valign="top">
           <form name="form1" id="form1" method="POST">
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
			      <td width="50%" nowrap="nowrap">
			         <table width="30%" cellspacing="4" cellpadding="0" border="0" class="SubCabecera">
			          <tr>
			            <td nowrap="nowrap">
			            <input type="text" placeholder="Documento" class="text" name="idcliente" id="idcliente" size="8"/>
			            <input type="text" placeholder="Nombres" class="text" name="nombrecompleto" id="nombrecompleto"/>
			            </td>
			            <td align="right" style="vertical-align:top"><input class="button" type="button" onclick="formCallbackbuscar();" value="Buscar"></td>
			           
			           <!-- <td width="35%" nowrap="nowrap"><div class="field-label"><label for="sRuc" class="label">Documento:</label></div></td>
			            <td nowrap="nowrap">
			              <select name="cboEstado" id="cboEstado" type="text" class="combo"/>
			                  <option value="Dni">DNI</option>
			             </select>
			            </td>
			            <td nowrap="nowrap"><input type="text" class="text required validate-digits" name="documento" id="documento" maxlength="11"/></td>
			            <td align="right" style="vertical-align:top"><input class="button" type="button" onclick="formCallback();" value="Nueva consulta"/></td>
			           -->
			          </tr>
			        </table>
			      </td>
			    </tr>

            </table>
              </form>
            <!--<div align="right">
              <input class="button" type="button" value="Buscar" onclick="findControl();"/>
            </div> -->
          </td>
        </tr>
      </table>
       
      
      <div id="resultGrtid">
      </div>
    </td>
  </tr>
</table>
<script type="text/javascript">
    var valid = new Validation('form1', {onSubmit:false,immediate : false});
    formCallback = function () 
	{
		var documento = $('documento').value;
	    var result = valid.validate();
	    if(result)
	    {
	    	objMainTab.modalDialog('<?=buildUrlComplet('rep.php/creniec/showSentinel/documento');?>'+documento,{title:'Detalle Sentinel',width:950,height:420,nameOtherWindow:'ov'});
	        
	    }
	}
	formCallbackbuscar= function () 
	{
		//$('documento').value = '';	
		findControl();
	}
    
</script>
<?php
if(isset($insert)){
  ?>
  <script>
    elementLoad.show(undefined,"Se inserto la ficha satisfactoriamente.");
    setTimeout("elementLoad.hide()",5000);
    $('txtivnid').value = "<?=$cod?>";
    findControl();
  </script>
  <?php
}
if(isset($update)){
  ?>
  <script>
    elementLoad.show(undefined,"Se actualizo la ficha satisfactoriamente.");
    setTimeout("elementLoad.hide()",5000);
    $('txtivnid').value = "<?=$cod?>";
    findControl();
  </script>
  <?php
}
if(isset($delete)){
  ?>
  <script>
    elementLoad.show(undefined,"Se elimino la ficha satisfactoriamente."); 
    findControl();
  </script>
  <?php 
  
}else{
	?>
  <script>
      findControl();
  </script>
  <?php 
}
?>