var type = "rule";
var enumSalaryFactorType = {
    rule: "rule",
    functional: "functional",
    legal: "legal"
};
$(document).ready(function () {
    loadGrid("grdRule");
    loadGrid("grdFunctional");
    loadGrid("grdFunctionalAmount");
    loadGrid("grdLegal");
});
function loadGrid(gridId, objectParameter) {
    var gridBuilder = $("#" + gridId).gridBuilder();
    var isExportExcel = objectParameter && objectParameter.exportExcel ? true : false;
    ajax({
        loading: true,
        url: "SalaryApi/GetSalaryFactors",
        data: {
            salaryFactorType: gridId.replace("grd", "").replace("Amount", ""),
            isAmount: gridId.toLowerCase().indexOf("functionalamount") > 0 ? true : false,
            filter: gridBuilder.getFilter(),
            sort: gridBuilder.getSortFields(),
            pageNo: isExportExcel ? -1 : gridBuilder.getCurrentPageNumber()
        },
        success: function (data) {
            if (isExportExcel) {
                exportExcel(data, gridBuilder.getColumns(), gridBuilder.getColumnsCaption());
            }
            else
                gridBuilder.loadData(data);
        }
    });
}
function openModal(factorType) {
    var gridBuilder = $("#grd" + factorType).gridBuilder();
    var rowIndex = gridBuilder.getActiveRowIndex();
    if (rowIndex < 0)
        return;
    var title = window.top.edit + " " +  window.top.operative;
    if (factorType.toLowerCase() === enumSalaryFactorType.rule)
        title += " " + window.top.rule;
    else if (factorType.toLowerCase().indexOf(enumSalaryFactorType.functional) >= 0) {
        title += " " + window.top.functional;
        factorType = enumSalaryFactorType.functional;
    }
    else if (factorType.toLowerCase() === enumSalaryFactorType.legal)
        title += " " + window.top.legal;
    var code = gridBuilder.getCellValue(rowIndex, "Code");
    src = "Salary/FactorFunctionalSave?code=" + code + '&type=' + factorType;
    openInModal("", src, title, 950, 550, false);
}
function refresh(type) {
    loadGrid("grd" + type);
    if (type === "Functional")
        loadGrid("grdFunctionalAmount");
}
$(".menu-item").click(function () {
    $(".menu-item").removeClass("selected-menu-item");
    $(this).addClass("selected-menu-item");
    if ($(this).attr('id') == 'rule') {
        type = $(this).attr('id');
        $('#div-rule').show();
        $('#div-functional').hide();
        $('#div-legal').hide();
    }
    else if ($(this).attr('id') == 'functional') {
        type = $(this).attr('id');
        $('#div-rule').hide();
        $('#div-functional').show();
        $('#div-legal').hide();
    }
    else if ($(this).attr('id') == 'legal') {
        type = $(this).attr('id');
        $('#div-rule').hide();
        $('#div-functional').hide();
        $('#div-legal').show();
    }
});