﻿function Msg_Init(type, sText) {
    if (!sText)
        sText = "";
    if (typeof (sText) == 'string')
        sText = sText.replace('\n', '<br/>').replace('\r', '<br/>');
    var msgHTML = "";
    if (type == 'al') {
        msgHTML = "<table id='XMessage'  border='0' cellpadding='0' cellspacing='0' style='WIDTH: 300px; POSITION:absolute;DISPLAY:none;CURSOR:default;z-index:1000000;opacity:0.9;filter:alpha(opacity=90);'>";
        msgHTML += "<tr id='msg-header' style='CURSOR:move;HEIGHT: 29px;'>";
        msgHTML += "<td style='WIDTH:9px; BACKGROUND: url(" + imgResources['msg_tl'] + ") no-repeat center center;'></td>";
        msgHTML += "<td style='BACKGROUND:url(" + imgResources['msg_tb'] + ") repeat-x center center;'><span style='FONT-WEIGHT: bold; COLOR: #FFF; MARGIN: 0px 10px; LINE-HEIGHT: 29px;FONT-FAMILY: Arial,Tahoma; FONT-SIZE: 9pt'>" + msgTitle() + "</span></td>";
        msgHTML += "<td style='WIDTH:9px; BACKGROUND: url(" + imgResources['msg_tr'] + ") no-repeat center center;'></td></tr>";
        msgHTML += "<tr><td style='BACKGROUND:url(" + imgResources['msg_l'] + ") repeat-y center center;'></td><td style='BACKGROUND:#FFF;PADDING: 20px 10px; TEXT-ALIGN: center;'>";
        msgHTML += "<div style='COLOR:#000; FONT-WEIGHT: bold; FONT-FAMILY: Arial,Tahoma; FONT-SIZE: 9pt;WIDTH:100%'>";
        msgHTML += "<img src='" + imgResources['msg_exclamation1'] + "' align='left' hspace='10' />" + sText + "</div>";
        msgHTML += "<div style='CLEAR: both;'>" + msgCmd();
        msgHTML += "</div>";
        msgHTML += "</td><td style='BACKGROUND:url(" + imgResources['msg_r'] + ") repeat-y center center;'></td>";
        msgHTML += "</tr>";
        msgHTML += "<tr style='HEIGHT: 9px;'>";
        msgHTML += "<td style='WIDTH:9px; BACKGROUND: url(" + imgResources['msg_bl'] + ") no-repeat center center;'></td>";
        msgHTML += "<td style='BACKGROUND: url(" + imgResources['msg_bb'] + ") repeat-x center center;'></td>";
        msgHTML += "<td style='WIDTH:9px; BACKGROUND: url(" + imgResources['msg_br'] + ") no-repeat center center;'></td>";
        msgHTML += "</tr>";
        msgHTML += "</table>";
    }
    else {
        msgHTML = "<table id='XMessage'  border='0' cellpadding='0' cellspacing='0' style='WIDTH: 300px; POSITION:absolute;DISPLAY:none;CURSOR:default;z-index:1000000;opacity:0.9;filter:alpha(opacity=90);'>";
        msgHTML += "<tr id='msg-header' style='CURSOR:move;HEIGHT: 29px;'>";
        msgHTML += "<td style='WIDTH:9px; BACKGROUND: url(" + imgResources['msg_tl'] + ") no-repeat center center;'></td>";
        msgHTML += "<td style='BACKGROUND:url(" + imgResources['msg_tb'] + ") repeat-x center center;'><span style='FONT-WEIGHT: bold; COLOR: #FFF; MARGIN: 0px 10px; LINE-HEIGHT: 29px;FONT-FAMILY: Arial,Tahoma; FONT-SIZE: 9pt'>" + msgTitle() + "</span></td>";
        msgHTML += "<td style='WIDTH:9px; BACKGROUND: url(" + imgResources['msg_tr'] + ") no-repeat center center;'></td></tr>";
        msgHTML += "<tr><td style='BACKGROUND:url(" + imgResources['msg_l'] + ") repeat-y center center;'></td><td style='BACKGROUND:#FFF;PADDING: 20px 10px; TEXT-ALIGN: center;'>";
        msgHTML += "<div style='COLOR:#000; FONT-WEIGHT: bold; FONT-FAMILY: Arial,Tahoma; FONT-SIZE: 9pt;WIDTH:100%'>";
        msgHTML += "<img src='" + imgResources['msg_exclamation1'] + "' align='left' hspace='10' />" + sText + "</div>";
        msgHTML += "<div style='CLEAR: both;'>" + msgCmd(2);
        msgHTML += "</div>";
        msgHTML += "</td><td style='BACKGROUND:url(" + imgResources['msg_r'] + ") repeat-y center center;'></td>";
        msgHTML += "</tr>";
        msgHTML += "<tr style='HEIGHT: 9px;'>";
        msgHTML += "<td style='WIDTH:9px; BACKGROUND: url(" + imgResources['msg_bl'] + ") no-repeat center center;'></td>";
        msgHTML += "<td style='BACKGROUND: url(" + imgResources['msg_bb'] + ") repeat-x center center;'></td>";
        msgHTML += "<td style='WIDTH:9px; BACKGROUND: url(" + imgResources['msg_br'] + ") no-repeat center center;'></td>";
        msgHTML += "</tr>";
        msgHTML += "</table>";
    }
    if (msgHTML != "") {
        if (!Xrow.getObj('msgBg', window))
            $(top.document.body).append('<div id="msgBg" style="background:#000;TOP:0px;LEFT:0px;position:absolute; opacity:0.3;filter:alpha(opacity=30);z-index:100000;"></div>');
        var bH = $(top).height();
        if (bH < $(top.document).height())
            bH = $(top.document).height();
        top.$('#msgBg').css('width', $(top).width()).css('height', bH);

        $(top.document).bind("contextmenu", function(e) {
            return false;
        });
        $(document).unbind('mousedown');
        if (!Xrow.getObj('XMessage', window)) {
            try {
                $(top.document.body).append(msgHTML);
            }
            catch (e) { }
        }
        
        
        var iTop = ($(top).height()) / 2 - top.$('#XMessage').height() + $(top).scrollTop();
        var iLeft = ($(top.document.body).width() - top.$('#XMessage').width()) / 2;
        top.$('#XMessage').css('top', iTop).css('left', iLeft);
        if (jQuery.browser.msie) {
            $(top).scroll(function(e) {
                top.$('#XMessage').css('top', ($(top).height() - top.$('#XMessage').height()) / 2 + Xrow.windowTop()).css('left', iLeft);
            });
        } else {
            $(top.document).scroll(function(e) {
                top.$('#XMessage').css('top', ($(top).height() - top.$('#XMessage').height()) / 2 + Xrow.windowTop()).css('left', iLeft);
            });
        }
    }
}
function msgTitle() {
    switch (xLg) {
        case "en":
            return "Message";
        case "ja":
            return "メッセージ";
        case "ch":
            return "訊息";
        default:
            return "Thông báo";

    }
}
function msgCmd(i) {
    if (i == 2) {
        switch (xLg) {
            case "en":
                return "<input id='msgXOK' type='button' value='Yes' style='FONT-SIZE:8pt;WIDTH:80px;BACKGROUND:url(" + imgResources['msg_ok'] + ") no-repeat 2px center;PADDING-LEFT:20px'/> <input id='msgXNo' type='button' value='No' style='FONT-SIZE:8pt;WIDTH:80px;BACKGROUND:url(" + imgResources['msg_cancel'] + ") no-repeat 2px center;PADDING-LEFT:20px'/>";
            case "ja":
                return "<input id='msgXOK' type='button' value='はい' style='FONT-SIZE:8pt;WIDTH:80px;BACKGROUND:url(" + imgResources['msg_ok'] + ") no-repeat 2px center;PADDING-LEFT:20px'/> <input id='msgXNo' type='button' value='いいえ' style='FONT-SIZE:8pt;WIDTH:80px;BACKGROUND:url(" + imgResources['msg_cancel'] + ") no-repeat 2px center;PADDING-LEFT:20px'/>";
            case "ch":
                return "<input id='msgXOK' type='button' value='是的' style='FONT-SIZE:8pt;WIDTH:80px;BACKGROUND:url(" + imgResources['msg_ok'] + ") no-repeat 2px center;PADDING-LEFT:20px'/> <input id='msgXNo' type='button' value='否' style='FONT-SIZE:8pt;WIDTH:80px;BACKGROUND:url(" + imgResources['msg_cancel'] + ") no-repeat 2px center;PADDING-LEFT:20px'/>";
            default:
                return "<input id='msgXOK' type='button' value='Chấp nhận' style='FONT-SIZE:8pt;WIDTH:80px;BACKGROUND:url(" + imgResources['msg_ok'] + ") no-repeat 2px center;PADDING-LEFT:20px'/> <input id='msgXNo' type='button' value='Bỏ qua' style='FONT-SIZE:8pt;WIDTH:80px;BACKGROUND:url(" + imgResources['msg_cancel'] + ") no-repeat 2px center;PADDING-LEFT:20px'/>";

        }
    }
    else {
        switch (xLg) {
            case "en":
                return "<input id='msgXOK' type='button' value='Yes' style='FONT-SIZE:8pt;WIDTH:80px;BACKGROUND:url(" + imgResources['msg_ok'] + ") no-repeat 2px center;PADDING-LEFT:20px'/>";
            case "ja":
                return "<input id='msgXOK' type='button' value='はい' style='FONT-SIZE:8pt;WIDTH:80px;BACKGROUND:url(" + imgResources['msg_ok'] + ") no-repeat 2px center;PADDING-LEFT:20px'/>";
            case "ch":
                return "<input id='msgXOK' type='button' value='是的' style='FONT-SIZE:8pt;WIDTH:80px;BACKGROUND:url(" + imgResources['msg_ok'] + ") no-repeat 2px center;PADDING-LEFT:20px'/>";
            default:
                return "<input id='msgXOK' type='button' value='Chấp nhận' style='FONT-SIZE:8pt;WIDTH:80px;BACKGROUND:url(" + imgResources['msg_ok'] + ") no-repeat 2px center;PADDING-LEFT:20px'/>";

        }
    }
}
//if($.data($("#" + oTarget.id).get(0), "events").click!=null||$("#" + oTarget.id).attr("onclick")!=null){$("#" + oTarget.id).unbind("click",confirm);$("#" + oTarget.id).click();} else
function confirm(sText, oFn) {
    if ($('#' + oTarget.id).attr('disabled') == 'disabled')
        return false;
    Msg_Init('cf', sText);
    top.$('#XMessage').draggable({ handle: '#msg-header', containment: 'parent' });
    top.$('#XMessage').fadeIn(200);
    try {
        top.$('#XMessage').find('#msgXOK').click(function() { $(document).mousedown(function(e) { getTarget(e); }); top.$('#XMessage').fadeOut(200); top.$('#msgBg').remove(); if (oFn) { eval(oFn); return true; } setTimeout('top.$("#XMessage").remove(); if(typeof (oTarget.href) != "undefined") { eval(oTarget.href); } else { __doPostBack(oTarget.name, ""); }', 300); });
        top.$('#XMessage').find('#msgXNo').click(function() { $(document).mousedown(function(e) { getTarget(e); }); top.$('#XMessage').fadeOut(200); top.$('#msgBg').remove(); setTimeout('top.$("#XMessage").remove();', 300); });
    } catch (e) { }
    return false;
}
function alert(sText) {
    if (oTarget && $('#' + oTarget.id).attr('disabled') == 'disabled')
        return false;
    Msg_Init('al', sText);
    top.$('#XMessage').draggable({ handle: '#msg-header' });
    top.$('#XMessage').fadeIn(200);
    try {
        top.$('#XMessage').find('#msgXOK').click(function() { top.$('#XMessage').fadeOut(200); top.$('#msgBg').remove(); setTimeout('top.$("#XMessage").remove();', 300); });
    } catch (e) {
    }
    return false;
}
