﻿function show_popup(accept_url, accept_text, decline_url, decline_text, title, text, width, height, resizable, modal) {
    $.ui.dialog.defaults.bgiframe = true;

    $(function () {
        var dialog_span = document.getElementById('lbl_dialog_text');
        if (dialog_span) {
            dialog_span.firstChild.nodeValue = text;
        }
        else {
            dialog_span.firstChild.nodeValue = text;
        }

        var buttons_string = '';
        if ((accept_text != "") || (decline_text != "")) {
            buttons_string += " {";
            if (decline_text != "") {
                buttons_string += "'" + decline_text + "': function(ev, ui) { var new_url = window.location.href('" + decline_url + "'); $(this).dialog('destroy'); }";
            }
            else {
                buttons_string += "'" + decline_text + "': function(ev, ui) { $(this).dialog('destroy');}";
            }

            if ((accept_text != "") && (decline_text != "")) {
                buttons_string += ",";
            }


            if (accept_text != "") {
                buttons_string += "'" + accept_text + "': function(ev, ui) { var new_url = window.location.href('" + accept_url + "'); $(this).dialog('destroy'); }";
            }
            else {
                buttons_string += "'" + accept_text + "': function(ev, ui) { $(this).dialog('destroy');}";
            }
            buttons_string += " } ";


        }


        if (buttons_string != "") {
            if ((accept_text != "") && (decline_text != "")) {
                $("#dialog_client").dialog({ position: 'center', hide: 'blind', show: 'slide', width: width, height: height, modal: modal, resizable: resizable, title: title, buttons: { "Cancel": function (ev, ui) { $(this).dialog('destroy'); }, "I Agree": function (ev, ui) { var new_url = window.open(accept_url); $(this).dialog('destroy'); } }, open: function () { $(this).parents('.ui-dialog-buttonpane button:eq(1)').focus(); }, bgiframe: true, close: function (ev, ui) { $(this).dialog('destroy'); } });
            }
            else {
                $("#dialog_client").dialog({ position: 'center', hide: 'blind', show: 'slide', width: width, height: height, modal: modal, resizable: resizable, title: title, buttons: { "Cancel": function (ev, ui) { $(this).dialog('destroy'); }, "I Agree": function (ev, ui) { var new_url = window.open(accept_url); $(this).dialog('destroy'); } }, bgiframe: true, close: function (ev, ui) { $(this).dialog('destroy'); } });
            }
        }
        else {
            $("#dialog_client").dialog({ position: 'center', hide: 'blind', show: 'slide', width: width, height: height, modal: modal, resizable: resizable, title: title, bgiframe: true, close: function (ev, ui) { $(this).dialog('destroy'); } });
        }
        $("#dialog_client").dialog("open");
    })

}
