﻿/*
@   蒋峰 2009-08-04 新增
@   此脚本用来对页面的弹出框进行自定义
@   用法：
此扩展最终针对Jquery的扩展，主要包含方法：

属性名                      属性参数                        描述
MaskLayerShow                  无                           显示蒙版
MaskLayerHide                  无                           隐藏蒙板
MessageBox                  text,caption,buttons,icon       弹出框{四个重载方法，参数依次展开}
MessageButtonOk_Click       p_fn,p_url,p_isServerClick      点击弹出框OK按钮时的方法设定
MessageButtonYes_Click      p_isServerClick                 点击弹出框Yes按钮时的方法设定
MessageButtonNo_Click       p_isServerClick                 点击弹出框No按钮时的方法设定
MessageButtonCancel_Click   p_isServerClick                 点击弹出框Cancel按钮时的方法设定
------------------------------------------------------------------------------------------------------------
@   此脚本是在Jquery的基础上扩展而成，因此在引用此脚本之前要引用Jquery的JS文件。
@   此脚本配合后台程序可同时使用，需要注意在页面中引用BasePageX基类









*/
//$.include(['http://image.esunny.com/script/jquery.divbox.js','/css/pop_win.css']);
//function includeFile(curfileName, file) {
//    var files = typeof file == "string" ? [file] : file;
//    var A, T, R, I, J;
//    for (var i = 0; i < files.length; i++) {
//        var name = files[i].replace(/^\s|\s$/g, "");
//        var att = name.split('.');
//        var ext = att[att.length - 1].toLowerCase();
//        var isCSS = ext == "css";
//        var tag = isCSS ? "link" : "script";
//        J = "script"; //curfileName.substring(curfileName.lastIndexOf('.') + 1);
//        R = $(J);
//        I = '';
//        for (var B = 0; B < R.length; B++) {
//            T = R.eq(B).attr('src');
//            I = T.substring(0, T.toLowerCase().indexOf(curfileName.toLowerCase()));
//            A = I.lastIndexOf("/")
//            if (A > 0) I = T.substring(0, A + 1);
//            if (I) break;
//        }
//        var attr = isCSS ? " type='text/css' rel='stylesheet' " : " language='javascript' type='text/javascript' ";
//        var link = (isCSS ? "href" : "src") + "='" + I + name + "'";
//        if ($(tag + "[" + link + "]").length == 0) document.write("<" + tag + attr + link + "></" + tag + ">");
//    }
//}
$.include('MessageBoxShow.js', ['css/extend.messagebox.css']);

//控件唯一ID
var _MessageBoxTableName = "MessageBoxPanel";
var _MessageContentName = "MessageContent";
var _MessageIconPanelName = "MessageIconPanel";
var _MessageTextPanelName = "MessageTextPanel";
var _MessageTextLabelName = "MessageTextLabel";
var _MessageButtonPanelName = "MessageButtonPanel";
var _MessageCaptionPanelName = "MessageCaptionPanel";
var _MessageCaptionLabelName = "MessageCaptionLabel";
var _MaskLayerName = "MessageLayer";


//按钮预置唯一ID
var _MessageButton_OK_ID = "MessageButton_OK";
var _MessageButton_Yes_ID = "MessageButton_Yes";
var _MessageButton_Cancel_ID = "MessageButton_Cancel";
var _MessageButton_No_ID = "MessageButton_No";
var _MessageButton_Yes_Server_ID = "MessageButton_Yes_Server";
var _MessageButton_OK_Server_ID = "MessageButton_Ok_Server";
var _MessageButton_No_Server_ID = "MessageButton_No_Server";
var _MessageButton_Cancel_Server_ID = "MessageButton_Cancel_Server";
var _MessageButton_OK_CommandArgument_ID = "Hid_MessageButton_OK_Argument";
var _MessageButton_Yes_CommandArgument_ID = "Hid_MessageButton_Yes_Argument";
var _MessageButton_Cancel_CommandArgument_ID = "Hid_MessageButton_Cancel_Argument";
var _MessageButton_No_CommandArgument_ID = "Hid_MessageButton_No_Argument";


//按钮预置显示文本
var _MessageButton_OK = "确定";
var _MessageButton_Yes = "是";
var _MessageButton_Cancel = "取消";
var _MessageButton_No = "否";


//样式预定义
var messagebox = "messagebox";
var messagebox_caption = "MessageCaption";
var messagebox_corner_lefttop = "messagebox_corner_lefttop";
var messagebox_corner_righttop = "messagebox_corner_righttop";
var messagebox_corner_leftbottom = "messagebox_corner_leftbottom";
var messagebox_corner_rightbottom = "messagebox_corner_rightbottom";
var messagebox_top = "messagebox_top";
var messagebox_left = "messagebox_left";
var messagebox_right = "messagebox_right";
var messagebox_bottom = "messagebox_bottom";
var messageicon = "messageicon_";
var messagebox_content = "messagebox_content";
var message_content_text = "messagetextpanel";
var message_button = "message_button";
var message_button_ok = "messagebutton_ok";
var message_button_no = "messagebutton_no";
var message_button_yes = "messagebutton_yes";
var message_button_cancel = "messagebutton_cancel";
var _MaskClass = "shadowMask";

var MessageBoxButtons = {
    None: "None",
    OK: "OK",
    OKCancel: "OKCancel",
    AbortRetryIgnore: "AbortRetryIgnore",
    YesNoCancel: "YesNoCancel",
    YesNo: "YesNo",
    RetryCancel: "RetryCancel"
};
var MessageBoxIcon =
    {
        None: "None",
        Error: "Error",
        Hand: "Hand",
        Stop: "Stop",
        Question: "Question",
        Exclamation: "Exclamation",
        Warning: "Warning",
        Information: "Information",
        Asterisk: "Asterisk",
        Loading: "Loading"
    };

//刷新当前弹出框和蒙板的位置
function ReflashControl() {
    // debugger;
    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;
    var scrollTop = document.documentElement.scrollTop;
    $("#" + _MaskLayerName).css({ position: "absolute", left: 0, top: 0, width: $(document).width(), height: $(document).height(), "z-index": 1000 });
    $("#" + _MessageBoxTableName).css({ position: "absolute", left: (windowWidth - $("#" + _MessageBoxTableName).width()) / 2, top: (windowHeight - $("#" + _MessageBoxTableName).height()) / 2 + scrollTop, "z-index": 1001 });
}
//初始化页面时对蒙板进行初始化是否显示
function InitMaskLayer(p_flag) {
    $(document).ready(function() {
        if (p_flag && p_flag == true) {
            $("#" + _MaskLayerName).show();
        } else {
            $("#" + _MaskLayerName).hide();
        }
    })
}
//是否显示蒙板操作方法
function IsMaskLayerShow(p_flag) {
    if (!($("#" + _MaskLayerName) != null && $("#" + _MaskLayerName).length > 0)) {
        $(document.body).append("<div id='" + _MaskLayerName + "' class='" + _MaskClass + "'></div>");
    }
    ReflashControl();
    if (p_flag && p_flag == true) {
        $("#" + _MaskLayerName).show();
    } else {
        $("#" + _MaskLayerName).hide();
    }
}
//显示蒙板
function MaskLayerShow() {
    IsMaskLayerShow(true);
}

function MessageButton_OK_Server_Click(p_OKCommandArgument) {
    $("#" + _MessageButton_OK_CommandArgument_ID).val(p_OKCommandArgument);
    if (p_OKCommandArgument != '') {
        $("#" + _MessageButton_OK_Server_ID).click();
    }
}
function MessageButton_OK_Client_Click(p_fn, p_url, p_OKCommandArgument) {
    $("#" + _MessageButton_OK_ID).unbind("click").bind('click', function() {
        IsMaskLayerShow(false);
        $("#" + _MessageBoxTableName).hide();
        if (p_fn != null && typeof (p_fn) == 'function') {
            p_fn();
        }
        if (p_url != null && typeof (p_url) == 'string' && p_url != "") {
            window.location.href = p_url;
            return;
        }
        MessageButton_OK_Server_Click(p_OKCommandArgument);
    })
}
function MessageButton_OK_Click(p_fn, p_url, p_OKCommandArgument) {
    $(document).ready(function() {
        MessageButton_OK_Client_Click(p_fn, p_url, p_OKCommandArgument);
    })
}
function MessageButton_Yes_Server_Click(p_YesCommandArgument) {
    $("#" + _MessageButton_Yes_CommandArgument_ID).val(p_YesCommandArgument);
    if (p_YesCommandArgument != '') {
        $("#" + _MessageButton_Yes_Server_ID).click();
    }
}
function MessageButton_Yes_Client_Click(p_fn, p_YesCommandArgument) {
    $("#" + _MessageButton_Yes_ID).unbind("click").bind('click', function() {
        IsMaskLayerShow(false);
        $("#" + _MessageBoxTableName).hide();
        if (p_fn != null && typeof (p_fn) == 'function') {
            p_fn();
        }
        MessageButton_Yes_Server_Click(p_YesCommandArgument);
    })
}
function MessageButton_Yes_Click(p_fn, p_YesCommandArgument) {
    $(document).ready(function() {
        MessageButton_Yes_Client_Click(p_fn, p_YesCommandArgument);
    })
}
function MessageButton_No_Server_Click(p_NoCommandArgument) {
    $("#" + _MessageButton_No_CommandArgument_ID).val(p_NoCommandArgument);
    if (p_NoCommandArgument != '') {
        $("#" + _MessageButton_No_Server_ID).click();
    }
}
function MessageButton_No_Client_Click(p_fn, p_NoCommandArgument) {
    $("#" + _MessageButton_No_ID).unbind("click").bind('click', function() {
        IsMaskLayerShow(false);
        $("#" + _MessageBoxTableName).hide();
        if (p_fn != null && typeof (p_fn) == 'function') {
            p_fn();
        }
        MessageButton_No_Server_Click(p_NoCommandArgument);
    })
}
function MessageButton_No_Click(p_fn, p_OpenServerClick) {
    $(document).ready(function() {
        MessageButton_No_Client_Click(p_fn, p_OpenServerClick);
    })
}

function MessageButton_Cancel_Server_Click(p_CancelCommandArgument) {
    $("#" + _MessageButton_Cancel_CommandArgument_ID).val(p_CancelCommandArgument);
    if (p_CancelCommandArgument != '') {
        $("#" + _MessageButton_Cancel_Server_ID).click();
    }
}
function MessageButton_Cancel_Client_Click(p_fn, p_CancelCommandArgument) {
    $("#" + _MessageButton_Cancel_ID).bind('click', function() {
        IsMaskLayerShow(false);
        $("#" + _MessageBoxTableName).hide();
        if (p_fn != null && typeof (p_fn) == 'function') {
            p_fn();
        }
        MessageButton_Cancel_Server_Click(p_CancelCommandArgument);
    })
}
function MessageButton_Cancel_Click(p_fn, p_OpenServerClick) {
    $(document).ready(function() {
        MessageButton_Cancel_Client_Click(p_fn, p_OpenServerClick);
    })

}

function MessageBoxShow4(text, caption, buttons, icon) {
    //先将页面上的原来弹出框清除
    $("#" + _MessageBoxTableName).remove();
    var httable = "";
    //Table样式
    httable += "<table ID='" + _MessageBoxTableName + "' border='0' cellpadding='0' cellspacing='0' class='" + messagebox + "' style='position:absolute; z-index:1001; display:block;'>";
    //第一行
    httable += "<tr><td class='" + messagebox_corner_lefttop + "'></td><td class='" + messagebox_top + "'></td><td class='" + messagebox_corner_righttop + "'></td></tr>";
    //第二行
    httable += "<tr><td class='" + messagebox_left + "'></td>";
    httable += "<td id='" + _MessageContentName + "' class='" + messagebox_content + "'>";
    //标题
    httable += "<div id='" + _MessageCaptionPanelName + "' class='" + messagebox_caption + "'><span id='" + _MessageCaptionLabelName + "'>" + caption + "</span></div>";
    //图标
    httable += "<div id='" + _MessageIconPanelName + "' class='" + messageicon + icon + "'></div>";
    //消息
    httable += "<div id='" + _MessageTextPanelName + "' class='" + message_content_text + "'><span id='" + _MessageTextLabelName + "'>" + text + "</span></div>";
    //按钮
    httable += "<div style='clear:both;'></div>";
    httable += "<div id='" + _MessageButtonPanelName + "' class='" + message_button + "'>";
    switch (buttons) {
        case "None":
            httable += "&nbsp;";
            break;
        case "OK":
            httable += "<input type='button' id='" + _MessageButton_OK_ID + "' value='" + _MessageButton_OK + "' class='" + message_button_ok + "' />";
            break;
        case "OKCancel":
            httable += "<input type='button' id='" + _MessageButton_OK_ID + "' value='" + _MessageButton_OK + "' class='" + message_button_ok + "' />";
            httable += "<input type='button' id='" + _MessageButton_Cancel_ID + "' value='" + _MessageButton_Cancel + "' class='" + message_button_cancel + "' />";

            break;
        case "YesNo":
            httable += "<input type='button' id='" + _MessageButton_Yes_ID + "' value='" + _MessageButton_Yes + "' class='" + message_button_yes + "' />";
            httable += "<input type='button' id='" + _MessageButton_No_ID + "' value='" + _MessageButton_No + "' class='" + message_button_no + "' />";

            break;
        case "YesNoCancel":
            httable += "<input type='button' id='" + _MessageButton_Yes_ID + "' value='" + _MessageButton_Yes + "' class='" + message_button_yes + "' />";
            httable += "<input type='button' id='" + _MessageButton_No_ID + "' value='" + _MessageButton_No + "' class='" + message_button_no + "' />";
            httable += "<input type='button' id='" + _MessageButton_Cancel_ID + "' value='" + _MessageButton_Cancel + "' class='" + message_button_cancel + "' />";
            break;
        default:
            httable += "<input type='button' id='" + _MessageButton_OK_ID + "' value='" + _MessageButton_OK + "' class='" + message_button_ok + "' />";
            break;
    }
    httable += "</div>";
    httable += "</td>";
    httable += "<td class='" + messagebox_right + "'></td>";
    httable += "</tr>";
    //第三行
    httable += "<tr><td class='" + messagebox_corner_leftbottom + "'></td><td class='" + messagebox_bottom + "'></td><td class='" + messagebox_corner_rightbottom + "'></td></tr>";
    httable += "</table>";
    $(document.body).append(httable);
    MessageButton_OK_Client_Click(null, "", "");
    MessageButton_Yes_Client_Click("");
    MessageButton_Cancel_Client_Click(null, '');
    MessageButton_No_Client_Click(null, '');
    //位置刷新
    ReflashControl();
}






























































































































































































































function MessageBoxShow3(text, caption, buttons) {
    MessageBoxShow4(text, caption, buttons, MessageBoxIcon.Information);
}
function MessageBoxShow2(text, caption) {
    MessageBoxShow3(text, caption, MessageBoxButtons.OK);
}
function MessageBoxShow1(text) {

    MessageBoxShow2(text, "提示信息");
}
function MessageBoxShow0() {
    MessageBoxShow1("&nbsp;");
}
$(document).ready(function() {
    ReflashControl();
    $(window).resize(function() {
        ReflashControl();
    })
})

$.extend({
    MaskLayerShow: function() {
        MaskLayerShow();
    },
    MaskLayerHide: function() {
        IsMaskLayerShow(false);
    },
    MessageBox: function() {
        switch (arguments.length) {
            case 0:
                //默认弹出框
                MessageBoxShow0();
                break;
            case 1:
                //一个参数：【Text】
                MessageBoxShow1(arguments[0]);
                break;
            case 2:
                //两个参数：【Text】【Caption】
                MessageBoxShow2(arguments[0], arguments[1]);
                break;
            case 3:
                //三个参数：【Text】【Caption】【Butttons】
                MessageBoxShow3(arguments[0], arguments[1], arguments[2]);
                break;
            case 4:
                //④个参数：【Text】【Caption】【Butttons】【Icons】
                MessageBoxShow4(arguments[0], arguments[1], arguments[2], arguments[3]);
                break;













































        }
    },
    MessageBoxHide: function() {
        $("#" + _MessageBoxTableName).hide();
    },
    //点击确定按钮时触发事件：所能够执行的JS操作，所要跳转的页面，是否触发服务器端按钮事件
    MessageButtonOk_Click: function(p_fn, p_url, p_OkCommandArgument) {
        MessageButton_OK_Click(p_fn, p_url, p_OkCommandArgument);
    },
    MessageButtonOk_Client_Click: function(p_fn, p_url, p_OkCommandArgument) {
        MessageButton_OK_Client_Click(p_fn, p_url, p_OkCommandArgument);
    },
    //点击是按钮时触发事件：是否触发服务器端按钮事件
    MessageButtonYes_Click: function(p_fn, p_YesCommandArgument) {
        MessageButton_Yes_Click(p_fn, p_YesCommandArgument);
    },
    MessageButtonYes_Client_Click: function(p_fn, p_YesCommandArgument) {
        MessageButton_Yes_Client_Click(p_fn, p_YesCommandArgument);
    },
    //点击否按钮时触发客户端事件：是否触发服务器端按钮事件
    MessageButtonNo_Click: function(p_fn, p_OpenServerClick) {
        MessageButton_No_Click(p_fn, p_OpenServerClick);
    },
    MessageButtonNo_Client_Click: function(p_fn, p_NoCommandArgument) {
        MessageButton_No_Client_Click(p_fn, p_NoCommandArgument);
    },
    //点击取消按钮时触发客户端事件
    MessageButtonCancel_Click: function(p_fn, p_CancelCommandArgument) {
        MessageButton_Cancel_Click(p_fn, p_CancelCommandArgument);
    },
    //点击取消按钮时触发的客户端事件
    MessageButtonCancel_Client_Click: function(p_fn, p_CancelCommandArgument) {
        MessageButton_Cancel_Client_Click(p_fn, p_CancelCommandArgument);
    },
    //点击确定按钮时触发的服务器事件
    MessageButtonOk_Server_Click: function(p_OKCommandArgument) {
        MessageButton_OK_Server_Click(p_OKCommandArgument);
    },
    //点击是按钮时触发的服务器事件
    MessageButtonYes_Server_Click: function(p_YesCommandArgument) {
        MessageButton_Yes_Server_Click(p_YesCommandArgument);
    },
    //点击否按钮是出发的服务器事件
    MessageButtonNo_Server_Click: function(p_NoCommandArgument) {
        MessageButton_No_Server_Click(p_NoCommandArgument);
    },
    //点击取消按钮时触发的服务器事件
    MessageButtonCancel_Server_Click: function(p_CancelCommandArgument) {
        MessageButton_Cancel_Server_Click(p_CancelCommandArgument);
    }
})


