<style type="text/css">
    #OrderTable thead tr th {
        color:#555;
        border-bottom: 1px solid rgba(0,0,0,0.1);
    }
    #OrderTable tbody tr td input{
        width:100%;
        margin:0;
        border: 1px solid rgba(0,0,0,0.02);
        background-color:#e5e5e5;
        padding: 5px 9px 12px;
        height: 40px;
    }
    #OrderTable tbody tr td {
        border:0;
        padding:3px 1px;
        position:relative;
    }
    #OrderTable tbody tr:first-child td{
        padding-top:10px;
    }
    #InvoiceDiscountInput{
        display: inline-block;
        width: 40px;
        padding: 3px;
        line-height: 20px;
        background: rgb(250, 250, 250);
        min-height: 12px;
        text-align: center;
        height: 25px;
        font-size: 12px;
        top: -2px;
        position: relative;
        margin: 0 3px;
    }
    #OrderTable .Hint{
        position: absolute;
        font-size: 10px;
        display: block;
        font-weight: bold;
        height: 12px;
        line-height: 11px;
        cursor: default;
        background: #ccc;
        padding: 0 2px;
        text-overflow: ellipsis;
        overflow: hidden;
        white-space: nowrap;
        bottom: 3px;
        right: 1px;
        left: 1px;
        color: #4c0870;
    }
    #OrderTable .TotalTD{
        width: auto;
        display: inline-block;
        text-align: center;
        font-size: 20px;
        font-weight: bold;
    }
    #OrderTable .Disc{
        width:70px;
    }
    #OrderTable input.wrong{
        border: 1px solid rgba(255, 0, 0, 0.2);
        background: rgba(255, 0, 0, 0.05);
        /*        width:100%;*/
    }
    .DropDownForForms > .dropdown-menu{
        width:100%;
        height:200px;
        max-height:200px;
        overflow-y:scroll;
    }
    .DropDownForForms > .dropdown-menu{
        height:auto;
        cursor: pointer;
        overflow-y:auto;
    }
    .DropDownForForms > button{
        position:relative;
        z-index:999;
    }
    .DropDownForForms > button > input{
        position: absolute;
        left:5;
        top: 0;
        width:90%;
        cursor: pointer;
        -webkit-user-select:none;
        -moz-user-select:none;
        user-select:none;
        padding: 0;
        border: 0;
        background: transparent;
    }
    .Disabled{
        cursor:default;
        opacity:0.5;
    }
    #AdvanceValue{
        width: 102px;
        display: inline-block;
    }
    .datepicker thead tr .dow {
        color:#ed9421 !important;
    }
    .datepicker table tr td.day:hover {
        background: #ed9421 !important;
        color:#fff;
    }
    .datepicker table tr td.active {
        background-color: #ed9421 !important;
    }
    .datepicker thead tr .datepicker-switch {
        color: #ed9421  !important;
        font-size: 13px;
    }
    .datepicker table tr td span.active {
        background-color: #ed9421 !important;
    }
    .datepicker table tr td span:hover {
        background-color: #ed9421 !important;
        color:#fff;
    }
    datepicker thead tr .next:before, .datepicker thead tr .prev:before {
        color: #ed9421 !important;
        font-family: 'FontAwesome';
        font-size: 10px;
    }
    .datepicker thead tr .next:before, .datepicker thead tr .prev:before {
        color: #ed9421 !important;
        font-family: 'FontAwesome';
        font-size: 10px;
    }
    /*    .select2-container > .select2-choice{
    background-color: #e5e5e5;
    width: 150px;
    }*/
    .InputSpinner{
        width: 60px;
    }
    .InputSpinner > .form-control{
        border-color: rgb(221, 221, 221);
        height:36px;
        margin:0;
        padding:0;
        text-align: center;
    }
    .InputSpinner > .input-group-btn-vertical {
        position: relative;
        white-space: nowrap;
        width: 25px;
        vertical-align: middle;
        display: table-cell;
    }
    .InputSpinner > .input-group-btn-vertical > .btn {
        height:19px;
        display: block;
        float: none;
        width: 100%;
        max-width: 100%;
        padding: 8px;
        margin-left: -1px;
        position: relative;
        border-radius: 0;
    }
    .InputSpinner > .input-group-btn-vertical > .btn:first-child {
        border-top-right-radius: 4px;
    }
    .InputSpinner > .input-group-btn-vertical > .btn:last-child {
        margin-top: -2px;
        border-bottom-right-radius: 4px;
    }
    .InputSpinner > .input-group-btn-vertical i{
        position: absolute;
        top: 50%;
        left: 6px;
        margin-top:-9px;
        font-size: 18px;
    }
    .InputSpinner .input-group-btn-vertical .btn.btn-default{
        font-size: 10px;
        padding: 6px 10px;
    }
    #OrderTable .select2-container .select2-choice {
        background-image: none;
        border-radius: 2px;
        border: 1px solid rgba(0,0,0,0.07);
        padding: 5px 9px 16px;
        transition: border 0.2s linear 0s;
        height: 40px;
        background-color: #e5e5e5;
        /*width: 150px;*/
    }
    .tags{
        cursor:pointer;
    }
    .inputDiv {
        background-color: transparent;
        font-size: large;
        border: none;
        border-radius: 0;
    }
    .inputDiv input {
        position: absolute;
        left: 0px;
        top: 0px;
        width: 100%;
        height: 100%;
        opacity: 0.01;
        cursor: pointer;
    }
    #TagsTable td:not(:first-child){
        padding:0;
    }
    .tagSelected,.inputDiv:hover{
        background-color:#ed9421 !important;
        border-color:#ed9421 !important;
        color:white;
    }
    .inputDiv.tagSelected .inputDiv{
        color:white;
    }
    .removeTags{
        text-align:center;
        vertical-align:middle !important;
        width:10%;
        cursor:pointer;
    }
    #OrderTable td span.mylabel{
        font-size:10px !important;
        display: inline-table !important;
        white-space:normal !important;
        line-height: 21px !important;
    }
    #OrderTable .bootstrap-tagsinput .tag [data-role="remove"] {
        font-size:13px !important;

    }
    #OrderTable .bootstrap-tagsinput{
        max-height: 40px;
        overflow: auto;

    }
</style>
<script src="<?php echo THEME_PATH; ?>plugins/jquery-validation/js/jquery.validate.min.js"></script>

<?php echo Forms::ModalLoader('OrderDisabler'); ?>
<form method="POST" action="" onsubmit="return false" id="OrderForm">
    <div class="container-fluid container-fixed-lg">
        <div class="panel panel-default">
            <div class="panel-body">

                <div id="OrderSuccess"></div>
                <div class="invoice padding-20 sm-padding-10">
                    <div class="container-sm-height">
                        <div class="row">
                            <h2 class="font-montserrat all-caps hint-text"><?php print $title; ?></h2>

                            <div class="col-md-6  sm-no-padding">
                                <div class="row">
                                    <div class="form-group col-md-6 pull-right">
                                        <label><strong><?php print CommonLanguage::getMessage('To'); ?></strong></label>
                                        <div class="input-group m-b">
                                            <span class="input-group-btn">
                                                <button type="button" class="btn" style="width:0 ;background-color:#ed9421" ><i class="fa fa-compass"style="color:#fff;margin-left:-7px"></i> </button> </span>
                                            <select name="Depot_Name1" id="Depot_Name1" class="full-width" data-init-plugin="select2" disabled>
                                                <option value="" disabled selected ><?php echo CommonLanguage::getMessage('select'); ?></option>
                                                <?php foreach ($all_depots as $depot): ?>
                                                    <option value="<?php echo $depot['Depot_ID']; ?>"   <?php echo $edit_arr['main']['Request_From'] == $depot['Depot_ID'] ? 'selected' : '' ?>              ><?php echo $depot['Depot_Name']; ?></option>
                                                <?php endforeach; ?>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="form-group col-md-6 ">
                                        <label><strong><?php print CommonLanguage::getMessage('From') ?></strong></label>
                                        <div class="input-group m-b">
                                            <span class="input-group-btn">
                                                <button type="button" class="btn" style="width:0 ;background-color:#ed9421" ><i class="fa fa-compass"style="color:#fff;margin-left:-7px"></i> </button> </span>
                                            <select name="Depot_Name2" id="Depot_Name2" class="full-width" data-init-plugin="select2"  disabled >
                                                <option value="" disabled selected ><?php echo CommonLanguage::getMessage('select'); ?></option>
                                                <?php foreach ($all_depots as $depot): ?>
                                                    <option value="<?php echo $depot['Depot_ID']; ?>" <?php echo $edit_arr['main']['Request_To'] == $depot['Depot_ID'] ? 'selected' : '' ?>  ><?php echo $depot['Depot_Name']; ?></option>
                                                <?php endforeach; ?>
                                            </select>
                                        </div>
                                    </div>
                                </div>

                            </div>
                            <div class="col-md-4  pull-right" style="vertical-align: top;">
                                <div class="sm-m-t-20">
                                    <h4><?php print CommonLanguage::getMessage('Request'); ?> # <?php echo $edit_arr['main']['req_id'] ?></h4>
                                </div>

                                <br>
                            </div>
                        </div>
                    </div>
                    <div>
                        <div class="clearfix"></div>
                    </div>
                    <div class="table-responsive">
                        <table class="table m-t-50" id='OrderTable'>
                            <thead>
                                <tr>
                                    <th class="text-center" style="width:3%"></th>
                                    <th class="text-center" style="width:10%"> <?php print CommonLanguage::getMessage('Code'); ?></th>
                                    <th class="text-center" style="width:10%"><?php print CommonLanguage::getMessage('Name'); ?></th>
                                    <!--<th class="text-center <?php echo (smc_session()['default_setting']['activate_expiry_date'] == 0 ) ? 'hidden' : ''; ?>"><?php print CommonLanguage::getMessage('Expiry_Date'); ?></th>-->
                                    <th class="text-center" style="width:5%"><?php print CommonLanguage::getMessage('Quantity'); ?></th>
                                    <th class="text-center" style="width:5%"><?php print CommonLanguage::getMessage('delivered_qty'); ?></th>
                                    <th class="text-center" style="width:10%"><?php print CommonLanguage::getMessage('UOM'); ?></th>
                                    <!--<th class="text-center" style="width:7%"><?php print CommonLanguage::getMessage('lot'); ?></th>-->
                                    <!--<th class="text-center " style="width:7%"><?php print CommonLanguage::getMessage('serial'); ?></th>-->
                                    <th class="text-center " style="width:20%"><?php print CommonLanguage::getMessage('note'); ?></th>
                                    <?php if (smc_session()['default_setting']['is_tag_active'] == 1) { ?>
                                                                    <!--<th class="text-center"style="width:5%"></th>-->
                                        <th class="text-center"style="width:20%"></th>
                                    <?php } ?>
                                </tr>
                            </thead>
                            <tbody>
                                <?php
                                $data_arr = $edit_arr['Request'];
                                foreach ($data_arr as $item) {
                                    ?>
                                    <tr data-conv="<?php echo $item['conversion_amount'] ?>" 
                                        data-qty="<?php echo $item['total_default_quantity'] ?>"  
                                        data-id="<?php echo $item['Product_ID'] ?>" 
                                        data-entry="<?php echo $item['Entry_ID'] ?>">
                                        <td>  <span class="fa fa-minus-circle deleteRowRequest " style="color: #4c0870;margin-left: 5px;cursor: pointer;font-size: 16px;"></span></td>

                                        <td><input type="text" class="form-control  CODE " value = "<?php echo $item['Product_Code'] ?>" disabled ></td>
                                        <td><input type="text" class="form-control  ProductName" value = "<?php echo $item['Product_Name'] ?>"  disabled ><span class="Hint"></span></td>
                                        <!--<td><input type="hidden" class="full-width  expiry_date  <?php echo $item['is_expiry'] ? '' : 'hidden' ?>" value = "<?php echo $item['expiry_date'] ?>" data-select-name="<?php echo $item['expiry_date'] ?>" disabled></td>-->
                                        <td><input type="text" class="form-control main_qty isnumber" disabled value = "<?php echo $item['Current_Quantity'] ?>"  ><span class="Hint"></span></td>
                                        <td><input type="text" class="form-control Quantity isnumber" value = "<?php echo $item['delivered_current_qty'] ?>"  ><span class="Hint"></span></td>
                                        <td>

                                            <select required name="UOM_ID"  class="full-width UOM_ID " data-init-plugin="select2"  disabled >
                                                <?php foreach ($edit_arr['uoms'][$item['Product_ID']] as $uom): ?>
                                                    <option value="<?php echo $uom; ?>"  <?php echo ($item['Request_UOM'] == $uom ? 'selected' : '') ?>        ><?php echo $all_uom[$uom]['UOM_Name']; ?></option>
                                                <?php endforeach; ?>
                                            </select>

                                        </td>
    <!--                                        <td >
                                            <input type="hidden" class="full-width lot_nb  <?php echo $item['is_lot'] ? '' : 'hidden' ?>"  disabled value="<?php echo $item['lot_nb']; ?>" data-select-name="<?php echo $item['lot_nb']; ?>"/>
                                        </td>-->
    <!--                                        <td class="text-center " >
                                            <input type="hidden" class="full-width serial_nb   <?php echo $item['is_serial'] ? '' : 'hidden' ?>"  disabled  value="<?php echo $item['serial_nb']; ?>" data-select-name="<?php echo $item['serial_nb']; ?>"/>
                                        </td>-->
                                        <td class="text-center " >
                                            <input type="text" class="full-width detail_note " value="<?php echo $item['delivered_note'] ?>" />
                                        </td>
                                        <?php if (smc_session()['default_setting']['is_tag_active'] == 1) { ?>
                                                                        <!--<td class="tags"><i class="fa fa-tag fa-2x"></i></td>-->
                                            <td class="tag-main-td">
                                                <div class=" bootstrap-tagsinput">
                                                    <?php
                                                    if (!empty($item['criteria'])) {
                                                        foreach ($item['criteria'] as $criteria) {
                                                            ?>
                                                            <span class="tag label label-stock mylabel" data-content="<?php echo $criteria['criteria_detail_name'] ?>" 
                                                                  data-criteria-id="<?php echo $criteria['criteria_id'] ?>" data-note="<?php echo $criteria['criteria_note'] ?>" 
                                                                  data-entry="<?php echo $criteria['criteria_detail_id'] ?>">
                                                                <?php echo $criteria['criteria_detail_name'] ?><span class="hidden" data-role="remove"></span></span>
                                                                <?php
                                                            }
                                                        } else {
                                                            echo'No Tags';
                                                        }
                                                        ?>
                                                </div>
                                            </td>

                                        <?php } ?>
                                    </tr>
                                <?php }
                                ?>
                            </tbody>
                        </table>
                    </div>
                    <br>

                    <div class="container-sm-height" >

                        <button class=" btn  btn-cons m-b-10 pull-right" id="OrderSubmitButton" style="color:#fff;background-color:#ed9421;padding-top: 10px;top: 20px;min-width:253px;" type="button"><i class="pg-form"></i> <span class="bold"><?php print CommonLanguage::getMessage('Save'); ?></span></button>

                    </div>
                    <hr>
                </div>
            </div>
        </div>
    </div>
</form>
<!--<div class="modal fade" id="tagsModal" data-backdrop="static" data-id="" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header clearfix text-left">
                <div class="row">
                    <h4 class="text-center"><i class="fa fa-tags"></i> <?php print CommonLanguage::getMessage('criteria') ?></h4>
                </div>
            </div>
            <div class="modal-body">
<?php echo Forms::AlertDiv('tag_Alert'); ?>
                <div class="row criteria-detail-div">      
                </div>
            </div>
            <div class="modal-footer">
                <div class="col-md-12 row ">
                    <button id="cancelTag" type="submit" data-dismiss="modal" class="btn btn-danger btn-cons"><i class="fa fa-times"></i> <?php print CommonLanguage::getMessage('Close') ?></button>
                    <button id="addTag" type="submit" class="btn bg-complete-light btn-cons"><i class="fa fa-check"></i> <?php print CommonLanguage::getMessage('Save') ?></button>
                </div>
            </div>
<?php echo Forms::ModalLoader('Criteria_Loader'); ?>
        </div>
    </div>
</div>-->
<select required id="Select_UOM" name="Select_UOM"  class="full-width Select_UOM hidden" data-init-plugin="select2">
    <?php foreach ($all_uom as $uom): ?>
        <option value="<?php echo $uom['UOM_ID']; ?>"><?php echo $uom['UOM_Name']; ?></option>
    <?php endforeach; ?>
</select>
<script>
    var Failed_Submit = <?php echo json_encode(CommonLanguage::getMessage('Failed_Submit')); ?>,
            Submitted_Successfully = <?php echo json_encode(CommonLanguage::getMessage('Submitted_Successfully')); ?>,
            Required_Fields = <?php echo json_encode(CommonLanguage::getMessage('Required_Fields')); ?>,
            have_not_saved = <?php echo json_encode(CommonLanguage::getMessage('have_not_saved')); ?>,
            CheckSubmit = true,
            ID_Edit = <?php echo json_encode($id); ?>,
            user_depot = <?php echo json_encode(smc_session()['user_accounts']['depot_id']); ?>,
            display_shelf_locations = <?php echo json_encode(smc_session()['default_setting']['display_shelf_locations']) ?>,
            negative_sales = <?php echo json_encode(smc_session()['negative_sales']); ?>,
            request_id, max_criteria_column = 5;
    var req_nb = <?php echo json_encode(CommonLanguage::getMessage('transfer_nb')); ?>;
    $(function () {



//        $("#loading_order_date,#Delivery_Date").datepicker({autoclose: true})

        $("#OrderTable ").on("click", ".deleteRowRequest", function () {//to delete a row
            var numItems = $('#OrderTable tr').length; //number of rows
            if (numItems > 2) {//only if number of rows is more than one row remove the deleted row
                $(this).parents("tr").remove()
            }

        })
//        $("#OrderTable").on("click", ".tags", function () {
//            var tr = $(this).parents("tr");
//            if (tr.attr("data-id") == undefined)
//                return;
//            getProductCriteria(tr.attr("data-id"), getCurrentTags(tr), tr)
//            $("#tagsModal").attr("data-id", tr.index())
//        })
//        $(".criteria-detail-div").on("click", '.removeTags', function () {
//            $(this).parents("tr").find("input:checked").removeAttr("checked")
//            removeTags()
//        });
//        $(".criteria-detail-div").on("click", '#TagsTable input', function () {
//
//            removeTags()
//        });
//        $(".criteria-detail-div").on("click", '#TagsTable input[type=checkbox]', function () {
//            var max_count = $(this).attr('max-count'),
//                    criteria_id = $(this).attr("data-criteria-id"),
//                    current_selected_length = $('td.tagSelected input[data-criteria-id=' + criteria_id + ']').length
//
//            if (current_selected_length > parseInt(max_count)) {
//
//                $(this).parents('td.inputDiv').removeClass('tagSelected');
//                this.checked = false
//            }
//        })
//        $("#addTag").on("click", function () {
//            updateTags()
//        });
//        $("#OrderTable").on("click", "[data-role=remove]", function () {
//            var item = $(this).parents("tr").attr("data-ref"),
//                    Parent = $(this).parents("tr");
//
//            $(this).parents("span.tag").remove()
//            if ($("span.tag", Parent).length == 0) {
//                $("tr:eq(" + item + ")").find('div.bootstrap-tagsinput').html('No Tags')
//            }
//        })






        $("#OrderTable tbody").delegate("> tr input", "keyup", function (e) {
            CheckSubmit = false;
            var me = $(this), TR = me.parents("tr");
            if (me.hasClass("Quantity")) {
                if (parseFloat(me.val()) * parseFloat(TR.attr('data-conv')) > parseFloat(TR.attr('data-qty'))) {
                    me.addClass("wrong")
                } else {
                    me.removeClass("wrong")
                }
            }



        })
        $("#OrderSubmitButton").on("click", ApplyPostMethod);

    })

    function ApplyPostMethod() {
        $("#OrderSubmitButton").addClass('disabled')
        $("#OrderSuccess").attr("class", "hidden");
        $("#OrderTable tbody .wrong").removeClass("wrong")
        $("#OrderForm").validate()
        if ($("#OrderForm").valid()) {
            var IsValidated = true, is_empty_quantity = false,
                    Data = {
                        Request_ID: ID_Edit,
                        Products: []
                    };
            $("#OrderTable tbody tr").each(function (e) {
                var me = $(this);
                if (me.find(".ProductName").val()) {
                    if (!me.find(".Quantity").val())
                        is_empty_quantity = true;
                }
                var tags = [];
                if (me.find(".Quantity").val() != '' && me.find(".ProductName").val() != '') {
//                    $("td.tag-main-td .mylabel", $(this)).each(function () {
//                        tags.push({
//                            Quantity: me.find(".Quantity").val(),
//                            criteria_detail_id: $(this).attr("data-entry"),
//                            criteria_note: $(this).attr("data-note") || ''
//                        });
//                    });
                    Data.Products.push({
                        UOM_ID: me.find("select.UOM_ID").val(),
                        Product_ID: me.attr("data-id"),
                        entry_id: me.attr("data-entry"),
                        Request_Qty: me.find(".Quantity").val(),
                        detail_note: me.find(".detail_note").val(),
                    });
                    me.find(".CODE,.ProductName,.Quantity").each(function () {
                        if ($.trim($(this).val()) == "" || ($(this).hasClass("isnumber") && $.trim($(this).val()).match(/^\s*?([\d]+(\.\d+)?|\.\d{1,2})\s*$/) == null)) {
                            $(this).addClass("wrong")
                            CheckSubmit = false;
                            IsValidated = false;
                        } else {
                            $(this).removeClass("wrong")
                        }

                    })

                }
            })


            if (Data.Products.length == 0) {
                $("#OrderSuccess").attr("class", "alert alert-danger").html('<?php echo CommonLanguage::getMessage('input_option'); ?>')
                $("#OrderSubmitButton").removeClass('disabled')
                $(document.body).animate({scrollTop: 0}, 800)
                return;
            }
            if (is_empty_quantity) {
                $("#OrderSuccess").attr("class", "alert alert-danger").html('<?php echo CommonLanguage::getMessage('fill_quantity_alert'); ?>')
                $("#OrderSubmitButton").removeClass('disabled')
                $(document.body).animate({scrollTop: 0}, 800)
                return;
            }

            if (!IsValidated) {
                $("#OrderSubmitButton").removeClass('disabled')
                return;
            }
            $("#OrderDisabler").removeClass('hidden');
            $.ajax({
                url: "StockAjax/confirm_delivered_items_ajax",
                method: "POST",
                data: Data,
                complete: function (v1, v2) {
                    if (v2 == "success") {
                        if (v1.responseText == 'OK') {
                            $("#OrderSuccess").attr("class", "alert alert-success").html(Submitted_Successfully)
                            CheckSubmit = true;
                        } else {

                            $("#OrderSuccess").attr("class", "alert alert-danger").html(v1.responseText)
                            $("#OrderSubmitButton").removeClass('disabled')
                        }
                    } else {
                        $("#OrderSuccess").attr("class", "alert alert-danger").html(Failed_Submit)
                        $("#OrderSubmitButton").removeClass('disabled')
                        CheckSubmit = true;
                    }
                    $(document.body).animate({scrollTop: 0}, 800)
                    $("#OrderDisabler").addClass('hidden');
                }
            })
        } else {
            $(document.body).animate({scrollTop: 0}, 800)
            $("#OrderSubmitButton").removeClass('disabled')
            $("#OrderSuccess").attr("class", "alert alert-danger").html(Required_Fields)
        }
    }
    $(document).ready(function () {
        window.onbeforeunload = function (e) {
            if (!CheckSubmit) {
                var message = have_not_saved, e = e || window.event;
                if (e) {
                    e.returnValue = message;
                }
                return message;
            }
        }
    });

//    function getCurrentTags(currentTR) {
//        var tags = [], tag_notes = [];
//        $("td.tag-main-td .mylabel", currentTR).each(function () {
//            tags.push($(this).attr("data-entry"));
//            if ($(this).attr("data-note") != undefined) {
//                tag_notes[$(this).attr("data-criteria-id")] = $(this).attr("data-note")
//            }
//        });
//        //        console.log(tag_notes)
//        return [tags, tag_notes];
//    }
//    function getProductCriteria(product_id, criteria_data, SelectedTR) {
//        current_criteria = criteria_data[0];
//        current_criteria_notes = criteria_data[1];
//        //        console.log(criteria_data)
//        $("#tagsModal").modal('show')
//        $("#tagsModal .criteria-detail-div").empty();
//        CommonViewById('RestaurantAjax/getProductCriteria', {Product_ID: product_id, is_all: 1, category_id: SelectedTR.attr('data-category-id')}, '#Criteria_Loader', function (Response) {
//            if (Object.keys(Response).length > 0) {
//                var tagTable = ' <table class="col-md-12 table table-bordered table-responsive" id="TagsTable">',
//                        product_criteria = '', general_criteria = '';
//                //                console.log(Response)
//                $.each(Response, function (key1, value) {
//                    var all_details = Response[key1]['detail'], content = '', type = Response[key1]['criteria_type'] == 2 ? 'radio' : 'checkbox',
//                            up_to_condition = 'Choose ' + (Response[key1]['criteria_type'] == 2 ? '1' : ' UP to ' + Response[key1]['criteria_max_count'] + ' ');
//                    var rows_nb = Math.ceil(all_details.length / max_criteria_column);
//                    content += '<tr max-count="' + Response[key1]['criteria_max_count'] + '" data-type="' + type + '">' +
//                            '<td class="tag_note_td" rowspan="' + rows_nb + '" style="width:15%;"><textarea class="tag-note form-control" rows="1">' + (current_criteria_notes[Response[key1]['criteria_id']] || '') + '</textarea></td>' +
//                            '<th class="tag_note_cond" rowspan="' + rows_nb + '"  style="width:12%"><div><span>' + up_to_condition + '</span></div></th>' +
//                            '<th rowspan="' + rows_nb + '" class=" ' + (Response[key1]['product_id'] == 0 ? 'btn-primary' : 'btn-info') + ' removeTags">' +
//                            '<div><i class="fa fa-times"></i> <span>' + Response[key1]['criteria_name'] + '</span></div> </th>';
//                    var row_col_index = 0;
//                    $.each(all_details, function (key2, value) {
//                        if (row_col_index == max_criteria_column) {
//                            content += '</tr><tr>';
//                            row_col_index = 0;
//                        }
//                        row_col_index++;
//                        content += '<td style="vertical-align:middle;text-align:center;" class="inputDiv ' + ($.inArray(all_details[key2]['criteria_detail_id'], current_criteria) !== -1 ? 'tagSelected' : '') + '">' +
//                                '<div class="btn btn-style inputDiv" style="width:100%">' + all_details[key2]['criteria_detail_name'] +
//                                '<input type="' + type + '" max-count="' + Response[key1]['criteria_max_count'] + '" data-criteria-id="' + Response[key1]['criteria_id'] + '" data-entry="' + all_details[key2]['criteria_detail_id'] + '"  tag-name="' + all_details[key2]['criteria_detail_name'] +
//                                '" data-ref ="" data-tag = "" ' + ($.inArray(all_details[key2]['criteria_detail_id'], current_criteria) !== -1 ? 'checked' : '') + ' value="' + all_details[key2]['criteria_detail_id'] + '" name="' + $.trim(Response[key1]['criteria_name']) + '" id="" class="form-control multiple-checkbox"></div>' +
//                                '</td>';
//                    });
//                    if (row_col_index < max_criteria_column)
//                        content += '<td colspan="' + (max_criteria_column - row_col_index) + '">&nbsp;</td>';
//                    content += '</tr>';
//                    if (Response[key1]['product_id'] == 0)
//                        general_criteria += content;
//                    else
//                        product_criteria += content;
//                });
//                tagTable += product_criteria + general_criteria + '</table>';
//                $('#tagsModal .criteria-detail-div').append($(tagTable))
//                $.each(current_criteria_notes, function (note_id, entry_id) {
//                    if (entry_id != undefined) {
//                        $("input[data-entry=" + note_id + "]").closest(".tag-note").val(entry_id)
//                    }
//                    //                        console.log(note_id + '==' + entry_id)
//                })
//                $('#addTag').attr('disabled', false)
//            } else {
//                $("#tagsModal .criteria-detail-div").append(' <div class="col-md-12 m-t-10 alert alert-warning">No criteria related to this item</div>');
//                $('#addTag').attr('disabled', true)
//            }
//        });
//    }
//    function removeTags() {
//        $("#TagsTable td,#TagsTable button").removeClass("tagSelected")
//        $("#TagsTable tr input:checked").parents('td').addClass("tagSelected")
//        $("#TagsTable tr input:checked").parents('button').addClass("tagSelected")
//
//    }
//    function updateTags() {
//        var item = $("#tagsModal").attr("data-id");
//        $("#OrderTable tbody tr:eq(" + item + ") div.bootstrap-tagsinput").empty();
//        var row_title = '';
//        $("#tagsModal .criteria-detail-div input:checked").each(function () {
//            var tag_name = $(this).attr("tag-name"),
//                    entry = $(this).val(),
//                    criteria_id = $(this).attr("data-criteria-id"),
//                    note = $(this).parents("tr").find(".tag-note").val();
//            row_title += tag_name + '\n';
//            var label_tag = '<span class="tag label label-stock mylabel" data-content="' + tag_name + '" data-criteria-id="' + criteria_id + '" data-note="' + note + '"  data-entry="' + entry + '">' + tag_name + '<span data-role="remove"></span></span>';
//            $("#OrderTable tbody tr:eq(" + item + ") div.bootstrap-tagsinput").append($(label_tag));
//        });
//        $("#OrderTable tbody tr:eq(" + item + ")").attr("title", row_title)
//        $("#tagsModal").modal("hide")
//    }
</script>
