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

executeFind = function(str){ 
  //str = str + '&block=001';
  url = "<?=buildUrl('doc/gridFind', "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>
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>
<script language="JavaScript">
findControl = function(){
  
  var pars = $('form1').serialize();
  
	disabledWin.setPathImage('/images/common/progress.gif');
	disabledWin.show(true,true,'resultGrtid');
  
	url = "<?=buildUrl('doc/gridFind', "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();
                                      		}
                                	     });
  
}
</script>

<script language="JavaScript">
resultFind = function(value){

  <? if(isset($iframe)){ ?>
    if(parent.document.getElementById('<?=$iframe?>')){
      var elmIframe = parent.document.getElementById('<?=$iframe?>');
      var elmImp = elmIframe.contentDocument.getElementById('<?=$nameElm?>');
    }else{
      var elmImp = parent.document.getElementById('<?=$nameElm?>');
    }
  <? }else{ ?>
    var elmImp = parent.document.getElementById('<?=$nameElm?>');
  <? } ?>
  
  elmImp.value = value;
  elmImp.onblur();
  
  
  parent.objMainTab.windowsCloseAll();
  
  //elmImp.focus();
    
}
</script>
<?php
//Facultades
$o_DocenteSystemClass = new DocenteSystemClass(new FacultadBean());
$a_Facultad = $o_DocenteSystemClass->getFacultad();
?>
<table class="cuerpo" style="background:#FFFFFF" width="100%" 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;Docente</li></td>
          <td align="right" valign="baseline">
            &nbsp;
          </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="50%" valign="top">
                  <table class="SubCabecera" width="100%" border="0" cellpadding="0" cellspacing="2">
                    <tr>
                      <td width="20%" height="26" nowrap="nowrap"><label class="label" for="txtCodigo">C&oacute;digo : </label></td>
                      <td width="80%" nowrap="nowrap"><input name="txtCodigo" id="txtCodigo" type="text" class="text"/></td>
                    </tr>
                     <tr>
                      <td width="20%" height="26" nowrap="nowrap"><label class="label" for="txtNombre">Nombre : </label></td>
                      <td width="80%" nowrap="nowrap"><input name="txtNombre" id="txtNombre" type="text" class="text"/></td>
                    </tr>
                  </table>
                </td>
                <td width="50%" valign="top">
                  <table class="SubCabecera" width="100%" border="0" cellpadding="0" cellspacing="2">
                    <tr>
                      <td width="20%" height="26" nowrap="nowrap"><label class="label" for="txtFacultad">Facultad : </label></td>
                      <td width="80%" 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 width="20%" height="26" nowrap="nowrap"><label class="label" for="txtNombre">Departamento : </label></td>
                      <td width="80%" nowrap="nowrap"><select name="cboEspecialidad" id="cboEspecialidad" type="text" class="combo"/> <option value="" > - Seleccionar - </option></select></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>

<script>
<? if (isset($value)){ ?>
  $('txtCodigo').value = "<?=$value?>";
<? } ?>
findControl();
</script>