﻿jQuery.fn.extend({
    //绘画手形
    //调用：$("#按钮ID").Hand();
    Hand: function() {
        $(this).css({ cursor: "pointer" });
    },
    //控制GridView表头的水平位置
    HeaderGridView: function(Val) {
        $(this).css({
            'text-align': Val.ALIGN, //水平对齐
            'font-weight': Val.WEIGHT//粗体设置
        });
    },
    //判断TEXTBOX文本输入是否为空
    isTextNull: function() {
        if ($.trim($(this).val()) == "" || $.trim($(this).val()) == null || $.trim($(this).val()).length <= 0)
            return null;
        else
            return $(this).val();
    },
    //实现windows的提示问号窗口
    WinConfirm: function(Msg) {
        $(this).click(function() {
            if (!window.confirm(Msg))
                return false;
        });
    },
    //使用EXT实现windows的提示问号窗口效果
    ExtConfirm: function(Msg) {
        $(this).click(function() {
            Ext.MessageBox.confirm(Msg.TITLE, Msg.MSG, Msg.FN);
        });
        //        Ext.MessageBox.confirm(Msg.TITLE, Msg.MSG, Msg.FN);
    },
    //Ext.MessageBox.show
    ExtShow: function(Msg) {
        Ext.MessageBox.show({
            title: Msg.TITLE, //(String)标题
            msg: Msg.MSG, //(String)消息的内容
            buttons: Msg.BUTTONS, //(ARRAY)弹出框按钮的设置，主要有以下几种：Ext.Msg.OK,Ext.Msg.OKCANCEL,Ext.Msg.CANCEL,Ext.Msg.YESNO,Ext.Msg.YESNOCANCEL,你也可以自定义按钮上面的字：{"ok","我本来是ok的"}。若设为false，则不显示任何按钮.
            fn: Msg.FN, //(fn)关闭弹出框后执行的函数
            animEl: Msg.ANIMEL, //(String)对话框弹出和关闭时的动画效果，比如设置为“id1”，则从id1处弹出并产生动画，收缩则相反
            width: Msg.WIDTH, //(int)弹出框的宽度，不带单位
            icon: Msg.ICON, //弹出框内容前面的图标，取值为Ext.MessageBox.INFO，Ext.MessageBox.ERROR,Ext.MessageBox.WARNING,Ext.MessageBox.QUESTION
            closable: Msg.CLOSABLE, //(boole)如果为false，则不显示右上角的小叉叉，默认为true
            progress: Msg.PROGRESS, //(Boolean)设为true，显示进度条，（但是是死的）
            wait: Msg.WAIT, //(Boolean)设为true，动态显示progress
            progressText: Msg.PROGRESSTEXT, //(String)显示在进度条上的字
            prompt: Msg.PROMPT, //(Boolean)设为true，则弹出框带有输入框
            multiline: Msg.MULTILINE, //(Boolean)设为true，则弹出框带有多行输入框
            multilineStyle: 'height:100px'
        });
    },
    //鼠标经过行时变颜色
    trHoverColor: function() {
        $(this).hover(function() {
            $(this).css("backgroundColor", "");
        }, function() {
            $(this).css("backgroundColor", "#FFFFFF");
        });
    },
    //防止表单按钮的重复提交
    //Strformid参数为：form的ID名
    SubmitDisabled: function(Strformid) {
        var getButton = $(this);
        $(Strformid).submit(function() {
            getButton.attr('disabled', 'true');
            $(Strformid).submit();
        });
    },
    /*参数说明
    TYPE:支持(GET与POST),
    URL:发送请求的地址,
    DATA:如 {foo:["bar1", "bar2"]} 转换为 '&foo=bar1&foo=bar2'
    DATATYPE(String):"(xml html script json jsonp text)",
    GLOBAL(Bool):是否启用ajax事件 true或false,
    LOADTEXT(String):提示字符串,
    ERROR(fn)自定义错误,
    SUCCESS(fn)自定义返回数据
    */
    Ajax_ZGH: function(info) {
        $.ajax({
            type: info.TYPE,
            url: info.URL,
            data: info.DATA,
            dataType: info.DATATYPE,
            global: info.GLOBAL,
            error: info.ERROR,
            success: info.SUCCESS
        });
    },
    /*参数说明
    ELS(String)主体显示的html元素，也可以写为el:"win"
    TITLE(String)窗口标题,
    WIDTH(int)窗口宽度,
    HEIGHT(int)窗口高度,
    AUTOLOAD(指定新的页面) 例如：autoLoad: { url: '' + info.HTMLCONTENT + '', scripts: true },
    HTML(String) 字符串 (注意 AUTOLOAD与HTML 只要一个)
    HTMLCONTENT(String)窗口内容
    MODAL(Bool)true为模式窗口，后面的内容都不能操作，默认为false,
    RESIZABLE(Bool)是否可以改变大小，默认可以,
    MAXIMIZABLE(Bool)是否增加最大化，默认没有,
    DRAGGABLE(Bool)是否可以拖动，默认可以,
    MINIMIZABLE(Bool)是否增加最小化，默认无,
    CLOSABLE(Bool)是否显示关闭，默认有关闭,
    PLAIN(Bool)true则主体背景透明，false则主体有小差别的背景色，默认为false,
    ITEMS(items)可扩展,
    items:new Ext.TabPanel({activeTab:0,//当前标签为第1个tab（从0开始索引）
    border:false,
    items:[{title:"tab1",html:"tab1在windows窗口中"},{title:"tab2",html:"tab2在windows窗口中"}]//TabPanel中的标签页，以后再深入讨论
    }),
    plain:true,//true则主体背景透明，false则主体有小差别的背景色，默认为false
    title:"标题"
    });
    BUTTONS buttons:[{text:"确定"},{text:"取消",handler:function(){w.close();}}],
    BUTTONALIGN(String)按钮的对齐方式buttonAlign:"center"
    */
    ExtOpenWindow: function(info) {
        var wins;
        wins = new Ext.Window({
            contentEl: info.EL,
            title: info.TITLE,
            width: info.WIDTH,
            height: info.HEIGHT,
            autoLoad: (info.AUTOLOAD == null) ? null : info.AUTOLOAD,
            html: (info.HTML == null) ? null : info.HTML,
            modal: (info.MODAL == null) ? true : false,
            resizable: (info.RESIZABLE == null) ? false : true,
            maximizable: (info.MAXIMIZABLE == null) ? false : true,
            draggable: (info.DRAGGABLE == null) ? false : true,
            minimizable: (info.MINIMIZABLE == null) ? false : true,
            closable: (info.CLOSABLE == null) ? true : false,
            plain: (info.PLAIN == null) ? false : true,
            items: (info.ITEMS == null) ? null : info.ITEMS,
            buttons: (info.BUTTONS == null) ? null : info.BUTTONS,
            buttonAlign: (info.BUTTONALIGN == null) ? null : info.BUTTONALIGN
        });
        return wins;
    },
    //这里给所支持Html代码设置
    SetHTMLTable: function() {
        $(this).focus(function() {
            $(window.parent.document).find("#HideUbbValue").val('#' + $(this).attr('id') + '');
        });
    },
    /*实现鼠标与层的偏移效果
    参数为：显示层离鼠标的距离偏移数
    实例如下：
    参数传值
    {
    divoffsetLeft: 30,
    divoffsetTop: -70,
    setUrl: '/M/showRoomDetailInfo.html',
    setData: 'id=0',
    setGlobal: false,
    setEventOpen:'click',
    setEventClose:'click'
    }
    必须在body内加入
    <div id='tooltip' style="position: absolute;overflow: hidden;display: none;z-index:100;"><div id="toolContent"></div>
    在关闭容器命名为：closeDiv
    */
    tooltipOpen: function(DATA) {
        var tooltip = $("#tooltip"); //获取显示层
        var toolContent = $("#toolContent"); //获取显示内容层
        $(this).bind(DATA.setEventOpen, function(e) {
            Mouse(e); //计算显示层的位置
            $().Ajax_ZGH({
                TYPE: 'GET',
                URL: DATA.setUrl,
                DATA: DATA.setData,
                DATATYPE: 'html',
                GLOBAL: DATA.setGlobal,
                ERROR: null,
                SUCCESS: function(msg) {
                    toolContent.html(msg);
                    if (DATA.setEventClose != null) {
                        $("#closeDiv").bind(DATA.setEventClose, function() {
                            $(this).tooltipClose();
                        });
                    }
                }
            });
            tooltip.css({ top: toppos, left: leftpos }); //给显示层定义CSS--当前计算出的位置
            tooltip.show(); //显示效果
        });
        //=============================================计算坐标函数
        var Mouse = function(e) {
            mouse = new MouseEvent(e);
            leftpos = mouse.x + DATA.divoffsetLeft;
            toppos = mouse.y + DATA.divoffsetTop;
        }
        var MouseEvent = function(e) {
            this.x = e.pageX
            this.y = e.pageY
        }
    }, tooltipClose: function() {
        $("#tooltip").hide();
    }, isEmail: function() {
        var reg = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/;
        if ($(this).isTextNull() != null) {
            if (reg.test($(this).isTextNull())) {
                return true;
            } else {
                return false;
            }
        }
    }, inputNumber: function() {
        $(this).keyup(function() {
            return $(this).val($(this).val().replace(/[^\d]/g, ''));
        });
    }
});
/*****************************************************
* 这里的初始化设置只对管理后台有用
*****************************************************/
$(function() {
    var getHttp = window.location.href;
    if (getHttp.indexOf('AdminSysmanage') > -1 && getHttp.indexOf('login.aspx') == -1 && getHttp.indexOf('HomePage.aspx') == -1) {
        $(window.parent.document).find("#HideUbbValue").val('');
    }
});
/*****************************************************
* 获取Response.QueryString值
*****************************************************/
function queryString(strName) {
    var strHref = window.document.location.href;
    var intPos = strHref.indexOf("?");
    var strRight = strHref.substr(intPos + 1);
    var arrTmp = strRight.split("&");
    for (var i = 0; i < arrTmp.length; i++) {
        var arrTemp = arrTmp[i].split("=");
        if (arrTemp[0].toUpperCase() == strName.toUpperCase())
            return arrTemp[1];
    }
    return "";
}




