﻿// JScript 文件
function MeihuaPop()
{
    var show = getCookie('meihuaPop');
    if(show==null||show=='')
    {
        var popObj = document.getElementById('meihuaPop');
        rect = SetCenter();
//        popObj.style.pixelTop = rect.Height/2 - popObj.offsetHeight/2;
//        popObj.style.pixelLeft = rect.Width/2 - popObj.offsetWidth/2 + 50;

        popObj.style.pixelTop = rect.Height/2 - 140;
        popObj.style.pixelLeft = rect.Width/2 - 220;
        popObj.style.position = 'absolute';
        popObj.style.zIndex = '1';
        popObj.style.display = 'block';
    }
}

function MeihuaPopClose()
{
    var cbObj = document.getElementById('showItID');
    
    if(cbObj.checked)
    {
        setCookie('meihuaPop','1');
    }
    
    var popObj = document.getElementById('meihuaPop');
    popObj.style.display = 'none';
}

//Cookies 操作
//写入
function setCookie(name,value)
{
    var nextyear = new Date();  //此 cookie 将被保存 一年
    nextyear.setFullYear(nextyear.getFullYear() + 1); 
    var expireDate = nextyear.toGMTString();
    document.cookie = name + "=" + escape(value) + ";expires=" + expireDate;
}

//读取
function getCookie(name)
{
    var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
    if(arr != null) return unescape(arr[2]); return null;
}

//删除
function delCookie(name)
{
  var exp = new Date();
  exp.setTime(exp.getTime() - 1);
  var cval = getCookie(name);
  if(cval!=null) document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
}

function SetCenter()
{
    var scrollX=0,scrollY=0,width=0,height=0,contentWidth=0,contentHeight=0;
    if(typeof(window.pageXOffset)=='number')
    {
        scrollX=window.pageXOffset;
        scrollY=window.pageYOffset;
    }
    else if(document.body&&(document.body.scrollLeft||document.body.scrollTop))
    {
        scrollX=document.body.scrollLeft;
        scrollY=document.body.scrollTop;
    }
    else if(document.documentElement&&(document.documentElement.scrollLeft||document.documentElement.scrollTop))
    {
        scrollX=document.documentElement.scrollLeft;
        scrollY=document.documentElement.scrollTop;
    }
    if(typeof(window.innerWidth)=='number')
    {
        width=window.innerWidth;
        height=window.innerHeight;
    }
    else if(document.documentElement&&(document.documentElement.clientWidth||document.documentElement.clientHeight))
    {
        width=document.documentElement.clientWidth;
        height=document.documentElement.clientHeight;
    }
    else if(document.body&&(document.body.clientWidth||document.body.clientHeight))
    {
        width=document.body.clientWidth;
        height=document.body.clientHeight;
    }
    if(document.documentElement&&(document.documentElement.scrollHeight||document.documentElement.offsetHeight))
    {
        if(document.documentElement.scrollHeight>document.documentElement.offsetHeight)
        {
            contentWidth=document.documentElement.scrollWidth;
            contentHeight=document.documentElement.scrollHeight;
        }
        else
        {
            contentWidth=document.documentElement.offsetWidth;
            contentHeight=document.documentElement.offsetHeight;
        }
    }
    else if(document.body&&(document.body.scrollHeight||document.body.offsetHeight))
    {
        if(document.body.scrollHeight>document.body.offsetHeight)
        {
            contentWidth=document.body.scrollWidth;
            contentHeight=document.body.scrollHeight;
        }
        else
        {
            contentWidth=document.body.offsetWidth;
            contentHeight=document.body.offsetHeight;
        }
    }
    else
    {
        contentWidth=width;
        contentHeight=height;
    }
    if(height>contentHeight)
        height=contentHeight;
    if(width>contentWidth)
        width=contentWidth;
        
    var rect = new Object();
    rect.ScrollX = scrollX;
    rect.ScrollY = scrollY;
    rect.Width = width;
    rect.Height = height;
    rect.ContentWidth = contentWidth;
    rect.ContentHeight = contentHeight;
    return rect;
}
