
var ImMsg={PageIndex:1,PageSize:100,PageCount:0,RealPageIndex:0,UrlUserId:0,lxp:0,pwm:"/images/common/room2.png",bby:"/images/common/room4.png",hri:null};ImMsg.akl=null;$(document).ready(function(){ImMsg.NameCards={}});$(window).load(function(){var b=tzm("userId");if(ymr(b)||isNaN(b)||parseInt(b,10)<1)b=0;else b=parseInt(b,10);if(b>0)ImMsg.UrlUserId=b;b=tzm("roomId");if(ymr(b)||isNaN(b)||parseInt(b,10)<1)b=0;else b=parseInt(b,10);if(b>0)ImMsg.lxp=b;ImMsg.hri=$("#contactsContainer");ImMsg.mqw=$("#div_msgList");ImMsg.pba=$("#groupName");ImMsg.ehc();ImMsg.akl=$("#div_msgPage");ImMsg.akl.hide();ImMsg.bgi=$("#btn_deleteAll");ImMsg.bgi.hide();ImMsg.nmt=$("#a_curPage");ImMsg.zre=ImMsg.nmt.prev();var c=$.browser.msie?"mouseenter":"mouseover";var d=$.browser.msie?"mouseleave":"mouseout";ImMsg.nmt.unbind(c).bind(c,function(){ImMsg.nmt.prev().show()});$(document).mouseup(function(a){ImMsg.nmt.prev().hide()})});ImMsg.ehc=function(){if(!ymr(ImMsg.Friends)){return false}
var n="/WebServices/WebIM/WebIM.asmx/GetFriendsAndLinkGroup";$.ajax({type:"POST",contentType:"application/json; charset=utf-8",url:n,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("读取IM的基本信息失败。详情："+b);return false},success:function(b){var c=hmy(b);ImMsg.Friends=c.Friends;ImMsg.LinkManGroup=c.LinkManGroup;ImMsg.UserId=c.UserId;ImMsg.UserName=c.UserName;if(ymr(ImMsg.Friends)){ImMsg.Friends=new Array()}
if(ymr(ImMsg.LinkManGroup)){ImMsg.LinkManGroup=new Array()}
ImMsg.csy();if(ImMsg.UrlUserId>0){for(var i=0;i<ImMsg.Friends.length;i++){var d=ImMsg.Friends[i];if(d.UserId==ImMsg.UrlUserId&&d.RoomId==ImMsg.lxp){ImMsg.FriendId=d.UserId;ImMsg.FriendName=d.UserName;ImMsg.RoomId=d.RoomId;ImMsg.dok(null,1,null,true);return}}}
var f=new Array();for(var i=0;i<ImMsg.Friends.length;i++){var d=ImMsg.Friends[i];if(!ymr(d.LastMsg)){try{var g=JSON2.parse(d.LastMsg);g.RoomId=d.RoomId;g.RealName=d.RealName;f.push(g)}catch(e){}}}
var h=new nzy();h.append("<div class=\"all_msg_list\">\n");for(var i=f.length-1;i>=0;i--){var d=f[i];var j=d.SenderId;var k=d.SenderName;var l=jbc(j,2);if(d.RoomId<1&&ImMsg.UserId==d.SenderId){j=d.ReceiverId;k=d.ReceiverName}
if(d.RoomId>0){j=d.RoomId;k=d.RealName;l=ImMsg.pwm}
if(ymr(j))continue;h.append("<div class=\"WB_msg_type \"  userName=\""+d.ReceiverName+"\" roomId=\""+d.RoomId+"\" userId=\""+j+"\" msgId=\""+d.MsgId+"\">\n");h.append("<div class=\"msg_list_node S_line2 clearfix\" block=\"0\" black=\"0\" >\n");h.append("<div class=\"id_avatar\">\n");h.append("<img src=\""+l+"\" style=\"width:50px;height:50px;\"></div>\n");h.append("<div class=\"msg_main\">\n");h.append("<div class=\"W_f14 W_fb msg_title\">\n");if(ImMsg.UserId==d.SenderId)h.append("发给 "+d.ReceiverName+" ：\n");else h.append(d.SenderName+" ：\n");h.append("</div>\n");h.append("<div class=\"W_f14 msg_detail S_txt2\">\n");h.append(""+d.MsgContent+" \n");h.append("</div>\n");h.append("</div>\n");h.append("<div class=\"msg_ctrls\">\n");var m=d.SentDate;if(typeof(m)=="object"){m=Dcx.Date.lvk(m.__Value);m.setHours(m.getHours()-8)}
h.append("<span class=\"S_txt2\">"+Dcx.Date.obi(m)+"</span>\n");h.append("<a href=\"javascript:void(0);\" class=\"W_ico12 icon_choose\" ></a>\n");h.append("</div>\n");h.append("</div>\n");h.append("</div>\n")}
h.append("</div>\n");ImMsg.pba.html("最新聊天记录");ImMsg.mqw.html(h.toString());ImMsg.mqw.find("div.WB_msg_type").unbind("click").bind("click",function(){var a=$(this);ImMsg.FriendId=parseInt(a.attr("userId"),10);ImMsg.FriendName=a.attr("userName");ImMsg.RoomId=parseInt(a.attr("roomId"),10);ImMsg.dok(null,1,null,true)})}})};ImMsg.qmn=function(a){var b=$(a).parent();if(b.hasClass("list_box_fold")){b.removeClass("list_box_fold").addClass("clearfix")}else{b.addClass("list_box_fold").removeClass("clearfix")}};ImMsg.csy=function(){if(ImMsg.hri.attr("hasLoad")=="1")return true;if(ymr(ImMsg.Friends)){return}
if(ymr(ImMsg.LinkManGroup)){return}
var a=ImMsg.Friends;var b=ImMsg.LinkManGroup;var c=new nzy();b.push({"GroupId":0,"GroupName":"临时会话"});b.push({"GroupId":-1,"GroupName":"讨论组"});for(var i=0;i<b.length;i++){var d=new nzy();var e=b[i];d.append("<div class=\"list_box "+(i==0?"":"list_box_fold")+" clearfix\" nodehid=\"maxListRoot\" groupId=\""+e.GroupId+"\" >\n");d.append("<div class=\"list_title\" nodehid=\"maxListTitleContainer\"  onclick=\"javscript:ImMsg.qmn(this);\" >\n");d.append("<p class=\"title_cate\">\n");d.append("<a title=\""+e.GroupName+"\" nodehid=\"maxUserListTitle\" href=\"javascript:void(0);\" onclick=\"return false;\" class=\"list_title_a\"><span class=\"WB_webim_arrow\"><em class=\"down\">◆</em></span>\n");var f=ImMsg.riy(e.GroupId,a);if(ymr(f))f={friendCount:0,onlineCount:0,strHtml:""};d.append("<span nodehid=\"maxListTitleNode\" style=\"margin-left: 5px;\">"+e.GroupName+"</span> (<span nodehid=\"maxListOnlineCount\">"+f.onlineCount+"/"+f.friendCount+"</span>)</a></p>\n");d.append("</div>\n");d.append("<div class=\"list_content\" style=\"padding-left:15px;\">\n");d.append("<ul class=\"list_content_li\" nodehid=\"maxListContainer\">\n");d.append(f.strHtml);d.append("</ul>\n");d.append("</div>\n");d.append("</div>\n");if(b[i].GroupId>0||(b[i].GroupId<=0&&f.friendCount>0))c.append(d.toString())}
ImMsg.hri.html(c.toString())};ImMsg.riy=function(a,b){var c={friendCount:0,onlineCount:0,strHtml:""};if(ymr(b))return c;var d=0;var e=0;var f=new nzy();for(var k=0;k<b.length;k++){if(a<0&&b[k].RoomId<1)continue;if(a>0&&b[k].GroupId!=a)continue;if(a==0&&(b[k].GroupId!=a||b[k].RoomId>0))continue;var g=b[k];var h=null;if(b[k].RoomId>0){h=ImMsg.bby;g.UserName=g.RealName}else h=jbc(g.UserId,3);f.append("<li class=\"clearfix\" UserId=\""+g.UserId+"\"  UserName=\""+g.UserName+"\" RoomId=\""+g.RoomId+"\" onclick=\"javscript:ImMsg.dok(this);\" >\n");f.append("<div class=\"webim_list_head webim_head_30\">\n");f.append("<span class=\"head_pic\">\n");f.append("<img class=\"webimcexr_item_img\" src=\""+h+"\" width=\"30\" height=\"30\" title=\""+g.UserName+"\" />\n");f.append("</span>\n");f.append("<span class=\"W_chat_stat ");if(b[k].RoomId<1&&g.IsOnLine){e++;f.append("W_chat_stat_online\"></span>\n")}else f.append("W_chat_stat_offline\"></span>\n");f.append("<span class=\"WBIM_icon_dev WBIM_icon_#{resource}\"></span>\n");f.append("<span class=\"WBIM_icon_new\"></span>\n");f.append("</div>\n");f.append("<div class=\"webim_list_name\">\n");f.append("    <span class=\"user_name\">"+g.UserName+"</span>&nbsp; \n");f.append("</div>\n");f.append("</li>\n");d++}
if(d<1){f.append("<li style=\"display: none;\"></li>\n");f.append("<li style=\"display: none;\"></li>\n")}
c.friendCount=d;c.onlineCount=e;c.strHtml=f.toString();return c};ImMsg.dok=function(c,d,e,f){var g=-1;var h=null;var i=-1;if(!ymr(c)){g=parseInt($(c).attr("UserId"),10);i=parseInt($(c).attr("roomId"),10);h=$(c).attr("UserName");ImMsg.FriendId=g;ImMsg.FriendName=h;ImMsg.RoomId=i;ImMsg.PageIndex=1;ImMsg.Count=-1;f=true}else{g=ImMsg.FriendId;h=ImMsg.FriendName;i=ImMsg.RoomId;if(f==undefined)f=false}
if(!ymr(d)&&!isNaN(d))ImMsg.PageIndex=d;ImMsg.bgi.show();if(ImMsg.RoomId>0)ImMsg.bgi.find("a[btntype=1]").find("span").html("清除讨论组的聊天记录");else ImMsg.bgi.find("a[btntype=1]").find("span").html("清除和Ta的聊天记录");var j={"pageIndex":ImMsg.PageIndex,"friendId":g,"friendName":h,"getCount":f};var k="/WebServices/WebIM/WebIM.asmx/dok";if(i>0){k="/WebServices/WebIM/WebIM.asmx/GetRoomMessage";j={"pageIndex":ImMsg.PageIndex,"roomId":i,"getCount":f}}
$.ajax({type:"POST",contentType:"application/json; charset=utf-8",url:k,data:JSON2.stringify(j),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("读取IM的基本信息失败。详情："+b);return false},success:function(a){a=hmy(a);ImMsg.Messages=a.MsgList;if(a.Count>-1)ImMsg.Count=a.Count;if(ymr(ImMsg.Messages)){ImMsg.Messages=new Array()}
ImMsg.pba.html(h);ImMsg.sly();if(ImMsg.PageIndex<2&&f){ImMsg.tmc(ImMsg.PageIndex)}}})}
ImMsg.sly=function(){var a=ImMsg.FriendId;var b=ImMsg.FriendName;var c=ImMsg.RoomId;var d=new nzy();var e=jbc(ImMsg.FriendId,2);var f=jbc(ImMsg.UserId,2);for(var i=ImMsg.Messages.length-1;i>=0;i--){var g=ImMsg.Messages[i];var h=g.SenderId;var l=g.SenderName;var m=e;if(g.RoomId>0){m=jbc(g.SenderId,2)}
var n="private_SRLl";var o="<a username=\""+g.SenderName+"\" title=\""+g.SenderName+"\" namecard=\""+g.SenderId+"\" href=\"/vonlegogo\">"+g.SenderName+"</a>";if(ImMsg.UserId==g.SenderId){n="private_SRLr";m=f;o="我"}
d.append("<div class=\""+n+" clearfix msgobj\" userId=\""+g.SenderId+"\" msgId=\""+g.MsgId+"\" >\n");d.append("<div class=\"face\">\n");d.append("<a title=\"\" href=\"javascript:void(0);\">\n");d.append("<img src=\""+m+"\" style=\"width:50px;height:50px;\" /></a></div>\n");d.append("<div class=\"S_line2 "+(ImMsg.UserId==g.SenderId?"S_bg1":"S_bg5")+" content \">\n");var k=i;for(;k>=0;k--){var p=ImMsg.Messages[k];if(k!=i&&h!=p.SenderId){break}
if(k!=i)d.append("<div class=\"W_linedot S_line2\"></div>\n");d.append("<div class=\"R_msg\" msgId=\""+p.MsgId+"\">\n");d.append("<div class=\"private_operate clearfix\">\n");d.append("<div class=\"close\" style=\"\">\n");d.append("<a href=\"javascript:void(0);\" onclick=\"javascript:ImMsg.ptv("+p.MsgId+");\" title=\"删除\" class=\"hover W_ico12 icon_close\" ></a>\n");d.append("</div>\n");d.append("<div class=\"op_cbox\" style=\"display: none;\">\n");d.append("<input type=\"checkbox\" class=\"W_checkbox\">\n");d.append("</div>\n");d.append("<div class=\"txt\" >\n");d.append("<lable>"+o+"："+p.MsgContent+" </lable>\n");d.append("</div>\n");d.append("</div>\n");d.append("<div class=\"private clearfix\">\n");d.append("<div class=\"piclist WB_feed\"> \n");if(!ymr(p.FileJson)){var q=null;try{q=eval("("+p.FileJson+")")}catch(err){}
if(!ymr(q)&&q.length==undefined){var r=new Array();r.push(q);q=r}
if(!ymr(q)&&q.length>0){var s=new nzy();var t=new nzy();s.append("<ul class=\"WB_media_list clearfix\" style=\"\">\n");s.append("<li>\n");s.append("<div class=\"list_pic_list out_width\" style=\"height: 115px;\">\n");s.append("<ul class=\"pic_list clearfix inner_width\">\n");t.append("<ul class=\"WB_media_list clearfix\" style=\"padding: 0px 0 5px;\">\n");t.append("<li>\n");t.append("<div class=\"list_pic_list2 \">\n");t.append("<ul class=\"filecell unselect pic_list clearfix inner_width\">\n");var u=false;var v=false;for(var j=0;j<q.length;j++){var w=q[j];if(w.FileTypeId!=2){t.append("<li class=\"filecolumn\" "+($.browser.msie?"onmouseleave='javascript:pcq(this,false);'  onmouseenter='javascript:pcq(this,true);'":"")+" fileId=\""+w.FileId+"\" MsgId=\""+p.MsgId+"\" >\n");t.append("<a class=\"f_type f_type_single\"><span class=\""+Dcx.ryk(w.FileTypeId)+"\" unselectable=\"on\"></span></a>\n");t.append("<div class=\"filedetail\" data-columnselect=\"1\">\n");t.append("<div onclick=\"Attach.rename(this);getTop().stopPropagation(event);\" class=\"filename\" >"+w.FileName+"</div>\n");t.append("<p class=\"graytext datasize\" data-columnselect=\"1\">"+Dcx.Utility.ucr(w.FileSize)+"</p>\n");t.append("</div>\n");t.append("<div class=\"operation\" onclick=\"\">\n");t.append("<ul class=\"btn_operation\">\n");t.append("<li><a class=\"ico_attach ico_odown\" title=\"下载\" onclick=\"Dcx.ped('"+escape(w.FilePath)+"',"+w.FileId+")\"></a></li>\n");t.append("<li><a class=\"ico_attach ico_ostar\" title=\"删除\" onclick=\"Dcx.DeleteFile('"+escape(w.FilePath)+"',"+w.FileId+")\"></a></li>\n");t.append("</ul>\n");t.append("</div>\n");t.append("</li>\n");v=true}else{s.append("<li fileId=\""+w.FileId+"\" MsgId=\""+g.MsgId+"\" onclick=\"javascript:DcxComMsg.ggn(this);\">\n");s.append(" <img title=\""+w.FileName+"\" class=\"bigcursor\" src=\""+Dcx.File.trv(w.FilePath)+"\">");s.append("</li>\n");u=true}}
s.append("</ul>\n");s.append("</div>\n");s.append("</li>\n");s.append("</ul>\n");t.append("</ul>\n");t.append("</div>\n");t.append("</li>\n");t.append("</ul>\n");if(u)d.append(s.toString());if(v)d.append(t.toString())}}
d.append("</div>\n");d.append("</div>\n");d.append("<div class=\"operation clearfix\" style=\"\">\n");d.append("<div class=\"fl\">\n");d.append("<em class=\"S_txt2  date\" href=\"\">"+Dcx.Date.mnf(p.SentDate)+"</em>\n");d.append("</div> \n");d.append("</div>\n");d.append("</div>\n")}
i=k+1;d.append("<div class=\"message_arrow\">\n");d.append("<em class=\"S_line1_c\">◆</em><span class=\""+(ImMsg.UserId==g.SenderId?"S_bg1_c":"S_bg5_c")+"\">◆</span></div>\n");d.append("</div>\n");d.append("</div>\n")}
ImMsg.mqw.html(d.toString());if(ImMsg.Messages.length<1)ImMsg.mqw.html("<p style=\"line-height: 190px; text-align: left;margin-left:200px; color: #999;font-size:15px;\" class=\"j-no-result\">没有聊天记录&nbsp;&nbsp;~_~</p>");DcxComMsg.DataList=ImMsg.Messages};ImMsg.tmc=function(a){if(ImMsg.akl==null)ImMsg.akl=$("#div_msgPage");ImMsg.akl.show();var b=ImMsg.akl;if(isNaN(a)||a<1){a=1}
var c=parseInt(ImMsg.Count/ImMsg.PageSize,10);if(ImMsg.Count%ImMsg.PageSize!=0)c=c+1;if(ImMsg.Count<1||c==1)b.hide();else b.show();ImMsg.PageCount=c;var d=50;var e=a-d;var f=a+d;if(e<1)e=1;if(f>c)f=c;var g=new nzy();for(var i=e;i<=f;i++){g.append("<a pageId=\""+i+"\"    style=\"width:50px;\"  href =\"javascript:void(0);\" onclick=\"javascript:ImMsg.uio("+i+",this);\" >第&nbsp;"+(ImMsg.PageCount-i+1)+"&nbsp;页</a>\n")}
var h=b.find("#divPageList");h.html(g.toString());h.children(":first").addClass("current");h.next().find("span").html("第&nbsp;"+ImMsg.PageCount+"&nbsp;页");if(a<2)b.find("[isPrev=1]").hide();else b.find("[isPrev=1]").show();if(c<=a)b.find("[isNext=1]").hide();else b.find("[isNext=1]").show();b.find("#divPageList").css("overflow-x","hidden");b.find("#divPageList").css("overflow-y","auto")};ImMsg.uio=function(a,b,p){var c=ImMsg.akl;if(a<1){if(p==1)ImMsg.PageIndex=ImMsg.PageIndex-1;else ImMsg.PageIndex=ImMsg.PageIndex+1;if(ImMsg.PageIndex<1){ImMsg.PageIndex=1;art.VLdialog.tips("已是第一页",1.8);return}
var d=c.find("[isPageList=1]");d.children().removeClass("current");var e=d.children("[pageId="+ImMsg.PageIndex+"]");if(e!=null&&e.length>0)e.addClass("current");c.find("[isCurPage=1]").html("第&nbsp;"+(ImMsg.PageCount-ImMsg.PageIndex+1)+"&nbsp;页")}else{ImMsg.PageIndex=a;var d=$(b).parent();d.children().removeClass("current");$(b).addClass("current");d.next().find("span").html("第&nbsp;"+(ImMsg.PageCount-a+1)+"&nbsp;页");d.hide()}
$('body,html').scrollTop(0);var f=parseInt(ImMsg.Count/ImMsg.PageSize,10);if(ImMsg.Count%ImMsg.PageSize!=0)f=f+1;if(ImMsg.PageIndex<2)c.find("[isPrev=1]").hide();else c.find("[isPrev=1]").show();if(f<=ImMsg.PageIndex)c.find("[isNext=1]").hide();else c.find("[isNext=1]").show();ImMsg.dok(null,ImMsg.PageIndex,null)}
ImMsg.ikr=function(a){for(var i=ImMsg.Messages.length-1;i>=0;i--){if(ImMsg.Messages[i].MsgId==a){return ImMsg.Messages[i];break}}}
ImMsg.ptv=function(e){var f=ImMsg.ikr(e);if(ymr(f)){art.VLdialog.tips("已删除",2);return false}
art.VLdialog.confirm('确定要删除吗？',function(){var c={"senderId":f.SenderId,"receiverId":ImMsg.UserId,"msgId":e};var d="/WebServices/WebIM/WebIM.asmx/ptv";if(f.RoomId>0){d="/WebServices/WebIM/WebIM.asmx/DeleteRoomMsg";c={"roomId":f.RoomId,"msgId":e}}
$.ajax({type:"POST",contentType:"application/json; charset=utf-8",url:d,data:JSON2.stringify(c),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){var a=hmy(a);if(!a){art.VLdialog.alert("删除消息失败");return}
art.VLdialog.tips("删除成功！",3);var b=ImMsg.mqw.find("div.msgobj[msgId="+e+"]");if(b.length>0&&b.find("div.R_msg").length<2)b.remove();b=ImMsg.mqw.find("div.R_msg[msgId="+e+"]");if(b.length>0){if(b.next().hasClass("R_msg"))b.next().remove();b.remove()}}})},function(){art.VLdialog.tips('你取消了删除')})};ImMsg.bzg=function(){if(ymr(ImMsg.FriendId)||isNaN(ImMsg.FriendId)||ImMsg.FriendId<1){art.VLdialog.tips("请先点击左边的好友，再清除",2);return false}
var c={friendId:ImMsg.FriendId};var d="/WebServices/WebIM/WebIM.asmx/bzg";if(ImMsg.RoomId>0){d="/WebServices/WebIM/WebIM.asmx/DeleteRoomAllMsg";c={"roomId":ImMsg.RoomId}}
art.VLdialog.confirm('确定要清除和Ta的聊天记录吗？',function(){$.ajax({type:"POST",contentType:"application/json; charset=utf-8",url:d,data:JSON2.stringify(c),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){var a=hmy(a);if(!a){art.VLdialog.alert("删除消息失败");return}
art.VLdialog.tips("清除成功！",3);ImMsg.mqw.html("")}})},function(){art.VLdialog.tips('你取消了清除')})};