loadPrioritySelectCell=function(selectId){
    $('#commonValidAlert').remove();
    $(".slick-cell.active").removeClass("redAlert");
    var serviceId=$("#serviceList").val();
    var moduleId = $("#moduleId").val();
    var projectId=$("#projectId").val();
    var grid =$('#listingGrid').data("gridInstance1");
    var row = grid.getActiveCell().row;
    var cell = grid.getActiveCell().cell;
    var colum = '';
var levels = [];
var data=grid.getData()[row];
for (var key in data) {
    if (data.hasOwnProperty(key) && key !== "impact") {
        levels.push(key);
    }
}
levels.sort();
 colum = levels[cell - 1];
    var selectedPriorityMatrixID = grid.getData()[row][colum][0].selectedKey;
    var $input;
    $.ajax({
        url: "getPriorityList.do",
        type: "POST",
        dataType: 'json',
        async: false,
        data:"projectId="+projectId+"&serviceId="+serviceId,
        success:function(result){
            $input=$("#"+selectId);
            $input.empty();
            $.each(result, function(key, value){
                var selected = "";
                if((","+selectedPriorityMatrixID+",").indexOf(key) !== -1){
                    selected = "selected";
                }
                $input.append("<option value='"+key+"' "+selected+">"+value+"</option>");
            });
        },complete:function(){

        }
    });
}

$(document).on("click", "#applyConfigForAllService", function () {
    if($("#commonValidAlert").is(":visible")==false){
        var isActive=$(this).prop("checked");
        if(isActive==true){
            $(".columnGroupHeader").before('<div id="ConfirmationBlk" class="confirmBlk" style="display: block;"><p>This configuration will be applied for all the services. Do you want to continue?<a href="javascript:void(0)" id="ConfirmActivateBtn" class="yesBtn">Yes</a><a href="javascript:void(0)" id="hideAlertBox" class="noBtn">No</a></p></div>');
        }else{
            var projectId=$("#projectId").val();
            $.ajax({
                url: "getServiceList.do",
                type: "POST",
                dataType: 'json',
                async: false,
                data:"projectId="+projectId,
                success:function(result){
                    $input=$("#serviceList");
                    $("#serviceList").empty();
                    $.each(result, function(key, value){
                        $input.append("<option id="+key+" value='"+key+"'>"+value+"</option>");
                    });
                    $("#serviceList").multipleSelect("refresh");
                    $("#serviceList").multipleSelect("enable");
                },complete:function(){

                }
            });
            $("#PriorityMatrixGridBlock #hideAlertBox").click();
        }
    }
});
$(document).on("click","#PriorityMatrixGridBlock #ConfirmActivateBtn",function(){
    $("#loading.loadIco").show();
    var serviceId=$("#serviceList").val();
    var projectId=$("#projectId").val();
    var moduleId = $("#moduleId").val();
    setTimeout(function(){
        $.ajax({
            url: "applyConfigForAllServices.do",
            type: "POST",
            dataType: 'json',
            async: false,
            data: "serviceId=" + serviceId + "&projectId=" + projectId + "&allServices=true",
            success: function (result) {
            },
            complete: function () {
                $("#ConfirmationBlk").remove();
                $("#applyConfigForAllService").prop("checked",false);
                $("#loading.loadIco").hide();
            }
        });
        loadSdGridData(projectId, moduleId,'1','10');
    },100);

});
$(document).on("click","#PriorityMatrixGridBlock #hideAlertBox",function(){
    $("#applyConfigForAllService").prop("checked",false);
    var serviceId=$("#serviceList").val();
    var projectId=$("#projectId").val();
    $.ajax({
        url: "applyConfigForAllServices.do",
        type: "POST",
        dataType: 'json',
        async: false,
        data: "serviceId=" + serviceId + "&projectId=" + projectId + "&allServices=false",
        success: function (result) {
        },
        complete: function () {
            $(document).click();
        }
    });
});
$(document).on("click","#PriorityMatrixGridBlock #allowOverridePriority",function(){
    var serviceId=$("#serviceList").val();
    var projectId=$("#projectId").val();
    var moduleId = $("#moduleId").val();
    var isActive=$(this).prop("checked");
    if(isActive==true){
        isActive=1;
    }else{
        isActive=0;
    }
    $.ajax({
        url: "overridePriority.do",
        type: "POST",
        dataType: 'json',
        async: false,
        data: "serviceId=" + serviceId + "&projectId=" + projectId + "&loadPriority="+isActive,
        success: function (result) {
        },
        complete: function () {

        }
    });
    loadSdGridData(projectId, moduleId,'1','10');
});
savePriorityMatrixDetails=function(projectId, dataToSave){
    var serviceId=$("#serviceList").val();
    var moduleId = $("#moduleId").val();
    $.ajax({
        url: "savePriorityMatrixDetails.do",
        type: "POST",
        dataType: 'json',
        async: false,
        data: "serviceId=" + serviceId + "&projectId=" + projectId + "&urgencyID="+dataToSave[0].urgencyKey + "&impactID="+dataToSave[0].impactKey + "&priorityName="+dataToSave[0].selectedPriority,
        success: function (result) {
        },
        complete: function () {
        }
    });
    loadSdGridData(projectId, moduleId, '1', '10');
}