﻿//=================================================

//    名称:popup弹窗

//    作者:吕明堂

//    时间:2009-03-13

//    功能:popup弹窗,同时遮盖住原页面

//    用法: 
//          打开:FloatShow('http://592hualian2.com.yinggou.com/PersonInfo-7390.html','我的个人信息',480,470);
//          关闭:FloatClose();

//=================================================

        var Popup_IFRAME_Width = 0;
        var Popup_IFRAME_Height = 0;
        
        function FloatShow(sUrl, PageTitle, iWidth, iHeight) 
        {
            iWidth = typeof(iWidth) == "number" ? parseInt((iWidth + 10),[10]) : 400; 
            iHeight = typeof(iHeight) == "number" ? iHeight : 400; 
            PageTitle = typeof(PageTitle)=="string" ? PageTitle : "";
            sUrl = typeof(sUrl)=="string" ? sUrl : "";  
            Popup_IFRAME_Width = iWidth;
            Popup_IFRAME_Height = iHeight;     
                  
            Popup_Veil_fn();
            PageMaskShow(window);
            
            var e = document.getElementById("ID_QQLOVE_WAIT_IFRAME");
            
            var Popup_Tb_Html="";
		    Popup_Tb_Html +='<div style="width:100%; background-color: #5bc23c;line-height :30px; height:30px;">';
		    Popup_Tb_Html +='<a style ="font-size :20px; color: #ffff66; float:left; margin-left :12px;">' + PageTitle + '</a>';
		    Popup_Tb_Html +='<a style=" font-size :13px; color: #ffff66; float:right;margin-right :12px;" href="javascript:FloatClose();">关闭</a></div>';
		    Popup_Tb_Html +='<div style="text-align:center;"><div style="width:' + iWidth + 'px;height:5px;background-color:#ffffff;"></div>';
		    Popup_Tb_Html +='<div style ="width:' + parseInt((iWidth-10),[10]) + 'px;height:' + parseInt((iHeight - 40),[10]) + 'px;margin:0px auto;">';
		    Popup_Tb_Html +='<iframe allowTransparency="true" id="ID_QQLOVE_FLOAT_IFRAME" style ="width:100%;height:0px;" src = "' + sUrl +'" name="ID_QQLOVE_FLOAT_IFRAME" frameborder="0" onload="popup_show_iframe(' + parseInt((iHeight - 40),[10]) + ');"></iframe>';
		    Popup_Tb_Html +='<div style ="width:100%;height:100%;text-align: center;" id = "iframe_load"><img src="/images/LOADYY.GIF" alt ="" /></div>';		
		    Popup_Tb_Html +='</div>';
		    Popup_Tb_Html +='<div style="width:' + iWidth + 'px;height:5px;background-color:#ffffff;"></div>';		
		    Popup_Tb_Html +='</div>';

            e.innerHTML = Popup_Tb_Html;
        }
        
        //关闭Popup
        function FloatClose()
        {
            document.getElementById("ID_QQLOVE_WAIT_BACKGND").style.display = "none";
            document.getElementById("ID_QQLOVE_WAIT_IFRAME").style.display = "none";
            Popup_Show_fn();
        }

        //iframe加载完后隐藏加载图片并显示iframe
        function popup_show_iframe(iframeHeight)
        {
            document.getElementById("iframe_load").style.display = "none";
            document.getElementById("ID_QQLOVE_FLOAT_IFRAME").style.height = iframeHeight + "px";  
        }

        //隐藏select标签
        function Popup_Veil_fn()
        {
            if(window.ActiveXObject)
            {
                var browser=navigator.appName 
                var b_version=navigator.appVersion 
                var version=b_version.split(";"); 
                var trim_Version=version[1].replace(/[ ]/g,""); 
                if(browser=="Microsoft Internet Explorer" && trim_Version=="MSIE6.0") 
                { 
                    Popup_Veil_Main_fn(window);
                } 
            }
        }
        
        function Popup_Veil_Main_fn(oWin)
        {
            var objs = oWin.document.getElementsByTagName("select");
            for(var n = 0; n<objs.length; n++) 
            {
                objs[n].style .display="none";
            }
            var _objs = oWin.frames;
            if(_objs.length>0)
            {
                for(var i=0;i<_objs.length;i++)
                {
                    Popup_Veil_Main_fn(_objs[i])
                }
            }
        }
        
        
        
        //显示select标签
        function Popup_Show_fn()
        {
            if(window.ActiveXObject)
            {
                var browser=navigator.appName 
                var b_version=navigator.appVersion 
                var version=b_version.split(";"); 
                var trim_Version=version[1].replace(/[ ]/g,""); 
                if(browser=="Microsoft Internet Explorer" && trim_Version=="MSIE6.0") 
                { 
                    Popup_Show_Main_fn(window);
                } 
            }    
        }
        
        function Popup_Show_Main_fn(oWin)
        {
            var objs = oWin.document.getElementsByTagName("select");
            for(var n = 0; n<objs.length; n++) 
            {
                objs[n].style .display="";
            }
            var _objs = oWin.frames;
            if(_objs.length>0)
            {
                for(var i=0;i<_objs.length;i++)
                {
                    Popup_Show_Main_fn(_objs[i])
                }
            }
        } 
        
        //滚动条滚动触发的事件(调整iframe层的位置)
        function Popup_Scroll_fn()
        {
            var e = document.getElementById("ID_QQLOVE_WAIT_BACKGND");
            var eIframe = document.getElementById("ID_QQLOVE_WAIT_IFRAME");
            
            if(e!=null && eIframe!=null)
            {
                if(get_MarginTop() + parseInt(Popup_IFRAME_Height,[10]) + 50 < parseInt((e.style.height.replace(/px/g,"")),[10]))
                {
	                eIframe.style.top = get_MarginTop() + "px"; 
                }     
                if(get_MarginLeft() + parseInt(Popup_IFRAME_Width,[10]) < parseInt((e.style.width.replace(/px/g,"")),[10]))
                {
	                eIframe.style.left = get_MarginLeft() + "px"; 
                }                 
            }
        }
        
        //窗体大小改变时触发的事件,重新定义遮罩层的长宽,并定位ifram层的位置
        function Popup_Resize_fn()
        {
            var e = document.getElementById("ID_QQLOVE_WAIT_BACKGND");
            var eIframe = document.getElementById("ID_QQLOVE_WAIT_IFRAME");
            
            if(e!=null && eIframe!=null)
            {
                e.style.height = get_Height() + "px";    
                e.style.width = get_Width() + "px";
                eIframe.style.top = get_MarginTop() + "px";
                eIframe.style.left = get_MarginLeft() + "px";
            }
        }
     
        
        window.onscroll=Popup_Scroll_fn; 
        window.onresize=Popup_Resize_fn;

/*======================== 创建遮罩层 =============================*/

        function PageMaskShow(oWin)
        {
	        var e = PageMaskCreate(oWin);
            var eIframe = PageIframeDivCreate(oWin);
	        
	        if(e && eIframe)
	        {
	            e.style.width = get_Width() + "px";
	            e.style.height = get_Height() + "px";
	            
	            eIframe.style.top = get_MarginTop() + "px"; 
	            eIframe.style.left = get_MarginLeft() + "px"; 	            
	            
		        e.style.display = "block";
		        eIframe.style.display = "block";
	        }
        }
        
        function PageIframeDivCreate(oWin)
        {
	        if(oWin && oWin.document)
	        {
		        if (!oWin.document.getElementById("ID_QQLOVE_WAIT_IFRAME"))
		        {
			        var ebg = DivCreate(oWin, oWin.document.body, "ID_QQLOVE_WAIT_IFRAME", 65530, 0, 0, "100%", "100%", "none");
	                ebg.style.width = Popup_IFRAME_Width+ "px";
	                ebg.style.height = Popup_IFRAME_Height + "px";		
			        ebg.style.backgroundColor = "#ffffff";	                	        
		        }
		        else
		        {
		            var ebg = oWin.document.getElementById("ID_QQLOVE_WAIT_IFRAME");
		            ebg.style.width = Popup_IFRAME_Width+ "px";
		            ebg.style.height = Popup_IFRAME_Height + "px";
		        }
		        return oWin.document.getElementById("ID_QQLOVE_WAIT_IFRAME");
	        }
	        else return null;            
        }
        
        function PageMaskCreate(oWin)
        {
	        if(oWin && oWin.document)
	        {
		        if (!oWin.document.getElementById("ID_QQLOVE_WAIT_BACKGND"))
		        {
			        var ebg = DivCreate(oWin, oWin.document.body, "ID_QQLOVE_WAIT_BACKGND", 65529, 0, 0, "100%", "100%", "none");
			        ebg.style.backgroundColor = "#000";
			        ebg.style.opacity = 0.3;
			        ebg.style.filter = "alpha(opacity=30)";
		        }
		        return oWin.document.getElementById("ID_QQLOVE_WAIT_BACKGND");
	        }
	        else return null;
        }
        
        //创建遮罩层
        function DivCreate(oWin, oParent, sID, zIndex, iLeft, iTop, sWidth, sHeight, sDisplay)
        {
	        if (!oWin.document.getElementById(sID))
	        {
		        var e = oWin.document.createElement("DIV");
		        e.id = sID;
		        
		        e.style.position = "absolute";
		        e.style.zIndex = zIndex;
		        e.style.left = iLeft;
		        e.style.top = iTop;
		        e.style.width = sWidth;
		        e.style.height = sHeight;
		        e.style.display = sDisplay;
		        try{ oParent && oParent.appendChild(e); } catch(e) { }
		        return e;
	        }
	        return oWin.document.getElementById(sID);
        }
        
/*======================== 遮罩层长宽 =============================*/

        //获取遮罩层宽度
        function get_Width()
        {
            var scrollWidth = Math.max(window.document.documentElement.scrollWidth,window.document.body.scrollWidth);
            var offsetWidth = Math.max(window.document.documentElement.offsetWidth,window.document.body.offsetWidth);
            var clientWidth = Math.max(window.document.documentElement.clientWidth,window.document.body.clientWidth);

            return  Math.max(Math.max(Math.max(scrollWidth,offsetWidth),clientWidth),(Popup_IFRAME_Width + get_MarginLeft()));
        }
        
        //获取遮罩层高度
        function get_Height()
        {
            var scrollHeight = Math.max(window.document.documentElement.scrollHeight,window.document.body.scrollHeight);
            var offsetHeight = Math.max(window.document.documentElement.offsetHeight,window.document.body.offsetHeight);
            var clientHeight = Math.max(window.document.documentElement.clientHeight,window.document.body.clientHeight);

            return Math.max(Math.max(Math.max(scrollHeight,offsetHeight),clientHeight),(Popup_IFRAME_Height + get_MarginTop()));
        }   
        
/*======================= 与高相关 ==============================*/

        //获取Div上边距
        function get_MarginTop()
        {
            return get_scrollTop() + get_CliectTopLong();
        }
        
        //获取滚动高度
        function get_scrollTop()
        {
            return Math.max(window.document.documentElement.scrollTop,window.document.body.scrollTop);
        }     
        
        //获取浏览器显示上边距
        function get_CliectTopLong()
        {
            return Math.max((get_CliectHeight() - Popup_IFRAME_Height)/2,0);
        }

        //返回浏览器的高度  OK
        function get_CliectHeight()
        {
            if(navigator.userAgent.indexOf("MSIE")>0) 
            { 
                if(window.document.documentElement.clientHeight==0)             //无标准
                {
                    return window.document.body.clientHeight;
                }
                else        //有标准
                { 
                    return window.document.documentElement.clientHeight;
                }
            } 
            else if(navigator.userAgent.indexOf("Firefox")>0)
            {
                if(window.document.documentElement.scrollHeight==window.document.body.scrollHeight)   //无标准
                {
                    return window.document.body.clientHeight;
                }
                else        //有标准
                {
                    return window.document.documentElement.clientHeight;
                }
            } 
            else if(navigator.userAgent.indexOf("Safari")>0) 
            { 
                if(window.document.documentElement.clientWidth==window.document.body.clientWidth)             //无标准
                {
                    return window.document.body.clientHeight;
                }
                else        //有标准
                {
                    return window.document.documentElement.clientHeight;
                }                 
            } 
            else
            {
                return Math.max(window.document.documentElement.clientHeight,window.document.body.clientHeight);
            } 
        }

/*========================= 与宽相关 ============================*/
        
        //获取Div左边距
        function get_MarginLeft()
        {
            return get_scrollLeft() + get_CliectLeftLong();
        }
        
        //获取滚动宽度
        function get_scrollLeft()
        {
            return Math.max(window.document.documentElement.scrollLeft,window.document.body.scrollLeft);
        }     
        
        //获取浏览器显示左边距
        function get_CliectLeftLong()
        {
            return Math.max((get_CliectWidth() - Popup_IFRAME_Width)/2,0);
        }        
        
        //返回浏览器的宽度   OK
        function get_CliectWidth()
        {
            if(navigator.userAgent.indexOf("MSIE")>0) 
            { 
                if(window.document.documentElement.clientWidth==0)             //无标准
                {
                    return window.document.body.clientWidth;
                }
                else        //有标准
                {
                    return window.document.documentElement.clientWidth;
                }
            } 
            else if(isFirefox=navigator.userAgent.indexOf("Firefox")>0)
            { 
                if(window.document.documentElement.scrollWidth==window.document.body.scrollWidth)   //无标准
                {
                    return window.document.body.clientWidth;
                }
                else        //有标准
                {
                    return window.document.documentElement.clientWidth;
                }
            } 
            else if(navigator.userAgent.indexOf("Safari")>0) 
            { 
                if(window.document.documentElement.clientWidth==window.document.body.clientWidth)             //无标准
                {
                    return window.document.body.clientWidth;
                }
                else        //有标准
                {
                    return window.document.documentElement.clientWidth;
                }                 
            } 
            else
            {
                return Math.max(window.document.documentElement.clientWidth,window.document.body.clientWidth);
            }
        }

    //显示提示框
        function ShowMess(PageTitle,content,showclose, iWidth, iHeight)
        {
                    iWidth = typeof(iWidth) == "number" ? parseInt((iWidth + 10),[10]) : 400; 
                    iHeight = typeof(iHeight) == "number" ? iHeight : 400; 
                    PageTitle = typeof(PageTitle)=="string" ? PageTitle : "";
                    sUrl = typeof(sUrl)=="string" ? sUrl : "";  
                    Popup_IFRAME_Width = iWidth;
                    Popup_IFRAME_Height = iHeight;     
                          
                    Popup_Veil_fn();
                    PageMaskShow(window);
                    
                    var e = document.getElementById("ID_QQLOVE_WAIT_IFRAME");
                    
                    var Popup_Tb_Html="";
		            Popup_Tb_Html +='<div style="width:100%; background-color: #5bc23c;line-height :30px; height:30px;">';
		            Popup_Tb_Html +='<a style ="font-size :20px; color: #ffff66; float:left; margin-left :12px;">' + PageTitle + '</a></div>';
        		    
        		    if(showclose)
        		        Popup_Tb_Html +='<a style=" font-size :13px; color: #ffff66; float:right;margin-right :12px;" href="javascript:FloatClose();">关闭</a></div>';
        		    
		            Popup_Tb_Html +='<div style="text-align:center;"><div style="width:' + iWidth + 'px;height:5px;background-color:#ffffff;"></div>';
		            Popup_Tb_Html +='<div style ="width:' + parseInt((iWidth-10),[10]) + 'px;height:' + parseInt((iHeight - 40),[10]) + 'px;margin:0px auto;">';
		            Popup_Tb_Html+=content;
		            Popup_Tb_Html +='</div>';
		            Popup_Tb_Html +='<div style="width:' + iWidth + 'px;height:5px;background-color:#ffffff;"></div>';		
		            Popup_Tb_Html +='</div>';

                    e.innerHTML = Popup_Tb_Html;
        }