<div class="modal-header">
     <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
     <h4 class="modal-title" id="myModalLabel">Editar Informe</h4>
</div>
<div class="modal-body">
   <form class="form-horizontal" id="FormActualizar" name="formul">
      <div class="form-group">
	 <label for="inputEmail3" class="col-sm-2 control-label">RUT</label>
	 <div class="col-sm-4">
	    <input type="rut" class="form-control" id="rut" name="rut" placeholder="Rut" disabled>
	 </div>
	 <div class="col-sm-2">
	    <input type="dv" class="form-control" id="dv" name="dv" placeholder="Dv" disabled>
	 </div>
      </div>
      <div class="form-group">
	 <label for="inputEmail3" class="col-sm-2 control-label">Nombres</label>
	 <div class="col-sm-3">
	    <input type="text" class="form-control col-sm-4" id="nombres" name="nombres" placeholder="Nombres" disabled>
	 </div>
	 <div class="col-sm-3">
	    <input type="text" class="form-control col-sm-4" id="ap_paterno" name="ap_paterno" placeholder="Ap. Paterno" disabled>
	 </div>
	 <div class="col-sm-3">
	    <input type="text" class="form-control col-sm-4" id="ap_materno" name="ap_materno" placeholder="Ap. Materno" disabled>
	 </div>
      </div>
      <div class="form-group">
	 <label for="inputEmail3" class="col-sm-2 control-label">Detalle de Frascos</label>
	 <div class="col-sm-4">
	    <img id="btn_frasco" class="img-rounded" src="<?php echo base_url(); ?>/assets/images/otro.jpg" style="width: 60px;" title="Nuevo Frasco" onmouseover="$(this).css('cursor','pointer');" >
	 </div>
      </div>
      <div id="frascos">
	 <div class="form-group">
	    <label class="col-sm-2 control-label">Datos de Frasco</label>
	    <div class="col-sm-4">
	       <input type="text" class="form-control" id="rotulos" name="rotulos[]" placeholder="Rotulaci&oacute;n" >
	    </div>
	    <div class="col-sm-4">
	       <input type="text" class="form-control" id="muestras" name="muestras[]" placeholder="N&uacute;mero de Muestras" >
	    </div>
	 </div>
      </div>
      <div class="form-group">
	 <label class="col-sm-2 control-label">C&oacute;digos de Uso Interno</label>
      </div>
      <div class="form-group">
	 <label class="col-sm-2 control-label">0801001</label>
	 <div class="col-sm-4">
	    <input type="text" class="form-control" id="0801001" name="0801001" placeholder="Cantidad" >
	 </div>
      </div>
      <div class="form-group">
	 <label class="col-sm-2 control-label">0801002</label>
	 <div class="col-sm-4">
	    <input type="text" class="form-control" id="0801002" name="0801002" placeholder="Cantidad" >
	 </div>
      </div>
      <div class="form-group">
	 <label class="col-sm-2 control-label">0801003</label>
	 <div class="col-sm-4">
	    <input type="text" class="form-control" id="0801003" name="0801003" placeholder="Cantidad" >
	 </div>
      </div>
      <div class="form-group">
	 <label class="col-sm-2 control-label">0801004</label>
	 <div class="col-sm-4">
	    <input type="text" class="form-control" id="0801004" name="0801004" placeholder="Cantidad" >
	 </div>
      </div>
      <div class="form-group">
	 <label class="col-sm-2 control-label">0801005</label>
	 <div class="col-sm-4">
	    <input type="text" class="form-control" id="0801005" name="0801005" placeholder="Cantidad" >
	 </div>
      </div>
      <div class="form-group">
	 <label class="col-sm-2 control-label">0801006</label>
	 <div class="col-sm-4">
	    <input type="text" class="form-control" id="0801006" name="0801006" placeholder="Cantidad" >
	 </div>
      </div>
      <div class="form-group">
	 <label class="col-sm-2 control-label">0801007</label>
	 <div class="col-sm-4">
	    <input type="text" class="form-control" id="0801007" name="0801007" placeholder="Cantidad" >
	 </div>
      </div>
      <div class="form-group">
	 <label class="col-sm-2 control-label">0801008</label>
	 <div class="col-sm-4">
	    <input type="text" class="form-control" id="0801008" name="0801008" placeholder="Cantidad" >
	 </div>
      </div>
      <div class="form-group">
	 <div class="col-sm-6">
	    <center>
	    <button type="button" id="btn_actualizar" class="btn btn-md btn-primary">Actualizar</button>
	    <button type="button" id="btn_borrar" class="btn btn-md btn-warning">Borrar</button>
	    </center>
	 </div>                
	 <div class="col-sm-6">
	    <center>
	       <button type="button" id="btn_cerrar" class="btn btn-md btn-default">Cerrar</button>
	    </center>
	 </div>
      </div>                                                              
   </form>
</div>            
        
<script>
$(document).ready(function(){
        
        var datos =  <?php echo $persona; ?>;
        $('#rut').val(datos[0].rut);
        $('#dv').val(datos[0].dv);
        $('#nombres').val(datos[0].nombres);
        $('#ap_paterno').val(datos[0].ap_paterno);
        $('#ap_materno').val(datos[0].ap_materno);
   
        $('#FormActualizar').bootstrapValidator({
        feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields: {
            rut: {
                validators: {
                    notEmpty: {
                    },
                    stringLength: {
                        min: 7,
                        max: 8
                    },
                    regexp: {
                        regexp: /^[0-9]+$/,
                        message: 'Solo debe ingresar numeros'
                    }
                }
            },
            dv: {
                validators: {
                    notEmpty: {
                    },
                    stringLength: {
                        min: 1,
                        max: 1
                    },
                    regexp: {
                        regexp: /^[k-kK-K0-9]+$/,
                        message: 'Solo Digitos Validos'
                    }                    
                }
            },
            nombres: {
                validators: {
                    notEmpty: {
                    }
                }
            },
            ap_paterno: {
                validators: {
                    notEmpty: {
                    }
                }
            },
            ap_materno: {
                validators: {
                    notEmpty: {
                    }
                }
            }
         
        },      
        onSuccess: function(e) {
	       e.preventDefault();
	       var rotulos = "";
	       var array_rotulos = document.formul.elements["rotulos[]"];
	       for(i=0;i<array_rotulos.length;i++){
		  rotulos = rotulos + '"' + array_rotulos[i].value + '"';
		  if (array_rotulos.length != (i+1))
		     rotulos = rotulos + ',';
	       }
	       
	       var muestras = "";
	       var array_muestras = document.formul.elements["muestras[]"];
	       var array_muestras_muestras = "";
	       for(i=0;i<array_muestras.length;i++){
		  muestras = muestras + '"' + array_muestras[i].value + '"';
		  if (array_muestras.length != (i+1))
		     muestras = muestras + ',';
	       }
	       var datos = '{'
		     + '"rut" : "' + $('#rut').val() + '" ,'
		     + '"dv" : "' + $('#dv').val() + '" ,'
		     + '"nombres" : "' + $('#nombres').val() + '", '
		     + '"paterno" : "' + $('#ap_paterno').val() + '", '
		     + '"materno" : "' + $('#ap_materno').val() + '", '
		     + '"rotulos" : ['  
			+ rotulos
			+ '], '
		     + '"muestras" : ['  
			+ muestras
			+ '], '
		     + '"0801001" : "' + $('#0801001').val() + '", '
		     + '"0801002" : "' + $('#0801002').val() + '", '
		     + '"0801003" : "' + $('#0801003').val() + '", '
		     + '"0801004" : "' + $('#0801004').val() + '", '
		     + '"0801005" : "' + $('#0801005').val() + '", '
		     + '"0801006" : "' + $('#0801006').val() + '", '
		     + '"0801007" : "' + $('#0801007').val() + '", '
		     + '"0801008" : "' + $('#0801008').val() + '"'
		     +'}';
	       var parametros = JSON.parse(datos);
	       console.log(parametros);
	       $.ajax({
		     data:  parametros,
		     url:   '<?php echo base_url();?>index.php/inicio/actualizar_estadistica',
		     type:  'post',
		     async:false,
		     success:  function (response) {
			   eval(response);
			   $('#ventana_modal').modal('hide'); 
			   $.ajax({
			       data:  null,
			       url:   '<?php echo base_url();?>index.php/inicio/tabla_estadistica',
			       type:  'post',
			       async:false,
			       success:  function (response) {                
				   $('#contenido_tabla').html(response); 
			       }
			  });   
		      }
	       });
                
        }        
        });	
        $('#btn_actualizar').click(function() {
            $('#FormActualizar').bootstrapValidator('validate');
        });
        
        $('#btn_borrar').click(function() {
             if(confirm("Esta seguro de borrar el registro?")) {                
				var parametros = {
						"rut" : $('#rut').val()                                                
				};
				$.ajax({
						data:  parametros,
						url:   '<?php echo base_url();?>index.php/inicio/eliminar_persona',
						type:  'post',
                                                async:false,
						success:  function (response) {
                                                        eval(response);
                                                        $('#ventana_modal').modal('hide'); 
                                                        $.ajax({
                                                            data:  null,
                                                            url:   '<?php echo base_url();?>index.php/inicio/tabla_personas',
                                                            type:  'post',
                                                            async:false,
                                                            success:  function (response) {                
                                                                $('#contenido_tabla').html(response); 
                                                            }
                                                       });   
						}
				});                 
             }
        });        
        
        $('#btn_cerrar').click(function() {
            $('#ventana_modal').modal('hide');
        });             

	 $('#btn_frasco').click(function() {
	    var linea = '  <div class="form-group">'
		     + '      <label class="col-sm-2 control-label">Datos de Frasco </label>'
		     + '      <div class="col-sm-4">'
		     + '	 <input type="text" class="form-control" id="rotulo1" name="rotulos[]" placeholder="Rotulaci&oacute;n" >'
		     + '      </div>'
		     + '      <div class="col-sm-4">'
		     + '	 <input type="text" class="form-control" id="muestra1" name="muestras[]" placeholder="N&uacute;mero de Muestras" >'
		     + '      </div>'
		     + '   </div>';
	    $('#frascos').append(linea);
	 })
});

</script>