var loginStatus = {loginip : '',lastlogin:''};
loginStatus.refreshStatus = function()
{
    if (loginStatus.getCookie('M_loginId') != null)
    {
        var status = document.getElementById("userStatus");
        if (status != null)
        {
            document.body.removeChild(status);
        }
        var userStatus = document.createElement('script');
        userStatus.id = 'userStatus';
        userStatus.type = 'text/javascript';
        userStatus.src = 'http://members.nubb.com/ui/statusRefresh.jsp';
        userStatus.charset = 'utf-8';
        userStatus.onload = userStatus.onreadystatechange = function()
        {
            if (!this.readyState || this.readyState == "loaded" || this.readyState == "complete")
            {
                loginStatus.getStatus();
            }
        }
        document.body.appendChild(userStatus);
    }
}
loginStatus.getStatus = function()
{
    var getStatus = document.getElementById("getUserStatus");
    if (getStatus != null)
    {
        if (typeof(getStatusResult) != 'undefined')
        {
            getStatusJSON = eval('(' + getStatusResult + ')');
            if (getStatusJSON.status == 0)
            {
                getStatus.innerHTML = "未知";
            } else
            {
                getStatus.innerHTML = "<font color=\"red\">在线</font>";
            }
        } else
        {
            getStatus.innerHTML = "未知";
        }
    }
    //message.js测试用
    //    if (document.getElementById("tipDetail") != null)
    //    {
    //        if (typeof(getStatusResult) != 'undefined')
    //        {
    //            getStatusJSON = eval('(' + getStatusResult + ')');
    //            if (getStatusJSON.status == 0)
    //            {
    //                document.getElementById("tipDetail").innerHTML = "未知";
    //            } else
    //            {
    //                if (loginStatus.lastlogin != getStatusJSON.lastlogin)
    //                {
    //                    if (tip.tipCount >= 10)
    //                    {
    //                        return false;
    //                    }
    //                    tip.tipCount++;
    //                } else
    //                {
    //
    //                }
    //                var obj = document.getElementById("tip");
    //                if (parseInt(obj.style.height) == 0)
    //                {
    //                    obj.style.display = "block";
    //                    tip.handle = setInterval("tip.changeH('up')", 2);
    //                }
    //                document.getElementById("tipCount").innerHTML = tip.tipCount;
    //                document.getElementById("tipDetail").innerHTML = document.getElementById("tipDetail").innerHTML + "<br>" + getStatusJSON.lastlogin;
    //            }
    //        } else
    //        {
    //            document.getElementById("tipDetail").innerHTML = "未知";
    //        }
    //    } else
    //    {
    ////        alert("no tipDetail element");
    //    }
}
loginStatus.getCookie = function(name)
{
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;

    while (i < clen)
    {
        var j = i + alen;
        if (document.cookie.substring(i, j) == arg)
        {
            var endstr = document.cookie.indexOf(";", j);
            if (endstr == -1)    endstr = document.cookie.length;
            try
            {
                var r = decodeURI(document.cookie.substring(j, endstr));
            }
            catch(e)
            {
                var r = document.cookie.substring(j, endstr);
            }
            return r;
        }
        i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0) break;
    }
    return null;
}
window.setInterval("loginStatus.refreshStatus()", 30000);
if (document.all)
{
    window.attachEvent('onload', loginStatus.refreshStatus);//对于IE
}
else
{
    window.addEventListener('load', loginStatus.refreshStatus, false);//对于FireFox
}