var $=document.getElementById,http_request=false,rEmail=/\w[@]{1}\w+[.]{1,3}\w/,rDate=/^2{1}\d{7}$/,stamp=new Date(),rTime,theDate="",type,kind,flag=1,sayNow="",bearType=0,allPut=["username","email","rnd1","how","ok"];master="<font style=background-color:red;color:white;font-weight:bold>系统提示</font><font style=font-size:10px;color:red>"+stamp.getHours().toString()+":"+stamp.getMinutes().toString()+":"+stamp.getSeconds().toString()+"</font><br>";
window.onload=function(){if(say.innerText=="正在接收数据……"){say.focus();}getNow();if(location.href.substring(location.href.length-3,location.href.length)=="reg")allAction(0);all_right.style.height=all_left.offsetHeight;var tPoint=getPosition($("say"));var left=tPoint.left+parseInt($("say").currentStyle.borderLeftWidth)+parseInt($("say").currentStyle.paddingLeft);$("say").onmousemove=function(){var cw=this.clientWidth,e=window.event,x=e.x;if(left+cw<x){return;}rollAll();}
if(nickname.value.length>0){nickname.readOnly=true;content.disabled=false;gb.disabled=false;content.focus();}else{nickname.focus();}parseInt((stamp.getMonth()+1).toString())<10?tM="0"+(stamp.getMonth()+1).toString():tM=(stamp.getMonth()+1).toString();parseInt(stamp.getDate().toString())<10?tD="0"+stamp.getDate().toString():tD=stamp.getDate().toString();rTime2=stamp.getYear().toString()+tM+tD;master="<font style=background-color:red;color:white;font-weight:bold>系统提示</font>"+rTime+"<br>";if(named==1){sendMsg(2);}else{$("say").innerHTML=master+"<b>欢迎加入集群^^</b><br><font color=red>Ctrl+Enter</font>可以直接送递信息。本窗口显示<u>当日</u>所有聊天内容，速度因终端网速而定，如果很长时间没有反应，可以刷新再进来。<br>集群试运行中……<br>";}}
function getNow(){stamp=new Date();rTime="<font style=font-size:10px;color:red>"+stamp.getHours().toString()+":"+stamp.getMinutes().toString()+":"+stamp.getSeconds().toString()+"</font>";return rTime;}
function getPosition(obj){var left=0;var width=obj.clientWidth;while(obj.offsetParent){left+=obj.offsetLeft;obj=obj.offsetParent;}return{"left":left,"width":width};}
function bear(now){if(now==1){getNow();bearSay[0]="<br><font style=background-color:orange;color:white;font-weight:bold>不良小熊</font>"+rTime+"<br><font color=green>我给你削个苹果吧。^^</font>";bearSay[1]="<br><font style=background-color:orange;color:white;font-weight:bold>不良小熊</font>"+rTime+"<br><font color=green>说什么呢？我不是很明白呢……</font>";bearSay[2]="<br><font style=background-color:orange;color:white;font-weight:bold>不良小熊</font>"+rTime+"<br><font color=green>用E.R.N.I.E买彩票了么？我上次还中了5元钱呢。^——^</font>";bearSay[3]="<br><font style=background-color:orange;color:white;font-weight:bold>不良小熊</font>"+rTime+"<br><font color=green>我好困哪。(*_*)</font>";bearSay[4]="<br><font style=background-color:orange;color:white;font-weight:bold>不良小熊</font>"+rTime+"<br><font color=green>注册E.R.N.I.E自己的名字多牛牛啊，例如：不良老熊。-0-!!</font>";bearSay[5]="<br><font style=background-color:orange;color:white;font-weight:bold>不良小熊</font>"+rTime+"<br><font color=green>这个群聊站还行吧，有我才精彩，瓦卡卡。^^</font>";bearSay[6]="<br><font style=background-color:orange;color:white;font-weight:bold>不良小熊</font>"+rTime+"<br><font color=green>ZZZZZZzzzz。Z_Z</font>";bearSay[7]="<br><font style=background-color:orange;color:white;font-weight:bold>不良小熊</font>"+rTime+"<br><font color=green>每期坚持用E.R.N.I.E摇出的号码买彩票，中大奖的机率很高哦~~</font>";bearSay[8]="<br><font style=background-color:orange;color:white;font-weight:bold>不良小熊</font>"+rTime+"<br><font color=green>zzzzZZZZZZ。*_*</font>";bearSay[9]="<br><font style=background-color:orange;color:white;font-weight:bold>不良小熊</font>"+rTime+"<br><font color=green>我说的话怎么没有了，是不是bug啊~@_@</font>";bearSay[10]="<br><font style=background-color:orange;color:white;font-weight:bold>不良小熊</font>"+rTime+"<br><font color=green>你试过站着打字吗？~?_?</font>";bearSay[11]="<br><font style=background-color:orange;color:white;font-weight:bold>不良小熊</font>"+rTime+"<br><font color=green>世界如此美妙,我却如此暴躁,这样不好,不好。~_~</font>";bearSay[12]="<br><font style=background-color:orange;color:white;font-weight:bold>不良小熊</font>"+rTime+"<br><font color=green>你说的我听都不想听****$_$</font>";bearSay[13]="<br><font style=background-color:orange;color:white;font-weight:bold>不良小熊</font>"+rTime+"<br><font color=green>去玩一圈E.R.N.I.E看看手气吧~~~~~</font>";bearSay[14]="<br><font style=background-color:orange;color:white;font-weight:bold>不良小熊</font>"+rTime+"<br><font color=green>我不是托儿，E.R.N.I.E真的好好噢~~~~~~~~~~~~.o0</font>";bearSay[15]="<br><font style=background-color:orange;color:white;font-weight:bold>不良小熊</font>"+rTime+"<br><font color=green>我在网通1区玩跑跑卡丁车哦，谁和我一起啊，我叫:<u>胖才稳</u></font>";bearSayNow=bearSay.splice(Math.floor(Math.random()*bearSay.length),1);}else{bearSayNow="";}return bearSayNow;}
function upKey(which){if(which==0){if(event.keyCode==13 || event.enterKey)checkNick();}else if(which==1){if(event.keyCode==13 && event.ctrlKey){$("limit").innerText=99;gbUp();}/*else{sendMsg(2);}*/}else{return false;}}
function rollAll(){$("say").scrollTop=$("say").scrollHeight;}
function toTop(point){content.createTextRange().moveStart("character",point);content.createTextRange().collapse(true);content.createTextRange().select();}     
function checkNick(){if(nickname.value.replace(/( )|($)|(&)/gi,"")==""){if(flag==1){$("say").innerHTML+=master+"不填写昵称，让我怎么称呼你呢。</font><br>";}else if(flag==2){$("say").innerHTML+=master+"真的不留名啊，不留名不能和我说话哦。</font><br>";}else if(flag==3){$("say").innerHTML+=master+"真固执啊，那我只能跟其他人聊天了-_-!!</font><br>";}flag++;rollAll();return false;}else{if(named==1){sendMsg(2);}else{$("say").innerHTML=master+"原来是<u><b>"+nickname.value+"</b></u>啊，幸会幸会，欢迎光顾哇。阁下昵称好眼熟，重名不负责哦T_T<br>";$("say").innerHTML+=master+"<font color=red>如果对这个集群不了解可以输入：<b><br><font color=brown>/?</font>（斜杠+问号）</b><br>进行提交以获得即时帮助。<br><b>Ctrl+Enter继续。</b></font><br>PS.有神秘嘉宾相伴哦~<br>";}content.disabled=false;content.focus();gb.disabled=false;nickname.readOnly=true;setTimeout("sendMsg(3)","6000");}}
function gbUp(){if(content.value.replace(/( )|($)|(&)/gi,"")==""){sendMsg(2);rollAll();return false;}sendMsg(1);rollAll();content.value="";}
function showGB(){$("limit").innerText=99-content.value.length;if($("limit").innerText<=0){$("limit").innerText=0;content.value=content.value.substring(0,98);}}
function send_request(url){http_request=false;if(window.XMLHttpRequest){http_request=new XMLHttpRequest();if (http_request.overrideMimeType){http_request.overrideMimeType('text/xml');}}else if(window.ActiveXObject){try{http_request=new ActiveXObject("Msxml2.XMLHTTP");}catch(e){try{http_request=new ActiveXObject("Microsoft.XMLHTTP");}catch(e){}}}if(!http_request){alert("创建对象实例失败，请确认网络的畅通。");return false;}http_request.onreadystatechange=processRequest;http_request.open("GET",url,true);http_request.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=gb2312");http_request.setRequestHeader("If-Modified-Since","0");http_request.send(null);}function processRequest(){if(http_request.readyState==4){if(http_request.status==200){getMsg=http_request.responseText;if(getMsg=="该用户已经注册。"){$("tip1").innerHTML=getMsg;temp=0;return false;}else if(getMsg.substring(0,5)=="注册成功。"){in_short1.style.display='none';in_short2.style.display='none';in_short3.style.display='';in_short4.style.display='';allow.style.display='none';$("sth").innerText="注册码信息。";temp2=getMsg.split("。");who.value=temp2[1];getTheCodes(who.value);$("tip1").innerHTML="";$("tip2").innerHTML="<font color=#990000>高级用户版本可以拥有自己的用户名。</font><br>请务必牢记，注册码当日有效。<br>如果当日无法注册成功，可于第二日使用解救码进行注册。";ok.style.display='none';}else if(getMsg=="可以使用的用户名。"){$("tip1").innerHTML=getMsg;temp=1;}else if(getMsg.replace(/( )|($)|(&)/gi,"")==""){sendMsg(2);}else{$("say").innerHTML=getMsg;rollAll();content.disabled=false;content.focus();gb.value="确认提交";gb.disabled=false;}}else{alert("您所请求的页面有异常，请刷新再试。");return false;}}}
function sendMsg(kind){if(kind==0){send_request('save.php?username='+username.value+'&email='+email.value+'&rnd1='+rnd1.value+'&rnd_now='+$("rnd2").innerText);}else if(kind==1){getNow();if(tColor=="red"){talker='<font style=background-color:'+tColor+';color:white;font-weight:bold>作者T.Z</font>'+rTime+'<br>';}else{talker='<font style=background-color:'+tColor+';color:white;font-weight:bold>'+nickname.value+'</font>'+rTime+'<br>';}if(content.value.toLowerCase()=="bear come"){bearType=1;}else if(content.value.toLowerCase()=="bear go"){bearType=0;}else if(rDate.test(content.value)){theDate=content.value;sendMsg(2);return false;}else if(content.value.toLowerCase().substring(0,5)=="name " && content.value.replace(/( )|($)|(&)/gi,"").length>5){nickname.value=content.value.substring(5,content.value.length);sendMsg(3);}else if(content.value.toLowerCase()=="/?"){flag=0;$("say").innerHTML=master+"召唤不良小熊：<br><font color=brown>bear come</font><br>关闭小熊的对话：<br><font color=brown>bear go</font><br><b>PS.</b><font color=#006699>不良小熊为作者爱宠，交流可能存在一定的障碍，但是不要伤害它哦@_0~</font><br>察看当日之前的集群讨论内容，直接输入：<br><font color=green>2007xxyy</font><br>更换昵称：<br><font color=brown>name 昵称</font>";}if(flag!==0){gb.value="提交中..";gb.disabled=true;content.disabled=true;bear(bearType);other=bearSayNow+"<br>";content.value=content.value.replace(/\r\n/gi,"<br>");send_request('talk.php?nickname='+talker+'&content='+content.value+'&other='+other);}else{flag++;}}else if(kind==2){if(theDate=="")theDate=rTime2;send_request('get.php?theDate='+theDate);}else if(kind==3){send_request('session.php?nickname='+nickname.value);}rollAll();}
function existMem(){temp=0;tTime=stamp.getHours().toString()+stamp.getMinutes().toString()+stamp.getSeconds().toString();if(username.value==""){$("tip1").innerHTML="用户名不能为空。";username.focus();return false;}else if(username.value.length<3 || username.value.length>12){$("tip1").innerHTML="用户名应在3-12位之间。";username.focus();return false;}else{$("tip1").innerHTML="正在发送数据...";send_request('search.php?username='+username.value);if(temp==0)return false;}}
function allCheck(){if(!rEmail.test(email.value)){$("tip2").innerHTML="<br>Email格式不正确。";email.focus();return false;}else{$("tip2").innerHTML="<br>";}if(rnd1.value!==$("rnd2").innerHTML){$("tip2").innerHTML="<br><br>输入的确认码不正确。";rnd1.focus();return false;}if(temp==1){ok.value="提交中..";ok.disabled=true;sendMsg(0);}}
function allAction(type){for(i=0;i<allPut.length;i++){if(type==1){eval(allPut[i]).disabled=false;username.focus();$("tip1").style.color="red";$("tip2").style.color="red";}else{eval(allPut[i]).disabled=true;$("tip1").style.color="#cccccc";$("tip2").style.color="#cccccc";}}}
function howToKnow(){if(username.value.replace(/( )|($)|(&)/gi,"")!="" && how.value.replace(/( )|($)|(&)/gi,"")!=""){nickname.value=username.value;ok.focus();content.value="我获知本程式的来源："+how.value;sendMsg(1);content.value="";}}
