﻿/**************************************************
 * 弹出层
 * 2009.8.13
 * creat by zhengchong
 **************************************************/
var swin={
    width:350,
    height:250,
    el:'',
    okClick:'',
    title:'提示',
    okText:'确定',
    cleText:'关闭',
    delok:false,
    aType:0,   
    msg:'',  
    isHid:false,
    hTime:3000,
    //创建遮罩层
    _creatMask : function(mType){
		var sWidth,sHeight;
		sWidth=this._windowWidth();
		sHeight=this._windowHeight();
        if (window.ActiveXObject){
            sHeight=sHeight;
        } 
		//创建遮罩背景
		var maskObj = document.createElement("div");
		maskObj.setAttribute('id','maskDiv'+mType);
		maskObj.style.position = "absolute";
		maskObj.style.top = "0";
		maskObj.style.left = "0";
		maskObj.style.background = "#777";
		maskObj.style.filter = "Alpha(opacity=30);";
		maskObj.style.opacity = "0.3";
		maskObj.style.width = "100%";
		maskObj.style.height = sHeight + "px";
		maskObj.style.zIndex = "10000";
		maskObj.innerHTML = '<iframe id="ifrwin" border="0" frameborder="none" style="opacity:0; border:0px;filter:Alpha(opacity=0);  width:100%; height: 100%; "></iframe>';
		document.body.appendChild(maskObj);
//		var maskifr = document.createElement("iframe");
//		maskifr.setAttribute("id",'ifr'+mType);
//		maskifr.style.position = "absolute";
//		maskifr.style.top = "0";
//		maskifr.style.left = "0";	
//		maskifr.style.filter = "Alpha(opacity=0);";
//		maskifr.style.opacity = "0";
//		maskifr.style.width = sWidth-15 + "px";
//		maskifr.style.height = "100%"
//		maskifr.style.zIndex = "9999";	
//		document.body.appendChild(maskifr);		
    },
    //创建弹出div
    show : function(){
        this._creatMask('win');
        var _this=this;
        var iHtml=document.getElementById(_this.el);
        var c_height = _this.height + 'px';
        var c_width = _this.width + 'px';
        var vheight=(parseInt(c_height)-120);
        var vwidth=(parseInt(c_height)-30);
        if(vheight)
		var q_heihgt = parseInt(c_height) + 12 + 'px';
		var w_height = parseInt(c_height) + 76 + 'px';
		var e_height = parseInt(c_height) + 78 + 'px';
		var r_height = parseInt(c_height) + 80 + 'px';
		var q_width = parseInt(c_width) + 12 + 'px';
		var w_width = parseInt(c_width) + 24 + 'px';
		var e_width = parseInt(c_width) + 26 + 'px';
		var r_width = parseInt(c_width) + 28 + 'px';
		
        var iWidth=this._pageWidth();
        var iHeight=this._pageHeight();
		var ileft = this._leftPosition();
		var itop = this._topPosition();     
        var wWidth=parseInt(c_width) + 28;
        var wHeight=parseInt(c_height) + 80;
                
		var toppos = (itop + (iHeight / 2) - (wHeight / 2)) + 50 + 'px';
		var leftpos = ileft + (iWidth / 2) - (wWidth / 2) + 'px';
		
		var windiv=document.createElement("div");
		windiv.id="windiv";
		windiv.style.display="";
		windiv.style.height = r_height;
		windiv.style.top = toppos;
		windiv.style.width = '100%';
		windiv.style.zIndex = 10002;
		windiv.style.position = 'absolute';
		var il ="";
        //il=il+"<div style='height:"+r_height+";top:"+toppos+";width:100%;z-index:10002;position:absolute;'>";
        il=il+iHtml.innerHTML;
        //il=il+" </div>";
        windiv.innerHTML=il;
        document.body.appendChild(windiv);
        document.documentElement.style.overflow="hidden";
        document.getElementById(this.el).innerHTML = '';
    },
    //关闭弹出层
    close : function(){
    
        document.documentElement.style.overflow="auto";  
        document.getElementById(this.el).innerHTML = document.getElementById("windiv").innerHTML;
        
        var maskObj=document.getElementById("maskDivwin");
        var winObj=document.getElementById("windiv");
        var ifrObj=document.getElementById("ifrwin");
        if(maskObj){
            document.body.removeChild(maskObj);
        }
        if(winObj){
            document.body.removeChild(winObj);
        }   
//        if(ifrObj){
//            document.body.removeChild(ifrObj);
//        }  
    },
    _windowWidth : function(){
        var rootEl = document.compatMode == 'CSS1Compat' ? document.documentElement: document.body;
        var sWidth = Math.max(rootEl.scrollWidth,rootEl.clientWidth);
        return sWidth;
    },
   _windowHeight : function(){
        var rootEl = document.compatMode == 'CSS1Compat' ? document.documentElement: document.body;
        var sHeight = Math.max(rootEl.scrollHeight,rootEl.clientHeight);
        return sHeight;
    },  
    //计算当前窗口的宽度
    _pageWidth : function() {
        return window.innerWidth != null ? window.innerWidth : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;
    },
    //计算当前窗口的高度
    _pageHeight :function() {
        return window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;
    },
    //计算当前窗口的上边滚动条
    _topPosition : function(){
		return typeof window.pageYOffset != 'undefined' ? window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;
    },
    //计算当前窗口的左边滚动条
    _leftPosition : function(){
		return typeof window.pageXOffset != 'undefined' ? window.pageXOffset : document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ? document.body.scrollLeft : 0;
    }
}
