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

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
                            		});
}



findControl = function(){
  
  concatValueStr();
  
}

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

executeFind = function(str,action){ 
  
   if(typeof(action) == 'undefined'){
	  url = "<?=buildUrl('ivn/grid', "block=".$block)?>";
	}else{
	  switch (action){
	    case 'excel': parent.objMainTab.reqBody('<?=buildUrl('ivn/excel')?>','001&'+str); break;
	    case 'pdf': parent.objMainTab.reqBody('<?=buildUrl('ivn/pdf')?>','001&'+str); break;	    
	  }
	  
	  return;
	}
  
  //str = str + '&block=001';
  //url = "<?//=buildUrl('ivn/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);
}

showInvestigacion= function(id){
  parent.objMainTab.modalDialog('<?=buildUrl('ivn/show',"&block=001")?>/id/'+id,{title:'Detalle Investigacion',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('ivn/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/deleinv/id/'block=001'
  if(confirm("żEsta seguro de eliminar la ficha de la investigacion de posicion " + codigo+ "?")){
      //objMainTab.reqBody('<? //=buildUrl('doc/add')?>','block=001&delete=1&id='+id);   
      parent.objMainTab.reqBody('<?=buildUrl('ivn/delete')?>','&delete=1&cod=jj&id='+id);
  }
}


</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

//Facultades
$o_DocenteSystemClass = new DocenteSystemClass(new FacultadBean());
$a_Facultad = $o_DocenteSystemClass->getFacultad();

$o_TipoInvetigacionSystemClass = new InvestigacionSystemClass(new TipoInvestigacionBean());
$a_TipoInvetigacion       = $o_TipoInvetigacionSystemClass->getTipoInvetigacion();  




?>
<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">
      <form name="form1" id="form1" method="POST">
      <input type="hidden" name="txtivnid" id="txtivnid">
      <table border="0" cellpadding="0" cellspacing="0" width="100%">
        <tr>
          <td class="titleBody"><li>&nbsp;&nbsp;Investigaci&oacute;n</li></td>
          <td align="right" valign="baseline">
            <!--<input type="image" src="/images/common/buttons/btnAdd.gif" alt="Nuevo" onclick="" />-->
            <img name="add" src="/images/common/buttons/btnAdd.gif" onClick="parent.objMainTab.reqBody('<?=buildUrl('ivn/add')?>','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%" height="100" border="0" cellpadding="0" cellspacing="0">
              <tr>
                <td width="50%" valign="top">
                <table class="SubCabecera" width="100%" border="0" cellpadding="0" cellspacing="2">
                    <tr>
                      <td nowrap="nowrap"><label class="label" for="txtCod">Tipo Investigaci&oacute;n:</label>                      </td>
                      <td colspan="4" nowrap="nowrap">
                      <select name="cboTipoInvestigacion" id="cboTipoInvestigacion" type="text" class="combo" onchange="acutalizarEspecialidad('cboEspecialidad',this)"/> 
                      <option value="" > - Seleccionar - </option>
                          <?php foreach ($a_TipoInvetigacion as $iKey => $o_TipoInvetigacion){ ?>
                            <option value="<?=$o_TipoInvetigacion->getTipoInvestigacionId()?>">
                              <?=$o_TipoInvetigacion->getDescripcion()?>
                            </option>
                          <?php } ?>
                      </select></td>
                    </tr>
                    <tr>
                      <td nowrap="nowrap"><label class="label" for="txtCod">Clave</label></td>
                      <td colspan="4" nowrap="nowrap">
                          <input class="text" type="text" name="txtClave" id="txtClave" size="40"/></td>
                    </tr>
                    <tr>
                      <td nowrap="nowrap" style="height:3px"></td>
                      <td colspan="4" nowrap="nowrap" style="height:3px"></td>
                    </tr>
                    <tr>
                      <td nowrap="nowrap"><label class="label" for="txtCod">Revista</label></td>
                      <td colspan="4" nowrap="nowrap">
                          <input class="text" type="text" name="txtRevista" id="txtRevista" size="40"/></td>
                    </tr>
                    <tr>
                      <td nowrap="nowrap" style="height:3px"></td>
                      <td colspan="4" nowrap="nowrap" style="height:3px"></td>
                    </tr>
                    <tr>
                      <td nowrap="nowrap"><label class="label" for="txtCod">F.Publicaci&oacute;n : </label></td>
                      <td nowrap="nowrap" width="5%"><label class="label" width="10px" for="textfield">Desde:</label></td>
                      <td nowrap="nowrap"><input class="text" type="text" ondblclick="this.value=''" size="8" maxlength="10" name="FechaPublicacionIni" id="FechaPublicacionIni" /><button type="button" onclick="return false" id="btnFechaPublicacionIni">...</button>
                      <script type="text/javascript">
                            document.getElementById("btnFechaPublicacionIni").disabled = false;
                            Calendar.setup({
                              inputField : "FechaPublicacionIni",
                              ifFormat : "%Y-%m-%d",
                              daFormat : "%Y-%m-%d",
                              button   : "btnFechaPublicacionIni"
                            });
                        </script></td>
                      <td nowrap="nowrap"><label class="label" for="label">Hasta:</label></td>
                      <td nowrap="nowrap"><input class="text"  size="8" maxlength="10" ondblclick="this.value=''" type="text" name="FechaPublicacionFin" id="FechaPublicacionFin" /><button type="button" onclick="return false" id="btnFechaPublicacionFin">...</button>
                      <script type="text/javascript">
                            document.getElementById("btnFechaPublicacionFin").disabled = false;
                            Calendar.setup({
                              inputField : "FechaPublicacionFin",
                              ifFormat : "%Y-%m-%d",
                              daFormat : "%Y-%m-%d",
                              button   : "btnFechaPublicacionFin"
                            });
                        </script></td>
                    </tr>
                    <tr>
                      <td nowrap="nowrap"><label class="label" for="txtCod">Facultad</label></td>
                      <td colspan="4" nowrap="nowrap">
                          <select name="cboFacultad" id="cboFacultad" type="text" class="combo" onchange="acutalizarEspecialidad('cboEspecialidad',this)"/> 
                          <option value="" > - Seleccionar - </option>
                           <?php foreach ($a_Facultad as $iKey => $o_FacultadBean){ ?>
                            <option value="<?=$o_FacultadBean->getFacultadId()?>">
                              <?=$o_FacultadBean->getDescripcion()?>
                            </option>
                            <?php } ?>
                          </select>
                        </td>
                    </tr>
                     <tr>
                      <td nowrap="nowrap"><label class="label" for="txtCod">Departamento</label></td>
                      <td colspan="4" nowrap="nowrap"><select name="cboEspecialidad" id="cboEspecialidad" type="text" class="combo"/> <option value="" > - Seleccionar - </option></select></td>
                    </tr>
                  </table></td>
                <td width="50%" valign="top">
                <table class="SubCabecera" width="100%" border="0" cellpadding="0" cellspacing="2">
                  <tr>
                    <td nowrap="nowrap"><label class="label" for="txtCod">Titulo</label></td>
                    <td colspan="4" nowrap="nowrap">
                        <input class="text" type="text" name="txtTitulo" id="txtTitulo" size="40"/></td>
                  </tr>
                   
                  <tr>
                      <td nowrap="nowrap"><label class="label" for="txtCod">Volumen</label></td>
                      <td colspan="4" nowrap="nowrap"><input class="text" type="text" name="txtVolumen" id="txtVolumen" size="10"/><input type="checkbox" name="index" class = 'combo' id name="index" value="1">&nbsp;<label class="label" for="txtCod">Con Index</label></td>
                  </tr>
                  <tr>
                      <td nowrap="nowrap" style="height:3px"></td>
                      <td colspan="4" nowrap="nowrap" style="height:3px"></td>
                  </tr>
                  <tr>
                    <td nowrap="nowrap"><label class="label" for="txtCod">F.Recepci&oacute;n :</label> </td>
                    <td nowrap="nowrap"><label class="label" for="FechaPublicacionFinD">Desde:</label></td>
                    <td nowrap="nowrap"><input class="text" ondblclick="this.value=''" size="8" readonly maxlength="10" type="text" name="FechaRecepcion" id="FechaRecepcion" /><button type="button" onclick="return false" id="btnFechaRecepcion">...</button>
                      <script type="text/javascript">
                            document.getElementById("btnFechaRecepcion").disabled = false;
                            Calendar.setup({
                              inputField : "FechaRecepcion",
                              ifFormat : "%Y-%m-%d",
                              daFormat : "%Y-%m-%d",
                              button   : "btnFechaRecepcion"
                            });
                        </script></td>
                    <td nowrap="nowrap"><label class="label" for="label">Hasta:</label></td>
                    <td nowrap="nowrap"><input class="text"  ondblclick="this.value=''" size="8" maxlength="10" readonly type="text" name="FechaRecepcionFin" id="FechaRecepcionFin" /><button type="button" onclick="return false" id="btnFechaRecepcionFin">...</button>
                      <script type="text/javascript">
                            document.getElementById("btnFechaRecepcionFin").disabled = false;
                            Calendar.setup({
                              inputField : "FechaRecepcionFin",
                              ifFormat : "%Y-%m-%d",
                              daFormat : "%Y-%m-%d",
                              button   : "btnFechaRecepcionFin"
                            });
                        </script></td>                     
                    </tr>
                      <tr>
                      <td nowrap="nowrap"><label class="label" for="txtCod">Docente</label></td>
                      <td colspan="4" nowrap="nowrap">
                          <input class="text" type="text" name="txtDocente" id="txtDocente"/></td>
                  </tr>
                  </table>
                </td>
              </tr>
            </table>
            <div align="center">
              <input class="button" type="button" value="Buscar" onclick="findControl();"/>
            </div>
          </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);
    $('txtivnid').value = "";
    findControl();
  </script>
  <?php
}
if(isset($update)){
  ?>
  <script>
    elementLoad.show(undefined,"Se actualizo la ficha satisfactoriamente.");
    setTimeout("elementLoad.hide()",5000);
    $('txtivnid').value = "";
    findControl();
  </script>
  <?php
}
if(isset($delete)){
  ?>
  <script>
    elementLoad.show(undefined,"Se elimino la ficha satisfactoriamente."); 
    findControl();
  </script>
  <?php 
  
}
?>