﻿
$(function() {

    var recid = $("#hiduid").val(); //接收者编号
    var recname = $("#hiduname").val();
    $(function() {

        if (dUserid != -1) {
            if (dUserid != $("#hiduid").val()) {//自已不能关注自己
                //关注此用户
                $.get("/WebServe/Handler1.ashx?uid=" + dUserid + '&num=10' + '&round=' + (new Date).getSeconds() + "&followuid=" + $("#hiduid").val(), function(data) {
                    if (data == 0) {//未关注过此人
                        $("#guanzuta").css("display", "inline-block");
                    }
                    else { //已关注过
                        fllowd();
                    }
                })
            }
            else {
                $("#divguanzu").html('');
            }
        } else { $("#guanzuta").css("display", "inline-block"); }

        function getstringlength(str) {
            return str.replace(/[^\x00-\xff]/ig, "aa").length;
        }
        //已关注过
        function fllowd() {
            $("#divguanzu").html("<span  id='followproc'><span id='uhei'><span id='folok'></span></span><span id='已关注'>已关注&nbsp;&nbsp;|&nbsp;<span id='canelfol'>取消</span></span></span>");

            $("#canelfol").click(function() { //取消关注
                $("#divguanzu").html('提交中...');

                $.get("/WebServe/Handler1.ashx?uid=" + dUserid + '&num=14' + "&followuid=" + $("#hiduid").val(), function(data) {
                    if (data != 0) {//取消关注成功
                        $("#divguanzu").html("<span id='guanzuta'></span>");
                        $("#guanzuta").css("display", "inline-block");
                        $("#guanzuta").bind("click", bindclick);
                    }

                })
            })
        }


        function bindclick() {
            if (dUserid != "-1") {///已登录
                if ($("#hiduid").val() == "0") return false;
                $("#divguanzu").html('提交中...');
                
                $.get("/WebServe/Handler1.ashx?uid=" + dUserid + '&num=9' + '&round=' + (new Date).getSeconds() + "&followuid=" + $("#hidESUid").val(), function(data) {
                    if (data == 1) {
                        fllowd();
                    }
                    else if (data == 2) {
                        alert('自己不能关注自己'); $("#divguanzu").html("");
                    }
                    pathul();
                })

            }
            else { //没有登录
                showlog("followuser");

            }

            $("#loading").bind("ajaxStart", function() {
                $(this).show();
                $("#clicklog").hide();

            })
            $("#loading").bind("ajaxStop", function() {
                $(this).hide();
                $("#clicklog").show();
            })

            $("#yp_userPwd").keyup(function(event) {
                if (event.which == 13) {
                    $("#clicklog").click();
                }
            })
        }
        $("#guanzuta").bind("click", bindclick);

        if ($.trim($("#cityde span").eq(0).attr("id")) == "" && $.trim($("#cityName").text()) == "" && $.trim($("#u8").text()) == "")
        { $("#cityde").html("<span style='color:#999'>尚未添写任何个人资料</span>"); }


        //发私信
        if ($("#u_fasx").length != 0 && dUserid != -1) {
            $("#u_fasx").click(function() {
                sefs();
            })
        }

    })
    function gotoReg() {
        window.location.href = '/reg_new1.aspx';
    }



    $(window).scroll(function() { center("#ssxsub"); })
    ///向粉丝发私信
    function sendsifs(id, name)
    { recid = id; recname = name; sefs(); }

    //start 发送粉丝
    function sefs() {

        var dbhtml = "<div style='margin-left:20px; margin-top:20px;'><div style='font-weight:bold'>对" + recname + "说：</div><div style='margin-top:10px;'><textarea rows='5' id='cbody' cols='40' style='border:1px solid #CCCCCC; height:100px; width:350px;'></textarea></div><div style='display:inline;float:left;width:280px; color:#999;margin-top:12px;'>私信内容小于300字，并只能发送给你的粉丝。</div><div id='sendxsxin'></div></div>";
        showWindow('', dbhtml, '发私信', '', '400', '220', 'tgrz');
        $("#sendxsxin").click(function() {
            $("#sendxsxin").hide();
            $("#sendxsxin").after("<div style='color:#999999;float:left;height:28px;line-height:28px;margin-top:5px;'>加载中...</div>");

            $.post("/WebServe/userHand.ashx?usertype=13&ruid=" + recid + "&cbody=" + escape($.trim($("#cbody").val())) + "&r=" + (new Date()).getSeconds(), function(data) {
                if (data == "true") {
                    closeWindow("tgrz");
                    $("#ssxsub").show();
                    center("#ssxsub");
                    $("#ssxsub").fadeOut(1500);
                }
            })
        })
        //end
    }
    function center(obj) {
        var windowWidth = document.documentElement.clientWidth;
        var windowHeight = document.documentElement.clientHeight;
        var popupHeight = $(obj).height();
        var popupWidth = $(obj).width();
        $(obj).css({
            "position": "absolute",
            "top": (windowHeight - popupHeight) / 2 + $(document).scrollTop() - 100,
            "left": (windowWidth - popupWidth) / 2
        });
    }
});

///向粉丝发私信
function sendsifs(id, name)
{ recid = id; recname = name; sefs(); }

//start 发送粉丝
function sefs() {

    var dbhtml = "<div style='margin-left:20px; margin-top:20px;'><div style='font-weight:bold'>对" + recname + "说：</div><div style='margin-top:10px;'><textarea rows='5' id='cbody' cols='40' style='border:1px solid #CCCCCC; height:100px; width:350px;'></textarea></div><div style='display:inline;float:left;width:280px; color:#999;margin-top:12px;'>私信内容小于300字，并只能发送给你的粉丝。</div><div id='sendxsxin'></div></div>";
    showWindow('', dbhtml, '发私信', '', '400', '220', 'tgrz');
    $("#sendxsxin").click(function() {
        $("#sendxsxin").hide();
        $("#sendxsxin").after("<div style='color:#999999;float:left;height:28px;line-height:28px;margin-top:5px;'>加载中...</div>");

        $.post("/WebServe/userHand.ashx?usertype=13&ruid=" + recid + "&cbody=" + escape($.trim($("#cbody").val())) + "&r=" + (new Date()).getSeconds(), function(data) {
            if (data == "true") {
                closeWindow("tgrz");
                $("#ssxsub").show();
                center("#ssxsub");
                $("#ssxsub").fadeOut(1500);
            }
        })
    })
    //end
}
function center(obj) {
    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;
    var popupHeight = $(obj).height();
    var popupWidth = $(obj).width();
    $(obj).css({
        "position": "absolute",
        "top": (windowHeight - popupHeight) / 2 + $(document).scrollTop() - 100,
        "left": (windowWidth - popupWidth) / 2
    });
}
