var userlist;
var listflag=1;
var hflag=1;
var filterlist='';
var newlist=0;
var max=4;var saymsg=new Array(max); var base=-1;
var max2=4;var saymsg2=new Array(max2); var base2=-1;
var perflag=0;
var noreftime=0;
var scrollscreen=1;
var jsjs="";
var headsize=32;
var allusernum=0;
var sortdirect=0;
var sorttype=1;
var listreftime=0;
var listtype=0;
var transtimer=0;
var i_mms=0;
var perlist=myname;

//右键显示信息，可以修改和添加，这里屏蔽了右键但是并不能阻止别人看客户端代码
var alertMsg=new Array("聊天室全面升级！","聊天时请注意休息！","祝您聊得开心哟！","欢迎光临紫儿聊吧！","经常使用计算机请注意保护您的眼睛！");
var alertNum=0;
var mdstr='<\script>function cl() {if (event.button==2){alert(top.alertMsg[top.alertNum++]);if (top.alertNum==top.alertMsg.length) top.alertNum=0;}}document.onmousedown=cl;</\script>';
document.write(mdstr);

var semotion=new Array("","微笑着","温柔地","脸红着","洋洋自得地","大笑着","神秘兮兮地","战战兢兢地","毛手毛脚地","嘟着嘴","慢条斯理地","同情地","幸灾乐祸地","快要哭地","哭哭泣泣地","拳打脚踢地","不怀好意地","遗憾地","满脸奇怪地","幸福地","翻箱倒柜地","悲痛地","正义凛然地","严肃地","非常生气地","大声地","傻乎乎地","满足地","手足无措地","无辜地","自言自语地","瞪着眼","想要吐地","无精打采地","依依不舍地","口吐白沫地","有气无力地","无可奈何地","可怜巴巴地");
function gettimestr(){var now_time=new Date();return now_time.getHours()+":"+now_time.getMinutes()+":"+now_time.getSeconds()}
function gbt() {return "scrollbar-Base-Color: "+bc2+";SCROLLBAR-DARKSHADOW-COLOR:"+bc2+";SCROLLBAR-arrow-COLOR:"+bc1+";SCROLLBAR-TRACK-COLOR: "+bgcolor+";SCROLLBAR-3DLIGHT-COLOR: "+bc2+";SCROLLBAR-SHADOW-COLOR: "+bc1+";SCROLLBAR-HIGHLIGHT-COLOR: "+bc2+";background-color:"+bgcolor+";";}
function clearsay() {var j;base=-1;for (j=0;j<=max;j++) saymsg[j]='';base2=-1;for (j=0;j<=max2;j++) saymsg2[j]='';}
clearsay();

function chftitle(t) {self.title.fTitle.innerHTML="<font color=blue>"+t+"</font>"}
function chttitle(t) {self.title.tTitle.innerHTML="〖"+roomname+"〗"+t}

function showjs(n,n1){return "※<font style='color:blue;cursor:hand' onclick='parent.jsjs="+n+";parent.clearper()'>"+n1+"</font>"}
function clearper(){
   var j;var bodystr;var jsjsstr='';
   var scname="包厢窗口】</font>显示包厢名单中聊友的发言！";if (roomguests!='') scname="公众窗口】</font>显示公众的发言！";
   if (jsjs!='') jsjsstr="<\script src=data/"+jsjs+" ></\script>";
   bodystr="<META content='text/html; charset=gb2312' http-equiv=content-type>"
    +"<STYLE type=text/css>.p{font-size:20pt}.font{font-family:宋体;line-height:"+LHeight+"%;font-size:"+saysize+"pt;}"
    +"a{text-decoration:none;}.A {cursor:hand;}"
    +"</STYLE>"+mdstr+"</head><body style='"+gbt()+"' topmargin=5>"+
    "<basefont class=font><font style='color:cc0000'>【"+scname+
    "<select style='color:#3366cc;background-color:ffeeee' name=ds onchange=\"definescr(this.value);if (this.value==5) this.options[0].selected=true\"><\script>"+
    "function definescr(n){var jsarr=new Array('','starmoon.js','test.js','js.js','');"+
    "if (n==5) {parent.toolbar.switchSysBar();parent.toolbar.switchTitle();parent.viewsay.cols='*';if (parent.viewsay.rows=='0,*' || parent.roomguests!='') parent.viewsay.rows='*,*';else parent.viewsay.rows='0,*';}"+
    "else {parent.jsjs=jsarr[n];parent.clearper();}}"+
    "var jsstr=new Array('定制屏幕','星月传说','快乐天使','我心飞扬','返朴归真','极大极小');for (i=0;i<6;i++) document.write(\"<option value=\"+i+\">\"+jsstr[i]+\"</option>\");</\script></select>"+
    "<small>("+gettimestr()+")</small><br>"+jsjsstr;
  if (base2>-1) for (j=0;j<=base2;j++) bodystr=bodystr+saymsg2[j];
  this.say2.document.open();this.say2.document.write(bodystr);
  putsay1();clearsay();}
function putsay1(){
 var time_str="<small>("+gettimestr()+")</small><br>"
 var scname="公众窗口】</font>显示公众的发言！";var welcomestr="%%由##修建，"+room_des;
 if (roomguests!='') {scname="嘉宾窗口】</font>显示嘉宾的发言！";welcomestr=welcomestr+"<font color=green>[嘉宾名单："+roomguests+"]</font>"}
 var bodystr="<META content='text/html; charset=gb2312' http-equiv=content-type>";
 this.say1.document.open();
 bodystr=bodystr+"<STYLE type=text/css>.p{font-size:20pt}.font{font-family:宋体;line-height:"+LHeight+"%;font-size:"+saysize+"pt;}"
  +"a{text-decoration:none;}.A {cursor:hand;}"
  +"</STYLE>"+mdstr+"</head><body style='"+gbt()+"' topmargin=5><basefont class=font>";
 bodystr=bodystr+"<font style='color:cc0000'>【"+scname+time_str;
 bodystr=bodystr+show(welcomestr,room_owner,roomname,0,"#000099","#009900",-3,gettimestr());
 if (base>-1) for (j=0;j<=base;j++) bodystr=bodystr+saymsg[j];
 this.say1.document.write(bodystr);}
function checkper(){var ns4up=(document.layers) ? 1 : 0;var ie4up=(document.all) ? 1 : 0;
 var say1_height=600;var say2_height=600;
 if (ns4up) {say1_height=this.say1.innerHeight;say2_height=this.say2.innerHeight;}
 else if (ie4up) {say1_height=this.say1.document.body.clientHeight;say2_height=this.say2.document.body.clientHeight;}
 if (say1_height<30) {if (roomguests=='') {perflag=2;if (say1_height>0) this.viewsay.rows="0,*"}else{perflag=1;this.viewsay.rows="*,*"}}
 else if (say2_height<30) {if (roomguests=='') {perflag=0;if (say2_height>0) this.viewsay.rows="*,0"}else{perflag=1;this.viewsay.rows="*,*"}}
 else {perflag=1;}}

var re_t,re_t2;
function tttext(j1, j2){j1 = j1.replace(re_t2,"$1&");j1 = j1.replace(re_t,j2+"$1"+"</font>");return(j1);}
function ttcheck(s){
var temps;
if (roomtt!=0) {
 re_t=/\[SY\](.|&.{1,6};)\[\/SY\]/gi;re_t2=/(\[SY\])&amp;/gi;s=tttext(s,"<font face=Symbol class=p>");
 re_t=/\[WI\](.|&.{1,6};)\[\/WI\]/gi;re_t2=/(\[WI\])&amp;/gi;s=tttext(s,"<font face=Wingdings class=p>");
 re_t=/\[WE\](.|&.{1,6};)\[\/WE\]/gi;re_t2=/(\[WE\])&amp;/gi;s=tttext(s,"<font face=Webdings class=p>");
 re_t = /\[IMG\]([0-9]+)\[\/IMG\]/gi;s = s.replace(re_t, "<img src=pic/p$1.gif>");}
if (roomhtml!=0) {
 re_t=/\[size=([2-6])\](.+)\[\/size\]/gi;do {temps=s;s=s.replace(re_t, "<font size='$1'>$2</font>")} while(s!=temps);
 re_t=/\[\/size\](.+)\[size=([2-6])\]/gi;s = s.replace(re_t, "</font>$1<font size='$2'>");
 re_t=/\[color=([a-z0-9\#]{3,12})\](.+)\[\/Color\]/gi;do {temps=s;s = s.replace(re_t, "<font color='$1'>$2</font>")} while(s!=temps);
 re_t=/\[\/Color\](.+)\[color=([a-z0-9\#]{3,12})\]/gi;s = s.replace(re_t, "</font>$1<font color='$2'>");
 re_t=/\[I\](.+)\[\/I\]/gi;do {temps=s;s = s.replace(re_t, "<I>$1</I>")} while(s!=temps);
 re_t=/\[\/I\](.+)\[I\]/gi;s = s.replace(re_t, "</I>$1<I>");
 re_t=/\[B\](.+)\[\/B\]/gi;do {temps=s;s = s.replace(re_t, "<B>$1</B>")} while(s!=temps);
 re_t=/\[\/B\](.+)\[B\]/gi;s = s.replace(re_t, "</B>$1<B>");
 re_t=/\[LEFT\](.+)\[\/LEFT\]/gi;s = s.replace(re_t, "<marquee width=50% direction=left>$1</marquee>");
 re_t=/\[RIGHT\](.+)\[\/RIGHT\]/gi;s = s.replace(re_t, "<marquee width=50% direction=right>$1</marquee>");}
return s;
}
function addsay(){
 var body,j,who,towho;
 var argv=addsay.arguments;var argc=addsay.arguments.length;var i=0;checkper();
 while ((i+6)<argc) {
  if ( (argv[i]>this.input.document.forms[0].id.value && (" "+filterlist+" ").indexOf(" "+argv[i+2]+" ",0)==-1) || argv[i]==-1 || argv[i+7]<-1){
   if (argv[i+7]==-5) this.say2.document.write(argv[i+1]);
   else {who=argv[i+2];towho=argv[i+3];
    body=show(argv[i+1],who,towho,argv[i+4],argv[i+5],argv[i+6],argv[i+7],argv[i+8]);
    if ((roomguests!='' && notguest(argv[i+2])) || (roomguests=='' && (((inperlist(argv[i+2]) || inperlist(argv[i+3]) || argv[i+7]==-4) && perflag==1) || perflag==2 || argv[i+7]==-5))) {
     sclscreen(2);this.say2.document.write(body);sclscreen(2);
     if (base2<max2){base2++;saymsg2[base2]=body;}else{for (j=0;j<max2;j++) saymsg2[j]=saymsg2[j+1];saymsg2[base2]=body;}}
    else {sclscreen(1);this.say1.document.write(body);sclscreen(1);
     if (base<max){base++;saymsg[base]=body;}else{for (j=0;j<max;j++) saymsg[j]=saymsg[j+1];saymsg[base]=body;}}
  }}i=i+9;}}
function show(body,who,towho,secret,color1,color2,semote,saytime){
 var color2str,j,kickwho,kicktowho;var w1=who;var t1=towho;var w2=who;
 if (semote>semotion.length) semote=0;
 body=ttcheck(body);
 color1="<font color="+color1+">";
 color2str="<font class=a onmouseout=\"this.style.textDecoration=\'none\'\" onmouseover=\"this.style.textDecoration=\'underline\'\" color="+color2;
 kickwho=" ondblclick=\"window.open('topuser2.asp?selwho="+who+"','newsay')\"";
 kicktowho=" ondblclick=\"window.open('topuser2.asp?selwho="+towho+"','newsay')\"";
 if (w1==myname) w1="<u>"+w1+"</u>";if (t1==myname) t1="〖"+t1+"〗";
 who=color2str+" onclick=\"javascript:parent.chuser('"+who+"')\""+kickwho+">"+w1+"</font>";
 if (semote==-3) towho=color2str+" onclick=\"window.open('roomset.asp?room="+towho+"','roomset','width=520,height=400,scrollbars=1')\">『"+towho+"』</font>";
 else towho=color2str+" onclick=\"javascript:parent.chuser('"+towho+"')\""+kicktowho+">"+t1+"</font>";
 if (semote<0) {
   while (body.indexOf("##",0)!=-1) body=body.replace("##",who);
   while (body.indexOf("%%",0)!=-1) body=body.replace("%%",towho);
   if (secret==0 && semote==-1) body="【动作】"+body;}
 else body=getheadface(w2)+who+semotion[semote]+"对"+towho+"说："+body;
 if (secret==1) body="【私聊】"+body;body=color1+body+"</font><small>("+saytime+")</small>"; body=body+"<br>";
 return body;}
 
function isfriend(name) {if (friendlist) if ((" "+friendlist+" ").indexOf(" "+name+" ",0)!=-1) return true;return false;}
function inperlist(name) {if ((" "+perlist+" ").indexOf(" "+name+" ",0)!=-1) return true;return false;}
function notguest(name) {if (roomguests) if ((" "+roomguests+" ").indexOf(" "+name+" ",0)!=-1) return false;return true;}

function addperlist(name) {addsay(-1,'【系统】您把['+name+']加入到您的包厢名单中!','',myname,0,'green','',-2,gettimestr());
 if (name) {var la=name.split(" ");for (var i=0;i<la.length;i++) if (la[i]) if ((" "+perlist+" ").indexOf(" "+name+" ",0)==-1) perlist=perlist+" "+name;}}
function delperlist(name) {var fl=" "+perlist+" ";var shmsg="["+name+"]并不在您的包厢名单里！";if (fl.indexOf(" "+name+" ",0)!=-1) {fl=fl.replace(" "+name,"");perlist=fl.substr(1,fl.length-2);shmsg="您把["+name+"]从包厢名单里面删除！";}addsay(-1,'【系统】'+shmsg,'',myname,0,'green','',-2,gettimestr());}

function splitlist(l) {var ls='';if (l){var la=l.split(" ");for (var i=0;i<la.length;i++) if (la[i]) ls+="<font style=\'color:black;cursor:hand\' onclick=\'parent.chuser(\""+la[i]+"\")\'>"+la[i]+"</font> ";}return ls;}
function addfriend(name) {if ((" "+friendlist+" ").indexOf(" "+name+" ",0)==-1) friendlist=friendlist+" "+name;}
function cancelfriend(name) {var fl=" "+friendlist+" ";var shmsg="["+name+"]并不在您的好友名单里！";if (fl.indexOf(" "+name+" ",0)!=-1) {fl=fl.replace(" "+name,"");friendlist=fl.substr(1,fl.length-2);shmsg="您把["+name+"]从好友名单里面删除！";}addsay(-1,'【系统】'+shmsg,'',myname,0,'green','',-2,gettimestr());}
function addfilter(name) {var shmsg="您不能屏蔽["+name+"]的发言！";if (name!="大家" && name!=myname) {if ((" "+filterlist+" ").indexOf(" "+name+" ",0)==-1) filterlist=filterlist+" "+name;shmsg="您把["+name+"]加入到屏蔽名单!"}addsay(-1,'【系统】'+shmsg,'',myname,0,'green','',-2,gettimestr());}
function cancelfilter(name) {var fl=" "+filterlist+" ";var shmsg="["+name+"]并不在您的屏蔽名单里！";if (fl.indexOf(" "+name+" ",0)!=-1) {fl=fl.replace(" "+name,"");filterlist=fl.substr(1,fl.length-2);shmsg="您取消对["+name+"]的发言屏蔽!"}addsay(-1,'【系统】'+shmsg,'',myname,0,'green','',-2,gettimestr());}

function showfriend() {var shmsg="您暂时还没有设定任何好友！";if (friendlist) shmsg="您的好友有："+splitlist(friendlist);addsay(-1,'【系统】'+shmsg,'',myname,0,'green','',-2,gettimestr());}
function showfilter() {var shmsg="您暂时还没有屏蔽任何人！";if (filterlist) shmsg="您的屏蔽名单："+splitlist(filterlist);addsay(-1,'【系统】'+shmsg,'',myname,0,'green','',-2,gettimestr());}
function showperlist() {addsay(-1,'【系统】以下聊友发言将显示在包厢窗口里：'+splitlist(perlist),'',myname,0,'green','',-2,gettimestr());}

function getheadface(u){
  if (!hflag) return "";
  if (userlist!=null && userlist.length>0) for(var i=0;i<userlist.length;i=i+1){
    var namesex=userlist[i].split(' ');
    if (namesex[0]==u) return "<img src='headface/"+namesex[2]+".gif' height=16 width=16 >";
  }return ""}
function addl(nickname,sex,headface,status){
 if (userlist == null) return ;
 for(var i=0;i<userlist.length;i=i+1){
  var namesex=userlist[i].split(' ');
  if(namesex[0]==nickname)
  {userlist[i]=nickname+' '+sex+' '+headface+' '+status;newlist=1;
  return;};};
 userlist[userlist.length]=nickname+' '+sex+' '+headface+' '+status;
 if (isfriend(nickname)) this.say2.document.write('<bgsound loop=1 src=data/knock.mid>');
 newlist=1;}
function dell(name){
   if (userlist == null) return ;
   for(var i=0;i<userlist.length;i=i+1){
     var namesex=userlist[i].split(' ');
     if (namesex[0]==name){
	for (var j=i;j<userlist.length-1;j=j+1) userlist[j]=userlist[j+1];
        userlist.length=userlist.length-1;newlist=1;
	if (isfriend(name)) this.say2.document.write('<bgsound loop=1 src=data/ring.mid>');return;}}}
function sortl() {var userarr,i;if (sorttype<2) userlist.sort();
else{
for (i=0;i<userlist.length;i++) {userarr=userlist[i].split(" ");userlist[i]=userarr[1]+" "+userarr[0]+" "+userarr[2]+" "+userarr[3]}
userlist.sort();
for (i=0;i<userlist.length;i++) {userarr=userlist[i].split(" ");userlist[i]=userarr[1]+" "+userarr[0]+" "+userarr[2]+" "+userarr[3]}}
sortdirect=sorttype%2;showlist();}
function showlist(){
  var bodystr,j;var titlestr;var colorstr;var hstr="";var colorarray=new Array("red","red","red");colorarray[listtype]="black";
  listflag=1;newlist=0;var usernum;if (userlist!=null) usernum=userlist.length;else usernum=0;self.listtitle.chtl(1);self.list.document.open();
  self.list.document.writeln("<html><head><META content='text/html;charset=gb2312' http-equiv=content-type>"
   +"<STYLE type=text/css>font{FONT-SIZE:12;cursor:hand}td{FONT-SIZE:10pt;line-height:130%;text-align:left;font-family:宋体}input{font-size:12}select{font-size:12;background-color:ffeeee;color:3366cc}A {color:224466;TEXT-DECORATION: none;line-height:110%;}"
   +"A:hover {color:#009900;TEXT-DECORATION: underline}</STYLE>"+mdstr+"<\script language='JavaScript'>var NS4 = (document.layers);var IE4 = (document.all);var win = window;var n=0;function findInPage(str){var txt,i,found;if(str==''){return false;}if(NS4){if(!win.find(str))while(win.find(str,false,true))n++;else{n++;}if(n==0)alert('您要的名字没有找到！');}if(IE4){txt=win.document.body.createTextRange();for(i=0;i<=n&&(found=txt.findText(str))!=false;i++){txt.moveStart('character',1);txt.moveEnd('textedit');}if(found){txt.moveStart('character',-1);txt.findText(str);txt.select();txt.scrollIntoView();n++;}else{if(n>0){n=0;findInPage(str);}else{alert('您要的名字没有找到！');}}}return false;}</\script></head>"
   +"<body title=\"男蓝女绿，单击选择，双击...\" style=\""+gbt()+"margin:0px\">"
   +"<table height=100% width=100% ><tr><td valign=top>"
   +"<center><a href='#' onclick=\"java\script:window.open('roomset.asp?room="+roomname+"','roomset','width=520,height=400,scrollbars=1');return false\" style='color:green' title=查看当前房间的信息><b>〖"+roomname+"〗</b></a>"
   +"<br><a href='rooms_info.asp' title=\'人气不错吧,看看其他房间如何\' target='roominfo'><font color=3366cc>|人气:"+roomlife+"|</font></a>"
   +"<br><font color="+colorarray[2]+" onclick=\'parent.listtype=2;parent.showlist()\' title=\'只显示好友名单\'>好友</font>"
   +"|<font color="+colorarray[1]+" onclick=\'parent.listtype=1;parent.showlist()\' title=\'只显示包厢名单\'>包厢</font>|"
   +"<font color="+colorarray[0]+" onclick=\'parent.listtype=0;parent.showlist()\' title=\'显示全部名单\'>全部</font>"
   +"<br><font color=cc0000 title='查看在线名单' onclick=\"window.open('online_list.asp','_blank')\">"+usernum+"(<span id=aun name=aun>"+allusernum+"</span>)人</font> <font color=cc9900 title='点击重新读入名单' onclick=\"window.open('list.asp','newsay')\">刷新</font>"
   +"</center></td></tr><form name='search' onSubmit='return findInPage(this.string.value);'><tr><td><center><select onchange='java\script:parent.sorttype=this.options[selectedIndex].value;parent.sortl();'><option value='0'>排序方式<option value='0'>--------<option value='0'>姓名逆序<option value='1'>姓名顺序<option value='2'>女士优先<option value='3'>男士优先</select></center></td></tr><tr><td><center><input name='string' type='text' size=6 onChange='n=0;' style='font-family:宋体;font-size:9pt;background-color:eaf0ff;color:blue;border: 1 double'> <input type='submit' value='查找' style='font-family:宋体;background-color:b0d8ff;color:navy;border: 1 double'>"
   +"</td></tr></form><tr><td height=100% valign=top><center><hr width=100% color=336699 size=1><table cellspacing=1 cellpadding=0 border=0><tr><td></td><td><a href=\"javascript:parent.chuser('大家')\" title=同房间的所有人>大家</a>");
 if (usernum!=0) for (var i=usernum-1;i>=0;i--){
   j=i;if (sortdirect==1) j=usernum-i-1;
   userarr=userlist[j].split(" ");
   if (listtype==0 || (listtype==1 && inperlist(userarr[0]) ) || (listtype==2 && isfriend(userarr[0]) ) || userarr[0]==myname ){
   if (userarr[1]==1) {titlestr="我是Girl";colorstr="green";}else {titlestr="我是Boy";colorstr="blue";}
   if (hflag) hstr="<img alt=\'是的,我很酷\' src='headface/"+userarr[2]+".gif' height="+headsize+" width="+headsize+">";
   self.list.document.write("</td></tr><tr><td>"+hstr+"<td><a style='color:"+colorstr+"' href=\"javascript:parent.chuser('"+userarr[0]+"')\" ");
   self.list.document.write("ondblclick=window.open('topuser2.asp?selwho="+userarr[0]+"','newsay') ");
   self.list.document.write("title='"+titlestr+"'>"+userarr[0]+"</a>");if (userarr[3]) self.list.document.write(" <font color=990099 title=\'状态很好\' >"+userarr[3]+"</font>");}}
 else {self.list.document.write("<br><br>正在读取名单<br><br>请等待....<br><br>");window.open("list.asp","newsay");}
 self.list.document.write("</td></tr><tr><td></td><TD><a href=\"javascript:parent.chuser('"+roomauto+"')\" title=\"我是这里的机器人\">"+roomauto+"</a>");
 self.list.document.write("</td></tr></table><hr width=100% color=336699 size=1></td></tr></table></body></html>");}

function leave(){var lvstr="leave.asp";lvstr=lvstr + "?mc=" + this.input.document.forms[0].addwordcolor.selectedIndex + "&sc=" + this.input.document.forms[0].sayscolor.selectedIndex;window.open("about:blank","refresh");window.open(lvstr,"_top")}
function refresh(){window.open("refresh.asp"+"?sayid="+this.input.document.forms[0].id.value,"refresh")}
function ref(n){noreftime=0;this.input.document.forms[0].id.value=n;}
function chuser(u) {this.input.document.forms[0].towho.value=u;this.input.document.forms[0].saystemp.focus();}

function cface(c1,c2){bc1=c1;bc2=c2;self.title.document.body.style.backgroundColor=c2;self.toolbar.document.body.style.backgroundColor=c1;}
function chscroll() {if (scrollscreen==1) scrollscreen=0;else {scrollscreen=1;sclscreen(1);sclscreen(2);}this.input.document.forms[0].saystemp.focus();}
function sclscreen(n) {if (scrollscreen==1) {if (n==1) this.say1.scrollBy(0,6500);else this.say2.scrollBy(0,6500);}}
function chcolor(){
 bgcolor=this.input.document.forms[0].bgc.value;
 if (bgcolor=="") bgcolor=oldbgcolor;
 this.say1.document.body.style.backgroundColor=bgcolor;
 this.say2.document.body.style.backgroundColor=bgcolor;
 this.list.document.body.style.backgroundColor=bgcolor;}
