#!/usr/bin/perl

require "bc_html_util.cgi";
require "bc_setup.cgi";
require "bc_loginsetup.cgi";

&Parse_Form;

if (!$formdata{'cname'}) {
if ($backgroundimage ne '') {
  $backgroundimage = 'background="' . $backgroundimage . '"';
}
foreach $rule (@rules) {
 $TheRules .= $rule . '<br>';
}

&Mime;
print <<ENDHTML;
<html>
<head>
<title>$yourname чат</title>
<script language="JavaScript"><!--
function LogIn(){
var MyWindow;
var MyUrl;
if (!document.forms[0].cname.value) {alert('Вы должны ввести имя для входа'); return;}
MyUrl = 'bluechat.cgi' + '?cname=' + escape(document.forms[0].cname.value);
MyWindow = window.open(MyUrl, "BlueChat", "STATUS=NO,TOOLBAR=NO,LOCATION=NO,DIRECTORIES=NO,COPYHISTORY=NO,MENU=NO,RESISABLE=NO,SCROLLBARS=NO,TOP=50,LEFT=20,WIDTH=600,HEIGHT=400");
window.history.back();
}
// --></script>
</head>
<body bgcolor="$backgroundcolor" text="$textcolor" link="$linkcolor" vlink="$visitedcolor" alink="$activecolor" $backgroundimage>
<p align="center"><font color="$titlecolor"><strong><big><big>Добро пожаловать в чат $yourname </big></big></strong></font></p>
<p>$TheRules</p>
<form onsubmit="javascript:{return false;}">
  <div align="center"><center><p>Введите ник под которым Вы будете чатать<br>
  <input type="text" name="cname" size="20"><br>
  <input type="button" value="Войти" onclick="javascript:LogIn();"></p>
  </center></div>
</form>
<p align="center"><small>Цвет имени:<br>
<strong><font color="#0000A8">`1</font> <font color="#007000">`2</font> <font
color="#008080">`3</font> <font color="#A80000">`4</font> <font color="#A800A8">`5</font> <font
color="#A85400">`6</font> <font color="#808080">`7</font> <font color="#505050">`8</font> <font
color="#5454FC">`9</font> <font color="#00B000">`0</font> <font color="#00A0A0">`!</font> <font
color="#FC5454">`\@</font> <font color="#FC54FC">`\#</font> <font color="#AAAA00">`\$</font> <font
color="#000000">`\%</font></strong><br>
<I>например:</I> `1Вася = <font color="#0000A8">Вася</font></small></p>
<p>$additional</p>
<p><em><small>Version 1.3</small></em></p>
</body></html>
ENDHTML
exit;
}

if ($formdata{'cname'}){
my $cname = $formdata{'cname'};
$cname =~ s/\`\#/`A/g;
$cname =~ s/\#//g;
$cname =~ s/ /\%20/g;

&Mime;
print <<MAINHTML;
<html><head>
<title>$yourname Chat</title>
</head>
<frameset cols="150,*">
  <frameset rows="150,*">
    <frame name="logo" scrolling="no" noresize src="bc_logo.cgi">
    <frame name="commands" scrolling="no" noresize src="bc_commands.cgi?cname=$cname">
  </frameset>
  <frameset rows="*,40">
    <frame name="main" scrolling="auto" noresize src="bc_chat.cgi?cname=$cname&room=general&message=.me%20входит%20в%20чат">
    <frame name="sendchat" target="main" scrolling="no" noresize src="bc_chatbar.cgi?cname=$cname" marginwidth="5" marginheight="5">
  </frameset>
  <noframes>
  <body>
  <p>This page uses frames, but your browser doesn't support them.</p>
  </body>
  </noframes></frameset></html>
MAINHTML
exit;
}

&Mime;
print <<ERRORHTML;
<html><head><title>Error</title></head><body>
<p><font color="#800000"><big><strong>BlueSparks Chat</strong></big></font></p>
<p>There was an error trying to run BlueSparks Chat script.</p>
</body></html>
ERRORHTML
exit;