<?php use_helper('UrlFunctions'); ?>
<?php use_helper('UtilFunctions');?>
<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>

<?php

if(isset($control)){

	$o_AjuCorrelativoExpDP =  new AjuCorrelativoExpDP();
	
	$o_AjuCorrelativoExpDP->setIdanio($idanio);
	$o_AjuCorrelativoExpDP->setNumeroactual('1');
	$o_AjuCorrelativoExpDP->setEstado($estado);
	$o_AjuCorrelativoExpDP->setFechacreacion(date("Y-m-d H:i:s"));
	$o_AjuCorrelativoExpDP->setUsuariocreacion(myUser::getUser()->getUserId());
	$bResult = $o_AjuCorrelativoExpDP->save();
  
  //exit;
	if($bResult > 0){
		?>
		<script language="JavaScript">
		parent.objMainTab.reqBody('<?=buildUrl('correlativo/list')?>','001&msg=Se registro el correlativo');
		parent.objMainTab.windowsCloseAll();
		</script>
		<?
	}else{
	$mensaje = $bResult;
	}
  
}
$o_AjuCorrelativoExpFN = new AjuCorrelativoExpFN();
$o_AjuCorrelativoExpFN->setEstado('A');
$a_o_AjuCorrelativoExpFN = $o_AjuCorrelativoExpFN->select();

if(is_array($a_o_AjuCorrelativoExpFN)){
	foreach ($a_o_AjuCorrelativoExpFN as $key => $a_o_AjuCorrelativoExpFN){
		$a_anios[] = $a_o_AjuCorrelativoExpFN->getIdanio();
	}
}
 	
   
?>

<img src="/images/common/spacer.gif" width="10">
<table class="cuerpo" width="100%" border="0" cellpadding="0" cellspacing="0">
	<tr>
		<td height="0">
		  <table border="0" cellpadding="0" cellspacing="0" width="100%">
			<tr>
			  <td class="titleBody"><li>Nuevo Correlativo</li></td>
			</tr>
		  </table>
		</td>
	</tr>
    
	<tr>
		<td valign="top">
			<form id="form1" name="form1" method="POST" enctype="multipart/form-data">
				<input type="hidden" name="control" value="1">
		  
				<table hspace="20px" class="marco" width="96%">
					<tr>
						<td valign="top" colspan="2">
				
							<table hspace="1px"  width="100%" style="border:1px solid #d3d3d3; min-height:220px">
								<tr>
									<td height="0">
								  
										<table width="100%" border="0" cellspacing="6" cellpadding="0">
										   
											<tr>
												<td width="20%"><label class="label">Año</label></td>
												<td nowrap="nowrap">
													<select name="anio" id="anio" type="text" class="combo" ><option value="">Seleccione</option>
										            <?php 
										            $anoTope = date(Y) +4;
										            for($anio= date('Y');$anio<=$anoTope;$anio++){
										            	if(!in_array($anio,$a_anios)){?>
															<option value="<?php echo $anio ?>"><?php echo $anio;?></option>
														<?php }
														}?>
										            </select>
												</td>
												<td nowrap="nowrap" width="8%" class="cabecera">&nbsp;</td>
											</tr>
											<tr>
											    <td  width="10%" ><label class="label">Estado</label></td>
												<td nowrap="nowrap" width="38%">
												   <select name="estado" id="estado" class="combo required" title="Seleccione el estado"/> 
													  <option value="" >Seleccione</option>
													  <option value="A" >Activo</option>
													  <option value="I" >Inactivo</option>
													</select>
												</td>
											</tr>  										
											
										</table>
												
									</td>
								</tr>
								<tr>
									<td height="0" width="100%">
										<table width="100%" border="0" cellspacing="0" cellpadding="0">
											<tr>
												<td><img src="/images/common/spacer.gif" width="10"></td>
											</tr>
											<tr>
											  <td align="center">
											  <input type="hidden" name="typeSubmit" id="typeSubmit">
											  <input type="hidden" name="noredir" id="noredir" value="<?=$noredir?>">
											  <input class="button" type="submit" value="Grabar" onclick="$('typeSubmit').value='list';">
											  <input class="button" type="button" value="Cancelar" onclick="document.location.href='<?=buildUrl('texto/list',"block=001")?>';"/>
											  </td>
											</tr>
											<tr>
												<td height="10">&nbsp;</td>
											</tr>
										</table>
								
									</td>
								</tr>
							
							</table>
							
							
						</td>
					</tr>
				</table>
			</form>
				<script type="text/javascript">
					$("#form1").validate();
				 </script>
		</td>
	</tr>
</table>
