﻿// JScript 文件

    function GetH(){
            if (window.innerHeight && window.scrollMaxY) {
                yScroll = window.innerHeight + window.scrollMaxY;
            } else if (document.body.scrollHeight > document.body.offsetHeight){
                yScroll = document.body.scrollHeight;
            } else {yScroll = document.body.offsetHeight;}
            return yScroll;
    }
    function PW(el){
            if(!document.getElementById(el)){return false;}
            if(!document.createElement){return false;}
            CPW(el);
            if(HasSlt()){CIFR();}
    }
    
    function CPW(el){
            el= document.getElementById(el);      
            el.className = "popupdiv";
            el.style.marginLeft = "-" + el.clientWidth/2 + "px";
            pwb = document.createElement('div');
            pwb.setAttribute('id','popupbg');
            ph =el.clientHeight;
            sh = (window.innerHeight) ? window.innerHeight : (document.documentElement && document.documentElement.clientHeight) ? document.documentElement.clientHeight : document.body.offsetHeight;
            bh = GetH();
            if(ph>bh){
                el.style.marginTop = "-180px";
                pwb.style.height = ph+180+"px";
            }else{
                if(ph>sh){
                    pwb.style.height = bh>ph?bh+'px':ph+'px';
                    el.style.marginTop = '-180px';
                }else{      
                    el.style.marginTop = "-" + ph/2 + 'px';
                    pwb.style.height = sh>bh?sh+'px':bh+'px';
                }  
            }
            return document.body.appendChild(pwb);
    };
    
    function CIFR(){
            if(!document.createElement("iframe")){return false;};
            ifr = document.createElement("iframe");
            ifr.setAttribute("id","divshim");
            ifr.setAttribute("src","javascript:void(0);");
            ifr.setAttribute("scrolling","no");
            ifr.setAttribute("frameborder","0");
            ifr.setAttribute("allowtransparency","true");
            InsertAfter(ifr,pwb);
            ifr.className = "popupifra";
            ifr.style.height = pwb.style.height;
            ifr.style.width = pwb.style.width;      
    };
    
    function InsertAfter(nEl,tEl) {
          var p = tEl.parentNode;if (p.lastChild == tEl) {p.appendChild(nEl);
          } else {p.insertBefore(nEl,tEl.nextSibling); }
    };
    
    function HasSlt(){
            var a = document.getElementsByTagName('*');
            var hasSlt = false;
            for(var i=a.length-1;i>=0;i--){
                if(a[i].nodeName == 'SELECT'){hasSlt = true;break;}
            }
            return hasSlt;
    }
    
    function Attr(el,name,value){
            if(!name || name.constructor != String){return '';}
            name = {'for':'htmlFor','class':'className'}[name] || name;
            if(typeof value != 'undefined'){
                el[name] = value;
                if(el.setAttribute){el.setAttribute(name,value);}
                return el[name] || el.getAttribute(name) || '';
            }
     }
     
     function CW(el){
            pwb.className = "hidden";
            document.getElementById(el).className = "hidden";  
            if(HasSlt()){ifr.className="hidden"}
    }
           
    function POPUP()
    {
        this.getH = GetH;
        this.pw = PW;
        this.cpw = CPW;
        this.cifr = CIFR;
        this.insertAfter = InsertAfter;        
        this.hasSlt = HasSlt;        
        this.attr = Attr;        
        this.cw = CW;
    }

    function addLoadEvent(func){
        var oldonload = window.onload;
        if(typeof window.onload != 'function'){
            window.onload = func;}
        else{
            window.onload = function(){oldonload();func();}
        }
    }

    var lPopup = new POPUP();
    
    addLoadEvent(lPopup.getH);