$.fn.wait = function(time, type) {
    time = time || 1000;
    type = type || "fx";
    return this.queue(type, function() {
        var self = this;
        setTimeout(function() {
            $(self).dequeue();
        }, time);
    });
};
/** 
 * 单击一个checkbox，全选/取消全选指定的checkbox
 * @param {String} checkid:全选的选择框
 * @param {String} clickid:单击的选择框
 * 调用方法：$.check("a","b"):a(需要全选的选择框id),b(单击的选择框id)
 */
jQuery.extend({
    checkAll: function(checkid, clickid) {
        var obj = $("#" + clickid).click(function() {
            var chk = this;
            $(":input[id='" + checkid + "']").each(function() {
                this.checked = chk.checked;
            })
        })
    }
})

jQuery.extend({
    maskDiv: function() {
        //设置遮罩层
        $("<div id='sitemask'></div>").each(function() {
            var weidth = document.documentElement.clientWidth;
            var height = document.documentElement.clientHeight;
            $(this).appendTo("body").css({
                position: "absolute",
                display: "block",
                left: "0px",
                top: "0px",
                width: weidth + "px",
                height: height + "px",
                background: "#000",
                filter: "progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=5,finishOpacity=75)",
                opacity: "0.60",
                "z-index": "997"
            })
        });
    }
})



/**
 * 创建loading div
 */
jQuery.extend({
    loading: function(text) {
        if (text == null) {
            text = "页面正在加载中，请稍候...";
        }
        $("<div id='loading'></div>").appendTo("body").append("<img style='vertical-align:middle' src='../../images/loading.gif' border='0'>" + text).css({
            position: "absolute",
            //display: "block",
            width: "200px",
            //height: "60px",
            border: "1px solid #336699",
            color: "#483D8B",
            background: "#00FFFF",
            "list-style-type": "none",
            "font-size": "12px",
            "line-height": "60px",
            "text-align": "center",
            "vertical-align": "middle",
            "z-index": "9999"
        }).each(function() {
            var left = document.documentElement.clientWidth / 2 - $(this).width() / 2;
            var top = document.documentElement.clientHeight / 2 - $(this).height() / 2;
            $(this).css({
                left: left + "px",
                top: top + "px"
            });
        }).ajaxStart(function(){
			$(this).show();
		}).ajaxSuccess(function(){
			$(this).hide();
		});
        $(window).scroll(function() {
            $("#loading").each(function(i) {
                var left = document.documentElement.clientWidth / 2 - $(this).width() / 2 + document.documentElement.scrollLeft;
                var top = document.documentElement.clientHeight / 2 - $(this).height() / 2 + document.documentElement.scrollTop;
                $(this).css({
                    left: left + "px",
                    top: top + "px"
                });
            })
        });
    }
})

jQuery.extend({
    showTip: function(text) {
        if (text == null) {
            text = "操作成功";
        }
        $("<div id='showoperatetip'></div>").appendTo("body").append(text).css({
            position: "absolute",
            display: "block",
            //width: "200px",
            //height: "60px",
            border: "1px solid #336699",
            color: "#483D8B",
            padding: "5px",
            margin: "5px",
            background: "#00FFFF",
            "font-size": "12px",
            //"line-height": "22px",
            "text-align": "center",
            "vertical-align": "middle",
            "z-index": "9999"
        }).each(function() {
            var left = document.documentElement.clientWidth / 2 - $(this).width() / 2;
            var top = document.documentElement.scrollTop + document.documentElement.clientHeight / 2 - $(this).height() / 2;
            $(this).css({
                left: left + "px",
                top: top + "px"
            });
        })
        setTimeout("$('#showoperatetip').remove()", 3000);
        //alert(document.documentElement.offsetHeight+","+document.documentElement.clientHeight+","+document.documentElement.scrollHeight+","+document.documentElement.scrollTop);
    }
})

jQuery.extend({
    loaded: function() {
        //$(window).load(function() {
            $("#loading").remove();
        //});
    }
})

jQuery.extend({
    documentBody: function() {
        return document.body || document.documentElement;
    }
})
