﻿
var AIRBUM_WATERMARKT_SEARCH_LOCATION = "输入你感兴趣的地点,例如：北京颐和园";
var AIRBUM_WATERMARKT_SEARCH_TAG = "输入你感兴趣的照片标签,例如：旅游";
var AIRBUM_WATERMARKT_SEARCH_USER = "输入用户名称或者Email地址,例如：张三";
var AIRBUM_WATERMARKT_UPDATE_PHOTO_DESCRIPTION = "照片描述";
var AIRBUM_WATERMARKT_UPDATE_PHOTO_TAGS = "内容标签";
var AIRBUM_WATERMARKT_LOGIN_USERNAME = "注册邮箱/用户名";
var AIRBUM_WATERMARKT_UPLOAD_LOCATION_ADDRESSSEARCH = "输入你感兴趣的地点,例如：北京颐和园";



//关注-基础方法
function FollowUser(taId, callback) {
    $.post('/Ajax.aspx',
                    {
                        Action: "FollowUser",
                        Taid: taId
                    },
                    function (data) {
                        callback(data);
                    });
}

//关注取消-基础方法
function FollowUserCancel(taId, callback) {
    $.post('/Ajax.aspx',
        {
            Action: "FollowUserCancel",
            TaId: taId
        },
        function (data) {
            callback(data);
        });
}


//移除粉丝 - 看自己关注列表
function FollowerRemoveConfirm(taId, objectId, userName,userHead) {
    var str = "<div class=\"pop_sml\">  ";
    str += "        <div class=\"pop_message_ok\">  \r\n";
    str += "            <div>  \r\n";
    str += "                <img class=\"fans_img\" alt=\"\" src=\""+userHead+"\" >确认移除 " + userName + " 吗？  \r\n";
    str += "            </div>  \r\n";
    str += "        </div>  \r\n";
    str += "  \r\n";
    str += "        <div class=\"pop_handle\">  \r\n";
    str += "            <a id=\"lnkOk\" class=\"btn_sml\" href='javascript:void(0);' >确认</a><a class=\"btn_sml_cancel\"  href='javascript:void(0);' onclick='closePopup();'>取消</a>  \r\n";
    str += "  \r\n";
    str += "            <div class=\"clear\"></div>  \r\n";
    str += "        </div>  \r\n";
    str += "    </div>  \r\n";

    dialog("FollowingUserCancelConfirm", [
                { val: "FollowingUserCancelConfirm", text: str, isPanel: true, fadeOut: -1, width: 240 }
            ]);
    $("#lnkOk").click(function () {
        FollowerRemove(taId, objectId);
    });

}

//移除粉丝
function FollowerRemove(taId, objectId) {
    $.post('/Ajax.aspx',
        {
            Action: "FollowerRemove",
            TaId: taId
        },
        function (res) {

            res = eval('(' + res + ')');

            if (res.status == "OK") {
                closePopup();
                $("#FollowerCount").html(parseInt($("#FollowerCount").text()) - 1);
                $(objectId).parent().parent().parent().slideUp(500);
            }
            else {
                var data = eval('(' + res.data + ')');
                var message = data.message;
                dialog(data.message, [
                        { val: "UserLoginNeed", className: "x", title: "请先登录或注册", text: "" },
                        { val: "UserStatusError", className: "x", title: "你的帐户异常", text: "" },
                        { val: "UserNotFound", className: "x", title: "你的帐户异常", text: "" },
                        { val: "ServerException", className: "x", title: "操作失败", text: "" },
                        { val: "FollowingInvalidTargetUserID", className: "x", title: "操作失败", text: "" }
                    ]);
            }

        });
}

 
//关注 全部 注册页
function FollowUserAll() { 
    $(".btn_sml_dark").each(function () {
        FollowUserS5($(this).attr("value"), this);
    }); 
}


//关注  个人首页
function FollowUserS1(taId, objectId) {
    //进入加载关注状态
    //提交数据
    var res = FollowUser(taId, function (res) {

        res = eval('(' + res + ')');

        if (res.status == "OK") {
            //更按键状态
            $(objectId).replaceWith("<a href=\"javascript:void(0);\" onclick='FollowingUserCancelS2(\"" + taId + "\",this);' class=\"btn_light_unfollow\"><span>已关注</span>取消</a>");

        } else {
            var data = eval('(' + res.data + ')');
            var message = data.message;
            dialog(data.message, [
                        { val: "UserLoginNeed", className: "x", title: "请先登录或注册", text: "" },
                        { val: "UserStatusError", className: "x", title: "你的帐户异常", text: "" },
                        { val: "UserNotFound", className: "x", title: "你的帐户异常", text: "" },
                        { val: "ServerException", className: "x", title: "操作失败", text: "" },
                        { val: "FollowingInvalidTargetUserID", className: "x", title: "操作失败", text: "" }
                    ]);
        }

    });

}

//关注 列表
function FollowUserS2(taId, objectId) {
    //进入加载关注状态
    //提交数据
    var res = FollowUser(taId, function (res) {

        res = eval('(' + res + ')');

        if (res.status == "OK") {
            //更按键状态
            $(objectId).replaceWith("<span class=\"sta_followed\">已关注</span>");
        }
        else {
            var data = eval('(' + res.data + ')');
            var message = data.message;
            dialog(data.message, [
                        { val: "UserLoginNeed", className: "x", title: "请先登录或注册", text: "" },
                        { val: "UserStatusError", className: "x", title: "你的帐户异常", text: "" },
                        { val: "UserNotFound", className: "x", title: "你的帐户异常", text: "" },
                        { val: "ServerException", className: "x", title: "操作失败", text: "" },
                        { val: "FollowingInvalidTargetUserID", className: "x", title: "操作失败", text: "" }
                    ]);
        }


    });
}


//关注 (请求关注)
function FollowUserS3(taId, objectId, userName, userHead) {
    var str = "<div class=\"pop_request\">  \r\n";
    str += "    	<div class=\"title_bar\">  \r\n";
    str += "    		<img height=\"50\" width=\"50\" alt=\"User Avatar\" src=\"" + userHead + "\">  \r\n";
    str += "    		<p class=\"quiet\">" + userName + "对自己的照片设置了隐私保护，加关注需要经过TA的同意。简单地写个理由吧。</p>  \r\n";
    str += "    	</div>  \r\n";
    str += "    	<div class=\"request\">  \r\n";    
    str += "        <form id=\"frmFollowingRequest\" accept=\"#\">";
    str += "    		<textarea rows=\"3\" cols=\"30\"  name=\"txtFollowingRequestContent\" id=\"txtFollowingRequestContent\"></textarea>  \r\n";
    str += "        </form>";
    str += "    	</div>  \r\n";
    str += "    	<div class=\"request_handle\">  \r\n";
    str += "            <a class=\"btn_sml_long\"  href='javascript:void(0);' onclick='FollowingRequest(\"" + taId + "\");'>发送请求</a>  \r\n";
    str += "			<a class=\"btn_sml_cancel\" href='javascript:void(0);' onclick='closePopup();'>取消</a>  \r\n";
    str += "            <div class=\"clear\"></div>  \r\n";
    str += "        </div>  \r\n";
    str += "    </div>  \r\n";

    dialog("FollowingRequest", [
                { val: "FollowingRequest", text: str, isPanel: true, fadeOut: -1, width: 360 }
            ]);


    $("#frmFollowingRequest").validate({ 
        errorElement: "span",
        errorClass: "warn",
        errorPlacement: function (error, element) {
            element.closest("#frmFollowingRequest").append(error);
        }
    });

    $("#txtFollowingRequestContent").rules("add", {
        required: true,
        rangelength: [0, 100],
        messages: {
            required: "请输入内容!",
            rangelength: jQuery.format("内容在{0}到{1}个字符之间")
        }
    });
}


//关注  个人照片展示页
function FollowUserS4(taId, objectId) {
    //进入加载关注状态
    //提交数据
    var res = FollowUser(taId, function (res) {

        res = eval('(' + res + ')');

        if (res.status == "OK") {
            //更按键状态
            $(objectId).replaceWith("<a href=\"javascript:void(0);\" onclick='FollowingUserCancelS3(\"" + taId + "\",this);' class=\"btn_light_unfollow btn_light_unfollow2\"><span>已关注</span>取消</a>");

        } else {
            var data = eval('(' + res.data + ')');
            var message = data.message;
            dialog(data.message, [
                        { val: "UserLoginNeed", className: "x", title: "请先登录或注册", text: "" },
                        { val: "UserStatusError", className: "x", title: "你的帐户异常", text: "" },
                        { val: "UserNotFound", className: "x", title: "你的帐户异常", text: "" },
                        { val: "ServerException", className: "x", title: "操作失败", text: "" },
                        { val: "FollowingInvalidTargetUserID", className: "x", title: "操作失败", text: "" }
                    ]);
        }

    });

}


//关注  用户注册 
function FollowUserS5(taId, objectId) {
    //进入加载关注状态
    //提交数据
    var res = FollowUser(taId, function (res) {

        res = eval('(' + res + ')');

        if (res.status == "OK") {
            //更按键状态
            $(objectId).replaceWith("<a href=\"javascript:void(0);\" onclick='FollowingUserCancelS4(\"" + taId + "\",this);' class=\"btn_light_unfollow\"><span>已关注</span>取消</a>");

        } else {
            var data = eval('(' + res.data + ')');
            var message = data.message;
            dialog(data.message, [
                        { val: "UserLoginNeed", className: "x", title: "请先登录或注册", text: "" },
                        { val: "UserStatusError", className: "x", title: "你的帐户异常", text: "" },
                        { val: "UserNotFound", className: "x", title: "你的帐户异常", text: "" },
                        { val: "ServerException", className: "x", title: "操作失败", text: "" },
                        { val: "FollowingInvalidTargetUserID", className: "x", title: "操作失败", text: "" }
                    ]);
        }

    });

}


//关注 (请求关注提交数据)
function FollowingRequest(taId) {
    if (!$("#frmFollowingRequest").valid()) {
        return false;
    }

    var content = $("#txtFollowingRequestContent").val();
    $.post('/Ajax.aspx',
                    {
                        Action: "FollowUserRequest",
                        Taid: taId,
                        MessageContent: content
                    },
                    function (res) {
                        res = eval('(' + res + ')');

                        if (res.status == "OK") {
                            dialog("OK", [
                                            { val: "OK", className: "v", title: "发送成功", text: "" }
                                        ]);

                        } else {
                            var data = eval('(' + res.data + ')');
                            var message = data.message;
                            dialog(data.message, [
                                            { val: "MissingValue", className: "x", title: "请输入回应内容", text: "" },
                                            { val: "FollowingRequestInvalidMessageContent", className: "x", title: "内容太长", text: "" },
                                            { val: "UserLoginNeed", className: "x", title: "请先登录或注册", text: "" },
                                            { val: "UserNotFound", className: "x", title: "你的帐户异常", text: "" },
                                            { val: "UserStatusError", className: "x", title: "你的帐户异常", text: "" },
                                            { val: "ServerException", className: "x", title: "操作失败", text: "" },
                                            { val: "FollowingInvalidTargetUserID", className: "x", title: "操作失败", text: "" }
                                        ]);
                        }
                    });

}




//关注取消 - 看自己关注列表
function FollowingUserCancelS1Confirm(taId, objectId, userName,userHead) {
    var str = "<div class=\"pop_sml\">  ";
    str += "        <div class=\"pop_message_ok\">  \r\n";
    str += "            <div>  \r\n";
    str += "                <img class=\"fans_img\" alt=\"\" src=\"" + userHead + "\" >确认取消对 " + userName + " 的关注吗？  \r\n";
    str += "            </div>  \r\n";
    str += "        </div>  \r\n";
    str += "  \r\n";
    str += "        <div class=\"pop_handle\">  \r\n";
    str += "            <a id=\"lnkOk\" class=\"btn_sml\" href='javascript:void(0);' >确认</a><a class=\"btn_sml_cancel\"  href='javascript:void(0);' onclick='closePopup();'>取消</a>  \r\n";
    str += "  \r\n";
    str += "            <div class=\"clear\"></div>  \r\n";
    str += "        </div>  \r\n";
    str += "    </div>  \r\n";

    dialog("FollowingUserCancelConfirm", [
                { val: "FollowingUserCancelConfirm", text: str, isPanel: true, fadeOut: -1, width: 240 }
            ]);
    $("#lnkOk").click(function () {
        FollowingUserCancelS1(taId, objectId);
    });
    
}

//关注取消 - 看自己关注列表
function FollowingUserCancelS1(taId, objectId) {
    //进入加载取消状态
    //提交数据
    var res = FollowUserCancel(taId, function (res) {

        res = eval('(' + res + ')');

        if (res.status == "OK") {
            closePopup();
            $("#FollowingCount").html(parseInt($("#FollowingCount").text()) - 1);
            $(objectId).parent().parent().parent().slideUp(500);
        }
        else {
            var data = eval('(' + res.data + ')');
            var message = data.message;
            dialog(data.message, [
                        { val: "UserLoginNeed", className: "x", title: "请先登录或注册", text: "" },
                        { val: "UserStatusError", className: "x", title: "你的帐户异常", text: "" },
                        { val: "UserNotFound", className: "x", title: "你的帐户异常", text: "" },
                        { val: "ServerException", className: "x", title: "操作失败", text: "" },
                        { val: "FollowingInvalidTargetUserID", className: "x", title: "操作失败", text: "" }
                    ]);
        }


    });

}


//关注取消 - 个人首页
function FollowingUserCancelS2(taId, objectId) {
    //进入加载取消状态
    //提交数据
    var res = FollowUserCancel(taId, function (res) {

        res = eval('(' + res + ')');

        if (res.status == "OK") {
            $(objectId).replaceWith("<a href=\"javascript:void(0);\" onclick='FollowUserS1(\""+taId+"\",this);' class=\"btn_light_big\">关注该用户</a>");
        }
        else {
            var data = eval('(' + res.data + ')');
            var message = data.message;
            dialog(data.message, [
                        { val: "UserLoginNeed", className: "x", title: "请先登录或注册", text: "" },
                        { val: "UserStatusError", className: "x", title: "你的帐户异常", text: "" },
                        { val: "UserNotFound", className: "x", title: "你的帐户异常", text: "" },
                        { val: "ServerException", className: "x", title: "操作失败", text: "" },
                        { val: "FollowingInvalidTargetUserID", className: "x", title: "操作失败", text: "" }
                    ]);
        }


    });

}


//关注取消 - 个人照片展示页
function FollowingUserCancelS3(taId, objectId) {
    //进入加载取消状态
    //提交数据
    var res = FollowUserCancel(taId, function (res) {

        res = eval('(' + res + ')');

        if (res.status == "OK") {
            $(objectId).replaceWith("<a href=\"javascript:void(0);\" onclick='FollowUserS4(\"" + taId + "\",this);' class=\"btn_sml_light\">+关注</a>");
        }
        else {
            var data = eval('(' + res.data + ')');
            var message = data.message;
            dialog(data.message, [
                        { val: "UserLoginNeed", className: "x", title: "请先登录或注册", text: "" },
                        { val: "UserStatusError", className: "x", title: "你的帐户异常", text: "" },
                        { val: "UserNotFound", className: "x", title: "你的帐户异常", text: "" },
                        { val: "ServerException", className: "x", title: "操作失败", text: "" },
                        { val: "FollowingInvalidTargetUserID", className: "x", title: "操作失败", text: "" }
                    ]);
        }


    });

}


//关注取消 - 用户注册
function FollowingUserCancelS4(taId, objectId) {
    //进入加载取消状态
    //提交数据
    var res = FollowUserCancel(taId, function (res) {

        res = eval('(' + res + ')');

        if (res.status == "OK") {
            $(objectId).replaceWith("<a href=\"javascript:void(0);\" onclick='FollowUserS5(\"" + taId + "\",this);' class=\"btn_sml_dark\">+关注</a>");
        }
        else {
            var data = eval('(' + res.data + ')');
            var message = data.message;
            dialog(data.message, [
                        { val: "UserLoginNeed", className: "x", title: "请先登录或注册", text: "" },
                        { val: "UserStatusError", className: "x", title: "你的帐户异常", text: "" },
                        { val: "UserNotFound", className: "x", title: "你的帐户异常", text: "" },
                        { val: "ServerException", className: "x", title: "操作失败", text: "" },
                        { val: "FollowingInvalidTargetUserID", className: "x", title: "操作失败", text: "" }
                    ]);
        }


    });

}




//关注同意
function FollowingAgree(taId, objectId) {

    $.post('/Ajax.aspx',
                    {
                        Action: "FollowingAgree",
                        Taid: taId
                    },
                    function (res) {
                        res = eval('(' + res + ')');

                        if (res.status == "OK") {
                            $("#FollowingRequestCount").html(parseInt($("#FollowingRequestCount").text()) - 1);
                            $(objectId).parent().parent().parent().slideUp(500);

                        } else {
                            var data = eval('(' + res.data + ')');
                            var message = data.message;
                            dialog(data.message, [
                                    { val: "UserLoginNeed", className: "x", title: "请先登录或注册", text: "" },
                                    { val: "UserStatusError", className: "x", title: "你的帐户异常", text: "" },
                                    { val: "UserNotFound", className: "x", title: "你的帐户异常", text: "" },
                                    { val: "ServerException", className: "x", title: "操作失败", text: "" },
                                    { val: "FollowingInvalidTargetUserID", className: "x", title: "操作失败", text: "" }
                                ]);
                        }
                    });

}
//关注拒绝
function FollowingDisAgree(taId, objectId) {
    $.post('/Ajax.aspx',
                        {
                            Action: "FollowingDisAgree",
                            Taid: taId
                        },
                        function (res) {
                            res = eval('(' + res + ')');

                            if (res.status == "OK") { 
                                $("#FollowingRequestCount").html(parseInt($("#FollowingRequestCount").text()) - 1);
                                $(objectId).parent().parent().parent().parent().slideUp(500);

                            } else {
                                var data = eval('(' + res.data + ')');
                                var message = data.message;
                                dialog(data.message, [
                                                { val: "UserLoginNeed", className: "x", title: "请先登录或注册", text: "" },
                                                { val: "UserStatusError", className: "x", title: "你的帐户异常", text: "" },
                                                { val: "UserNotFound", className: "x", title: "你的帐户异常", text: "" },
                                                { val: "ServerException", className: "x", title: "操作失败", text: "" },
                                                { val: "FollowingInvalidTargetUserID", className: "x", title: "操作失败", text: "" }
                                            ]);
                            }
                        });

}
 
