
/**
 * params:
 *   - id
 *   - diag_title
 *   - width
 *   - close_btn_text
 */
function show_modal_dialog(params) {
    function uof(x) { return (x == undefined || x == null); }

    if (uof(params.id)) { return; }
    if (uof(params.diag_title)) { params.diag_title = '' };
    if (uof(params.width)) { params.width = 600 };
    if (uof(params.close_btn_text)) { params.close_btn_text = 'Close' };

    var btns = {};
    btns[params.close_btn_text] = function() { $(this).dialog('close'); };

    $('#' + params.id).dialog({
        modal: true,
        buttons: btns,
        title: params.diag_title,
        closeOnEscape: true,
        width: params.width,
        minWidth: 400
    });
}

function post_dict_as_form(dict, post_url, method) {
    if (post_url == undefined) { post_url = ''; }
    if (method == undefined) { method = 'post'; }
    var form = $('<form />')
    form.attr('method', method);
    form.attr('action', post_url);

    var field = $('<input />');
    field.attr('type', 'hidden');

    for (var i in dict) {
        var f = field.clone();
        f.attr('name', i);
        f.attr('value', dict[i]);
        form.append(f);
    }
    $('body').append(form);
    form.submit();
    form.remove();
}

