<link rel="stylesheet" href="<?php echo base_url();?>assets/js/validationEngine.jquery.css" type="text/css" />
<link rel="stylesheet" href="<?php echo base_url();?>assets/css/cust_paginition.css" type="text/css" />
<div class="" id="addSub">
<div class="modal-dialog">
<div class="modal-content">
<!-- Modal heading -->
<div class="modal-header">
    <a class="btn  pull-right mar" href="<?php echo base_url(); ?>index.php/subscriber/subscriber_list"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button> </a>
    <h3 class="modal-title" align="left">Add Vouchers Details</h3>
</div>
<!-- // Modal heading END -->
<!-- Modal body -->
<div class="modal-body">
<div class="innerAll">
<div class="innerLR">
<form class="form-horizontal" role="form" id = "add_subscriber" action="<?php echo base_url(); ?>index.php/vouchers/add_vouchers" method = "post" enctype="multipart/form-data">
<?php $this->load->view('admin/flashdata_admin'); ?>
    <div id="errorMsg" style="text-align: center"></div>
<div class = "form-group mmar" id="give_msgs" style="text-align: center"></div>
<div class="form-group mmar">
    <label  class="col-sm-4 control-label text-left">Voucher Name: </label>
    <div class="col-sm-8">
        <input type="text" class="form-control validate[required] text-input" name = "voucher_name" id="voucher_name" value="<?php echo $voucher_name;?>" />
    </div>
</div>
<div class="form-group mmar">
    <label  class="col-sm-4 control-label text-left">Voucher Amount: </label>
    <div class="col-sm-8">
        <input type="text" class="form-control validate[required] text-input" name = "voucher_amount" id="voucher_amount" value="<?php echo $voucher_amount;?>"/>
    </div>
</div>
<div class="form-group mmar">
    <label  class="col-sm-4 control-label text-left">Valid Until: </label>
    <div class="col-sm-8">
        <input type="text" class="form-control validate[required] text-input date" name = "valid_until" id="valid_until" data-date-format="d-M-yyyy" readonly="readonly" value="<?php echo $valid_until;?>"/>
    </div>
</div>
<div class="form-group">
    <div class="col-sm-offset-4 col-sm-8">
        <input type="hidden" id="system_base_url" value="<?php echo base_url();?>">
        <input type="hidden" name="voucher_id" value="<?php echo $this->input->get('voucher_id'); ?>" />
        <button type="submit" class="btn btn-primary" id="submit_sub">Submit</button>
    </div>
</div>
</form>
</div>
</div>
</div>
<!-- // Modal body END -->
</div>
</div>
</div>
<script src="<?php echo base_url();?>assets/js/main.js" type="text/javascript"></script>
<script src="<?php echo base_url();?>assets/js/custom.js" type="text/javascript"></script>
<script src="<?php echo base_url();?>assets/js/jquery.validationEngine-en.js" type="text/javascript"></script>
<script src="<?php echo base_url();?>assets/js/jquery.validationEngine.js" type="text/javascript"></script>

<script src="<?php echo base_url();?>assets/plugins/forms_elements_bootstrap-datepicker/js/bootstrap-datepicker.js"></script>
<script>
    $(document).ready(function() {
        var system_base_url = $("#system_base_url").val();
        $("#add_subscriber").validationEngine();
        $("#submit_sub").click(function(){
            var voucher_name = $("#voucher_name").val();
            var voucher_amount = $("#voucher_amount").val();
            var valid_until = $("#valid_until").val();

            if(voucher_name == '') {
                $("#errorMsg").html('<span style="color: red">Enter Voucher Name</span>');
                return false;
            }

            if(valid_until == '') {
                $("#errorMsg").html('<span style="color: red">Enter Valid Until</span>');
                return false;
            }

            var count = 0;
            $.ajax({
                url:"<?php echo base_url(); ?>index.php/vouchers/checkVoucher",
                'data' : {
                    'voucher_name' :voucher_name
                },
                'type' : 'GET',
                async: false,
                success:function(result){
                    if (result > 0) {
                        var msg = "<p style='color: red'>Voucher already exists</p>"
                        $("#errorMsg").html(msg);
                        count = 1;
                    }
                }
            });

        if (count > 0) {
                return false;
            }
        });
    });
</script>