function set_dialog(type, str, time, action)
{
    // 預設值
    var overlay_opacity = 0;
    if (!action) action = '';

    // 判斷類型
    if (type == 'confirm')
    {
        var _modal = $jQuery('#confirm_modal'),
            _hit   = $jQuery('#confirm_txt'),
            _btn   = $jQuery('#confirm_yes');
        var overlay_opacity = .75;
        _btn.attr('btn_act', action);
    }
    else if (type == 'alert')
    {
        var _modal = $jQuery('#alert_modal'),
            _hit   = $jQuery('#alert_txt'),
            _btn   = $jQuery('#alert_close');
        _btn.attr('btn_act', action);
    }
    else if (type == 'process')
    {
        var _modal = $jQuery('#process_modal'),
            _hit   = $jQuery('#process_txt');
    }

    // 提示文字訊息
    _hit.html(str);

    // 執行 dialog
    $jQuery.blockUI({
        message: _modal,
        fadeIn: 0,
        fadeOut: 350,
        timeout: time,
        showOverlay: true,
        centerY: true,
        overlayCSS: {
            backgroundColor: '#000',
            opacity: overlay_opacity,
            cursor: 'default'
        },
        css: {
            width: '500px',
            border: 'none',
            padding: '5px',
            backgroundColor: '#222',
            '-webkit-border-radius': '15px',
            '-moz-border-radius': '15px',
            opacity: .95,
            cursor: 'default'
        }
    });
}

$jQuery(function() {
    // 確認按鈕
    $jQuery('#confirm_yes').click(function() {
        set_dialog('process', '程式執行中，請稍候...', 32000);
        _action = $jQuery(this).attr('btn_act');
        eval($jQuery(_action).html());
    });

    // 取消按鈕
    $jQuery('#confirm_no').click(function() {
        $jQuery.unblockUI();
    });

    // 關閉按鈕
    $jQuery('#alert_close').click(function() {
        $jQuery.unblockUI();
        _action = $jQuery(this).attr('btn_act');
        if (_action) eval($jQuery(_action).html());
    });

    // 切換按鈕樣式
    $jQuery('.ezpos').hover(
    function() {
        // 變換樣式
        $jQuery(this).css('background-position', '0px -23px');
    },
    function() {
        // 變換樣式
        $jQuery(this).css('background-position', '0px 0px');
    });
});

// 執行區塊
document.write('<div id="process_modal" style="display:none;">');
document.write('<table border="0" cellspacing="8" cellpadding="0" align="center"><tr>');
document.write('<td align="right" valign="middle"><img src="images/loading.gif" width="18" height="18" /></td>');
document.write('<td id="process_txt" valign="middle" style="font-size:13px; color:#ccc;"></td>');
document.write('</tr></table></div>');

// 確認區塊
document.write('<div id="confirm_modal" style="display:none;">');
document.write('<table border="0" cellspacing="10" cellpadding="0" align="center"><tr>');
document.write('<td id="confirm_txt" valign="middle" style="font-size:13px; color:#ccc;"></td>');
document.write('</tr><tr>');
document.write('<td valign="middel"><input type="button" id="confirm_yes" class="icon_comm icon_submit ezpos" />&nbsp;&nbsp;');
document.write('<input type="button" id="confirm_no" class="icon_comm icon_reset ezpos" /></td>');
document.write('</tr></table></div>');

// 提示區塊
document.write('<div id="alert_modal" style="display:none;">');
document.write('<table border="0" cellspacing="10" cellpadding="0" align="center"><tr>');
document.write('<td id="alert_txt" align="left" style="font-size:13px; color:#ccc;"></td>');
document.write('</tr><tr>');
document.write('<td><input type="button" id="alert_close" class="icon_comm icon_close ezpos" /></td>');
document.write('</tr></table></div>');
