var jq = jQuery.noConflict();
//光标聚焦时显示空，如果不输入任何值，光标离开时为默认值
function OnInput(txt) {
    if (txt.value == "输入博客名称或Email地址") {
        txt.value ="";
    }
}
function OnOut(txt) {
    if ( txt.value == "") {
     txt.value = "输入博客名称或Email地址";
    }
}
//加载用户的头像
function BindPic(userID) {
    jq.ajax({
        type: 'post',
        url: 'Dd_image_deal',
        data: { UserID: userID, time: new Date().getTime() },
        success: function (data) {
            if (data != null) {
                jq("#'pic" + userID).attr("background-image", "url(" + data + ")");
            }
            else {
                jq("#'pic" + userID).attr("background-image", "url('/images/avatar_64_64_$1095.png')");
            }
        },
        error: function () {

        }
    });
}
//关注 与 取消关注

jq(document).ready(function () {

    jq(".cancel-follow").live("click", function () {
        jq(this).css("display", "none");
        jq(this).prev().css("display", "block");
        var ID = jq(this).parent().parent().attr("id");
        jq.ajax({
            type: "post",
            url: '/ashx/Dd_attention_manage.ashx',
            data: { AttentionByuserID: ID, state: "cancel_follow", time: new Date().getTime() },
            success: function (data) {
                if (data != 0) {

                }
                else {
                    alert("取消关注失败！");
                }
            },
            error: function () {
                alert("取消关注失败！");
            }
        });
    });

    jq(".do-follow").live("click", function () {
        jq(this).parent().css("display", "none");
        jq(this).parent().next().css("display", "");
        var ID = jq(this).parent().parent().parent().attr("id");
        jq.ajax({
            type: "post",
            url: '/ashx/Dd_attention_manage.ashx',
            data: { AttentionByuserID: ID, state: "do_follow", time: new Date().getTime() },
            success: function (data) {
                if (data != 0) 
                {

                }
                else 
                {
                    alert("关注失败！");
                }
            },
            error: function () {
                alert("关注失败！");
            }
        });

    });

    //根据输入的用户名进行查询用户
    jq("#search-blog-button").click(function () {
        var checkname = jq("#blog-search-input").val();
        var test = "";
        if (test != "isornotclick") {
            jq("#search-blog-button").append("<p style='display:none'>isornotclick</p>");
            jq.ajax({
                type: "post",
                url: '/ashx/Dd_attention_manage.ashx',
                data: { SeachName: checkname, state: "SeachUser", time: new Date().getTime() },
                success: function (data) {
                    if (data != null) {
                        jq(".one").hide();
                        jq(".two").show();
                        jq(".clearfixother").html("");
                        BindFindUser(data);
                    }
                },
                error: function () {

                }
            });
        }
    });

    function BindFindUser(data) {
        var json = eval(data);
        for (var index in json) {
            jq(".clearfixother").append('<li id ="' + json[index].id + '" class="clearfix" url="javascript:void(0)">'
                      + '<span class="user-info">'
                      + '<a style="background-image:url(' + json[index].url + ');" class="f-avatar" href="javascript:void(0)">'
                      + json[index].username
                      + ' </a> '
                      + '<a class="f-name" href="javascript:void(0)">'
                      + json[index].username
                      + '</a> '
                      + '</span>'
                      + '<span class="action">'
                      + '<a style="display: block;" class="do-follow b-button icon-add">'
                      + '<span class="do-follow">关注</span>'
                      + '</a>'
                      + '<a class="cancel-follow" style="display: none;">取消关注</a> '
                      + '</span>'
                     + ' </li>'
                     );
        }
    }
});
