/**
 * 前端窗口类
 * @param   string  foreWinId   前端窗口对象的ID
 */
function ForeWindow(foreWinId)
{
    var self = this;
    var m_isIE = (document.all ? true : false);
    var m_foreWin = $(foreWinId); // 前端窗口对象
    var m_boardWin = null;        // 遮罩窗口对象
    var m_screenWidth = 0;
    var m_screenHeight = 0;
    var m_left = 0;
    var m_top = 0;
    var m_isShow = false;
    var m_Overflow = '';
    
    /**
     * 遮罩窗口的颜色
     */
    this.backColor = '#333333';
    
    /**
     * 遮罩窗口的不透明度
     */
    this.opacity = 55;
    
    /**
     * 自适应浏览器窗口大小
     */
    function autoResize()
    {
        try
        {
			if(!m_isShow) return;
            m_screenWidth = document.documentElement.clientWidth;
            m_screenHeight = document.documentElement.clientHeight;
            m_foreWin.style.position='absolute';
            m_foreWin.style.display = 'block';
            if(m_left != null && m_top != null){
                m_foreWin.style.top = document.documentElement.scrollTop + m_top + 'px';
                m_foreWin.style.left = document.documentElement.scrollLeft + m_left + 'px';
            }else{
                m_foreWin.style.top = document.documentElement.scrollTop + ((m_screenHeight - m_foreWin.offsetHeight)/2) - 55 + 'px';
                m_foreWin.style.left = document.documentElement.scrollLeft + ((m_screenWidth - m_foreWin.offsetWidth)/2) + 'px';
            }
            m_foreWin.style.zIndex = '' + (m_boardWin.style.zIndex + 1);			
            m_boardWin.style.width = m_screenWidth + 'px';
            m_boardWin.style.height = m_screenHeight + 'px';			
            m_boardWin.style.top = document.documentElement.scrollTop + 'px';
            m_boardWin.style.left = document.documentElement.scrollLeft + 'px';
            m_boardWin.style.display = 'block';
        }
        catch(ex){}
    }
        
    /**
     * 显示窗口
     * @param   integer     left    窗口距左端的距离
     * @param   integer     top     窗口距顶端的距离
     */
    this.show = function(left, top)
    {
        try
        {
            if(m_isShow) return;
            m_isShow = true;
            m_left = left;
            m_top = top;
            m_Overflow = document.body.parentNode.style.overflow;
            document.body.parentNode.style.overflow="hidden";
            createBoardWindow();
            autoResize();
            if(m_isIE){ // 添加事件监听
                window.attachEvent('onresize',autoResize);
            }else{
                window.addEventListener('resize',autoResize,false);
            }
        }
        catch(ex){}
    };
    
    /**
     * 隐藏窗口
     */
    this.hide = function()
    {
        try
        {
            m_isShow = false;
            m_foreWin.style.display = 'none';
            m_boardWin.style.display = 'none';
            document.body.parentNode.style.overflow = m_Overflow;
            if(m_isIE){ // 取消事件监听
                window.detachEvent('onresize',autoResize);
            }else{
                window.removeEventListener('resize',autoResize,true);
            }
            document.body.removeChild(m_boardWin);
            m_boardWin = null;
        }
        catch(ex){}
    };
    
    /**
     * 获取DOM对象实例句柄
     */
    function $(id){return document.getElementById(id);}
    
    /**
     * 创建遮罩窗口
     */
    function createBoardWindow()
    {
        try
        {
            m_boardWin = document.createElement('IFRAME');
            m_boardWin.frameBorder=0;
            m_boardWin.allowTransparency=false;
            document.body.appendChild(m_boardWin);
            m_boardWin.style.cssText="position:absolute;left:0px;top:0px;display:none";
            m_boardWin.contentWindow.document.open();
            m_boardWin.contentWindow.document.write('<html><body style="background-color:'+self.backColor+'"></body></html>');
            m_boardWin.contentWindow.document.close();
            m_boardWin.style.filter='alpha(opacity='+self.opacity+')';
            m_boardWin.style.opacity=(self.opacity/100);
            m_boardWin.style.MozOpacity=(self.opacity/100);
			m_boardWin.style.zIndex = 999;
        }
        catch(ex){}
    }
}