url=self.location.toString();iev=0;
if(typeof document.all!='object'&&typeof XMLHttpRequest!='object'&&typeof XMLHttpRequest!='function'&&url.indexOf('=browser')==-1){window.location='info.php?reason=browser'}

if(typeof document.all=='object'){
	iev=navigator.userAgent;
	iev=iev.split('MSIE');
	iev=parseInt(iev[1]);
	if(iev<7){
		document.write('<link rel="stylesheet" type="text/css" href="'+skin_dir+'/msie56.css" />');
	}
	document.write('<meta http-equiv="Page-Enter" content="revealtrans(duration=0)"><meta http-equiv="Page-Exit" content="revealtrans(duration=0)">')
	document.write('<link rel="stylesheet" type="text/css" href="'+skin_dir+'/msie.css" />');
}

flash='<object data="'+skin_dir+'/sound.swf" type="application/x-shockwave-flash" width="1" height="1" style="visibility:hidden"><param name="movie" value="'+skin_dir+'/sound.swf" /><param name="menu" value="false" /><param name="quality" value="high" /></object>';


/* --- */

hookevent = function (obj,ev,func){
	obj.attachEvent?obj.attachEvent('on'+ev,func):obj.addEventListener(ev,func,false);
}

unhookevent = function (obj,ev,func){
	obj.detachEvent?obj.detachEvent('on'+ev,func):obj.removeEventListener(ev,func,false);
}

ee = function (id) {
	return document.getElementById(id);
}

focusform = function(e) {
	var mainbox = document.getElementById('inpt');
	var pmbox = eeG || document.getElementById('dvG');
	if(mainbox == undefined || pmbox == undefined) return true;
	if(mainbox.style.visibility == 'visible' && eeG.style.display == 'none') { // we're in a room and the pm box is not opened (i.e. only one input box available)
		//var mainbox = document.formmain["inputmain"];
		// keycode ref.: http://javascript.js-x.com/key_codes/
		if(!e) e = window.event;

		var k = e.keyCode;

		// dont meddle with the following keys
		if (
			(k >= 112 && k <= 123) || // F1 - F12
			(k >= 16 && k <= 18) || // shift, alt, control
			(k >= 33 && k <= 40) || // pgup,pgdown,end,home,left,up,right,down
			(k >= 44 && k <= 46) || // print screen, ins, del
			false
		) return true;

		
		// dont meddle with the following keys
		switch(k) {
			case 8: // bkspc
			case 9: // tab
			case 13: // enter
			case 19: // pause/break
			case 20: // capslock
			case 27: //esc
			case 144: // numlock
			case 145: // scrolllock
				return true;
		}

		var hasModifiers = e.altKey || e.ctrlKey || e.metaKey;

		if (hasModifiers) {
			// don't meddle with keys with a modifier, but allow Ctrl+V since it should paste to the input box
			// hence if the key is not Ctrl+V, then return true
			if (! (e.ctrlKey && e.keyCode == 86) ) { return true; }
		}
		eeL.focus();
	}
	return true;
}


function setWH(){
	if(typeof document.all=='object'&&iev<7){
		dh=document.body.clientHeight;
		if(dh<500){
			self.resizeTo(800,screen.availHeight);
			self.moveTo(0,0)
		}
	}
	adjustChatDivSize();
}

/* --- */

function go(w){a=/&amp;/g;w=w.replace(a,'&');window.location=w;return false;}
function ad(w){eeL.value=eeL.value+ ' '+w+' ';fc();}
function rn(){r=Math.round(99999999*Math.random());return r}
function fc(){eeL.focus()}
function op(m,n){if(typeof document.all=='object'){m.style.filter='alpha(opacity='+n*10+')';}else{m.style.opacity=n/10;}return false}
function q0(){switch(set_midd){case 8:q=5*5+6;break;case 9:q=99999;break;default:q=1;break;}return q;}
function load_genSmilies(){for(i=0;i<smiles.length;i++){document.writeln(' <a href="info.php?reason=link" onclick="ad(\''+smiles[i]+'\');return false"><img class="e" src="'+skin_dir+'/smilies/'+sfiles[i]+'" alt="'+smiles[i]+'" title="'+smiles[i]+'" onmouseover="return op(this,5)" onmouseout="return op(this,10)" /></a> ')}}
function load_genColours(){for(i=0;i<colors.length;i++){document.writeln('<img class="r" src="incl/trans.png" onclick="set_color(\'#'+colors[i]+'\')" style="background-color:#'+colors[i]+'" alt="" />')}}

function adtime(w){
	if(eeG.style.display=='none')	{
		eeL.value=eeL.value+ ' '+w+' ';fc();
	}else{
		eeM.value=eeM.value+ ' '+w+' ';eeM.focus();
	}
}

function adtime2(w){
	if(window.opener.parent.eeG.style.display=='none'){
		window.opener.parent.eeL.value=window.opener.parent.eeL.value+ ' '+w+' ';window.opener.parent.eeL.focus();
	}else{
		window.opener.parent.eeM.value=window.opener.parent.eeM.value+ ' '+w+' ';window.opener.parent.eeM.focus();
	}
}

/* --- */

function check_log(w){
	f=document.forms.fms;ok=1;a=f.name;b=f.pass
	if(typeof f.turnum=='object'){
		c=f.turnum;d=parseInt(c.value);d=d.toString()
		if(d.length!=5){c.value='';c.focus();ok=0}
	}
	if(a.value==b.value){a.value='';b.value='';a.focus();ok=0}
	if(b.value.length<3){b.value='';b.focus();ok=0}
	if(a.value.length<3){a.value='';a.focus();ok=0}
	if(ok==1){return true}
	else{
		document.getElementById('emms').innerHTML=w
		return false
	}
}

/* --- */

function check_reg(w){
	f=document.forms.fms;ok=1;a=f.name
	b=f.pass;c=f.cass;g=f.mail
	if(typeof f.turnum=='object'){
		d=f.turnum;
		e=parseInt(d.value);
		e=e.toString();
		if(e.length!=5){d.value='';d.focus();ok=0}
	}
	if(g.value.length<7||g.value.indexOf('@')==-1||g.value.indexOf('.')==-1){g.value='';g.focus();ok=0}
	if(b.value.length<3){b.value='';b.focus();ok=0}
	if(b.value!=c.value){b.value='';c.value='';b.focus();ok=0}
	if(a.value==b.value){b.value='';c.value='';b.focus();ok=0}
	if(a.value.length<3){a.value='';a.focus();ok=0}
	if(ok==1){return true}
	else{document.getElementById('emms').innerHTML=w;return false}
}

/* --- */

function check_pro(){
	f=document.forms.fms;ok=1;
	a=f.oass;b=f.pass;c=f.cass;d=f.mail
	if(d.value.length<7||d.value.indexOf('@')==-1||d.value.indexOf('.')==-1){
		f.reset();ok=0
	}
	if(a.value.length>0||b.value.length>0||c.value.length>0){
		if((b.value!=c.value)||a.value.length<3||b.value.length<3||a.value==b.value){
			a.value='';b.value='';c.value='';a.focus();ok=0
		}
	}
	if(ok==1){return true}else{return false}
}

/* --- */

function check_ver(w){
	f=document.forms.fms;ok=1;a=f.vcode
	if(typeof f.turnum=='object'){
		d=f.turnum;e=parseInt(d.value);e=e.toString();
		if(e.length!=5){d.value='';d.focus();ok=0}
	}
	if(a.value.length!=8){a.value='';a.focus();ok=0}
	if(ok==1){return true}else{document.getElementById('emms').innerHTML=w;return false}
}

/* --- */

function check_fps(w){
	f=document.forms.fms;ok=1;g=f.mail
	if(typeof f.turnum=='object'){
		d=f.turnum;e=parseInt(d.value);e=e.toString()
		if(e.length!=5){d.value='';d.focus();ok=0}
	}
	if(g.value.length<7||g.value.indexOf('@')==-1||g.value.indexOf('.')==-1){g.value='';g.focus();ok=0}
	if(ok==1){return true}else{document.getElementById('emms').innerHTML=w;return false}
}

/* --- */

function http_obj(){
	if(typeof document.all=='object'){
		r=new ActiveXObject("Microsoft.XMLHTTP")
	}else{r=new XMLHttpRequest()}
	return r
}

/* --- */

function reset_some(){
	eeE.style.display='none'
	eeF.style.display='none'
	eeG.style.display='none'
	eeI.style.display='none'
	eeK.style.display='none'
}

/* --- */
function reset_top(){
	eeY.style.display='none'
	eeYY.style.display='none'
}

/* --- */

function reset_all(){
	elements();reset_some();reset_top();
	lock1=0;lock2=0;lock3=0;
	txt='';ajx_line='';ajx_last=0;ajx_toid=0;ajx_room=0;ajx_cmnd=0;
	eeA.innerHTML='';
	eeAA.innerHTML='';
	eeB.innerHTML='';
	eeYY.innerHTML='';
	document.getElementById('reqt').innerHTML='';
	document.getElementById('quer').innerHTML='';
	document.getElementById('inpt').style.visibility='hidden'
	eeB.style.display='none'
	eeC.style.display='none'
	eeJ.style.display='none'

	if(typeof room_tout=='number'){clearTimeout(room_tout)}
	if(typeof chat_tout=='number'){clearTimeout(chat_tout)}
}

/* --- */

//function not_connected(){
//	if(ajx_sndd==1){allow_flash=flash}else{allow_flash=''}
//	tit='<br /><br />'+set_disc+'<br /><a href="blab.php?r='+r+'"><b>'+set_clck+'</b></a>'+allow_flash;
//	if(typeof room_tout=='number'){clearTimeout(room_tout)}
//	if(typeof chat_tout=='number'){clearTimeout(chat_tout)}
//	eeB.innerHTML=tit
//}

not_connected = function(){
	var ihtml = '<div class="msgDisconnected">' + set_disc;
	if(typeof room_tout == 'number') {
		clearTimeout(room_tout);
		room_tout = undefined;
		ihtml += ' <a href="javascript:void(0)" onClick="try{room();}finally{return false;}"><b>'+set_clck+'</b></a>';
	} else if(typeof chat_tout == 'number') {
		clearTimeout(chat_tout);
		chat_tout = undefined;
		ihtml += ' <a href="javascript:void(0)" onClick="try{chat();}finally{return false;}"><b>'+set_clck+'</b></a>';
	} else {
		ihtml += ' <a href="blab.php?r=' + r + '&ref=dc&t=' + (new Date).getTime() + '"><b>' + set_clck + '</b></a>';
	}
	ihtml += '</div>';
	core_appendlog(ihtml);
}

/* --- */

function connected(){
	if(sup_errs<1){
		r=rn();
		if(typeof conn_tout=='number')
			clearTimeout(conn_tout);
		conn_tout=setTimeout('not_connected()',set_refr*6000);
	}
}

/* --- */

function set_post(){
	if(lock1==0){
		if(eeL.value.length>0){
			ajx_line=eeL.value;eeL.value='';
			stlB=stlB.toString();stlI=stlI.toString()
			stlU=stlU.toString();stlC=stlC.toString()
			ajx_lbiu=stlB+stlI+stlU;ajx_lclr=stlC

			if(ajx_toid==0){fc()}
			if(typeof chat_tout=='number'){clearTimeout(chat_tout)}
			chat();
		}
	}
}

/* --- */

function set_private(){
	if(lock1==0){
		if(eeM.value.length>0){
			mpt=eeL.value;
			ajx_toid=tmp;
			eeL.value=eeM.value;
			eeM.value='';
			eeM.focus();
			set_post();
			eeL.value=mpt;
			ajx_toid=0;
		}
	}
}

/* --- */

function set_color(w){
	eeL.style.color=w;
	eeM.style.color=w;
	document.getElementById('cl').style.backgroundColor=w;
	eeC.style.display='block';
	eeE.style.display='none';
	eeF.style.display='none';
	eeI.style.display='none';
	eeK.style.display='none';
	stlC=w;
	fc();
}

/* --- */

function set_time(s){
	if(ajx_room>0){
		mpt=eeL.value;
		s=parseInt(s);
		ajx_zone=parseInt(ajx_zone);
		ajx_toid=ajx_user;
		if(s==0){ajx_zone=0;}else{ajx_zone=s;}
		eeL.value='GMT ['+ajx_zone+']';
		set_post();
		ajx_toid=0;
		eeL.value=mpt;
		eeI.style.display='none';
		fc();
	}
}

/* --- */

function set_sound(q,r){
	if(ajx_room>0){
		ajx_sndd=q;
		/*
		mpt=eeL.value;
		ajx_toid=ajx_user;
		eeL.value=r
		set_post();
		ajx_toid=0;
		eeL.value=mpt;
		*/
		eeK.style.display='none';
		fc();
	}
}

/* --- */

function show_colors(){
	if(ajx_room!=0){
		if(eeF.style.display!='block'){
			reset_some();
			eeF.style.display='block';
		}else{
			reset_some();
		}
		fc();
	}
}
/* --- */

function show_sound(){
	if(ajx_room>0){
		if(eeK.style.display=='none'){
			reset_some();
			eeK.style.display='block';
		}else{
			reset_some()
		}
		fc();
	}
}

/* --- */

function show_smilies(){
	if(ajx_room>0){
		if(eeE.style.display!='block'){
			reset_some();eeE.style.display='block';
		}else{
			reset_some()
		}
		fc();
	}
}

/* --- */

function show_links(){
	if(ajx_room>0){
		if(eeYY.style.display!='block'){
			reset_top();eeYY.style.display='block';
		}else{
			reset_top()
		}
		fc();
	}
}

/* --- */

function show_funcs(){
	if(eeY.style.display!='block'){
		reset_top();eeY.style.display='block';
	}else{
		reset_top()
	}
	fc();

}

/* --- */

function show_time(){
	if(ajx_room>0){
		if(eeI.style.display=='none'){
			reset_some();
			eeI.style.display='block';
		}else{
			reset_some()
		}
		fc();
	}
}

/* --- */

function show_user(s,t){
	reset_some();
	s=parseInt(s);
	if(s<100000000||s>500000000){eeH.innerHTML='';user(s);}
	else{eeH.innerHTML=' <div style="font-weight:bold" class="s">'+t+'<br /><br /></div>'}
	eeG.style.display='block';
	tmp=s;
	eeM.focus();
}

/* TBC */

function show_rname(p,q){
	p=parseInt(p);
	eeA.innerHTML=q+'<span style="font-weight:normal">&nbsp;&nbsp;&nbsp;<a href="info.php?reason=link" class="tt2" onclick="pp=window.open(\'history.php?room='+p+'\',\'history\',\'width=800,height=600,resizable=0,scrollbars=1\');pp.focus();return false">'+set_hist+'</a> (<a href="info.php?reason=link" class="tt2" onclick="pp=window.open(\'search.php?room='+p+'\',\'search\',\'width=800,height=600,resizable=0,scrollbars=1\');pp.focus();return false">'+set_sech+'</a>)</span>';
	eeYY.innerHTML='<div><span style="font-weight:normal"> <b>&middot;</b> <a href="info.php?reason=link" class="tt2" onclick="pp=window.open(\'rules.htm\');pp.focus();return false">'+set_rule+'</a></div><div><span style="font-weight:normal"> <b>&middot;</b> <a href="info.php?reason=link" class="tt2" onclick="pp=window.open(\'history.php?room='+p+'\',\'history\',\'width=800,height=600,resizable=0,scrollbars=1\');pp.focus();return false">'+set_hist+'</a> (<a href="info.php?reason=link" class="tt2" onclick="pp=window.open(\'search.php?room='+p+'\',\'search\',\'width=800,height=600,resizable=0,scrollbars=1\');pp.focus();return false">'+set_sech+'</a>)</span></div><div><span style="font-weight:normal"> <b>&middot;</b> <a href="info.php?reason=link" class="tt2" onclick="pp=window.open(\'penalty.php\',\'penalty\',\'width=800,height=600,resizable=0,scrollbars=1\');pp.focus();return false">'+set_penl+'</a></span></div><div><b>&middot;</b> <a href="info.php?reason=link" class="tt2" onclick="pp=window.open(\'equivalence.htm\');pp.focus();return false">'+set_eqiv+'</a></span></div>';
}

/* --- */

function show_msg(tt){
	pp=window.open('msg.php?room='+ajx_room+'&msgt='+tt+'','msg','width=400,height=200,resizable=0,scrollbars=1');
	pp.focus();
}

/* --- */

function log(p){
	var startTime = new Date();
	r=rn();
	s='ajx_room='+p+'&ajx_user='+ajx_user+'&ajx_funn='+ajx_funn+'&ajx_code='+ajx_code+'&ajx_name='+ajx_name+'&ajx_sess='+ajx_sess+'&rnd='+r;
	http_log.open('post','log.php');
	http_log.onreadystatechange=function (){ null; }
	http_log.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	http_log.onreadystatechange=function (){
		if(http_log.readyState==4){
			try { http_log.status; } catch(e){ return false; } 
			var responseTime = new Date() - startTime;
			if(ajx_user=='32')
				ee('httpResponse').innerHTML = ' ' + responseTime + 'ms ' + http_log.status;
			if(http_log.status == 200) { //OK
				response=http_log.responseText.toString()
				if(response.length<2){response=parseInt(response)}
				if(!isNaN(response)&&response>0){
					if(sup_errs<1){url='info.php?reason='+response;go(url)}
					else{response=response.toString();
						txt=response;
						core_appendlog(response); //eeB.innerHTML=response;
					}
				}else{

					response=response.toString();
					reply=response.split('^');

					txt=reply[0].toString();
					core_appendlog(txt); //eeB.innerHTML=txt;
					eeB.style.display="block";
					eeC.style.display="block";	
					eeD.style.display="none";	
					eeJ.style.display="inline";	
					document.getElementById("inpt").style.visibility="visible";
					adjustChatDivSize();

					slast=reply[1].toString();
					ajx_last=slast;

				}
			}
		}
	}
	http_log.send(s);
}

/* --- */

function pen(){
	id=parseInt(tmp)
	if(!isNaN(id)&&id>0){
		uri='penalty.php?penalty='+id;
		bnw=window.open(uri,'bn_win','width=300,height=200,resizable=1');
		bnw.focus();
	}
}



/* --- */

function ban(){
	id=parseInt(tmp)
	if(!isNaN(id)&&id>0){
		uri='ban.php?ban='+id;
		bnw=window.open(uri,'bn_win','width=300,height=200,resizable=1');
		bnw.focus();
	}
}

/* --- */

function room(){
	if(lock2==0&&lock1==0){
		var startTime = new Date();
		//reset_all();
		r=rn();
		lock2=1;

		s='ajx_user='+ajx_user+'&ajx_code='+ajx_code+'&ajx_mod='+ajx_mod+'&ajx_com='+ajx_com+'&ajx_name='+ajx_name+'&ajx_sess='+ajx_sess+'&rnd='+r;
		http_room.open('post','rooms.php');
		http_room.onreadystatechange=function(){null;};
		http_room.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		http_room.onreadystatechange=function(){
			if(http_room.readyState==4){
				// test if http.status is ready (in some funny cases, it is not)
				// cannot use if(!http.status), since it will still issue errors
				try { http_room.status; } catch(e){ return false; } 
				var responseTime = new Date() - startTime;
				if(ajx_user=='32')
					ee('httpResponse').innerHTML = ' ' + responseTime + 'ms ' + http_room.status;
				if(http_room.status == 200) { //OK
					nidd=q0();midd=0;lock4=0;
					response=http_room.responseText.toString();
					if(response.length<2){response=parseInt(response)}
					if(!isNaN(response)&&response>0){
						if(sup_errs<1){
							url='info.php?reason='+response;
							go(url);
						}
					}else if(ajx_cmnd==1){
						response=response.toString();
						lines=response.split('^');
							aline=lines[0].toString(); // ***
							aline=aline.split('|');
							if(aline[3]){
							show_rname(aline[0],aline[1]);ajx_room=aline[0];log(aline[0]);chat();
							}
					}else{

						eeD.style.display='block';
						rooms='<div style="width:400px;margin:auto"><table style="width:100%" class="d" cellspacing="0"><tr class="b"><td colspan="2" class="b"><div class="u">'+set_rnme+'</div></td></tr>';

						response=response.toString();
						lines=response.split('^');
						for(i=0;i<lines.length;i++){
							aline=lines[i].toString();
							aline=aline.split('|');
							if(aline[3]){
								cu=parseInt(aline[3]);
								midd+=cu;
								rooms=rooms+'<tr class="c"><td class="c" style="padding:12px">';
								if(cu<set_uspr){rooms=rooms+'<a class="u" href="info.php?reason=link" onclick="if(lock4==0){show_rname('+aline[0]+',\''+aline[1]+'\');ajx_room='+aline[0]+';log('+aline[0]+');chat()};return false"><b>'+aline[1]+'</b></a>'}
								else{rooms=rooms+'<b class="u">'+aline[1]+'</b>'}
								rooms=rooms+'<div class="s">'+aline[2]+'</div></td><td style="text-align:center" class="s">&nbsp;'+set_onle+': '+aline[3]+'&nbsp;</td></tr>';
							}
						}
						rooms=rooms+'</table></div>';
						eeD.innerHTML=rooms
					}
					if(midd>nidd){lock4=1;}
				}
				lock2=0;
				connected(); //Modified by Small Potato at 2008/12/16: added heart beating "connected()" to room_answer()
				room_tout=setTimeout('room()',set_refr*2000);
			}
		}
		http_room.send(s)
	}
}

/* --- 

function chat(){

	if(ajx_room>0&&lock1==0){
		eeD.style.display='none';
		eeJ.style.display='inline';

		r=rn();lock1=1;
		if(typeof room_tout=='number'){clearTimeout(room_tout)}
		s='ajx_user='+ajx_user+'&ajx_name='+ajx_name+'&ajx_code='+ajx_code+'&ajx_mod='+ajx_mod+'&ajx_funn='+ajx_funn+'&ajx_sess='+ajx_sess+'&ajx_last='+ajx_last+'&ajx_room='+ajx_room+'&ajx_zone='+ajx_zone+'&ajx_tfrm='+ajx_tfrm+'&ajx_toid='+ajx_toid+'&rnd='+r;
		http_chat.open('post','aroom.php');
		if(ajx_line!=''){
			per=/%/g;ajx_line=ajx_line.replace(per,'%25');
			amp=/&/g;ajx_line=ajx_line.replace(amp,'%26');
			pl=/\+/g;ajx_line=ajx_line.replace(pl,'%2B');
			s=s+'&ajx_line='+ajx_line+'&ajx_lbiu='+ajx_lbiu+'&ajx_lclr='+ajx_lclr
		}
		ajx_line='';
		http_chat.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		http_chat.onreadystatechange=chat_answer;
		http_chat.send(s);
	}
}

/* --- */

chat = function (){

	if(ajx_room>0&&lock1==0){
		var startTime = new Date();
		r=rn();lock1=1;
		if(typeof room_tout=='number'){clearTimeout(room_tout)}
		s='ajx_user='+ajx_user+'&ajx_name='+ajx_name+'&ajx_code='+ajx_code+'&ajx_mod='+ajx_mod+'&ajx_funn='+ajx_funn+'&ajx_sess='+ajx_sess+'&ajx_last='+ajx_last+'&ajx_room='+ajx_room+'&ajx_zone='+ajx_zone+'&ajx_tfrm='+ajx_tfrm+'&ajx_toid='+ajx_toid+'&rnd='+r;
		http_chat.open('post','aroom.php');
		if(ajx_line!=''){
			per=/%/g;ajx_line=ajx_line.replace(per,'%25');
			amp=/&/g;ajx_line=ajx_line.replace(amp,'%26');
			pl=/\+/g;ajx_line=ajx_line.replace(pl,'%2B');
			s=s+'&ajx_line='+ajx_line+'&ajx_lbiu='+ajx_lbiu+'&ajx_lclr='+ajx_lclr
		}
		ajx_line='';
		http_chat.onreadystatechange = function(){null;};
		http_chat.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		var chat_answer = function chat_answer(){
			if(http_chat.readyState==4){
				// test if http.status is ready (in some funny cases, it is not)
				// cannot use if(!http.status), since it will still issue errors
				try { http_chat.status; } catch(e){ return false; } 
				var responseTime = new Date() - startTime;
				if(ajx_user=='32')
					ee('httpResponse').innerHTML = ' ' + responseTime + 'ms ' + http_chat.status;
				if(http_chat.status == 200) { //OK
					response=http_chat.responseText.toString();
					if(response.length<2){
						response=parseInt(response)
						if(!isNaN(response)&&response>0){
							if(sup_errs<1){url='info.php?reason='+response;go(url);}
							//else{chat_tout=setTimeout('chat()',set_refr*1000);}
						}
					}else{
						//online='<div style="overflow:hidden" class="b">'+set_onle+'</div><div style="padding:5px;overflow:auto;height:' + (eeC.offsetHeight - (eeC.childNodes.length ? eeC.firstChild.offsetHeight : 33)) + 'px">';
						online = '';
						addlns='';

						response=response.toString();
						reply=response.split('^');

						if(!reply[4]){
							//if(sup_errs<1){url='info.php?reason='+response;go(url);} //surpress all errors!
							//else{chat_tout=setTimeout('chat()',set_refr*1000);}
						}else if(!isNaN(reply[0])) { // Modified by Small Potato at 2008/12/16 - bugfix for eaten msg. This line was: "}else{" instead of "}else if(!isNaN(reply[0])) {"
							ajx_last=Number(reply[0]);
							//slast=reply[0].toString();
							lines=reply[1].toString();
							users=reply[2].toString();
							queri=reply[3].toString();
							ttrun=reply[4].toString();
							anoun=reply[5].toString();

							//ajx_last=slast;

							users=users.split('|');
							for(i=0;i<users.length;i++){
								aline=users[i].toString();
								aline=aline.split('*');
								if(parseInt(aline[1])==parseInt(ajx_user)){dtt=' &not;'}else{dtt=''}
								online=online+'<a href="info.php?reason=link" title="'+set_usri+'" class="o" onclick="show_user('+aline[1]+',\''+aline[0]+'\');return false">&middot; '+aline[0]+dtt+'</a><br />';
							}

							lines=lines.split('|');
							for(i=0;i<lines.length;i++){
								aline=lines[i].toString()
								aline=aline.split('*');
								if(aline.length > 3){ // 2009-04-29: was "if(aline[3]){" , which made cr skip all empty lines (those cases where aline[3] is an empty string)
									tmm=aline[0].toString();
									usr=aline[1].toString();
									too=aline[2].toString();

									if(tmm.length>1){tmm='<span class="msgTime"><a href="info.php?reason=link" class="tt2" onclick="adtime(\'['+tmm+']\');return false">['+tmm+']</a></span>  ';}

									if(too.length>1){
										whsp=' [<span class="msgArrow">&raquo;</span>] <span class="msgRecipient">'+too+'</span>';
									}else{whsp=''}

									if(usr.length>1){
										usr='<span class="msgSender">'+usr+'</span>'+whsp+':';
										usr='<span class="msgNick">'+usr+'</span>'
									}
									addlns += '<div class="msg' + (whsp.length ? 'Private' : 'Public') + '">' + tmm + usr + ' ' + aline[3] + '</div>'; //TODO: surround this with a <div> for easier message searching
								}
							}
							
							if(addlns.length>9){
								//txt=decr_lines(txt); //dont need to limit to 30 lines
								//txt=txt+addlns;
								//eeB.innerHTML=txt+allow_flash;
								//if(ajx_sndd==1){allow_flash=flash}else{allow_flash=''}
								core_appendlog(addlns);
								txt += addlns; //keep a copy of innerHTML in txt just for legacy (?) purpose
							}

							var allowance = 10; // allow some room for it to wriggle around
							var atBottom = (eeC.scrollTop + allowance >= eeC.scrollHeight - (eeC.innerHeight ? eeC.innerHeight : eeC.clientHeight));
							eeC.lastChild.innerHTML=online;
							eeAA.innerHTML=anoun;
							if(atBottom)
								setTimeout("eeC.scrollTop = eeC.scrollHeight", 0);

								document.getElementById('reqt').innerHTML=ttrun+'ms';
							//if(ajx_user=='1' || ajx_user=='32'){
							//	document.getElementById('quer').innerHTML=' ['+queri+']'
							//}
						}
					}
				}
				lock1=0;
				connected();
				chat_tout=setTimeout('chat()',set_refr*1000);
			}
		}
		http_chat.onreadystatechange=chat_answer;
		http_chat.send(s);
	}
}


/* --- */

function user(q){
	q=parseInt(q);
	if(q<100000000 || q>500000000){
		if(ajx_room>0&&lock3==0){
			var startTime = new Date();
			r=rn();lock3=1;
			q=parseInt(q);
			s='ajx_user='+ajx_user+'&ajx_name='+ajx_name+'&ajx_code='+ajx_code+'&ajx_sess='+ajx_sess+'&ajx_unfo='+q+'&set_extn='+set_extn+'&rnd='+r;
			http_user.open('post','user.php');
			http_user.onreadystatechange=function(){null;};
			http_user.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			http_user.onreadystatechange=function(){
				if(http_user.readyState==4){
					// test if http.status is ready (in some funny cases, it is not)
					// cannot use if(!http.status), since it will still issue errors
					try { http_user.status; } catch(e){ return false; } 
					var responseTime = new Date() - startTime;
					if(ajx_user=='32')
						ee('httpResponse').innerHTML = ' ' + responseTime + 'ms ' + http_user.status;
					if(http_user.status == 200) { //OK
						response=http_user.responseText.toString()
						if(response.length<2){
							response=parseInt(response);
						}
						if(!isNaN(response)&&response>0){
							if(sup_errs<1){
								url='info.php?reason='+response;
								go(url);
							}else{
								document.getElementById('dvG').style.display='none';
							}
						}else{
							eeH.innerHTML=response;
						}
					}
					lock3=0;
				}
			}
			http_user.send(s);
		}
	}
}

/* --- */

function user_answer(){
	if(http_user.readyState==4){
		response=http_user.responseText.toString()
		if(response.length<2){
			response=parseInt(response);
		}
		if(!isNaN(response)&&response>0){
			if(sup_errs<1){
				url='info.php?reason='+response;
				go(url);
			}else{
				document.getElementById('dvG').style.display='none';
			}
		}else{
			eeH.innerHTML=response;

			//added automatic grayscale by Small Potato on 24 Aug 2010
			//try{
			//	grayscale(eeH);
			//} catch(e) {}
		}
		lock3=0;
	}
}

/* --- */

function room_answer(){
	if(http_room.readyState==4){
		nidd=q0();midd=0;lock4=0;
		response=http_room.responseText.toString();
		if(response.length<2){response=parseInt(response)}
		if(!isNaN(response)&&response>0){
			if(sup_errs<1){
				url='info.php?reason='+response;
				go(url);
			}else{
				room_tout=setTimeout('room()',set_refr*2000);
			}
		}else{

			eeD.style.display='block';
			rooms='<div style="width:400px;margin:auto"><table style="width:100%" class="d" cellspacing="0"><tr class="b"><td colspan="2" class="b"><div class="u">'+set_rnme+'</div></td></tr>';

			response=response.toString();
			lines=response.split('^');
			for(i=0;i<lines.length;i++){
				aline=lines[i].toString();
				aline=aline.split('|');
				if(aline[3]){
					cu=parseInt(aline[3]);
					midd+=cu;
					rooms=rooms+'<tr class="c"><td class="c" style="padding:12px">';
					if(cu<set_uspr){rooms=rooms+'<a class="u" href="info.php?reason=link" onclick="if(lock4==0){show_rname('+aline[0]+',\''+aline[1]+'\');ajx_room='+aline[0]+';log('+aline[0]+');chat()};return false"><b>'+aline[1]+'</b></a>'}
					else{rooms=rooms+'<b class="u">'+aline[1]+'</b>'}
					rooms=rooms+'<div class="s">'+aline[2]+'</div></td><td style="text-align:center" class="s">&nbsp;'+set_onle+': '+aline[3]+'&nbsp;</td></tr>';
				}
			}
			rooms=rooms+'</table></div>';
			eeD.innerHTML=rooms
			
			//added automatic grayscale by Small Potato on 24 Aug 2010
			//try{
			//	grayscale(eeD);
			//} catch(e) {}
		}
		if(midd>nidd){lock4=1;}
		lock2=0;
		connected(); //Modified by Small Potato at 2008/12/16: added heart beating "connected()" to room_answer()
		room_tout=setTimeout('room()',set_refr*2000);
	}
}

/* --- */

function chat_answer(){

	if(http_chat.readyState==4){
		eeB.style.display='block';
		eeC.style.display='block';
		document.getElementById('inpt').style.visibility='visible';
		response=http_chat.responseText.toString();
		if(response.length<2){response=parseInt(response)}
		if(!isNaN(response)&&response>0){
			if(sup_errs<1){url='info.php?reason='+response;go(url);}
			else{chat_tout=setTimeout('chat()',set_refr*1000);}
		}else{
			online='<div style="overflow:hidden" class="b">'+set_onle+'</div><div style="padding:5px;overflow:auto;height:279px">';
			addlns='';

			response=response.toString();
			reply=response.split('^');

			if(!reply[4]){
				if(sup_errs<1){url='info.php?reason='+response;go(url);}
				else{chat_tout=setTimeout('chat()',set_refr*1000);}
			}else if(!isNaN(reply[0])) { // Modified by Small Potato at 2008/12/16 - bugfix for eaten msg. This line was: "}else{" instead of "}else if(!isNaN(reply[0])) {"
				ajx_last=Number(reply[0]);
				//slast=reply[0].toString();
				lines=reply[1].toString();
				users=reply[2].toString();
				queri=reply[3].toString();
				ttrun=reply[4].toString();

				//ajx_last=slast;

				users=users.split('|');
				for(i=0;i<users.length;i++){
					aline=users[i].toString();
					aline=aline.split('*');
					if(parseInt(aline[1])==parseInt(ajx_user)){dtt=' &not;'}else{dtt=''}
					online=online+'<a href="info.php?reason=link" title="'+set_usri+'" class="o" onclick="show_user('+aline[1]+',\''+aline[0]+'\');return false">&middot; '+aline[0]+dtt+'</a><br />';
				}

				lines=lines.split('|');
				for(i=0;i<lines.length;i++){
					aline=lines[i].toString()
					aline=aline.split('*');
					if(aline[3]){
						tmm=aline[0].toString();
						usr=aline[1].toString();
						too=aline[2].toString();

						if(tmm.length>1){tmm='<span class="s"><a href="info.php?reason=link" class="tt2" onclick="adtime(\'['+tmm+']\');return false">['+tmm+']</a></span>  ';}

						if(too.length>1){
							whsp=' <b>&raquo;</b> <b>'+too+'</b>';
						}else{whsp=''}

						if(usr.length>1){
							usr='<b>'+usr+'</b>'+whsp+':';
							usr='<span class="s">'+usr+'</span>'
						}
						addlns=addlns+tmm+usr+' '+aline[3]+'<br />';
					}
				}

				if(addlns.length>9){
					txt=decr_lines(txt);
					txt=txt+addlns;
					if(ajx_sndd==1){allow_flash=flash}else{allow_flash=''}
					eeB.innerHTML=txt+allow_flash;
				}

				eeC.innerHTML=online+'</div>';
				eeB.scrollTop=999999;

				//if(ajx_user=='1'){
					document.getElementById('reqt').innerHTML=ttrun+'ms';
				//	document.getElementById('quer').innerHTML=' ['+queri+']'
				//}
				
				//added automatic grayscale by Small Potato on 24 Aug 2010
				// try{
					// grayscale(eeC);
					// grayscale(eeB);
				// } catch(e) {}
			}
			lock1=0;
			connected();
			chat_tout=setTimeout('chat()',set_refr*1000);
		}
	}
}

/* --- */

function decr_lines(t){
	l=30;
	a=t.split('<br />');
	if(a.length>l){
		b=a.length-l;t=a[b];
		for(i=b+1;i<a.length;i++){t=t+'<br />'+a[i];}
	}
	return t;
}

/* --- */

function elements(){
	eeA=document.getElementById('dvA');
	eeAA=document.getElementById('dvAA');
	eeB=document.getElementById('dvB');
	eeC=document.getElementById('dvC');
	eeD=document.getElementById('dvD');
	eeE=document.getElementById('dvE');
	eeF=document.getElementById('dvF');
	eeG=document.getElementById('dvG');
	eeH=document.getElementById('dvH');
	eeI=document.getElementById('dvI');
	eeJ=document.getElementById('dvJ');
	eeK=document.getElementById('dvK');
	eeY=document.getElementById('dvY');
	eeYY=document.getElementById('dvYY');
	eeL=document.getElementById('ln');
	eeM=document.getElementById('pm');
}

adjustChatDivSize = function() {
	try{
		if(document.URL.indexOf("blab.php") != -1) {
			var sw = window.innerWidth?window.innerWidth:document.documentElement.clientWidth;
			var sh = window.innerHeight ? window.innerHeight : (document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight);
			//eeB.style.height = (sh - ee('dvx').offsetHeight /* weather bar */ - ee('dvA').offsetHeight /* name of room */ - ee('dvz').offsetHeight /* input box form */ - ee('reqt').offsetHeight /* request time + # of queries run */) + 'px';
			eeAA.style.width = (sw - eeAA.offsetLeft) + 'px';
			eeB.style.height = (ee('reqt').parentNode.offsetTop /* request time + # of queries run */ - eeB.offsetTop) + 'px';
			eeC.style.height = (ee('reqt').parentNode.offsetTop /* input box form */ - eeC.offsetTop) + 'px';
			if(eeC.childNodes.length > 1) { //browsers showing different slightly offsets. argh!
				//javascript:void(alert(parseFloat(navigator.appVersion)))

				//TODO: Check Opera's offset
				/*@cc_on
				@if (@_jscript_version <= 5.6)
				var offset = 0; // IE6
				@else @*/
				var offset = 13; // Google Chrome + IE7 + default
				/*@end @*/
				if(navigator.userAgent.indexOf("Chrome") == -1 // We want Firefox, but Google Chrome (not using Gecko) has "like Gecko" in the user-agent string
				&& navigator.userAgent.indexOf("Gecko") != -1)
					offset = 10; // Firefox

				eeC.lastChild.style.height = (eeC.offsetHeight - eeC.firstChild.offsetHeight - offset) + 'px';
				//eeC.lastChild.style.height = (eeC.offsetHeight - eeC.lastChild.offsetTop - offset) + 'px';
			}
		}
	} catch(e) {}
}

core_appendlog = function(ihtml) {
	//Check scroll status before we add to innerHTML
	var allowance = 10; // allow some room for it to wriggle around
	var atBottom = (eeB.scrollTop + allowance >= eeB.scrollHeight - (eeB.innerHeight?eeB.innerHeight:eeB.clientHeight));

	//Create a new <div>
	var newdiv = document.createElement('DIV');
	newdiv.innerHTML = ihtml;
	eeB.appendChild(newdiv);
	
	//added automatic grayscale by Small Potato on 24 Aug 2010
	// try{
		// grayscale(newdiv);
	// } catch(e) {}

	if(ajx_sndd == 1) {
		core_playsound(skin_dir+'/sound.mp3');
	}
	if(atBottom)
		setTimeout("eeB.scrollTop = eeB.scrollHeight", 0); //setTimeout to make it thread safe (i.e. ensure the innerHTML is added before changing the scrollTop)

}

core_playsound = function(url) {
	var s = document.getElementById("divsound");
	if (!s) {
		var newdiv = document.createElement("DIV");
		newdiv.id = "divsound";

		// hide it hackishly (visibility: hidden could be problematic)
		newdiv.style.position = "absolute";
		newdiv.style.top = "1px";
		newdiv.style.left = "-30px";

		document.body.appendChild(newdiv);

		s = newdiv;
	}
	var mime_type = "audio/mpeg"; // this is the standard mime type

	// workaround the stupid "feature" where the WMP plugin doesn't handle audio/mpeg (but it could!) in Windows Firefox
	var ua_lower = navigator.userAgent.toLowerCase();
	if (ua_lower.indexOf("gecko") != -1  && ua_lower.indexOf("windows") != -1) { mime_type = "video/x-ms-wmv"; }

	s.innerHTML = '<object data="'+url+'" type="'+mime_type+'" width="10" height="10"><param name="ShowStatusBar" value="1"><param name="src" value="'+url+'"><param name="autostart" value="1"><param name="volume" value="0"></object>';
}
