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

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

executeFind = function(str, action){
  if(typeof(action) == 'undefined'){
	  url = "<?=buildUrl('covid19/gridgenerar', "block=".$block)?>";
	}else{
	  switch (action){
		case 'addpays':
	    			if($('cboSucursal').selectedIndex > 0){
	    				if($('cboMercado').selectedIndex > 0){
							parent.objMainTab.reqBody('<?=buildUrl('covid19/generar')?>','001&'+str); 
						}else{
							alert('Debe de seleccionar el Mercado')
							return;
						}
	    			}else{
	    				alert('Debe de seleccionar un Sucursal')
	    				return;
	    			}
	    			break;
	    case 'excel': parent.objMainTab.reqBody('<?=buildUrl('cli/excel')?>','001&'+str); break;
	    case 'pdf': parent.objMainTab.reqBody('<?=buildUrl('cli/pdf')?>','001&'+str); break;	    
	  }
	  
	  return;
	}
  //str = str + '&block=001';
  url = "<?=buildUrl('covid19/gridgenerar', "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>
findControl = function(){
  
  var pars = $('form1').serialize();
  
	disabledWin.setPathImage('/images/common/progress.gif');
	disabledWin.show(true,true,'resultGrtid');
  
	url = "<?=buildUrl('covid19/gridgenerar', "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){
  if(confirm("�Esta seguro de eliminar la ficha del Cliente con Id : "+id+ " ?")){
      parent.objMainTab.reqBody('<?=buildUrl('cli/delete')?>','&delete=1&cod=jj&id='+id);
  }
  
}

acutalizarMercado = function(destino,elm){
  $(destino).options.length = 1;
  var url = '<?=buildUrlComplet('mnt.php/ajax/request')?>';
  var pars = 'type=getMercado&nombreElm='+destino+'&value='+elm.value;
  
	var myAjax = new Ajax.Request(
                            		url, 
                            		{
                            			method: 'get', 
                            			parameters: pars, 
                            			onComplete: actualizaJSON
                            		});
}

</script>
<script>
acutalizarRepresentante = function(destino,elm){
  $(destino).options.length = 1;
  var url = '<?=buildUrlComplet('mnt.php/ajax/request')?>';
  var pars = 'type=getRepresentanteUser&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
$o_crcovid19FN = new CrCovid19paramFN();
$a_o_crcovid19FN = $o_crcovid19FN->select();
if(is_array($a_o_crcovid19FN)){
	$v_crcovid19FN = $a_o_crcovid19FN[0];
	$fechaParo		= $v_crcovid19FN->getFechapara();//"2020-03-17";
	$fechaReinicio	= $v_crcovid19FN->getFechareinicio(); //"2020-04-27";
}else{
	exit("Debe de ");
}

if($control){
	
	///////////////////////////////////////////////
	// Antes debo validar si no existe cabecera
	
	grabar_reprogramacioncovid19($cboSucursal,$cboMercado,$fechaParo,$fechaReinicio,myUser::getUser()->getUserId());
	  
	//exit(" <script language=\"JavaScript\">
    //  parent.objMainTab.reqBody('".buildUrl('covid19/list')."','&block=001&insert=1&idMercado=".$cboMercado."');
    // </script>");
}

?>

<img src="/images/common/spacer.gif" width="10">
<table class="cuerpo" style="background: #E3E9E2" width="99%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td valign="top">
      <form name="form1" id="form1" method="POST">
      <input type="hidden" name="control"  id="control" value="1">
      <input type="hidden" name="cboSucursal"  id="cboSucursal" value="<?php echo $cboSucursal;?>">
      <input type="hidden" name="cboMercado"  id="cboMercado" value="<?php echo $cboMercado;?>">
      <input type="hidden" name="fechaParo"  id="fechaParo" value="<?php echo $fechaParo;?>">
      <input type="hidden" name="fechaReinicio"  id="fechaReinicio" value="<?php echo $fechaReinicio;?>">
      <table border="0" cellpadding="0" cellspacing="0" width="100%">
        <tr>
          <td class="titleBody"><li>&nbsp;&nbsp;Reprogramacion Covid-19 </li></td>
          <td align="right" valign="baseline">
          </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="100%" valign="top">
                  <table class="SubCabecera" width="75%" border="0" cellpadding="0" cellspacing="2">
                     <tr>
		                <td height="26" nowrap="nowrap" class="cabecera"><label class="label" for="txtNombre">Sucursal</label></td>
		                <td nowrap="nowrap"><label class="label">
				
					 	            
			                        
			                          <?php 
									  $o_CrSucursalBean = new SucursalBean();
									  $o_CrSucursalBean->setIdSucursal($cboSucursal);
									  $o_CrSucursalDP = new SucursalDP($o_CrSucursalBean);
									  $a_o_CrSucursalDP = $o_CrSucursalDP->select();
										foreach( $a_o_CrSucursalDP as $key => $o_CrSucursalDP){
											$DescripcionSucursal = $o_CrSucursalDP->getDescripcion();
										}
									  echo $DescripcionSucursal;?>
			                    </label>    
		               	</td>
		               	<td height="26" nowrap="nowrap" class="cabecera"><label class="label" for="txtNombre">Mercado</label></td>
		                <td nowrap="nowrap">
						<label class="label">
				
					 	            
			                        
			                          <?php 
									  $o_CrMercadoBean = new MercadoBean();
									  $o_CrMercadoBean->setIdMercado($cboMercado);
									  $o_CrMercadoDP = new MercadoDP($o_CrMercadoBean);
									  $a_o_CrMercadoDP = $o_CrMercadoDP->select();
										foreach( $a_o_CrMercadoDP as $key => $o_CrMercadoDP){
											$DescripcionMercado = $o_CrMercadoDP->getDescripcion();
										}
									  echo $DescripcionMercado;?>
			                    </label>    
		                      	 
		               	</td>
						<td height="26" nowrap="nowrap" class="cabecera"><label class="label" for="txtNombre">Fecha Paro</label></td>
		                <td nowrap="nowrap">
		                      	 <label class="label"><?=$fechaParo?></label> 
		               	</td>
						<td height="26" nowrap="nowrap" class="cabecera"><label class="label" for="txtNombre">Fecha Reinicio</label></td>
		                <td nowrap="nowrap">
		                      	 <label class="label"><?=$fechaReinicio?></label> 
		               	</td>
		            </tr>
					
                  </table>
                </td>
            </table>
          </td>
        </tr>
      </table>
      
      <div id="resultGrtid">
      </div>
    </td>
  </tr>
  <tr>
	<td colspan="10" align="center"><b>
	<input class="button" type="button" value="Cancelar" onclick=""/></b>
	<!--<input class="button" type="submit" value="Grabar" onclick=""/></b>-->
	</td>
  </tr>
  </form>
</table>


<?php
if(isset($insert)){
  ?>
  <script>
    elementLoad.show(undefined,"Se inserto la ficha satisfactoriamente.");
    setTimeout("elementLoad.hide()",5000);
    $('IdCliente').value = "<?=$id?>";
    $('Dni').value = "<?=$Dni?>";
    $('cboEstado').value = "<?=$cboEstado?>";
    $('cboTipoNegocio').value = "<?=$cboTipoNegocio?>";
    $('cboSexo').value = "<?=$cboSexo?>"; 
    /* if ('cboNombres'= 'ApellidoPaterno'){
        $('ApellidoPaterno').value = "<?=$txtNombre?>";
     }else{
        $('Nombres').value = "<?=$txtNombre?>";  
     }*/
    findControl();
  </script>
  <?php
}

  ?>
  <script>
    findControl();
  </script>
  <?php

if(isset($delete)){
  ?>
  <script>
    elementLoad.show(undefined,"Se elimino la ficha satisfactoriamente.");
    setTimeout("elementLoad.hide()",5000);
    $('IdCliente').value = "<?=$id?>";
    $('Dni').value = "<?=$Dni?>";
    $('cboEstado').value = "<?=$cboEstado?>";
    $('cboTipoNegocio').value = "<?=$cboTipoNegocio?>";
    $('cboSexo').value = "<?=$cboSexo?>"; 
    /* if ('cboNombres'= 'ApellidoPaterno'){
        $('ApellidoPaterno').value = "<?=$txtNombre?>";
     }else{
        $('Nombres').value = "<?=$txtNombre?>";  
     }*/
    findControl();
  </script>
  <?php 
  
}
?>