function ShowNotification(type, msg, closeCallback, acceptCallback) {
    PopUpNotificationModal(type, msg, closeCallback, acceptCallback)

    //var tbsErrorWindowElement = $("<div class='TBSErrorWindow'>"
    //            + "<img />"
    //            + "<div class='ErrorMessage'>"
    //            + "</div>"
    //            + "<div class='ErrorButtons'>"
    //                + "<button class='ErrorButton tbsButton btnAccept'>تایید</button>"
    //                + "<button class='ErrorButton tbsButton btnCancel'>انصراف</button>"
    //            + "</div>"
    //        + "</div>").appendTo('body');
    //var tbsErrorWindow = $(tbsErrorWindowElement).kendoWindow({
    //          draggable: true
    //        , modal: true
    //        , title: false
    //        , resizable: false
    //        , visible: false
    //    }).data('kendoWindow');

    //switch (type) {
    //    case 'error':
    //        $(tbsErrorWindowElement).css('border-color', '#fc430c');
    //        $(tbsErrorWindowElement).children('img').attr("src", tbsRootURL + '/Content/Image/Component/Notification/Error.png');
    //        break;
    //    case 'success':
    //        $(tbsErrorWindowElement).css('border-color', '#65bb0e');
    //        $(tbsErrorWindowElement).children('img').attr("src", tbsRootURL + '/Content/Image/Component/Notification/Access.png');
    //        break;
    //    case 'conf':
    //        $(tbsErrorWindowElement).css('border-color', '#7574a8');
    //        $(tbsErrorWindowElement).children('img').attr("src", tbsRootURL + '/Content/Image/Component/Notification/Confirm.png');
    //        break;
    //    case 'inf':
    //        $(tbsErrorWindowElement).css('border-color', '#2780c4');
    //        $(tbsErrorWindowElement).children('img').attr("src", tbsRootURL + '/Content/Image/Component/Notification/Information.png');
    //        $(tbsErrorWindowElement).children('.ErrorButtons').children('.tbsButton.btnCancel').css('display', 'inline-block');
    //        break;
    //    case 'warn':
    //        $(tbsErrorWindowElement).css('border-color', '#fcbe0d');
    //        $(tbsErrorWindowElement).children('img').attr("src", tbsRootURL + '/Content/Image/Component/Notification/Warning.png');
    //        break;
    //    case 'fail':
    //        $(tbsErrorWindowElement).css('border-color', '#fa7419');
    //        $(tbsErrorWindowElement).children('img').attr("src", tbsRootURL + '/Content/Image/Component/Notification/fail.png');
    //        break;
    //}
    //if (closeCallback != undefined)
    //    tbsErrorWindow.bind('close', closeCallback);
    //$(tbsErrorWindowElement).children('.ErrorMessage').html(msg);
    //tbsErrorWindow.center();

    ////$("#myErrorModal").modal();

    //tbsErrorWindow.open();


    //$(tbsErrorWindowElement).keypress(function (args) {
    //    if (args.keyCode == 13) {
    //        $(tbsErrorWindowElement).children('.ErrorButtons').children('.tbsButton.btnAccept').click();
    //    }
    //})
    //$(tbsErrorWindowElement).children('.ErrorButtons').children('.tbsButton').click(function () {
    //    if (type == 'inf' && $(this).hasClass('btnAccept')) {
    //        acceptCallback();
    //    }
    //    if (closeCallback != undefined)
    //        closeCallback();
    //    tbsErrorWindow.close();
    //});

}

function ShowNotification(type, msg, closeCallback, acceptCallback, Components) {
    PopUpNotificationModal(type, msg, closeCallback, acceptCallback, Components)

    //var tbsErrorWindowElement = $("<div class='TBSErrorWindow'>"
    //            + "<img />"
    //            + "<div class='ErrorMessage'>"
    //            + "</div>"
    //            + "<div class='ErrorButtons'>"
    //                + "<button class='ErrorButton tbsButton btnAccept'>تایید</button>"
    //                + "<button class='ErrorButton tbsButton btnCancel'>انصراف</button>"
    //            + "</div>"
    //        + "</div>").appendTo('body');
    //var tbsErrorWindow = $(tbsErrorWindowElement).kendoWindow({
    //    draggable: true
    //        , modal: true
    //        , title: false
    //        , resizable: false
    //        , visible: false
    //}).data('kendoWindow');



    //switch (type) {
    //    case 'error':
    //        $(tbsErrorWindowElement).css('border-color', '#fc430c');
    //        $(tbsErrorWindowElement).children('img').attr("src", tbsRootURL + '/Content/Image/Component/Notification/Error.png');
    //        break;
    //    case 'success':
    //        $(tbsErrorWindowElement).css('border-color', '#65bb0e');
    //        $(tbsErrorWindowElement).children('img').attr("src", tbsRootURL + '/Content/Image/Component/Notification/Access.png');
    //        break;
    //    case 'conf':
    //        $(tbsErrorWindowElement).css('border-color', '#7574a8');
    //        $(tbsErrorWindowElement).children('img').attr("src", tbsRootURL + '/Content/Image/Component/Notification/Confirm.png');
    //        break;
    //    case 'inf':
    //        $(tbsErrorWindowElement).css('border-color', '#2780c4');
    //        $(tbsErrorWindowElement).children('img').attr("src", tbsRootURL + '/Content/Image/Component/Notification/Information.png');
    //        $(tbsErrorWindowElement).children('.ErrorButtons').children('.tbsButton.btnCancel').css('display', 'inline-block');
    //        break;
    //    case 'warn':
    //        $(tbsErrorWindowElement).css('border-color', '#fcbe0d');
    //        $(tbsErrorWindowElement).children('img').attr("src", tbsRootURL + '/Content/Image/Component/Notification/Warning.png');
    //        break;
    //    case 'fail':
    //        $(tbsErrorWindowElement).css('border-color', '#fa7419');
    //        $(tbsErrorWindowElement).children('img').attr("src", tbsRootURL + '/Content/Image/Component/Notification/fail.png');
    //        break;
    //}
    //if (closeCallback != undefined)
    //    tbsErrorWindow.bind('close', closeCallback);
    //$(tbsErrorWindowElement).children('.ErrorMessage').html(msg);
    //tbsErrorWindow.center();

    ////$("#myErrorModal").modal();

    //tbsErrorWindow.open();

    //$(tbsErrorWindowElement).keypress(function (args) {
    //    if (args.keyCode == 13) {
    //        $(tbsErrorWindowElement).children('.ErrorButtons').children('.tbsButton.btnAccept').click();
    //    }
    //})
    //$(tbsErrorWindowElement).children('.ErrorButtons').children('.tbsButton').click(function () {
    //    if (type == 'inf' && $(this).hasClass('btnAccept')) {
    //        acceptCallback();
    //    }
    //    if (closeCallback != undefined)
    //        closeCallback();
    //    tbsErrorWindow.close();
    //});
}

function PopUpNotificationModal(type, msg, closeCallback, acceptCallback, Components) {
    if (msg == "" || msg == undefined)
        msg = "عملیات با خطا مواجه گردید";
    var modalWindow = $("#myErrorModal > .modal-dialog > .modal-content");
    var modalBody = $("#myErrorModal > .modal-dialog > .modal-content > .modal-body");
    var MessageImage = $("#myErrorModal .modal-content > .modal-body > span.MessageImage");
    var MessageText = $("#myErrorModal .modal-content > .modal-body > p.MessageText");//.text('alire')
    var ActionButtons = $("#myErrorModal .modal-content > .modal-footer");
    var CloseButton;
    //CloseButton = "<button type=\"button\" id=\"btnClose\" class=\"btn btn-default btn-xs\" data-dismiss=\"modal\">بستن</button>";
    CloseButton = "<a role=\"button\" id=\"btnClose\" class=\"popup-notification-close\" data-dismiss=\"modal\"><span class=\"fa fa-times\"></span></a>";
    modalBody.css("min-height", "100px");
    modalWindow.css("color", "white");
    MessageImage.css("padding-top", "20px");
    MessageText.css("margin-right", "5px");
    var AcceptButton = "";
    if (acceptCallback != undefined && acceptCallback != '') {
        AcceptButton = "<button type=\"button\" id=\"btnAccept\" class=\"btn btn-default btn-xs\" data-dismiss=\"modal\" >تایید</button>";
    }
    //if (closeCallback != undefined && closeCallback != '') {
    //    CloseButton = "<button type=\"button\" class=\"btn btn-default btn-xs\" data-dismiss=\"modal\" onclick=\"" + closeCallback + "\">Close</button>";
    //}
    //else {
    //    CloseButton = "<button type=\"button\" class=\"btn btn-default btn-xs\" data-dismiss=\"modal\">Close</button>";
    //}
    //var AcceptButton;
    //if (acceptCallback != undefined && acceptCallback != '') {
    //    AcceptButton = "<button type=\"button\" class=\"btn btn-default btn-xs\" data-dismiss=\"modal\" onclick=\"" + acceptCallback + "()\">Close</button>";
    //}
    //else {
    //    AcceptButton = "";
    //}
    switch (type) {
        case 'error':
            //modalWindow.css("border", "solid 3px #fc430c");
            //MessageImage.html("<img class=\"modal-title-image\" src=\" " + tbsRootURL + "/Content/Image/Component/Notification/Error.png\" >");
            modalWindow.css("background-color", "red");
            MessageImage.html("<span class=\"notification-icon fa  fa-times-circle\"></span>");
            break;
        case 'Error':
            //modalWindow.css("border", "solid 3px #fc430c");
            //MessageImage.html("<img class=\"modal-title-image\" src=\" " + tbsRootURL + "/Content/Image/Component/Notification/Error.png\" >");
            modalWindow.css("background-color", "red");
            MessageImage.html("<span class=\"notification-icon fa fa-times-circle\"></span>");
            break;
        case 'success':
            //modalWindow.css("border", "solid 3px #65bb0e");
            //MessageImage.html("<img class=\"modal-title-image\" src=\" " + tbsRootURL + "/Content/Image/Component/Notification/Access.png\" >");
            modalWindow.css("background-color", "#65bb0e");
            MessageImage.html("<span class=\"notification-icon fa fa-check-circle\"></span>");
            break;
        case 'conf':
            //modalWindow.css("border", "solid 3px #7574a8");
            //MessageImage.html("<img class=\"modal-title-image\" src=\" " + tbsRootURL + "/Content/Image/Component/Notification/Confirm.png\" >");
            modalWindow.css("background-color", "#7574a8");
            MessageImage.html("<span class=\"notification-icon fa fa-question-circle\"></span>");
            break;
        case 'inf':
            //modalWindow.css("border", "solid 3px #2780c4");
            //MessageImage.html("<img class=\"modal-title-image\" src=\" " + tbsRootURL + "/Content/Image/Component/Notification/Information.png\" >");
            modalWindow.css("background-color", "#2780c4");
            MessageImage.html("<span class=\"notification-icon fa fa-info-circle\"></span>");
            break;
        case 'warn':
            //modalWindow.css("border", "solid 3px #fcbe0d");
            modalWindow.css("background-color", "#fcbe0d");
            MessageImage.html("<span class=\"notification-icon fa fa-exclamation-triangle\"></span>");
            //MessageImage.html("<img class=\"modal-title-image\" src=\" " + tbsRootURL + "/Content/Image/Component/Notification/Warning.png\" >");
            break;
        case 'fail':
            //modalWindow.css("border", "solid 3px #fa7419");
            modalWindow.css("background-color", "red");
            MessageImage.html("<span class=\"notification-icon fa fa-minus-circle\"></span>");
            //MessageImage.html("<img class=\"modal-title-image\" src=\" " + tbsRootURL + "/Content/Image/Component/Notification/fail.png\" >");
            break;
    }
    MessageText.html(msg);
    modalBody.prepend(CloseButton);
    ActionButtons.html(AcceptButton);
    //ActionButtons.html(AcceptButton + "\n" + CloseButton);
    if (closeCallback != undefined && closeCallback != '') {
        $("#myErrorModal #btnClose").click(function () {
            debugger
            closeCallback();
        });
    }
    if (acceptCallback != undefined && acceptCallback != '') {
        $("#myErrorModal #btnAccept").click(function () {
            acceptCallback();
        });
    }

    $("#myErrorModal").modal();
}

function ErrorHandler(e) {
    if (e.Errors) {
        var message = "";
        // Create a message containing all errors.
        $.each(e.Errors, function (key, value) {
            if ('errors' in value && key === "Error") {
                $.each(value.errors, function () {
                    message += this;
                });
            }
        });
        // Display the message

        ShowNotification('error', message);
    }
    else if (e.errors) {
        var message = "";
        // Create a message containing all errors.
        $.each(e.errors, function (key, value) {
            if ('errors' in value && key === "Error") {
                $.each(value.errors, function () {
                    message += this;
                });
            }
        });
        // Display the message

        ShowNotification('error', message);
    }
    else if (typeof e === 'string' || e instanceof String) {
        ShowNotification('error', e);
    }
    else if (e === 409) {
        ShowNotification('error', "<p>خطا در ارسال درخواست تکراری ... لطفا دوباره تلاش کنید</p>");
    }
    else if (e === 403 || e.errorThrown == 'Forbidden') {
        ShowNotification('error', "<p>خطا در احراز هویت...</p>");
        setTimeout(function () {
            window.location.href = "Account/Logout"; location.reload(true);
        },2000);
    }
    else if (e === 426) {
        ShowNotification('error', "<p>عبارت امنیتی صحیح نیست ...</p>");
    }
    else {
        ShowNotification('error', 'انجام عملیات با بروز خطا مواجه گردید');
    }
}