#!/usr/local/bin/perl5
#require 'ctime.pl';
require "../lib/syscall.pl";
require "../lib/counter.pl";

#<META TITLE="Submit A Voice Actor Addition To The Database">

##### EMAIL STUFF
$SENDMAIL      = "/usr/sbin/sendmail -t -n -oi";	#free form authoring
$MAIL          = "/usr/bin/Mail";			#no header changing
$PROBLEMS      = "ClintJCL\@gmail.com";

##### WWW STUFF:
$BASEURL           = "http://clint.sheer.us";
$ThisProgram       = "$BASEURL/~clint/cgi/voices/addvoice.pl";

##### UNIX FILESYSTEM STUFF:
$APPROVECGI         = "approve_new_voice_addition.pl";		#CGI of page to approve these requests
$AUDIT_PREFIX       = "voice-submission";			#filenames will be 

##### FILES/DIRS:
$CLINT              = "/home/clint";			#my homedir
$BASE_HOLDING_DIR   = "$CLINT/WWW/pub/voices";

##### DEBUG:
#$DEBUG_LEVELS=1;		#debug what level the form is at	
#$DEBUG_START_FORM_LEVELS=1;	#debug what level the start form is at	
#$DEBUG_NO_AUDIT_WRITES=1;	#do not write any audit files
#$DEBUG_VERBOSE=2;

##### &Print_Start_Form CONSTANTS:
$PRINT_START_FORM_NORMAL        = 0;
$PRINT_START_FORM_NORMAL_BUTTON = 1;
$PRINT_START_FORM_EPISODE       = 2;
$PRINT_START_FORM_SHOW          = 3;
$PRINT_START_FORM_NAME          = 4;

################################################################################################### MAIN PROGRAM - BEGIN
################################################################################################### MAIN PROGRAM - BEGIN
################################################################################################### MAIN PROGRAM - BEGIN
$FOOTER_ALREADY_PRINTED=0;	#for print_footer
$HEADER_PRINTED_YET=0;		#for print_header
$COOKIES_DEALT_WITH_YET=0;	#for deal_with_cookies
$NORMAL_FORM_PRINTED=0;		#for print_start_form

&read_cookies;
if (($ENV{REQUEST_METHOD} eq "POST") || ($ENV{REQUEST_METHOD} eq "GET")) {
        &Parse_Data;
} else {
        &Deal_With_Cookies;
        &Print_Start_Form($PRINT_START_FORM_NORMAL);
	&Welcome;
}#endif
&Print_Footer;
################################################################################################### MAIN PROGRAM - END
################################################################################################### MAIN PROGRAM - END
################################################################################################### MAIN PROGRAM - END


############################################################################################
sub Parse_Data {
my $ERRORS_TO_PRINT="";		#add error messages to this str

if ($DEBUG_VERBOSE) { &Print_Header; print "<h1>parsing data</h1>\n"; }

##### CAPTURE THE FORM INPUT DATA:
if ($ENV{REQUEST_METHOD} eq "POST") {
        read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
} else {
        $buffer=$ENV{QUERY_STRING};
}#endif
@pairs = split(/&/, $buffer);

##### TRANSLATE THE FORM INPUT DATA:
foreach $pair (@pairs) {
        ($name, $value) = split(/=/, $pair);
        $value =~ tr/+/ /;
        $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

	##### PRE-SCRUB FORM INPUT APPROPRIATELY:
	#remove leading and trailing spaces:
	$value =~ s/^\s+//;
	$value =~ s/\s+$//;
	#normalize names:
	if ((($name eq "firstname")   || ($name eq "middlename") || ($name eq "lastname")   || 
	     ($name eq "featurename") || ($name eq "character")  || ($name eq "guestepisode")) 
		&&    ($value ne "UNKNOWN")) {
		$value = &normalize_name($value);
	}#endif
	#capitalize genre name:
	if ($name =~ /genre_other/) {
		$value =~ tr/[a-z]/[A-Z]/;
	}#endif

	##### ASSIGN VALUE:
        $FORM{$name} = $value;

	##### POST-SCRUB FORM INPUT APPROPRIATELY:
	$ERRORS_TO_PRINT .= &disallow_special_characters($name);

	#DEBUG: &Print_Header; print "Making \$FORM{$name} eq \"$FORM{$name}\"<BR>\n";
}#endfor


##### COMBAT MY OWN PROGRAMMER STUPIDITY:
$FORM{title} = $FORM{featurename};	#I'm allowed to change my mind.

##### PRINT THE HEADERS AND DEAL WITH COOKIES:
&Deal_With_Cookies;
&Print_Header;

if ($DEBUG_LEVELS) { print "Level is <b>$FORM{level}</b><hr>\n"; }#endif debugging levels

##### REACT APPROPRIATELY ACCORDING TO FORM LEVEL:
#if ($FORM{"level"} eq "resubmit") {
#	##### in this case, they have already submitted their credit, and are progressing to submit a second
#	##### credit, based on some rolled over input from the first credit. However, we still want to attempt
#	##### to reprompt them for missing info so let's change any "UNKNOWN" back to "":
#	if ($FORM{guestepisode} eq "UNKNOWN") { $FORM{guestepisode}=""; }
#	if ($FORM{character}    eq "UNKNOWN") { $FORM{character}="";    }
#}#endif

if ($FORM{"level"} eq "") {
	&Welcome;
	&Print_Start_Form($PRINT_START_FORM_NORMAL);
} else {	############# CHECK FOR ERRORS:
	##### FIRST, THE HARD-CODED ERRORS:
	if ($FORM{firstname} eq "") { $ERRORS_TO_PRINT .= &firstname_errmsg; }#endif
	if (($FORM{lastname} eq "") && ($FORM{middlename} ne "")) {
		$ERRORS_TO_PRINT .= &middlenolast_errmsg;	
	}#endif

	##### THEN USE THE ERROR-CHECKING FUNCTIONS:
	$ERRORS_TO_PRINT .= &check_email_address_for_errors($FORM{Your_Email_Address});
	$ERRORS_TO_PRINT .= &check_other;
	$ERRORS_TO_PRINT .= &check_genre_for_check;
	$ERRORS_TO_PRINT .= &check_genre_for_other;
	$ERRORS_TO_PRINT .= &check_subgenre_for_check;
	$ERRORS_TO_PRINT .= &check_subgenre_for_other;
	$ERRORS_TO_PRINT .= &check_for_audio_genre_discrepancy;
	$ERRORS_TO_PRINT .= &check_for_audio_subgenre_discrepancy;
	$ERRORS_TO_PRINT .= &check_for_title;
	$ERRORS_TO_PRINT .= &check_status_for_check;
	$ERRORS_TO_PRINT .= &check_for_other_genre;

	##### IF THERE ARE NO ERRORS, THEN CHECK FOR WARNINGS:
	## RESOLVE "OTHER" CHECKBOX ISSUES:
	if ($ERRORS_TO_PRINT eq "") {
		$ERRORS_TO_PRINT .= &check_for_other_without_a_check("namesuffix","namesuffix_other");
		$ERRORS_TO_PRINT .= &check_for_other_without_a_check("genre",     "genre_other");
		$ERRORS_TO_PRINT .= &check_for_other_without_a_check("subgenre",  "subgenre_other");
	}#endif
	## RESOLVE CHARACTER NAME ISSUES:
	if ($ERRORS_TO_PRINT eq "") {
		$ERRORS_TO_PRINT .= &check_for_character_name;
		$ERRORS_TO_PRINT .= &check_for_first_but_no_last_name;
	}#endif
	## RESOLVE GUEST EPISODE TITLE ISSUES:
	if ($ERRORS_TO_PRINT eq "") {
		$ERRORS_TO_PRINT .= &check_status_for_no_guest_title;		#what if they click guest but don't put a title?
		$ERRORS_TO_PRINT .= &check_for_guest_title_without_checkbox;	#what if they put a title but don't click guest?
	}#endif

	##### FINALLY, WE PRINT OUT ANY ERRORS, UNLESS THE LEVEL IS RESUBMIT IN WHICH CASE WE GIVE THEM ONE ITERATION BEFORE DOING SO:
	if ($FORM{level} ne "resubmit") {
		&print_errors($ERRORS_TO_PRINT);
	} else {
		&Resubmit_Welcome;
	}#endif
}#endif

if ($DEBUG_VERBOSE) { print "<h1>Done checking form input for errors</h1>\n"; }

if (($FORM{level} eq "submit") && ($ERRORS_TO_PRINT eq "")) {
	umask(000);
	&Write_Audit;
	&Print_Footer;
	exit;
} else {
	&Print_Start_Form($PRINT_START_FORM_NORMAL);	#give them their form to re-fill out
}#endif level is write
}#endsub parse_data
############################################################################################

#BLANK CHECK FUNCTION:
####################################################################################### 
#sub {
#my $retval="";
#if (1) {
#	$retval = <<__EOF__;
#	<font color=5555ff size=5><B>ERROR:</b> 
#	</font><BR>
#	<font size=4>
#	</font><BR><BR>
#__EOF__
#}#endif
#return($retval);
#}#endsub 
#######################################################################################

###########################################################################################
sub disallow_special_characters {
my ($name) = $_[0];
my $retval="";
my $bad_character,$temp,$good_character="";

foreach $bad_character (":","<",">") {
	$good_character=""; $temp="";

	#DEBUG: &Print_Header; print "Checking form{$name} for $bad_character...";

	if ($FORM{$name} =~ /$bad_character/) {
		
		#DEBUG: print "<font size=7>Found</font>!<BR>\n";#

		if ($bad_character eq ":") { $good_character=" -- "; }
		if ($bad_character eq "<") { $good_character="(";    }
		if ($bad_character eq ">") { $good_character=")";    }

		#BLANK:
		#if ($bad_character eq "") { $good_character="";    }

		$FORM{$name} =~ s/$bad_character/$good_character/g;

		$temp = <<__EOF__;
                <font color=5555ff size=5><B>WARNING:</b> The character &quot;$bad_character&quot; is not allowed in form inputs.<BR>
		You used this character in the &quot;$name&quot; section.
		</font><BR><font size=4>I have changed the character to &quot;$good_character&quot; instead.<BR>Hope you don't mind.<BR>
		You might want to touch up my fix if it is not appropriate.<BR>I'm just a poor little Perl script, y'know.
		<BR>I'm not that smart.</font><BR><BR>
__EOF__
		$retval .= "$temp";
	} else {
		#do nothing
		#DEBUG: print "NOT FOUND.<BR>\n";#
	}#endif	
}#endif
return($retval);
}#endsub disallow_special_characters
###########################################################################################

###################################################################################### 
sub check_for_guest_title_without_checkbox {
my $retval="";
if ((($FORM{status} ne "guest") && ($FORM{status} ne "semiregular")) && ($FORM{guestepisode} ne "")) {
	if ($FORM{guest_episode_given_without_checkbox_warning_given} eq "1") {
		$FORM{guest_episode_given_without_checkbox_warning_given}="";
		$FORM{guestepisode}="";
	} elsif ($FORM{guestepisode} eq "UNKNOWN") {	#don't tell them in this case since it's trivial.
		$FORM{guestepisode}="";
	} else {
		$FORM{guest_episode_given_without_checkbox_warning_given}="1";
		$retval = <<__EOF__;
		<font color=5555ff size=5><B>WARNING:</b> You gave an Episode Title of &quot;$FORM{guestepisode}&quot;,
but selected the status of &quot;$FORM{status}&quot;, which does not allow episode titles.<BR>
<B>IF THIS REALLY <I>IS</i> A GUEST APPEARANCE, YOU WILL NEED TO CLICK ON &quot;GUEST&quot; BELOW!!</B></font><BR><font size=4>
Please input the episode title of the guest appearance.<BR>
If you don't know the title, you could describe what happened in the episode.<BR>
		(EXAMPLE: &quot;The One With The Jellyfish&quot;)<BR>
(If this is a musical guest, the episode title would be the album/song name.)<BR>
	 	If you <I>REALLY</i> want to leave this field blank, just click on &quot;Submit&quot;.<BR>
	<B><I>TO MAKE THIS WARNING GO AWAY, JUST RE-CLICK ON SUBMIT.</i></B>
		</font><BR><BR>
__EOF__
	}#endif
}#endif
return($retval);
}#endsub check_for_guest_title_without_checkbox
######################################################################################

###################################################################################### 
sub check_status_for_no_guest_title {
my $retval="";
if (($FORM{status} eq "guest") && ($FORM{guestepisode} eq "")) {
	if ($FORM{no_guest_episode_warning_given} eq "1") {
		$FORM{no_guest_episode_warning_given}=""; 
		$FORM{guestepisode}="UNKNOWN";
	} else {
		$FORM{no_guest_episode_warning_given}="1";
		$retval = <<__EOF__;
		<font color=5555ff size=5><B>NON-FATAL WARNING:</b> You clicked on &quot;</font><font color=ffffff size=5>Guest</font><font 
		color=5555ff size=5>&quot; but did <i>not</i> 
		provide the title of the episode they guest-starred in.
		</font><BR><font size=4>
		Please input the episode title of the guest appearance.<BR>
		If you don't know the title, you could describe what happened in the episode.<BR>
		(EXAMPLE: &quot;The One With The Jellyfish&quot;)<BR>
(If this is a musical guest, the episode title would be the album/song name.)<BR>
	 	If you <I>REALLY</i> want to leave this field blank, just click on &quot;Submit&quot;, and I will automatically mark
		it as &quot;UNKNOWN&quot;. <BR>
	<B><I>TO MAKE THIS WARNING GO AWAY, JUST RE-CLICK ON SUBMIT.</i></B>
		</font><BR><BR>
__EOF__
	}#endif
}#endif
return($retval);
}#endsub check_status_for_no_guest_title
######################################################################################

####################################################################################### 
sub check_for_audio_genre_discrepancy {
my $retval="";
if ((($FORM{subgenre} eq "music") || (0)) && ($FORM{genre} ne "audio")) {
	if ($FORM{audio_genre_discrepancy_warning_given} eq "1") {
		$FORM{audio_genre_discrepancy_warning_given}="";
		$FORM{genre}="audio";
	} else {
		$FORM{audio_genre_discrepancy_warning_given}="1";	#for suppressing the errmsg after future clicks
		$retval = <<__EOF__;
		<font color=5555ff size=5><B><I>NON</i>-FATAL WARNING:</b> You selected a subgenre of &quot;$FORM{subgenre}&quot;,
but selected a genre of &quot;$FORM{genre}&quot;. 
		</font><BR>
		<font size=5><B>$FORM{subgenre} can only be considered audio-only.</B><BR></font><font size=4>
		<B><I>TO HAVE ME AUTOMATICALLY CHANGE YOUR GENRE TO AUDIO-ONLY, RE-CLICK ON SUBMIT.</i></B><BR>
		<B><I>TO MAKE THIS WARNING GO AWAY, JUST RE-CLICK ON SUBMIT.</i></B>
		</font><BR><BR>
__EOF__
	}#endif
}#endif
return($retval);
}#endsub check_for_audio_genre_discrepancy
######################################################################################

####################################################################################### 
sub check_for_first_but_no_last_name {
my $retval="";
if (($FORM{firstname} ne "") && ($FORM{lastname} eq "")) {
	if ($FORM{first_but_no_last_warning_given} eq "1") {
		$FORM{first_but_no_last_warning_given}="";
	} else {
		$FORM{first_but_no_last_warning_given}="1";	#for suppressing the errmsg after future clicks
		$retval = <<__EOF__;
		<font color=5555ff size=5><B><I>NON</i>-FATAL WARNING:</b> You have given a first name but no last name.
		</font><BR>
		This is okay. I just wanted to warn you in case you wanted to fix the problem.<BR>
		However, maybe it's someone like &quot;Cher&quot; or &quot;Fabio&quot; or a band like &quot;The Beatles&quot;.<BR>
		In that case, just click on submit and this warning will go away.<BR>
		<font size=6><B><I>TO MAKE THIS WARNING GO AWAY, JUST RE-CLICK ON SUBMIT.</i></B>
		</font><BR><BR>
__EOF__
	}#endif
}#endif
return($retval);
}#endsub check_for_first_but_no_last_name
######################################################################################

####################################################################################### 
sub check_for_audio_subgenre_discrepancy {
my $retval="";
if (($FORM{genre} eq "audio") && 
(
	($FORM{subgenre} eq "show") || ($FORM{subgenre} eq "awardshow") || ($FORM{subgenre} eq "miniseries") || 
	($FORM{subgenre} eq "special") || ($FORM{subgenre} eq "movie") || ($FORM{subgenre} eq "commercial")
)
) {
	#if ($FORM{audio_subgenre_discrepancy_warning_given} eq "1") {
	#	$FORM{audio_subgenre_discrepancy_warning_given}="";
	#	$FORM{subgenre}="";
	#} else {
		$FORM{audio_subgenre_discrepancy_warning_given}="1";	#for suppressing the errmsg after future clicks
		$retval = <<__EOF__;
		<font color=5555ff size=5><B><I>NON</i>-FATAL WARNING:</b> You selected a subgenre of &quot;$FORM{subgenre}&quot;,
but selected a genre of &quot;Audio&quot;. 
		</font><BR>
		<font size=5><B>The only valid sub-genres for audio-only are Music, Theme Park/Museum, or &quot;Other&quot;.</B><BR>
		<B>If this is a voice-over-only role in a <I>non</i>-cartoon, then select the genre of whatever the feature is (not audio-only)
and simply put &quot;(voice)&quot;
		after the character name.</B>  Sorry for the confusion.<BR></font><font size=4>
		<B><I>I HAVE AUTOMATICALLY UNCHECKED &quot;$FORM{subgenre}&quot;.</i></B><BR>
		PLEASE CHECK A VALID SUBGENRE OF MUSIC, THEME PARK/MUSEUM, or OTHER.
		</font><BR><BR>
__EOF__
		$FORM{subgenre}="";
	#}#endif
}#endif
return($retval);
}#endsub check_for_audio_subgenre_discrepancy
######################################################################################

####################################################################################### 
sub check_for_character_name {
my $retval="";
if ($FORM{character} eq "") {
	if ($FORM{character_name_warning_given} eq "1") {
		$FORM{character_name_warning_given}="";
		$FORM{character}="UNKNOWN";
	} else {
		$FORM{character_name_warning_given}="1";	#for suppressing the errmsg after future clicks
		$retval = <<__EOF__;
		<font color=5555ff size=5><B><I>NON</i>-FATAL WARNING:</b> You left a blank character name. 
		</font><BR>
		<font size=4>Of course you are allowed to leave this field blank.<BR>
		This warning is to tell you that it would be nice if you could describe the character a bit (something is better than nothing).<BR>
		Just click on submit again to designate the character as &quot;UNKNOWN&quot;.<BR>
		<B><I>TO MAKE THIS WARNING GO AWAY, JUST RE-CLICK ON SUBMIT.</i></B>
		</font><BR><BR>
__EOF__
	}#endif
}#endif
return($retval);
}#endsub check_for_character_name
######################################################################################

###################################################################################### 
sub check_for_other_without_a_check {
my $inputname      = $_[0];		#namesuffix,genre,subgenre
my $inputothername = $_[1];		#generally "$_[0]" . "_other"
my $retval,$inputname_for_printing="";

if    ($inputname eq "namesuffix") { $inputname_for_printing="Name Suffix"; }
elsif ($inputname eq "genre")      { $inputname_for_printing="Genre";       }
elsif ($inputname eq "subgenre")   { $inputname_for_printing="Sub-Genre";   }
else {
	print "<h1>INTERNAL ERROR CFOWAC1($inputname,$inputothername): NOTIFY <a href=\"MAILTO:$PROBLEMS\">$PROBLEMS</a> IMMEDIATELY!!</h1>";
	&send_bug_report("inputname=$inputname,inputothername=$inputothername");
}#endif

if (($FORM{$inputname} ne "other") && ($FORM{$inputothername} ne "")) {
	$retval  = "<font color=5555ff size=5><B>WARNING:</b> You put text in the &quot;";
	$retval .= "$inputname_for_printing" . ":Other&quot; field without selecting the &quot;$inputname_for_printing:Other&quot; checkbox!";
	$retval .= "</font><BR><font size=4>Maybe you changed your mind and decided not to click &quot;$inputname_for_printing:Other&quot;.<BR>";
	$retval .= "The text that you put in the &quot;$inputname_for_printing" . ":Other&quot; field was:<BR>";
	$retval .= "&quot;</font><font color=8888ff size=4>$FORM{$inputothername}</font><font size=5>&quot;.<BR>";
	
	$retval .= "Since you did not click &quot;$inputname_for_printing:Other&quot;, <I>I have erased &quot;";
	$retval .= $FORM{$inputothername} . "&quot; from the &quot;$inputname_for_printing:Other&quot; field below!!</i><BR>";
	$retval .= "If you <i>really</i> meant to click on &quot;$inputname_for_printing:Other&quot;, please type &quot;$FORM{$inputothername}&quot;";
	$retval .= " back into the &quot;$inputname_for_printing" . ":Other&quot; field.<BR>";

	$retval .= "<I>IF YOU DON'T UNDERSTAND THIS ERROR MESSAGE, JUST CLICK ON SUBMIT AGAIN.</i>";
	$retval .= " (&quot;$FORM{$inputothername}&quot; will remain erased).<BR>";
	$retval .= "<B><I>TO MAKE THIS WARNING GO AWAY, JUST RE-CLICK ON SUBMIT.</i></B>";
#	$retval .= "<BR>";
	$retval .= "</font><BR><BR><BR><BR><BR><BR>";

	##### DO WHAT WE SAID AND ERASE THE INPUT:
	$FORM{$inputothername} = "";
}#endif
return($retval);
}#endsub check_for_other_without_a_check
######################################################################################

######################################################################################
sub send_bug_report {
my ($text)=$_[0];

open(MAIL,"|$SENDMAIL");
print MAIL <<__EOF__;
From:$PROBLEMS
To:$PROBLEMS
Subject: **** ADDVOICE.PL CRISIS ****

Text:
[$text]
__EOF__
close(MAIL);
}#endsub send_bug_report
######################################################################################

########################################################################################
sub check_for_title {
my $retval="";
if ($DEBUG_VERBOSE >= 2) { print "<h1>Checking for title...</h1>\n"; }
if ($FORM{featurename} eq "") {
	$retval = <<__EOF__;
	<font color=5555ff size=5><B>ERROR:</b> 
	You must fill in the &quot;<B>Title or description of what they were in</B>&quot; field to submit this credit!
	</font><BR><font size=4>
	If this is a vague title/set-of-titles, like "several Wheaties commercials", 
	or "Star Wars movies", or "lots of cheezy action B-movies", then enter that into the title field.
	</font><BR><BR>
__EOF__
}#endif
if ($DEBUG_VERBOSE >= 2) { print "<h1>Checking for title...DONE...returning &quot;$retval&quot;</h1>\n"; }
return($retval);
}#endsub check_for_title
########################################################################################

########################################################################################
sub check_subgenre_for_check {
my $retval="";
if (($FORM{subgenre} eq "") && ($FORM{genre} ne "other")) {
	$retval = <<__EOF__;
	<font color=5555ff size=5><B>ERROR:</b> 
	You must select a <B>sub-genre</B> for this credit!
	</font><BR><font size=4>
	Please select a sub-genre before continuing.<BR>
	If the sub-genre of your credit is not listed, you can click &quot;Other&quot; and type in whatever it actually is.
	</font><BR><BR>
__EOF__
}#endif
return($retval);
}#endsub check_subgenre_for_check
########################################################################################
########################################################################################
sub check_for_other_genre {
my $retval="";
if (($FORM{subgenre} ne "") && ($FORM{genre} eq "other")) {
	$retval = <<__EOF__;
	<font color=5555ff size=5><B>NON-FATAL WARNING:</b> 
	You selected a <B>sub-genre</B> for this credit, but your genre is &quot;Other&quot;.
	</font><BR><font size=4>
	It is not necessary to select a sub-genre when genre is &quot;Other&quot;.<BR>
	I have erased your sub-genre information.  If this was a mistake, then enter your sub-genre information in
	the Genre:Other field.
	</font><BR><BR>
__EOF__
	$FORM{subgenre} = "";
	$FORM{subgenre_other} = "";
}#endif
return($retval);
}#endsub check_for_other_genre
########################################################################################
########################################################################################
sub check_status_for_check {
my $retval="";
if ($FORM{status} eq "") {
	$retval = <<__EOF__;
	<font color=5555ff size=5><B>ERROR:</b> 
	You must select a <B>status</B> for this credit!
	</font><BR><font size=4>
	Please select a status before continuing.<BR>
	This means clicking on &quot;Regular&quot;, &quot;Guest&quot;, &quot;Semi-Regular&quot;, or &quot;UNKNOWN&quot; if you don't know their status.
	</font><BR><BR>
__EOF__
}#endif
return($retval);
}#endsub check_status_for_check
########################################################################################
########################################################################################
sub check_subgenre_for_other {
my $retval="";
if (($FORM{subgenre} eq "other") && ($FORM{subgenre_other} eq "")) {
	$retval = <<__EOF__;
	<font color=5555ff size=5><B>ERROR:</b> 
	You checked &quot;</font><font color=ffffff size=5>Other</font><font color=5555ff size=5>&quot; for &quot;</font><font 
	color=ffffff size=5>Sub-Genre</font><font color=5555ff size=5>&quot;, but did not fill in the &quot;Other&quot; field!

	</font><BR><font size=4>Clicking &quot;Other&quot; implies that this credit is for a sub-genre other than those listed 
	in the sub-genre checkboxes<BR>(tv show, movie, commercial, etc).<BR>Whatever it is, <I>you will need to fill it out</i>
	in the &quot;Other&quot; field, <B><I>or</i></B> unclick &quot;Other&quot;.
	</font><BR><BR>
__EOF__
}#endif
return($retval);
}#endsub check_subgenre_for_other
########################################################################################



########################################################################################
sub check_genre_for_check {
my $retval="";
if ($FORM{genre} eq "") {
	$retval = <<__EOF__;
	<font color=5555ff size=5><B>ERROR:</b> 
	You must select a <B>genre</B> for this credit!
	</font><BR><font size=4>
	Please select a genre before continuing.<BR>
	If the genre of your credit is not listed, you can click &quot;Other&quot; and type in whatever it actually is.
	</font><BR><BR>
__EOF__
}#endif
return($retval);
}#endsub check_genre_for_check
########################################################################################
########################################################################################
sub check_genre_for_other {
my $retval="";
if (($FORM{genre} eq "other") && ($FORM{genre_other} eq "")) {
	$retval = <<__EOF__;
	<font color=5555ff size=5><B>ERROR:</b> 
	You checked &quot;</font><font color=ffffff size=5>Other</font><font color=5555ff size=5>&quot; for &quot;</font><font 
	color=ffffff size=5>Genre</font><font color=5555ff size=5>&quot;, but did not fill in the &quot;Other&quot; field!

	</font><BR><font size=4>Clicking &quot;Other&quot; implies that this credit is for a genre other than animation, live 
	action, or audio-only.<BR>Whatever it is, <I>you will need to fill it out</i>
	in the &quot;Other&quot; field, or unclick &quot;Other&quot;.
	</font><BR><BR>
__EOF__
}#endif
return($retval);
}#endsub check_genre_for_other
########################################################################################

########################################################################################
sub check_other {
my $retval="";
if (($FORM{namesuffix} eq "other") && ($FORM{namesuffix_other} eq "")) {
	$retval = <<__EOF__;
	<font color=5555ff size=5><B>ERROR:</b> 
	You checked &quot;</font><font color=ffffff size=5>Other</font><font color=5555ff size=5>&quot; for &quot;</font><font color=ffffff size=5>Name 
	Suffix</font><font color=5555ff size=5>&quot;, but did not fill in the &quot;Other&quot; field!
	</font><BR><font size=4>Clicking &quot;Other&quot; implies that they have a last name suffix that is <i>not</i>
	Jr., Sr., or III. <BR>(It might be D.D.S., Esq., IV, or whatever.)<BR>But whatever it is, <I>you will need to fill it out</i>
	in the &quot;Other&quot; field, or unclick &quot;Other&quot;.
	</font><BR><BR>
__EOF__
}#endif
return($retval);
}#endsub check_other
########################################################################################
######################################################################################
sub print_errors {
my $ERRORS=$_[0];
if ($ERRORS eq "") { 
	#DEVELOPMENT: print "<h1 align=center>No errors! -- WARNING: THIS FORM DOES NOT ACTUALLY *DO* ANYTHING YET. YOUR SUBMISSION WAS *NOT* SUBMITTED.</h1>";
} else {
	print <<__EOF__;
<p align=center><center><font size=7 color=ff0000><B>The following errors were encountered:</B></font><BR><BR>
$ERRORS</center></p><BR><BR><BR>
__EOF__
}#endif
}#endsub print_errors
######################################################################################
################################################################################
sub check_email_address_for_errors {
my $address=$_[0];
my $retval="";		#error messages go here

if ($address eq "") {
	$retval = <<__EOF__;
	<font color=5555ff size=5><B>ERROR:</b> You did not enter an email address!</font><BR>
	<font size=4>This address will not be put on the contributors list if you uncheck the
	&quot;<B>Please publicly credit me as a contributor</B>&quot; checkbox.  <BR>
	Furthermore, this address will not be given out to anyone and would only be used
	for follow-up questions.  Sometimes I need to ask, &quot;<i>What did you mean by that?</I>&quot;<BR>
	Of course, you might not <i>have</i> an email address, and I'd still like your contribution,
	so just put anything in the field to bypass this error message.  <i>YOU COULD EVEN PUT
	YOUR NAME...</I>
</font>
	<BR><BR>
__EOF__
}#endif

}#endsub check_email_address_for_errors
################################################################################
################################################################################
sub middlenolast_errmsg {
my $retval="";
$retval = <<__EOF__;
<font color=5555ff size=5><B>ERROR:</B> Your submission has a middle name but no last name!<BR></font>
<font size=4>Entries may be <I>just</i> a first name (for people like Cher or Fabio, or for bands), <I>or</i> a first name <i>and</i> a last name.  
<BR>Middle names are not allowed unless there are last names.</font>
<BR><BR>
__EOF__
}#endsub middlenolast_errmsg
################################################################################

################################################################################
sub firstname_errmsg {
my $retval="";
$retval = <<__EOF__;
<font color=5555ff size=5><B>ERROR:</B> Your submission <I>MUST</I> include a first name!<BR></font>
<font size=4>If you are entering a band name like &quot;The Beatles&quot;, or a person with only one name like
&quot;Fabio&quot;, or &quot;Cher&quot, then please enter that info into the first name field.<BR><BR>
__EOF__
}#endsub firstname_errmsg
################################################################################




############################# cookie functions:
#############################################################################################
sub Deal_With_Cookies {
my $temp,$temp1,$temp2="";

#####$DEBUG_COOKIES=1;

if ($DEBUG_COOKIES >= 1) {
        print "Content-type: text/html\r\n\r\n"; #I'd call &Print_Header, but that would make infinite loop since it calls back to here
        print "\$cookies{Your_Email_Address} is \"$cookies{Your_Email_Address}\"<BR>\n";
        #####print "\$FORM{account_team_email} is \"$FORM{account_team_email}\"<BR>\n";
}#endif

if (!$COOKIES_DEALT_WITH_YET) {
        $COOKIES_DEALT_WITH_YET=1;

        ##### CHECK EMAIL ADDRESS AND UPDATE IF NECESSARY:
        #if the email cookie is different from the entered cookie, and they are not both blank, then update:
        $temp = $FORM{Your_Email_Address};
        if (
		($cookies{Your_Email_Address} ne $temp) 
		&& ($temp ne "")
	) {
                &give_simple_cookie("Your_Email_Address","$temp");
        } else {
                $FORM{Your_Email_Address} = $cookies{Your_Email_Address};
        }#endif
}#endif
}#endsub Deal_With_Cookies
#############################################################################################
#################################################################################################
sub read_cookies {
        #On platforms that support the environment variable $ENV{'HTTP_COOKIE'},
        #such as Solaris, cookies can be read into PERL with that environment variable.  
my @nvpairs=();
@nvpairs=split(/;/, $ENV{'HTTP_COOKIE'});
foreach $pair (@nvpairs) {
    ($name, $value) = split(/=/, $pair);
    $name = &remove_leading_and_trailing_spaces($name);
    $cookies{$name} = $value;
    if ($VERBOSE_READ_COOKIES) {
        print "<BR>setting cookies \"$name\" to \"$value\"<BR>\n\n";
    }#endif
}#endforeach
}#endsub
#################################################################################################
#################################################################################################
sub remove_leading_and_trailing_spaces {
my $s=$_[0];
$s =~ s/^\s+//;
$s =~ s/\s+$//;
return($s);
}#endsub remove_leading_and_trailing_spaces
#################################################################################################
#################################################################################################
sub give_simple_cookie {
my $name     = $_[0];
my $value    = $_[1];
my $verbose  = $_[2];

##### CLEAN THE COOKIE:
$value =~ s/;/:/g;      #we can't have semicolons in cookies so we'll sub it into a colon -- the closet match

##### GIVE THE COOKIE:
my $cookietext=&give_complex_cookie_perl($name,$value,"/","Fri, 31-Dec-99 00:00:00 GMT");

##### NOT TYPICALLY USED:
return $cookietext;
}#endsub give_simple_cookie give_cookie_simple
#################################################################################################
#################################################################################################
#Content-type: text/html
#Set-Cookie: foo=bar; path=/; expires=Fri, 01-Jan-98 00:00:00 GMT   
#Here, an HTML page would follow after a cookie has been set.
#Another very popular HTTP header used in PERL is Location. Be aware that location is best placed as the last header in a group:
#Content-type: text/html
#Set-Cookie: foo=bar; path=/; expires=Fri, 01-Jan-98 00:00:00 GMT
#Location: http://www.mysever.com
sub give_complex_cookie_perl {
my $name      = $_[0];
my $value     = $_[1];
my $path      = $_[2];
my $expires   = $_[3];
#my $location = $_[4];#no location support for this version
my $cookie    = "";

$name  = &remove_leading_and_trailing_spaces($name);
$value = &remove_leading_and_trailing_spaces($value);

 $cookie  = "Content-type: text/html\r\n";
 $cookie .= "Set-Cookie:$name=$value; expires=$expires; path=$path;\n";
#$cookie .= "Location: $location\n"; #no location support for this version

print  $cookie;
return $cookie;
}#endsub give_complex_cookie_perl
#################################################################################################





############################################################################################
sub Print_Header { 
&Deal_With_Cookies;
#ASSUME GLOBAL $HEADER_PRINTED_YET = 0 at start of program;
if (!$HEADER_PRINTED_YET) {
	$HEADER_PRINTED_YET=1;
	print "Content-type: text/html\r\n\r\n";
	print <<__END__;
	<html><head><title>Submit A Voice Actor Addition To The Database</title>
	<META name="keywords" CONTENT="cartoon voice actor submit addition">
	<META name="description" CONTENT="Clint's Voice Actor Database: Submit A New Credit To The Database.">
	</head> <BODY LINK="#FF0000" VLINK="#FF0000"  BGCOLOR="000000" text="FFFFFF">
__END__
}#endif
}#endsub
############################################################################################

############################################################################################
sub Print_Footer {
#ASSUMES FOOTER_ALREADY_PRINTED global;
if (!$FOOTER_ALREADY_PRINTED) {
	$FOOTER_ALREADY_PRINTED=1;
	print <<__EOF__;
	<font size=1 color=FF0000><B>Copyright  &copy; 1998 <a href="mailto:$PROBLEMS">Clint JCL</a>. All Rights Reserved.</b></font>
	</body></html>
__EOF__
}#endif
}#endsub
############################################################################################

############################################################################################
sub Print_Start_Form {
my $START_FORM_TYPE                = $_[0];
my $BUTTON                         = "";		#0 to print table, 1 to print form button
my $TEXT,$CHECKBOX,$RADIO          = "";
my $CREDIT_ME_CHECKED		   = "";
my $NAMESUFFIX_NONE_CHECKED	   = "";
my $NAMESUFFIX_SR_CHECKED	   = "";
my $NAMESUFFIX_JR_CHECKED	   = "";
my $NAMESUFFIX_III_CHECKED	   = "";
my $NAMESUFFIX_OTHER_CHECKED	   = "";
my $NAMESUFFIX_VALUE      	   = "";
my $GENRE_ANIMATED_CHECKED	   = "";
my $GENRE_LIVEANIMATION_CHECKED    = "";
my $GENRE_LIVEACTION_CHECKED	   = "";
my $GENRE_AUDIO_CHECKED		   = "";
my $GENRE_OTHER_CHECKED		   = "";
my $GENRE_VALUE   		   = "";
my $GUESTEPISODE_OFFICIAL_CHECKED  = "";
my $GUESTEPISODE_CONTRIVED_CHECKED = "";
my $GUESTEPISODE_STATUS_VALUE      = "";
my $SUBGENRE_SHOW_CHECKED	   = "";
my $SUBGENRE_MOVIE_CHECKED	   = "";
my $SUBGENRE_MINISERIES_CHECKED	   = "";
my $SUBGENRE_MUSIC_CHECKED	   = "";
my $SUBGENRE_THEMEPARK_CHECKED	   = "";
my $SUBGENRE_OTHER_CHECKED	   = "";
my $SUBGENRE_AWARDSHOW_CHECKED	   = "";
my $SUBGENRE_COMMERCIAL_CHECKED	   = "";
my $SUBGENRE_SPECIAL_CHECKED	   = "";
my $SUBGENRE_VALUE       	   = "";
my $STATUS_REGULAR_CHECKED	   = "";
my $STATUS_GUEST_CHECKED	   = "";
my $STATUS_SEMIREGULAR_CHECKED	   = "";
my $STATUS_UNKNOWN_CHECKED	   = "";
my $STATUS_VALUE         	   = "";
my $SUBMIT_BUTTON_NAME	           = "";
my $name                           = "";
my $COLOR                          = "";
#ASSUMES $NORMAL_FORM_PRINTED      = 0 until printed and then 1;
#ASSUMES $PRINT_START_FORM_NORMAL  = some unique number;
#ASSUMES $PRINT_START_FORM_EPISODE = some unique number;
#ASSUMES $PRINT_START_FORM_SHOW    = some unique number;
#ASSUMES $PRINT_START_FORM_NAME    = some unique number;
my %LOCALFORM=%FORM;

if ($DEBUG_START_FORM_LEVELS) { print "Print_Start_Form($START_FORM_TYPE)\n<HR>\n"; }

##### ARE WE PRINTING THE FULL TABLE FORM, OR JUST A DINKY BUTTON (WITH ALL THE SAME INPUT INFORMATION):
if ($START_FORM_TYPE eq $PRINT_START_FORM_NORMAL) {
	$BUTTON=0;
	$SUBMIT_BUTTON_NAME="Submit Voice Addition";
	if ($NORMAL_FORM_PRINTED==1) {
		return; 
	} else {
		$NORMAL_FORM_PRINTED=1;
	}#endif
} else {
	$BUTTON=1;
	if ($START_FORM_TYPE eq $PRINT_START_FORM_EPISODE) {
		$SUBMIT_BUTTON_NAME="Submit another credit for the episode &quot;$FORM{guestepisode}&quot; of the show &quot;$FORM{featurename}&quot;";
		$LOCALFORM{firstname}="";
		$LOCALFORM{middlename}="";
		$LOCALFORM{lastname}="";
		$LOCALFORM{namesuffix}="";
		$LOCALFORM{namesuffix_other}="";
		$LOCALFORM{character}="";
		$LOCALFORM{comments}="";
	} elsif ($START_FORM_TYPE eq $PRINT_START_FORM_SHOW) {
		$SUBMIT_BUTTON_NAME="Submit another credit for the show &quot;$FORM{featurename}&quot;";
		$LOCALFORM{firstname}="";
		$LOCALFORM{middlename}="";
		$LOCALFORM{lastname}="";
		$LOCALFORM{namesuffix}="";
		$LOCALFORM{namesuffix_other}="";
		$LOCALFORM{character}="";
		$LOCALFORM{comments}="";
		$LOCALFORM{status}="";
		$LOCALFORM{genre}="";
		$LOCALFORM{subgenre}="";
		$LOCALFORM{guestepisode}="";
		$LOCALFORM{guestepisode_status}="";
	} elsif ($START_FORM_TYPE eq $PRINT_START_FORM_NAME) {
		$name=&get_printable_name_from_form_inputs;
		$SUBMIT_BUTTON_NAME="Submit another credit for the person &quot;$name&quot;";
		$LOCALFORM{character}="";
		$LOCALFORM{comments}="";
		$LOCALFORM{status}="";
		$LOCALFORM{guestepisode}="";
		$LOCALFORM{featurename}="";
		$LOCALFORM{guestepisode}="";
		$LOCALFORM{guestepisode_status}="";
		#let's ONLY carry over their previous input if it's an animated TV show:
		if (($FORM{genre} ne "animated") || ($FORM{subgenre} ne "show")) {
			$LOCALFORM{genre}="";
			$LOCALFORM{subgenre}="";
			$LOCALFORM{genre_other}="";
			$LOCALFORM{subgenre_other}="";
		}#endif
	} elsif ($START_FORM_TYPE eq $PRINT_START_FORM_NORMAL_BUTTON) {
		$SUBMIT_BUTTON_NAME="Submit another unrelated credit";
		%LOCALFORM=();	#erase list
	} else {
		print <<__EOF__;
		<h1>INTERNAL ERROR PSFTNF!!!</h1>
		<font size=6>Please notify <a href=\"MAILTO:$PROBLEMS\">$PROBLEMS</a> of this problem!</font>
		<font size=5>Please include the error message: START_FORM_TYPE eq \"$START_FORM_TYPE\".</font>
__EOF__
		&Print_Footer;
		exit;
	}#endif
}#endif



##### FIRST WE MUST FIGURE STUFF OUT:
if (($FORM{credit_me} eq "1") || ($FORM{level} eq "")) { 
	$CREDIT_ME_CHECKED="checked"; 
}#endif

if    ($LOCALFORM{namesuffix} eq "none")  { $NAMESUFFIX_NONE_CHECKED  = "checked"; $NAMESUFFIX_VALUE="none";  }
elsif ($LOCALFORM{namesuffix} eq "sr")    { $NAMESUFFIX_SR_CHECKED    = "checked"; $NAMESUFFIX_VALUE="sr";    }
elsif ($LOCALFORM{namesuffix} eq "other") { $NAMESUFFIX_OTHER_CHECKED = "checked"; $NAMESUFFIX_VALUE="other"; }
elsif ($LOCALFORM{namesuffix} eq "jr")    { $NAMESUFFIX_JR_CHECKED    = "checked"; $NAMESUFFIX_VALUE="jr";    }
elsif ($LOCALFORM{namesuffix} eq "iii")   { $NAMESUFFIX_III_CHECKED   = "checked"; $NAMESUFFIX_VALUE="iii";   }
else                                      { $NAMESUFFIX_NONE_CHECKED  = "checked"; $NAMESUFFIX_VALUE="none";  }

if    ($LOCALFORM{genre} eq "animated")      { $GENRE_ANIMATED_CHECKED      = "checked"; $GENRE_VALUE="animated";      }
elsif ($LOCALFORM{genre} eq "liveanimation") { $GENRE_LIVEANIMATION_CHECKED = "checked"; $GENRE_VALUE="liveanimation"; }
elsif ($LOCALFORM{genre} eq "liveaction")    { $GENRE_LIVEACTION_CHECKED    = "checked"; $GENRE_VALUE="liveaction";    }
elsif ($LOCALFORM{genre} eq "audio")         { $GENRE_AUDIO_CHECKED         = "checked"; $GENRE_VALUE="audio";         }
elsif ($LOCALFORM{genre} eq "other")         { $GENRE_OTHER_CHECKED         = "checked"; $GENRE_VALUE="other";         }
#Let's leave this input completely blank to make sure they don't just go with the flow:
#else                                        { $GENRE_ANIMATED_CHECKED      = "checked"; $GENRE_VALUE="animated";      }

if    ($LOCALFORM{subgenre} eq "show")       { $SUBGENRE_SHOW_CHECKED       = "checked"; $SUBGENRE_VALUE="show";       }
elsif ($LOCALFORM{subgenre} eq "awardshow")  { $SUBGENRE_AWARDSHOW_CHECKED  = "checked"; $SUBGENRE_VALUE="awardshow";  }
elsif ($LOCALFORM{subgenre} eq "movie")      { $SUBGENRE_MOVIE_CHECKED      = "checked"; $SUBGENRE_VALUE="movie";      }
elsif ($LOCALFORM{subgenre} eq "miniseries") { $SUBGENRE_MINISERIES_CHECKED = "checked"; $SUBGENRE_VALUE="miniseries"; }
elsif ($LOCALFORM{subgenre} eq "commercial") { $SUBGENRE_COMMERCIAL_CHECKED = "checked"; $SUBGENRE_VALUE="commercial"; }
elsif ($LOCALFORM{subgenre} eq "music")      { $SUBGENRE_MUSIC_CHECKED      = "checked"; $SUBGENRE_VALUE="music";      }
elsif ($LOCALFORM{subgenre} eq "special")    { $SUBGENRE_SPECIAL_CHECKED    = "checked"; $SUBGENRE_VALUE="special";    } 
elsif ($LOCALFORM{subgenre} eq "themepark")  { $SUBGENRE_THEMEPARK_CHECKED  = "checked"; $SUBGENRE_VALUE="themepark";  }
elsif ($LOCALFORM{subgenre} eq "other")      { $SUBGENRE_OTHER_CHECKED      = "checked"; $SUBGENRE_VALUE="other";      }
#Let's leave this input completely blank to make sure they don't just go with the flow:
#else                                        { $SUBGENRE_SHOW_CHECKED       = "checked"; $SUBGENRE_VALUE="show";       }

if    ($LOCALFORM{status} eq "regular")     { $STATUS_REGULAR_CHECKED     = "checked"; $STATUS_VALUE="regular";     }
elsif ($LOCALFORM{status} eq "semiregular") { $STATUS_SEMIREGULAR_CHECKED = "checked"; $STATUS_VALUE="semiregular"; }
elsif ($LOCALFORM{status} eq "guest")       { $STATUS_GUEST_CHECKED       = "checked"; $STATUS_VALUE="guest";       }
elsif ($LOCALFORM{status} eq "unknown")     { $STATUS_UNKNOWN_CHECKED     = "checked"; $STATUS_VALUE="unknown";     }
#Let's leave this input completely blank to make sure they don't just go with the flow:
#else                                       { $STATUS_REGULAR_CHECKED     = "checked"; $STATUS_VALUE="regular";     }

if    ($LOCALFORM{guestepisode_status} eq "official")  { $GUESTEPISODE_OFFICIAL_CHECKED  = "checked"; $GUESTEPISODE_STATUS_VALUE="official";  }
elsif ($LOCALFORM{guestepisode_status} eq "contrived") { $GUESTEPISODE_CONTRIVED_CHECKED = "checked"; $GUESTEPISODE_STATUS_VALUE="contrived"; }
#Let's leave this input completely blank to since it's commonly nonapplicable:
#else                                       	       { $GUESTEPISODE_CHECKED           = "checked"; $GUESTEPISODE_STATUS_VALUE="regular";   }

#if ($LOCALFORM{} eq "1") { $_CHECKED="checked"; $_VALUE=""; }
#if ($LOCALFORM{} eq "1") { $_CHECKED="checked"; $_VALUE=""; }

##### PRINT HEADER IF APPLICABLE:
if ($HEADER_PRINTED_YET==0) { 
	&Print_Header; 
	#if ($FORM{level} eq "") { &Welcome; }
}#endif
#DEBUG: print "<h1>Printing start form</h1>\n"; #



##### IF WE ARE JUST PRINTING A BUTTON, WE NEED TO CONVERT CERTAIN INPUT TYPES TO HIDDEN:
if ($BUTTON) { 
	$TEXT="hidden";	$CHECKBOX="hidden";	$RADIO="hidden";
} else {
	$TEXT="text";	$CHECKBOX="checkbox";	$RADIO="radio";
}#endif



##### AFTER FIGURING STUFF OUT, WE KNOW HOW TO PRINT THE START FORM:
$COLOR="88C0FF";

if (!$BUTTON) { print "<font face=\"arial,helvetica,courier\">"; }

print "<form method=\"post\" action=\"$ThisProgram\">\n";

if (!$BUTTON) {
	print <<__ENDOFTEXT__;
<p align=center><center><input type="reset" value="Clear Form">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp;<input type="submit" value="Submit Voice Addition"></center></p>
<table bgcolor=890000 color=000000 cellpadding=10 cellspacing=0 align=center border=0>
<input type="hidden" name="character_name_warning_given" value="$LOCALFORM{character_name_warning_given}">
<input type="hidden" name="audio_genre_discrepancy_warning_given" value="$LOCALFORM{audio_genre_discrepancy_warning_given}">
<input type="hidden" name="audio_subgenre_discrepancy_warning_given" value="$LOCALFORM{audio_subgenre_discrepancy_warning_given}">
<input type="hidden" name="no_guest_episode_warning_given" value="$LOCALFORM{no_guest_episode_warning_given}">
<input type="hidden" name="guest_episode_given_without_checkbox_warning_given" value="$LOCALFORM{guest_episode_given_without_checkbox_warning_given}">
<input type="hidden" name="first_but_no_last_warning_given" value="$LOCALFORM{first_but_no_last_warning_given}">
<TR><TD><font size=+2 color=$COLOR>YOUR Email Address:</font></TD>
__ENDOFTEXT__
	print "<TD>";
}#endif

print "<input type=\"$TEXT\" name=\"Your_Email_Address\" size=35 maxlength=250 value=\"$LOCALFORM{Your_Email_Address}\">\n";

if (!$BUTTON) {
	print <<__ENDOFTEXT__;
</TD></TR><TR>
<TD>(<B><I>NOT</i></b> <B>for spam,</B> but for follow-up questions--if necessary)<BR>
(if you don't have email, you could enter other contact information)</TD>
__ENDOFTEXT__
	print "<TD valign=top>";
}#endif

print "<input type=\"$CHECKBOX\" name=\"credit_me\" value=\"1\" $CREDIT_ME_CHECKED>\n";

if (!$BUTTON) {
	print <<__ENDOFTEXT__;
	<B>Please publicly credit me as a contributor using my email address,</B> 
	 or whatever I put in this field.</TD></TR>
	<TR bgcolor=A10000>
	<TD><font size=+2 color=$COLOR>First Name:</font></TD>
__ENDOFTEXT__
	print "<TD valign=top>";
}#endif

print "<input type=\"$TEXT\" name=\"firstname\" size=35 maxlength=99 value=\"$LOCALFORM{firstname}\">\n";

if (!$BUTTON) {
	print <<__EOF__;
<BR>(if it's a band, or someone with only one name, like Fabio or Cher, enter the <i>entire</i> name here)</TD></TR>
<TR><TD><font size=+2 color=$COLOR>Middle Name:</font><BR>(initials acceptable)</TD>
__EOF__
	print "<TD valign=top>";
}#endif

print "<input type=\"$TEXT\" name=\"middlename\" size=35 maxlength=99 value=\"$LOCALFORM{middlename}\">\n";

if (!$BUTTON) {
	print <<__EOF__;
<BR>(leave blank if unknown)</TD></TR>
<TR bgcolor=A10000><TD><font size=+2 color=$COLOR>Last Name:</font></TD>
__EOF__
	print "<TD valign=top>";
}#endif

print "<input type=\"$TEXT\" name=\"lastname\" size=35 maxlength=99 value=\"$LOCALFORM{lastname}\">\n";

if (!$BUTTON) {
	print <<__EOF__;
</TD></TR><TR><TD><font size=+2 color=$COLOR>Name Suffix:</font></TD>
<TD><table cellpadding=2 cellspacing=0 border=0>
<TR><TD><input type=\"$RADIO\" name=\"namesuffix\" value=\"none\" $NAMESUFFIX_NONE_CHECKED><B>None</B>&nbsp;&nbsp;&nbsp;&nbsp;</TD>
<TD><input type=\"$RADIO\" name=\"namesuffix\" value=\"sr\" $NAMESUFFIX_SR_CHECKED>Sr.&nbsp;&nbsp;&nbsp;</TD>
<TD><input type=\"$RADIO\" name=\"namesuffix\" value=\"other\" $NAMESUFFIX_OTHER_CHECKED><B>Other:</B>
<input type=\"$TEXT\" name=\"namesuffix_other\" value=\"$LOCALFORM{namesuffix_other}\" size=5 maxlength=99></TD></TR>
<TR><TD><input type=\"$RADIO\" name=\"namesuffix\" value=\"jr\" $NAMESUFFIX_JR_CHECKED>Jr.</TD>
<TD colspan=2><input type=\"$RADIO\" name=\"namesuffix\" value=\"iii\" $NAMESUFFIX_III_CHECKED>III</TD></TR></table></TD></TR>
__EOF__
} else {
	print "<input type=\"$RADIO\" name=\"namesuffix\" value=\"$NAMESUFFIX_VALUE\">\n";
	print "<input type=\"$TEXT\" name=\"namesuffix_other\" value=\"$LOCALFORM{namesuffix_other}\">\n";
}#endif


if (!$BUTTON) {
	print <<__EOF__;
<TR bgcolor=A10000><TD><font size=+2 color=$COLOR>Genre:</font></TD>
<TD><table cellspacing=2 cellpadding=0>
<TR><TD valign=top><input type=\"$RADIO\" name=\"genre\" value=\"animated\" $GENRE_ANIMATED_CHECKED></TD>
<TD valign=top><B>Animation</B> (normal cartoons)</TD></TR>
<TR><TD valign=top><input type=\"$RADIO\" name=\"genre\" value=\"liveanimation\" $GENRE_LIVEANIMATION_CHECKED></TD>
<TD valign=top><B>Live Animation</B> (claymation and such)</TD></TR>
<TR><TD valign=top><input type=\"$RADIO\" name=\"genre\" value=\"liveaction\" $GENRE_LIVEACTION_CHECKED></TD>
<TD valign=top><B>Live Action</B> (normal TV)</TD></TR>
<TR><TD valign=top><input type=\"$RADIO\" name=\"genre\" value=\"audio\" $GENRE_AUDIO_CHECKED><BR><BR></TD>
<TD valign=top><B>Audio-only</B> (music, theme park narration, <B><I>NOT</i></B> voice-overs)<BR>(see sub-genre entry below)<BR>
<B>(If they were a voice-only role in something with video, simply put &quot;(voices)&quot; next to their character name.)</B></TD></TR>
<TR><TD valign=top><input type=\"$RADIO\" name=\"genre\" value=\"other\" $GENRE_OTHER_CHECKED></TD>
<TD valign=top><B>Other:</B> <input type=\"$TEXT\" name=\"genre_other\" value=\"$LOCALFORM{genre_other}\" size=25 maxlength=99></TD></TR></table>
</TD></TR>
__EOF__
} else {
	print <<__EOF__;
<input type="$RADIO" name="genre" value="$GENRE_VALUE">
<input type="$TEXT" name="genre_other" value="$LOCALFORM{genre_other}">
__EOF__
}#endif


if (!$BUTTON) {
	print <<__EOF__;
<TR><TD><font size=+2 color=$COLOR>Sub-Genre:</font></TD>
<TD><table cellpadding=1 cellspacing=0 border=0>
<TR><TD><input type=\"$RADIO\" name=\"subgenre\" value=\"show\" $SUBGENRE_SHOW_CHECKED><B>TV Show</B></TD>
<TD><input type=\"$RADIO\" name=\"subgenre\" value=\"awardshow\" $SUBGENRE_AWARDSHOW_CHECKED>Awards Show <font size=3><B>(genre unused)</B></font></TD></TR>
<TR><TD><input type=\"$RADIO\" name=\"subgenre\" value=\"movie\" $SUBGENRE_MOVIE_CHECKED><B>Movie</B></TD>
<TD><input type=\"$RADIO\" name=\"subgenre\" value=\"miniseries\" $SUBGENRE_MINISERIES_CHECKED>Mini-Series</TD></TR>
<TR><TD><input type=\"$RADIO\" name=\"subgenre\" value=\"commercial\" $SUBGENRE_COMMERCIAL_CHECKED>Commercial&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
<TD><input type=\"$RADIO\" name=\"subgenre\" value=\"music\" $SUBGENRE_MUSIC_CHECKED>Music <font size=3><B>(audio only)</B></font></TD></TR>
<TR><TD><input type=\"$RADIO\" name=\"subgenre\" value=\"special\" $SUBGENRE_SPECIAL_CHECKED>Special</TD>
<TD><input type=\"$RADIO\" name=\"subgenre\" value=\"themepark\" $SUBGENRE_THEMEPARK_CHECKED>Theme Park / Museum <font size=3><B>(genre unused)</B></font></TD></TR>
<TR><TD colspan=2><input type=\"$RADIO\" name=\"subgenre\" value=\"other\" $SUBGENRE_OTHER_CHECKED><B>Other:</B> 
<input type=\"$TEXT\" name=\"subgenre_other\" value=\"$LOCALFORM{subgenre_other}\" size=25 maxlength=99></TD></TR>
</table></TD></TR>
__EOF__
} else {
	print <<__EOF__;
<input type="$RADIO" name="subgenre" value="$SUBGENRE_VALUE">
<input type="$TEXT" name="subgenre_other" value="$LOCALFORM{subgenre_other}">
__EOF__
}#endif



if (!$BUTTON) {
	print <<__EOF__;
<TR bgcolor=A10000>
<TD><font size=+2 color=$COLOR>Title or description of what they were in:</font><BR>
(<B>show title, movie title,</b> song title, theme park title,
band name -- <B><I>whatever applies</i></B> to this particular credit -- you could even put something like &quot;tons of Kung-Fu movies&quot;)</TD>
__EOF__
	print "<TD>";
}#endif

print "<input type=\"$TEXT\" name=\"featurename\" size=35 maxlength=99 value=\"$LOCALFORM{featurename}\">\n";

if (!$BUTTON) {
	print "<BR><B>(Remember: It doesn't necessarily have to be a cartoon!!)</b></TD></TR>";
	print <<__EOF__;
<TR><TD><font size=+2 color=$COLOR>Character's Name:</font><br>
<B>(you can enter several characters separated by commas if you wish!!!)</B>
(<B>descriptions</b> rather than actual names <B>are fine</b>!)<BR>
<font color=88CC62>(write &quot;(voice only)&quot; after the character name <B><I>if</i></B> it is a voice-only 
role <I>in a live action medium</i>!!!)</font></TD>
__EOF__
	print "<TD>";
}#endif

print "<input type=\"$TEXT\" name=\"character\" size=35 maxlength=99 value=\"$LOCALFORM{character}\">\n";


if (!$BUTTON) {
	print "<BR><font size=-1>(Something is always better than nothing!!)<BR>(Too much is better than too little!!)</font><BR>";
	print "<B>(But leave blank or type UNKNOWN if you're clueless)</b></TD></TR>";
	print <<__EOF__;
<TR bgcolor=A10000>
<TD><font size=+2 color=$COLOR>Status:</font></TD>
<TD><table align=left border=0 cellpadding=1 cellspacing=0><TR>
<TD><input type=\"$RADIO\" name=\"status\" value=\"regular\" $STATUS_REGULAR_CHECKED>Regular&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
<TD><input type=\"$RADIO\" name=\"status\" value=\"semiregular\" $STATUS_SEMIREGULAR_CHECKED>Semi-Regular</TD>
</TR><TR>
<TD><input type=\"$RADIO\" name=\"status\" value=\"guest\" $STATUS_GUEST_CHECKED>Guest</TD>
<TD><input type=\"$RADIO\" name=\"status\" value=\"unknown\" $STATUS_UNKNOWN_CHECKED>Unknown</TD>
</TR></TABLE>
</TD>
</TR>
__EOF__
} else {
	print "<input type=\"$RADIO\" name=\"status\" value=\"$STATUS_VALUE\">\n";
}#endif



if (!$BUTTON) {
	print <<__EOF__;
<TR><TD><font size=+2 color=$COLOR>Episode Title:</font><BR>
(if they are a <B>semi-regular</b>, you may give multiple episode titles, 
or describe <i>when</i> they were a semi-regular--such as &quot;season 2&quot;)</TD>
__EOF__
	print "<TD valign=top>";
}#endif

print "<input type=\"$TEXT\" name=\"guestepisode\" size=35 maxlength=99 value=\"$LOCALFORM{guestepisode}\">\n";

if (!$BUTTON) {
	print "<BR><font size=+1>(leave blank if they are a regular!!)</font></TD></TR>\n";
}#endif

if (!$BUTTON) {
	print <<__EOF__;
<TR bgcolor=A10000><TD><font size=+2 color=$COLOR>Guest Episode Title Status:</font><BR>
(only necessary if you clicked &quot;Guest&quot; above)</TD>
<TD><table cellspacing=0 cellpadding=0 border=0><TR>
	<TD><input type=$RADIO name=guestepisode_status value="official"  $GUESTEPISODE_OFFICIAL_CHECKED>Official title&nbsp;&nbsp;&nbsp;&nbsp;</TD>
	<TD><input type=$RADIO name=guestepisode_status value="contrived" $GUESTEPISODE_CONTRIVED_CHECKED>Made-up title</TD></TR></TABLE>
</TD></TR>
__EOF__
} else {
	print "<input type=\"$RADIO\" name=\"guestepisode_status\" value=\"$GUESTEPISODE_STATUS_VALUE\">\n";
#ohohohoh
}#endif


if (!$BUTTON) {
	print <<__EOF__;
	<TR bgcolor=890000><TD><font size=+2 color=$COLOR>Comments:</font><BR>
	Elaborate on things you are unsure about, or enter information that the form would not let you enter elsewhere.
	You could also include personal facts about the celebrity.</TD>
	<TD><textarea name=comments rows=5 cols=35>$LOCALFORM{comments}</textarea></TD></TR></table>
	<center><P align=center><input type="reset" value="Clear Form">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
__EOF__
} else {
	print "<input type=\"hidden\" name=\"comments\" value=\"$LOCALFORM{comments}\">\n";
}#endif


print "<input type=\"submit\" value=\"$SUBMIT_BUTTON_NAME\">\n";


if ($BUTTON) { 
	print "<input type=\"hidden\" name=\"level\" value=\"resubmit\">\n</form>\n"; 
} else {
	print "<input type=\"hidden\" name=\"level\" value=\"submit\">\n</form>\n"; 
	print "</font></center>\n";
}#endif

%LOCALFORM=();
}#endsub Print_Start_Form
############################################################################################




##############################################################################################################################################
sub check_email_address {
        $address = $_[0];

#print "<hr>\$address is $address<hr>";

        $address =~ s/^\s+//;
        $address =~ s/\s+$//;
        if (($address !~ /^\S+\@\S+\.\S+$/) ||
            ($address =~ /\S+\@\S+\@/i)) {
                print "<b>FATAL ERROR:  Your email address \"$address\" does not appear to be ";
                print "valid...</b><p>";
                print "Remember, your email address should only contain a valid email ";
                print "address, not your actual names.<p>";
                print "Also note, a valid email address takes the form <b>\"someone\@something.something\"</b><p>";

                &Print_Footer;
                exit(1);
        }#endif
}#endsub
##############################################################################################################################################



############################################################################################
sub Successful_Add {
print "<font color=\"dd1515\"><h1 align=center>Thank you for your submission!</h1></font>\n";

##### Print the proper start forms -- note that we should not print the guest option if this is a general non-guest thingee:
if ($FORM{guestepisode} ne "") {
	&Print_Start_Form($PRINT_START_FORM_EPISODE);
}#endif
&Print_Start_Form($PRINT_START_FORM_SHOW);
&Print_Start_Form($PRINT_START_FORM_NAME);
&Print_Start_Form($PRINT_START_FORM_NORMAL_BUTTON);

print <<__ENDOFTEXT__;
<hr><FONT SIZE=+2><CENTER><B>****** New Voice Database Addition Successfully Processed</B></CENTER></FONT><hr>
<b>NOTE:</b> If you don't receive an email approval or rejection notice within the next few weeks, then you probabaly 
entered the wrong email address for yourself.<BR><i><b>KNOW YOUR OWN EMAIL ADDRESS OR ACCEPT THAT YOU WILL RECEIVE NO ACKNOWLEDGEMENT.</b></i>
__ENDOFTEXT__
}#endsub
############################################################################################



############################################################################################
sub Write_Audit {
my $AUDIT="";		#text of audit file
my $FILENAME="";	#name of audit file
my $SUFFIX="";
#ASSUMES $BASE_HOLDING_DIR = the base dir that [http/nobody can write to] for storing audit files;
#ASSUMES $AUDIT_PREFIX     = the base filename, for example the word "audit" is sufficient.

##### DETERMINE AUDIT FILE SUFFIX:
$SUFFIX =  "$FORM{character}" . "." . "$FORM{firstname}" . "." . "$FORM{featurename}";	#save this crap for an age when people don't submit twice: . "$$";
$SUFFIX =~ s/[\s\;\/\\]+/_/g;

##### DETERMINE THE AUDIT FILE CONTENTS:
$AUDIT .= "BEGIN_TRANSACTION\n";
$AUDIT .= &audit_text;
$AUDIT .= "EMAIL::::$FORM{Your_Email_Address}\n";
if ($FORM{credit_me} eq "1") {
	$AUDIT .= "CREDITME\n";
}#endif
$AUDIT .= "END_TRANSACTION\n";

##### WRITE AUDIT FILE TO LOCALFILESYSTEM:
$FILENAME = "$BASE_HOLDING_DIR/$AUDIT_PREFIX" . "." . "$SUFFIX";
if ($DEBUG_NO_AUDIT_WRITES) {
        print "<hr><font size=7 color=ff0000><B>Service temporarily unavailable</B></font><BR>\n";
        print "<h2>Sorry, the saving of your output has been temporarily suspended while $PROBLEMS is working on this script</h2>"; 
        print "Feel free to <a href=\"MAILTO:$PROBLEMS\">mail me</a> and ask me to &quot;Turn DEBUG_NO_AUDIT_WRITES off&quot; so "; 
        print "you can submit your addition.  All I have to do is comment out a line of code, then you can click reload, and your ";
        print "info will be submitted.  Alternately, you can just leave this browser window open, and reload a few minutes/hours later.<P>";
        print "Below I will give the output that would normally be given if this error message was not being printed.  Do NOT use any of ";
        print "the links below or you will lose your output. This is just for me to debug my own script.<hr>";
        &Successful_Add;
} else {
	while (-e "$FILENAME") {		#ensure unique filename
		$FILENAME .= "_";
	}#endif
	if (!open(AUDIT,">$FILENAME")) {
		print "FATAL ERROR: Could not open $FILENAME" . "!!! NOTIFY $PROBLEMS IMMEDIATELY!!!<BR>";
		print "(This would be indicative of a permissions problem, or a severe technical difficulty, like a full harddrive)";
		print "<BR>(please include this errormessage with your notification if possible)<BR>";
		exit(1);
	} else {
		print AUDIT "$AUDIT";
		close (AUDIT);
		&Successful_Add;	#acknowledge submission
	}#endif
}#endif

##### SHOW CONTENTS TO USER:
#This was originally a debug but I like showing them their results were read:
print "<hr><PRE>$AUDIT</PRE><HR>\n";

}#endsub
############################################################################################


###################################################################################################################################
sub Welcome {
print <<__EOF__;
<center><p align=center><font size=5><B><I>W</I></B></font><font size=3>elcome to...</font>
<table align=center cellpadding=0 cellspacing=10>
<TR><TD align=right><font color="bb0000" face="arial,courier,helvetica" size=4><B>The</B></font></TD>
<TD align=center><font color="ee3333" face="arial,courier,helvetica" size=6><B>Contribute To The Database</B></font></TD>
<TD align=left><font color="bb0000" face="arial,courier,helvetica" size=4><B>Form</B></font></td></tr>
</table>
__EOF__

print &counter;#({begintext=>'You are visitor number <font color=\"FF0000\">',
		#endtext=>'</font>.'});

print <<__EOF__;
<P align=center><font face="arial,helvetica,courier">
Please <B>bookmark this page</B> so you can continue to contribute in the future.
</font><font size=+3><TT><B>:)</B></TT></font></P>
<P align=center><font face="arial,helvetica,courier">
<B><font size=+1>R</font></B>emember: <B>Use question marks</B> if you are unsure about something<B>!!</B><br>
<B><font size=+1>R</font></B>emember: <B>Please capitalize properly</B> so I don't have to fix it<B>!!</B><br>
<BR><font size=3 color=ffd5aa>It's <B><I>perfectly fine</i></B> to be unsure about something!
But <B>I'd prefer a question mark next to unsure information</B>, rather than
just having incorrect information and not knowing it is uncertain.</font></P><BR>
__EOF__
}#endsub Welcome
###################################################################################################################################

##############################################################################################################################
sub get_printable_name_from_form_inputs {
my $name="";
#ASSUMES $FORM{firstname}, $FORM{middlename}, $FORM{lastname} are equal to user input;

$name = $FORM{firstname};

if ($FORM{middlename} ne "") { $name .= " $FORM{middlename}"; }
if ($FORM{lastname}   ne "") { $name .= " $FORM{lastname}"; }

return($name);
}#endsub get_printable_name_from_form_inputs
##############################################################################################################################
################################################################################################################
sub Resubmit_Welcome {
print <<__EOF__;
<center><font size=6 color=ff0000><B>Enter your next credit below.</B></font><BR>
<font size=4 color=22cc88>Depending on what button you clicked on the last page, certain inputs may have been carried over
for your convenience.  This translates to less typing on your part.</font>
</center>
__EOF__
}#endsub resubmit_welcome
################################################################################################################

###########################################################################################################
sub audit_text {	#returns text of audit file without begin/end. assumes lots of form inputs.
#Lastname, Firstname Middlename: CARTOONS: A show's name:Charactername[guest if applicable]
#<====== printable name ======>  <pgenre>  <==showname=> <=character=> <== guest title ==>

my $AUDIT="";	#return value. should end in newline.
my $printable_name="";
my $printable_genre="";
my $printable_suffix="";
my $showname=$FORM{featurename};
my $character=$FORM{character};
my $guest_title=$FORM{guestepisode};
my $temp="";

##### DETERMINE NAME PART:
$printable_name = &normalize_name($FORM{lastname});

#DEBUG: #print "<BR>[[[ form{charactername} is $FORM{character} ]]]<BR>\n";#

#DEBUG: #print "Checking form{namesuffix} which equals &quot;$FORM{namesuffix}&quot;<BR>\n";#

if ($FORM{namesuffix} ne "none") {
	$printable_suffix="";
	if ($FORM{namesuffix} eq "other") {
		$printable_suffix = "$FORM{namesuffix_other}";
	} else {
		if ($FORM{namesuffix} eq "sr") {
			$printable_suffix="Sr.";
		} elsif ($FORM{namesuffix} eq "jr") {
			$printable_suffix="Jr.";
		} elsif ($FORM{namesuffix} eq "iii") {
			$printable_suffix="III";
		}#endif	
	}#endif
	if ($printable_suffix ne "") {
		$printable_name .= " $printable_suffix";
	}#endif
}#endif
#it is invalid to enter a middle name without a last name so we do not need to consider that possibility.
if ($FORM{firstname} ne "") {
	$temp=&normalize_name($FORM{firstname});
	#DEBUG: #print "[printable name is currently &quot;$printable_name&quot;]<BR>\n";#
	if ($printable_name ne "") {
		$printable_name .= ", ";	#there is no comma unless there is a last name
	}#endif
	$printable_name .= "$temp";
	if ($FORM{middlename} ne "") {
		$temp=&normalize_name($FORM{middlename});
		$printable_name .= " $temp";
	}#endif
}#endif

##### DETERMINE THE GENRE PART:
#12XU
if ($FORM{genre} eq "animated") {
	if ($FORM{subgenre} eq "show") {
		$printable_genre="CARTOONS";
	} else {
		$printable_genre="ANIMATED";
	}#endif
} elsif ($FORM{genre} eq "audio") {
	$printable_genre="";
} elsif ($FORM{genre} eq "other") {
	$printable_genre="$FORM{genre_other}";
} elsif ($FORM{genre} eq "liveaction") {
	$printable_genre="LIVE";
} elsif ($FORM{genre} eq "animated") {
	$printable_genre="ANIMATED";
} elsif ($FORM{genre} eq "liveanimation") {
	$printable_genre="LIVE ANIMATION";
}#endif

if ($FORM{subgenre} eq "show") {
	#animated shows are called 'cartoons' in this database:
	if      ($FORM{genre} eq "liveanimation") {
		$printable_genre .= " (SERIES)";
	} elsif ($FORM{genre} ne "animated") {
		$printable_genre .= " SERIES";
	}#endif
} elsif ($FORM{subgenre} eq "awardshow") {
	#I'm not aware of any animated or audio only or liveanimated award shows, so we
	#use "=" and not ".=" here:
	$printable_genre = "AWARDS";
} elsif ($FORM{subgenre} eq "movie") {
	if      ($FORM{genre} eq "liveanimation") {
		$printable_genre .= " (MOVIES)";
	} else {
		$printable_genre .= " MOVIES";
	}#endif
} elsif ($FORM{subgenre} eq "commercial") {
	if      ($FORM{genre} eq "liveanimation") {
		$printable_genre .= " (COMMERCIALS)";
	} else {
		$printable_genre .= " COMMERCIALS";
	}#endif
} elsif ($FORM{subgenre} eq "special") {
	if      ($FORM{genre} eq "liveanimation") {
		$printable_genre .= " (SPECIALS)";
	} else {
		$printable_genre .= " SPECIALS";
	}#endif
} elsif ($FORM{subgenre} eq "miniseries") {
	if      ($FORM{genre} eq "liveanimation") {
		$printable_genre .= " MINISERIES";
	} else {
		$printable_genre .= " MINISERIES";
	}#endif
} elsif ($FORM{subgenre} eq "themepark") {
	#don't say "audio_only":
	$printable_genre = "THEME PARKS/MUSEUMS";
} elsif ($FORM{subgenre} eq "music") {
	#no live, or animated music, just music -- "=" not ".=":
	$printable_genre = "MUSIC";
} elsif ($FORM{subgenre} eq "other") {
	if      ($FORM{genre} eq "liveanimation") {
		$printable_genre .= " ($FORM{subgenre_other})";
	} elsif ($FORM{genre} eq "audio") {
		$printable_genre = "AUDIO-ONLY ($FORM{subgenre_other})";
	} else {
		$printable_genre .= " $FORM{subgenre_other}";
	}#endif

#BLANK:
#} elsif ($FORM{subgenre} eq "") {
#	$printable_genre .= "";

}#endif

#ohohohohoh make sure this looks right for all combinations


#} else {
#	print "INTERNAL ERROR!! SORRY FOR THE INCONVENIENCE!! CLINT HAS BEEN NOTIFIED AND SHOULD FIX THIS IMMEDIATLEY.<P>\n\n";
#	print "Clint suggests you leave this browser window open, and come back in 30 minutes (business hours--EST time zone) ";
#	print "to a day (nonbusiness hours) and then click reload.<P>";
#	&send_bug_report("form{genre} eq \"$FORM{genre}\"\n\nemail=$FORM{Your_Email_Address}\n\n");
#}#endif

#DEBUG: print "status is &quot;$FORM{status}&quot;<BR>\n";#

##### PUT THE PIECES TOGETHER AND RETURN THE AUDIT LINE:
$AUDIT = "$printable_name: $printable_genre: $showname";
if ($character !~ /UNKNOWN/i) {
	$AUDIT .= ":$character";	#credit part
} else {
	$COLON_NOT_PRINTED=1;
}#endif
if ($guest_title ne "") {		#guest part
	if ($COLON_NOT_PRINTED) { $AUDIT .= ":"; }
	if ($guest_title !~ /unknown/i) {
		if ($FORM{guestepisode_status} eq "contrived") {
			$guest_title =~ s/\"/'/g;
			$guest_title =~ s/,\s+/,/g;
			$guest_title =~ s/,/ /g;
			$guest_title =~ s/^(.*)$/\"$1\"/;
		} else {
			if ($guest_title =~ /[,]/) {
				$guest_title =~ s/,\s+/,/g;
				$guest_title =~ s/^(.*)$/\"$1\"/g;
			}#endif
		}#endif
		$AUDIT .= "[$guest_title]";
	} else {
		$AUDIT .= "[guest]";
	}#@endif
} elsif ($FORM{status} eq "unknown") {
	if ($COLON_NOT_PRINTED) { $AUDIT .= ":"; }
	$AUDIT .= "[regular?? guest??]";
}#endif
$AUDIT .= "\n";

return($AUDIT);
}#endsub audit_text
###########################################################################################################
###################################################################################
sub normalize_name {
my $name=$_[0];
my @NAMES=();
my $temp_name="";
my $retval,$first,$rest="";

@NAMES=split(/\s+/,"$name");

foreach $name (@NAMES) {
	#if there's no lowercase letters, translate it
	if (($name !~ /[a-z]/) && ($name =~ /[A-Z]/)) {	
		$name =~ tr/[A-Z]/[a-z]/;
	}#endif

	#at this point it should either be all lowercase, or user-formatted:

	#if all lowercase, capitolize first letter:
	if ($name =~ /^[a-z]/) {
		$first =  $name;
		$rest  =  $name;
		$first =~ s/^(.)(.*)$/$1/;
		$rest  =~ s/^(.)(.*)$/$2/;
		$first =~ tr/[a-z]/[A-Z]/;
		$name  =  "$first" . "$rest";
	}#endif

	#if it starts with a quote, capitalize the first letter after the quote:
	if ($name =~ /^\"/) {
		$name =~ s/^\"//;
		$first =  $name;
		$rest  =  $name;
		$first =~ s/^(.)(.*)$/$1/;
		$rest  =~ s/^(.)(.*)$/$2/;
		$first =~ tr/[a-z]/[A-Z]/;
		$name  =  "\"$first" . "$rest";		
	}#endif

	if ($name =~ /^(Mc)([a-z])/) {		#"Mcdonalds" -> "McDonalds"
		$first =  $name;
		$rest  =  $name;
		$first =~ s/^(..)(.)(.*)$/$2/;
		$rest  =~ s/^(..)(.)(.*)$/$3/;
		$first =~ tr/[a-z]/[A-Z]/;
		$name  =  "Mc" . "$first" . "$rest";
	}#endif

	if ($retval eq "") {
		$retval  = $name; 
	} else {
		$retval .= " $name";
	}#endif
}#endforeach


return($retval);
}#endsub normalize_name
###################################################################################
