scrolldelay = 1000;
aliveinterval = 60000;
refreshdelay = 10000;
autokick = 0;
send_blocking_timeout = 15000;

flooding_maxnum = 5;
flooding_interval = 5000;
flooding_warnings = 1;
flooding_expireinterval = 600000;

function showReminder()
{
	hwnd=window.open(cgi+"&action=reminder","reminder","resizable=yes,bars=yes,width=430,height=200");
}
function setLocation(location,link)
{
	location.replace(link);
}
function doLogin()
{
	parent.data.document.form.mustLogout.value=0;
	setLocation(parent.location,cgi+"&action=logout");
}
function doSend()
{
	text = parent.input.document.inputForm.text.value;
	if(text.indexOf('/msg') != -1)
	{
		MsgTest = text.split(' ');
		i = 0;
		while(MsgTest[i].length == 0) i++;
		if(MsgTest[i] != '/msg') if(confirm("you got the /msg in the wrong place!\n do you want to send anyway?") == false) return 0;
	}
	AddToBuffer(text);
	sendText(text);
	parent.input.document.inputForm.text.value = "";
	parent.input.document.inputForm.text.focus();
	return false;
}
function sendText(text,frame)
{
	if (parent.input && parent.input.document && parent.input.document.sendForm)
	{
		parent.data.document.form.buffer.value += text+'\x01';
		if (getSendAllowed(frame) != 0)
		{
			setSendAllowed(0,frame);
			parent.input.document.sendForm.text.value = parent.data.document.form.buffer.value;
			parent.data.document.form.buffer.value = "";
			parent.input.document.sendForm.submit();
		}
	}
}
function getSendAllowed(frame)
{
	return parent.data.document.form.canSend.value;
}
function setSendAllowed(allow,frame)
{
	if (parent.data.document.form.canSend.value==allow)
		return;
	parent.data.document.form.canSend.value=allow;
	if (allow==0)
		parent.data.document.form.timeout.value = parent.data.setTimeout("setSendAllowed(1,self)",send_blocking_timeout);
	else
		parent.data.clearTimeout(parent.data.document.form.timeout.value*1);
	if (allow!=0 && parent.data.document.form.buffer.value!="")
		sendText("");
}
function addText(text)
{
	parent.input.document.inputForm.text.value += " "+text+" ";
	parent.input.document.inputForm.text.focus();
}
function insertText(text)
{
	if (parent.input.document.inputForm.text.value.replace(/^\s*/,"").substr(0,1)!='/')
		parent.input.document.inputForm.text.value = " "+text+" "+parent.input.document.inputForm.text.value;
	parent.input.document.inputForm.text.focus();
}
function updateMessages(mode)
{
	setLocation(parent.messages.location,cgi+"&action=receive&dhtml="+mode);
}
function updateUserList()
{
	setLocation(parent.users.location,cgi+"&action=userlist");
}
function updateInput()
{
	setLocation(parent.input.location,cgi+"&action=inputframe");
}
function updateOptions()
{
	setLocation(parent.options.location,cgi+"&action=optionsframe");
}
function updateRoomList()
{
	setLocation(parent.rooms.location,cgi+"&action=roomlist");
}
function viewProfile(user)
{
	hwnd=window.open(cgi+"&action=viewprofile&username="+user,user.substr(1),"resizable=yes,scrollbars=yes,width=430,height=480");
}
function editProfile(user)
{
	hwnd=window.open(cgi+"&action=modifyprofile&username="+user,user.substr(1),"resizable=yes,scrollbars=yes,width=430,height=480");
}
function viewRooms()
{
	hwnd=window.open(cgi+"&action=viewrooms","roomlist","resizable=yes,scrollbars=yes,width=600,height=450");
}
function showUsers()
{
	hwnd=window.open(cgi+"&action=searchuser","allusers","resizable=yes,scrollbars=yes,width=430,height=480");
}
function showAllUsers()
{
	hwnd=window.open(cgi+"&action=allusers","allusers","resizable=yes,scrollbars=yes,width=430,height=480");
}
function addToBanList(host,ip,forwardedfor)
{
	hwnd=window.open(cgi+"&action=modifybanlist&domain="+host+"&ip="+ip+"&forwardedfor="+forwardedfor,"admin","resizable=yes,scrollbars=yes,width=600,height=450");
}
function viewAdmin()
{
	hwnd=window.open(cgi+"&action=admin","admin","resizable=yes,scrollbars=yes,width=600,height=450");
}
function viewSmilies()
{
	hwnd=window.open(cgi+"&action=smileylist","smileys","resizable=yes,scrollbars=yes,toolbars=no,location=no,status=no,top=0,left=620,height="+screen.availHeight+",width="+(screen.availWidth-620));
}
function viewColors()
{
	hwnd=window.open("http://www.567thadm.org/chat/ColorChart.htm","colors","resizable=yes,scrollbars=yes,toolbars=no,location=no,status=no,top=0,left=250,height=400,width=512");
}
function viewLog()
{
	MsgWnd = window.open("http://www.567thadm.org/chat/log.html","msgs","toolbars=no,location=no,status=no,resizable=yes,scrollbars=yes,top=0,left=0,width=1000,height=210");
}
function viewChatLog()
{
	hwnd = window.open(cgi+"&action=viewlog","log","toolbars=no,location=no,status=no,resizable=yes,scrollbars=yes,width=700,height=600");
}
function testcol(color)
{
	if (color.length!=6)
		return false;
	for (i=0;i<color.length;i++)
	{
		if ((color.charAt(i)<"0" || color.charAt(i)>"9") && (color.charAt(i)<"a" || color.charAt(i)>"f") && (color.charAt(i)<"A" || color.charAt(i)>"F"))
			return false;
	}
	return true;
}
function toInt(h)
{
	mask="0123456789abcdef";
	h=h.toLowerCase();
	return mask.indexOf(h.charAt(0))*16+mask.indexOf(h.charAt(1));
}
function toHex(i)
{
	mask="0123456789abcdef";
	if (i>255)
		i=255;
	if (i<0)
		i=0;
	return mask.charAt(i/16)+mask.charAt(i%16);
}
function selcol(color)
{
	if (color.charAt(0)=="#")
		color=color.substr(1);
	if (testcol(color))
	{
		if (document.form.color.style)
			document.form.color.style.color=color;
		else if (document.layer)
			document.layer.bgColor=color;
		document.form.red.value = toInt(color.substr(0,2));
		document.form.green.value = toInt(color.substr(2,2));
		document.form.blue.value = toInt(color.substr(4,2));
		color="#"+color;
	}
	else
	{
		if (document.form.color.style)
			document.form.color.style.color="black";
		else if (document.layer)
			document.layer.bgColor="black";
		document.form.red.value = "";
		document.form.green.value = "";
		document.form.blue.value = "";
	}
	document.form.color.value = color;
}
function combineColors()
{
	selcol(toHex(document.form.red.value)+toHex(document.form.green.value)+toHex(document.form.blue.value));
}
function msgOutput(msg)
{
	lines=msg.split("\n");
	for (i=0;i<lines.length;i++)
	{
		if (lines[i].substr(0,8)=="<script>" && lines[i].substr(lines[i].length-9,9)=="</script>")
		{
			lines[i]=lines[i].substr(8,lines[i].length-17);
			setTimeout(lines[i],0);
		}
		else
		{
			if (parent.messages.document.all && parent.messages.document.all.dtext)
				parent.messages.document.all.dtext.innerHTML += lines[i]+'\n'; //IE
			else
				parent.messages.document.writeln(lines[i]); //firefox
		}
	}
	doScroll();
}
function doScroll(frame)
{
	if (parent.data.document.form.scroll.value!=0 && parent.messages)
	{
		parent.messages.scroll(1,5000000);
		if (parent.messages.document.ftext)
			parent.messages.document.ftext.scroll(1,5000000);
	}
}
function ClearMsgs()
{
	if(confirm("Are you sure you want to clear all messages?") == true)
	{
		if(parent.messages.document.getElementById('dtext'))
			parent.messages.document.getElementById('dtext').innerHTML = "[ <b>ADMChat:</b> Messages Cleared ]<br>\n";
		else if(parent.messages.document.getElementById('body'))
			parent.messages.document.getElementById('body').innerHTML = "[ <b>ADMChat:</b> Messages Cleared ]<br>\n";
	}
	parent.input.document.inputForm.text.focus();
}
function AddToBuffer(text)
{
	parent.data.document.form.log.value += text + "-|||-";
	LogCount = parent.data.document.form.LogCount.value;
	storage = parent.data.document.form.log.value;
	if(LogCount >= 10)
	{
		index = storage.indexOf("-|||-");
		parent.data.document.form.log.value = storage.substr(index+5);
	}
	else
		parent.data.document.form.LogCount.value++;
}
function checkFlooding()
{
	form = parent.data.document.form;
	now = (new Date()).getTime();
	
	if(flooding_maxnum<=0 || flooding_interval<=0) return;

	value = form.lasttimes.value;

	lasttime = "";
	newvalue = "";
	for(i=0;i<flooding_maxnum;i++)
	{
		if (value.lastIndexOf(" ") >= 0)
		{
			if (i == flooding_maxnum-1) lasttime=value.substring(value.lastIndexOf(" ")+1,value.length);
			else newvalue=" "+value.substring(value.lastIndexOf(" ")+1,value.length)+newvalue;
			value=value.substring(0,value.lastIndexOf(" "));
		}
	}
	newvalue+=" "+now;
	form.lasttimes.value=newvalue;

	if (lasttime!="" && now-lasttime<flooding_interval)
	{
		if (flooding_expireinterval > 0 && now-form.lastwarning.value > flooding_expireinterval) form.numwarnings.value = 0;
		form.numwarnings.value++;
		form.lastwarning.value=now;
		if (form.numwarnings.value > flooding_warnings) sendText('/quit');
		else alert(form.warntext.value);
		form.lasttimes.value="";
	}
}