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

<?php

if($control){//cuando se hizo el submit
  
   
   

  if(is_array($tipo)){
    
    $o_TesisBean = new TesisBean();
    $o_TesisBean->setTipoTesisId($cboTipoTesis);
    $o_TesisBean->setDescripcion($txtTitulo);
    $o_TesisBean->setTituloObtener($txtTituloObtener);
    $o_TesisBean->setPalabraClave($txtClave);
    $o_TesisBean->setCodigoBAN($txtCodigoBAN);
    $o_TesisBean->setFilePdf($_FILES);
    $o_TesisBean->setFechaAprobacion($FechaAprobacion);
    $o_TesisBean->setFechaPublicacion($FechaPublicacion);
    $o_TesisBean->setFechaSustentacion($FechaSustentacion);
    $o_TesisBean->setFacultadId($cboFacultad);
    $o_TesisBean->setEspecialidadId($cboEspecialidad);
    $o_TesisBean->setUsuarioRegistro(myUser::getUser()->getUserId());
    $o_TesisBean->setFechaRegistro(date("Y-m-d H:i:s"));
    
       
    while(list($key,$val_tipo)=each($tipo)){
      switch ($val_tipo){
        case "alm":
                 
                $o_TesisAlumnoBean = new TesisAlumnoBean();
                
                $o_AlumnoBean = new AlumnoBean();
                $o_AlumnoBean->setCodigoAlumno($codigo[$key]);
                $o_AlumnoBL = new AlumnoBL();
                $a_ObjectAlumnoBean = $o_AlumnoBL->busquedaAlumno($o_AlumnoBean);
                       
                $o_TesisAlumnoBean->setAlumnosId($a_ObjectAlumnoBean[0]->getAlumnosId());
                $o_TesisAlumnoBean->setParticipacion($part[$key]);
                $o_TesisAlumnoBean->setFechaRegistro(date("Y-m-d H:i:s"));
                $o_TesisAlumnoBean->setUsuarioRegistro(myUser::getUser()->getUserId());
                $a_concatResultA[] = $o_TesisAlumnoBean;
                break;
              
        case "doc":
                        
                $o_TesisDocenteBean = new TesisDocenteBean();
                
                $o_DocenteBean = new DocenteBean();
                $o_DocenteBean->setCodigoDocente($codigo[$key]);
                $o_DocenteBL = new DocenteBL();
                $a_ObjectDocenteBean = $o_DocenteBL->busquedaDocente($o_DocenteBean);
                
                $o_TesisDocenteBean->setDocenteId($a_ObjectDocenteBean[0]->getDocenteId());
                $o_TesisDocenteBean->setParticipacion($part[$key]);
                $o_TesisDocenteBean->setFechaRegistro(date("Y-m-d H:i:s"));
                $o_TesisDocenteBean->setUsuarioRegistro(myUser::getUser()->getUserId());
                $a_concatResultD[] = $o_TesisDocenteBean;
                break;
          
        case "ext":
          
                $o_TesisExternoBean = new TesisExternoBean();

                $o_ExternoBean = new ExternoBean();
                $o_ExternoBean->setCodigo($codigo[$key]);
                $o_ExternoBL = new ExternoBL();
                $a_ObjectExternoBean = $o_ExternoBL->busquedaExterno($o_ExternoBean);
                                
                $o_TesisExternoBean->setExternoId($a_ObjectExternoBean[0]->getExternoId());
                $o_TesisExternoBean->setParticipacion($part[$key]);
                $o_TesisExternoBean->setFechaRegistro(date("Y-m-d H:i:s"));
                $o_TesisExternoBean->setUsuarioRegistro(myUser::getUser()->getUserId());
                $a_concatResultE[] = $o_TesisExternoBean;
                break;
          
      }
    }
    
    $o_TesisBean->setArrayTesisAlumno($a_concatResultA);
    $o_TesisBean->setArrayTesisDocente($a_concatResultD);
    $o_TesisBean->setArrayTesisExterno($a_concatResultE);
    
    $o_TesisSystemClass = new TesisSystemClass($o_TesisBean);
    $bResult = $o_TesisSystemClass->insertTesis();
    
    if($bResult){
    ?>
      <script language="JavaScript">
      parent.objMainTab.reqBody('<?=buildUrl('gge/'.$typeSubmit)?>','&block=001&insert=1&cod=<?=$o_TesisBean->getTesisId()?>');
      </script>
    <?
    }
  }
  
  
}
$o_TesisSystemClass = new TesisSystemClass(new TipoTesisBean());
$a_TipoTesis = $o_TesisSystemClass->getTipoTesis();

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

?>

<script>
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>
<script type="text/javascript">
tinyMCE.init({

mode : "textareas",

theme : "advanced",

elements : "txtTitulo",

theme_advanced_toolbar_align : "left",

theme_advanced_toolbar_location : "top"



});

</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>Gastos</li>
            <span class="subtitle"><I>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:::&nbsp;Gastos Generales</I></span></td>
          <td align="right" valign="baseline">&nbsp;</td>
        </tr>
      </table>
    </td>
  </tr>
      <script type="text/javascript">
        validatePass = function(){
          
            valid.onSubmit = false;
          
        }
      </script>
  <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%">
          <tr>
            <td valign="top">
              <table width="100%" border="0" cellpadding="5" cellspacing="0">
          		<tr>
    				  <td height="0">
    				  <fieldset>
    					<legend class="fielsettex"><I>Asignaci&oacute;n de Gastos</I></legend>
    					 <table width="100%" border="0" cellspacing="2" cellpadding="0">
							  <tr>
								<td nowrap="nowrap" width="10%" class="cabecera"><label class="label req" for="txtRepresentante" >Descripcion</label></td>
								<td nowrap="nowrap" width="65%">
								   <input class="text" type="text" name="Capital" id="Capital" size="35"/>
								</td>
							    </tr>
								<tr>
								 <td width="12%" nowrap="nowrap" class="cabecera"><label class="label req" for="txtCapital" >Ducumento Refer.</label></td>
								 <td nowrap="nowrap" width="65%"><input class="text" type="text" name="Capital" id="Capital" size="35"/></td>
							   </tr>
							   <tr>
								 <td width="12%" nowrap="nowrap" class="cabecera"><label class="label req" for="txtCapital" >Cantidad</label></td>
								 <td nowrap="nowrap" width="65%"><input class="text" type="text" name="Capital" id="Capital" size="10"/></td>
							   </tr>
							    <tr>
									<td height="10" colspan="5">&nbsp;</td>
				  				</tr>
							    <tr>
									<td align="center" colspan="5">
									  <input type="hidden" name="typeSubmit" id="typeSubmit">
									  <!--<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" colspan="5">&nbsp;</td>
				  				</tr>
							</table>
    					</fieldset>				
    				</td>
                </tr>
      </table>
      </form>
			<script type="text/javascript">
				var valid = new Validation('form1', {immediate : true});
			</script>
    </td>
  </tr>
</table>
