<?php Yii::app()->clientScript->registerScriptFile(Yii::app()->request->baseUrl.'/js/jquery.mask.min.js',CClientScript::POS_HEAD); ?>
<?php Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl.'/js/fileinput.js',CClientScript::POS_END);
        Yii::app()->clientScript->registerCssFile(Yii::app()->baseUrl.'/css/fileinput.css');?>


<h3><center>Solicitud de Mutuo Auxilio</center></h3>

	<?php
	$form=$this->beginWidget('bootstrap.widgets.TbActiveForm', array(
		'id'=>'solicitudma-form',
		'type' => 'horizontal',
		'focus'=>array($model,'cedula'),
        'enableAjaxValidation' => false,
        'enableClientValidation' => true,
        'clientOptions' => array(
	        'validateOnSubmit' => true,
	        'validateOnChange' => true,
	        'validateOnType' => true,
	        ),
        'htmlOptions' => array('onsubmit' => 'return verificarCheckbox()'),
		));
	?>
	
	<fieldset>  <!--Datos del asociado-->
		<legend style=" font-size: 17px;"><b>Datos del asociado</b></legend>            
		<table class="table table-bordered">
	        <tr>
	            <td style="width: 25%"><b>C&eacute;dula</b></td>
	            <td style="width: 25%"><div id="cedula" class="datosPersonales"><?php echo (!empty($data['ci']))?$data['ci']:""; ?></div></td>
	            <td style="width: 20%"><b>Nombres y apellidos</b></td>
	            <td style="width: 30%"><div id="nombres_apellidos" class="datosPersonales"><?php echo (!empty($data['nombre_completo']))?$data['nombre_completo']:""; ?></div></td>
	        </tr>
	        <tr>
	            <td><b>Empresa</b></td>
	            <td><div id="empresa" class="datosPersonales"><?php echo (!empty($data['lugar_trabajo']))?$data['lugar_trabajo']:""; ?></div></td>
	            <td><b>Unidad</b></td>
	            <td><div id="unidad" class="datosPersonales"><?php echo (!empty($data['unidad']))?$data['unidad']:""; ?></div></td>
	        </tr>
	        <tr>
	            <td><b>&Uacute;ltimo sueldo</b></td>
	            <td><div id="sueldo" class="datosPersonales"><?php echo (!empty($data['sueldo']))?$data['sueldo']:""; ?></div></td>
	            <td><b>Porcentaje de aporte</b></td>
	            <td><div id="porcentaje" class="datosPersonales"><?php echo (!empty($data['porc']))?$data['porc']:""; ?></div></td>
	        </tr>
	        <tr>
	            <td><b>Fecha de inscripci&oacute;n</b></td>
	            <td><div id="fecha_inscripcion" class="datosPersonales"><?php echo (!empty($data['f_ingreso']))?$data['f_ingreso']:""; ?></div></td>
	            <td><b>Estatus</b></td>
	            <td><div id="estatus" class="datosPersonales"><?php echo (!empty($data['status']))?$data['status']:""; ?></div></td>
	        </tr>	        
	    </table>
	</fieldset> <!--fin datos del asociado-->
	
	<?php if (!empty($data['nobenef'])) { ?>

		<span id="nobenef" class="help-inline error"><?php echo $data['nobenef']; ?></span>   <!--alerta de beneficiarios-->
	
	<?php }else{ ?>

	<div id="asociado_activo">
		<div id="datos_fallecido">
			<fieldset>  <!--Datos del beneficiario/fallecido-->
				<legend style=" font-size: 17px;"><b>Beneficiarios</b></legend>            
				
				<?php $this->widget('ext.selgridview.BootSelGridView',
									array(
					                	'type' => 'bordered',
					                    'id'=>'beneficiarios-grid',
					                    'dataProvider'=>$modelBeneficiario->searchBenefid($modelAsociado->idasociado),
					                    'selectableRows'=> 1,

					                    'columns'=>array(
					                            array(
					                            'id'=>'seleccion',
					                            'class' => 'CCheckBoxColumn',
					                            'checkBoxHtmlOptions' => array('onchange'=>'showCampoFecha()'),
					                            ),

					                            
					                            array('header'=>'Nombre',
					                            		'value'=>'($data->nombre)'),

					                            array('header'=>'Apellido',
					                            		'value'=>'($data->apellido)'),

					                            array('header'=>'Cédula',
					                            		'value'=>'($data->cedula)'),

					                            array('header'=>'Fecha de Nacimiento',
					                            		'value'=>'date(\'d-m-Y\' ,strtotime($data->fecha))'),

					                            array('header'=>'Parentesco',
					                            		'value'=>'($data->parent->descripcion)'),
					                    ),
	                    			)
	                    		); 
	            ?>
	            <div id="selGriderror"></div>
	            <div id="f_fallece"><?php echo $form->labelEx($model, 'fecha_Bfallece'); ?>
	            	<?php $this->widget('zii.widgets.jui.CJuiDatePicker', array(
		                                        'model' => $model,
		                                        'attribute' => 'fecha_Bfallece',
		                                        'value' => $model->fecha_Bfallece,
		                                        'language' => 'es',
		                                        'htmlOptions' => array('readonly' => "readonly", 'class' => 'input-xlarge', 'id'=>'f_deceso'),
		                                        //additional javascript options for the date picker plugin
		                                        'options' => array(
		                                            'autoSize' => true,
		                                            // 'defaultDate'=>$model->fechanacimiento,
		                                            //'dateFormat'=>'yy-m-d',
		                                            'dateFormat' => 'dd-mm-yy',
		                                            'buttonImage' => Yii::app()->baseUrl . '/images/calendar.png',
		                                            'buttonImageOnly' => true,
		                                            'buttonText' => 'Escoger fecha',
		                                            'selectOtherMonths' => true,
		                                            'showAnim' => 'slide',
		                                            'showButtonPanel' => true,
		                                            'showOn' => 'button',
		                                            'changeMonth' => 'true',
		                                            'changeYear' => 'true',
		                                            'yearRange' => "1900:+nn",
		                                            'maxDate'=> "+0D",
		                                        ),
		                                    ));
		                              ?></div>
		        <div id="error_fecha"></div>
			</fieldset> <!--fin datos del beneficiario/fallecido-->
		</div>
	
		<br><br>
		<div class="form-actions"  style="text-align: center">
		        <?php $this->widget('bootstrap.widgets.TbButton',
		        	array(
						'buttonType' => 'submit',
						'type' => 'success',
			            'icon'=>'icon-ok',
						'label' => 'Realizar solicitud',
						'htmlOptions' => array(
										'id' => 'btn_regSolicitud',
										),
					)
		    	);?>
		
		</div><br>
	</div>
	<div id="msgerror"></div>

	<?php } ?>

<?php $this->endWidget(); ?>

<br>	

<?php Yii::app()->clientScript->registerScript('Solicitudma', '

	$(document).ready(function(){

		$("#f_fallece").hide();

		$("form").keypress(function(e) {
                                if (e.which == 13) {
                                    return false;
                                }
                            });
	});

	function showCampoFecha(){

		var check = $("table.items tbody tr td input:checkbox");
		var row = $("table.items tbody tr");
		var fecha = $("#f_deceso");
		
		check.each(function(){

			if (row.hasClass("selected")) {
				
				$("#f_fallece").show(0500);
				$("#selGriderror").html("");
				$("#error_fecha").html("");
			
			}else{

				$("#f_fallece").hide(0500);
				fecha.val("");
				$("#error_fecha").html("");
			}
		});
	}

	//comprobacion de seleccion de checkboxes de la tabla de beneficiarios cargados
	function verificarCheckbox(){

		var checkbox = $("#beneficiarios-grid").selGridView("getAllSelection");
		var filas = $(".items tbody tr").length;
		var fecha = $("#f_deceso").val();
					

		if (filas <= 0) {
				
		
			$("#selGriderror").html("<span class=\"help-inline error\"><b>Debe cargar un beneficiario antes de realizar una solicitud!.</b></span>");
			return false;
		
		}else{

			if (checkbox == "") {

				$("#selGriderror").show(0500);
				$("#selGriderror").html("<span class=\"help-inline error\"><b>Debe seleccionar el beneficiario fallecido de la lista de beneficiarios para procesar la solicitud!</b></span>");
				return false;

			}else{

				$("#selGriderror").html("");

				if (fecha == "") {
					
					$("#error_fecha").html("<span class=\"help-inline error\"><b>Debe introducir la fecha de deceso del beneficiario para proceder!</b></span>");
					return false;

				}else{
					
					$("#selGriderror").html("");
					$("#error_fecha").html("");
					return false;

				}
			}
		}		
	}

',CClientScript::POS_HEAD); ?>