<div class="row">
	<h4>Seleccione una acci&oacute;n:</h4>
	<div class="form-group">
		<div class="col-md-6">
			<div class="radio i-checks crediaccion"><label> <input type="radio" id="crediaccion-efectivo" value="0" name="crediaccion"> <i></i> Reintegro en efectivo</label></div>
		</div>
		<div class="col-md-6">
			<div class="radio i-checks crediaccion"><label> <input type="radio" id="crediaccion-abonar" value="1" name="crediaccion" data-display="#creditos-cliente-list"> <i></i>Abonar un cr&eacute;dito existente </label></div>
		</div>
		<div class="clearfix"></div>
	</div>
	
	<div class="row">
		<div class="m-l-md m-r-md" id="creditos-cliente-select-list-wrapper" style="height:200px;overflow:hidden;border:solid 1px #F1F1F1;">
			
			<div class="table-responsive" style="display:none;" id="creditos-cliente-list">
				<table class="table table-striped">
					<thead>
						<tr>
							<th></th>
							<th>ID</th>
							<th>Monto</th>
							<th>Saldo</th>
							<th>Final</th>
							<th>Estado</th>
						</tr>
					</thead>
					<tbody>
						
						<?php if(count($creditos)>0): foreach($creditos as $credito):?>
						<tr data-deuda="<?php echo $credito->id_credito;?>">
							<td><div class="radio i-checks creditoradio"><input type="radio" value="option1" name="deuda"></div></td>
							<td><?php echo $credito->id_credito;?></td>
							<td><?php echo $credito->monto_credito;?></td>
							<td><?php echo $credito->saldo_credito;?></td>
							<td><?php echo $credito->finalizacion_credito;?></td>
							<td>
								<?php switch($credito->estado_credito):
								case 0:?>
								<span class="label label-info">Activo</span>
								<?php break; case 1:?>
								<span class="label">Liquidado</span>
								<?php break; endswitch;?>
							</td>
						</tr>
						<?php endforeach;
						else:?>
							<tr>
								<td colspan="6"><small style="display:block;" class="text-center">No se han encontrados cr&eacute;ditos para este cliente.</small></td>
							</tr>
						<?php endif;?>
					</tbody>
				</table>
			</div>
		</div>
	</div>
	<div class="form-group text-center m-t-md">
		<button type="button"  id="cancel-credit-btn" class="btn btn-danger btn-rounded" onclick="$('#guardar-devolucion-btn').removeAttr('disabled');Custombox.close();">Cancelar</button>
		<button type="button" id="selcredit-btn" class="btn btn-info btn-rounded">Aceptar</button>
	</div>
</div>
<script>
	$(document).ready(function(){
		$("#creditos-cliente-select-list-wrapper").slimScroll({
			height: '200px'
		});
		$('.i-checks').iCheck({
			checkboxClass: 'icheckbox_square-green',
			radioClass: 'iradio_square-green'
		});
		$('.crediaccion input:radio').on('ifChecked', function(event){
			$('#creditos-cliente-select-list-wrapper > div').hide();
			$($(this).attr('data-display')).show();
			$(".creditoradio input:radio").attr('checked', false);
			$('.creditoradio input:radio').iCheck('update');
		});
		$("#selcredit-btn").click(function(){
			if($('#crediaccion-ninguna').is(':checked') || $('#crediaccion-abonar').is(':checked') || $('#crediaccion-efectivo').is(':checked')){
					if($('#crediaccion-efectivo').is(':checked')){
						$("#credito-devolucion").val("efectivo");
						devoluciones.validarDevolucion(jQuery.Event("click",{target:$('#guardar-devolucion-bt')}));
						Custombox.close();
					}else if($('#crediaccion-abonar').is(':checked')){
						if ($("input[name='deuda']:checked").val()) {
							var selRadio=$("input[name='deuda']:checked"); 
							var CreditoID=selRadio.closest('tr').attr('data-deuda');
							$("#credito-devolucion").val(CreditoID);
							devoluciones.validarDevolucion(jQuery.Event("click",{target:$('#guardar-devolucion-bt')}));
							Custombox.close();
						}
						else {
							 toastr.options = {
								"closeButton": true,
								"progressBar": true,
								"positionClass": "toast-top-right"
							}
							toastr.error('Seleccione un cr&eacute;dito de la lista para continuar...');
						}
					}
			}else{
				toastr.options = {
					"closeButton": true,
					"progressBar": true,
					"positionClass": "toast-top-right"
				}
				toastr.error('Seleccione una acci&oacute;n para registrar el abono de esta devoluci&oacute;n');
			}
		});
	});
</script>