<div style="display:none">
    <div id="addMiscPopup" class="popupouter">
        <fieldset style="margin: 0 auto;padding: 0px">
            <div class="popup-body row">
                <div id="addMiscPopupContent" class="warningPopupContent col-lg-12 col-md-12 col-sm-12 col-xs-12">
                    <?php echo form_open('gkpos/orders/addmisc/', array('id' => 'addmisc_form', 'enctype' => 'multipart/form-data', 'class' => 'form-horizontal')); ?>
                    <?php $OrderServiceData = $this->Orders_Model->get_servicecharge($this->Orders_Model->get_current_orderid()); ?>
                    <div class="form-group form-group-sm">	
                        <?php echo form_label($this->lang->line('gkpos_name'), 'misc_name', array('class' => 'control-label col-lg-4 col-md-4 col-sm-4 col-xs-4 text-capitalizerequired')); ?>
                        <div class="col-lg-8 col-md-8 col-sm-8 col-xs-8">
                            <div class="input-group">
                                <span class="input-group-addon" style="background-color: #FF0000;"><i class="fa fa-table" aria-hidden="true"></i></span>
                                <input name="menu_title" class="form-control required"  type="text" id="misc_name">
                            </div>
                        </div>
                    </div>
                    <div class="form-group form-group-sm">	
                        <?php echo form_label($this->lang->line('gkpos_price'), 'misc_price', array('class' => 'control-label col-lg-4 col-md-4 col-sm-4 col-xs-4 text-capitalizerequired')); ?>
                        <div class="col-lg-8 col-md-8 col-sm-8 col-xs-8">
                            <div class="input-group">
                                <span class="input-group-addon" style="background-color: #FF0000;"><i class="fa fa-money" aria-hidden="true"></i></span>
                                <input name="price" class="form-control required"  type="text" id="misc_price">
                            </div>
                        </div>
                    </div>
                    <div class="form-group form-group-sm">	
                        <?php echo form_label($this->lang->line('gkpos_quantity'), 'misc_quantity', array('class' => 'control-label col-lg-4 col-md-4 col-sm-4 col-xs-4 text-capitalizerequired')); ?>
                        <div class="col-lg-8 col-md-8 col-sm-8 col-xs-8">
                            <div class="input-group">
                                <span class="input-group-addon" style="background-color: #FF0000;"><i class="fa fa-bars" aria-hidden="true"></i></span>
                                <input name="quantity" class="form-control required"  type="text" id="misc_quantity">
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="discount" class="col-lg-4 col-md-4 col-sm-4 col-xs-4 control-label required"><?php echo $this->lang->line('gkpos_category_type') ?></label>
                        <div class="col-lg-8 col-md-8 col-sm-8 col-xs-8">
                            <label class="radio-inline text-capitalizerequired"><input type="radio" name="type" id="type1" value="1" <?php (isset($type) && $type == "1") ? print "checked" : '' ?> ><?php echo $this->lang->line('gkpos_food') ?></label>
                            <label class="radio-inline text-capitalizerequired"><input type="radio" name="type" id="type2" value="2" <?php (isset($type) && $type == "2") ? print "checked" : '' ?>><?php echo $this->lang->line('gkpos_non_food') ?></label>
                        </div>
                    </div>
                    <div class="fieldset">
                        <legend style="font-size: 9px;"><?php echo $this->lang->line('gkpos_kitchen_print_setting') ?></legend>
                        <div class="form-group" style="margin:10px 2px; ">
                            <?php $printingOptions = printing_options(); ?>
                            <?php foreach ($printingOptions as $key => $prinOption): ?>
                                <label class="radio-inline text-capitalize"><input type="radio" name="print_option" id="printerSet<?php $key ?>" value="<?php echo $key ?>" ><?php echo $prinOption ?></label>
                            <?php endforeach; ?>
                        </div>
                    </div>
                    <ul id="addmisc_form_error_message_box" class="error_message_box"></ul>
                    <div class="form-group form-group-md" style="margin-bottom: 20px;">	
                        <div class="col-md-12">
                            <input type="hidden" id="addMiscOrderId" name="order_id" value="<?php isset($order_id) ? print $order_id : print $this->Orders_Model->get_current_orderid() ?>">
                            <input type="hidden" id="miscLine" name="misc_line"/>
                            <input class="form-submit-button mainsystembg2 waiting-bg img-responsive delivery-info-submit-btn" type="submit" name="submit_form" value="<?php echo $this->lang->line('gkpos_numpad_key_enter') ?>" onclick="saveMisc()">
                        </div>
                    </div>
                    <?php echo form_close(); ?>
                </div>
            </div>
        </fieldset>
    </div>
    <script>
        function addMisc(order_id) {
            var orderId = $('#orderId').val();
            if ((!order_id || !orderId) && order_id != orderId) {
                jQuery('#cartWarningHeader').text("<?php echo $this->lang->line('gkpos_cart_warning') ?>");
                jQuery('#cartWarningContent').text("<?php echo $this->lang->line('gkpos_make_order_sure') ?>");
                jQuery(".cartWarning").colorbox({inline: true, slideshow: false, scrolling: false, height: "250px", open: true, width: '100%', maxWidth: '400px', 'left': '10%'});
                return false;
            } else {
                $('#addMiscOrderId').val(order_id);
                $('#misc_name').val('');
                $('#misc_price').val('');
                $('#misc_quantity').val('');
                $("input[name=type]").prop('checked', false);
                $("input[name=print_option]").prop('checked', false);
                var addMiscPopup = $("#addMiscPopup").html();
                $('#categoryTitle').html('<p class="sidebar-heading text-uppercase"><?php echo $this->lang->line('gkpos_add_misc') ?></p>');
                $('#menuListArea').html(addMiscPopup);
                return false;
            }
        }

        function saveMisc() {
            $('#addmisc_form').validate({
                submitHandler: function () {
                    var myform = document.getElementById('addmisc_form');
                    var formdata = new FormData(myform);
                    $.ajax({
                        url: $('#addmisc_form').attr('action'),
                        data: formdata,
                        cache: false,
                        processData: false,
                        contentType: false,
                        type: 'POST',
                        dataType: 'json',
                        success: function (response) {
                            if (response.success) {
                                jQuery.colorbox.close();
                                $('#misc_name').val('');
                                $('#misc_price').val('');
                                $('#misc_quantity').val('');
                                $("input[name=type]").prop('checked', false);
                                $("input[name=print_option]").prop('checked', false);
                                $('#selectedRow').val('');
                                loadCart(response.order_id, response.line);
                                $('#menuListArea').html('');
                                $('#categoryTitle').html('<p class="sidebar-heading text-uppercase"><?php echo $this->lang->line('gkpos_click_category_mesage') ?></p>');
                            } else {
                                alert(response.message);
                            }
                        }
                    });
                },
                errorClass: "has-error",
                errorLabelContainer: "#addmisc_form_error_message_box",
                wrapper: "li",
                highlight: function (e) {
                    $(e).closest('.form-group').addClass('has-error');
                },
                unhighlight: function (e) {
                    $(e).closest('.form-group').removeClass('has-error');
                },
                rules: {
                    menu_title: {
                        required: true
                    },
                    price: {
                        number: true,
                        required: true
                    },
                    quantity: {
                        number: true,
                        required: true
                    },
                    type: "required",
                    print_option: {
                        required: function () {
                            return $("#type1").is(":checked");
                        }
                    }
                },
                messages: {
                    menu_title: "Please specify valid name",
                    price: "Price is required in number",
                    quantity: "Quantity is required in number",
                    print_option: "<?php echo $this->lang->line('gkpos_print_option_required'); ?>",
                    type: "<?php echo $this->lang->line('gkpos_select_category_food_type') ?>"
                }
            });
        }
    </script>  
</div>