﻿
function tips_pop() {
    if (getCookie("pop") == "close") {
        return;
    }
    var MsgPop = document.getElementById("winpop"); //获取窗口这个对象,即ID为winpop的对象
    var popH = parseInt(MsgPop.style.height); //用parseInt将对象的高度转化为数字,以方便下面比较
    if (popH == 0) {//如果窗口的高度是0
        MsgPop.style.display = "block"; //那么将隐藏的窗口显示出来
        show = setInterval("changeH('up')", 2); //开始以每0.002秒调用函数changeH("up"),即每0.002秒向上移动一次
    }
    else {//否则
        hide = setInterval("changeH('down')", 2); //开始以每0.002秒调用函数changeH("down"),即每0.002秒向下移动一次
    }
}
function changeH(str) {
    var MsgPop = document.getElementById("winpop");
    var popH = parseInt(MsgPop.style.height);
    if (str == "up") {//如果这个参数是UP
        if (popH <= 100) {//如果转化为数值的高度小于等于100
            MsgPop.style.height = (popH + 4).toString() + "px"; //高度增加4个象素
        }
        else {
            clearInterval(show); //否则就取消这个函数调用,意思就是如果高度超过100象度了,就不再增长了
        }
    }
    if (str == "down") {
        if (popH >= 4) {//如果这个参数是down
            MsgPop.style.height = (popH - 4).toString() + "px"; //那么窗口的高度减少4个象素
        }
        else {//否则
            clearInterval(hide); //否则就取消这个函数调用,意思就是如果高度小于4个象度的时候,就不再减了
            MsgPop.style.display = "none"; //因为窗口有边框,所以还是可以看见1~2象素没缩进去,这时候就把DIV隐藏掉
        }
    }
}
window.onload = function() {//加载
    document.getElementById('winpop').style.height = '0px'; //我不知道为什么要初始化这个高度,CSS里不是已经初始化了吗,知道的告诉我一下
    setTimeout("tips_pop()", 800); //3秒后调用tips_pop()这个函数
}
$(window).scroll(function() {
    var w, h, de;
    de = document.documentElement;
    w = self.innerWidth || (de && de.clientWidth) || document.body.clientWidth;
    h = self.innerHeight || (de && de.clientHeight) || document.body.clientHeight;
    var diagtop = h - $("#winpop").height() + eval($(document).scrollTop());
    $("#winpop").css({ "top": diagtop, "right": 0 });
});

function closeCookie() {
    tips_pop();
    setCookie("pop", "close", "h1");
}

function setCookie(name, value, time) {
    var strsec = getsec(time);
    var exp = new Date();
    exp.setTime(exp.getTime() + strsec * 1);
    document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
}

function getsec(str) {
    var str1 = str.substring(1, str.length) * 1;
    var str2 = str.substring(0, 1);
    if (str2 == "s") {
        return str1 * 1000;
    } else if (str2 == "h") {
        return str1 * 60 * 60 * 1000;
    } else if (str2 == "d") {
        return str1 * 24 * 60 * 60 * 1000;
    }
}







function getCookie(c_name) {
    if (document.cookie.length > 0) {
        c_start = document.cookie.indexOf(c_name + "=")
        if (c_start != -1) {
            c_start = c_start + c_name.length + 1;
            c_end = document.cookie.indexOf(";", c_start);
            if (c_end == -1) {
                c_end = document.cookie.length;
            }
            return unescape(document.cookie.substring(c_start, c_end));
        }
    }
    return null
}
