﻿//---------------------------------------blockUI part end-----------------------------------
//change blockUI default settings
//change blockUI border
$.blockUI.defaults.css.border = '5px solid #ccc';
$.blockUI.defaults.css.cursor = 'default';
$.blockUI.defaults.css.top = '40%';
$.blockUI.defaults.css.left = '40%';
$.blockUI.defaults.overlayCSS.cursor = 'default';

//change fadeOut effact speed
$.blockUI.defaults.fadeOut = 100;
$.blockUI.defaults.fadeIn = 100;

//----------==================================华丽的分割线================================---
//blockUI extend function
//以下三个方法在页面调用时，给点按钮或者文字添加onlick事件调用
//Confirm Delete or any other events
//1，该方法弹出带有确认与取消两个按钮的层，点击确认触发clickEvent()方法
$.confirm = function(settings) {
	var htmlDom = $("<div id=\"displayPanle\" style=\"height:170px\" ></div>");
//    htmlDom.css({ "text-align": "center", "vertical-align": "middle", "line-height": "70px" });
    htmlDom.append("<table cellpadding=\"0\" cellspacing=\"20px\" bgcolor=\"#f6f6f6\" class=\"solidtable\" width=\"100%\" height=\"170px\"><tr style=\height:80px\><td width=\"80px\" align=\"center\" valign=\"top\"><img src=\""+settings.image+"\" width=\"50px\" height=\"50px\"/></td><td width=\"100%\" class=\"bigtextfont\"><table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr height=\"35px\"><td colspan=\"3\" width=\"100%\" style=\"text-align:left;padding-left:20px;word-wrap:break-word\" ><strong>"+ settings.msg + "</strong></td></tr></table></td></tr><tr><td  nowrap=\"nowrap\" colspan=\"2\" align=\"center\"><input type=\"button\" id=\"confirmButton\"  value=\"确认\" class=\"inputbtnmain\" style=\"width:80px;height:25px;\"/><input type=\"button\" id=\"cancelButton\"  value=\"取消\" class=\"inputbtnmain\" style=\"width:80px;height:25px;\" onclick=\"javascript:closeBlockUINoFresh();\"/></td></tr></table>");
    htmlDom.find('#confirmButton').click(settings.clickEvent);
    $.blockUI({
         message: htmlDom,
         css: { width: "400px", height: "170px", "background-color": "#fff", "z-index": settings.baseZ }
    });
    pressEscOut();
}

//弹出提示框
$.prompt = function(settings) {
    var htmlDom = $("<div id=\"displayPanle\" style=\"height:100%\"></div>");
    //htmlDom.css({ "text-align": "center", "vertical-align": "middle", "line-height": "70px" });
    htmlDom.append("<table cellpadding=\"0\" cellspacing=\"20px\" bgcolor=\"#f6f6f6\" class=\"solidtable\" width=\"350px\" height=\"140px\"><tr><td width=\"80px\" align=\"center\" valign=\"top\"><img src=\""+settings.image+"\" width=\"50px\" height=\"50px\"/></td><td width=\"320px\" class=\"bigtextfont\"><table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr height=\"35px\"><td colspan=\"3\" width=\"80%\" style=\"text-align:left;padding-left:20px;word-wrap:break-word\" ><strong>"+ settings.msg + "</strong></td></tr></table></td></tr><tr><td  nowrap=\"nowrap\" colspan=\"2\" align=\"center\"><input type=\"button\" id=\"Confirm\"  value=\"确认\" class=\"inputbtnmain\" style=\"width:80px;height:25px;\" onclick=\"javascript:closeBlockUINoFresh();\"/></td></tr></table>");
    $.blockUI({
        message: htmlDom,
        css: { width: "350px", height: "140px", "background-color": "#fff", "z-index": settings.baseZ }
    });
    pressEscOut();
}

//弹出提示框  可进行处理
$.promptfunction = function(settings) {
	var htmlDom = $("<div id=\"displayPanle\" style=\"height:100%\"></div>");
	//htmlDom.css({ "text-align": "center", "vertical-align": "middle", "line-height": "70px" });
	htmlDom.append("<table cellpadding=\"0\" cellspacing=\"20px\" bgcolor=\"#f6f6f6\" class=\"solidtable\" width=\"350px\" height=\"100%\"><tr><td width=\"80px\" align=\"center\" valign=\"top\"><img src=\""+settings.image+"\" width=\"50px\" height=\"50px\"/></td><td width=\"320px\" class=\"bigtextfont\"><table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr height=\"35px\"><td colspan=\"3\" width=\"80%\" style=\"text-align:left;padding-left:20px;word-wrap:break-word\" ><strong>"+ settings.msg + "</strong></td></tr></table></td></tr><tr><td  nowrap=\"nowrap\" colspan=\"2\" align=\"center\"><input type=\"button\" id=\"Confirm\"  value=\"确认\" class=\"inputbtnmain\" style=\"width:80px;height:25px;\"/></td></tr></table>");
	htmlDom.find('#Confirm').click(settings.clickEvent);
	$.blockUI({
		message: htmlDom,
		css: { width: "350px", height: "140px", "background-color": "#fff", "z-index": settings.baseZ }
	});
	pressEscOut();
}

//该方法弹出添加或者修改的层，调用时需要传一个DOM以及层的标题。方法分别是formTitle(),appendTable()，且该方法有确认与取消两个按钮，确认按钮事件需要在页面js中重写方法是clickEvent()
$.msgBox = function(settings) {
    var tempScreen = (document.body.clientWidth - settings.width.replace("px", "")) / 2;
    var htmlDom = $("<div id=\"displayPanle\" style=\"display:none;border:1px solid #005eac\"></div>");
    var msg = $("<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" class=\"innderTable\" style=\"vertical-align:top;width:100%\"><tr><td width=\"80%\" style=\"text-align:left;font-family:宋体;font-size:14px;padding-left:15px;padding-top:10px;padding-bottom:10px;background-color:#3777bc;vertical-align:middle;color:#fff;font-weight:bold\">" + settings.title + "</td><td id=\"ConfirmTd\" style=\"text-align:right;padding-right:5px;padding-top:10px;padding-bottom:10px;background-color:#3777bc;vertical-align:middle;cursor:pointer;color:#fff;font-weight:bold\" onclick=\"javascript:closeBlockUINoFresh();\">关闭</td></tr><tr><td colspan=\"2\" style=\"text-align:center;width:100%\">" + settings.dom + "</td></tr><tr><td colspan=\"2\" style=\"text-align:right;padding-right:10px;padding-bottom:10px;\"><input type=\"button\" class=\"standard-button\" id=\"confirmButton\" value=\"确认\"/>&nbsp;&nbsp;<input type=\"button\" id=\"close\"class=\"standard-button\" value=\"取消\" onclick=\"javascript:closeBlockUINoFresh();\"/></td></tr></table>");
    htmlDom.append(msg);
    msg.parent().find('#confirmButton').click(settings.clickEvent);
    $.blockUI({
        message: htmlDom,
        css: { width: settings.width, "background-color": "#fff", "z-index": settings.baseZ, left: tempScreen }
    });
    pressEscOut();
}

//关闭blcokUI，该方法为默认方法，不需要变动。
function closeBlockUI() {
    $.unblockUI();
    location.reload();
    return false;
}

//关闭blockUI但不刷新页面
function closeBlockUINoFresh() {
    $.unblockUI();
}

function pressEscOut() {
    $("*").keypress(function(event) {
        var jianzhi = event.keyCode;
        var input_keydown = $(this);
        switch (jianzhi) {
            case 27:
                closeBlockUINoFresh();
                break;
        }
    });
}
