﻿/*
    USerice前端组件 包含PosU定位组件 PopU弹窗组件 TipU提示组件 ProcessU进度条组件\
    Cray.Lin - NetDragon Inc
    Create date : 2009-10
    Update date : 2010-02-22
*/
/* 最后更新: */

var USerice = {
    ie6 : $.browser.msie && ($.browser.version == "6.0")
};
//全局统一的定位获取对象 by Cray.Lin
var PosU = {
    // 设置弹出层跟随对象显示并计算相对位置
    getOffsetX: function(obj, positionNum)
    {
        var $this = this;
        var jqObj = $(obj);
        obj = jqObj[0];
        var x = $this.offsetX(obj);
        //        if(frameElement)
        //            x += $this.offsetX(frameElement);
        return x + positionNum; //POPUCONTROL.iframeX;
    },
    // 设置弹出层跟随对象显示并计算相对位置
    getOffsetY: function(obj, positionNum)
    {
        var $this = this;
        var $obj = $(obj);
        obj = $obj[0];
        var y = $this.offsetY(obj);
        //y += $this.getHeight($obj);
        //        if(frameElement)
        //            y += $this.offsetY(frameElement);
        return y + positionNum; //POPUCONTROL.iframeY;
    },
    //获得卷屏高度
    getScrollTop: function()
    {
        var scrollTop = 0;
        if (document.documentElement && document.documentElement.scrollTop)
            scrollTop = document.documentElement.scrollTop;
        else if (document.body)
            scrollTop = document.body.scrollTop;
        return scrollTop;
    },
    //取得页面在当前屏幕内可视区域的宽度
    getInnerW: function()
    {
        return (window.innerWidth) ? window.innerWidth : (document.documentElement && document.documentElement.clientWidth) ? document.documentElement.clientWidth : document.body.offsetWidth;
    },
    //取得页面在当前屏幕内可视区域的高度
    getInnerH: function()
    {
        return (window.innerHeight) ? window.innerHeight : (document.documentElement && document.documentElement.clientHeight) ? document.documentElement.clientHeight : document.body.offsetHeight;
    },
    //取得对象距离顶部的值
    offsetY: function(obj)
    {
        if (!obj)
            return 0;
        var y = 0;
        if (obj.offsetTop)
            y += obj.offsetTop;
        while (obj = obj.offsetParent)
            if (obj.offsetTop)
            y += obj.offsetTop;
        return y;
    },
    //取得对象距离顶部的值
    offsetX: function(obj)
    {
        if (!obj)
            return 0;
        var x = 0;
        if (obj.offsetLeft)
            x += obj.offsetLeft;
        while (obj = obj.offsetParent)
            if (obj.offsetLeft)
            x += obj.offsetLeft;
        return x;
    },
    //取得对象高度值
    getHeight: function(obj) {
        var $obj = $(obj);
        var h = $obj.height();
        if (h.toString().indexOf("px", 0) > -1) {
            h = parseInt(h.replace(/px/, ""));
        }
        else
            h = parseInt(h);
        try{
            var tmpH = 0;
            tmpH = parseInt($obj.css("padding-top").replace("px", ""));
            if (tmpH != NaN && tmpH > 0) h += tmpH;
            tmpH = parseInt($obj.css("padding-bottom").replace("px", ""));
            if (tmpH != NaN && tmpH > 0) h += tmpH;
            tmpH = parseInt($obj.css("border-width").replace("px", ""));
            if (tmpH != NaN && tmpH > 0) h += tmpH * 2;
        } catch(e) {
            alert(h);
            return h;
        }
        return h;
    }
};

// =========== PopU 核心 ===========
// 修改Jquery不识别IE8的bug
var userAgent = navigator.userAgent.toLowerCase();
jQuery.browser = {
    version: (userAgent.match(/.(?:rv|it|ra|ie)[\/: ]([\d.]+)/) || [])[1],
    safari: /webkit/.test(userAgent),
    opera: /opera/.test(userAgent),
    msie: /msie/.test(userAgent) && !/opera/.test(userAgent),
    mozilla: /mozilla/.test(userAgent) && !/(compatible|webkit)/.test(userAgent)
};

// jqDrag 拖拽方法
// this:拖拽的对象
// h:触发拖拽事件的对象
(function($) {
    $.fn.jqDrag = function(h) { return i(this, h, 'd'); };
    $.fn.jqResize = function(h) { return i(this, h, 'r'); };
    $.jqDnR = { dnr: {}, e: 0,
        drag: function(v) {
            if (M.k == 'd') E.css({ left: M.X + v.pageX - M.pX, top: M.Y + v.pageY - M.pY });
            else E.css({ width: Math.max(v.pageX - M.pX + M.W, 0), height: Math.max(v.pageY - M.pY + M.H, 0) });
            return false;
        },
        stop: function() { E.css('opacity', M.o); $().unbind('mousemove', J.drag).unbind('mouseup', J.stop); }
    };
    var J = $.jqDnR, M = J.dnr, E = J.e,
    i = function(e, h, k) {
	    	return e.each(function() {
	        h = (h) ? $(h, e) : e;
	        h.bind('mousedown', { e: e, k: k }, function(v) {
	            var d = v.data, p = {}; E = d.e;
	            // attempt utilization of dimensions plugin to fix IE issues
	            if (E.css('position') != 'relative') { try { E.position(p); } catch (e) { } }
	            M = { X: p.left || f('left') || 0, Y: p.top || f('top') || 0, W: f('width') || E[0].scrollWidth || 0, H: f('height') || E[0].scrollHeight || 0, pX: v.pageX, pY: v.pageY, k: d.k };
	            $().mousemove($.jqDnR.drag).mouseup($.jqDnR.stop);
	            return false;
	        });
	    });
	},
	f = function(k) { return parseInt(E.css(k)) || false; };
})(jQuery);

// jqPopU 弹窗控制器
var POPUCONTROL = {
    list: [],
    iframeList: [],
    basePopuObj: null,
    z_index : 1080,
    ID : 0,
    push: function(obj) {
        this.ID ++;
        this.list.push( { popuObj: obj, popuID: this.ID } );
    },
    show: function() {
        this.z_index += 4;
        return this.z_index;
    },
    //传递参数为空时清除最新一个弹窗，有ID值时根据ID删除
    del: function(ID) {
        if(ID<0)
            return;
        if(ID == undefined && this.list.length > 0)
        {
            this.list.pop();
        }
        //var begin = new Date().getTime();
        for(i=0;i<this.list.length;i++)
        {
            if(this.list[i].popuID == ID)
            {
                this.list = this.list.slice(0,i).concat(this.list.slice(i+1,this.list.length));
                //alert(this.list.length + "__耗时:" + (new   Date().getTime()   -   begin) );
            }
        }
        return;
    },
    onESC: function(keyEvent) {
        if (!keyEvent) keyEvent = window.event;
        var kc = keyEvent.which || keyEvent.keyCode;
        if (kc == this.keyIsESC && this.list.length > 0) {
            for(i=this.list.length-1;i>0;i--)
            {
                if(this.list[i].popuObj.isShow && this.list[i].popuObj.canEsc)
                {
                    this.list[i].popuObj.close();
                    return;
                }
            }
        }
    },
    keyIsESC: 27
};
//全局响应ESC按键关闭方法
(function($) {
    $(document).bind("keydown", function(e) { POPUCONTROL.onESC(e); });
    
})(jQuery);

// jqPopU 弹窗体系
function PopU() {
    //填充到对象列表
    POPUCONTROL.push(this);
    
    //公共调用方法
    ie6 = $.browser.msie && ($.browser.version == "6.0")
    //初始化
    this._initialize();
};
PopU.prototype._initialize = function() {
    var $this = this;
    
    this.timerClosePop = null;
    this.initTop = null;
    this.z_index = POPUCONTROL.z_index;
    this.ID = POPUCONTROL.ID;
    this.closeIsHide = false;
    this.type = null;
    this.isShow = false; //是否显示
    this.canEsc = false; //是否接受热键关闭
    this.onLoadFn = function() { };
    this.onShowFn = function() { };
    this.onHideFn = function() { };
    //对象化核心部件
    this.param = {};
    this.pubOverlay = null;//遮罩层
    this.pubWindow = null;//弹窗对象
    this.pubContent = null;//传入显示内容
    this.pubLoading = null;//加载信息
    this.pubBtnList = null;//按钮容器
    this.pubTipsAtIframe = null;//弹窗跟随对象所在的Iframe对象
    
    //处理IE6下滚动时的定位
//    if ($.browser.version == "6.0") {
//        $(window).bind("scroll", function() {
//            if (toolTmp.initTop == null) toolTmp.initTop = 150;
//                var topscroll = parseInt(document.documentElement.scrollTop || document.body.scrollTop,10);
//            $("#popWindow").css("top", parseInt(toolTmp.initTop,10) + topscroll);
//            $("#popConfirm").css("top", parseInt(toolTmp.initTop,10) + topscroll);
//            $("#popAlert").css("top", parseInt(toolTmp.initTop,10) + topscroll);
//        });
//    }
}
//定义窗口方法
PopU.prototype.init = function(param) {
    //测试执行时间
    //    var startTime,endTime; 
    //    var d=new Date(); 
    //    startTime=d.getTime();
    //当弹窗对象存在而且设置不需缓存时 清理对象
    if (this.pubWindow) {
        this._initialize();
    }
    var $this = this;
    /* 参数整理 --------------------------- */
    param = param || {};
    if (undefined == param.showYesBtn) param.showYesBtn = false;  //是否显示确认按钮
    if (undefined == param.showNoBtn) param.showNoBtn = false;  //是否显示取消按钮
    if (undefined == param.onYesFn || typeof (param.onYesFn) != "function")
        param.onYesFn = function() { $this.close(); };
    else
        param.showYesBtn = true;
    if (undefined == param.onNoFn || typeof (param.onNoFn) != "function")
        param.onNoFn = function() { };
    else
        param.showNoBtn = true;
    if (undefined == param.onShowFn || typeof (param.onShowFn) != "function") param.onShowFn = function() { }; //显示完成后执行回调
    if (undefined == param.onLoadFn || typeof (param.onLoadFn) != "function") param.onLoadFn = function() { }; //调用开始时执行回调
    if (undefined == param.onHideFn || typeof (param.onHideFn) != "function") param.onHideFn = function() { }; //关闭或隐藏时执行回调
    //执行调用事件
    param.onLoadFn();
    if (undefined == param.w) param.w = 240; //弹窗宽度
    if (undefined == param.h) param.h = 0; //弹窗高度
    if (undefined == param.showOverlay) param.showOverlay = true;  //是否显示遮罩层
    if (undefined == param.overlayParam) param.overlayParam = 0; //遮罩层透明度[0-100] (0为透明 但是有这一层)
    if (undefined == param.onOverlay) param.onOverlay = 0; //遮罩层事件 (0:点击遮罩层时窗口闪烁 1:点击遮罩层时窗口关闭 2:mouseover遮罩层时窗口关闭)
    if (undefined == param.autoClose) param.autoClose = false; //是否自动关闭
    if (undefined == param.closeTime) param.closeTime = 2000; //自动关闭时间 (单位毫秒 0为不关闭)
    if (undefined == param.closeIsHide) param.closeIsHide = false; //关闭时是否只是隐藏对象而不是移除对象
    this.closeIsHide = param.closeIsHide;
    if (undefined == param.tipsAtObj) param.tipsAtObj = false; //悬浮紧跟对象
    if (undefined == param.offsetX) param.offsetX = 0; // 相对偏移量X值
    if (undefined == param.offsetY) param.offsetY = 0; // 相对偏移量Y值
    if (undefined == param.title) param.title = ""; //标题栏信息
    if (undefined == param.drag) param.drag = true; //是否允许拖拽 (2009-11-09)
    if (undefined == param.positionType) param.positionType = 'absolute'; //窗口定位方式
    if (undefined != param.canEsc) this.canEsc = param.canEsc; //是否允许热键关闭

    if (undefined == param.contents) {
        param.contents = ""; //显示内容绑定
        if (undefined != param.msg)
            param.contents = param.msg; //兼容其他旧版本输入习惯
        if (undefined != param.content)
            param.contents = param.content; //兼容可能出现的输入错误情况
    }
    if (undefined == param.type) param.type = "string"; //传入的Contents的类型 ("string":字符串,"jquery":JQ对象,"iframe":框架页面URL,"ajax":异步请求页面URL)
    this.type = param.type;
    if (undefined == param.x) { //弹窗x坐标
        param.x = PosU.getInnerW() / 2 - param.w / 2;
    } else {
        param.x = param.x;
    }
    if (undefined == param.y) { //弹窗y坐标
        var popHeight = param.h + 46; //46px是边框高度加各级内边距
        if (param.title.length > 0) popHeight += 24; //24px为标题栏高度
        if (param.showNoBtn || param.showYesBtn) popHeight += 32; //32px为底部按钮拦高度
        param.y = +parseInt(PosU.getInnerH() * 0.8 / 2 - popHeight / 2);
        if (param.positionType == 'absolute')
            param.y += PosU.getScrollTop();
        if (param.y < 50) param.y = 50;
    } else {
        param.y = param.y;
    }
    param.btnList = param.btnList || new Array(); //窗口系统按钮列表

    //    d=new Date();
    //    endTime=d.getTime();
    //    alertD(endTime-startTime);

    //param处理调整完毕 将param缓存
    this.param = param;
    //var scrollTop = document.documentElement.scrollTop;

    /* 对象化输出 --------------------------- */
    this.pubWindow = $('<div class="popU" style="left:' + param.x + 'px;top:' + param.y + 'px;width:' + param.w + 'px; position: ' + param.positionType + '"></div>'); //整个弹窗对象
    this.pubOverlay = $('<div class="popU_Overlay"></div>').css({ position: ie6 ? 'absolute' : 'fixed', opacity: param.overlayParam / 100, 'height': PosU.getInnerH() + "px" });
    if (!param.showOverlay)
        this.pubOverlay.css({ width: "0px", height: "0px" });
    var popHtml;
    if (POPUCONTROL && POPUCONTROL.basePopuObj) {
        popHtml = POPUCONTROL.basePopuObj;
    } else {
        popHtml = new Array();
        popHtml.push('        <div class="popU_Tl limitH"></div>');
        popHtml.push('        <div class="popU_Tr limitH"></div>');
        popHtml.push('        <div class="popU_T limitH BgColor"></div>');
        popHtml.push('        <div class="popU_L">');
        popHtml.push('            <div class="popU_Lin BgColor"></div>');
        popHtml.push('            <div class="popU_R">');
        popHtml.push('                <div class="popU_Rin BgColor"></div>');
        popHtml.push('                <div class="popU_Main">');
        popHtml.push('                    <div class="popU_Btn"></div>');
        popHtml.push('                    <div class="hd"></div>');
        popHtml.push('                    <div class="bd popBd clearfix" style="position:relative;"></div>');
        popHtml.push('                    <div class="ft clearfix"></div>');
        popHtml.push('                </div>');
        popHtml.push('            </div>');
        popHtml.push('        </div>');
        popHtml.push('        <div class="popU_Bl limitH"></div>');
        popHtml.push('        <div class="popU_Br limitH"></div>');
        popHtml.push('        <div class="popU_B limitH BgColor"></div>');
        POPUCONTROL.basePopuObj = popHtml.join('\n');
    }
    this.pubWindow.append(POPUCONTROL.basePopuObj);

    this.pubBtnList = this.pubWindow.find(".popU_Btn").css("z-index", this.z_index);
    var popU_Main = this.pubWindow.find(".popU_Main"); //内框对象
    if (param.title.length > 0)
        popU_Main.find(".hd").text(param.title);
    else
        popU_Main.find(".hd").addClass("emptyHd");
    if (param.drag) {
        this.pubWindow.jqDrag(popU_Main.find(".hd"));
    }
    if (param.h > 0) {
        popU_Main.find(".popBd").css("height", param.h + "px")
    }
    //填充传入系统按钮
    $.each(param.btnList, function(i, item) {
        popU_Main.find(".popU_Btn").append(item);
    });
    //填充传入内容
    switch (param.type) {
        case "string":
            this.pubContent = $(popU_Main.find("div.popBd"));
            this.pubContent.append(param.contents);
            break;
        case "jquery":
        case "div":
            this.pubContent = $(param.contents);
            if (this.pubContent.hasClass("bd") || this.pubContent.find("div.bd").length > 0)
                popU_Main.find("div.popBd").replaceWith(this.pubContent.addClass("clearfix"));
            else
                popU_Main.find("div.popBd").append(this.pubContent);
            break;
        case "iframe":
            this.pubLoading = $("<div id='popWindowLoading' style='margin: 0pt; padding: 0pt; width: 100%; height: 100%;'>&nbsp;</div>");
            this.pubContent = $("<iframe name='popuIframe' style='width: 100%; height: " + param.h + "px;' scrolling='auto' frameborder='0' onload='popuOnShowFn()' src='" + param.contents + "'></iframe>");
            //将回调事件
            popuOnShowFn = this.param.onShowFn;
            popU_Main.find("div.popBd").append(this.pubContent);
            if (typeof ($.fn.jqProcessU) != "undefined") {
                popU_Main.find("div.popBd").append(this.pubLoading);
                popU_Main.find("div.popBd").addClass("iframe");
                this.pubContent.hide();
                this.pubLoading.jqProcessU({ type: 1 });
                setTimeout(function() {
                    if ($this.pubLoading.length > 0) {
                        $this.pubLoading.remove();
                        $this.pubContent.show();
                    }
                }, 1000);
            }
            break;
        case "ajax":
            popU_Main.find("div.popBd").append("暂不支持AJAX类型内容");
            break;
    }
    try {
        //修复IE6的select的遮罩层Bug
        this.pubWindow.bgiframe();
    }
    catch (e) { }
    //填充确认或取消按钮
    if (param.showYesBtn) {
        popU_Main.find("div.ft").append("<span class=\"btn1\"><span><button class='PopU_BtnYes'>确定</button></span></span>&nbsp;");
        popU_Main.find(".PopU_BtnYes").bind("click", function() { param.onYesFn(); });
    }
    if (param.showNoBtn) {
        popU_Main.find("div.ft").append("<span class=\"btn2\"><span><button class='PopU_BtnNo'>取消</button></span></span>");
        popU_Main.find(".PopU_BtnNo").bind("click", function() { param.onNoFn(); $this.close(); });
    }
    //遮罩层事件
    if (param.onOverlay == 0)
        this.pubOverlay.bind("click", function() { $this.flash(); });
    else if (param.onOverlay == 1)
        this.pubOverlay.bind("click", function() { $this.close(); });
    else if (param.onOverlay == 2)
        this.pubOverlay.hover(function() { }, function() { $this.close(); });
    //自动关闭事件
    if (param.autoClose && param.closeTime > 0)
        this.timerClosePop = window.setTimeout(function() { $this.close() }, param.closeTime);
    //增加IE6遮罩层
    //    if ($.browser.msie && $.browser.version == "6.0") {
    //        this.pubWindow.append('<iframe class="popU_ifr6" frameborder="0" scrolling="no" src="" style="width:' + (param.w - 10) + '"></iframe>');   
    //    }
}
//窗口定义方法
PopU.prototype.initPop = function(param) {
    var $this = this;
    if( $this.pubWindow)
        $this.pubWindow.remove();
    if( $this.pubOverlay)
        $this.pubOverlay.remove();
    param = param || {};
    if(undefined == param.btnList)
    {
        param.btnList = new Array();
        //添加关闭按钮
        var btnClose = $("<div class='btnClose' title='按ESC关闭'>&nbsp;</div>");
        btnClose.bind("click",function(){ $this.close(); } );
        param.btnList.push(btnClose);
    }
    //调用定义方法
    this.init(param);
    //添加到页面
    this.pubWindow.hide();
    this.pubWindow.appendTo(document.body);
    this.pubOverlay.hide();
    this.pubOverlay.appendTo(document.body);
}
//显示窗口方法
PopU.prototype.showPop = function(param) {
    var $this = this;
    param = param || {};
    if(undefined != param.offsetX) this.param.offsetX = param.offsetX;
    if(undefined != param.offsetY) this.param.offsetY = param.offsetY;
    if (this.param.tipsAtObj) {
        var x = PosU.getOffsetX(this.param.tipsAtObj, this.param.offsetX);
        var y = PosU.getOffsetY(this.param.tipsAtObj, this.param.offsetY) + PosU.getHeight(this.param.tipsAtObj);
        //若存在显示的Iframe对象
        if(this.pubTipsAtIframe) {
            x += PosU.offsetX(this.pubTipsAtIframe);
            y += PosU.offsetY(this.pubTipsAtIframe);
        }
        if(this.param.w + x > PosU.getInnerW())
            x = PosU.getInnerW() - this.param.w;
        this.pubWindow.css( { left:x + "px",top:y+"px" } );
    }
    else
    {
    }
    if(this.pubWindow.find("div.ft").children().length == 0)    //若没有按钮则隐藏底部按钮栏
        this.pubWindow.find("div.ft").hide();
    this.isShow = true; //标记显示状态
    this.pubWindow.show();
    this.pubWindow.focus();//取得焦点
    this.pubOverlay.show();
    //修改IE遮罩层的高度
    if ($.browser.msie && $.browser.version == "6.0") {
        var ifr6H = $this.pubWindow.height();
        if(parseInt(ifr6H) != NaN)
        {
            ifr6H = (parseInt(ifr6H) - 10) + 'px';
            this.pubWindow.find(".popU_ifr6").css({'height':ifr6H });
        }
    }
    //修改显示层顺序
    this.z_index = POPUCONTROL.show();
    this.pubWindow.css({ 'z-index': (this.z_index - 1) });
    this.pubOverlay.css({ 'z-index': (this.z_index - 2) });
    //父窗口响应对当前窗口iframe的高度调整
    if (parent.resetIframeHeight)
    {
        var top = parseInt(this.pubWindow.css("top").replace("px",""));
        if( top + this.pubWindow.height() > document.body.scrollHeight )
            setTimeout( function() { parent.resetIframeHeight( top + $this.pubWindow.height() ) }, 0);
    }
    //若不是iframe弹窗就执行显示后回调
    if(this.type != "iframe") this.param.onShowFn();
}
//获取按钮列表  暂未开放此方法
PopU.prototype.getBtn = function() {
    if(undefined == param.btnList)
    {
        param.btnList = new Array('close');
    }
    if(undefined == param.btnObjList)
    {
        param.btnObjList = new Array();
    }
    $.each( param.btnList,function(index, item) {
        switch(item)
        {
            case "close":
                //添加关闭按钮
                var btnClose = $("<div class='btnClose' title='按ESC关闭'>&nbsp;</div>");
                btnClose.bind("click",function(){ $this.close(); } );
                param.btnObjList.push(btnClose);
                break;
            case "pushpin":
                //添加图钉按钮
                var btnClose = $("<div class='btnClose' title='按ESC关闭'>&nbsp;</div>");
                btnClose.bind("click",function(){ $this.close(); } );
                param.btnObjList.push(btnClose);
                break;
        }
    });
}
//提示方法
PopU.prototype.alert = function(param) {
    var $this = this;
    param = param || {};
    param.closeIsHide = false; //坚决不缓存窗口 避免重复定义
    if (undefined != param.onNoFn) param.onNoFn = null; //屏蔽取消按钮
    param.showNoBtn = false; //屏蔽取消按钮
    param.showOverlay = true; //强制开启遮罩层
    if (undefined == param.onYesFn || typeof (param.onYesFn) != "function")
    {
        param.onOverlay = 1;//点击遮罩层则关闭窗口
        if(undefined == param.title && undefined == param.autoClose)
        {
            //若不定义标题栏不定义确认按钮 则自动关闭 默认关闭时间为两秒
            param.autoClose = true;
        }
    }
    else
    {
        var onYesFnTemp = param.onYesFn;
        param.onYesFn = function() { onYesFnTemp(); $this.close(); };
        param.onOverlay = 0;//点击遮罩层则弹窗闪烁
    }
    //调用定义方法
    this.init(param);
    //定义后特殊处理
    if (param.type == "string")
        this.pubContent.addClass("centerText"); //纯提示文字的增加醒目样式
    //显示到页面
    this.pubWindow.appendTo(document.body);
    this.pubWindow.find(".PopU_BtnYes").focus();//给确认按钮加焦点
    this.pubOverlay.appendTo(document.body);
    //调用显示方法
    this.showPop();
    
}
//确认方法
PopU.prototype.confirm = function(param) {
    var $this = this;
    param = param || {};
    param.closeIsHide = false; //坚决不缓存窗口 避免重复定义
    param.showNoBtn = true; //显示确认按钮
    param.ShowYesBtn = true; //显示取消按钮
    param.showOverlay = true; //强制开启遮罩层
    if (undefined == param.title) param.title = "确认窗口"; //标题栏信息
    if (undefined != param.onYesFn && typeof (param.onYesFn) == "function")
    {
        var onYesFnTemp = param.onYesFn;
        param.onYesFn = function() { onYesFnTemp(); $this.close(); };
    }
    //调用定义方法
    this.init(param);
    //定义后特殊处理
    if (param.type == "string")
        this.pubContent.addClass("centerText"); //纯提示文字的增加醒目样式
    //显示到页面
    this.pubWindow.appendTo(document.body);
    this.pubWindow.find(".PopU_BtnYes").focus();//给确认按钮加焦点
    this.pubOverlay.appendTo(document.body);
    //调用显示方法
    this.showPop();
}
//关闭方法
PopU.prototype.close = function() {
    var $this = this;
    //清除自动关闭事件
    if ($this.timerClosePop != null)
        window.clearTimeout($this.timerClosePop);
    //判断是否存在对象
    if(!$this.pubWindow || !$this.pubOverlay)
        return;
    this.isShow = false; //标记显示状态
    //判断关闭或隐藏
    if(this.closeIsHide)
    {
        $this.pubWindow.hide();
        $this.pubOverlay.hide();
        this.param.onHideFn();
    }
    else
    {
        $this.pubWindow.remove();
        $this.pubOverlay.remove();
        this.param.onHideFn();
        //在弹窗列表清除对象
        POPUCONTROL.del($this.ID);
        $this = null;
    }
}
// 点击非弹窗区域时 提示用户关注弹出窗口
PopU.prototype.flash=function() {
    var $this = this;
    setTimeout( function(){ $this.pubWindow.find(".hd").addClass('flash') }, 50);
    setTimeout( function(){ $this.pubWindow.find(".hd").removeClass('flash') }, 80);
    setTimeout( function(){ $this.pubWindow.find(".hd").addClass('flash') }, 150);
    setTimeout( function(){ $this.pubWindow.find(".hd").removeClass('flash') }, 180);
}
//判断若父窗体存在popU的引用则使用它
//if(parent && typeof(parent.document) != 'unknown' &&
//    typeof(parent.document) != 'undefined' &&
//    typeof(parent.document.body) != 'undefined' &&
//    parent.document.body != null &&
//    parent.PopU &&
//    parent.POPUCONTROL)
//{
//    PopU = parent.PopU; // By Cray.Lin 2009-10-19 暂不将PopU强制定义父窗口上
//    POPUCONTROL = parent.POPUCONTROL;
//}
// =========== PopU 全局对象 ===========
//全局单例方法 兼容旧版本调用方法 但参数需要修改
var _publicAlert = new PopU();
var _publicConfirm = new PopU();
var _publicWindow = new PopU();
    
popuAlert = function(param) {
    param = param || {};
    param.closeIsHide = false; //坚决不缓存窗口 避免冲突
    //关闭已经打开的对象
    if(_publicAlert.isShow)
        _publicAlert.close();
    //确保在全局处不出现冲突
    _publicAlert.alert(param);
};
closeAlert = function() {
    _publicAlert.close();
};
popuConfirm = function(param) {
    param = param || {};
    param.closeIsHide = false; //坚决不缓存窗口 避免冲突
    //关闭已经打开的对象
    if(_publicConfirm.isShow)
        _publicConfirm.close();
    //确保在全局处不出现冲突
    _publicConfirm.confirm(param);
};
closeConfirm = function() {
    _publicConfirm.close();
};
popuWindow = function(param) {
    param = param || {};
    param.closeIsHide = false; //坚决不缓存窗口 避免冲突
    this.popU = _publicWindow;
    //关闭已经打开的对象
    if(_publicWindow.isShow)
        _publicWindow.close();
    //确保在全局处不出现冲突
    _publicWindow.initPop(param);
    _publicWindow.showPop();
};
closeWindow = function() {
    _publicWindow.close();
};
//用于iframe加载完成后的全局回调
popuOnShowFn = function() {};

// =========== PopU 定制窗口 ===========
/* 带图钉的悬浮窗体 Start */
function pushpinWindow() {
	this.iPopU = new PopU();
    this.isPush = false;
    this.btnPush = null;
    this.timer = null;
    this.tipsAtObj = null;
}
pushpinWindow.prototype.initPop=function(param) {
	var $this = this;
	if(this.isPush || this.iPopU.isShow) {
	    this.iPopU.pubContent.html(param.contents);
	    return ;
	}
	this.iPopU.close();
	this.tipsAtObj = param.tipsAtObj;
	param.showOverlay = false;
    param.btnList = new Array();
    param.cloesIsHide = true;
    
    this.btnPush = $("<div class='pushBtn' title='是否将弹窗钉在页面上'>&nbsp;</div>");
    this.btnPush.bind("click", function () { $this.pushPin(); } );
    param.btnList.push(this.btnPush);
	this.iPopU.initPop(param);
	
	this.tipsPop();//执行鼠标悬停策略
}
pushpinWindow.prototype.showPop=function(param) {
	var $this = this;
	if(this.isPush)
	{
		this.btnPush.addClass("Push");
		this.iPopU.pubWindow.unbind();
    }
}
pushpinWindow.prototype.close=function(param) {
    var $this = this;
    clearTimeout($this.timer);
    $this.iPopU.pubWindow.unbind();
    $this.tipsAtObj.unbind();
	this.iPopU.close();
}
pushpinWindow.prototype.tipsPop = function() {
    var $this = this;
    $(this.tipsAtObj).mouseover( function(){
        clearTimeout($this.timer);
        $this.timer = setTimeout( function(){ $this.iPopU.showPop(); } , 300 );
    });
    $(this.tipsAtObj).mouseout( function(){
        clearTimeout($this.timer);//取消显示
        $this.timer = setTimeout( function(){ $this.close(); } , 200 );
    });
    this.iPopU.pubWindow.mouseover( function(){
        clearTimeout($this.timer);
    });
    this.iPopU.pubWindow.mouseout( function(){
        $this.timer = setTimeout( function(){ $this.close(); } , 200 );
    });
}
pushpinWindow.prototype.pushPin= function() {
	var $this = this;
	this.isPush = !this.isPush;
	if(this.isPush)
	{
		this.btnPush.addClass("Push");
        clearTimeout($this.timer);
        $this.iPopU.pubWindow.unbind();
        $this.tipsAtObj.unbind();
	}
	else
	{
		this.btnPush.removeClass("Push");
        this.tipsPop();//执行鼠标悬停策略
	}
}
//初始化·带图钉的悬浮窗体
$(document).ready(function() {
    popuPushpinWindow = new pushpinWindow();
    showPushpinWindow = function(param) {
        popuPushpinWindow.initPop(param);
        popuPushpinWindow.showPop();
    };
    closePushpinWindow = function(param) {
        myPopPushpinWindow.close(param);
    };
});
/* 带图钉的悬浮窗体 End */

var fixedScreenPopU;
/* 居中自适应大小的编辑题目窗体 Start */
function fixedScreenWindow() {
    fixedScreenPopU = new PopU();
    this.iPopU = fixedScreenPopU;
}
$(document).ready(function()
{
    fixedScreenWindow.prototype.initPop = function(param)
    {
        var $this = this;
        if (this.iPopU.isShow)
            this.iPopU.close();
        param.showOverlay = true;
        param.overlayParam = 80;
        param.w = PosU.getInnerW() - 80;
        param.h = PosU.getInnerH() - 150;
        param.cloesIsHide = true;
        param.drag = false;
        param.positionType = "fixed";

        $(window).bind('resize', function()
        {
            fixedScreenPopU.pubWindow.css({ 'width': (PosU.getInnerW() - 80) + 'px' });
            fixedScreenPopU.pubWindow.find(".popBd").css({ 'height': (PosU.getInnerH() - 150) + 'px' });
        });
        $this.iPopU.initPop(param);

    }
    fixedScreenWindow.prototype.showPop = function(param)
    {
        var $this = this;
        $this.iPopU.showPop();
    }
    fixedScreenWindow.prototype.close = function(param)
    {
        this.iPopU.close();
    }
});
/* 居中自适应大小的编辑题目窗体 End */

/*
* ScrollU - v2010.01.19
* Cray.Lin(501900@qq.com) - EA - Netdragon(www.nd.com.cn)
*/
(function($) {
    jQuery.fn.extend({
        scrollU: function(param) {
            var $this = this;
            //默认参数定义
            var _duration = 0;//动画持续时间
            var _type = 0;//漂浮类型 0:默认漂浮 1:条件跟随(距离可视区顶部值小于y时漂浮)
            var _x = 0;//漂浮x坐标
            var _y = 0;//漂浮y坐标
            var _marginTop = 10;//距离顶部最小值
            
            if (undefined != param) {
                if (!isNaN(param.duration))
                    _duration = parseInt(param.duration);
                if (!isNaN(param.x))
                    _x = parseInt(param.x);
                if (!isNaN(param.y))
                    _y = parseInt(param.y);
                if (!isNaN(param.marginTop))
                    _marginTop = parseInt(param.marginTop);
                if (!isNaN(param.type))
                    _type = parseInt(param.type);
            }
            //设置定位属性
            $this.each(function(index,item) {
                //获取函数传入的参数
                _x = isNaN( PosU.offsetX(item) ) ? 0 : PosU.offsetX(item);
                _y = isNaN( PosU.offsetY(item) ) ? 0 : PosU.offsetY(item);
//                if( !USerice.ie6 && _duration == 0 && _type == 0 )
//                    $(item).css({ "position": "fixed", "left": _x });
//                else
                    $(item).css({ "position": "absolute", "left": _x });
            });

            //响应滚动条滚动事件
            $(window).scroll(function() {
                //确定漂浮位置
                var scrollPos;
                if (typeof window.pageYOffset != 'undefined') {
                    scrollPos = window.pageYOffset;
                }
                else if (typeof document.compatMode != 'undefined' && document.compatMode != 'BackCompat') {
                    scrollPos = document.documentElement.scrollTop;
                }
                else if (typeof document.body != 'undefined') {
                    scrollPos = document.body.scrollTop;
                }
                $this.each( function(index,item) {
                    //根据动画时间 决定用动画或不用
                    if( _duration == 0 ) {
                        alertD(scrollPos +"_"+ _y);
                        if ( _type == 1 ) {
                            if( _y -scrollPos > _marginTop )
                                $(item).css({ "top": _y });
                            else
                                $(item).css({ "top": scrollPos + _marginTop })
                        } else if ( _type == 0 ) {
                            $(item).css({ "top": _y + scrollPos });
                        }
                    } else {
                        o.stop().animate({ "top": _y + scrollPos }, _duration);
                    }
                });
            });
            return $this;
        }
    });
})(jQuery);

/*
* jqProcessU - v2009.09.14
* Cray.Lin(501900@qq.com) - EA - Netdragon(www.nd.com.cn)
*/
(function($) {
    //重写jq的propertyChange属性修改事件
    //By HuangXu 2009.09.16
    $.fn.propertyChange = function(fn) {
        if (document.all) {
            $(this[0]).bind('propertychange', fn);
        } else {
            this[0].addEventListener("input", fn, false);
            this[0].addEventListener("change", fn, false);
        }
    }
    //进度条显示方法
    $.fn.jqProcessU = function(param) {
        if (typeof param == "string") {
            param = eval('(' + param + ')');
        }
        param = param || {};
        if (undefined == param.element) param.element = $(this);
        if (undefined == param.type || param.type > 2) param.type = 1;

        var divProcess;
        if (param.type == 1)
            divProcess = $("<div class='ProcessBar'><div class='Bar'>&nbsp;</div><div class='Font'>加载中...</div></div>");
        else if (param.type == 2)
            divProcess = $("<div class='ProcessBar'><div class='Icon'>&nbsp;</div></div>");
        if (!param.element) {
            alert("定义错误")
        }
        else {
            $(this).append(divProcess);
            if (param.element.length > 0 && param.element[0].tagName && param.element[0].tagName == 'IFRAME') {
                param.element[0].onload = function() { alert() };
            }
            param.element.propertyChange = function() { alert() };
        }
    };
})(jQuery);

(function($) {
    $.fn.extend({
        //弹窗提示方法
        jqTipU : function(param){
            if (typeof param == "string") {
                param = eval('(' + param + ')');
            }
            param = param || {};
            param.element = this;
            var _jqTipU = new jqTipU(param);
        }
    });
    var jqTipU = function(param){
        this.divTipU = null;
        this.timer = null;
        this.closeTimer = null; //自动消失时间器
        this.closeRelay = 1200; //自动消失时间(毫秒)
        this.direction = 'up';
        this.element = null; //弹窗跟随的对象
        this.showTip(param);
    };
    jqTipU.prototype.showTip = function(param) {
        var $this = this;
        if (typeof(param.contents) == "undefined") param.contents = '';
        if (typeof(param.type) == "undefined") param.type = 'normal';//insert[在对象后插入],normal[正常一次性悬浮提示],mouseover[鼠标悬停提示]
        if (typeof(param.w) == "undefined")
            param.w = "auto";
        else if (parseInt(param.w) != NaN && parseInt(param.w) > 0)
            param.w += "px";
        if (typeof(param.element) == "undefined")
            this.element = $(document.body).children().eq(0);
        else
            this.element = $(param.element);
        if (typeof(param.autoClose) == "undefined")
            param.autoClose = false;
        if (typeof(param.closeRelay) != "undefined")
            this.closeRelay = param.closeRelay;
        if (typeof(param.direction) == "undefined")
            this.direction = 'up';
        else
            this.direction = param.direction;
        
        //显示内容处理
        var divHtml;
        switch(this.direction) {
            case "up":
                if(jqTipUI.divUpHtml && jqTipUI.divUpHtml.length > 0)
                    divHtml = jqTipUI.divUpHtml;
                else {
                    divHtml = new Array();
                    divHtml.push('<table cellpadding="0" cellspacing="0" class="tipU"><tr><td class="tipU_top"><div class="tipU_topLen"><div class="tipU_direction"&nbsp;</div></div></td></tr>');
                    divHtml.push('<tr><td class="tipU_contents"></td></tr>');
                    divHtml.push('<tr><td class="tipU_bottom"><div class="tipU_bottomLen">&nbsp;</div></td></tr></table>');
                    jqTipUI.divUpHtml = divHtml;
                }
                break;
            case "down":
                if(jqTipUI.divDownHtml && jqTipUI.divDownHtml.length > 0)
                    divHtml = jqTipUI.divDownHtml;
                else {
                    divHtml = new Array();
                    divHtml.push('<table cellpadding="0" cellspacing="0" class="tipU"><tr><td class="tipU_top"><div class="tipU_topLen">&nbsp;</div></td></tr>');
                    divHtml.push('<tr><td class="tipU_contents"></td></tr>');
                    divHtml.push('<tr><td class="tipU_bottom"><div class="tipU_bottomLen"><div class="tipU_direction"&nbsp;</div></div></td></tr></table>');
                    jqTipUI.divDownHtml = divHtml;
                }
                break;
        }
        $this.divTipU = $(divHtml.join(''));
        $this.divTipU.find(".tipU_contents").append(param.contents);
        //将tipU对象填充到页面上 默认隐藏
        if( param.type == "insert" ) { //将tipU插入到某个对象后面
            param.element.append($this.divTipU);
            $this.divTipU.show();
        } else {
            //param.element.after($this.divTipU);
            $this.divTipU.prependTo(document.body);
        }
        if( param.type == "normal" || param.type == "mouseover" ) { //正常一次性悬浮提示&&鼠标悬停提示
            $this.divTipU.addClass("float");
            if(param.w != "auto")
                $this.divTipU.css( { width:param.w } );
        }
        if( param.type == "normal" ) { //正常一次性悬浮提示
            var x = PosU.getOffsetX(this.element, 0);
            var y = PosU.getOffsetY(this.element, $this.getOffsetY());
            $this.divTipU.css( { left:x + "px",top:y+"px"} );
            $this.divTipU.click(function(){
                $this.divTipU.remove();
            });
            //自动关闭方法
            if(param.autoClose) {
                clearTimeout($this.timer);
                $this.closeTimer = setTimeout( function(){ $this.closeTip(); } , this.closeRelay );
            }
            //正常显示
            $this.divTipU.show();
        }
        if( param.type == "mouseover" ) { //鼠标悬停提示
            $this.divTipU.mouseover( function(){
                clearTimeout($this.timer);
            });
            $this.divTipU.mouseout( function(){
                clearTimeout($this.timer);
                $this.timer = setTimeout( function(){ $this.closeTip(); } , 200 );
            });
            $.each(this.element,function(index,item){
                $(item).mouseover( function(){
                    var x = PosU.getOffsetX($(item), 0);
                    var y = PosU.getOffsetY($this.element, $this.getOffsetY());
                    $this.divTipU.css( { left:x + "px",top:y+"px"} );
                    clearTimeout($this.timer);
                    $this.timer = setTimeout( function(){ $this.divTipU.fadeIn(); } , 300 );
                });
                $(item).mouseout( function(){
                    clearTimeout($this.timer);
                    $this.timer = setTimeout( function(){ $this.closeTip(); } , 200 );
                });
            });
        }
    };
    jqTipU.prototype.getOffsetY = function() {
        var $this = this;
        var offsetY = 0;
        switch($this.direction){
            case "up":
                offsetY = PosU.getHeight($this.element);
                break;
            case "down":
                offsetY = -PosU.getHeight($this.divTipU);
                break;
        }
        return offsetY;
    };
    jqTipU.prototype.closeTip = function() {
        clearInterval(this.timer);
        this.divTipU.fadeOut(50);
    };
    //全局共用的插件元素 提升效率
    var jqTipUI = {
        divUpHtml: null,
        divDownHtml : null
    };
})(jQuery);
/*
 * Copyright (c) 2008 Gary Teo
 * http://t.wits.sg
 */
(function($) {
	$.extend({
		progressU: new function() {
			this.defaults = {
				increment	: 5,
				speed		: 15,
				showText	: true,											// 是否显示文字 百分比
				innerText	: "",											// 进度条内显示文字
				width		: 120,											// Width of the progressbar - don't forget to adjust your image too!!!
				boxImageCss	: 'ProgressU',						// boxImage : image around the progress bar
				barImagePos	: {
								0:	14,
								30: 28,
								70: 42
							},												// Image to use in the progressbar. Can be a single image too: 'images/progressbg_green.gif'
				height		: 12											// Height of the progressbar - don't forget to adjust your image too!!!
			};
			
			/* public methods */
			this.construct = function(arg1, arg2) {
				var argpercentage	= null;
				var argconfig		= null;
				
				if (arg1 != null) {
					if (!isNaN(arg1)) {
						argpercentage 	= arg1;
						if (arg2 != null) {
							argconfig	= arg2; }
					} else {
						argconfig		= arg1; 
					}
				}
				return this.each(function(child) {
					var pb		= this;
					if (argpercentage != null && this.bar != null && this.config != null) {
						this.config.tpercentage	= argpercentage;
						if (argconfig != null)
							pb.config			= $.extend(this.config, argconfig);
					} else {
						var $this				= $(this);
						var config				= $.extend({}, $.progressU.defaults, argconfig);
						var percentage			= argpercentage;
						if (argpercentage == null)
							var percentage		= $(this).attr("percent");;	// parsed percentage
						
						
						$this.html("");
						var border				= document.createElement('span');
						border.id 				= this.id + "_percentImage";
						border.title			= percentage + "%";
						border.className        = config.boxImageCss;
						border.width			= config.width;
						var bar					= document.createElement('span');
						bar.className           = "ProU_Inner";
						bar.innerHTML           = config.innerText != "%" ? config.innerText : "";
						var text				= document.createElement('span');
						text.id 				= this.id + "_percentText";
						text.className          = "ProU_Percent";
						var $border				= $(border);
						var $bar				= $(bar);
						var $text				= $(text);
						
						this.bar				= $bar;
						this.ntext				= $text;
						this.config				= config;
						this.config.cpercentage	= 0;
						this.config.tpercentage	= percentage;
						
						//$bar.css("background-position", getBarImage(this.config.cpercentage, config) + "50%" );
						$border.append($bar);
						if(config.innerText == "%")
						    $bar.append($text);
					    else
						    $border.append($text);
						$this.append($border);
					}
					
					function getBarImage (percentage, config) {
						var image = config.barImagePos;
						if (typeof(config.barImagePos) == 'object') {
							for (var i in config.barImagePos) {
								if (percentage >= parseInt(i)) {
									image = config.barImagePos[i];
								} else { break; }
							}
						}
						return image;
					}
					
					var t = setInterval(function() {
						var config		= pb.config;
						var cpercentage = parseInt(config.cpercentage);
						var tpercentage = parseInt(config.tpercentage);
						var increment	= parseInt(config.increment);
						var bar			= pb.bar;
						var text		= pb.ntext;
						var pixels		= config.width / 100;			// Define how many pixels go into 1%
						
						bar.css("background-position", (((config.width * -1)) + (cpercentage * pixels)) + 'px -' + getBarImage(cpercentage, config) + "px");
						if (config.showText)
							text.html(" " + Math.round(cpercentage) + "%");
						
						if (cpercentage > tpercentage) {
							if (cpercentage - increment  < tpercentage) {
								pb.config.cpercentage = 0 + tpercentage
							} else {
								pb.config.cpercentage -= increment;
							}
						}
						else if (pb.config.cpercentage < pb.config.tpercentage) {
							if (cpercentage + increment  > tpercentage) {
								pb.config.cpercentage = tpercentage
							} else {
								pb.config.cpercentage += increment;
							}
						} 
						else {
							clearInterval(t);
						}
					}, pb.config.speed); 
				});
			};
		}
	});
	$.fn.extend({
        progressU: $.progressU.construct
	});
})(jQuery);