﻿//拖动对象
var Drag={
	"obj":null,
	"init":function(a, aRoot){//初始化
			a.onmousedown=Drag.start;//鼠标按下的事件
			a.root = aRoot;//拖动条
			//默认位置
			if(isNaN(parseInt(a.root.style.left)))a.root.style.left="0px";
			if(isNaN(parseInt(a.root.style.top)))a.root.style.top="0px";
			//定义了拖动开始，正在拖动，拖动结束几个方法
			a.root.onDragStart=new Function();
			a.root.onDragEnd=new Function();
			a.root.onDrag=new Function();
		},
	"start":function(a){//拖动开始
			top.event.cancelBubble = true;//禁止事件冒泡
			var b=Drag.obj=this;//赋值
			a=Drag.fixE(a);//修正一些意外情况
			var c=parseInt(b.root.style.top);//top
			var d=parseInt(b.root.style.left);//left
			b.root.onDragStart(d,c,a.clientX,a.clientY);
			b.lastMouseX=a.clientX;//记录下最初的位置
			b.lastMouseY=a.clientY;
			top.document.onmousemove=Drag.drag;//挂载正在拖动的事件函数
			top.document.onmouseup=Drag.end;//挂载拖动结束的函数
			return false;
		},	
	"drag":function(a){//正在拖动
			a=Drag.fixE(a);//修正意外
			var b=Drag.obj;//拖动条对象
			var c=a.clientY;//记录下被拖对象的位置
			var d=a.clientX;
			var e=parseInt(b.root.style.top);//拖动条的位置
			var f=parseInt(b.root.style.left);
			var h,g;
			h=f+d-b.lastMouseX;
			g=e+c-b.lastMouseY;
			b.root.style.left=h+"px";//拖动条的新位置
			b.root.style.top=g+"px";			
			b.lastMouseX=d;//纪录下上次的鼠标位置
			b.lastMouseY=c;
			b.root.onDrag(h,g,a.clientX,a.clientY);
			return false;
		},
	"end":function(){//拖动结束			
			top.document.onmousemove=null;//把挂载的事件取消
			top.document.onmouseup=null;
			//拖动结束
			Drag.obj.root.onDragEnd(parseInt(Drag.obj.root.style.left),parseInt(Drag.obj.root.style.top));
			Drag.obj=null;//清空对象
		},
	"fixE":function(a){//修正undefined的问题
			if(typeof a=="undefined")a=top.event;//最定层窗体的 事件
			if(typeof a.layerX=="undefined")a.layerX=a.offsetX;//x轴位置
			if(typeof a.layerY=="undefined")a.layerY=a.offsetY;//y轴位置
			return a;
		}
};


// 用层显示窗口
var wndNum=0;//已经显示的窗口数目
//显示窗口
function showInfoWnd( left, top,otherid,othername) {
	if(wndNum>8)//打开的窗口数目太多，则禁止打开
	{
	myAlert("对不起,同一时刻你最多只能打开8个聊天窗口!请先关闭一个.");
	return;
	}
	wndNum++;//窗口数目加一
	var div = self.top.document.createElement("div");
	div.id = "infoSys"+wndNum;//id
	var html =""; //窗口字符串
if(arguments.length==4)//两人聊天的窗口
{
    //构造字符串
    html ='<div> <table width="420" height="420"  border="0" cellspacing="0" cellpadding="0">\
    <tr><td colspan="5"><iframe id ="me" frameborder=0 scrolling=no width=420 height=420 '; 
    html +='src=\"../chat/chat.aspx?otherid='+ otherid +'&othername='+ escape(othername) ;
    html += '\"></iframe></td> </tr></table>\
    <div style=\" position:absolute ; left :';
    html += (left-175+';top:'+(top-92)+'; width: 300px; height: 27px;font-size:12px;cursor:pointer\">与'+
    othername+'聊天中.....</div></div>');
}

	div.innerHTML = html;//设置内部html
	div.style.position = "absolute";//绝对位置
	div.style.left = left+"px";
	div.style.top = top+"px";
	div.onmousedown = function() { window.event.cancelBubble=false;};//屏蔽鼠标按下的冒泡事件
	self.top.document.body.appendChild(div);//添加上这个窗体
	Drag.init(div, div);//允许拖动
}
//显示两人对聊和群聊的窗口
function getChatWnd(otherid,othername)
{
if(arguments.length==2)//对聊
  showInfoWnd(200,100,otherid,othername);

}
//关闭窗口
function closeInfoWnd(name) {
	try {
		div = top.document.getElementById(name);//找到这个窗口
		if (div) {
			top.document.body.removeChild(div);//移除
			delete div;
			div = null;
			if(name.split(0,7)[0]=="infoSys")
			wndNum--;//窗口数目减一
		}
	} catch(E) {}
}

//成功后的回调函数
function doSendMessageRes(req, data) {
	myAlert("操作成功");
	top.frames('chatqq').closeInfoWnd('friendwnd');
}
//失败后的回调函数
function doSendMessageFail(req, data) {
	myAlert("操作失败");
		top.frames('chatqq').closeInfoWnd('friendwnd');
}
//显示聊天记录
function getsys(name,isgroup)
{
//产生一个元素
    var div = top.document.createElement("div");
	div.id = "Sysmsg";
//构造字符串
	var html =' <table width="100%" height="450"  border="0" cellspacing="0" cellpadding="0">\
  <tr><td ><iframe frameborder=0 scrolling=no width=600 height=450 '; 
 //显示自己的聊天记录
if(arguments.length==0)
    html +='src=\"msgrecord.aspx'+"?rnd="+10000*Math.random()+"\"";
 //显示和某人的聊天纪录   
if(arguments.length==1)
    html +='src=\"msgrecord.aspx?othername='+escape(name)+"&rnd="+10000*Math.random()+"\"";
 //显示群的聊天纪录     
if(arguments.length==2)
    html +='src=\"msgrecord.aspx?groupid='+name+"&rnd="+10000*Math.random()+"\"";
  //字符串构造完成
    html += '></iframe></td> </tr></table>';
 //设置一些属性	
	div.innerHTML = html;
	div.style.position = "absolute";
	div.style.left = 260+"px";
	div.style.top = 90+"px";
	div.style.width=600+"px";
	div.style.height= 450+"px";
	div.onmousedown = function() { top.event.cancelBubble=false;};
	top.document.body.appendChild(div);
	Drag.init(div, div);//可以拖动
}
//显示用户的详细资料
function getdetail(userid,username)
{
var div = top.document.createElement("div");
	div.id = "Sysmsg";
	//字符串
	var html =' <table width="530" height="450"  border="0" cellspacing="0" cellpadding="0">\
  <tr><td ><iframe frameborder=0 scrolling=no id = mydetail width=530 height=450 '; 
if(arguments.length==1)//显示特定人的详情
    html +='src=\"detail.aspx?userid='+userid;
if(arguments.length==0) //显示自己的详情   
    html +='src=\"detail.aspx';
if(arguments.length==2)//显示黑名单中的某人的详情
    html +='src=\"detail.aspx?type=black&userid='+userid+"&username="+escape(username);
    html += '\"></iframe></td> </tr></table>';
//设置一些参数	
	div.innerHTML = html;
	div.style.position = "absolute";
	div.style.left = 300+"px";
	div.style.top = 100+"px";
	div.style.width=530+"px";
	div.style.height= 450+"px";
	div.onmousedown = function() { top.event.cancelBubble=false;};
	top.document.body.appendChild(div);
	Drag.init(div, div);//初始化拖动
}
//创建一个群
function createG(gname,gnotes)
{
//构造url字符串
url = "createg.ashx?rnd="+10000*Math.random()+"&gname="+escape(gname)+"&gnotes="+escape(gnotes);
//发出请求
Request.sendPOST(url, "", doSendMessageRes,true, doSendMessageFail);
//加载的提示
top.document.getElementById("friendwnd").innerHTML = "<br /><br /><br />正在提交请求,请稍后.......";
}
// 显示创建群的窗口
function createGroupWnd()
{
	var div = top.document.createElement("div");
	div.id = "friendwnd";
//构造字符串
	var html = "<iframe id = 'friendmy' frameborder=0 style ='display:none' scrolling=no src=\"about:blank\"></iframe><img src=\"images/c.gif\" onclick=\"top.frames('chatqq').closeInfoWnd('friendwnd');\">\
<div class=\"winTitle\" align='left'><br /> <form name=\"sendMsgForm\" ><span align='left'>群的名称：<input type=\"text\" id=\"gname\" name =\"gname\" ></input> </span> </div>\
<div class=\"winCont\" id=\"sendMsgBoxCont\">\
<table class=\"t_l\">\
		<tr><td valign=\"top\">群描述：</td>\
				<td><textarea name=\"gnotes\" id =\"gnotes\" rows=\"\" cols=\"\"  class=\"tArea1\"></textarea></td></tr>\
		<tr><td>&nbsp;</td><td>\
		</td>\
	</tr>\
	<tr><td></td><td><input type=\"button\" value=\"创建\"  onclick =\"top.frames('chatqq').createG(\
	document.getElementById('gname').value,document.getElementById('gnotes').value);\"  class='button1' >&nbsp;&nbsp;<input type=\"reset\" value=\"关闭\"  class='button1'  onclick=\"top.frames('chatqq').closeInfoWnd('friendwnd')\"></td></tr>\
</form></table>\
</div>";
	div.innerHTML = html;
	//设置一些必要属性
	div.style.position = "absolute";
	div.style.left =460+"px";
	div.style.backgroundImage="url(images/4_r3_c4.gif)";
	div.style.top = 190+"px";
	div.style.height = 100+"px";
	div.style.textAlign="right";
	div.onmousedown = function() { top.event.cancelBubble=false;};
	top.document.body.appendChild(div);
}
//更改自身的头像
function changehead() {
	var div = top.document.createElement("div");
	div.id = "headlist";
	//字符串
	var html = "<iframe  frameborder=0 style ='display:none' scrolling=no src=\"about:blank\"></iframe>头像选择&nbsp &nbsp<img src=\"images/c.gif\" onclick=\"top.frames('chatqq').closeInfoWnd('headlist')\">\
<table class=\"t_l\">\
		<tr><td valign=\"top\"><iframe id = 'friendmy' frameborder=0 width=\"344px\" height=\"340px\" scrolling=no src=\"headlist.htm\"></td>\
		<tr><td>&nbsp;</td>\
	</tr>\
	<tr><td>&nbsp;&nbsp;<input type=\"reset\" value=\"关闭\"  class='button1'  onclick=\"top.frames('chatqq').closeInfoWnd('headlist')\"></td></tr>\
</table>\
</div>";
	div.innerHTML = html;
//设置一些属性
	div.style.position = "absolute";
	div.style.color="whiteSmoke";
	div.style.left =322+"px";
	div.style.top = 202+"px";
	div.style.height = 350+"px";
	div.style.width=350+"px";
	div.style.textAlign="right";
	top.document.body.appendChild(div);
}
//显示在线还是隐身的配置
 function showOnlineConfig()
 {
 //取得当前位置
 var mx = window.event.x;
 var my = window.event.y;
 var div = document.createElement("div");//创建一个div，然后赋予它一些属性
 div.style.fontSize="11px";
 div.id = "ayer";
 div.style.color ="blue";
 div.style.backgroundColor="#B2D7F2"; 
//字符串表示
var html = "\
<span  style='align:right;' onclick=\"$(Label3).innerText='在线';Request.sendGET('config.ashx?status=1&rnd=10000*Math.random()',null,null,null,null);closeme('"+div.id;
html += "');\">上线</span></br>\
<span style='align:right;' onclick=\"$(Label3).innerText='隐身';Request.sendGET('config.ashx?status=0&rnd=10000*Math.random()',null,null,null,null);closeme('"+div.id;
html += "');\">隐身</span><br/>";
div.innerHTML = html
div.style.position = "absolute";
div.style.left = mx-10+"px";
div.style.top = my+"px";
document.body.appendChild(div);
 }  
// 显示邀请的窗口
function createInviteWnd()
{
	var div = top.document.createElement("div");
	div.id = "dwnd";
	//字符串
	var html = "<iframe id = 'friendmy' frameborder=0 style ='display:none' scrolling=no src=\"about:blank\"></iframe><img src=\"images/c.gif\" onclick=\"top.frames('chatqq').closeInfoWnd('dwnd');\">\
<div class=\"winTitle\" align='left'><br /> <form name=\"sendMsgForm\" ><span align='left'>被邀请者<input type=\"text\" id=\"gname\" name =\"gname\" ></input> </span> </div>\
<div class=\"winCont\" id=\"sendMsgBoxCont\">\
<table class=\"t_l\">\
		<tr><td valign=\"top\">消息：</td>\
				<td><textarea name=\"gnotes\" id =\"gnotes\" rows=\"\" cols=\"\"  class=\"tArea1\"></textarea></td></tr>\
		<tr><td>&nbsp;</td><td>\
		</td>\
	</tr>\
	<tr><td></td><td><input type=\"button\" value=\"邀请\"  onclick ='invite(";
	html += "document.getElementById(\"gname\").value,document.getElementById(\"gnotes\").value);'  class='button1' >&nbsp;&nbsp;<input type=\"reset\" value=\"关闭\"  class='button1'  onclick=\"top.frames('chatqq').closeInfoWnd('dwnd')\"></td></tr>\
</form></table>\
</div>";
	div.innerHTML = html;
	//设置属性
	div.style.position = "absolute";
	div.style.left =360+"px";
	div.style.backgroundImage="url(images/4_r3_c4.gif)";
	div.style.top = 190+"px";
	div.style.height = 150+"px";
	div.style.textAlign="right";//右对齐
	div.onmousedown = function() { top.event.cancelBubble=false;};
	top.document.body.appendChild(div);
}
//邀请某人加入群
function invite(gname,gnotes)
{
//构造url
url = "invite.ashx?rnd="+10000*Math.random()+"&gname="+escape(gname)+"&gnotes="+escape(gnotes);
//发出请求
Request.sendPOST(url, "", doSendMessageRes,true, doSendMessageFail);
}

//控制web qq的最小化和还原
oa_tool=function()
{
var obj1=parent.document.getElementById("chatqq");
var obj2=parent.document.getElementById("chatqqcont");
if(obj2.style.height=="30px")
  {
    obj1.style.height="585";
    obj2.style.height="585"
  }
else
  {
    obj1.style.height="30";
    obj2.style.height="30"
  }

}	