 

String.Format = function () {
    try {
        var s = arguments[0];
        for (var i = 0; i < arguments.length - 1; i++) {
            var reg = new RegExp("\\{" + i + "\\}", "gm");
            s = s.replace(reg, arguments[i + 1]);
        }
        return s;
    }
    catch (error) {
        console.log("Error: " + error);
    }
}
var dialogConfirmed = false;

function confirmationDialog(obj, title, dialogText) {
    try {
        if ($("#pageName").html() != null) {
            title = "Confirmation - " + $("#pageName").html();
            //Commented by anirudh J.
            //alert($("#pageName").html());
        }

        if (!dialogConfirmed) {
            $('body').append(String.Format("<div id='dialog' title='{0}'><p style='float:left;'><span class='ui-icon ui-icon-alert' style='float:left; margin:0 5px 20px 0;'></span>{1}</p></div>", title, dialogText));
            //alert("hi " + title);
            $('#dialog').dialog
                    ({
                        height: 180,
                        width: 350,
                        modal: true,
                        resizable: false,
                        draggable: true,
                        close: function (event, ui) { $('html').find('#dialog').remove(); },
                        buttons:
                        {
                            'Yes': function () {
                                $(this).dialog('close');
                                dialogConfirmed = true;
                            if (typeof obj === 'string' || obj instanceof String) {
                                    if (obj) $('[id$="' + obj + '"]').click();
                                    dialogConfirmed = false;
                                }
                            else {

                             
                                    if (obj) obj.click();
                                    dialogConfirmed = false;
                                }
                               
                            },
                            'No': function () {
                                $(this).dialog('close');
                            }
                        }
                    });
        }

        return dialogConfirmed;

        $(".ui-widget-overlay").height($("body").height());

    }
    catch (error) {
        console.log("Error: " + error);
    }
}


function Workflow_confirmationDialog(obj, title, dialogText,mode) {
    try {
       
        if ($("#pageName").html() != null) {
            title = "Confirmation - Workflow Blotter"; 
        }
        if (mode == 'dialog') {
            $('html').append(String.Format("<div id='dialog' title='{0}'><p style='float:left;'><span class='ui-icon ui-icon-alert' style='float:left; margin:0 5px 20px 0;'></span>{1}</p></div>", title, dialogText));
            $('#dialog').dialog
                    ({
                        height: 180,
                        width: 350,
                        position:{
                            my: "center",
                            at: "center",
                            of: screen
                        },
                        dialogClass: 'fixedClass',   /*Added by Arati k for popup position on 24 Dec 2020*/
                        modal: true,
                        resizable: false,
                        draggable: true,
                        close: function (event, ui) { $('html').find('#dialog').remove(); },
                        open: function (event, ui) {
                            $(this).parent().css('position', 'fixed');
                            
                        },
                        buttons:
                        {
                            'Yes': function () {
                                $(this).dialog('close');
                                //dialogConfirmed = true; 
                                //$("#ctl00_MainContent_workflowControl_hdnConfirmation").val("True");
                                //if (obj) obj.click($("#ctl00_MainContent_workflowControl_hdnConfirmation").val);
                                //PageMethods.GetCurrentTime("Rohit");

                                $("#ctl00_MainContent_workflowControl_btnConfirmation").click();

                                // dialogConfirmed = false;
                            },
                            'No': function () {
                                //$("#ctl00_MainContent_workflowControl_hdnConfirmation").val("False");
                                $(this).dialog('close');
                            }
                        }
                    })
        }
        if (mode == '') {
            $("#ctl00_MainContent_workflowControl_btnConfirmation").click();
        }
        //return dialogConfirmed;

       // $(".ui-widget-overlay").height($("body").height());

    }
    catch (error) {
        console.log("Error: " + error);
    }
}

//Added  by Arati K || 18 - Apr - 2022 || DBUPIN - 1015 || Start
function WorkflowCallDynamicAction_confirmationDialog(obj, title, dialogText, mode) {
    try {

        $(document).ready(function () {
            $.support.cors = true;
            $(document).find('[id$="dialog12345"]').remove();
            if ($("#pageName").html() != null) {
                title = "Confirmation - Workflow Blotter";
            }
            if (mode == 'dialog') {
                $('body').append(String.Format("<div id='dialog12345' title='{0}'><p style='float:left;'><span class='ui-icon ui-icon-alert' style='float:left; margin:0 5px 20px 0;'></span>{1}</p></div>", title, dialogText));

                $(document).find('[id$="dialog12345"]').dialog({
                    display: 'block',
                    modal: true,
                    draggable: true,
                    resizable: false,
                    autoOpen: true,
                    closeOnEscape: true,
                    autoOpen: true,
                    height: 200,
                    width: 350,
                    close: function (event, ui) {
                        $(document).find('[id$="dialog12345"]').remove();
                    },
                    open: function (event, ui) {
                        $(this).parent().css('position', 'fixed');
                    },
                    buttons:
                    {
                        'Yes': function () {
                            $("#ctl00_MainContent_workflowControl_btnConfirmation_calldynamicaction").click();
                            $(this).dialog('close');
                        },
                        'No': function () {
                            $(this).dialog('close');
                        }
                    }
                });
            }
            if (mode == '') {
                $("#ctl00_MainContent_workflowControl_btnConfirmation_calldynamicaction").click();
                return true;
            }
           
        });

    }
    catch (error) {
        console.log("Error: " + error);
    }
}
//Added  by Arati K || 18 - Apr - 2022 || DBUPIN - 1015 || Start
//Modified on 27-Sep-2019 by Shekhar for Empty Dailog.
var dialogConfirmed1 = false;
function UCP_ConfirmationDialog(obj, title, dialogText, width, height) {
    try {
        $(document).ready(function () {
            
            if ($("#pageName").html() != null && title == "") {
                  title = "Confirmation - " + $("#pageName").html();
            }
            if (height == undefined || height == "") {
                height = 180;
            }
            if (width == undefined || width == "") {
                width = 350;
            }
       
            if (!dialogConfirmed1) {
                if ($('#dialog').length <= 0) {
                    $('<div id="dialog" title=""></div>').appendTo('body');
                }
            $('#dialog').dialog
                    ({
                        title: title,
                        body: dialogText,
                        height: height,
                        width: width,
                        modal: true,
                        resizable: false,
                        draggable: true,
                        closeOnEscape: true,
                        closeOnMaskClick: false,
                        transitionMask: false,
                        //code Added by tejaswini on 15-Oct-2019 
                        close: function (event, ui) { $('html').find('#dialog').remove(); }, 
                        open:function() {
                            $('<p></p>').html(dialogText).appendTo('#dialog');
                        },
                        buttons:
                        {
                            'Yes': function () {
                                $(this).dialog('close');
                                dialogConfirmed1 = true;
                                $("#ctl00_MainContent_oUCPCtrl_hdnConfirmation").val("True");
                                document.getElementById(obj).click();
                                dialogConfirmed1 = false;
                            },
                            'No': function () {
                                $("#ctl00_MainContent_oUCPCtrl_hdnConfirmation").val("False");
                                $(this).dialog('close');
                            }
                        }
                    });
             }

            return dialogConfirmed1;

            $(".ui-widget-overlay").height($("body").height());
        });
    }
    catch (error) {
        console.log("Error: " + error);
    }
    return dialogConfirmed1;
}
 

//<Start || Added by Arshin S || on 14th Jan 2019 || asked by Milind Sir || PP-49 Getting pop up message while loading the existing package>
function confirmDialog(title, dialogText) {
    if ($("#pageName").html() != null) {
        title = "Confirmation - " + $("#pageName").html();
    }

    if (!dialogConfirmed) {
        var def = $.Deferred();

        $('html').append(String.Format("<div id='dialog' title='{0}'><p style='float:left;'><span class='ui-icon ui-icon-alert' style='float:left; margin:0 5px 20px 0;'></span>{1}</p></div>",
                    title, dialogText));

        $('#dialog').dialog
                ({
                    height: 180,
                    width: 350,
                    modal: true,
                    resizable: false,
                    draggable: true,
                    modal: true,
                    close: function (event, ui) { $('html').find('#dialog').remove(); },
                    buttons:
                    {
                        'Yes': function () {
                            $(this).dialog('close');
                            def.resolve("Yes");
                        },
                        'No': function () {
                            $(this).dialog('close');
                            def.resolve("No");
                        }
                    }
                });
    }

    return def.promise();

    $(".ui-widget-overlay").height($("body").height());
}
//<End || Added by Arshin S || on 14th Jan 2019 || asked by Milind Sir || PP-49 Getting pop up message while loading the existing package>

//START Added by Abhinav Tiwari for WLB Bonds Interation
function MsgDialog(obj, title, x, dialogText) {

    try {

        if (!dialogConfirmed) {
            if (x === 1) {
                if ($("#pageName").html() != null) {
                    title = "Information - " + $("#pageName").html();
                }

                $('html').append(String.Format("<div id='dialog' title='{0}'><table cellpadding='2' cellspacing='0'><tr><td style='padding:10px;'><img src='../App_Themes/images/imgSuccess.png' style='width:18px;height:18px;'></td><td><p style='float:left;color:#008000;'><span style='float:left;margin:0 0 20px 0;'></span>{1}</p></td> </tr></table></div>",
                               title, dialogText));
            }
            else if (x === 0) {
                if ($("#pageName").html() != null) {
                    title = "Warning - " + $("#pageName").html();
                }

                $('html').append(String.Format("<div id='dialog' title='{0}'><table cellpadding='2' cellspacing='0'><tr><td style='padding:10px;'><img src='../App_Themes/images/Warning_Msg.png' style='width:18px;height:18px;'></td><td><p style='float:left;color:#0368b6;'><span style='float:left;margin:0 0 20px 0;'></span>{1}</p></td> </tr></table></div>",
                               title, dialogText));

            }
            $('#dialog').dialog
                    ({
                        height: 180,
                        width: 350,
                        modal: true,
                        resizable: false,
                        draggable: true,
                        close: function (event, ui) { $('html').find('#dialog').remove(); },
                        buttons:
                        {

                            'OK': function () {
                                $(this).dialog('close');
                            }
                        }
                    });
        }

        return dialogConfirmed;

        $(".ui-widget-overlay").height($("body").height());

    }
    catch (error) {
        console.log("Error: " + error);
    }
}
//END Added by Abhinav Tiwari for WLB Bonds Interation



