function set_dialog(type, str, time, action)
{
    // 預設值
    var time   = time   || 0,
        action = action || '',
        overlay_opacity = .75;

    // 判斷類型
    if (type == 'confirm')
    {
        var _modal = $jQuery('#confirm_modal'),
            _hit   = $jQuery('#confirm_txt');
        $jQuery('#confirm_yes').attr('btn_act', action);
    }
    else if (type == 'alert')
    {
        var _modal = $jQuery('#alert_modal'),
            _hit   = $jQuery('#alert_txt');
        $jQuery('#alert_close').attr('btn_act', action);
    }
    else if (type == 'process')
    {
        var _modal = $jQuery('#process_modal'),
            _hit   = $jQuery('#process_txt');
    }
    else
    {
        set_dialog('alert', '您指定錯誤類型：' +type);
        return true;
    }

    // 提示訊息
    _hit.html(str);

    // 執行 dialog
    if (type == 'process')
    {
        $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'
            }
        });
    }
    else
    {
        // 計算高度
        _top = Math.round(($jQuery(window).height() - _modal.height()) / 2) - 1;
        if (_top < 0) _top = 0;
     
        $jQuery.blockUI({
            message: _modal,
            fadeIn: 0,
            fadeOut: 350,
            timeout: time,
            showOverlay: true,
            centerY: true,
            overlayCSS: {
                backgroundColor: '#000',
                opacity: overlay_opacity,
                cursor: 'default'
            },
            css: {
                top: _top,
                width: '440px',
                border: '3px solid #525252',
                cursor: 'default'
            }
        });
     
        $jQuery('.dialog_title').css('opacity', .85);
    }
}

$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('.dialog_title > img').css('cursor', 'pointer').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/dialog_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('<div class="dialog_title"><div style="float:left;">系統確認視窗</div><img src="images/dialog_close.png" style="float:right;" /></div>');
document.write('<table border="0" cellspacing="10" cellpadding="0" align="center"><tr>');
document.write('<td id="confirm_txt" valign="middle" style="font-size:13px;"></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('<div class="dialog_title"><div style="float:left;">系統訊息視窗</div><img src="images/dialog_close.png" style="float:right;" /></div>');
document.write('<table border="0" cellspacing="10" cellpadding="0" align="center"><tr>');
document.write('<td id="alert_txt" align="left" style="font-size:13px;"></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>');
