<div style="display: none;">
    <div id="menuCustomDealPopup" class="popup-attributes">
        <div class="popup-header toolbar-header">
            <div class="popup-title">
                <?php
                $AllStatus = array('2' => 'Inactive', '3' => 'Active');
                $heading = null;
                if ($selection !== '0') {
                    $heading = get_title('menuselection', array('id' => $selection)) . '-' . get_title('menu', array('id' => $menu));
                } else {
                    $heading = get_title('menu', array('id' => $menu));
                }
                echo ucwords($heading . ' ' . $this->lang->line('custom_deal'));
                ?>

            </div>
            <div class="popup-close-btn" onclick="zamanEposPopupcloser()"><span class="icon icon-cancel"></span></div>
        </div>
        <div class="popup-content">
            <div class="page-loader popup-page-loader" style="display: none;"></div>
            <div class="clearfix">
                <div class="text-center">
                    <?php $menuSelInfo = get_single_record($selection > 0 ? 'menuselection' : 'menu', array('id' => $selection > 0 ? $selection : $menu)); ?>
                    <label class="text-highlight"><input type="checkbox" <?php echo $menuSelInfo->ctop == '2' ? 'checked="checked"' : '' ?> id="cumulativeToppings" onchange="cumulativeFact(this.id, this.value, 'ctop')" value="<?php $selection > 0 ? print'menuselection-' . $selection : print'menu-' . $menu ?>"><?php echo $this->lang->line('use_cumulative_toppings') ?></label>
                    <label class="text-highlight"><input type="checkbox" <?php echo $menuSelInfo->cmod == '2' ? 'checked="checked"' : '' ?> id="cumulativeModifier" onchange="cumulativeFact(this.id, this.value, 'cmod')" value="<?php $selection > 0 ? print'menuselection-' . $selection : print'menu-' . $menu ?>"><?php echo $this->lang->line('use_cumulative_modifiers') ?></label>
                </div>
                <div class="clearfix"></div>
                <div class="caption"><?php echo $this->lang->line('custom_deal') . ' ' . $this->lang->line('Set') ?></div>
                <table class="collection-bg" id="toppingsHeadList">
                    <tr>
                        <th class="text-left"><?php echo $this->lang->line('title') ?></th>
                        <th class="text-center"><?php echo $this->lang->line('min') ?></th>
                        <th class="text-center"><?php echo $this->lang->line('max') ?></th>
                        <th class="text-center"><?php echo $this->lang->line('rel') ?></th>
                        <th class="text-center"><?php echo $this->lang->line('with') ?></th>
                        <th class="text-center"><?php echo $this->lang->line('status') ?></th>
                        <th class="text-center"><?php echo $this->lang->line('items') ?></th>
                        <th class="text-center"><?php echo $this->lang->line('attribute') ?></th>
                        <th class="text-center"><?php echo $this->lang->line('delete') ?></th>
                    </tr>
                    <?php if (!empty($menuset)): ?>
                        <?php foreach ($menuset as $amenuset): ?>
                            <?php $thisSetItems = get_record_list('menusetitem', array('set' => $amenuset->id)) ?>
                            <?php $thisSetToppings = get_record_list('menusetitem', array('set' => $amenuset->id)) ?>
                            <tr>
                                <td class="text-left">
                                    <a href="javascript:void(0)" onclick="updatetmenusetcell('<?php echo"menuSet_title_" . $amenuset->id ?>')" data-type="text" id="menuSet_title_<?php echo $amenuset->id ?>" data-name="title" data-pk="<?php echo $amenuset->id ?>" data-url="<?php echo site_url('menu/updatetmenusetcell') ?>" data-title="Update title">
                                        <?php echo $amenuset->title ?>
                                    </a>
                                </td>
                                <td class="text-center">
                                    <a href="javascript:void(0)" onclick="updatetmenusetcell('<?php echo"menuSet_min_" . $amenuset->id ?>')" data-type="text" id="menuSet_min_<?php echo $amenuset->id ?>" data-name="min" data-pk="<?php echo $amenuset->id ?>" data-url="<?php echo site_url('menu/updatetmenusetcell') ?>" data-title="Update Min">
                                        <?php echo $amenuset->min ?>
                                    </a>
                                </td>
                                <td class="text-center">
                                    <a href="javascript:void(0)" onclick="updatetmenusetcell('<?php echo"menuSet_max_" . $amenuset->id ?>')" data-type="text" id="menuSet_max_<?php echo $amenuset->id ?>" data-name="max" data-pk="<?php echo $amenuset->id ?>" data-url="<?php echo site_url('menu/updatetmenusetcell') ?>" data-title="Update Max">
                                        <?php echo $amenuset->max ?>
                                    </a>
                                </td>

                                <td class="text-center">
                                    <a href="javascript:void(0)" onclick="updatetmenusetcell('<?php echo"menuSet_rel_" . $amenuset->id ?>')" data-type="select" id="menuSet_rel_<?php echo $amenuset->id ?>" data-name="rel" data-value="<?php echo $amenuset->rel ?>" data-pk="<?php echo $amenuset->id ?>" data-url="<?php echo site_url('menu/updatetmenusetcell') ?>" data-title="Update Rel">
                                        <?php echo $amenuset->rel ?>
                                    </a>
                                </td>
                                <td class="text-center">
                                    <?php
                                    if (trim($amenuset->rel_with) != null) {
                                        $relArray = explode('-', $amenuset->rel_with);
                                        foreach ($relArray as $relCat) {
                                            echo get_title('menuset', array('id' => $relCat)) . ' ';
                                        }
                                    } else {
                                        echo "---";
                                    }
                                    ?>
                                </td>
                                <td class="text-center">
                                    <a href="javascript:void(0)" onclick="updatetmenusetcell('<?php echo"menuSet_status_" . $amenuset->id ?>')" data-type="select" id="menuSet_status_<?php echo $amenuset->id ?>" data-name="status" data-value="<?php echo $amenuset->status ?>" data-pk="<?php echo $amenuset->id ?>" data-url="<?php echo site_url('menu/updatetmenusetcell') ?>" data-title="Update Status">
                                        <?php echo $AllStatus[$amenuset->status] ?>
                                    </a>
                                </td>
                                <?php if (!empty($thisSetItems)): ?>
                                    <td class="text-center"><span class="icon icon-eye"  onclick="zamanEposBlockHideAndShow('<?php echo 'setBlock-' . $amenuset->id ?>')"></span></td>
                                <?php else: ?>
                                    <td class="text-center"><span class="icon icon-eye"  onclick="warning('<?php echo $this->lang->line('warning') ?>', '<?php echo $this->lang->line('nothing_to_happen') ?>', '<?php echo $this->lang->line('close') ?>')"></span></td>
                                <?php endif; ?>
                                <td class="text-center"><span class="icon icon-eye" onclick="zamanEposBlockHideAndShow('<?php echo 'attributeBlock-' . $amenuset->id ?>')"></span></td>
                                <td class="text-center"><span class="icon icon-trash" id="setBlockHead-<?php echo $amenuset->id ?>" onclick="deleteSetBlock('<?php echo $amenuset->id ?>')"></span></td>
                            </tr>
                            <?php if (!empty($thisSetItems)): ?>
                                <tr id="setBlock-<?php echo $amenuset->id ?>" style="display: none;">
                                    <td colspan="8">
                                        <table class="table-bg">
                                            <tr>
                                                <td class="text-left"><?php echo $this->lang->line('item') ?></td>
                                                <td class="text-center"><?php echo $this->lang->line('qty') ?></td>
                                                <td class="text-center"><?php echo $this->lang->line('status') ?></td>
                                                <td class="text-center"><?php echo $this->lang->line('delete') ?></td>
                                            </tr>
                                            <?php foreach ($thisSetItems as $item): ?>
                                                <tr>
                                                    <?php if ((int) $item->selection > 0): ?>
                                                        <td class="text-left"><?php echo get_title('menuselection', array('id' => $item->selection)) . '-' . get_title('menu', array('id' => $item->menu)) ?></td>
                                                    <?php else: ?>
                                                        <td class="text-left"><?php echo get_title('menu', array('id' => $item->menu)) ?></td>
                                                    <?php endif; ?>
                                                    <td class="text-center">
                                                        <a href="javascript:void(0)" onclick="updatetmenusetitemcell('<?php echo"menuSetItem_qty_" . $item->id ?>')" data-type="text" id="menuSetItem_qty_<?php echo $item->id ?>" data-name="qty" data-pk="<?php echo $item->id ?>" data-url="<?php echo site_url('menu/updatetmenusetitemcell') ?>" data-title="Update Qty">
                                                            <?php echo $item->qty ?>
                                                        </a>
                                                    </td>
                                                    <td class="text-center">
                                                        <a href="javascript:void(0)" onclick="updatetmenusetitemcell('<?php echo"menuSetItem_status_" . $item->id ?>')" data-type="select" id="menuSetItem_status_<?php echo $item->id ?>" data-name="status" data-value="<?php echo $item->status ?>" data-pk="<?php echo $item->id ?>" data-url="<?php echo site_url('menu/updatetmenusetitemcell') ?>" data-title="Update Status">
                                                            <?php echo $AllStatus[$item->status] ?>
                                                        </a>
                                                    </td>
                                                    <td class="text-center"><span class="icon icon-trash" id="deletedSetItem-<?php echo $item->id ?>" onclick="deletemenusetitem('<?php echo $item->id ?>')"></span></td>
                                                </tr>
                                            <?php endforeach; ?>
                                        </table>
                                    </td>
                                </tr>
                            <?php endif; ?>
                            <tr id="attributeBlock-<?php echo $amenuset->id ?>" style="display: none;">
                                <td colspan="8">
                                    <div class="set-attribute-block">
                                        <div class="pane-one-half">
                                            <div class="caption">Set Topping</div>
                                            <?php $toppingHeads = get_record_list('menuattrcategory', array('set' => $amenuset->id)); ?>
                                            <table class="booking-bg">
                                                <tr>
                                                    <td><?php echo $this->lang->line('title') ?></td>
                                                    <td><?php echo $this->lang->line('price') ?></td>
                                                    <td><?php echo $this->lang->line('qty') ?></td>
                                                    <td><?php echo $this->lang->line('status') ?></td>
                                                </tr>
                                                <?php if (!empty($toppingHeads)): ?>
                                                    <?php foreach ($toppingHeads as $th): ?>
                                                        <tr>
                                                            <th colspan="3" class="text-center"><strong><?php echo $th->title ?></strong></th>
                                                        </tr>
                                                        <?php $headToppings = get_record_list('menuattr', array('menuttrcategory' => $th->id)); ?>
                                                        <?php if (!empty($headToppings)): ?>
                                                            <?php foreach ($headToppings as $ht): ?>
                                                                <tr>
                                                                    <td><?php echo $ht->title ?></td>
                                                                    <td><?php echo $ht->price ?></td>
                                                                    <td><?php echo $ht->qty ?></td>
                                                                    <td><?php echo $AllStatus[$ht->status] ?></td>
                                                                </tr>
                                                            <?php endforeach; ?>
                                                        <?php endif; ?>

                                                    <?php endforeach; ?>
                                                <?php endif; ?>
                                            </table>
                                            <div class="tab-group config-submit clearfix">
                                                <button type="button" onclick=" attrPopup('menuToppingPopup', '75%', '<?php echo $category ?>', '<?php echo $menu ?>', '<?php echo $selection ?>', '<?php echo $amenuset->id ?>', '<?php echo site_url('menu/topping') ?>')"><span class="icon icon-tools"></span>&nbsp;<?php echo $this->lang->line('manage') . ' ' . $this->lang->line('toppings') ?></button>
                                            </div>
                                        </div>
                                        <div class="pane-one-half">
                                            <div class="caption">Set Modifier</div>
                                            <?php $modifiersHeads = get_record_list('modifiercategory', array('set' => $amenuset->id)); ?>
                                            <table class="booking-bg">
                                                <tr>
                                                    <td><?php echo $this->lang->line('title') ?></td>
                                                    <td><?php echo $this->lang->line('status') ?></td>
                                                </tr>
                                                <?php if (!empty($modifiersHeads)): ?>
                                                    <?php foreach ($modifiersHeads as $th): ?>
                                                        <tr>
                                                            <th colspan="2" class="text-center"><strong><?php echo $th->title ?></strong></th>
                                                        </tr>
                                                        <?php $headToppings = get_record_list('modifiermenu', array('modcategory' => $th->id)); ?>
                                                        <?php if (!empty($headToppings)): ?>
                                                            <?php foreach ($headToppings as $ht): ?>
                                                                <tr>
                                                                    <td><?php echo $ht->title ?></td>
                                                                    <td><?php echo $AllStatus[$ht->status] ?></td>
                                                                </tr>
                                                            <?php endforeach; ?>
                                                        <?php endif; ?>

                                                    <?php endforeach; ?>
                                                <?php endif; ?>
                                            </table>
                                            <div class="tab-group config-submit clearfix">
                                                <button type="button" onclick=" attrPopup('menuModifierPopup', '75%', '<?php echo $category ?>', '<?php echo $menu ?>', '<?php echo $selection ?>', '<?php echo $amenuset->id ?>', '<?php echo site_url('menu/itemmodifier') ?>')"><span class="icon icon-tools"></span>&nbsp;<?php echo $this->lang->line('manage') . ' ' . $this->lang->line('modifiers') ?></button>
                                            </div>
                                        </div>
                                    </div> 
                                </td>
                            </tr>
                        <?php endforeach; ?>
                    <?php endif; ?>
                </table>
            </div>
            <div class="popup-block">
                <div class="caption"><?php echo $this->lang->line('add_new_set') ?></div>
                <?php echo form_open('menu/save_customdealset', array('id' => 'menuSetForm')); ?>
                <div class="pane-one-fourth block">
                    <div class="form-group">
                        <label><?php echo $this->lang->line('title') ?></label>
                        <input type="text" name="title" class="form-control">
                    </div>
                </div>
                <div class="pane-one-fourth block">
                    <div class="form-group">
                        <label><?php echo $this->lang->line('min') ?></label>
                        <input type="text" name="min" value="0" class="form-control">
                    </div>
                </div>
                <div class="pane-one-fourth block">
                    <div class="form-group">
                        <label><?php echo $this->lang->line('max') ?></label>
                        <input type="text" name="max" value="0" class="form-control">
                    </div>
                </div>
                <div class="pane-one-fourth block">
                    <div class="form-group" style="width: 50%; float: left">
                        <label><?php echo $this->lang->line('relation') ?></label>
                        <select class="form-control" name="rel" onchange="setRelationWithOther(this.value)">
                            <option value=""><?php echo $this->lang->line('select') ?></option>
                            <option value="mono"><?php echo $this->lang->line('mono') ?></option>
                            <option value="poly"><?php echo $this->lang->line('poly') ?></option>
                        </select>
                    </div>
                    <div class="form-group" id="relationWithBlockOther" style="width: 50%; float: right; display: none;">
                        <label><?php echo $this->lang->line('with') ?></label>
                        <select multiple size="2" class="form-control" name="rel_with[]" id="relationWithElementsOther">
                            <?php if (!empty($menuset)): ?>
                                <?php foreach ($menuset as $amenuset): ?>
                                    <?php if (trim($amenuset->rel) === trim('mono')): ?>
                                        <option value="<?php echo $amenuset->id ?>"><?php echo ucwords($amenuset->title) ?></option>
                                    <?php endif; ?>
                                <?php endforeach; ?>
                            <?php endif; ?>
                        </select>
                    </div>
                </div>
                <div class="tab-group config-submit clearfix">
                    <input type="hidden" id="menuSetHeadCategory" name="category" value="<?php echo $category ?>">
                    <input type="hidden" id="menuSetHeadMenu" name="menu" value="<?php echo $menu ?>">
                    <input type="hidden" id="menuSetHeadSelection" name="selection" value="<?php echo $selection ?>">
                    <input type="hidden" id="menuSetHeadSet" name="set" value="<?php echo $set ?>">
                    <button type="submit" onclick="saveMenuSetForm('menuSetForm')"><span class="icon icon-folder"></span>&nbsp;<?php echo $this->lang->line('save') ?></button>
                </div>
                <?php echo form_close() ?>
            </div>
            <div style="height: 30px; margin: 10px 0px;" class="text-right">
                <button class="btn btn btn-large btn-warning icon icon-arrows-ccw" onclick="attrPopup('menuCustomDealPopup', '80%', '<?php echo $category ?>', '<?php echo $menu ?>', '<?php echo $selection ?>', '<?php echo $set ?>', '<?php echo site_url('menu/customdeal') ?>')">&nbsp;<?php echo $this->lang->line('refresh') ?></button>
            </div>
            <div class="caption"><?php echo $this->lang->line('hook_item_set') ?></div>
            <?php echo form_open('menu/save_menusetitems', array('id' => 'menuSetItemForm')); ?>
            <div class="form-group">
                <label>Select menu set</label>
                <select class="form-control" name="set">
                    <option value=""><?php echo $this->lang->line('select') ?></option>
                    <?php if (!empty($menuset)): ?>
                        <?php foreach ($menuset as $amenuset): ?>
                            <option value="<?php echo $amenuset->id ?>"><?php echo ucwords($amenuset->title) ?></option>
                        <?php endforeach; ?>
                    <?php endif; ?>
                </select>
            </div>
            <div id="menuSetItemsBlock"></div>
            <div class="form-group">
                <label>Select menu category</label>
                <select class="form-control" onchange="getmenusetitems(this.value)">
                    <option value="0"><?php echo $this->lang->line('select') ?></option>
                    <?php if (!empty($menucategory)): ?>
                        <?php foreach ($menucategory as $amenucategory): ?>
                            <option value="<?php echo $amenucategory->id ?>"><?php echo ucwords($amenucategory->title) ?></option>
                        <?php endforeach; ?>
                    <?php endif; ?>
                </select>
            </div>
            <div class="tab-group config-submit clearfix">
                <button type="submit" onclick="saveMenuSetItemForm('menuSetItemForm')"><span class="icon icon-folder"></span>&nbsp;<?php echo $this->lang->line('save') ?></button>
            </div>
            <?php echo form_close() ?>
        </div>
    </div>
</div>
<script>
    function setRelationWithOther(relType) {
        var size = Number(($('#relationWithElementsOther option').size()));
        if ($.trim(relType) === $.trim('mono') && size > 0) {
            $('#relationWithBlockOther').show();
        } else {
            $('#relationWithBlockOther').hide();
        }
    }
    function saveMenuSetForm(formId) {
        if (!$('.page-loader').is(":visible")) {
            $('#' + formId).validate({
                submitHandler: function () {
                    var myform = document.getElementById(formId);
                    var formdata = new FormData(myform);
                    if (checkInternetConnection()) {
                        $.ajax({
                            url: $('#' + formId).attr('action'),
                            data: formdata,
                            cache: false,
                            processData: false,
                            contentType: false,
                            type: 'POST',
                            dataType: 'json',
                            beforeSend: function () {
                                $('.page-loader').show();
                            },
                            success: function (response) {
                                if (response.status) {
                                    attrPopup('menuCustomDealPopup', '80%', '<?php echo $category ?>', '<?php echo $menu ?>', '<?php echo $selection ?>', '<?php echo $set ?>', '<?php echo site_url('menu/customdeal') ?>')
                                } else {
                                    warning('<?php echo $this->lang->line('error') ?>', response.message, '<?php echo $this->lang->line('ok') ?>');
                                }
                                $('.page-loader').hide();
                            }
                        });
                    } else {
                        warning('<?php echo $this->lang->line('lost_connection') ?>', '<?php echo $this->lang->line('lost_connection_message') ?>', '<?php echo $this->lang->line('close') ?>');
                    }
                },
                errorClass: "has-error",
                highlight: function (e) {
                    $(e).closest('.form-group').addClass('has-error');
                },
                unhighlight: function (e) {
                    $(e).closest('.form-group').removeClass('has-error');
                },
                rules: {
                    title: {
                        required: true,
                        remote: {
                            url: "<?php echo site_url('menu/checkmenuset') ?>",
                            type: "post",
                            data: {
                                category: function () {
                                    return $('#menuSetHeadCategory').val();
                                },
                                menu: function () {
                                    return $('#menuSetHeadMenu').val();
                                },
                                selection: function () {
                                    return $('#menuSetHeadSelection').val();
                                },
                                set: function () {
                                    return $('#menuSetHeadSet').val();
                                }
                            }
                        }
                    },
                    min: {number: true, min: 0},
                    max: {number: true, min: 0},
                    rel: {required: true}
                },
                errorPlacement: function (error, element) {
                    errorPlacement(error, element);
                }
            });
        }
    }
    function updatetmenusetcell(field) {
        $('#' + field).editable({
            mode: 'inline',
            source: function () {
                if (field.includes("status")) {
                    return [
                        {value: 3, text: '<?php echo $this->lang->line('active') ?>'},
                        {value: 2, text: '<?php echo $this->lang->line('inactive') ?>'}
                    ];
                }
                if (field.includes("rel")) {
                    return [
                        {value: 'mono', text: '<?php echo strtolower($this->lang->line('mono')) ?>'},
                        {value: 'poly', text: '<?php echo strtolower($this->lang->line('poly')) ?>'}
                    ];
                }
            },
            validate: function (value) {
                if ($.trim(value) === '') {
                    warning('<?php echo $this->lang->line('error') ?>', '<?php echo $this->lang->line('data_required') ?>', '<?php echo $this->lang->line('close') ?>');
                    return false;
                } else {
                    if (field.includes("min") || field.includes("max") || field.includes("max")) {
                        if (isNaN(Number(value))) {
                            warning('<?php echo $this->lang->line('error') ?>', '<?php echo $this->lang->line('invalid_data') ?>', '<?php echo $this->lang->line('close') ?>');
                            return false;
                        }
                    }
                }
            }
        });
    }
    function deleteSetBlock(id) {
        if (!$('.page-loader').is(":visible")) {
            if (checkInternetConnection()) {
                $.ajax({
                    url: '<?php echo site_url('menu/deletemenuset') ?>',
                    data: {id: id},
                    type: 'POST',
                    dataType: 'json',
                    beforeSend: function () {
                        $('.page-loader').show();
                    },
                    success: function (response) {
                        if (response.status) {
                            if ($('#setBlock-' + id).length > 0) {
                                $('#setBlock-' + id).closest('tr').remove();
                            }
                            if ($('#setBlockHead-' + id).length > 0) {
                                $('#setBlockHead-' + id).closest('tr').remove();
                            }
                            $.colorbox.resize();
                        }
                        $('.page-loader').hide();
                    }
                });
            } else {
                warning('<?php echo $this->lang->line('lost_connection') ?>', '<?php echo $this->lang->line('lost_connection_message') ?>', '<?php echo $this->lang->line('close') ?>');
            }
        }
    }
    function getmenusetitems(id) {
        if (!$('.page-loader').is(":visible")) {
            if ($.trim(id) !== '0') {
                if (checkInternetConnection()) {
                    $.ajax({
                        url: '<?php echo site_url('menu/getmenusetitems/') ?>' + id,
                        type: 'GET',
                        beforeSend: function () {
                            $('.page-loader').show();
                        },
                        success: function (response) {
                            $('#menuSetItemsBlock').append(response);
                            $.colorbox.resize();
                            $('.page-loader').hide();
                        }
                    });
                } else {
                    warning('<?php echo $this->lang->line('lost_connection') ?>', '<?php echo $this->lang->line('lost_connection_message') ?>', '<?php echo $this->lang->line('close') ?>');
                }
            }
        }
    }
    function saveMenuSetItemForm(formId) {
        if (!$('.page-loader').is(":visible")) {
            $('#' + formId).validate({
                submitHandler: function () {
                    var myform = document.getElementById(formId);
                    var formdata = new FormData(myform);
                    if (checkInternetConnection()) {
                        $.ajax({
                            url: $('#' + formId).attr('action'),
                            data: formdata,
                            cache: false,
                            processData: false,
                            contentType: false,
                            type: 'POST',
                            dataType: 'json',
                            beforeSend: function () {
                                $('.page-loader').show();
                            },
                            success: function (response) {
                                if (response.status) {
                                    attrPopup('menuCustomDealPopup', '80%', '<?php echo $category ?>', '<?php echo $menu ?>', '<?php echo $selection ?>', '<?php echo $set ?>', '<?php echo site_url('menu/customdeal') ?>')
                                } else {
                                    warning('<?php echo $this->lang->line('error') ?>', response.message, '<?php echo $this->lang->line('ok') ?>');
                                }
                                $('.page-loader').hide();
                            }
                        });
                    } else {
                        warning('<?php echo $this->lang->line('lost_connection') ?>', '<?php echo $this->lang->line('lost_connection_message') ?>', '<?php echo $this->lang->line('close') ?>');
                    }
                },
                errorClass: "has-error",
                highlight: function (e) {
                    $(e).closest('.form-group').addClass('has-error');
                },
                unhighlight: function (e) {
                    $(e).closest('.form-group').removeClass('has-error');
                },
                rules: {
                    set: {
                        required: true
                    },
                    'items[]': {
                        required: true
                    }
                },
                errorPlacement: function (error, element) {
                    errorPlacement(error, element);
                }
            });
        }
    }
    function updatetmenusetitemcell(field) {
        $('#' + field).editable({
            mode: 'inline',
            source: function () {
                if (field.includes("status")) {
                    return [
                        {value: 3, text: '<?php echo $this->lang->line('active') ?>'},
                        {value: 2, text: '<?php echo $this->lang->line('inactive') ?>'}
                    ];
                }
                if (field.includes("rel")) {
                    return [
                        {value: 'mono', text: '<?php echo strtolower($this->lang->line('mono')) ?>'},
                        {value: 'poly', text: '<?php echo strtolower($this->lang->line('poly')) ?>'}
                    ];
                }
            },
            validate: function (value) {
                if ($.trim(value) === '') {
                    warning('<?php echo $this->lang->line('error') ?>', '<?php echo $this->lang->line('data_required') ?>', '<?php echo $this->lang->line('close') ?>');
                    return false;
                } else {
                    if (field.includes("qty") || field.includes("status")) {
                        if (isNaN(Number(value))) {
                            warning('<?php echo $this->lang->line('error') ?>', '<?php echo $this->lang->line('invalid_data') ?>', '<?php echo $this->lang->line('close') ?>');
                            return false;
                        }
                    }
                }
            }
        });
    }
    function deletemenusetitem(id) {
        if (!$('.page-loader').is(":visible")) {
            if (checkInternetConnection()) {
                $.ajax({
                    url: '<?php echo site_url('menu/deletemenusetitem') ?>',
                    data: {id: id},
                    type: 'POST',
                    dataType: 'json',
                    beforeSend: function () {
                        $('.page-loader').show();
                    },
                    success: function (response) {
                        if (response.status) {
                            if ($('#deletedSetItem-' + id).length > 0) {
                                $('#deletedSetItem-' + id).closest('tr').remove();
                            }
                            $.colorbox.resize();
                        }
                        $('.page-loader').hide();
                    }
                });
            } else {
                warning('<?php echo $this->lang->line('lost_connection') ?>', '<?php echo $this->lang->line('lost_connection_message') ?>', '<?php echo $this->lang->line('close') ?>');
            }
        }
    }
    function cumulativeFact(id, value, field) {
        if (!$('.page-loader').is(":visible")) {
            if (checkInternetConnection()) {
                var action = null;
                if ($('#' + id).is(':checked')) {
                    action = 'add';
                } else {
                    action = 'remove';
                }
                $.ajax({
                    url: '<?php echo site_url('menu/cumulativeFact') ?>',
                    type: 'POST',
                    data: {action: action, field: field, value: value},
                    dataType: 'json',
                    beforeSend: function () {
                        $('.page-loader').show();
                    },
                    success: function (response) {
                        if (response.status) {
                            $('.page-loader').hide();
                        }
                    }
                });
            } else {
                warning('<?php echo $this->lang->line('lost_connection') ?>', '<?php echo $this->lang->line('lost_connection_message') ?>', '<?php echo $this->lang->line('close') ?>');
            }
        }
    }
</script>