/* 
Front end for Chatster.org IRC Network using Java Chat
This tool does not work with a standard jpilot jirc
*/

placeofscript = "http://java.chatster.org/chatbox.js"
networkname = "powered by chatsters"
networkurl = "http://www.chatster.org"
frontend = "1"
URL = "http://java.chatster.org/chat.php";

function makechat (form) {
	var txt = '<script language="JavaScript1.3" src="'+placeofscript+'" type="text/javascript"></script>\r\n';
	txt+='<FORM NAME="login" action="">\r\n';
	txt+='<table width=160 border='+form.bdthick.value+' cellspacing=0 cellpadding=0 height=67 bordercolor='+form.bdcol.value+' bgcolor='+form.bgcolor.value+'>\r\n';
	txt+='<tr> \r\n';
	txt+='<td colspan=2 nowrap><b><font size=4 color="'+form.txtcol.value+'">Chat login:</font></b></td>\r\n';
	txt+='</tr>\r\n';
	txt+='<tr> \r\n';
	txt+='<td nowrap> \r\n';
	txt+='<input type="text" name="nickname" size="12" maxlength="30">\r\n';
	txt+='<i><font size="2" color="'+form.txtcol.value+'">Nickname</font></i><br>\r\n';
	txt+='</td>\r\n';
	txt+='</tr>\r\n';
	txt+='<tr> \r\n';
	txt+='<td nowrap> \r\n';
	txt+='<input type=password name=nickpass size=12>\r\n';
	txt+='<font size=2><i><font color="'+form.txtcol.value+'">Password (optional)</font></i></font></td>\r\n';
	txt+='</tr>\r\n';
	if (eval("form.configchannel[0].checked") == true) {
		txt+='<tr>\r\n';
      		txt+='<td nowrap height=2>\r\n';
        	txt+='<input type=text name=channel size=12>\r\n';
        	txt+='<font size=2><i><font color="'+form.txtcol.value+'">Channel</font> </i></font></td>\r\n';
      		txt+='</tr>\r\n';
	}
	else {
		txt+='<input type="hidden" name="channel" value="'+form.defaultchan.value+'">\r\n';
	}
	if (frontend != "2") {
		if (eval("form.opcontrol[0].checked") == true) {
			opcontrol = form.opcontrol[0].value;
		}
		if (eval("form.opcontrol[1].checked") == true) {
			opcontrol = form.opcontrol[1].value;
		}
		if (opcontrol == 'yes') {
			txt+='<tr> \r\n';
			txt+='<td nowrap height=2>\r\n';
			txt+='<input type="checkbox" name="opcontrol" value="show">\r\n';
			txt+='<i><font size=2 color="'+form.txtcol.value+'">op controls</font></i></td>\r\n';
			txt+='</tr>\r\n';
		}
		else {
		if (eval("form.opdefault[0].checked") == true) {
			opdefault = form.opdefault[0].value;
		}
		if (eval("form.opdefault[1].checked") == true) {
			opdefault = form.opdefault[1].value;
		}
			txt+='<input type="hidden" name="opcontrol" value="'+opdefault+'">\r\n';
		}
	}
	txt+='<tr align="center"> \r\n';
	txt+='<td colspan=2 height=2 valign=middle> \r\n';
	txt+='<input type="button" class="input" name="chat" value="Chat Now" onClick=javascript:chatnow(this.form);>\r\n';
	txt+='<p><font size="1"><a href="'+networkurl+'" target="_blank">'+networkname+'</a></font></td>\r\n';
	txt+='</tr>\r\n';
	txt+='</table>\r\n';
	txt+='<input type="hidden" name="limitchans" value="false"><input type="hidden" name="servername" value="irc">\r\n';
	txt+='</FORM>\r\n';
	form.code.value="";
	form.code.value=txt;
}
function disablecheck(form, what, value) {
	for (var i=0; i<form.elements.length; i++) {
		if (form.elements[i].name == what) {
			form.elements[i].disabled = value;
		}
	}
}
function previewcolor(what) {
		win=window.open("","Preview","resizable=no,height=50,width=50 scrollbars=no")
		win.document.write("<body bgcolor="+what+">");
		win.document.write("</body>");
		win.document.close;
}
function previewlogin(form) {
		win=window.open("","Preview","resizable=no,height=350,width=250 scrollbars=no")
		win.document.write(form.code.value);
		win.document.close;
}
function bordercol(form,action) {
	if (action == "yes") {
		form.bdthick.disabled=false;
		form.bdcolsc.disabled=false;
		form.bdcol.disabled=false;
		form.bah2.disabled=false;
	}
	else {
		form.bdthick.disabled=true;
		form.bdcolsc.disabled=true;
		form.bdcol.disabled=true;
		form.bah2.disabled=true;
	}
}
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) {
	nickname = form.nickname.value;
	if (nickname != '') {
		password = form.nickpass.value;
		opcontrol = form.opcontrol.checked;
		channel = form.channel.value;
		servername = form.servername.value;
		limitchans = form.limitchans.value;
		if (channel != '') {
			channel = replace(channel,'#','');
			if (frontend == "2") { opcontrol = null }
			else {
				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,'','resizable=yes,width=823,height=585,scrollbars=yes');
		}
		else { alert('please enter a channel'); }
	}
	else { alert('Please enter a nickname'); }
}
