
var AddFriend={};$(document).ready(function(){AddFriend.LinkMans={};AddFriend.GroupId=-1;AddFriend.UserList={};AddFriend.AddingUser=new Array();AddFriend.CurDeptId=-1;var a=tzm("GroupId");if(ymr(a)||isNaN(a)||parseInt(a,10)<1)a=0;else a=parseInt(a,10);if(a>0)AddFriend.GroupId=a});$(window).load(function(){AddFriend.czd=$("#dds_d1897_MaxVersionId");AddFriend.bde=$("#dcx_mainUs232erBtn");AddFriend.ako=$("#divUserList");AddFriend.ntp=$("#treeContainer");AddFriend.ofa=$("#selectedItems");AddFriend.chl=AddFriend.ofa.parent().children(".txt").children("span");var e="/WebServices/WebIM/WebIM.asmx/GetLinkMansAndGroups";$.ajax({type:"POST",contentType:"application/json; charset=utf-8",url:e,data:"{}",dataType:'json',beforeSend:function(a){},complete:function(a,b){},error:function(a){var b=JSON2.stringify(a);if(b.length>600)b=b.substr(0,600);alert("读取好友分组失败。详情："+b);return false},success:function(a){a=hmy(a);if(ymr(a)){art.VLdialog.alert("读取好友分组时失败2。",function(){},14,"提示");return false}
if(!ymr(a)){AddFriend.dsh=a.DeptId;AddFriend.poq=a.UserId;AddFriend.LinkMans=a.LinkMans;AddFriend.LinkGroups=a.LinkGroups;fhf(AddFriend.dsh);a=a.LinkGroups;var b=new nzy();for(var i=0;i<a.length;i++){var v=a[i].GroupId;var t=a[i].GroupName;if(i==0){if(AddFriend.GroupId<1)AddFriend.GroupId=v;AddFriend.GroupName=t}
b.append("<li onmousedown=\"javascript:qlx(this);\" id=\"dds_d1897_MaxVersionId_li"+i+"\" val=\""+v+"\" txt=\""+t+"\" class=\"sel_li\">");b.append("<a class=\"op_a\" id=\"d1897_MaxVersionIda\" href=\"javascript:void(0);\">");b.append("<span id=\"d1897_MaxVersionIds\" ist=\"1\">"+t+"</span>");b.append("<em id=\"d1897_MaxVersionIde\" isv=\"1\">"+v+"</em>");b.append("</a>");b.append("</li>")}
var c=AddFriend.czd.find("ul");c.html(b.toString());if(c.children().length>0){if(AddFriend.GroupId>0){var d=c.children("[val='"+AddFriend.GroupId+"']");if(d.length>0)qlx(d.get(0));else qlx(c.children(":first").get(0))}else qlx(c.children(":first").get(0))}
$(document).mouseup(function(){AddFriend.czd.hide();$("#dcx_mainUs232erBtn").find(".dcx-msgtoolbar4").css({"background-position":"0px 0px"})})}}});rqu(null,null,"DeptId",2035,0,false,null)});$(window).load(function(){Dcx.Utility.cdt(true)});function fhf(c){if(AddFriend.UserList[c]!=undefined){tuy(c);return}
var d="/WebServices/System/User.asmx/fhf";$.ajax({type:"POST",contentType:"application/json; charset=utf-8",url:d,data:"{id:"+c+",qType:2}",dataType:'json',beforeSend:function(a){},complete:function(a,b){},error:function(a){var b=JSON2.stringify(a);if(b.length>600)b=b.substr(0,600);alert("读取树节点失败。详情："+b);return false},success:function(a){a=hmy(a);if(!ymr(a)&&c==AddFriend.dsh){for(var i=0;i<a.length;i++){if(a[i].UserId==AddFriend.poq){a.splice(i,1);break}}}
if(ymr(a))AddFriend.UserList[c]=new Array();else AddFriend.UserList[c]=a;tuy(c)}})}
function gdc(){var c="/WebServices/WebIM/WebIM.asmx/gdc";$.ajax({type:"POST",contentType:"application/json; charset=utf-8",url:c,data:"{}",dataType:'json',beforeSend:function(a){},complete:function(a,b){},error:function(a){var b=JSON2.stringify(a);if(b.length>600)b=b.substr(0,600);alert("读取好友分组失败。详情："+b);return false},success:function(a){a=hmy(a);if(ymr(a)){art.VLdialog.alert("读取分组下的好友时失败2。",function(){},14,"提示");return false}
if(AddFriend.LinkMans[groupId]==undefined)AddFriend.LinkMans[groupId]=a}})}
function sjn(a){AddFriend.CurDeptId=a;var b=AddFriend.UserList[a];var c=new nzy();var d=AddFriend.LinkMans;var e=0;for(var i=0;i<b.length;i++){var v=b[i].UserId;var t=b[i].UserName;var f=false;if(!ymr(d)){for(var k=0;k<d.length;k++){if(d[k].UserId==v){f=true;break}}}
c.append("<div class=\"item group-all group-0  ");if(f)c.append("item-selected2 \" isAdded=\"1\" ");else c.append(" \" ");c.append("  val=\""+v+"\"   txt=\""+t+"\" isItem=\"1\">");c.append("<img  alt=\"\"  txt=\""+t+"\" src=\""+Dcx.jbc(v,2)+"\" class=\"pic\">");c.append("<p class=\"name\">"+t+" </p>");c.append("<div class=\"join-done\">");c.append("已加入</div>");c.append("<span class=\"ico-gs-ok\"></span>");c.append("</div>");e++}
if(e<1)c.append("<p style=\"line-height: 190px; text-align: left;margin-left:30px; color: #999;\" class=\"j-no-result\">找不到该部门的用户</p>");return c.toString()}
function byq(a,b,c){var d=new nzy();var e=a;var f=b;if(typeof(a)=="number"){e=a+"";f=b+"";e=e.split(',');f=f.split(',')}else if(typeof(a)=="string"){e=a.split(',');f=b.split(',')}
if(!ymr(e)&&e.length>0){for(var i=0;i<e.length;i++){if(!ymr(e[i])){d.append("<div class=\"W_btn_arrow tag\" val=\""+e[i]+"\" txt=\""+f[i]+"\"><span class=\"S_func1\">"+f[i]+"");if(c)d.append("<a href=\"javascript:void(0)\" class=\"W_ico12 icon_close\"></a>");else d.append("<a href=\"javascript:void(0)\" class=\"W_ico12 icon_close\" style=\"display:none;\"></a>");d.append("</span></div>")}}}
return d.toString()}
function eon(a,b,c,d,e,f,g,h,i,j,k){fhf(parseInt(d,10))}
function tuy(f){AddFriend.ako.children().hide();var g=AddFriend.ako.children("[deptId="+f+"]");if(ymr(g)||g.length<1){g=$("  <div isuserlist=\"1\" deptid=\""+f+"\"></div>");AddFriend.ako.append(g);g.html(sjn(f));g.children("div").unbind("click").bind("click",function(){if(parseInt($(this).attr("isAdded"),10)==1)art.VLdialog.tips("Ta已是您的好友。",1);else{var c=parseInt($(this).attr("val"),10);var d=$.trim($(this).attr("txt"));if(isNaN(c)||ymr(c))return false;var k=-1;for(var i=0;i<AddFriend.AddingUser.length;i++){if(c==AddFriend.AddingUser[i].UserId){k=i;break}}
if($(this).hasClass("item-selected")){if(k>-1){AddFriend.AddingUser.splice(k,1);AddFriend.ofa.children("div[val='"+c+"']").remove()}
$(this).removeClass("item-selected")}else{if(k<0){AddFriend.AddingUser.push({"UserId":c,"UserName":d});var e=$(byq(c,d,true));e.find("a").unbind("click").bind("click",function(){var a=$(this).parent().parent();var b=parseInt(a.attr("val"),10);if(isNaN(b)||ymr(b))return false;for(var i=0;i<AddFriend.AddingUser.length;i++){if(b==AddFriend.AddingUser[i].UserId){AddFriend.AddingUser.splice(i,1);a.remove();AddFriend.chl.html(" "+AddFriend.AddingUser.length+" ");g.children("div[val='"+b+"']").removeClass("item-selected");break}}});AddFriend.ofa.append(e)}
$(this).addClass("item-selected")}
AddFriend.chl.html(" "+AddFriend.AddingUser.length+" ")}})}
g.show()}
function fzj(a,b,c,d){var e=xfx(a,"Left")-1;var f=xfx(a,"Top")+$(a).height()+5;AddFriend.czd.css({"left":e+"px","top":f+"px"});if(AddFriend.czd.css("display").toLowerCase()=="none"){AddFriend.czd.show();AddFriend.czd.attr("isShowing",1);$(a).find(".dcx-msgtoolbar4").css({"background-position":"-13px 0px"})}else{AddFriend.czd.attr("isShowing",0);AddFriend.czd.hide();$(a).find(".dcx-msgtoolbar4").css({"background-position":"0px 0px"})}}
function qlx(a){var b=new Array();var c=new Array();var d=$(a).attr("val");var e=$(a).attr("txt");b.push($(a).attr("val"));c.push(e);AddFriend.GroupId=parseInt(d,10);AddFriend.GroupName=e;var f=AddFriend.bde;var g="请选择分组";if(b.length>0){f.find("div.S_bg5").html(byq(b,c))}else{if(isMain)f.find("div.S_bg5").html("<span style=\"font-weight:bold;\">+</span> "+g);else f.find("div.S_bg5").html("<div    style=\"margin-top:35px;\" isDealDiv=\"1\" ><span style=\"font-weight:bold;\">+</span> "+g+"</div>")}
AddFriend.czd.hide()}
function rqu(a,b,c,d,e,f,g){return dvg(22,a,b,c,d,e,f,g)}
function dvg(c,d,e,f,g,h,i,j){if(ymr(c)){alert("请指定树的ID。");return null}
var k=true;if(ymr(j)){k=false}
var l=null;if(ymr(d))d=null;if(ymr(e))e=null;if(ymr(f))f=null;if(ymr(g))g=-1;if(ymr(h))h=1;if(ymr(i))i=false;var m={treeId:c,"treeNodeJSonClick1":d,"treeNodeJSonClick2":e,"bindFieldName":f,"entId":g,"formType":h,"hideTree":i};var n="/WebServices/Control/Control.asmx/GetSuperTreeHtmlByTreeId";$.ajax({type:"POST",contentType:"application/json; charset=utf-8",url:n,data:JSON2.stringify(m),dataType:'json',beforeSend:function(a){},complete:function(a,b){},error:function(a){art.VLdialog.alert("获取主页信息失败。详情："+JSON2.stringify(a),function(){},668,"提示");return false},success:function(a){a=hmy(a);if(a==null){art.VLdialog.alert("获取树HTML失败！",function(){},8,"提示");return false}
if(a.IsOK==false){art.VLdialog.alert(a.ErrorMsg,function(){},8,"提示");return false}
if(!ymr(j)){j(a.ReturnValue,c)}
l=a.ReturnValue;AddFriend.ntp.html(l);AddFriend.ntp.find("#selector22").css({"border-width":"0px"}).children(":first").hide();AddFriend.ntp.find("span.spicon-unfold").hide();AddFriend.ntp.find("span.spicon-fold").hide();AddFriend.ntp.find("#sptree_searchbox22").hide();var b=AddFriend.ntp.find(".dscroll");b.height(217).width(187).children(":first").height(217).width(187);Dcx.Utility.cdt(true)}})}
function sbr(){if(ymr(AddFriend.AddingUser)||AddFriend.AddingUser.length<1){art.VLdialog.tips("您还未选择好友。",2);return false}
if(ymr(AddFriend.GroupId)||isNaN(AddFriend.GroupId)||AddFriend.GroupId<1){art.VLdialog.tips("您还未选择分组。",2);return false}
var h={"groupId":AddFriend.GroupId,"friends":AddFriend.AddingUser};var j="/WebServices/WebIM/WebIM.asmx/ncv";$.ajax({type:"POST",contentType:"application/json; charset=utf-8",url:j,data:JSON2.stringify(h),dataType:'json',beforeSend:function(a){},complete:function(a,b){},error:function(a){art.VLdialog.alert("保存好友失败。详情："+JSON2.stringify(a),function(){},668,"提示");return false},success:function(a){a=hmy(a);if(a==null){art.VLdialog.alert("保存好友失败！",function(){},8,"提示");return false}
if(a.reObj.IsOK==false){art.VLdialog.alert(a.reObj.ErrorMsg,function(){},8,"提示");return false}
var b=AddFriend.AddingUser;var c=AddFriend.poq;if(ymr(AddFriend.LinkMans))AddFriend.LinkMans=new Array();try{for(var i=0;i<b.length;i++){var d=b[i].UserId;var f=b[i].UserName;var g={};g.CreatorId=c;g.GroupId=groupId;g.UserId=d;g.UserName=f;AddFriend.LinkMans.push(g);AddFriend.ako.children().children("div[val='"+d+"']:first").addClass("item-selected2").attr("isAdded","1")}
AddFriend.AddingUser=new Array()}catch(e){AddFriend.AddingUser=new Array()}
art.VLdialog.tips("保存成功！",2)}})}