var m_GroupAddPersonType = "1";//邀请入群标识 1：成员添加到群，2: 群添加成员
var m_SelectGroupUsername = "";
var m_SelectMsgBatchMail = "1";// 1为消息列表 2为群列表 3为通讯录列表


// change m_GroupAddPersonType
function PersonAddGroup(value,type) {
	m_GroupAddPersonType = value;
	m_SelectMsgBatchMail = type;
}
//人员添加到群组或群组添加人员
function PersonToGroupOrGroupAddPerson() {
    //群组Show
    var objhidDocWechatKey = $("#hidDocWechatKey");
    var objhidDocUserName = $("#hidDocUserName");

    var strParaJson = $.toJSON({
        wechatkey: objhidDocWechatKey.val(),
        username: objhidDocUserName.val(),
    });
    talkObj.getbatchsbyuser(strParaJson);
}
//获取所有群组回调
function AsyncGetBatchsByUserResult(jsonResult) {
    var strContent = "";
    var strExist = "";
    if (jsonResult.success) {
        if (jsonResult.grouplist.length > 0) {
            for (var i = 0; i < jsonResult.grouplist.length; i++) {
                if (!jsonResult.grouplist[i].ishave) {
                    strContent += "<li id=\"batchadd"+i+"\" class=\"\" onclick=\"SelectChangeGroup(" + i + ",'" + jsonResult.grouplist[i].username + "')\">";
                    strContent += "<img src=\"" + jsonResult.grouplist[i].headimgurl + "\">";
                    strContent += "<div class=\"invate-number\">" + jsonResult.grouplist[i].nickname + "</div>";
                    strContent += "</li>";
                }
                //strExist = jsonResult.grouplist[i].ishave ? "<p style=\"margin:0;\">【已加入该群聊】</p>" : "<input type=\"radio\" value=" + jsonResult.grouplist[i].username + " name=\"Group\" style=\"margin:15px 5px 0 0; float:right; \"  onclick=\"SelectChangeGroup('" + jsonResult.grouplist[i].username + "')\"/>";

                //strContent += "<li><img src=\"" + jsonResult.grouplist[i].headimgurl + "\" style=\"height:40px;width:40px;\"><span>" + jsonResult.grouplist[i].nickname + "</span>" + strExist + "</li>";
            }
        } else {
            strContent = "暂无群";
        }
        $("#AllGroupShow").html(strContent);
        $("#FriendsAddToGroupModel").modal("show");
    } else {
        ShowError("myPageAlert", "获取所有群异常：" + jsonResult.error);
    }
}
//选中群
function SelectChangeGroup(index,GroupUserName) {
    var chkList = $("#AllGroupShow").find("li");
    chkList.each(function (i) {
        $(this).attr("class", "");
    });
    $("#batchadd" + index).attr("class", "list-checked");
    m_SelectGroupUsername = GroupUserName;
}
//确认邀请到群
function SavePersonAddGeoup() {
    var objhidDocWechatKey = $("#hidDocWechatKey");
    var objhidDocUserName = $("#hidDocUserName");
    if (m_SelectGroupUsername == "") {
        return;
    } else {
        var strParaJson = $.toJSON({
            wechatkey: objhidDocWechatKey.val(),
            username: objhidDocUserName.val(),
            fromusername: m_SelectGroupUsername
        });
        talkObj.personaddtogroup(strParaJson);
    }
}
//确认邀请到群回调
function AsyncPersonAddToGroupResult(jsonResult) {
    if (jsonResult.success) {
        ShowMsg("myPageAlert", "邀请好友成功！");
    } else {
        ShowError("myPageAlert", "邀请好友到群聊失败：该群主可能开启了验证！");
    }
    $("#FriendsAddToGroupModel").modal("hide");
}

