var m_Groupitemjson = "";
var m_Colorsitemjson = "";
$(function () {
    //changefriendgroupDataBind();
});
//绑定分组
function changefriendgroupDataBind(){
    talkObj.getgroupval();
}
//绑定分组回调
function AsyncGetGroupValResult(jsonResult) {
	if (jsonResult.success) {
		if (jsonResult.wechats.length > 0) {
			var paraitem = jsonResult.wechats;
			for (var i = 0; i < paraitem.length; i++) {
				if (paraitem[i].key == "friendgroup") {
					var groupitem = $.parseJSON(paraitem[i].valus);
					m_Groupitemjson = groupitem;
				}
			}
			var colorsitem = "";
			if (paraitem.length == "2") {
				for (var j = 0; j < paraitem.length; j++) {
					if (paraitem[j].key == "friendgroupcolor") {
						colorsitem = $.parseJSON(jsonResult.wechats[j].color);
						m_Colorsitemjson = colorsitem;
					}
				}
			}
			var objchangefriendgroup = $("#ulAllGroup");
			var objselectMailQueryGroup = $("#selectMailQueryGroup");
			var objselectRightGroup = $("#selectRightGroup");//右键分组模态框
			var objulAllGroupTalk = $("#ulAllGroupTalk");//对话中的联系人好友分组ID

			var strUlAllGroupTalk = "";//对话中的联系人中好友分组中的内容
			strUlAllGroupTalk += "<li onclick=\"ContactsGroup('分组','')\"><a href=\"#\"><span></span>分组</a></li>";
			var strallgroup = "<li onclick=\"SelectGroup('','')\"><a href=\"#\"><span class=\"fgroup-color\"></span>无分组</a></li>";
			for (var i = 0; i < groupitem.length; i++) {
				var itemcolor = "";
				if (colorsitem.length > 0) {
					itemcolor = colorsitem[i];
				}
				strallgroup += "<li onclick=\"SelectGroup('" + groupitem[i] + "','" + itemcolor + "')\"><a href=\"#\"><i class=\"icon iconfont icon-round\" style=\"color:" + itemcolor + "\"></i> " + groupitem[i] + "</a></li>";
				//strallgroup += "<li ><a href=\"#\"><span class=\"fgroup-color\" style=\"background:" + itemcolor + ";\"></span>" + groupitem[i] + "</a></li>";
				strUlAllGroupTalk += "<li onclick=\"ContactsGroup('" + groupitem[i] + "','" + itemcolor + "')\"><a href=\"#\"><span class=\"fgroup-color\" style=\"background:" + itemcolor + ";\"></span>" + groupitem[i] + "</a></li>";
				objselectRightGroup.append("<option value='" + groupitem[i] + "'>" + groupitem[i] + "</option>");
			}
			objchangefriendgroup.html(strallgroup);
			objulAllGroupTalk.html(strUlAllGroupTalk);
		}
	}
}
//对话消息中的好友分组单击事件
function SelectGroup(groupname, itemcolor) {
	$("#selectPersonDept").html(groupname);
	$("#iNowSelGroup").css("color", itemcolor);
	SetFriendDoc();//修改好友资料方法
}
//对话联系人中的好友分组单击事件
function ContactsGroup(groupname, itemcolor) {
    $("#selectMailQueryGroup").html(groupname);
    if (itemcolor.length > 0 ) {
        $("#selectMailQueryGroup").css("border-left", "5px solid " + itemcolor + "");
        $("#selectMailQueryGroup").css("padding-left", "10px");
    } else {
        $("#selectMailQueryGroup").css("border-left", "");
        $("#selectMailQueryGroup").css("padding-left", "0px");
    }   
}