﻿(function($) {
    attention = {
        add_count: null,
        remaind_count: null,
        obj: null,
        vip_obj: null,
        ajax_url: '../ajax/attention.aspx',
        attention_content: null,
        show_tips_temp: '<div class="attention_layout"><div class="attention_container"><div class="attention_bg popup_bg"></div><div class="attention_content"><p>添加此会员到关注列表中，您将更好的关注此会员的竞猜状况！</p><p id="attention_content">{content}</p></div></div></div>',
        show_tips: function(target) {
            var str = '';
            var content = '';
            var arr_val = target.attr("rel").split('_');
            if (attention.add_count == null) { attention.add_count = parseInt(arr_val[1]); attention.remaind_count = parseInt(arr_val[2]); }
            if (attention.add_count != 0) { content = '您已添加' + attention.add_count + '位关注对象'; if (attention.remaind_count < 100) { content += '，还可以添加' + attention.remaind_count + '位关注对象哦！'; }; }
            else {
                if (arr_val[1] == "0" && arr_val[2] == "0") { content = "您还没有登录，登录后才能关注此会员哦！"; }
                else { content = '您还没有添加关注对象哦，点击添加！'; }
            };
            if (attention.obj == null) { str = attention.show_tips_temp.replace(/\{content\}/g, content); attention.obj = $(str); $('body').append(attention.obj); }
            if (attention.attention_content == null) attention.attention_content = $("attention_content", attention.obj);
            attention.attention_content.html(content);
            var pos = target.offset();
            var l = pos.left;
            var t = pos.top;
            attention.obj.css({ left: l, top: t + 10 }).fadeIn();
        },
        show_vip_tips: function(vipObj, target) {
            if (attention.vip_obj == null) {
                attention.vip_obj = $(attention.show_tips_temp);
                var content = $("div.attention_content", attention.vip_obj);
                if (vipObj.type) {
                    content.html('<p>您是' + vipObj.type + '会员，到期日期为' + vipObj.expired + '</p>');
                }
                else {
                    content.html('<p>您还不是中体会员，请加入会员</p>');
                }
                $("body").append(attention.vip_obj)
            }
            var pos = target.offset();
            var l = pos.left;
            var t = pos.top;
            attention.vip_obj.css({ left: l, top: t + 15 }).show();
        },
        hide_vip_tips: function() {
            attention.vip_obj.hide();
        },
        hover: function(target) {
            attention.show_tips($(target));
        },
        over: function() {
            attention.obj.hide();
        },
        add: function(target, obj) {
            var o = $(target);
            var member_id = o.attr("rel").split('_')[0];
            $.ajax({ url: attention.ajax_url, type: "post", data: { cmd: "add_attention", add_member_id: member_id, send_msg: obj.find("input[name=send_msg]:checked").val() }, dataType: "json", success: function(data) {
                if (data.r == 0) { o.attr("src", "../images/icon/attention_ok.gif"); attention.remaind_count--; attention.add_count++; }
                else if (data.r == 1) { jAlert("您已添加该会员为关注对象！", "关注提示"); }
                else if (data.r == 2) { jAlert("对不起，不能添加自己为关注对象！", "关注提示"); }
                else { jAlert("添加失败，请重新添加！", "操作提示"); }
            }, error: function(xmlhttp) {
                //alert(xmlhttp.status);
            }
            });
        },
        add_tips: function(target) {
            var temp = '<p>此会员竞猜后是否发送短信通知！</p><p id="send_msg"><input type="radio" name="send_msg" value="1" id="allow_send_msg" checked="checked" /><label for="allow_send_msg">发送</label>&nbsp;&nbsp;&nbsp;<input type="radio" name="send_msg" value="0" id="forbid_send_msg" /><label for="forbid_send_msg">不发送</label></p><p class="red">注：惹选择发送短信，会员竞猜后系统将扣除您<br />相应的查看球币数同时此会员将得到相应的提成！</p>';
            jConfirm(temp, '关注提示', function(r, o) {
                if (r) { attention.add(target, o); }
            });
        },
        click: function(target) {
            if (attention.remaind_count == 0 && attention.add_count == 0) { jAlert('您还没有登录，请先登录！', '关注提示'); }
            else if (attention.remaind_count <= 0) { jAlert('您的添加关注数已满，想要获得更多添加数赶快<a href="../member/joinvip.aspx">[加入会员]</a>吧！', '关注提示'); }
            else { attention.add_tips(target); }
        }
    };
})(jQuery);
