<style type="text/css">
    #autoSuggestionsList > li {
        background: none repeat scroll 0 0 #F3F3F3;
        border-bottom: 1px solid #E3E3E3;
        list-style: none outside none;
        padding: 3px 15px 3px 15px;
        text-align: left;
    }
    #autoSuggestionsList > li a { color: #800000; }
    .auto_list {
        border: 1px solid #E3E3E3;
        border-radius: 5px 5px 5px 5px;
        position: absolute;
    }
</style>
<script type="text/javascript">

    function ajaxSearch() {

        var input_data = $('#pi_name').val();
        if (input_data.length === 0) {
            $('#suggestions').hide();
        } else {

            var post_data = {
                'pi_name': input_data,
                '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
            };

            $.ajax({
                type: "POST",
                url: "<?php echo base_url(); ?>charge/admin_charge/autocomplete/",
                data: post_data,
                success: function(data) {
                    // return success
                    if (data.length > 0) {
                        $('#suggestions').show();
                        $('#autoSuggestionsList').addClass('auto_list');
                        $('#autoSuggestionsList').html(data);
                    }
                }
            });

        }
    }


    $(document).on("click", ".branch", function() {
//        alert("ahmed");

        var br_id = this.id;
        var br_data = br_id.split("-");
        jQuery("input[name='pi_name']").val(br_data[0]);
        jQuery("#chg_pi_id").html(br_data[1]);
        jQuery("input[name='chg_pi_id']").val(br_data[1]);
        jQuery("input[name='chg_branch_id']").val(br_data[2]);
        jQuery("#branch_name").html(br_data[3]);
        jQuery("input[name='chg_pi_num']").val(br_data[4]);

        jQuery("#suggestions").hide();
    });

    // enable disable checkbox
    $(function() {
        $('#chk1').click(function() {
            var cb1 = $('#chk1').is(':checked');
            $('#date2').prop('disabled', !cb1);
        });
    });

</script>
<script type="text/javascript">

    $(document).ready(function() {
        $("#date, #date2,#date3,#date4").datepicker();
        $("#date,#date2,#date3,#date4 ").datepicker("option", "dateFormat", "yy/mm/dd");

        var d = new Date();
        var twoDigitMonth = (d.getMonth() + 1) + "";
        if (twoDigitMonth.length == 1)
            twoDigitMonth = "0" + twoDigitMonth;
        var twoDigitDate = d.getDate() + "";
        if (twoDigitDate.length == 1)
            twoDigitDate = "0" + twoDigitDate;
        var todaysM = d.getFullYear() + "/" + twoDigitMonth + "/" + twoDigitDate;
        if ($("#date,#date2,#date3,#date4").val() == "") {
            $("#date,#date2,#date3,#date4").val(todaysM);
        }
    });

</script>
<!-- Form Start -->
<div class="block">
    <div class="title lightTextShadow">المصروفات الشخصية</div>
    <div class="content">
        <?php echo form_open('charge/admin_charge/create', array('id' => 'charge_new')) ?>

        <fieldset class="form boxStyle">                            
            <?php
            echo $this->template->flash_msg();
            ?>

            <!-- /////////// 3 columns start /////////-->
            <div class="inlineBlock">
                <input type="hidden" name="chg_pi_id" value="" />
                <label class="label">رقم الحالة :</label><span id="chg_pi_id"></span><br />
            </div>

            <div class="inlineBlock">
                <label class="label">تاريخ الصرف :</label>
                <input class="inputDate textBox rnd5" name="chg_date"  id="date" value="" /><br />
            </div>



            <div class="inlineBlock">
                <label class="label">الفرع :</label><span id="branch_name"></span><br />
                <input type="hidden" name="chg_branch_id" value="" />
            </div><br /><br />

            <div class="inlineBlock">
                <label for="suggest1" class="label">اسم المريض <em>*</em>:</label>
                <input  class="textBox med2 rnd5" name="pi_name" id="pi_name" type="text" onkeyup="ajaxSearch();">
                <input  type="hidden" name="chg_pi_num" id="chg_pi_num" value="">
                <div class="something">
                    <div id="suggestions">
                        <div id="autoSuggestionsList">  
                        </div>
                    </div>
                </div>

                <label for="type" class="label">نوع الصرف <em>*</em>:</label>
                <input id="type" type="text" class="textBox med2 rnd5" name="chg_type" value="<?= set_value('chg_type') ?>"  /><br />
                <?php echo form_error('chg_type'); ?>

            </div>


            <div class="inlineBlock">
                <label for="chg_cost" class="label">التكلفة :</label>
                <input id="chg_price" class="textBox med2 rnd5" name="chg_cost" value="<?= set_value('chg_cost') ?>"/><br />
                <?php echo form_error('chg_cost'); ?><br />

                <label for="chg_phone" class="label">رقم الهاتف :</label>
                <input id="chg_phone" class="textBox med2 rnd5" name="chg_phone" value="<?= set_value('chg_phone') ?>"/>
            </div><br />
            <!-- /////////// 3 columns end /////////-->
            <label for="chg_address" class="label">العنوان :</label>
            <input id="title" class="textBox lrg rnd5" name="chg_address" value="<?= set_value('chg_address') ?>"/><br />

            <label class="label">الإجراءات :</label>
            <textarea rows="6" cols="0" class="textArea lrg rnd5" name="chg_steps"><?= set_value('chg_steps') ?></textarea><br /><br />

            <label class="label">ملاحظات :</label>
            <textarea rows="6" cols="0" class="textArea lrg rnd5" name="chg_notice"><?= set_value('chg_notice') ?></textarea><br /><br />

            <div class="center">
                <input id="clearFilds" type="reset" value="تفريغ الحقول" class="button sub inlineBlock rnd3 lightTextShadow" />
                <input id="print" type="submit" name="action" value="حفظ" class="button sml inlineBlock rnd5 drkTextShadow" />
                <input id="savePrint" type="submit" name="action" value="حفظ وطباعة" class="button sml inlineBlock rnd5 drkTextShadow" />
                <input id="list" type="submit" name="action" value="القائمة" class="button sml inlineBlock rnd5 drkTextShadow" />
            </div>
        </fieldset>
        </form>
    </div>
</div><!-- Form End -->
