﻿// JScript 文件
//显示表情列表框
function www()
{
}
function CloseTools(touin)
{
if($("divface"+touin)!=null)
{
Element.hide("divface"+touin);
}
if($("divimg"+touin)!=null)
{
Element.remove("divimg"+touin);
}     
if($("divfile"+touin)!=null)
{
Element.remove("divfile"+touin);
}
}
function getshowface(touin,flag)
{
if($("divface"+touin)==null)
{
var strface="<div id='divface"+touin+"' class=\"model_div01\" style=\"width:367px;height:183px;position:absolute;margin-top:-190px; margin-left:-50px;z-index:"+(index+1)+";\">"
+"<div class=\"model_div02\" style=\"height:17px;\" id='divfacetitle"+touin+"'>"
+"<div class=\"model_div03\">发送表情</div>"
+"<div class=\"model_div04\"><img src=\"/web/mymanage/img/close_button.gif\" border=0 onclick='closeGusetFace(\""+touin+"\");'  alt=\"关闭\" style=\"cursor:hand\"></div>"
+"</div>"
+"<div id='divface_m"+touin+"' style=\"float:left\"></div>"
+"</div>";  
new Insertion.Top("divfriendtool"+touin,strface);    
if(flag !="1"){
$("divface"+touin).style.marginLeft=-$("divface"+touin).offsetWidth+35+"px";;
$("divface"+touin).style.marginTop=-$("divface"+touin).offsetHeight-25+"px";   
}else{      
$("divface"+touin).style.marginLeft=$("divface"+touin).offsetWidth-200+"px";;
$("divface"+touin).style.marginTop=-$("divface"+touin).offsetHeight-25+"px";   
}
getface(1,touin);
}
else
{
Element.show("divface"+touin);
}     
}
function getface(j,touin)
{
var url="/web/Dynamic/GetFace.aspx?m="+j+"&touser="+touin+"&temp="+Math.random();
new Ajax.Request(url,{
method:"GET",
onComplete:function(xmlhttp){
var html=xmlhttp.responseText;        
if(!html || html.length==0)
{

}
else
{                                
$("divface_m"+touin).innerHTML=html;             
}
}
});     
}
//e是插入表情内容
function insertface(e,content,touin)
{
var oImg=document.createElement("IMG");
oImg.src="/web/face/"+e+".gif";
$("txtSendMessage"+touin).appendChild(oImg);
Element.hide("divface"+touin);
$("txtSendMessage"+touin).focus();
}
//隐藏游客表情框
function closeGusetFace(touin)
{
Element.hide("divface"+touin);
}
//插入图片
function toinsertimg1(touin){
if($("divimg"+touin)==null)
{  
var str="<div id='divimg"+touin+"' onmousedown='getFocus(\"divimg"+touin+"\");' class='model_div01' style='width:520px;height:300px;position: absolute; z-index:"+(index+1)+";'><div class='model_div02' style='height:17px;'  onmousedown='startDrag(this)' onmouseup='stopDrag(this)' onmousemove='drag(this)' id='divimgtitle"+touin+"'>"
+"<div class='model_div03'>插入图片</div><div class='model_div04'><img src='/web/mymanage/img/close_button.gif' border=0 onclick='Element.remove(\"divimg"+touin+"\");' alt='关闭' style='cursor:hand'></div></div><iframe width='100%'  height='400px' name='ifimg"+touin+"' id='ifimg"+touin+"' frameborder='0' scrolling='no' ></iframe></div>";
document.body.insertAdjacentHTML("beforeEnd",str);
$("divimg"+touin).style.left=event.offsetY+200;
$("divimg"+touin).style.top=event.offsetY+document.documentElement.scrollTop+50 ;  
$("ifimg"+touin).src="/web/mymanage/insetimg.aspx?touin="+touin;
if($("divface"+touin)!=null)
Element.hide("divface"+touin);
}
else
{
Element.show("divimg"+touin);
}
}
var myuin="";
var myusername="";
var mymenh_mingc="";
//发送文件
function showfile(tonick,todt,touin)
{
var strCookie=document.cookie;
var arrCookie=strCookie.split("; ");
for(var i=0;i<arrCookie.length;i++){
var arr=arrCookie[i].split("=");
if("uin"==arr[0]){
myuin=arr[1];
}
if("username"==arr[0]){
myusername=arr[1];
}
if("menh_mingc"==arr[0]){
mymenh_mingc=arr[1];
}
}
if(myuin==""||myuin==null){
alert("您没有登陆！无法使用此功能！");
addlogin();
}else{
if($("divfile"+touin)==null)
{
var strfile="<div id='divfile"+touin+"' class=\"model_div01\" style=\"width:360px;height:100px;position: absolute;z-index:"+(index+1)+";\">"
+"<div class=\"model_div02\" style=\"height:17px;\" id='divfiletitle"+touin+"'>"
+"<div class=\"model_div03\">发送文件</div>"
+"<div class=\"model_div04\"><img src=\"/web/mymanage/img/close_button.gif\" border=0 style='cursor:hand' alt='关闭' onclick='Element.remove(\"divfile"+touin+"\");'></div>"
+"</div><div style=\"float:left\" class=\"model_div05\" ><iframe id='mainFrame"+touin+"' width='360px' height='100px' marginwidth='0'  border=0  marginheight='0'  scrolling='no' /></div></div>";
document.body.insertAdjacentHTML("beforeEnd",strfile);    
$("divfile"+touin).style.left=document.body.scrollLeft+event.clientX-event.offsetX;
$("divfile"+touin).style.top=document.documentElement.scrollTop+event.clientY-event.offsetY-125;        	
if($("divface"+touin)!=null)
Element.hide("divface"+touin);
//插入一个框架 
$("mainFrame"+touin).src="/web/gateway/upload.aspx?fromuin="+myuin+"&touin="+touin+"&fromnick="+mymenh_mingc+"&tonick="+tonick+"&todt="+todt+"&dt="+dt;
} 
}
}
// 发送消息			
function sendMessage(touin,tonick,todt,adID)
{
// 消息内容输入框
var ta_content = $("txtSendMessage"+touin);				
var temp_content=ta_content.innerHTML;  
// 如果输入内容不为空
if(temp_content.strip()=="")
{
CreateDiv("内容不能为空");
return;
}
else if (temp_content.strip().length > 300)
{
alert("对不起，您发送的内容太长！");
}
else
{
// 消息显示区域
if (adID==null || adID=="undefined")
{
adID="0";
}		  
// 发送消息
AjaxSendMessage(uin,touin,temp_content,fromnickname,tonick,dt,todt,adID);   	
}
}
//发送好友之间的信息
function AjaxSendMessage(uin,touin,temp_content,fromnickname,tonick,dt,todt,adID)
{      
var div_recentMsg = $("recentMsg"+touin);	
var today = new Date();	
temp_content=temp_content.replace("[img]","<img src=");
temp_content=temp_content.replace("[/img]","></img>");		   	
var time=today.toLocaleTimeString();			
// 清空输入框
var oneMsg=document.createElement("div");				
// 显示样式		
oneMsg.innerHTML = "<div class=\"siliao_middle_textb\">"
+"<div style=\"float:left;\">"+fromnickname+"：</div>"
+"<div style=\"float:left;padding-left:3px;\">"+time+"</div>"
+"</div>"
+"<div class=\"siliao_middle_text\">" + temp_content + "</div>";
// 附加到DOM
div_recentMsg.appendChild(oneMsg);	
// 页面跟随输入框滚动
div_recentMsg.scrollTop = div_recentMsg.scrollHeight;				
// 获取新消息					
$("txtSendMessage"+touin).innerHTML = "";	           
temp_content=escape(temp_content);   
var url="WebImMessage.ashx?uin="+uin+"&touin="+touin+"&fromnick="+fromnickname+"&tonick="+tonick+"&dt="+dt+"&todt="+todt+"&content="+temp_content+"&flag=0&type="+adID+"&temp="+Math.random();
Request.sendGET(url, "spanmsg"+touin, doSearchFriendsRes,true, doSearchFriendsFail);          
$("spanmsg"+touin).innerHTML="正在发送信息......";  

}
//判断好友之间是否有新消息
var Msghandle;
var MsgXml="";
function BoolFrendsNewMsg(uin,dt)
{      
//if($("divmsgwin")==null)
//{
//var strmsg= "<div id='divmsgwin' >"
//+"<div style=\"padding-top:4px;padding-left:2px;float:left;\"><font style=\"font-size: 22px;font-family: 华文行楷;color:#132c7c;\">交流</font><font style=\" color:#3863a8;font-weight:bold;\">新消息</font></div>"
//+"<div style=\"float:right;padding-right:5px;padding-top:5px;\" onclick='start(\"1\")'><img  style='cursor:hand' src=\""+imgurl+"image/xiaoxi_close.gif\" width=\"11\" height=\"11\" /></div>"
//+"<div class=\"xiaoxi_content\">"

//+"<div style=\"width:100%;margin-top:5px;\">"
//+"<div style=\"float:left;\">"
//+"<div style=\"float:left;padding-left:10px;\"><img src=\""+imgurl+"image/gif-0372.gif\"  /></div>"
//+"<div style=\"float:left;padding-left:5px;color:#fc1eb0;\">新消息:</div>"
//+"</div>"
//+"<div style=\"float:right;\">"
//+"<div style=\"float:left;padding-right:5px;\"><img src=\""+imgurl+"image/xiaoxi_tix.gif\" width=\"14\" height=\"14\" /></div>"
//+"<div style=\"float:left;padding-right:10px;padding-top:2px;color:#606060;\">稍后提醒</div>"
//+"</div>"
//+"</div>"

//+"<div style=\"width:100%;margin-top:5px;\" id='divmsgwincontent'></div>"

//+"<div style=\"clear:both;\"><hr size=\"1\"  style=\"border:1px dotted #cecece;width:90%;\"/></div>"

//+"<div style=\"width:100%;color:#3692d5;\">"
//+"<div style=\"float:left;padding:0px 0px 0px 4px;\"><img src=\""+imgurl+"image/gif-0850.gif\" width=\"14\" height=\"16\" /></div>"
//+"<div style=\"float:left;padding:3px 0px 0px 3px;\">好友列表</div>"
//+"<div style=\"float:left;padding:2px 0px 0px 10px;\"><img src=\""+imgurl+"image/gif-0148.GIF\" width=\"14\" height=\"14\" /></div>"
//+"<div style=\"float:left;padding:4px 0px 0px 3px;\">主页</div>"
//+"<div style=\"float:left;padding:2px 0px 0px 10px;\"><img src=\""+imgurl+"image/xiaoxi_shezhi.gif\" width=\"14\" height=\"14\" /></div>"
//+"<div style=\"float:left;padding:4px 0px 0px 1px;\">设置</div>"
//+"</div>"
//+"</div>"
//+"</div>";
//document.body.insertAdjacentHTML("beforeEnd",strmsg); 
//var obj = $("divmsgwin");
//obj.style.height="0px";
//window.setTimeout("start(\"1\")",6000); 
//}
//AjaxBoolFrendsNewMsg(uin,dt);

}
function AjaxBoolFrendsNewMsg(uin,dt)
{            
var url="WebImMessage.ashx?uin="+uin+"&dt="+dt+"&flag=1&temp="+Math.random();
Request.sendGET(url,"divmsgwincontent",doBoolFriendsNewMsgRec,true, null);
window.setTimeout("AjaxBoolFrendsNewMsg(\""+uin+"\",\""+dt+"\")",6000);       
}
//服务器回调函数
function doBoolFriendsNewMsgRec(req,data) {

var xml= req.responseText;//服务器返回的信息显示在页面上    
if(!(xml =="||" || xml ==""))
{
var arrxml=xml.split('|');   
$(data).innerHTML=arrxml[0];  
var strfriendsmsg=arrxml[2]; 
var arrstrfriendsmsg=strfriendsmsg.split(',');
var arrmsgcounts=arrstrfriendsmsg.length-1;
for(var i=0;i<arrstrfriendsmsg.length-1;i++)
{

if($("divwinfriend"+arrstrfriendsmsg[i])!=null)
{
getNewMessage(uin,arrstrfriendsmsg[i],dt);
arrmsgcounts--;
}
else
{             
Element.show("divnewfriendmsg"+arrstrfriendsmsg[i]);
}
}
var strboolonline=arrxml[1];
var arrstrboolonline=strboolonline.split(',');
for(var j=0;j<arrstrboolonline.length-1;j++)
{	            
var mmm_arrds=arrstrboolonline[j].split(';');
if(mmm_arrds[1]=="10")
{	               
if($("friendimg"+mmm_arrds[0])!=null)
{
$("friendimg"+mmm_arrds[0]).src="/web/mymanage/img/on_line.jpg";
} 
}
else if(mmm_arrds[1]=="11")
{
if($("friendimg"+mmm_arrds[0])!=null)
{
$("friendimg"+mmm_arrds[0]).src="/web/mymanage/img/off_line.jpg";  
}  
}
}
if(xml!=MsgXml  && arrmsgcounts>=1)
{	         
start("0");
MsgXml=xml;
window.setTimeout("start(\"1\")",6000); 
}     
}
else
{
start("1");
}     
}
var msghandle;
function start(flag)
{  
var obj = $("divmsgwin");
if(flag=="0")
{
obj.style.display="block";
msghandle = setInterval("changeH('up')",2);
}
else
{
msghandle = setInterval("changeH('down')",2)    
}   
}
function changeH(str)
{  
var obj = $("divmsgwin");    
if(str=="up")
{
if (parseInt(obj.style.height)>parseInt($("divmsgwincontent").offsetHeight)+120)
{
clearInterval(msghandle);
}    
else
obj.style.height=(parseInt(obj.style.height)+4).toString()+"px";
}
if(str=="down")
{
if (parseInt(obj.style.height)<4)
{  
clearInterval(msghandle);
obj.style.display="none";
}
else        
obj.style.height=(parseInt(obj.style.height)-4).toString()+"px";    
}
}
function ChangeMsgWinPosition()
{
$("divmsgwin").style.top=(document.documentElement.scrollTop+document.documentElement.clientHeight-$("divmsgwin").offsetHeight)+"px";
$("divmsgwin").style.left=(document.documentElement.scrollLeft+document.documentElement.clientWidth-$("divmsgwin").offsetWidth)+"px";
}

// 获取最近的消息
function getNewMessage(uin,touin,dt)
{	
// 消息显示区域
var div_recentMsg = $("recentMsg"+touin);			
// 获取最新消息的数据表	
var url="WebImMessage.ashx?uin="+uin+"&touin="+touin+"&dt="+dt+"&flag=2&temp="+Math.random();
new Ajax.Request(url,{
method:"GET",
onComplete:function(xmlhttp){
var html=xmlhttp.responseText;        
if(!html || html.length==0)
{

}
else
{                                
var oneMsg=document.createElement("div");	
if(html!="")
{
oneMsg.innerHTML=html;
div_recentMsg.appendChild(oneMsg);				  
div_recentMsg.scrollTop = div_recentMsg.scrollHeight;
}		   
}
}
});			   

}
//获取系统消息
function ShowListSysMsg()
{
var strsyswin="<div id='divsystemwin' class=\"xiaoxi\" style=\"width:300px;height:auto;z-index:"+(index+1)+";position:absolute;top:0;left:0;\">"
+"<div style=\"width:100%;\" id='divsystemwintitle'  onmousedown='startDrag(this)' onmouseup='stopDrag(this)' onmousemove='drag(this)'>"
+"<div style=\"float:left;padding-left:5px;padding-top:5px;\"><img src=\"/web/mymanage/img/laba.gif\" width=\"16\" height=\"14\" /></div>"
+"<div style=\"float:left;color:#3863a8;font-weight:bold;padding-top:8px;\">系统消息</div>"
+"<div style=\"float:right;padding-right:5px;padding-top:5px;\"><img src=\""+imgurl+"image/xiaoxi_close.gif\" style='cursor:hand' onclick='Element.remove(\"divsystemwin\");' width=\"11\" height=\"11\" /></div>"
+"</div>"

+"<div class=\"xitxiaoxi\" id='dvisystemcontent' >"

+"</div>";
document.body.insertAdjacentHTML("beforeEnd",strsyswin); 
$("divsystemwin").style.left=(document.body.scrollWidth)/2;
$("divsystemwin").style.top=document.body.scrollTop+250;  
GetSystemMsg(uin,dt,"0","1","1","","0");    
}

function GetSystemMsg(uin,dt,showtype,pageCount,readPageCount,tiaoj,flag)
{

var url="WebImMessage.ashx?uin="+uin+"&dt="+dt+"&showtype="+showtype+"&tiaoj="+tiaoj+"&PageSize="+readPageCount+"&pageCount="+pageCount+"&flag=6&temp="+Math.random();
Request.sendGET(url,flag,doGetSystemMsgRec,true,null);
$("dvisystemcontent").innerHTML="正在加载消息......";
}
function doGetSystemMsgRec(req,data)
{
$("dvisystemcontent").innerHTML=req.responseText;  
if(data=="1")
{      
$("spannewmsgcounts").innerHTML=$F("hidNewMsgCounts");
$("spansysmsgcounts").innerHTML=$F("hidSysMsgCounts");
$("allpage").innerHTML=$F("hidlastCount"); 
}    
}
function showlistml(touin,tonick,todt,sysid)
{       
var str="<div id='divlistfriendml'  class='model_div01'  style='position:absolute; z-index:"+(index+1)+";width:200px; font-size:12px;'><div class='model_div02' style='height:17px;'>"
+"<div class='model_div03'>加入联系人</div><div class='model_div04'><img src='/web/mymanage/img/close_button.gif' border=0 onclick='Element.remove(\"divlistfriendml\");' alt='关闭' style='cursor:hand'></div></div><div>  请选择分组：<span id=spangroup></span></div><div><input value='确定' onclick='webchataddfriend(\""+touin+"\",\""+tonick+"\",\""+todt+"\",\""+sysid+"\");' type='button'/> <input value='取消' onclick='Element.remove(\"divlistfriendml\");' type='button' /></div></div>";
document.body.insertAdjacentHTML("beforeEnd",str);
GetUserGroup("spangroup");   
$("divlistfriendml").style.left=document.body.scrollLeft+event.clientX-event.offsetX-200;
$("divlistfriendml").style.top=document.body.scrollTop+event.clientY-event.offsetY;       
}
function webchataddfriend(touin,tonick,todt,sysid)
{        
if(uin!="")
{
var groupid = document.getElementById("friendgroup").options[document.getElementById("friendgroup").selectedIndex].value;
var url="HttpFriends.ashx?groupid="+groupid+"&uin="+uin+"&touin="+touin+"&flag=10&temp="+Math.random();
new Ajax.Request(url,{
method:"GET",
onComplete:function(xmlhttp){
var html=xmlhttp.responseText;       
if(html=="1")                    
{
var content=fromnickname+"接受了您的添加请求并添加您为联系人。";
var mcontent="您已经将“"+tonick+"”添加为联系人";
updateSys(touin,tonick,todt,sysid,mcontent);  
var status="0";                                            
var m_url="WebImMessage.ashx?uin="+uin+"&touin="+touin+"&fromnick="+fromnickname+"&tonick="+tonick+"&dt="+dt+"&todt="+todt+"&content="+content+"&flag=3&type=2&temp="+Math.random();
Request.sendGET(m_url,"", null,true,null);                                                    
var strpage="";
var m_flag="<span id='guanz" + touin + "' style='color:red'></span><span id='sharing" + touin + "' style='color:blue'></span>";
if(status=="1")
{
strpage="<div class=\"jl_online_zu2\"  id='divuser" + touin + "'>"
+ "<div style=\"float:left;margin:2px 0px 0px 15px;width:16px;\"><img onmouseout='close_UserInfo(\"" + touin + "\")' id='friendimg" + touin + "' onmouseover='getUserinfo(\"" + touin + "\");' src=\"/web/mymanage/friends/skin/default/image/online_6.gif\" width=\"16\" height=\"15\"/></div>"
+ "<div class=\"jl_online_zi\" ondblclick='SendFriendsWin(\"" + touin + "\",\"" + tonick + "\",\"" + todt + "\")' onmousedown='LeftFriendsWin(\"" + touin + "\",\"" + tonick + "\",\"" + groupid + "\",\"" + todt + "\")'  style=\"margin:7px 0px 0px 0px;cursor:default;\">" + tonick + " " + m_flag + "</div>"
+ "</div><div class=\"body_bg\" id='divuserinfo" + touin + "' style='position:absolute;display:none;left:0px;top:0px;'></div>";
}
else
{
strpage="<div class=\"jl_online_zu2\"  id='divuser" + touin + "'>"
+ "<div style=\"float:left;margin:2px 0px 0px 15px;width:16px;\"><img onmouseout='close_UserInfo(\"" + touin + "\")' id='friendimg" + touin + "' onmouseover='getUserinfo(\"" + touin + "\");' src=\"/web/mymanage/friends/skin/default/image/online_6.gif\" width=\"16\" height=\"15\"/></div>"
+ "<div class=\"jl_online_zi\" ondblclick='SendFriendsWin(\"" + touin + "\",\"" + tonick + "\",\"" + todt + "\")' onmousedown='LeftFriendsWin(\"" + touin + "\",\"" + tonick + "\",\"" + groupid + "\",\"" + todt + "\")'  style=\"margin:7px 0px 0px 0px;cursor:default;\">" + tonick + " " + m_flag + "</div>"
+ "</div><div class=\"body_bg\" id='divuserinfo" + touin + "' style='position:absolute;display:none;left:0px;top:0px;'></div>";
}
new Insertion.Bottom("divfriends"+groupid,strpage); 
} 
else if(html=="-1")
{
CreateDiv("不能自己添加自己");

}   
else
{
CreateDiv("添加失败！或者你以添加该好友。");
}  
Element.remove("divlistfriendml");

}  

});
}


} 
//更改信息的状态
function updateSys(touin,tonick,todt,sysid,content)
{
var mm_url="WebImMessage.ashx?uin="+uin+"&dt="+dt+"&sysid="+sysid+"&flag=5&type="+content+"&temp="+Math.random();     
Request.sendGET(mm_url,"", null,true,null);
}                      
function updatesysflag(touin,tonick,todt,sysid)
{
var content=+"“"+fromnickname+"”拒绝你的添加联系人请求。";
var mcontent="您拒绝 “"+tonick+"” 的添加请求。";
var m_url="WebImMessage.ashx?uin="+uin+"&touin="+touin+"&fromnick="+fromnickname+"&tonick="+tonick+"&dt="+dt+"&todt="+todt+"&content="+content+"&flag=3&type=2&temp="+Math.random();
Request.sendGET(m_url,"", null,true,null);   
updateSys(touin,tonick,todt,sysid,mcontent);   
} 
//得到好友的聊天记录
function GetAllFreindMsg(touin,m)
{
if(document.getElementById("oldMsg"+touin).style.display=="")
{
Element.hide("oldMsg"+touin); 
}
else
{
Element.show("oldMsg"+touin);  
MM_GetAllFreindMsg(touin,m);        
}
} 
function MM_GetAllFreindMsg(touin,m)
{
var url="WebImMessage.ashx?uin="+uin+"&touin="+touin+"&dt="+dt+"&pagecount="+m+"&flag=7&temp="+Math.random();
Request.sendGET(url,"oldMsg"+touin, doSearchFriendsRes,true,doSearchFriendsRes); 
$("oldMsg"+touin).innerHTML="正在加载信息......";  
} 
function SendSms(touin)
{
window.open("send_sms.aspx?flag="+touin);
}
function SendFax(touin)
{
window.open("postfax.aspx?flag="+touin); 
}
function receiveFile(id,todt,tonick,touin,filename)
{
AjaxSendMessage(uin,touin,fromnickname+"接受了<font color='red'> “"+filename+"” </font>文件",fromnickname,tonick,dt,todt);
var url="WebImMessage.ashx?uin="+uin+"&touin="+touin+"&fromnick="+fromnickname+"&tonick="+tonick+"&dt="+dt+"&todt="+todt+"&id="+id+"&flag=8&temp="+Math.random();
Request.sendGET(url, "", null,true, null);     
}
function RejectionFile(id,todt,tonick,touin,filename)
{     
AjaxSendMessage(uin,touin,fromnickname+"拒绝了<font color='red'> “"+filename+"” </font>文件",fromnickname,tonick,dt,todt);
var url="WebImMessage.ashx?uin="+uin+"&touin="+touin+"&fromnick="+fromnickname+"&tonick="+tonick+"&dt="+dt+"&todt="+todt+"&id="+id+"&flag=8&temp="+Math.random();
Request.sendGET(url, "", null,true, null);  
}