function replace(string,text,by) {
	var strLength = string.length, txtLength = text.length;
	if ((strLength == 0) || (txtLength == 0)) return string;
	var i = string.indexOf(text);
	if ((!i) && (text != string.substring(0,txtLength))) return string;
	if (i == -1) return string;
	var newstr = string.substring(0,i) + by;
	if (i+txtLength < strLength) {
		newstr += replace(string.substring(i+txtLength,strLength),text,by);
		return newstr;
	}
}
function chatnow(form) {
	URL = "chat2.php";
	nickname = form.nickname.value;
	if (nickname != '') {
		password = form.nickpass.value;
		opcontrol = form.opcontrol.checked;
		channel = form.channel.value;
		channel = replace(channel,'#','');
		if (opcontrol == true) { opcontrol = form.opcontrol.value; }
		else { opcontrol = null; }
		if (password != "") {
			URL = URL+'?nickname='+nickname+'&nickpass='+password+'&opcontrol='+opcontrol+'&channel='+channel+'';
		}
		 else {
			URL = URL+'?nickname='+nickname+'&opcontrol='+opcontrol+'&channel='+channel+'';

		}
		window.open(URL, '', 'width=760, height=510, scrollbars=auto');	
	}
	else { alert('Please enter a nickname'); }
}