/* Minification failed. Returning unminified contents.
(1,12): run-time error CSS1031: Expected selector, found '='
(1,12): run-time error CSS1025: Expected comma or open brace, found '='
(24,11): run-time error CSS1031: Expected selector, found ';'
(24,11): run-time error CSS1025: Expected comma or open brace, found ';'
(25,22): run-time error CSS1031: Expected selector, found ';'
(25,22): run-time error CSS1025: Expected comma or open brace, found ';'
(26,1): run-time error CSS1019: Unexpected token, found '$'
(26,2): run-time error CSS1019: Unexpected token, found '('
(26,11): run-time error CSS1031: Expected selector, found ')'
(26,11): run-time error CSS1025: Expected comma or open brace, found ')'
(212,2): run-time error CSS1019: Unexpected token, found ')'
(215,10): run-time error CSS1031: Expected selector, found 'IsPISelected('
(215,10): run-time error CSS1025: Expected comma or open brace, found 'IsPISelected('
(225,10): run-time error CSS1031: Expected selector, found 'SaveData('
(225,10): run-time error CSS1025: Expected comma or open brace, found 'SaveData('
(253,10): run-time error CSS1031: Expected selector, found 'CheckedChange('
(253,10): run-time error CSS1025: Expected comma or open brace, found 'CheckedChange('
(257,10): run-time error CSS1031: Expected selector, found 'PriceGroupCheckedChange('
(257,10): run-time error CSS1025: Expected comma or open brace, found 'PriceGroupCheckedChange('
(262,10): run-time error CSS1031: Expected selector, found 'ShowPriceGroup('
(262,10): run-time error CSS1025: Expected comma or open brace, found 'ShowPriceGroup('
(268,10): run-time error CSS1031: Expected selector, found 'SelectedAll('
(268,10): run-time error CSS1025: Expected comma or open brace, found 'SelectedAll('
(273,10): run-time error CSS1031: Expected selector, found 'changeButtonEnable('
(273,10): run-time error CSS1025: Expected comma or open brace, found 'changeButtonEnable('
(287,10): run-time error CSS1031: Expected selector, found 'resetPriceGroupCheckBox('
(287,10): run-time error CSS1025: Expected comma or open brace, found 'resetPriceGroupCheckBox('
(294,10): run-time error CSS1031: Expected selector, found 'changePriceGroupEnable('
(294,10): run-time error CSS1025: Expected comma or open brace, found 'changePriceGroupEnable('
(305,10): run-time error CSS1031: Expected selector, found 'changePriceGroupButtonEnable('
(305,10): run-time error CSS1025: Expected comma or open brace, found 'changePriceGroupButtonEnable('
(318,10): run-time error CSS1031: Expected selector, found 'getSelectID('
(318,10): run-time error CSS1025: Expected comma or open brace, found 'getSelectID('
(329,10): run-time error CSS1031: Expected selector, found 'getPriceGroupSelectID('
(329,10): run-time error CSS1025: Expected comma or open brace, found 'getPriceGroupSelectID('
(340,10): run-time error CSS1031: Expected selector, found 'ReLoadPIAndCompany('
(340,10): run-time error CSS1025: Expected comma or open brace, found 'ReLoadPIAndCompany('
 */
var config = {
    clims: GWZ.CLIMS,
    tableID: '#myPIAndCompanyTable', 
    tablePriceGroupID: '#myPriceGroupsTable',
    errorSection: '.gwz-pg-error-summary-section',
    priceGroupAssignType: '#PriceGroupAssignType',
    actionModalView: '#actionModalView',
    assignPriceGroup: '#assignPriceGroup',
    inactivePIIN: '#confirmInactive',
    btnRemove: '#btnRemove',
    btnAssin: '#btnAssin',
    ready2Inact: '#ready2Inact',
    btnInact: '#btnIsact',
    btnSave: '#btnSave',
    btnMsgYes: '#btnMsgYes',
    btnMsgNo: '#btnMsgNo',
    btnYes_Icon: '#btnYes_Icon',
    msgboxtitle: '#msgboxtitle',
    msgicon: '#msgicon',
    msgContent: '#msgContent',
    msgAction: '#msgAction',
    msgError: '#msgError',
};
var oTable;
var oPriceGroupsTable;
$(document).ready(function () {
    oPriceGroupsTable = $(config.tablePriceGroupID).DataTable({
        ajax: {
            url: PGAInfo.GetPriceGroupListUrl,
            type: "POST"
        },
        language: {
            lengthMenu: DataTableInfo.DataTableResource.lengthMenu,
            zeroRecords: DataTableInfo.DataTableResource.zeroRecords,
            sInfo: DataTableInfo.DataTableResource.sInfo,
            oPaginate: {
                sFirst: DataTableInfo.DataTableResource.sFirst,
                sPrevious: DataTableInfo.DataTableResource.sPrevious,
                sNext: DataTableInfo.DataTableResource.sNext,
                sLast: DataTableInfo.DataTableResource.sLast
            },
            sSearch: DataTableInfo.DataTableResource.sSearch
        },
        "dom": '<<"#gwz_dt_Processing"r><"row"><t><"gwz-grid-footer" <"col-md-3"l><"col-md-3"i><"col-md-6"p>>>',
        bAutoWidth: false,
        processing: true,
        serverSide: true,
        paging: true,
        pagingType: "bootstrap",
        lengthMenu: [[10, 25, 50, 500], [10, 25, 50, 500]],
        aoColumnDefs: [
            { "bSortable": false, "aTargets": [0] },
            { "sWidth": "10%", "aTargets": [0] },
            { "sWidth": "18%", "aTargets": [1, 2, 3, 4, 5] }
        ],
        aaSorting: [],
        order: [[1, "asc"]],
        columns: [
            {
                data: "PriceGroupID",
                className: "center",
                render: function (data, type, row) {
                    return '<label class="checkbox"><input onclick="PriceGroupCheckedChange(this);" data-pricegroupid="' + data + '" type="checkbox"  name="chkProject" ></label>' + row.IndexTemp;
                }
            },
            {
                data: "PriceGroupName",
                render: function (data, type, row) {
                    return '<a class="gwz-grid-link"  title="Edit project" onclick="ShowPriceGroup(this);" data-projectid="' + row.PriceGroupID + '" id="ShareOrder">' + data + '</a>';
                }
            },
            { data: "PriceGroupDetail" },
            { data: "BasePriceGroupName" },
            { data: "CurrencyCode" },
            {
                data: "ExpirationDate",
                render: function (data, type, row) {
                    if (row.IsExpired === true) {
                        return '<div style="width:100%; background-color:violet">' + row.ExpirDate + '</div>';
                    }
                    else {
                        return row.ExpirDate;
                    }
                }
            }
        ],
        tableTools: {
            aButtons: [
            ]
        }
    });
    //Bind the search function
    oPriceGroupsTable.columns().eq(0).each(function (colIdx) {
        var it = $('input', oPriceGroupsTable.column(colIdx).footer());
        if (it !== null) {
            it.on('keyup change', function () {
                oPriceGroupsTable.column(colIdx).search(this.value).draw();
            })
        };
    });

    oPriceGroupsTable.on('draw.dt', function () {
        changePriceGroupButtonEnable();
    });

    //Bind datatable
    oTable = $(config.tableID).DataTable({
        ajax: {
            url: PGAInfo.GetPIAndCompanyListUrl,
            type: "POST",
            data: function (param) {
                return param;
            }
        },
        language: {
            lengthMenu: DataTableInfo.DataTableResource.lengthMenu,
            zeroRecords: DataTableInfo.DataTableResource.zeroRecords,
            sInfo: DataTableInfo.DataTableResource.sInfo,
            oPaginate: {
                sFirst: DataTableInfo.DataTableResource.sFirst,
                sPrevious: DataTableInfo.DataTableResource.sPrevious,
                sNext: DataTableInfo.DataTableResource.sNext,
                sLast: DataTableInfo.DataTableResource.sLast
            },
            sSearch: DataTableInfo.DataTableResource.sSearch
        },
        "dom": '<<"#gwz_dt_Processing"r><"row"<"col-md-3"f><"gwz-action-button-box">><t><"gwz-grid-footer" <"col-md-3"l><"col-md-3"i><"col-md-6"p>>>',
        bAutoWidth: false,
        processing: true,
        serverSide: true,
        paging: true,
        pagingType: "bootstrap",
        lengthMenu: [[10, 25, 50, 500], [10, 25, 50, 500]],
        aoColumnDefs: [
            { "bSortable": false, "aTargets": [0] },
            { "sWidth": "1%", "aTargets": [0] },
            { "sWidth": "5%", "aTargets": [1, 2,3,4] },
            { "sWidth": "10%", "aTargets": [5] }
        ],
        aaSorting: [],
        order: [[1, "asc"]],
        columns: [
            {
                data: "ID",
                className: "center",
                render: function (data, type, row) {
                    return '<label class="checkbox"><input onclick="CheckedChange();" data-projectid="' + data + '" type="checkbox"  name="chkProject" ></label>';
                }
            },
            { "data": "CountryName" },
            { "data": "CountryCode" },
            { "data": "IndexTemp" },
            { "data": "PriceGroupCode" },
            { "data": "Description" }
        ],
        tableTools: {
            aButtons: [
            ]
        }
    });

    //Bind the search function
    oTable.columns().eq(0).each(function (colIdx) {
        var it = $('input', oTable.column(colIdx).footer());
        if (it !== null) {
            it.on('keyup change', function () {
                oTable.column(colIdx).search(this.value).draw();
            })
        };
    });

    oTable.on('draw.dt', function () {
        changeButtonEnable();
    });

    //move the buttons
    $("#actionButtons").appendTo($(".gwz-action-button-box"));
    //move the processing bar
    $("#pro_bar").appendTo($("#gwz_dt_Processing>.dataTables_processing"));


    //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    //bind remove assigned price group function
    $(config.btnRemove).on("click", function () {
        $(config.msgboxtitle).text(PGAInfo.LanguageResource.PGM_Assign_Unassign_Title);
        $(config.msgicon).removeClass().addClass("fa fa-trash-o");
        $(config.msgContent).text(PGAInfo.LanguageResource.PGM_Assign_Unassign_Content);
        $(config.msgAction).val("D");

        ShowMessageBox();
    });
    //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    //bind assing price group function
    $(config.btnAssin).on("click", function () {
        $(config.assignPriceGroup).modal('show');
        $(config.errorSection).hide();
        resetPriceGroupCheckBox();
    });
    //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    //Inactive duplicate PI or Institution
    $(config.btnInact).on("click", function () {
        $(config.inactivePIIN).modal('show');
    });

    //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    //bind save function
    $(config.btnSave).on("click", function () {
        SaveData();
    });
    //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

});

//function check if dropdown list selected is PI
function IsPISelected() {
    var value = $(config.priceGroupAssignType).val();
    if (value == "PI") {
        return true;
    } else {
        return false;
    }
}

//Save function save the form data
function SaveData() {
    config.clims.showPleaseWait(PGAInfo.LanguageResource.UI_Customer_Loading);

    actionUrl = PGAInfo.UpdateAssigendPriceGroupUrl;

    if (actionUrl.length > 0) {
        $.ajax({
            url: actionUrl,
            type: 'POST',
            data: JSON.stringify({ countryIds: getSelectID(), priceGroupID: getPriceGroupSelectID() }),
            contentType: 'application/json; charset=utf-8',
            success: function (data) {
                config.clims.hidePleaseWait();
                if (data.sta == 'true') {
                    $.jGrowl(PGAInfo.LanguageResource.COMPLETED, { header: PGAInfo.LanguageResource.PGM_Assign_Title, theme: "info", position: "top-right" });
                    ReLoadPIAndCompany();
                } else {
                    $.jGrowl(PGAInfo.LanguageResource.CustomerInternalError + '<br/>' + data.err.join('<br/>'), { header: PGAInfo.LanguageResource.PGM_Assign_Title, theme: "error", position: "top-right" });
                }
            },
            error: function (e) {
                config.clims.hidePleaseWait();
                $.jGrowl(PGAInfo.LanguageResource.CustomerInternalError, { header: PGAInfo.LanguageResource.PGM_Assign_Title, theme: "error", position: "top-right" });
            }
        });
    }
}
//function check checkbox change
function CheckedChange() {
    changeButtonEnable();
}
//function check checkbox change
function PriceGroupCheckedChange(chkbox) {

    changePriceGroupEnable(chkbox);
}
//function show new page to view price group details
function ShowPriceGroup(aLink) {
    var id = $(aLink).attr('data-projectid');
    var url = PGAInfo.EditPriceGroupUrl + '?ID=' + id + '&viewType=Edit';
    window.open(url, '_blank');
}
//function select all checkbox clicked
function SelectedAll(chkbox) {
    $(config.tableID + " input[data-projectid]").attr("checked", chkbox.checked);
    changeButtonEnable();
}
//function change the buttons disable based on selected records
function changeButtonEnable() {
    var selectedBox = $(config.tableID + " input[data-projectid]:checked").length;
    if (selectedBox === 0) {
        $(config.btnRemove).attr("disabled", "disabled");
        $(config.btnAssin).attr("disabled", "disabled");
        $(config.btnInact).attr("disabled", "disabled");
    }
    else {
        $(config.btnRemove).removeAttr("disabled");
        $(config.btnAssin).removeAttr("disabled");
        $(config.btnInact).removeAttr("disabled");
    }
}
//function reset all records as un checked
function resetPriceGroupCheckBox() {
    $(config.tablePriceGroupID + " input[data-pricegroupid]").each(function () {
        $(this).attr("checked", false);
    });
    changePriceGroupButtonEnable();
}
//functin only could select one record, should set other as un checked
function changePriceGroupEnable(chkbox) {
    if (chkbox.checked) {
        $(config.tablePriceGroupID + " input[data-pricegroupid]:checked").each(function () {
            if ($(this).attr("data-pricegroupid") !== $(chkbox).attr("data-pricegroupid")) {
                $(this).attr("checked", false);
            }
        });
    }
    changePriceGroupButtonEnable();
}
//function change the buttons disable based on selected records
function changePriceGroupButtonEnable() {

    var selectedBox = $(config.tablePriceGroupID + " input[data-pricegroupid]:checked").length;
    if (selectedBox === 0) {
        $(config.btnSave).attr("disabled", "disabled");
    }
    else {
        if (editAuthority != "False") {
            $(config.btnSave).removeAttr("disabled");
        }
    }
}
//function get all selected IDs
function getSelectID() {
    var ids = "";
    $(config.tableID + " input[data-projectid]:checked").each(function () {
        ids += $(this).attr("data-projectid") + ","
    });
    if (ids !== null && ids.length > 0) {
        return ids.substring(0, ids.length - 1);
    }
    return "";
}
//function get price group selected IDs
function getPriceGroupSelectID() {
    var ids = "";
    $(config.tablePriceGroupID + " input[data-pricegroupid]:checked").each(function () {
        ids += $(this).attr("data-pricegroupid") + ","
    });
    if (ids !== null && ids.length > 0) {
        return ids.substring(0, ids.length - 1);
    }
    return "";
}
//function reload table data
function ReLoadPIAndCompany() {
    if (oTable !== null) {
        oTable.ajax.reload(changeButtonEnable, false);
    }

    $(config.actionModalView).modal('hide');
    $(config.assignPriceGroup).modal('hide');
}
