﻿var PopWin=
{
    width:350,
    height:250,
    title:'',//标题名称
    el:'',//加载的元素ID
    html:'',
    type:0, //1加载层,2提示成功,3警告,9未知异常
    msg:'',  
    _keep:null,
    _html:'',
    
    _iframe:null,
    _divTop:null,
    _divIn:null,
    _divBody:null,
    _target:null,
    _body:document.body,
    _overflow:"",
    _paddingRight:"",
    show:function()
    {
        this._body=document.body; 
        if(this.el=="" && this.type==0){alert("未指定要加载的元素ID！");}
        if(this.type>0){this.width=490;this.height=100;}
        this._overflow=document.documentElement.style.overflow;
        this._paddingRight=16;//document.documentElement.style.paddingRight;
        this._createObj();
        this._addTaget();
        var wh=this._getWH();
        this._setStyle(wh);
    },
    hide:function()
    {
       if(this.el=="" && this.type==0){alert("未指定要加载过的元素ID！");}
       this._getAllObj();
       this._moveTaget();
       this._iframe.style.display="none";  
       this._divTop.style.display="none";
       this._divIn.style.display="none";
       if(this._target!=null){this._target.style.display="none";}
       this.title="";
       this.width=0;
       this.height=0;
       this.type=0;
       this._target=null;
       this.el="";
       document.documentElement.style.overflow=this._overflow;
       document.documentElement.style.paddingRight =0;//this._paddingRight;
    },
    resize:function()
    {
        var wh=this._getWH();
        this._setStyle(wh,true,true);
    },
    _getAllObj:function()
    {
        var tName=this.el;
        var ifra=document.getElementById("__ifa_lock");
        if(ifra==null || ifra+""=="undefined"){return;}
        var div=document.getElementById("__dv_lock");
        if(div==null || div+""=="undefined")return;
        var divIn=document.getElementById("__dv_lock_in");
        if(divIn==null || divIn+""=="undefined")return;
        this._iframe=ifra;
        this._divTop=div;
        this._divIn=divIn;
        if(tName!=null && tName+""!="undefined")this._target=document.getElementById(tName);
    },
    _getWH:function()
    {
        var tName=this.el;
        var ret=[];ret[0]=[];ret[1]=[];ret[2]=[];ret[3]=[];
        var bdy=document.body;
        ret[2][0]=window.innerWidtht != null? window.innerWidtht : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body != null? document.body.clientWidth : null;
        ret[2][1]=window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;
        ret[0][0]=bdy.clientWidth;
        ret[0][1]=bdy.clientHeight;
        var bdyOffH=bdy.offsetHeight;
        var bdyOffW=bdy.offsetWidth;
        var bdyScrW=bdy.scrollWidth;
        var bdyScrH=bdy.scrollHeight;
        ret[3][1]=typeof window.pageYOffset != 'undefined' ? window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;
        ret[3][0]=typeof window.pageXOffset != 'undefined' ? window.pageXOffset : document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ? document.body.scrollLeft : 0;
        
        if( ret[2][0]>ret[0][0])ret[0][0]= ret[2][0];
        if( ret[2][1]>ret[0][1])ret[0][1]= ret[2][1];
        
        if(bdyOffW>ret[0][0])ret[0][0]=bdyOffW;
        if(bdyOffH>ret[0][1])ret[0][1]=bdyOffH;
        if(bdyScrW>ret[0][0])ret[0][0]=bdyScrW;
        if(bdyScrH>ret[0][1])ret[0][1]=bdyScrH;
        ret[0][1]+=ret[3][1];
        
        if(this.type==0){
            var obj=document.getElementById(tName);
            ret[1][0]=obj.clientWidth;
            ret[1][1]=obj.clientHeight;
            var objOffH=obj.offsetHeight;
            var objOffW=obj.offsetWidth;
            var objScrW=obj.scrollWidth; 
            var objScrH=obj.scrollHeight;
            if(objOffW>ret[1][0])ret[1][0]=objOffW;
            if(objOffH>ret[1][1])ret[1][1]=objOffH;
            if(objScrW>ret[1][0])ret[1][0]=objScrW;
            if(objScrH>ret[1][1])ret[1][1]=objScrH;
            ret[1][0]+=20;
            ret[1][1]+=35;
        }
        else{ret[1][0]=0;ret[1][0]=0;}
        if(this.width==0)this.width=ret[1][0];else ret[1][0]=this.width+20;
        if(this.height==0)this.height=ret[1][1];else ret[1][1]=this.height+50;
        return ret;
    },
    _getPos:function(arrWH)
    {
        var ret=[];
        ret[0]=arrWH[3][0]+(arrWH[2][0]-arrWH[1][0])/2;
        ret[1]=arrWH[3][1]+(arrWH[2][1]-arrWH[1][1])/2;
        return ret;
    },
    _createObj:function()
    {
        var div=document.getElementById("__dv_lock");
        if(div==null || div+""=="undefined"){
            div=document.createElement("div");
            div.id="__dv_lock";
            div.style.display="none";
            this._body.appendChild(div);
        }
        var iframe=document.getElementById("__ifa_lock");
        if(iframe==null || iframe+""=="undefined"){
            iframe=document.createElement("iframe");
            iframe.id="__ifa_lock";
            iframe.style.display="none";
            div.appendChild(iframe);
        }
        var divIn=document.getElementById("__dv_lock_in");
        if(divIn==null || divIn+""=="undefined"){
            divIn=document.createElement("div");
            divIn.id="__dv_lock_in";
            divIn.style.display="none";
            this._body.appendChild(divIn);
        }
        this._iframe=document.getElementById("__ifa_lock");
        this._divTop=document.getElementById("__dv_lock");
        this._divIn=document.getElementById("__dv_lock_in");
        return;
    },
    _setStyle:function(wh,notop,noleft)
    {
        var div=this._divTop;
        var divIn=this._divIn;
        var iframe=this._iframe;
        var arrPos=this._getPos(wh);
        if(iframe!=null)
        {
        iframe.style.filter = "Alpha(opacity=0)";
        iframe.style.opacity = "0";
        iframe.style.width ="100%";
        iframe.style.height = wh[0][1] + "px";
        iframe.style.zIndex = "10000";
        iframe.style.display="block";
        iframe.frameBorder="0";
        iframe.scrolling="no";
        
        div.style.position = "absolute";
        div.style.top = "0px";
        div.style.left = "0px";
        div.style.background = "#777";
        div.style.filter = "Alpha(opacity=80)";
        div.style.opacity = "0.3";
        div.style.width ="100%";
        div.style.height = wh[0][1] + "px";
        div.style.zIndex = "10001";
        div.style.display="block";
        
        divIn.style.position="absolute";
        if(!noleft || noleft==undefined){
            divIn.style.left=arrPos[0]+"px";
        }
        if(!notop ||notop==undefined)
        {
            divIn.style.top=arrPos[1]+"px";
        }
        divIn.style.width=wh[1][0]+"px";
        divIn.style.backgroundColor="white";
        
        if(this.type==0){divIn.style.height=wh[1][1]+"px"}else{divIn.style.height=this.height+"px";}
        
        divIn.style.display="block";
        divIn.style.zIndex = "10002";
        
        divIn.style.border="1px solid #6B9BC3";
        divIn.style.overflow="hidden";
        divIn.margin="0px";
        divIn.padding="0px";
        document.documentElement.style.overflow="hidden";
        document.documentElement.style.paddingRight =this._paddingRight;
        }
    },
    _addTaget:function()
    {
        var tName=this.el;
        this._setWinBar();
        if(this.type==0){
            this._divBody=document.getElementById("__dv_lock_bdy");
            this._iframe.style.display="block";
            this._divIn.style.display="block";
            var obj=document.getElementById(tName);
            this._divTop.style.display="block";
            this._divBody.appendChild(obj);
            obj.style.display="block";
            this._target=obj;
        }
    },
    _moveTaget:function()
    {
       var tName=this.el;
        if(this.type==0)
        {
            var obj=document.getElementById(tName);
            this._divIn.appendChild(obj);
            this._target=obj;
        }
    },
    _setWinBar:function()
    {
        var tName=this.el;
        var divIn=this._divIn;
       
        var il="";
        if(this.type==0){
            var divTtl=document.getElementById("__dv_lock_ttl");
            if(divTtl!=null&& divTtl+""!="undefined" )
            {
                document.getElementById("__dv_lock_cap").innerHTML=this.title;
                return;
            }
            il="<div id=\"__dv_lock_ttl\" style=\"padding:0px 5px 0px 5px;background:url(/images/base/map_ttl_bg.gif) repeat-x; line-height: 28px;height:28px; font-size:13px;color:White; font-weight:bold;\">"
               +" <div id=\"__dv_lock_cap\" style=\"float:left;\">"+PopWin.title+"</div>"
               +" <em style=\"float:right;cursor:pointer;\">"
               +"     <img title=\"关闭\" style=\"float:left;vertical-align:middle\" onclick=\"PopWin.hide(PopWin.el);\"alt=\"\" src=\"/images/base/map_close.gif\" />"
               +" </em>"
               +"</div>"
               +"<div id=\"__dv_lock_bdy\"></div>";//style=\"padding:10px;\"
        }
        else if(this.type==1)
        {
            var divMsg=document.getElementById("__dv_lock_msg");
            if(divMsg!=null&& divMsg+""!="undefined" )return;
            il=il+"<div id=\"__dv_lock_msg\" style='border:1px solid #C6C6C6;width:"+ this.width +"px;height:"+this.height+"px;overflow:hidden;background:#ffffff;padding:20px;'>";
            il=il+ '<ul><li>数据处理中...</li></ul>';
            il=il+" </div>";
        }
        else if(this.type>0)
        {
            var icon ='';
            switch(this.type)
            {
                case 2:
                    icon= 'succeed';
                    break;
                case 3:
                    icon= 'warn';
                    break;
                case 9:
                    icon= 'error';
                    break;
            }
            var divMsg=document.getElementById("__dv_lock_msg");
            if(divMsg!=null&& divMsg+""!="undefined" )return;
            il=il+"<div id=\"__dv_lock_msg\" style='border:1px solid #C6C6C6;width:"+ this.width +"px;height:"+this.height+"px;overflow:hidden;background:#ffffff;padding-bottom:20px;'><img src='img/map_close.gif' alt='' style='vertical-align:middle;float:right;cursor:pointer;margin:8px 8px 0px 0px;' title='关闭' onclick='PopWin.hide(PopWin.el);'>";
            il=il+ '<ul style="overflow:hidden;margin:20px 20px 00px 30px;"><li style="float:left;"><img alt="" src="/ibs/images/icon/'+icon+'.gif"/></li><li style="float:left; line-height:43px;margin-left:15px;color:#4D4E50;width:370px;overflow:hidden; " title="'+this.msg+'">'+this.msg + '</li></ul>';
            il=il+" </div>"; 
        }
        divIn.innerHTML=il;
        
    }
}

   
 
/*
显示弹出窗
PopWin.width=500;窗体的宽
PopWin.height=200;窗体的高
PopWin.el='';要加载的元素ID
PopWin.title="";窗体显示的标题名称
PopWin.show();加载窗体

隐藏窗体
PopWin.el=''//要隐藏的元素ID
PopWin.hide();//隐藏窗体
*/