﻿//$(function() {
    //$("body").ajaxStart(function() {
 //       $.UI.Progress.Create();
 //   }).ajaxStop(function() {
 //       $.UI.Progress.Close();
  //  }).ajaxError(function(event, request, settings) {
  //      alert("url:" + settings.url + "并且data:" + settings.data + "访问出错，请检查！");
  //  });
//});

// 提示对话框。
// message：消息内容
// callback：单击确定后的回调方法
//function alert(message, callback) {
//    $("<div title='提示'></div>")
//    .html(message)
//    .prepend("<span class='ui-icon ui-icon-info' style='float: left; margin-right: .3em;'></span>")
//    .dialog({
//        modal: true,
//        resizable: false,
//        overlay: {
//            opacity: 0.5,
//            background: "black"
//        },
//        buttons: {
//            "确定": function() { if (jQuery.isFunction(callback)) callback(); $(this).dialog("close"); }
//        }
//    });
//}
// 询问对话框
// message：询问内容
// callback：单击确定的回调方法
function confirm(message, callback) {
    $("<div title='询问'></div>")
    .html(message)
    .prepend("<span class='ui-icon ui-icon-help' style='float: left; margin-right: .3em;'></span>")
    .dialog({
        modal: true,
        resizable: false,
        overlay: {
            opacity: 0.5,
            background: "black"
        },
        buttons: {
            "确定": function() { callback(); $(this).dialog("close"); },
            "取消": function() { $(this).dialog("close"); }
        }
    });
}
// 显示消息对话框
function messageDialog(dialog) {
    dialog.dialog({
        modal: true,
        resizable: false,
        overlay: {
            opacity: 0.5,
            background: "black"
        },
        buttons: {
            "确定": function() { $(this).dialog("close"); }
        }
    });
}
// 选中/取消复选框
function CheckAll(ele,cls) {
    if(cls==undefined)
        $(':check').attr("checked", $(ele).attr("checked"));
    else
        $(cls + ':check').attr("checked", $(ele).attr("checked"));
}
// 获取表格里选中复选框中行的标识
function getRowIDs(cls) {
    if (cls == undefined)
        cls = ".Check";
    var ids = '';
    $(cls + ":checked").each(
        function(i, row) {
            if (ids.length > 0)
                ids += ",";
            ids += $(row).parents("tr").attr("rowid");
        }
    );
    return ids;
}
// 通过名称获取URL参数的值
function getQueryString(name) {
    var url = window.location.href;
    var reg = new RegExp("(^|&|\\?)"+ name +"=([^&]*)(&|$)"), r;
    if (r = url.match(reg)) return unescape(r[2]); 
        return null;
}

//============Overlay与Progress===============
// 命名空间设置.设置了$.UI.Overlay与$.UI.Progress的命名空间
$.UI = {
    Overlay: {},
    Progress: {}
}
// 扩展了进度条插件，用于显示进度条
$.extend($.UI.Progress, {
    instances: [],
    Create: function() {
        $.UI.Overlay.Create();
        if (this.instances.length == 0) {
            var instance = $("<div/>").addClass("ui-progressbar").appendTo(document.body);
            this.instances.push(instance);
        }
    },
    Close: function() {
        $.UI.Overlay.Close();
        if (this.instances.length > 0) {
            this.instances.pop().remove();
        }
    }
});
// 扩展了遮避插件。它将随着屏幕的大小而改变。
$.extend($.UI.Overlay, {
    OverlayPanel: {}, // 遮避层元素对象
    Width: function() { // 获取工作区的宽度
        return $(window).width();
    },
    Height: function() { // 获取工作区的高度
        return $(window).height();
    },
    Create: function() { // 创建遮避层
        this.OverlayPanel = $('<div/>').appendTo(document.body)
		    .addClass('ui-widget-overlay').css({
		        borderWidth: 0, margin: 0, padding: 0,
		        position: 'absolute', top: 0, left: 0,
		        width: this.Width(),
		        height: this.Height()
		    });
        $(window).bind('resize', this.Resize);
        return this.OverlayPanel;
    },
    Close: function() { // 关闭遮避层
        $(window).unbind('resize', this.Resize);
        this.OverlayPanel.remove();
    },
    Resize: function() { // 重设遮避层大小
        $.UI.Overlay.OverlayPanel.css({
            width: 0,
            height: 0
        }).css({
            width: $.UI.Overlay.Width(),
            height: $.UI.Overlay.Height()
        });
    }
});

