//服务端数据
var NewMessage=0;
var ZaiXian,ZaiXianList,FJZaiXian;
var OnlineList;
var OnLineUser="|";
function LoadOnline(){
var AllOnlineNum = 0;
OnlineList.replace(/(\$)/g,function(){AllOnlineNum++});
if (AllOnlineNum!==0) {
for(i=1;i<AllOnlineNum+1;i++) {
	var UManage=OnlineList.split("$")[i];
if (i==1) {
	ZaiXian=UManage.split(",")[0];
	ZaiXianList=UManage.split(",")[1];
	//新短信数
	NewMessage=UManage.split(",")[2];
	ZaiXianList=ZaiXianList.replace(/#/g, "</a><br><a onclick=\"TalkOpen(innerText);return false\" href=###>");
	$("ZaiXainUser").innerHTML='<a onclick=\'GameWin("mymanage","玩家属性","integrate/UserManage.html?",350,400,20,200,1);return false\' href=###>'+XH_Name+' [自己]'+ZaiXianList;
	}else{
	var Uid=100+UManage.split(",")[0];
	var Uname=UManage.split(",")[1];
	var Uhead=UManage.split(",")[2];
	var Unum=UManage.split(",")[3];
	if (Unum!=="1000#1000") {MoveMan(Uid,Uname,Unum,100,Uhead)}
	OnLineUser=OnLineUser+Uid+"|"
		}
	}
}
//在线数
FJZaiXian=AllOnlineNum;
if (parseInt(NewMessage)>0) {
	PlaySE(6);
	$("OnlineRen").innerHTML="<marquee style='cursor:hand' onclick='TalkReceive()'>新短消息：<font color=red>"+NewMessage+"</font> 条</marquee>"
	}else{
	$("OnlineRen").innerHTML="在线　<font color=red>"+AllOnlineNum+"</font> <b>:</b> <font color=#FC00FF>"+ZaiXian+"</font>";
	}
//删除不在线的角色
var divs = $("XH_OnlineList").getElementsByTagName("div"), arr = [];
for (var i = 0; i < divs.length; i ++) {
var OnUid="|"+divs[i].id+"|";
if (IsInclude(OnLineUser,OnUid)==false) {
//window.clearTimeout(MyTimesup[divs[i].id]);
var OnDelDiv=divs[i].id;
DelDiv(OnDelDiv,1);
DelDiv("talk_"+OnDelDiv,1);
}
	}
OnLineUser="|";
}


function MoveMan(MoveId,MoveName,MoveXY,ForNum,PlayHead){
var result = 0;
MoveXY.replace(/(\_)/g,function(a,b){result++});
	if (ForNum!==100) {
	if (ForNum>result) {return}
	}else{ForNum=0}
ForNum=parseInt(ForNum);
var MoveShu=MoveXY.split("_")[ForNum];
var MoveX=MoveShu.split("#")[0];
var MoveY=MoveShu.split("#")[1];
var EMoveShu=MoveXY.split("_")[result];
var EMoveX=EMoveShu.split("#")[0];
var EMoveY=EMoveShu.split("#")[1];
if ($(MoveId)) {
//存在
var _XMan=$(MoveId).offsetLeft;
var _YMan=$(MoveId).offsetTop;
if ((_XMan==EMoveX)&&(_YMan==EMoveY)){
//没有移动
	}else{
	MoveNow(MoveId,MoveName,MoveX,MoveY,parseInt(ForNum+1),MoveXY,0)
	}
}else{
//不存在
var oDiv = document.createElement("DIV");
oDiv.id = MoveId;
//oDiv.id = MoveName;
oDiv.style.top = MoveY;
oDiv.style.left = MoveX;
oDiv.className = 'player';
oDiv.style.zIndex = parseInt(MoveY);
oDiv.innerHTML="<img src='images/player/"+PlayHead+".gif'>";
$("XH_OnlineList").appendChild(oDiv);

var oDiv2 = document.createElement("DIV");
oDiv2.id = "talk_"+MoveId;
oDiv2.style.top = MoveY-35;
oDiv2.style.left = MoveX-97;
oDiv2.className = 'newtalk';
$("XH_OnlineTalk").appendChild(oDiv2);

MoveMan(MoveId,MoveName,MoveXY,parseInt(ForNum+1));
	}
}

var MyTimesup = new Array();
function MoveNow(MoveId,MoveName,EMoveX,EMoveY,NextNum,MoveXY,ScrollNum) {
var SMoveX=$(MoveId).offsetLeft;
var SMoveY=$(MoveId).offsetTop;
$(MoveId).style.zIndex=SMoveY+95;
var Quick=2;
if (SMoveX<EMoveX) {SMoveX=SMoveX+Quick}else if(SMoveX>EMoveX){SMoveX=SMoveX-Quick}
if (SMoveY<EMoveY) {SMoveY=SMoveY+Quick}else if(SMoveY>EMoveY){SMoveY=SMoveY-Quick}
var FXCN="Stop";
var MoveFX=0;
if ((SMoveX<EMoveX)&&(SMoveY<EMoveY)) {FXCN="右下";MoveFX=5}
else if ((SMoveX>EMoveX)&&(SMoveY<EMoveY)) {FXCN="左下";MoveFX=4}
else if ((SMoveX<EMoveX)&&(SMoveY>EMoveY)) {FXCN="右上";MoveFX=7}
else if ((SMoveX>EMoveX)&&(SMoveY>EMoveY)) {FXCN="左上";MoveFX=6}
else if ((SMoveX<EMoveX)&&(SMoveY==EMoveY)) {FXCN="右";MoveFX=2}
else if ((SMoveX>EMoveX)&&(SMoveY==EMoveY)) {FXCN="左";MoveFX=1}
else if ((SMoveY<EMoveY)&&(SMoveX==EMoveX)) {FXCN="下";MoveFX=0}
else if ((SMoveY>EMoveY)&&(SMoveX==EMoveX)) {FXCN="上";MoveFX=3}
$(MoveId).scrollTop=MoveFX*131;
var ScrollImg=58;
if (ScrollNum==0) {
ScrollImg=$(MoveId).scrollLeft+58;
}else{
ScrollImg=$(MoveId).scrollLeft;
}
if (ScrollImg>348) {ScrollImg=58}
$(MoveId).scrollLeft=ScrollImg;
if (ScrollNum==2) {ScrollNum=0}else{ScrollNum=ScrollNum+1}
if ((Math.abs(EMoveX-SMoveX)>2)||(Math.abs(EMoveY-SMoveY)>2)){
	$(MoveId).style.left=SMoveX;
	$(MoveId).style.top=SMoveY;

	$("talk_"+MoveId).style.left=SMoveX-97;
	$("talk_"+MoveId).style.top=SMoveY-35;

	window.clearTimeout(MyTimesup[MoveId]);
	MyTimesup[MoveId]=window.setTimeout("MoveNow("+MoveId+",'"+MoveName+"',"+EMoveX+","+EMoveY+","+NextNum+",'"+MoveXY+"',"+ScrollNum+")",15);
	}else{
	$(MoveId).scrollLeft=0;
	MoveMan(MoveId,MoveName,MoveXY,NextNum);
	}
}

function ClearAllUser() {
$(XH_MyTalkId).style.display='none';
$("XH_OnlineTalk").innerHTML="";
var divs = $("XH_OnlineList").getElementsByTagName("div"), arr = [];
for (var i = 0; i < divs.length; i ++) {
//DelDiv(divs[i].id,1);
$(divs[i].id).style.display='none';
	}
}

function AllZXList(OpenId) {
PlaySE(2);
var Types=$(OpenId).style.display;
if (Types=='block') {
	$(OpenId).style.display='none';
	}else{
	$(OpenId).style.display='block';
	if ((OpenId=="Music_bg")&&($("Music_List").innerHTML=="")) {
		LoadMyMusic();
		}
	if (OpenId=="MyFriend") {
		$("MyFriend").innerHTML='<IFRAME name="MyFriendWin" width="196" height="480" frameborder="0" SCROLLING="no" SRC="friend.html"></IFRAME>';
		}
	}
}

function LoadMyMusic() {
var XmlUrl="xml/MusicList.asp?List="+MusicXml;
var XmlDoc=new ActiveXObject("Microsoft.XmlDOM");
XmlDoc.async = false;
XmlDoc.load(XmlUrl);
Nodes=XmlDoc.documentElement.childNodes;
var MPlayNum=XmlDoc.getElementsByTagName("item").length;
var MusicListHtml="";
for(i=0;i<MPlayNum;i++) {
	MusicListHtml=MusicListHtml+"<a href=javascript:PlayMusic("+i+")>"+Nodes.item(i).childNodes(0).text+"-"+Nodes.item(i).childNodes(1).text+"</a>"
	}
$("Music_List").innerHTML=MusicListHtml;
}

function TalkOpen(TalkName) {
//AllZXList('ZaiXainUser_bg');
$("ZaiXainUser_bg").style.display='none';
GameWin(TalkName,TalkName,'Talk.html?'+TalkName,456,433,8,250,5);
}

function TalkReceive() {
if (PK_Freak!==0) {alert('PK状态下无法启动聊天系统!');return}
if (parseInt(NewMessage)==0) {
	AllZXList("MyFriend");
	//GameWin('Myfriend','我的好友','Friend_List.asp?U='+XH_Uid,240,420,10,10,2);
	}else{
	$("XH_LoadJSNow").style.display='block';
	$("XH_LoadJSNow").innerHTML="<div style='width:220px;margin-top:200px;margin-left:280px;border:1px #000000 solid;background:#ffffff;text-align:Center;padding-top:3px;color:#000000'>正在读取数据...</div>";
	GameAjax("Talk_Load.asp?i=0&","XH_LoadJSNow",5)
	}
}