﻿function getPassportHost() {
    var hostname = location.hostname;
    var suffix = hostname.substring(hostname.lastIndexOf("."));
    return 'http://passport.cnblogs' + suffix;
}

function login() {
    location.href = getPassportHost() + "/login.aspx?ReturnUrl=" + location.href;
    return false;
}

function login2(anchor) {
    var url = encodeURIComponent(location.href + "#" + anchor);
    location.href = getPassportHost() + "/login.aspx?ReturnUrl=" + url;
    return false;
}

function register() {
    location.href = getPassportHost() + "/register.aspx?ReturnUrl=" + location.href;
    return false;
}

function logout() {
    if (confirm('确定要退出吗?')) {
        location.href = getPassportHost() + "/logout.aspx?ReturnUrl=" + location.href;
    }
    return false;
}

var ajaxRequest = {};
ajaxRequest.type = 'post';
ajaxRequest.dataType = 'json';
ajaxRequest.contentType = 'application/json; charset=utf8';

function GetUserInfo() {
    $.ajax({
        url: '/service/UserService.asmx/GetUserInfo',
        data: '{}',
        type: 'post',
        dataType: 'json',
        contentType: 'application/json; charset=utf-8',
        success: function (data) {
            $("#login_area").html(data.d);
        }
    });
}

function GetNewMsgCount() {
    if ($("#lnk_site_msg")) {
        $.ajax({
            url: '/service/UserService.asmx/GetNewMsgCount',
            data: '{}',
            type: 'post',
            dataType: 'json',
            contentType: 'application/json; charset=utf-8',
            cache: false,
            success: function (data) {
                if (data.d > 0) {
                    var span = document.createElement("span");
                    span.style.color = "red";
                    span.innerHTML = "(" + data.d + ")";
                    $("#lnk_site_msg").append(span);
                }
            }
        });
    }
}

if (typeof (jQuery) != 'undefined') {
    $(function () {
        GetNewMsgCount();
    });
}
