﻿$.include(["base/style/pop.css"]);
var Hellodg;
var helloloading = false;
var hellosending = false;
$(document).ready(function() {
    $.get("base/Control/Hello.htm", function(data) {
        $("#lr").html(data);
        helloloading = true;
        setTimeout(function() { if ($("#HelloDiv").length > 0) Hellodg = new Dialog('HelloDiv'); helloloading = false; }, 1000);
    });
});
function Blog_init(basePath) {
    if (typeof (aa) == "undefined")
        basePath = "";
    shenghuohui.BlogMethods = new HashTable();
    shenghuohui.BlogMethods.Add("AddFriend", "/base/Service/Blog.ashx");
    shenghuohui.BlogMethods.Add("DelFriend", "/base/Service/Blog.ashx");
    shenghuohui.BlogMethods.Add("AddConcern", "/base/Service/Blog.ashx");
    shenghuohui.BlogMethods.Add("DelFan", "/base/Service/Blog.ashx");
    shenghuohui.BlogMethods.Add("DelConcern", "/base/Service/Blog.ashx");
    shenghuohui.BlogMethods.Add("AddFavorite", "/base/Service/Blog.ashx");
    shenghuohui.BlogMethods.Add("CommandHello", "/base/Service/Utility.ashx");
    shenghuohui.BlogMethods.Add("ReadCommand", "/base/Service/Blog.ashx");
    shenghuohui.BlogMethods.Add("ExitGroup", "/base/Service/Community.ashx");
}
Blog_init();
function AddFriend(friendid) {
    var method = "AddFriend";
    var prams = "&friendid="+friendid;
    function OnSuccess(result) {
        if (result == 1)
            alert("添加好友成功！");
        else if (result == 2)
            alert("对方已经是您的好友！");
        else if (result == 3)
            alert("不能加自己为好友！");
        else {
            alert("请您先登录！");
            window.location = "http://www.shenghuohui.com/Login/Login.aspx?ReturnUrl=" + window.location;
        }
    }
    $.ajax({ type: "post", url: shenghuohui.BlogMethods.GetValue(method), dataType: "html", data: "m=" + method + prams, success: OnSuccess });
}
function DelFriend(userid) {
    var method = "DelFriend";
    var prams = "&userid=" + userid;
    function OnSuccess(result) {
        if (result == 1) {
            alert("删除成功！");
            $("#Friend_" + userid).remove();
        }
        else if(result == 3){
            alert("您没有权限！");
        }
        else {
            alert("删除失败！");
        }
    }
    $.ajax({ type: "post", url: shenghuohui.BlogMethods.GetValue(method), dataType: "html", data: "m=" + method + prams, success: OnSuccess });
}
function DelFan(userid) {
    var method = "DelFan";
    var prams = "&userid=" + userid;
    function OnSuccess(result) {
        if (result == 1) {
            alert("删除成功！");
            $("#Concern_" + userid).remove();
        }
        else if(result == 3){
            alert("您没有权限！");
        }
        else {
            alert("删除失败！");
        }
    }
    $.ajax({ type: "post", url: shenghuohui.BlogMethods.GetValue(method), dataType: "html", data: "m=" + method + prams, success: OnSuccess });
}
function AddConcern(userid, e,l,u) {
    var method = "AddConcern";
    var prams = "&userid=" + userid;
    function OnSuccess(result) {
        if (result == 1) {
            alert("关注成功！");
            if (e) {
                e.innerText = "取消关注";
                e.onclick = function() { DelConcern(userid, e) };
            }
            if (u) {
                window.location = u;
            }
        }
        else if (result == 2) {
            alert("对方已经在您的关注中！");
            if (e) {
                e.innerText = "取消关注";
                e.onclick = function() { DelConcern(userid, e) };
            }
        }
        else if (result == 3) {
            alert("不能关注自己！");
            if (e) {
                e.innerText = "";
                e.onclick = "";
            }
        }
        else {
            alert("请您先登录！");
            window.location = "http://www.shenghuohui.com/Login/Login.aspx?ReturnUrl=" + window.location;
        }
    }
    $.ajax({ type: "post", url: shenghuohui.BlogMethods.GetValue(method), dataType: "html", data: "m=" + method + prams, success: OnSuccess });
}
function DelConcern(userid) {
    var method = "DelConcern";
    var prams = "&userid=" + userid;
    function OnSuccess(result) {
        if (result == 1) {
            alert("取消成功！");
            $("#Concern_" + userid).remove();
        }
        else if(result == 3){
            alert("您没有权限！");
        }
        else {
            alert("取消失败！");
        }
    }
    $.ajax({ type: "post", url: shenghuohui.BlogMethods.GetValue(method), dataType: "html", data: "m=" + method + prams, success: OnSuccess });
}
function DelConcern(userid,e) {
    var method = "DelConcern";
    var prams = "&userid=" + userid;
    function OnSuccess(result) {
        if (result == 1) {
            alert("取消成功！");
            e.innerText = "加关注";
            e.onclick = function(){AddConcern(userid, e)};
        }
        else if (result == 3) {
            alert("您没有权限！");
        }
        else {
            alert("取消失败！");
        }
    }
    $.ajax({ type: "post", url: shenghuohui.BlogMethods.GetValue(method), dataType: "html", data: "m=" + method + prams, success: OnSuccess });
}
function AddFavorite(code,infoid,title,url,html) {
    var method = "AddFavorite";
    var prams = "&code=" + code;
    prams += "&infoid=" + infoid;
    prams += "&title=" + title;
    if (url == "")
        url = window.location;
    prams += "&url=" + url;
    if (html == "") {
        if ($("h_" + infoid).length > 0)
            prams += "&html=" + $("h_" + infoid).html();
        if ($("v_" + infoid).length > 0)
            prams += "&html=" + $("v_" + infoid).val();
    }
    else {
        prams += "&html=" + html;
    }
    function OnSuccess(result) {
        if (result > 0)
            alert("收藏成功！");
        else if (result == -1)
            alert("该地址已经加入收藏！");
        else if (result == -2)
            alert("不存在该类型数据，请确认您是在生活汇网站！");
        else if(result<=-10){
            alert("请您先登录！");
            window.location = "http://www.shenghuohui.com/Login/Login.aspx?ReturnUrl=" + window.location;
        }
        else
        {
            alert("系统数据错误！");
        }
    }
    $.ajax({ type: "post", url: shenghuohui.BlogMethods.GetValue(method), dataType: "html", data: "m=" + method + prams, success: OnSuccess });
}
function CommandHello(userid, title) {
    if (!Hellodg) {
        if (!helloloading) {
            helloloading = true;
            $.get("base/Control/Hello.htm", function(data) {
                $("#lr").html(data);
                setTimeout(function() { if ($("#HelloDiv").length > 0) Hellodg = new Dialog('HelloDiv'); if (Hellodg) Hellodg.ShowAndMask(); helloloading = false; }, 2000);
                alert("页面正在加载中，请稍后再尝试。");
            });
        }
        else {
            if ($("#HelloDiv").length > 0)
                Hellodg = new Dialog('HelloDiv');
            return;
        }
    }
    else {
        if ($.cookie("commandhello_" + userid) > 100) {
            alert("对不起，您目前等级每天只能对一个人发送100个招呼！");
            return;
        }
        $("#hello_userid").val(userid);
        $("#hello_title").val(title);
        Hellodg.ShowAndMask();
    }
}
function SendHello() {
    var method = "CommandHello";
    var userid = $("#hello_userid").val();
    var prams = "&type=hello_" + $("input[name='hello_type']:checked").val() + "&userid=" + userid + "&title=" + $("#hello_title").val();
    function OnSuccess(result) {
        hellosending = false;
        if (result == 1) {
            $("#hello_userid").val("");
            $("#hello_title").val("");
            alert("打招呼成功！");
            Hellodg.Hide();
            $.cookie("commandhello_" + userid, isNaN($.cookie("commandhello_" + userid)) ? "1" : parseInt($.cookie("commandhello_" + userid)) + 1, { domain: 'shenghuohui.com', path: '/', expires: 1 });
        }
        else if (result == 2)
            alert("打招呼失败！");
        else if (result == 3)
            alert("不能给自己打招呼！")
        else {
            alert("请您先登录！");
            window.location = "http://www.shenghuohui.com/Login/Login.aspx?ReturnUrl=" + window.location;
        }
    }
    if (hellosending)
        alert("发送中，请稍后。。");
    else
        $.ajax({ type: "post", url: shenghuohui.BlogMethods.GetValue(method), dataType: "html", data: "m=" + method + prams, success: OnSuccess });
    hellosending = true;
}
function ReadCommand(ids) {
    var method = "ReadCommand";
    var prams = "&ids=" + ids;
    function OnSuccess(result) {
    }
    if(ids!="")
        $.ajax({ type: "post", url: shenghuohui.BlogMethods.GetValue(method), dataType: "html", data: "m=" + method + prams, success: OnSuccess });
}
$(function() {
    $("table.geren_content_left a[href*='Prize']").addClass("recnew");
});

function ExitGroup(groupid) {
    var method = "ExitGroup";
    var prams = "&userid=" + userid;
    function OnSuccess(result) {
        if (result == True) {
            alert("退出成功！");
            $("#Group_"+groupid)
        }
        else {
            alert("退出失败！");
        }
    }
    $.ajax({ type: "post", url: shenghuohui.BlogMethods.GetValue(method), dataType: "html", data: "m=" + method + prams, success: OnSuccess });
}
