#!/usr/bin/perl
package sdevColleagueGeneRegistryUserPage;

#######################################################################
##### Author :	Shuai Weng
##### Date   :  March 2001
##### Rev.   :  May 2001 (Kane Tse)
##### Clean up to use new Colleague object. Shuai Weng  8/01
#####
##### Description : This package contains all necessary methods for 
#####               displaying colleague update form or new entry form 
#####               to user. 
#####              
#######################################################################
##################           RCS INFORMATION          ################
# $Author: emj466 $
# $Date: 2006/10/26 20:38:24 $
# $Header: /projects/dicty/build/source_files/db/lib/site_name/user/sdevColleagueGeneRegistryUserPage.pm,v 1.3 2006/10/26 20:38:24 emj466 Exp $
# $Log: sdevColleagueGeneRegistryUserPage.pm,v $
# Revision 1.3  2006/10/26 20:38:24  emj466
# change temporary file directory to not include site_name
# ie. dicty/data/submission/colleague
# instead of
# dicty/data/submission/colleague/DICTYBASE
#
# Revision 1.2  2006/10/26 15:46:51  emj466
# replaced is_dictyBase_contact with 'is_subscribed'
#
# Revision 1.1  2006/10/25 18:29:12  emj466
# new build directory
#
# Revision 1.1.1.2  2003/08/18 22:50:41  emj466
# no message
#
# Revision 1.1.1.1  2003/08/15 20:18:41  emj466
# initial load of dicty/build
#
# Revision 1.44  2003/07/28 21:15:41  shuai
# *** empty log message ***
#
# Revision 1.43  2003/07/28 20:43:20  shuai
# *** empty log message ***
#
# Revision 1.42  2003/07/02 20:56:21  shuai
# *** empty log message ***
#
# Revision 1.41  2003/07/02 20:28:15  shuai
# *** empty log message ***
#
# Revision 1.40  2003/07/02 18:41:51  anand
# Edited to handle the new alias type field
#
# Revision 1.39  2003/05/15 21:17:41  shuai
# *** empty log message ***
#
# Revision 1.32  2003/05/15 21:17:03  shuai
# *** empty log message ***
#
# Revision 1.31  2003/02/27 23:54:28  shuai
# *** empty log message ***
#
# Revision 1.38  2003/02/27 23:53:46  shuai
# *** empty log message ***
#
# Revision 1.40  2003/02/27 23:46:01  shuai
# *** empty log message ***
#
# Revision 1.39  2003/02/27 23:13:09  shuai
# *** empty log message ***
#
# Revision 1.38  2003/02/27 23:06:56  shuai
# *** empty log message ***
#
# Revision 1.37  2003/01/09 23:33:26  kara
# few more changes for is_subscribed
#
# Revision 1.36  2003/01/08 00:50:03  kara
# Modified to handle is_subscribed option.  Added dictyBasecontact subroutine
# and modified the following subs:  printContactSection,
# readContactInfo, writeContactInfo,displayContactInfo,
# createNewEntryFile, createUpdateFile.  All changes have my initials
# (KD) in the comments.
#
# $Revision: 1.3 $
# $Source: /projects/dicty/build/source_files/db/lib/site_name/user/sdevColleagueGeneRegistryUserPage.pm,v $
# $State: Exp $
# $Locker:  $
######################################################################
use strict;
use DBI;
use CGI qw/:all/;
use CGI::Carp qw(fatalsToBrowser);
use LWP::UserAgent;
use lib "/usr/local/dicty/www_dictybase/db/lib/common";
use Login qw (ConnectToDatabase);
use TextUtil qw (DeleteUnwantedChar);
use lib "/usr/local/dicty/www_dictybase/db/lib/dictyBase";
use dictyBaseCentralMod qw(:formatPage :getInfo);
use lib "/usr/local/dicty/www_dictybase/db/lib/dictyBase/Objects";
use Colleague;
use ConfigURLdictyBase;
use ConfigPathdictyBase;
use Feature;
use Locus;
use Reflink;
use Locus_gene_info;
use Reference;

$ENV{'NLS_LANG'} = '.we8dec';

my $dbh;
my $dblink;
my $configUrl;
my $configPath;
my $url;
my %mon2num = ('Jan'=>'01', 'Feb'=>'02', 'Mar'=>'03', 'Apr'=>'04', 
	       'May'=>'05', 'Jun'=>'06', 'Jul'=>'07', 'Aug'=>'08', 
	       'Sep'=>'09', 'Oct'=>'10', 'Nov'=>'11', 'Dec'=>'12');
my $numUrls = 3;
my $debugMessage = "";


#######################################################################
sub new {      ############ constructor ###############################
#######################################################################
       
	my ($self, %args) = @_;

	$self = {};
	bless $self;

      	$self->{'_database'} = $args{'database'};
	$self->{'_colleagueNo'} = $args{'colleagueNo'};
	$self->{'_gene'} = $args{'gene'};
	$self->{'_orf'} = $args{'orf'};
	if ($self->{'_database'}) {
	    $dbh = &ConnectToDatabase($self->{'_database'});
	    $self->{'_database'} =~ tr/[a-z]/[A-Z]/;
	}
    	return $self;
}

sub database { $_[0]->{_database} }
sub colleagueNo { $_[0]->{_colleagueNo} }
sub gene { $_[0]->{_gene}}
sub orf { $_[0]->{_orf}}
sub title { $_[0]->{_title}}
sub help {$_[0]->{_help}}
sub pid {$_[0]->{_pid}}

#####################################################################
sub start {
######################################################################
    my ($self) = @_;

    $configUrl = ConfigURLdictyBase->new;
    $configPath = ConfigPathdictyBase->new;
    $dblink = $configUrl->dblink($self->database);
    $url = $ENV{"SCRIPT_NAME"};
    $url =~ s/\?.+$//;
    if ($self->colleagueNo !~ /^[0-9]+$/) {
	$self->{'_colleagueNo'} = "";
    }
    if (!param('registerType')) {
	$self->{'_help'} = "colleagueform.html";
    }
    $self->{'_pid'} = param('pid');
    if (!$self->{'_pid'}) { $self->{'_pid'} = $$; }

    if (param('pid') && param('back')) {
	# $self->{'_colleagueNo'} = param('id');
	$self->printVerificationPage;
	exit;
    }

    if (param('pid') && param('editType')) {
	if (param('SaveDisplay')) {    
	    $self->printVerificationPage;
	}
	else {
	    $self->editForm;
	}
	exit;
    }
    if (param('finalUpdate') || param('finalNewEntry')){

	for (my $i = 1; $i <= 10; $i++) {
	    if (param("ORIassociate$i") && !param("associate$i")) {
		$self->err_report("On the colleague new entry form, you typed a new associate name ".param("ORIassociate$i").". If you wish to add that person as an associate, you must select that person on the 'Colleague New Entry Verification' form. Please return to that page and select a name. Or, if you have decided that you do not wish to add that associate, please go back two pages, to the colleague new entry form, and remove that name. Thanks!");
		exit;
	    }
	}
	$self->readInfo;
	if (param('finalNewEntry')) {
	    $self->createNewEntryFile;
	}
	else {
	    $self->{'_colleagueNo'} = param('id');
	    $self->createUpdateFile;
	}
    }
    elsif ((!param('lname') && !param('fname')) || 
	   (param('reserveAnotherGene') && !param('continue'))) {
	$self->printEntryPage;
    }
    elsif (param('lname') && param('fname') && param('email') && param('institution')) {
	my $emails = param('email');
	$emails =~ s/^ *//;
	$emails =~ s/ *$//;
        $emails =~ s/[,;\t]+/ /g;
	my @emailList = split(' ', $emails);
	foreach my $email (@emailList) {
	    if ($email) {
		my ($username, $hostname) = split('@', $email);
		my $hostvalid;
		if ( $username ne "" && $hostname ne "") {
		    $hostvalid = $self->hostcheck($hostname);
		}
		if ( !$hostvalid ) {
		    $self->err_report("Your email address '$email' is incomplete or does not contain a valid hostname. <p>Please return to the form and check that your email address is correct.");
		    exit;
	        }
	    }
	}
	$self->printVerificationPage;
    }
    elsif (param('reserveAnotherGene')) {
	$self->printVerificationPage;
    }
    else {
	$self->err_report("You must enter your last and first name(s), e-mail address and institution.<p>Please click on the BACK button to return to the form.");
	exit;
    }
}

######################################################################
sub printEntryPage {
######################################################################
    	my ($self) = @_;
	if (!param('registerType')) {
	    if (!$self->colleagueNo) {
		$self->{'_title'} = "$self->{'_database'} New Colleague Entry Form";
	    }
	    else {
		$self->{'_title'} = "$self->{'_database'} Colleague Update Form";
	    }
	}
	else {
	    $self->{'_title'} = "$self->{'_database'} Gene Registry Form";
	}	
	&printStartPage($self->database, $self->title, $self->help);
	$self->printTopText;
	print start_form(-action=>"$url",
    		         -method=>'post');

	my $collObject;
	if ($self->colleagueNo) {
	    if ($dbh) {
                $collObject = 
			 Colleague->new(dbh=>$dbh,
					colleague_no=>$self->colleagueNo);
	    }
	    else {
		print "You should pass database name or database handle to this object";
		return;
	    }
	    my $fullname;
	    if (!$collObject->suffix) {
		$fullname = $collObject->first_name ." ". 
		    $collObject->last_name;
	    }
	    elsif ($collObject->suffix =~ /\./) {
		$fullname = $collObject->first_name." ".
		    $collObject->last_name.
		    ", ".$collObject->suffix;
	    }
	    else {
		$fullname = $collObject->first_name." ".
		    $collObject->last_name.
		    " ".$collObject->suffix;
	    }
	    if (param('registerType')) {
		$self->geneRegistryForm;
		print hr;
	    }
	    print h3("Updating Colleague Information for ".$fullname);
	    print b(a({-href=>$configUrl->dictyBaseCGIRoot."$dblink/colleague/colleagueSearch?id=".$self->colleagueNo."&win=1",
		    -target=>"infowin",
		    -onClick=>"open_win()"},
		    "View"))." current information", p;
	    print hidden(-name=>'id',
                         -value=>$self->colleagueNo);
	}
	elsif (param('registerType')) {
	    $self->geneRegistryForm;
	    print hr;
	}
	print hidden(-name=>'continue',
		     -value=>'1');
	if (param('reserveAnotherGene')) {
	    print hidden(-name=>'lname',
			 -value=>param('lname')),
	          hidden(-name=>'fname',
			 -value=>param('fname')),
	          hidden(-name=>'email',
			 -value=>param('email')),
	          hidden(-name=>'reserveAnotherGene',
			 -value=>'1');
        }
	else {

	    print $self->subtitle("Your Address and Contact Information"),p;
	    $self->printContactSection($collObject);
	    print $self->subtitle("Your Group/Lab Members and Associates");
	    print $self->associate4pi($collObject);
	    print font({-color=>'red',
			-size=>'+4'}, b("OR"));
	    print $self->pi($collObject);
	    print $self->subtitle("Your Collaborators and Associates");
	    print $self->associate($collObject),p;
	    print $self->subtitle("Your Research Interests");
	    print $self->interest($collObject);
	    print $self->researchTopics($collObject);
	    print $self->keyword($collObject), p;
	    if (param('registerType')) {
		print $self->subtitle("Colleague Entry Comments");
	    }
	    else {
		print $self->subtitle("Your Comments");
	    }
	    print $self->comment($collObject);
	    print $self->curatorOnly($collObject);

	}

	$self->submitReset("Continue"), p;
	print p, b(" Please note: this information will not be available until an dictyBase curator processes your submission."), br;
	print end_form;
	&printEndPage;
}

########################################################################
sub printVerificationPage {
########################################################################
        my ($self) = @_;
	if (!param('registerType')) {
	    if ($self->colleagueNo) {
		$self->{'_title'}
			= "$self->{'_database'} Colleague Update Verification";
	    }
	    else {
		$self->{'_title'} 
			= "$self->{'_database'} Colleague New Entry Verification";
	    }
	}
	else {
	    $self->{'_title'} = "$self->{'_database'} Gene Registry Verification";
	}
	&printStartPage($self->database, $self->title, $self->help);
	print h3("Please verify your entry, then click the \"Submit\" button"), p;

	print start_form(-action=>"$url",
    		         -method=>'post');
	print hidden(-name=>'pid',
		     -value=>$self->pid);
       
        my $collObject;
	if ($self->colleagueNo) {
	    if ($self->{'_database'}) {
		$collObject = Colleague->new(dbh=>$dbh,
				     colleague_no=>$self->colleagueNo);
	    }
	    print hidden(-name=>'id',
                         -value=>$self->colleagueNo),
	          hidden(-name=>'finalUpdate',
			 -value=>'1');
	}
	else {
	    print hidden(-name=>'finalNewEntry',
			 -value=>'1');
	}
	print hidden(-name=>'registerType',
		     -value=>param('registerType')),
	      hidden(-name=>'reserveAnotherGene',
		     -value=>param('reserveAnotherGene'));
	if (param('back')) {
	   $self->readInfo;
	   $self->displayVerificationPage;
	}
	elsif (!param('pid')) {
	    $self->writeInfo;
	    $self->displayVerificationPage;
	}
	else {
	    if (param('editType') =~ /^contact/i) {
		    $self->writeContactInfo;
	    }
	    elsif (param('editType') =~ /^interest/i) {
		    $self->writeInterestInfo;
	    }
	    elsif (param('editType') =~ /^keyword/i) {
		    $self->writeKeywordInfo;
	    }
	    elsif (param('editType') =~ /^comment/i) {
		    $self->writeCommentInfo;
	    }
	    elsif (param('editType') =~ /^GeneInfo/i) {
		    $self->writeGeneInfo;
	    }
	    elsif (param('editType') =~ /^ReferenceInfo/i) {
		    $self->writeGeneReferenceInfo;
	    }
	    else {
		    $self->writeGeneCommentInfo;
	    }
	    $self->readInfo;
	    $self->displayVerificationPage;
        }
	print end_form;
	&printEndPage;
}

########################################################################
sub readInfo {
########################################################################
    my ($self) = @_;
    $self->readContactInfo;
    if (param('finalUpdate') || param('finalNewEntry')){
	$self->setAssociateInfo;
    }
    else {
	$self->readAssociateInfo;
    }
    $self->readInterestInfo;
    $self->readKeywordInfo;
    $self->readCommentInfo;
    if (param('registerType')) {
	$self->readGeneInfo;
	$self->readGeneReferenceInfo;
	$self->readGeneCommentInfo;
    }
}

########################################################################
sub writeInfo {
########################################################################
    my ($self) = @_;
    $self->writeContactInfo;
    $self->writeAssociateInfo;
    $self->writeInterestInfo;
    $self->writeKeywordInfo;
    $self->writeCommentInfo;
    if (param('registerType')) {
	$self->writeGeneInfo;
	$self->writeGeneReferenceInfo;
	$self->writeGeneCommentInfo;
    }
}

########################################################################
sub printContactSection {
########################################################################
## KD: adding dictyBasecontact
    my ($self, $collObject) = @_;
    print $self->dictyBasecontact($collObject);
    print table({-border=>'0',
		 -cellpadding=>'2',
		 -cellspacing=>'3',
		 -width=>'650'},
		$self->lastName($collObject).
		$self->firstName($collObject).
		$self->suffix($collObject).
		$self->otherName($collObject).
		$self->email($collObject).
		$self->jobTitle($collObject).
		$self->profession($collObject).
		$self->institution($collObject).
		$self->address($collObject).
		$self->city($collObject).
		$self->state($collObject).
		$self->region($collObject).
		$self->country($collObject).
		$self->zipCode($collObject)
    );
    print $self->phone($collObject);
    print $self->webPage($collObject), p;
}

########################################################################
sub editForm {
########################################################################
    my ($self) = @_;
    if (!param('registerType')) {
	$self->{'_title'} = "Edit Colleague Information";
    }
    else {
	$self->{'_title'} 
		= "Edit Gene Registry and Colleague Information";
    }
    &printStartPage($self->database, $self->title, $self->help); 
    print start_form(-action=>"$url",
    		     -method=>'post');
    print hidden(-name=>'SaveDisplay',
    		 -value=>'1'),
          hidden(-name=>'pid',
		 -value=>$self->pid),
          hidden(-name=>'editType',
		 -value=>param('editType')),
	  hidden(-name=>'registerType',
		 -value=>param('registerType')),
          hidden(-name=>'reserveAnotherGene',
		 -value=>param('reserveAnotherGene'));
    if ($self->colleagueNo) {
	print hidden(-name=>'id',
		     -value=>$self->colleagueNo);
    }
    if (param('editType') =~ /GeneInfo/i) {
	$self->readGeneInfo;
	print $self->subtitle("Information about the Gene");
	$self->printGeneInfoSection;
    }
    elsif (param('editType') =~ /ReferenceInfo/i) {
	$self->readGeneReferenceInfo;
	print $self->subtitle("Reference");
	$self->printGeneReferenceInfoSection;
    }
    elsif (param('editType') =~ /GeneCommentInfo/i) {
	$self->readGeneCommentInfo;
	print $self->subtitle("Gene Name Comments"),p;
	print $self->registryComments, p;
    }
    elsif (param('editType') =~ /contact/i) {
	$self->readContactInfo;
	print $self->subtitle("Your Address and Contact Information");
	$self->printContactSection;
    }
    elsif (param('editType') =~ /interest/i) {
	$self->readInterestInfo;
	print $self->subtitle("Your Research Interests");
	print $self->interest, p;
    }
    elsif (param('editType') =~ /keyword/i) {
	$self->readKeywordInfo;
	print $self->subtitle("Research Topics");
	print $self->researchTopics, p;
	print a({-name=>"Keywords"});
	print $self->subtitle("Keywords");
	print $self->keyword, p;
    }
    else { ### comment section
	$self->readCommentInfo;
	print $self->subtitle("Your Comments");
	print $self->comment, p;
    }
    $self->submitReset("Continue");
    print end_form;
    &printEndPage;
    exit;
}


########################################################################
sub displayVerificationPage {
########################################################################
    my ($self) = @_;
    if (param('registerType')) {
	$self->displayGeneInfo;
	$self->displayGeneReferenceInfo;
	$self->displayGeneCommentInfo;
    }
    if (!param('reserveAnotherGene')) {
	$self->displayContactInfo;
	$self->displayAssociateInfo;
	$self->displayInterestKeywordInfo;
	$self->displayCommentInfo;
    }
    $self->submitReset;
    print p, b(" Please note: this information will not be available until an dictyBase curator processes your submission."), br;
}


########################################################################
sub subtitle {
########################################################################
    my($self, $subtitle) = @_;
    return table({-border=>'0',
		  -cellpadding=>'4',
		  -cellspacing=>'3',
		  -width=>'650'},
		 Tr(td({-width=>'100%',
			-bgcolor=>'#a4abc2'},
		       font({-size=>'+2'},
			    b($subtitle)))));
    
}


########################################################################
sub submitReset {
########################################################################
    my ($self, $type) = @_;
    if (!$type) { $type = "Submit"; } 
    print p,
	   table({-border=>'0',
		  -cellpadding=>'0',
		  -cellspacing=>'0',
		  -width=>'650',
		  -bgcolor=>'#a4abc2'},
		 Tr(td({-width=>'15%'},
		       font({-size=>'+2'},
			    submit(-name=>'submit',
				   -value=>"$type"))).
		    td({-width=>'10%'},
		       font({-size=>'+2'},
			    submit(-name=>'reset',
				   -value=>'Reset'))).
		    td({-width=>'75%'},
		       br)));
}

#######################################################################
sub printTopText {
#######################################################################
    my ($self) = @_;
    if (param('reserveAnotherGene')) {
	print "Please fill in all the information you wish to make PUBLICLY AVAILABLE via dictyBase. If your information is already in the database you only need to include gene name and the information that needs to be changed or updated. There is no need to enter data about your gene that is already in the database. Press the submit button at the bottom of the form to send the information to the dictyBase curators.",p;
    }
    elsif (!param('registerType')) {
	print "This form is for you to send information about yourself to dictyBase. Please note that your name and e-mail address are required to complete this form. All other fields (boxes) are optional. Please submit as much information as you would like to be made publicly available to other dictyBase users. This information will not be available until an dictyBase curator processes your submission.", p;
    }
    else {
	print "Please fill in all the information you wish to make PUBLICLY AVAILABLE via dictyBase. Note that an e-mail address and institution is required to complete this form. If your information is already in the database you only need to include your name, e-mail address, gene name and the information that needs to be changed or updated. There is no need to enter data about your gene that is already in the database. Press the submit button at the bottom of the form to send the information to the dictyBase curators.",p;
    }
    print center("Once you have ".b("finished the form").", press the ".b("continue")." button to send it.");
}
########################################################################
sub dictyBasecontact {
########################################################################
    ## added by KD
    my ($self, $collObject) = @_;
    my $return = "Do you want to be a contact for dictyBase (receive quarterly newsletters)?: ";
    my $isContact;
    if ($collObject) { $isContact = $collObject->is_subscribed; }
    else { $isContact = $self->{'_dictyBasecontact'}; }
    if (!$isContact) {$isContact = 'N';}
    $return .= radio_group(-name=>"dictyBasecontact",
			 -values=>['Y','N'],
			 -default=>$isContact).p."\n";	

    return $return;
}

########################################################################
sub lastName {
########################################################################
    my ($self, $collObject) = @_;
    my $lname;
    if ($collObject) { $lname = $collObject->last_name; }
    else { $lname = $self->{'_lname'}; }
    return Tr(td({-width=>'140',
		  -bgcolor=>'#ACBDCC'},
		 "Last Name ".
		 font({-color=>'red',
		       -size=>'2'},
		      b("[required]"))).
	      td(textfield(-name=>'lname', 
			   -value=>"$lname", 
			   -size=>'20')).
	      td("(e.g., Jones, Smyth)"));
}

########################################################################
sub firstName {
########################################################################
    my ($self, $collObject) = @_;
    my $fname;
    if ($collObject) { $fname = $collObject->first_name; }
    else { $fname = $self->{'_fname'}; }
    return Tr(td({-width=>'140',
		  -bgcolor=>'#ACBDCC'},
		 "First Name ".
		 font({-color=>'red',
		       -size=>'2'},
		      b("[required]"))).
	      td(textfield(-name=>'fname', 
			   -value=>"$fname", 
			   -size=>'20')).
	      td("(e.g., John, C. David, Linda M.)"));
}

########################################################################
sub suffix {
########################################################################
    my ($self, $collObject) = @_;
    my $suffix;
    if ($collObject) { $suffix = $collObject->suffix; }
    else { $suffix = $self->{'_suffix'}; }
    my @suffixList = ('', 'Sr.', 'Jr.', 'II', 'III', 'IV');
    return Tr(td({-width=>'140',
		  -bgcolor=>'#ACBDCC'},
		 "Suffix ").
	      td(popup_menu(-name=>'suffix', 
			    -"value"=>\@suffixList,
			    -default=>"$suffix")));
}

########################################################################
sub otherName {
########################################################################
    my ($self, $collObject) = @_;
    my $oname;
    if ($collObject) { $oname = $collObject->other_name; }
    else { $oname = $self->{'_oname'}; }
    return Tr(td({-width=>'140',
		  -bgcolor=>'#ACBDCC'},
		 "Other Name ").
	      td(textfield(-name=>'oname', 
			   -value=>"$oname", 
			   -size=>'20')).
	      td("(e.g., your maiden name)"));
}

########################################################################
sub email {
########################################################################
    my ($self, $collObject) = @_;
    my $emails;
    if ($collObject) { 
	my $emailRef = $collObject->emailRef;
	foreach my $rowRef (@$emailRef) {
	    my ($email) = @$rowRef;
	    $emails .= ", " . $email;
	}
	$emails =~ s/^\, //;
    }
    else {
	$emails = $self->{'_email'};
    }
    return Tr(td({-width=>'140',
		  -bgcolor=>'#ACBDCC'},
		 "E-mail ".
		 font({-color=>'red',
		       -size=>'2'},
		      b("[required]"))).
	      td(textfield(-name=>'email', 
			   -value=>"$emails", 
			   -size=>'30')).
	      td("(if more than one, separate by space)"));
}

#######################################################################
sub jobTitle {
#######################################################################
    my ($self, $collObject) = @_;
    my $jobtitle;
    if ($collObject) { $jobtitle = $collObject->job_title; }
    else { $jobtitle = $self->{'_jobtitle'}; }
    return Tr(td({-width=>'140',
		  -bgcolor=>'#ACBDCC'},
		 " Job Title "
		).
	      td(textfield(-name=>'jobtitle', 
			   -value=>"$jobtitle", 
			   -size=>'30')).
	      td("(e.g., Research Fellow, Post-Doc)"));
	
}

#######################################################################
sub profession {
#######################################################################
    my ($self, $collObject) = @_;
    my $profession;
    if ($collObject) { $profession = $collObject->profession; }
    else { $profession = $self->{'_profession'}; }
    return Tr(td({-width=>'140',
		  -bgcolor=>'#ACBDCC'},
		 " Profession ").
	      td(textfield(-name=>'profession', 
			   -value=>"$profession", 
			   -size=>'30')).
	      td("(e.g., Dictyostelium Molecular Biologist)"));
}

#######################################################################
sub institution {
#######################################################################
    my ($self, $collObject) = @_;
    my $institution;
    if ($collObject) { $institution = $collObject->institution; }
    else { $institution = $self->{'_institution'}; }
    return Tr(td({-width=>'140',
		  -bgcolor=>'#ACBDCC'},
		 " Organization ".
		 font({-color=>'red',
		       -size=>'2'},
		      b("[required]"))).
	      td(textfield(-name=>'institution', 
			   -value=>"$institution", 
			   -size=>'30')).
	      td("(e.g., Stanford University)"));
}

#######################################################################
sub address {
#######################################################################
    my ($self, $collObject) = @_;
    my ($address1, $address2, $address3, $address4, $address5); 
    my @addr;
    if ($collObject) {
	$addr[1] = $collObject->address1;
	$addr[2] = $collObject->address2;
	$addr[3] = $collObject->address3;
	$addr[4] = $collObject->address4;
	$addr[5] = $collObject->address5;
    }
    else {
	$addr[1] = $self->{'_address1'};
	$addr[2] = $self->{'_address2'};
	$addr[3] = $self->{'_address3'};
	$addr[4] = $self->{'_address4'};
	$addr[5] = $self->{'_address5'};
    }
    my $address;
    for (my $i = 1; $i <= 5; $i++) {
	$address .= Tr(td({-width=>'140',
			   -bgcolor=>'#ACBDCC'},
			  " Address ").
		       td(textfield(-name=>"addr$i", 
				    -value=>"$addr[$i]", 
				    -size=>'30')).td());
    }
    return $address;
	      
}

#######################################################################
sub city {
#######################################################################
    my ($self, $collObject) = @_;
    my $city;
    if ($collObject) { $city = $collObject->city; }
    else { $city = $self->{'_city'}; }
    return Tr(td({-width=>'140',
		  -bgcolor=>'#ACBDCC'},
		 " City ").
	      td(textfield(-name=>'city', 
			   -value=>"$city", 
			   -size=>'30')).td());
}
#######################################################################
sub state {
#######################################################################
    my ($self, $collObject) = @_;
   
    my @usaList;
    my @canadaList;
    push(@usaList, "USA State (none)");
    push(@canadaList, "Canadian Province (none)");
    my $stateAbbrevArrayRef = Colleague->GetStateAbbrevArrayRef(dbh=>$dbh);
    foreach my $rowRef (@$stateAbbrevArrayRef) {
	my ($abbrev, $country) = @$rowRef;
	if ($country eq "USA") {
	    push(@usaList, $abbrev); 
	}
	else {
	    push(@canadaList, $abbrev); 
	}    
    }
    my ($state, $country);
    if ($collObject) {
	$state = $collObject->state;
	$country = $collObject->country;
    }
    else {
	$state = $self->{'_state'};
	$country = $self->{'_country'};
    }
    my ($USAstate, $canadaPro);
    if ($country =~ /usa/i) {
	$USAstate = $state;
    }
    else {
	$canadaPro = $state;
    }
    return Tr(td({-width=>'140',
		  -bgcolor=>'#ACBDCC'},
		 " State/Provinces ").
	      td(popup_menu(-name=>'USAstate', 
			    -value=>\@usaList, 
			    -default=>"$USAstate")." OR").
	      td(popup_menu(-name=>'CanadaPro', 
			    -value=>\@canadaList, 
			    -default=>"$canadaPro")));


}

########################################################################
sub region {
########################################################################
    my ($self, $collObject) = @_;
    my $region;
    if ($collObject) { $region = $collObject->region; }
    else { $region = $self->{'_region'}; }
    return Tr(td({-width=>'140',
		  -bgcolor=>'#ACBDCC'},
		 " Region ").
	      td(textfield(-name=>'region', 
			   -value=>"$region", 
			   -size=>'30')).td());

}

########################################################################
sub country {
########################################################################
    my ($self, $collObject) = @_;
    my $country;
    if ($collObject) { $country = $collObject->country; }
    else { $country = $self->{'_country'}; }
    return Tr(td({-width=>'140',
		  -bgcolor=>'#ACBDCC'},
		 " Country ").
	      td(textfield(-name=>'country', 
			   -value=>"$country", 
			   -size=>'30')).td());

}

########################################################################
sub zipCode {
########################################################################
    my ($self, $collObject) = @_;
    my $zipcode;
    if ($collObject) { $zipcode = $collObject->postal_code; }
    else { $zipcode = $self->{'_zip_code'}; }
    return Tr(td({-width=>'140',
		  -bgcolor=>'#ACBDCC'},
		 " Postal Code/Zip Code ").
	      td(textfield(-name=>'zip_code', 
			   -value=>"$zipcode", 
			   -size=>'30')).td());
}

########################################################################
sub phone {
########################################################################
    my ($self, $collObject) = @_;
    my @phoneTypeNum;
    my $return;
    if ($collObject  || $self->{'_phone1'}) {
	my $phoneRef;
	if ($collObject) { $phoneRef = $collObject->phoneRef;}
	foreach my $order ("Lab Phone", "Office Phone", "Department Phone", 
		       "Phone", "Lab Fax", "Office Fax", "Department Fax", 
			   "Fax", "Mobile", "Pager", "Telex") {
	    if ($collObject) {
		foreach my $rowRef (@$phoneRef) {
		    my ($phoneNum, $phoneType, $phoneLoc) = @$rowRef;
		    if ($phoneLoc !~ /unspecified/i) {
			$phoneType = $phoneLoc ." ". $phoneType;
		    }
		    if ($phoneType =~ /^$order/i) {
			push(@phoneTypeNum, "${phoneType}=$phoneNum");
		    }
		}
	    } 
	    else {
		for (my $i = 1; $i <= 5; $i++) {
		    my $phoneNum = $self->{"_phone$i"};
		    if (!$phoneNum) { next; }
		    my $phoneType = $self->{"_phone_type$i"};
		    if ($phoneType =~ /^$order/i) {
			push(@phoneTypeNum, "${phoneType}=$phoneNum");
		    }
		}
	    }
	}
	$return = table({-border=>'0',
			 -cellpadding=>'4'},
			Tr(td({ # -height=>'40',
			       -bgcolor=>'#ACBDCC'},
			      " Phone/Fax/Telex Numbers").
			   td("Please specify the type of phone and/or fax where needed in your current entry and when adding new entries")));
    }
    else {
	$return = table({-border=>'0',
			 -cellpadding=>'4'},
			Tr(td({-height=>'40',
			       -bgcolor=>'#ACBDCC'},
			      " Phone/Fax/Telex Numbers")));
    }
    my @phoneTypeList = ("Please specify", "Lab Phone", "Lab Fax", 
		      "Office Phone", "Office Fax", "Department Phone", 
		      "Department Fax", "Phone", "Fax", "Mobile", "Pager", 
		      "Telex");
    my $phoneList;
    for (my $i = 1; $i <= 5; $i++) {
	my ($phoneType, $phoneNum) = split(/=/, $phoneTypeNum[$i-1]);
        $phoneList .= Tr(td({-width=>'140'}, br).
			 td(textfield(-name=>"phone$i",
				      -value=>"$phoneNum",
				      -size=>'30')).
			 td(popup_menu(-name=>"phone_type$i",
				       -value=>\@phoneTypeList,
				       -default=>"$phoneType")));
    }
    $return .= table($phoneList);
}

########################################################################
sub webPage {
########################################################################
    my ($self, $collObject) = @_;
    my $urls;
    my $urlTypes;

    my $webPageString = "";

    if ($collObject) {
	my $urlRef = $collObject->urlRef;
	foreach my $rowRef (@$urlRef) {
	    my ($url, $wwwTitle, $urlType) = @$rowRef;
	    $urls .= ", ".$url;
	    $urlTypes .= ", ".$urlType;
	}
	$urls =~ s/^\, //;
	$urlTypes =~ s/^\, //;
    }
    else { 
      $urls = $self->{'_urls'}; 
      $urlTypes = $self->{'_url_type'};
    }

    my @urlTypeList = ("Please specify", "Lab", "Research summary", "Other");

    my $urlTypeList = "";

    foreach my $urlType (@urlTypeList) {
      $urlTypeList .= " ".$urlType;
    }

    my $help = div("Example of a 'Lab': ",
		a({-href=>'http:///usr/local/dicty/www_dictybase/db/lib/group/botlab/'},
		  "http:///usr/local/dicty/www_dictybase/db/lib/group/botlab/"), br,
		"Example of a 'Research Summary': ",
		a({-href=>'http://www.scs.uiuc.edu/~bioch/orlean.html'},
		  "http://www.scs.uiuc.edu/~bioch/orlean.html"), br,
		"Example of 'Other': ",
		a({-href=>'http:///usr/local/dicty/www_dictybase/db/lib/'},
		  "http:///usr/local/dicty/www_dictybase/db/lib/")
	       );

    my @urls = split(/, /, $urls);
    my @urlTypes = split(/, /, $urlTypes);

    $webPageString .= table({-border=>'0',
		     -cellpadding=>'4'},
		    Tr(td({
			   -width=>'140',
			   -bgcolor=>'#ACBDCC'},
			  " Web Pages ").
		       td("Please specify URLs and types of web pages"
			  , br, $help
			 )));

    my $webPageCells = "";

    for (my $counter = 0; $counter < $numUrls; $counter++) {
      my $url;
      my $urlType;

      if (defined $urls[$counter]) {
	$url = $urls[$counter];
	$urlType = $urlTypes[$counter];

	if ($urlTypeList !~ /$urlType/) {
	  $urlType = "Other";
	}
      }
      else {
	$url = $self->{"_url$counter"};
	$urlType = $self->{"_url_type$counter"};
      }

      my $currentRow = (td({-width=>'140'},
			   "&nbsp;").
			td({-width=>'30'},
			   textfield(-name=>"url$counter",
				     -value=>"$url",
				     -size=>'30')).
			td({-align=>'LEFT'},
			   popup_menu(-name=>"url_type$counter",
				      -value=>\@urlTypeList,
				      -default=>"$urlType"))
		       );

      $webPageCells .= Tr($currentRow);
    }
    $webPageString .= table(table({-border=>0}, $webPageCells));

    return $webPageString;

}

########################################################################
sub associate4pi {
########################################################################
    my ($self, $collObject) = @_;
    my @associate;
    my $return;
    if ($collObject) {
	my $associate4piRef = $collObject->associate4piRef; 
	foreach my $rowRef (@$associate4piRef) { 
	    my($colleagueNo, $lname, $fname, $suffix) = @$rowRef;
	    push(@associate, $lname .", ".$fname);
	}
    }

    my $row = Tr(td({-valign=>'top',
	             -rowspan=>'2',
		     -width=>'140',
		     -bgcolor=>'#ACBDCC'},
		    br.br.br.br." Enter the names of your students, post-docs, technicians ").
		 td(font({-size=>'+2'}, u("Option 1").": Complete if you ".u("are")." a Supervisor, Advisor, Lab Head, ".br."Group Leader, or P.I.").br.
	font({-color=>'red'}, i("NOTE: You ".b("must")." enter at least one name here to appear on the ".
				a({-onclick=>"open_win()",
				   -href=>$configUrl->dictyBaseCGIRoot."$dblink/colleague/DictyosteliumLabs/DictyosteliumLabs.pl",
				   -target=>'infowin'}, 
				  "dictyBase Dictyostelium Labs page").".".p))));

    my $box = Tr(th({-align=>'left'}, "Last name, First name").
		 th({-align=>'left'}, "Last name, First name"));
    for (my $i = 1; $i <= 10; $i += 2) {
	my $j = $i+1;
	$box .= Tr(td(textfield(-name=>"associate$i",
				   -value=>"$associate[$i-1]",
				   -size=>'30')).
		      td(textfield(-name=>"associate$j",
				   -value=>"$associate[$j-1]",
				   -size=>'30')));
    }
    $row .= Tr(td(table($box)));
    my $return = p.table($row);

    # if this is not a new colleague, we want to check to see if this 
    #   entry has '~Generic ~Associate' as one of its lab members.  If yes,
    #   then this record is a PIs without any students, post-docs or 
    #   technicians, and we need to preserve this information.
    if ($self->colleagueNo && $collObject->isPIWithoutAssocs) {
	$return .= input({-name=>"pi",
			  -value=>"true",
			  -type=>"hidden"});
    }

    return $return;

}

########################################################################
sub pi {
########################################################################
    my ($self, $collObject) = @_;
    my @pi;
    if ($collObject) {
	my $piRef = $collObject->piRef; 
	foreach my $rowRef (@$piRef) { 
	    my($colleagueNo, $lname, $fname, $suffix) = @$rowRef;
	    push(@pi, ${lname}.", ".$fname);
	}
    }

    my $row = Tr(td({-valign=>'top',
	             -rowspan=>'2',
		     -width=>'140',
		     -bgcolor=>'#ACBDCC'},
		    br.br." Enter the name(s) of your Supervisor, Advisor, Lab Head, Group Leader, P.I. ").
		 td(font({-size=>'+2'}, u("Option 2").": Complete if you ".u("have")." a Supervisor, Advisor, Lab Head, ".br."Group Leader, or P.I.".p)));

    
    $row .= Tr(td(table(Tr(th("Last name, First name").
			   th("Last name, First name")).
			Tr(td(textfield(-name=>'PILIST0',
					-value=>"$pi[0]",
					-size=>'30')).
			   td(textfield(-name=>'PILIST1',
					-value=>"$pi[1]",
					-size=>'30'))))));

    return br.table($row).p;
}

########################################################################
sub associate {
########################################################################
    my ($self, $collObject) = @_;
    my @associate;
    if ($collObject) {
	my $associateRef = $collObject->associateRef; 
	foreach my $rowRef (@$associateRef) { 
	    my($colleagueNo, $lname, $fname, $suffix) = @$rowRef;
	    push(@associate, ${lname}.", ".$fname);
	}
    }

    my $row = td({-valign=>'top',
		  -width=>'140',
		  -bgcolor=>'#ACBDCC'},
		 br.br.br.br." Enter the names of your collaborators or associates (not listed above): ");

    my $box = Tr(th({-align=>'left'}, "Last name, First name").
		 th({-align=>'left'}, "Last name, First name")); 
    for (my $k = 0; $k < 10; $k += 2)  {
	my $i = $k +11;
	my $j = $i+1;
	$box .= Tr(td(textfield(-name=>"associate$i",
				   -value=>"$associate[$k]",
				   -size=>'30')).
		      td(textfield(-name=>"associate$j",
				   -value=>"$associate[$k+1]",
				   -size=>'30')));
    }
    $row .= td((table($box)));
    return br.table(Tr($row)).p;

}

########################################################################
sub interest {
########################################################################
    my ($self, $collObject) = @_;
    my $interest;
    if ($collObject) {
	$interest = $collObject->interest; 
    }
    else { $interest = $self->{'_interests'}; }
    print "Please enter a general description of your scientific research interests.".br.font({-color=>'red'}, "Note").": Please do not enter more than 250 words. Thanks!".br;
    return textarea(-name=>'interests',
		    -value=>"$interest",
		    -rows=>4,
		    -columns=>60);


}

########################################################################
sub keyword {
########################################################################
    my ($self, $collObject) = @_;
    my $return = table({-border=>'0',
			-cellpadding=>'4',
			-cellspacing=>'3',
			-width=>'650'},
		       Tr(td({-width=>'100%',
			      -bgcolor=>'#a4abc2'},
			     font({-size=>'+1'},
				  b("Keywords")))));
    my @keyword;
    if ($collObject) {
	my $kwArrayRef = $collObject->keywordRef;
	foreach my $rowRef (@$kwArrayRef) {
	    my ($kw) = @$rowRef;
	    push(@keyword, $kw);
	}
    }
    else {
	for (my $i = 1; $i <= 10; $i++) {
	    if ($self->{"_keyword$i"}) {
		push(@keyword, $self->{"_keyword$i"});
	    }
	}
    }
    print p,"A list of keywords can also be associated with your Colleague entry.".br."For example: actin, transposon, protein translocation".br;
    my $return;
    for(my $i = 1; $i <= 5; $i++) {
	my $j = $i + 5;
	$return .= Tr(td({-align=>'center'},
			 textfield(-name=>"keyword$i",
				   -value=>"$keyword[$i-1]",
				   -size=>'30')).
		      td({-align=>'center'},
			 textfield(-name=>"keyword$j",
				   -value=>"$keyword[$j-1]",
				   -size=>'30')));
    }
    return table({-border=>'2'},
		 $return);

}

########################################################################
sub researchTopics {
########################################################################
    my ($self, $collObject) = @_;
    my $return = table({-border=>'0',
			-cellpadding=>'4',
			-cellspacing=>'3',
			-width=>'650'},
		       Tr(td({-width=>'100%',
			      -bgcolor=>'#a4abc2'},
			     font({-size=>'+1'},
				  b("ResearchTopics")))));
    my $collResearchTopics;
    if ($collObject) {
	my $rtArrayRef = $collObject->researchTopicsRef;
	foreach my $rowRef (@$rtArrayRef) {
	    my ($rt) = @$rowRef;
	    $collResearchTopics .= "\t" . $rt;
	}
	$collResearchTopics .= "\t";
    }
    else {
	$collResearchTopics = $self->{'_researchTopics'};
    }
    print p,"Please select any and all areas of research relevant to your expertise.", br;
    my $return = "\n";
    foreach my $researchTopic (split(/\t/, &getCDKeywords($dbh))) {
	if ($collResearchTopics =~ /\t$researchTopic\t/) {
	    $return .= checkbox(-name=>"$researchTopic",
				-label=>"$researchTopic",
				-checked=>"checked").br."\n";
	}
	else {
	    $return .= checkbox(-name=>"$researchTopic",
				-label=>"$researchTopic").br."\n";
	}
    }
    return table({-border=>'2'},
		Tr(td{-align=>'left'}, $return));
}

########################################################################
sub comment {
########################################################################
    my ($self, $collObject) = @_;
    my $comment;
    if ($collObject) {
	$comment = $collObject->comment;
    }
    else { $comment = $self->{'_Comments'}; }
    print "Anything else we did not ask about but that you wish to have included in the database.", br;   
    return textarea(-name=>'Comments',
		    -value=>"$comment",
		    -rows=>4,
		    -columns=>60);
}

###########################################################################
sub curatorOnly {
###########################################################################
    my ($self, $collObject) = @_;

    my $locusList = "";

    if ($collObject) {
	my $lociRef = $collObject->locusRef();
	my @associatedLoci = @$lociRef;

	foreach my $locusRow (@associatedLoci) {
	    my $locusNo  = $locusRow->[0]; 
	    $locusList .= "|$locusNo";
	}
	$locusList =~ s/^\|//g;

	print hidden(-name=>'associated_loci',
		     -value=>$locusList
		    );
    }

    return;

}



#######################################################################
sub geneRegistryForm {
#######################################################################
    my ($self) = @_;
    $self->printGeneOrfLink;
    print hidden(-name=>'registerType',
		 -value=>param('registerType'));
    print $self->subtitle("Information about the Gene");
    $self->printGeneInfoSection;
   
    print $self->subtitle("Reference");
    $self->printGeneReferenceInfoSection;

    print $self->subtitle("Gene Name Comments"),p;
    print $self->registryComments, p;
}

##########################################################################
sub printGeneOrfLink {
##########################################################################
    my ($self) = @_;
    if (!param('geneOrf')) { return; }
    my @geneOrfList = split(/\t/, param('geneOrf'));
    foreach my $geneOrf (@geneOrfList) {
	    my ($gene, $orf) = split(/\:\:/, $geneOrf);
	    if (uc($gene) eq uc(param('gene'))) {
		print b(a({-href=>$configUrl->dictyBaseCGIRoot."gene_page.pl?gene_name=$gene",
			   -target=>"infowin",
			   -onClick=>"open_win()"},
			  "View"))." current gene information", br; 
	    }
	    if (uc($orf) eq uc(param('orf'))) {
		print b(a({-href=>$configUrl->dictyBaseCGIRoot."gene_page.pl?gene_name=$orf",
			   -target=>"infowin",
			   -onClick=>"open_win()"},
			  "View"))." current ORF information", br; 
	    }
    }
    print p;
}

#########################################################################
sub printGeneInfoSection {
#########################################################################
    my ($self) = @_;

    my $locusObj;
    if (param('registerType') =~ /update/i && param('gene')) {
	$locusObj = Locus->new(dbh=>$dbh,
			       locus_name=>param('gene'));
	$self->{'_locus_no'} = $locusObj->locus_no;
    }
    print table({-border=>'0',
		 -cellpadding=>'4',
		 -cellspacing=>'3',
		 -width=>'650'},
		$self->geneName($locusObj).
		$self->geneDesc($locusObj).
		$self->orfName($locusObj).
		$self->otherGeneName($locusObj).
		$self->geneProduct($locusObj).
		$self->nullPhenotype($locusObj).
		$self->otherPhenotype($locusObj)),p;
}

########################################################################
sub printGeneReferenceInfoSection {
########################################################################
    my ($self) = @_;
    print "<p>Please provide a reference for the gene name. When entering an author name, spell it as it would appear in a publication, using initials for first and middle names (e.g. Fields, W. C.). If there are more than 12 authors, enter et al. after the first author (e.g., Vader, D., et al.).<p>";

#    if (param('registerType') =~ /update/i && $self->{'_locus_no'}) {
#       
#	my $refNos = Reflink->GetRefNoBYlocusNo(dbh=>$dbh,
#				  locus_no=>$self->{'_locus_no'});
#	if (!$refNos) {
#	    $refNos = Locus_gene_info->GetRefNoBYlocusNo(dbh=>$dbh,
#				  locus_no=>$self->{'_locus_no'});
#	}
#	if ($refNos) {
#	  
#	    my $refNo = $refNos;
#	    $refNo =~ s/^([^\:]+)/$1/;
#	    my $refObj = Reference->new(dbh=>$dbh,
#					reference_no=>$refNo);
#	    if ($refObj) {
#		$self->{'_journal'} = $refObj->journal;
#		$self->{'_year'} = $refObj->year;
#		$self->{'_volume'} = $refObj->volume;
#		$self->{'_pages'} = $refObj->page;
#		## don't use $refObj->title 
#                ## since it will use will page title
#		$self->{'_Reftitle'} = $refObj->Title; 
#		$self->{'_pubmedid'} = $refObj->pubmed;
#		$self->{'_reftype'} = $refObj->status;
#		my $i;
#		foreach my $rowRef (@{$refObj->authorArrayRef}) {
#		    $i++;
#		    my ($author, $order) = @$rowRef;
#		    $self->{"_author$i"} = $author;
#		}
#	    }
#	}
#    }
    
    print $self->authors,p;
    print $self->refTitle;
    
    print table({-border=>'0',
		 -cellpadding=>'4',
		 -cellspacing=>'3',
		 -width=>'650'},
		$self->journal.
		$self->volume.
		$self->pageNumbers.
		$self->year.
		$self->pubmedId), p;

    print $self->publishStatus, p;
}

##########################################################################
sub geneName {
##########################################################################
    my($self, $locusObj) = @_;
    if ($locusObj) { 
	$self->{'_gene'} = $locusObj->locus_name;
    }
    param('gene', $self->{'_gene'});
    return Tr(td({-width=>'120',
		  -bgcolor=>'#ACBDCC'},
		 "Proposed Gene Name").
	      td(textfield(-name=>'gene',
			   -value=>$self->gene,
			   -size=>'40')));
}

##########################################################################
sub geneDesc {
##########################################################################
    my ($self, $locusObj) = @_;
    if ($locusObj) {
	$self->{'_genedesc'} = $locusObj->description;
    }
    return Tr(td({-width=>'120',
		  -bgcolor=>'#ACBDCC'},
		 "Description of Gene Name Acronym").
	      td(textarea(-name=>'genedesc', 
			  -value=>$self->{'_genedesc'},
			  -rows=>'3',
			  -columns=>'40')));
}

##########################################################################
sub orfName {
##########################################################################
    my($self, $locusObj) = @_;
    if ($locusObj) {
	$self->{'_orf'} = $locusObj->featureNameList;
    }
    param('orf', $self->{'_orf'});
    
    my $featObj = Feature->new(dbh=>$dbh,
			       feature_name=>$self->{'_orf'});

    my ($types, $type);

    if ($featObj) {

	$types = $featObj->featureTypeList;

	$type = $types;

	$types =~ s/\|/, /g;

        $type =~ s/\|?ORF\|?//;
	
	$type =~ tr/A-Z/a-z/;

    }

    return Tr(td({-width=>'120',
		  -bgcolor=>'#ACBDCC'},
		 "ORF Name").
	      td(textfield(-name=>'orf',
			   -value=>$self->{'_orf'},
			   -size=>'40'))).
	   Tr(td({-width=>'120',
		  -bgcolor=>'#ACBDCC'},
		 "ORF Type(s)").
	      td(a({-href=>$configUrl->dictyBaseHelp."glossary.html#$type",
		    -target=>'infowin'}, 
		   $types)));

}

##########################################################################
sub otherGeneName {
##########################################################################
    my ($self, $locusObj) = @_;
    if ($locusObj) {
	$self->{'_othergene'} = $locusObj->aliasNameList; 
    }
    return Tr(td({-width=>'120',
		  -bgcolor=>'#ACBDCC'},
		 "Other Gene Name(s)").
	      td(textfield(-name=>'othergene',
			   -value=>$self->{'_othergene'},
			   -size=>'40').br.
                 font({-size=>'-1'},
                      "When entering multiple genes names, separate them by : or ; or ,".br."For example: PHM5:EPP1:END1")));
}

##########################################################################
sub geneProduct {
##########################################################################
    my ($self, $locusObj) = @_;
    if ($locusObj) {
	$self->{'_geneproduct'} = $locusObj->gene_product;
	$self->{'_geneproduct'} =~ s/\t/; /g;
    } 
    return Tr(td({-width=>'120',
		  -bgcolor=>'#ACBDCC'},
		 "Gene Product").
	      td(textfield(-name=>'geneproduct',
			   -value=>$self->{'_geneproduct'},
			   -size=>'40').br.
		 font({-size=>'-1'},
		      "Gene Product should describe the function of the protein or nucleic".br."acid product of the gene. For example: phosphoserine transaminase".br."snRNA U4.")));

}

##########################################################################
sub nullPhenotype {
##########################################################################
    my ($self, $locusObj) = @_;
    if (param('registerType') !~ /update/i) {
	return Tr(td({-width=>'120',
		      -bgcolor=>'#ACBDCC'},
		     "Null Phenotypes").
		  td(textfield(-name=>'nullphenotype',
			       -value=>$self->{'_nullphenotype'},
			       -size=>'40').br.
		     font({-size=>'-1'},
			  "Null Phenotypes should describe the phenotype(s) of a null mutation".br."(e.g., knock out or gene disruption)")));
    }
    if ($locusObj) {
	$self->{'_nullphenotype'} = $locusObj->freeTextPhenotype; 
    }
    return Tr(td({-width=>'120',
		  -bgcolor=>'#ACBDCC'},
		 "Phenotypes").
	      td(textfield(-name=>'nullphenotype',
			   -value=>$self->{'_nullphenotype'},
			   -size=>'40')));
    
}

##########################################################################
sub otherPhenotype {
##########################################################################
    my ($self, $locusObj) = @_;
    if ($locusObj || param('registerType') =~ /update/i) { return; }
    return Tr(td({-width=>'120',
		  -bgcolor=>'#ACBDCC'},
		 "Other Phenotypes").
	      td(textfield(-name=>'otherphenotype',
			   -value=>$self->{'_otherphenotype'},
			   -size=>'40').br.
		 font({-size=>'-1'},
		      "Other Phenotypes should describe the type(s) of any other mutation(s)<br>and the resulting phenotype(s).")));

}

########################################################################
sub authors {
########################################################################
    my ($self) = @_;
    my $authorList;    
    for (my $i = 1; $i <= 6; $i += 2) {
	my $j = $i + 1;
	$authorList .= Tr(td($i).
			  td(textfield(-name=>"author$i",
				       -value=>$self->{"_author$i"},
				       -size=>'27')).
			  td($j).
			  td(textfield(-name=>"author$j",
				       -value=>$self->{"_author$j"},
				       -size=>'27')));
    }
    return table(Tr(td({-width=>'130',
			-bgcolor=>'#ACBDCC'},
		       b("Authors")))).
	   table({-border=>'2'},
		 Tr(th({-align=>'center',
			-colspan=>'2'},
		       "Last name, First initial").
		    th({-align=>'center',
			-colspan=>'2'},
		       "Last name, First initial")).
		$authorList);		 
}

#########################################################################
sub refTitle {
#########################################################################
    my ($self) = @_;
    return table(Tr(td({-width=>'130',
			-bgcolor=>'#ACBDCC'},
		       b("Title")))).
		 textarea(-name=>'Reftitle', 
			  -value=>$self->{'_Reftitle'},
			  -rows=>'2',
			  -columns=>'60');
}

#########################################################################
sub journal {
#########################################################################
    my ($self) = @_;
    return Tr(td({-width=>'120',
		  -bgcolor=>'#ACBDCC'},
		 "Journal").
	      td(textfield(-name=>'journal',
			   -value=>$self->{'_journal'},
			   -size=>40)));
}

########################################################################
sub volume {
########################################################################
    my ($self) = @_;
    return Tr(td({-width=>'120',
		  -bgcolor=>'#ACBDCC'},
		 "Volume").
	      td(textfield(-name=>'volume',
			   -value=>$self->{'_volume'},
			   -size=>10)));
}

########################################################################
sub pageNumbers {
########################################################################
    my ($self) = @_;
    return Tr(td({-width=>'120',
		  -bgcolor=>'#ACBDCC'},
		 "Page Numbers").
	      td(textfield(-name=>'pages',
			   -value=>$self->{'_pages'},
			   -size=>20)));
}

########################################################################
sub year {
########################################################################
    my ($self) = @_;
    return Tr(td({-width=>'120',
		  -bgcolor=>'#ACBDCC'},
		 "Year").
	      td(textfield(-name=>'year',
			   -value=>$self->{'_year'},
			   -size=>10)));
}

########################################################################
sub pubmedId {
########################################################################
    my ($self) = @_;
    return Tr(td({-width=>'120',
		  -bgcolor=>'#ACBDCC'},
		 "Pubmed ID").
	      td(textfield(-name=>'pubmed',
			   -value=>$self->{'_pubmed'},
			   -size=>20)));
}

########################################################################
sub printPubMedId {
########################################################################
    my ($self) = @_;
    return Tr(td({-width=>'120',
		  -bgcolor=>'#ACBDCC'},
		 "PubMed ID").
	      td(textfield(-name=>'pubmedid',
			   -value=>$self->{'_pubmedid'},
			   -size=>20)));
}

#######################################################################
sub publishStatus {
#######################################################################
    my ($self) = @_;
    return radio_group(-name=>'reftype',
                       -values=>['Published', 'In press', 
				 'Submitted', 'In preparation', 
				 'Unpublished'],
                       -default=>$self->{'_reftype'}
		       );
}

########################################################################
sub registryComments{
########################################################################
    my ($self) = @_;
    print "Anything else we did not ask about, but you want included in the database about this gene name.",br;
    return textarea(-name=>'registryComment',
		    -value=>$self->{'_registryComment'},
		    -rows=>'5',
		    -columns=>'60',
		    -wrap=>'soft');
}

########################################################################
sub displayContactInfo {
########################################################################
    my ($self) = @_;
    print $self->subtitle("Your Address and Contact Information");
    my $fullname;
    if (!$self->{'_suffix'}) {
	$fullname = $self->{'_fname'}." ".$self->{'_lname'};
    }
    elsif ($self->{'_suffix'} =~ /\./) {
	$fullname = $self->{'_fname'}." ".$self->{'_lname'}.
	            ", ".$self->{'_suffix'};
    }
    else {
	$fullname = $self->{'_fname'}." ".$self->{'_lname'}.
	            " ".$self->{'_suffix'};
    }
    print $fullname, br;
    if ($self->{'_oname'}) {
	if ($self->{'_oname'} =~ /,/) {
	    my ($olname, $ofname) = split(/, */, $self->{'_oname'});
	    print "$ofname $olname", br;
	}
	else {    
	    print $self->{'_oname'}, br;
	}
    }
    if ($self->{'_email'}) {
	$self->{'_email'} =~ s/[,;]/ /g;
	$self->{'_email'} =~ s/ +/ /g;
	my @email = split(/ /, $self->{'_email'});
	foreach my $email (@email) {
	    print a({-href=>"mailto:$email"}, $email),br;
	}
    }
    if ($self->{'_jobtitle'}) {
	print $self->{'_jobtitle'}, br;
    }
    if ($self->{'_profession'}) {
	print $self->{'_profession'}, br;
    }
    if ($self->{'_institution'}) {
	print $self->{'_institution'}, br;
    }
    my $addressValue;
    for(my $i = 1; $i <= 5; $i++) {
	if ($self->{"_address$i"}) {
	    $addressValue .= "\t".$self->{"_address$i"};
	}
    }
    if ($self->{'_city'}) {
	$addressValue .= "\t".$self->{'_city'};
    }
    my $STATE;
    if ($self->{'_state'} or $self->{'_region'}) {
	if ($self->{'_state'}) {
	    $STATE = $self->{'_state'};
	}
	else {
	    $STATE = $self->{'_region'};
	}
	if ($self->{'_zip_code'}) {
	    $STATE = "${STATE} ".$self->{'_zip_code'};
	}
	if (!$addressValue) {
	    $addressValue = $STATE;
	}
	elsif ($self->{'_city'}) {
	    $addressValue .= ", ".$STATE;
	}
	else {
	    $addressValue .= "\t".$STATE;
	}
    }
    if ($self->{'_country'}) {
	$addressValue .= "\t".$self->{'_country'};
    }
    $addressValue =~ s/^\t//;
    $addressValue =~ s/\t/<br>/g;
    if ($addressValue) {
	print $addressValue, br;
    }
    my ($phoneValue, $faxValue, $mobileValue, $pagerValue, $telexValue);
    for(my $i = 1; $i <= 5; $i++) {
	    if (!$self->{"_phone$i"}) { next; }	   
            my $phone_num = $self->{"_phone$i"};
            my $phone_type = $self->{"_phone_type$i"};
            if ($phone_type =~ /phone/i) {
		if (!$phoneValue) {    
		    $phoneValue = "${phone_num} ${phone_type}";
		}
		else {
		    $phoneValue .= br."${phone_num} ${phone_type}";
		}
	    }
            elsif ($phone_type =~ /fax/i) {
		if (!$faxValue) {    
		    $faxValue = "${phone_num} ${phone_type}";
		}
		else {
		    $faxValue .= br."${phone_num} ${phone_type}";
		}
	    }
	    elsif ($phone_type =~ /mobile/i) {
		if (!$mobileValue) {    
		    $mobileValue = "${phone_num} \(Mobile\)";
		}
		else {
		    $mobileValue .= br."${phone_num} \(Mobile\)";
		}
	    }
	    elsif ($phone_type =~ /pager/i) {
		if (!$pagerValue) {    
		    $pagerValue = "${phone_num} \(Pager\)";
		}
		else {
		    $pagerValue .= br."${phone_num} \(Pager\)";
		}
	    }
	    elsif ($phone_type =~ /telex/i) {
		if (!$telexValue) {    
		    $telexValue = "${phone_num} \(Telex\)";
		}
		else {
		    $telexValue .= br."${phone_num} \(Telex\)";
		}
	    }
    }
    if ($phoneValue) { print $phoneValue, br; }
    if ($faxValue) { print $faxValue, br; }
    if ($mobileValue) { print $mobileValue, br; }
    if ($pagerValue) { print $pagerValue, br; }
    if ($telexValue) { print $telexValue, br; }

    for (my $counter = 0; $counter < $numUrls; $counter++) {

      my $url = $self->{"_url$counter"};
      my $urlType = $self->{"_url_type$counter"};

      if (length($url) > 0) {
	print "$urlType URL: ", a({-href=>"$url"},
		$url), br;
      }
    }

    if ($self->{'_associated_loci'}) {
	print hidden({-name=>'associated_loci',
		      -value=>$self->{'_associated_loci'}});
    }
    ## KD: adding dictyBase contact info
    print "dictyBase contact: ".$self->{'_dictyBasecontact'}, br;

    print br, a({-href=>"$url?pid=".$self->pid."&editType=contact&id=".param('id')."&registerType=".param('registerType')},
		img({-src=>$configUrl->breadServerRoot."images/edit_white.gif"})), p;

}

########################################################################
sub displayAssociateInfo {
########################################################################
    my ($self) = @_;

    $dbh = &ConnectToDatabase($self->{'_database'});
    
    print $self->subtitle("Your Group/Lab members or associates");
    print table({-width=>'650'}, 
		Tr(td(b("Please carefully check the names of your Group/Lab members and associates.".p))).
		Tr(td(ul(li("Hyperlinked names correspond to entries that already exist in dictyBase. Click on the name to see that person's information.").
			 li("Check the box next to the name that you wish to display on your entry, but please use existing entries whenever available. ").
			 li("Unless a box is checked, the individual's name will NOT be listed in your entry."))))),p;

    ####### your students ...
    print b("(1) ".u("Your students, post-docs, technicians, etc.")),p;
    
    my $j;
    for (my $i = 1; $i <= 10; $i++) {
	if (!$self->{"_associate$i"}) { next; }
	$j++;
	$self->listAssociates($self->{"_associate$i"}, $i, $j, "associate");
    }

    if (!$j) {
	print li(font({-color=>'red'}, "No names provided")),p;
    }

    ####### your PI(s) ...
    print b("(2) ".u("Your Supervisor, Advisor, Group Leader, Head of Lab, or P.I.")),p;
    
    for(my $j = 1; $j <= 2; $j++) {
        if (!$self->{"_pi$j"}) { next; }
        $self->listAssociates($self->{"_pi$j"}, $j, $j, "pi");   
    }
    if (!$self->{"_pi1"}) {
	print li(font({-color=>'red'}, "No names provided")),p
    }

    print $self->subtitle("Your Collaborators");
    print table({-width=>'650'}, 
		Tr(td(b("Please carefully check the following names of your Collaborators and Associates. Follow the same instructions as above.")))),p;

    my $k = $j;
    for (my $i = 11; $i <= 20; $i++) {
	if (!$self->{"_associate$i"}) { next; }
	$k++;
	$self->listAssociates($self->{"_associate$i"}, $i, $k, "associate");
    }
    if ($k == $j) {
	print li(font({-color=>'red'}, "No names provided")),p
    }

    if (defined param("pi")) {
	print hidden({-name=>"pi",
		      -value=>"true"});
    }

    $dbh->disconnect;
}

######################################################################
sub listAssociates {
######################################################################
        my ($self, $assocNm, $i, $j, $type) = @_;

	if ($assocNm =~ /^(.+),([a-zA-Z].*)$/) {
	    $assocNm = "${1}, ${2}";
	}
	if ($assocNm =~ /^(.+),([a-zA-Z].*)$/) {
	    $assocNm = "${1}, ${2}";
	}
	if ($assocNm && $assocNm !~ /\,/) {
	    my @assoc = split(/ /, $assocNm);
	    my $assoc_ltmp = pop(@assoc);
	    my $assoc_ftmp = join(' ', @assoc);
	    $assocNm = "${assoc_ltmp}, ${assoc_ftmp}"; 
	}
	print li("$assocNm (select one):"),br;
	if ($type =~ /pi/i) {
	    print hidden(-name=>"ORIpi$i",
			 -value=>"$assocNm");
	}
	else {
	    print hidden(-name=>"ORIassociate$i",
			 -value=>"$assocNm");
	}
	my ($assoc_lname, $other_names) = split(/\,/, $assocNm);   
	my $arrayRef = Colleague->GetColleagueInfoArrayRefBYname(
					     dbh=>$dbh,
					     last_name=>$assoc_lname);
	my $found;
	my @collWithSameLastNm;
	my %collLabel;
	my %checked;
	if (@$arrayRef) {
		foreach my $rowRef (@$arrayRef) {
		    my ($id, $fname, $lname, $institution) = @$rowRef;
		    my $assoc = "${lname}, $fname";
		    my $linkname = $assoc;
		    $linkname =~ s/ /+/g;
		    if ("\U$assoc" eq "\U$assocNm") {
			$assocNm = $assoc;
			$found = 1;
			$checked{$assoc} = "checked";
		    }
		    push(@collWithSameLastNm, $assoc);
		    
		    $collLabel{$assoc} = a({-href=>$configUrl->dictyBaseCGIRoot."$dblink/colleague/colleagueSearch?id=$id&win=1",
		    			    -target=>"infowin"},
		    			   $assoc); 
		    if ($institution) {
			$collLabel{$assoc} .= " at ".$institution;
		    }
		}
	}
	if (!$found) {
		push(@collWithSameLastNm, $assocNm);
		$collLabel{$assocNm} = $assocNm; 
		$checked{$assocNm} = "checked";
	}
	### following radio_group codes are not working for label link. 
	# print radio_group(-name=>"PILIST$j",
	#		      -values=>\@collWithSameLastNm,
	#		      -default=>"$assocNm",
	#		      -linebreak=>'true',
	#		      -labels=>\%collLabel),p;
	foreach my $assoc (@collWithSameLastNm) {
	    if ($type =~ /pi/i) {
		print "<input type='radio' name='pi$i' value='$assoc' $checked{$assoc}>$collLabel{$assoc}", br;
	    }
	    else {
		print "<input type='radio' name='associate$i' value='$assoc' $checked{$assoc}>$collLabel{$assoc}", br;
	    }
	}
	print p;
}

########################################################################
sub displayInterestKeywordInfo {
########################################################################
    my ($self) = @_;
    my $pid = $self->pid;

    if ($self->{'_interests'} || $self->{'_keyword1'} || $self->{'_researchTopics'}) {
	print $self->subtitle("Your Research Interests");
	print $self->{'_interests'}, p;
	print a({-href=>"$url?pid=".$self->pid."&editType=interest&id=".param('id')."&registerType=".param('registerType')},
		img({-src=>$configUrl->breadServerRoot."images/edit_white.gif"})), p;
    }

    if (($self->{'_keyword1'}) || ($self->{'_researchTopics'})) {
	print table({-border=>'0',
		     -cellpadding=>'4',
		     -cellspacing=>'3',
		     -width=>'650'},
		    Tr(td({-width=>'100%',
			   -bgcolor=>'#a4abc2'},
			  font({-size=>'+1'},
			       b("Research Topics")))));
	my $collRT = $self->{'_researchTopics'};
	$collRT =~ s/^\t//;
	$collRT =~ s/\t/\<BR\>/g;
	print $collRT;

	print p, a({-href=>"$url?pid=".$self->pid."&editType=keyword&id=".param('id')."&registerType=".param('registerType')},
		img({-src=>$configUrl->breadServerRoot."images/edit_white.gif"})), p;

	print table({-border=>'0',
		     -cellpadding=>'4',
		     -cellspacing=>'3',
		     -width=>'650'},
		    Tr(td({-width=>'100%',
			   -bgcolor=>'#a4abc2'},
			  font({-size=>'+1'},
			       b("Keywords")))));
	for(my $i = 1; $i <= 10; $i++) {
	    if (!$self->{"_keyword$i"}) { last;}
	    print $self->{"_keyword$i"},br;
	}
	print p, a({-href=>"$url?pid=".$self->pid."&editType=keyword&id=".param('id')."&registerType=".param('registerType') . "#Keywords"},
		img({-src=>$configUrl->breadServerRoot."images/edit_white.gif"})), p;
    }

}


######################################################################## 
sub displayCommentInfo {
########################################################################
    my ($self) = @_;
    if (!$self->{'_Comments'}) { return;}
    $self->{'_Comments'} =~ s/\\n/\&nbsp\;<BR>/g;
    print $self->subtitle("Your Comments"); 
    print $self->{'_Comments'}, p;
    print a({-href=>"$url?pid=".$self->pid."&editType=comment&id=".param('id')."&registerType=".param('registerType')},
		img({-src=>$configUrl->breadServerRoot."images/edit_white.gif"})), p;
}

########################################################################
sub displayGeneInfo {
########################################################################
    my ($self) = @_;
    print $self->subtitle("Information about the Gene");
    if ($self->{'_gene'}) {
	print "Proposed Gene Name = ", $self->{'_gene'}, br;
    }
    if ($self->{'_genedesc'}) {
	print "Description of Gene Name Acronym = ", $self->{'_genedesc'}, br;
    }
    if ($self->{'_orf'}) {
	print "ORF Name = ", $self->{'_orf'}, br;
    }
    if ($self->{'_othergene'}) {
	print "Other Gene Name(s) = ", $self->{'_othergene'}, br;
    }
    if ($self->{'_geneproduct'}) {
	print "Gene Product = ", $self->{'_geneproduct'}, br;
    }
    if ($self->{'_nullphenotype'}) {
	if (param('registerType') =~ /update/i) {
	    print "Phenotypes = ", $self->{'_nullphenotype'}, br;
	}
	else {
	    print "Null Phenotypes = ", $self->{'_nullphenotype'}, br;
	}
    }
    if ($self->{'_otherphenotype'}) {
	print "Other Phenotypes = ", $self->{'_otherphenotype'}, br;
    }   
    print a({-href=>"$url?pid=".$self->pid."&editType=GeneInfo&id=".param('id')."&registerType=".param('registerType')."&reserveAnotherGene=".param('reserveAnotherGene')},
		img({-src=>$configUrl->breadServerRoot."images/edit_white.gif"})), p;
}

########################################################################
sub displayGeneReferenceInfo {
########################################################################
    my ($self) = @_;
    my $authorlist;
    for (my $i = 1; $i <= 6; $i++) {
	if ($self->{"_author$i"}) {
	    $self->{"_author$i"} =~ s/,/ /g;
	    $self->{"_author$i"} =~ s/ +/ /g;
	    $authorlist .= $self->{"_author$i"}.", ";
	}
    }
    $authorlist =~ s/\, $//;
    my $paper;
    if ($authorlist) {
	$paper = "${authorlist} ";
    }
    if ($self->{'_year'}) {
	$paper .= "(".$self->{'_year'}.") ";
    }
    if ($self->{'_Reftitle'}) {
	if ($self->{'_Reftitle'} !~ /\.$/) {
	    $self->{'_Reftitle'} .= ".";
	}
	$paper .= $self->{'_Reftitle'}." ";
    }
    if ($self->{'_journal'}) {
	$paper .= $self->{'_journal'}." ";
    }
    if ($self->{'_volume'}) {
	$paper .= $self->{'_volume'}.": ";
    }
    if ($self->{'_pages'}) {
	$paper .= $self->{'_pages'}." ";
    }
    if ($self->{'_reftype'} !~ /Published/i) {
	$paper .= "(".$self->{'_reftype'}.")";
    }
    if (!$paper && !$self->{'_pubmed'}) { return; }
    print $self->subtitle("Reference");   
    print $paper, br;
    if ($self->{'_pubmed'}) {
	print "Pubmed ID = ", $self->{'_pubmed'}, br;
    }    
    print a({-href=>"$url?pid=".$self->pid."&editType=ReferenceInfo&id=".param('id')."&registerType=".param('registerType')."&reserveAnotherGene=".param('reserveAnotherGene')},
		img({-src=>$configUrl->breadServerRoot."images/edit_white.gif"})), p;
}
	
########################################################################
sub displayGeneCommentInfo {
########################################################################
    my ($self) = @_;
    if (!$self->{'_registryComment'}) { return;}
    print $self->subtitle("Gene Name Comments"); 
    print $self->{'_registryComment'}, br;
    print a({-href=>"$url?pid=".$self->pid."&editType=GeneCommentInfo&id=".param('id')."&registerType=".param('registerType')."&reserveAnotherGene=".param('reserveAnotherGene')},
		img({-src=>$configUrl->breadServerRoot."images/edit_white.gif"})), p;
}

########################################################################
sub createNewEntryFile {
########################################################################
    my ($self) = @_;
    my $pid = param('pid');
    my $emailSubject;
    if (!$self->{'_institution'}) {  ### reserve another gene
	$emailSubject = "$self->{'_database'} Gene Registry";
    }
    elsif (param('registerType')) {
	$emailSubject = "$self->{'_database'} Colleague Gene Registry";
    }
    else {
	$emailSubject = "$self->{'_database'} Colleague New Entry";
    }
    $self->{'_title'} .= $emailSubject." Result";

    &printStartPage($self->database, $self->title, $self->help);

    my $dbname = $self->database;
    $dbname = "\U$dbname";

    if ($self->{'_gene'}) {

	$emailSubject .= " for ".$self->{'_gene'};

	if ($self->{'_orf'}) {
	    $emailSubject .= "/".$self->{'_orf'};
	}
	
    }
	    
    $emailSubject .= " by ".$self->{'_lname'}.", ".$self->{'_fname'};
   
    ################
    open (MAIL, "|/usr/lib/sendmail -oi -t")||die "Can't open mail : $!\n";

    if ($self->{'_database'} =~ /dictyBase/i) {

print MAIL <<Mail_Headers;
From: <shuai\@genome.stanford.edu>
To: <shuai\@genome.stanford.edu>
Reply-To: <shuai\@genome.stanford.edu>
Subject: $emailSubject
Mail_Headers

    }
    else {

print MAIL <<Mail_Headers;
From: <e-just\\\northwestern.edu>
To: <e-just\\\northwestern.edu>
Reply-To: <e-just\\\northwestern.edu>
Subject: $emailSubject
Mail_Headers

    }

    ################

    if (param('reserveAnotherGene')) {
	print MAIL qq/Form_Name = Gene Registry Entry/, "\n";
	$self->presentInfo2User;
	print MAIL qq/Last_Name = /, $self->{'_lname'}, "\n";
	print MAIL qq/First_Name = /, $self->{'_fname'}, "\n";
       	$self->createGeneRegistryFile;
	close(MAIL);
	$self->removeTMP(param('pid'));
	&printEndPage;
	exit;
    }
    elsif (param('registerType') =~ /Reservation/i) {
	print MAIL qq/Form_Name = Gene Registry and Colleague New Entry/, "\n";
	print MAIL qq/Internet = /, $self->{'_email'}, "\n";
    }
    elsif (param('registerType')) {
	print MAIL qq/Form_Name = Update Gene Information and Colleague New Entry/, "\n";
    }
    else {
	print MAIL qq/Form_Name = Colleague New Entry/, "\n";
	
    }

    open (OUT, ">".$configPath->dataDir4web."submission/colleague/$pid.newEntry") || print "colleagueUpdate: Can't open '$pid.newEntry' for writing:$!\n";


    $self->presentInfo2User;
    print MAIL qq/Last_Name = /, $self->{'_lname'}, "\n";
    print MAIL qq/First_Name = /, $self->{'_fname'}, "\n";
    print OUT qq/Last_Name = /, $self->{'_lname'}, "\n";
    print OUT qq/First_Name = /, $self->{'_fname'}, "\n";
    if ($self->{'_suffix'}) {
	print MAIL qq/Suffix = /, $self->{'_suffix'}, "\n";
	print OUT qq/Suffix = /, $self->{'_suffix'}, "\n";
    }
    if ($self->{'_oname'}) {
	print MAIL qq/Other_Name = /, $self->{'_oname'}, "\n";
	print OUT qq/Other_Name = /, $self->{'_oname'}, "\n";
    }
    print MAIL qq/Internet = /, $self->{'_email'}, "\n";
    print OUT qq/Internet = /, $self->{'_email'}, "\n";
    if ($self->{'_institution'}) {
	print MAIL qq/Organization = /, $self->{'_institution'}, "\n";
	print OUT qq/Organization = /, $self->{'_institution'}, "\n";
    }
    for (my $i = 1; $i <= 5; $i++) {
	if ($self->{"_phone$i"}) {
	        print MAIL $self->{"_phone_type$i"}," = ", $self->{"_phone$i"}, "\n";
	    	print OUT $self->{"_phone_type$i"}," = ", $self->{"_phone$i"}, "\n";
    	}
    }

    my $urlCount = 0;
    for (my $counter = 0; $counter < $numUrls; $counter++) {
 	$self->{"_url$counter"} =~ s/[,; ]+/ /g;
	$self->{"_url$counter"} =~ s/^ *//;
	$self->{"_url$counter"} =~ s/ *$//;

	if (length($self->{"_url$counter"}) == 0) { next; }

	if ($self->{"_url$counter"} !~ /:\/\//) {
	  $self->{"_url$counter"} = "http:\/\/$self->{\"_url$counter\"}";
	}
	my $webtitle = $self->getWebTitleByURL($self->{"_url$counter"});
	print MAIL qq/URL$urlCount = $self->{"_url$counter"}/, "\n"; 
	print OUT qq/URL$urlCount = $self->{"_url$counter"}/, "\n"; 
	# print OUT qq/$self->{"_url_type$counter"} = $self->{"_url$counter"}/, "\n";
	print MAIL qq/WebTitle$urlCount = $webtitle/, "\n";
	print OUT qq/WebTitle$urlCount = $webtitle/, "\n";
	print MAIL qq/URLType$urlCount = $self->{"_url_type$counter"}/, "\n";
	print OUT qq/URLType$urlCount = $self->{"_url_type$counter"}/, "\n";

	$urlCount++;
    }
    for (my $i = 1; $i <= 5; $i++) {
    	if ($self->{"_address$i"}) {
    	    print MAIL qq/Address = /, $self->{"_address$i"}, "\n";
    	    print OUT qq/Address = /, $self->{"_address$i"}, "\n";   
    	}
    }
    if ($self->{'_city'}) {
    	print MAIL qq/City = /, $self->{'_city'}, "\n";
    	print OUT qq/City = /, $self->{'_city'}, "\n";
    }
    if ($self->{'_state'}) {
    	print MAIL qq/State = /, $self->{'_state'}, "\n";
    	print OUT qq/State = /, $self->{'_state'}, "\n";
    }
    if ($self->{'_region'}) {
	print MAIL qq/Region = /, $self->{'_region'}, "\n";
	print OUT qq/Region = /, $self->{'_region'}, "\n";
    }
    if ($self->{'_country'}) {
	print MAIL qq/Country = /, $self->{'_country'}, "\n";
	print OUT qq/Country = /, $self->{'_country'}, "\n";
    }
    if ($self->{'_zip_code'}) {
	print MAIL qq/Zip_code = /, $self->{'_zip_code'}, "\n";
	print OUT qq/Zip_code = /, $self->{'_zip_code'}, "\n";
    }
    if ($self->{'_jobtitle'}) {
	print MAIL qq/JobTitle = /, $self->{'_jobtitle'}, "\n";
	print OUT qq/JobTitle = /, $self->{'_jobtitle'}, "\n";
    }
    if ($self->{'_profession'}) {
	print MAIL qq/Profession = /, $self->{'_profession'}, "\n";
	print OUT qq/Profession = /, $self->{'_profession'}, "\n";
    }
    for (my $i = 1; $i <= 2; $i++) {
#        if ($self->{"_PILIST$i"}) {
        if ($self->{"_pi$i"}) {
	    print MAIL qq/Head_of_Lab = /, $self->{"_pi$i"}, "\n";
	    print OUT qq/Head_of_Lab = /, $self->{"_pi$i"}, "\n";
	}
    }
    for (my $i = 1; $i <= 20; $i++) {
	if ($self->{"_associate$i"}) {
	    if ($i <= 10) {
		print MAIL "PI (", $self->{"_associate$i"}, ") = ", $self->{'_lname'},", ", $self->{'_fname'}, "\n";
               print OUT "PI (", $self->{"_associate$i"}, ") = ", $self->{'_lname'},", ", $self->{'_fname'}, "\n"; 
            }
            else {
		print MAIL qq/Associate = /, $self->{"_associate$i"}, "\n";
	    	print OUT qq/Associate = /, $self->{"_associate$i"}, "\n";
            } 
	}
    }
    if ($self->{'_interests'}) {
	print MAIL qq/Interests = /, $self->{'_interests'}, "\n";
	print OUT qq/Interests = /, $self->{'_interests'}, "\n";
    }

    if ($self->{'_researchTopics'}) {
	print MAIL qq/ResearchTopics = /, $self->{'_researchTopics'}, "\n";
	print OUT qq/ResearchTopics = /, $self->{'_researchTopics'}, "\n";
    }

    for (my $i = 1; $i <= 10; $i++) {
	if ($self->{"_keyword$i"}) { 
		print MAIL qq/Keyword = /, $self->{"_keyword$i"}, "\n";
		print OUT qq/Keyword = /, $self->{"_keyword$i"}, "\n";
	}
    }
    my $date = `date`;
    my @date = split(' ', $date);
    if (length($date[2]) == 1) {
        $date[2] = "0$date[2]";
    }
    ## KD: adding dictyBase contact stuff
    if ($self->{'_dictyBasecontact'}) {
       print MAIL qq/CONTACT4dictyBase = /, $self->{'_dictyBasecontact'}, "\n";
       print OUT qq/CONTACT4dictyBase = /, $self->{'_dictyBasecontact'}, "\n";
    }

    if ($self->{'_Comments'}) {
        print MAIL qq/Comments = /, $self->{'_Comments'}, "\n";
        print OUT qq/Comments = /, $self->{'_Comments'}, "\n";
    }

    print OUT qq/Obtained_from = Direct Submission/, "\n";
    print MAIL qq/Obtained_from = Direct Submission/, "\n";
    print OUT qq/Last_Update = $date[5]-$mon2num{$date[1]}-$date[2]/,"\n";
    print MAIL qq/Last_Update = $date[5]-$mon2num{$date[1]}-$date[2]/,"\n";

#    print MAIL "\n\nThe file is available at :\n";
#    print MAIL $configPath->dataDir4web."submission/colleague/$pid.newEntry\n";
#    print MAIL "You may edit this file directly.\n\n";
#    print MAIL "Please use following url to view, edit and commit this file into database\n";
#    print MAIL $configUrl->dictyBaseCGIRoot."$dblink/curation/CommitNewEntry?id=$pid\n";
    close(OUT);
    if (param('registerType')) {
	$self->createGeneRegistryFile;
    }
    close(MAIL);
    $self->removeTMP(param('pid'));
    &printEndPage;
}

########################################################################
sub createUpdateFile {
########################################################################
    my ($self) = @_;

    my $pid = param('pid');

    my $emailSubject;

    if (param('registerType')) {
	$self->{'_title'} = "$self->{'_database'} Colleague Gene Registry Result";
	$emailSubject = "$self->{'_database'} Colleague Gene Registry";

    }
    else {
	$self->{'_title'} = "$self->{'_database'} Colleague Update Result";

	$emailSubject = "$self->{'_database'} Colleague Update";
	
    }
    &printStartPage($self->database, $self->title, $self->help);
    my $dbname = $self->database;
    $dbname = "\U$dbname";
    
#    print p, "Thank you for your Colleague submission. The following information was transmitted to the dictyBase curators:", p;
     
    open(OUT, ">".$configPath->dataDir4web."submission/colleague/$pid.MajorUpdate") || print "colleagueUpdate: Can't open '$pid.MajorUpdate' for writing:$!\n";

    open (MAIL, "|/usr/lib/sendmail -oi -t")||die "Can't open mail : $!\n";

    if ($self->{'_gene'}) {

	$emailSubject .= " for ".$self->{'_gene'}; 

	if ($self->{'_orf'}) {

	    $emailSubject .= "/".$self->{'_orf'};

	}

    }
    
    $emailSubject .= " by ".$self->{'_lname'}.", ".$self->{'_fname'};


    if ($self->{'_database'} =~ /dictyBase/i) {

print MAIL <<Mail_Headers;
From: <shuai\@genome.stanford.edu>
To: <shuai\@genome.stanford.edu>
Reply-To: <shuai\@genome.stanford.edu>
Subject: $emailSubject
Mail_Headers

    }
    else {

print MAIL <<Mail_Headers;
From: <e-just\\\northwestern.edu>
To: <e-just\\\northwestern.edu>
Reply-To: <e-just\\\northwestern.edu>
Subject: $emailSubject
Mail_Headers

    }

    if (param('registerType') =~ /Reservation/i) {
	print MAIL qq/Form_Name = Gene Registry and Colleague Major Update/, "\n";
    }
    elsif (param('registerType')) {
	print MAIL qq/Form_Name = Update Gene Information and Colleague Major Update/, "\n";
    }
    else {
	print MAIL qq/Form_Name = Colleague Major Update/, "\n";
    }
    my $collObject = Colleague->new(dbh=>$dbh,
				colleague_no=>$self->colleagueNo);
    $self->presentInfo2User;

    print MAIL qq/Colleague_no = /, $self->colleagueNo, "\n";
    print OUT qq/Colleague_no = /, $self->colleagueNo, "\n";
    
    print MAIL qq/\/\/ Last_Name = /, $collObject->last_name, "\n";
    print MAIL qq/\/\/ First_Name = /, $collObject->first_name, "\n";
    print OUT qq/\/\/ Last_Name = /, $collObject->last_name, "\n";
    print OUT qq/\/\/ First_Name = /, $collObject->first_name, "\n";
    if ($collObject->suffix) {
	print MAIL qq/\/\/ Suffix = /, $collObject->suffix, "\n";
	print OUT qq/\/\/ Suffix = /, $collObject->suffix, "\n";
    }
    #########
    my @comment_lines;
    #########
    my $name_changed;
    if ($collObject->last_name ne $self->{'_lname'} || 
	$collObject->first_name ne $self->{'_fname'} || 
	$collObject->suffix ne $self->{'_suffix'}) {
	if ($collObject->last_name ne $self->{'_lname'} ) {
	    print MAIL qq/-D Last_Name = /, $collObject->last_name, "\n";
	    print OUT qq/-D Last_Name = /, $collObject->last_name, "\n";
	    print MAIL qq/Last_Name = /, $self->{'_lname'}, "\n";
	    print OUT qq/Last_Name = /, $self->{'_lname'}, "\n";
	    
        }
	if ($collObject->first_name ne $self->{'_fname'}) {
	    print MAIL qq/-D First_Name = /, $collObject->first_name, "\n";
	    print OUT qq/-D First_Name = /, $collObject->first_name, "\n";
	    print MAIL qq/First_Name = /, $self->{'_fname'}, "\n";
	    print OUT qq/First_Name = /, $self->{'_fname'}, "\n";
	}
	if ($collObject->suffix ne $self->{'_suffix'}) {
	    if ($collObject->suffix) {
		print MAIL qq/-D Suffix = /, $collObject->suffix, "\n";
		print OUT qq/-D Suffix = /, $collObject->suffix, "\n";
	    }
	    if ($self->{'_suffix'}) {
		print MAIL qq/Suffix = /, $self->{'_suffix'}, "\n";
		print OUT qq/Suffix = /, $self->{'_suffix'}, "\n";
	    }
	}
	$name_changed = "yes";
    }
    #########
    if ($collObject->other_name ne $self->{'_oname'}) {
        print MAIL qq/-D Other_Name = /, $collObject->other_name, "\n" unless (!$collObject->other_name);
        print MAIL qq/Other_Name = /, $self->{'_oname'}, "\n" unless (!$self->{'_oname'});
        print OUT qq/-D Other_Name = /, $collObject->other_name, "\n" unless (!$collObject->other_name);
        print OUT qq/Other_Name = /, $self->{'_oname'}, "\n" unless (!$self->{'_oname'});
    }
    elsif ($collObject->other_name) {
        push(@comment_lines, "Other_Name = ".$collObject->other_name);
    }
    #########
    my @OLDemail;
    my $emailRef = $collObject->emailRef;
    my $num;
    foreach my $rowRef (@$emailRef) {
	my ($email) = @$rowRef;
	push(@OLDemail, $email);
	$num++;
    }
    $self->{'_email'} =~ s/[,; ]+/ /g;
    $self->{'_email'} =~ s/^ *//;
    $self->{'_email'} =~ s/ *$//;
    my @NEWemail = split(' ', $self->{'_email'});
    if (@NEWemail > $num) { $num = @NEWemail; }
    for (my $i = 0; $i <= $num; $i++) {
	&DeleteUnwantedChar(\$OLDemail[$i]);
        if ($OLDemail[$i] ne $NEWemail[$i]) {
            print MAIL qq/-D Internet = $OLDemail[$i]/, "\n" unless (!$OLDemail[$i]);
            print MAIL qq/Internet = $NEWemail[$i]/, "\n" unless (!$NEWemail[$i]);
            print OUT qq/-D Internet = $OLDemail[$i]/, "\n" unless (!$OLDemail[$i]);
            print OUT qq/Internet = $NEWemail[$i]/, "\n" unless (!$NEWemail[$i]);
        }
        elsif ($OLDemail[$i]) {
	    push(@comment_lines, "Internet = $OLDemail[$i]");
        }
    }
    #########
    if ($collObject->job_title ne $self->{'_jobtitle'}) {
        print MAIL qq/-D JobTitle = /, $collObject->job_title, "\n" unless (!$collObject->job_title);
        print MAIL qq/JobTitle = /, $self->{'_jobtitle'}, "\n" unless (!$self->{'_jobtitle'});
        print OUT qq/-D JobTitle = /, $collObject->job_title, "\n" unless (!$collObject->job_title);
        print OUT qq/JobTitle = /, $self->{'_jobtitle'}, "\n" unless (!$self->{'_jobtitle'});
    }
    elsif ($collObject->job_title) {
	push(@comment_lines, "JobTitle = ".$collObject->job_title);
    }
    #########
    if ($collObject->profession ne $self->{'_profession'}) {
        print MAIL qq/-D Profession = /, $collObject->profession, "\n" unless (!$collObject->profession);
        print MAIL qq/Profession = /, $self->{'_profession'}, "\n" unless (!$self->{'_profession'});
        print OUT qq/-D Profession = /, $collObject->profession, "\n" unless (!$collObject->profession);
        print OUT qq/Profession = /, $self->{'_profession'}, "\n" unless (!$self->{'_profession'});
    }
    elsif ($collObject->profession) {
	push(@comment_lines, "Profession = ".$collObject->profession);
    }
    #########
    if ($collObject->institution ne $self->{'_institution'}) {
        print MAIL qq/-D Organization = /, $collObject->institution, "\n" unless (!$collObject->institution);
        print MAIL qq/Organization = /, $self->{'_institution'}, "\n" unless (!$self->{'_institution'});
        print OUT qq/-D Organization = /, $collObject->institution, "\n" unless (!$collObject->institution);
        print OUT qq/Organization = /, $self->{'_institution'}, "\n" unless (!$self->{'_institution'});
    }
    elsif ($collObject->institution) {
	push(@comment_lines, "Organization = ".$collObject->institution);
    }
    #########
    my @OLDaddr = ('', $collObject->address1, $collObject->address2, $collObject->address3, $collObject->address4, $collObject->address5);
    my @addr = ('', $self->{'_address1'}, $self->{'_address2'},  $self->{'_address3'}, $self->{'_address4'}, $self->{'_address5'});
    my $addrChange = 0;
    for (my $i = 1; $i <= 5; $i++) {
	&DeleteUnwantedChar(\$OLDaddr[$i]);
	if ($addr[$i] ne $OLDaddr[$i]) {
	    $addrChange = 1;
	    last;
	}
    }
    if ($addrChange == 1) {
	for (my $i = 1; $i <= 5; $i++) {
	    &DeleteUnwantedChar(\$OLDaddr[$i]);
	    print MAIL qq/-D Address = $OLDaddr[$i]/, "\n" unless (!$OLDaddr[$i]);
	    print OUT qq/-D Address = $OLDaddr[$i]/, "\n" unless (!$OLDaddr[$i]);
	}
	for (my $i = 1; $i <= 5; $i++) {
	    print MAIL qq/Address = $addr[$i]/, "\n" unless (!$addr[$i]);
	    print OUT qq/Address = $addr[$i]/, "\n" unless (!$addr[$i]);  
	}
    }
    else {
	for (my $i = 1; $i <= 5; $i++) {
	    if ($OLDaddr[$i]) {
		push(@comment_lines, "Address = $OLDaddr[$i]");
	    }
	}
    }
    ########
    if ($collObject->city ne $self->{'_city'}) {
        print MAIL qq/-D City = /, $collObject->city, "\n" unless (!$collObject->city);
        print MAIL qq/City = /, $self->{'_city'}, "\n" unless (!$self->{'_city'});
        print OUT qq/-D City = /, $collObject->city, "\n" unless (!$collObject->city);
        print OUT qq/City = /, $self->{'_city'}, "\n" unless (!$self->{'_city'});
    }
    elsif ($collObject->city) {
	push(@comment_lines, "City = ".$collObject->city);   
    }

    ########
    if ($collObject->state ne $self->{'_state'}) {
        print MAIL qq/-D State = /, $collObject->state, "\n" unless (!$collObject->state);
        print MAIL qq/State = /, $self->{'_state'}, "\n" unless (!$self->{'_state'});
        print OUT qq/-D State = /, $collObject->state, "\n" unless (!$collObject->state);
        print OUT qq/State = /, $self->{'_state'}, "\n" unless (!$self->{'_state'});
    }
    elsif ($collObject->state) {
	push(@comment_lines, "State = ".$collObject->state);   
    }

    ########
    if ($collObject->region ne $self->{'_region'}) {
        print MAIL qq/-D Region = /, $collObject->region, "\n" unless (!$collObject->region);
        print MAIL qq/Region = /, $self->{'_region'}, "\n" unless (!$self->{'_region'});
        print OUT qq/-D Region = /, $collObject->region, "\n" unless (!$collObject->region);
        print OUT qq/Region = /, $self->{'_region'}, "\n" unless (!$self->{'_region'});
    }
    elsif ($collObject->region) {
	push(@comment_lines, "Region = ".$collObject->region);    
    }
    ########
    if ($collObject->country ne $self->{'_country'}) {
	print MAIL qq/-D Country = /, $collObject->country, "\n" unless (!$collObject->country);
        print MAIL qq/Country = /, $self->{'_country'}, "\n" unless (!$self->{'_country'}); 
        print OUT qq/-D Country = /, $collObject->country, "\n" unless (!$collObject->country); 
        print OUT qq/Country = /, $self->{'_country'}, "\n" unless (!$self->{'_country'});    
    }
    elsif ($collObject->country) {
	push(@comment_lines, "Country = ".$collObject->country);
    }
    ########
    if ($collObject->postal_code ne $self->{'_zip_code'}) {
	print MAIL qq/-D PostalCode = /, $collObject->postal_code, "\n" unless (!$collObject->postal_code); 
	print MAIL qq/PostalCode = /, $self->{'_zip_code'}, "\n" unless (!$self->{'_zip_code'});
        print OUT qq/-D PostalCode = /, $collObject->postal_code, "\n" unless (!$collObject->postal_code); 
	print OUT qq/PostalCode = /, $self->{'_zip_code'}, "\n" unless (!$self->{'_zip_code'});
    }
    elsif ($collObject->postal_code) {
	push(@comment_lines, "PostalCode = ".$collObject->postal_code);
    }
    ########
    my (%newphone, %oldphone);
    for (my $i = 1; $i <= 5; $i++) {
	if (!$self->{"_phone$i"}) { next; } 
	my $phoneType = $self->{"_phone_type$i"};
        $newphone{"\U$phoneType"} = $self->{"_phone$i"};
    }
    my $phoneRef = $collObject->phoneRef;
    foreach my $rowRef (@$phoneRef) {
	my ($phoneNum, $phoneType, $phoneLoc) = @$rowRef;
	if ($phoneLoc !~ /specified/i) {
	    $phoneType = $phoneLoc . " " . $phoneType;
	}
	$oldphone{"\U$phoneType"} = $phoneNum;
	if ($phoneNum ne $newphone{"\U$phoneType"}) {
	    print MAIL "-D $phoneType = $phoneNum\n";
	    print OUT "-D $phoneType = $phoneNum\n";
        }
        else {
	    push(@comment_lines, "$phoneType = $phoneNum");
        }
    }
    for (my $i = 1; $i <= 5; $i++) {
        if (!$self->{"_phone$i"}) { next; }
	my $type = $self->{"_phone_type$i"};
	if ($self->{"_phone$i"} ne $oldphone{"\U$type"}) {
            print MAIL $type, " = ", $self->{"_phone$i"}, "\n";
            print OUT $type, " = ", $self->{"_phone$i"}, "\n";
        }
    }
    #########

    my $urlRef = $collObject->urlRef;

    my @allURLObjectKeys = ();
    my %oldURLObjects;
    my %newURLObjects;
    my %checkedURLObjectKeys;

    my $formPos = 0;
    # create a list of existing URLs
    foreach my $rowRef (@$urlRef) { 

	$formPos++;

	my ($url, $wwwNm, $urlType) = @$rowRef;
	my @urlObject = ($url, $wwwNm, $urlType, $formPos);
	my $urlObjectKey = $url . $wwwNm . $urlType;

	$oldURLObjects{$urlObjectKey} = \@urlObject;
	push(@allURLObjectKeys, $urlObjectKey);
    }
    # create a list of new URLs (aka user-confirmed URLs)
    for (my $counter = 0; $counter < $numUrls; $counter++) {

	my ($url, $wwwNm, $urlType) 
	     = ($self->{"_url$counter"}, 
		$self->getWebTitleByURL($self->{"_url$counter"}),
		$self->{"_url_type$counter"}
	       );

	$url =~ s/^\s+//;
	$url =~ s/\s+$//;
	if (length($url) == 0) { next; }

	my @urlObject = ($url, $wwwNm, $urlType, $counter);
	my $urlObjectKey = $url . $wwwNm . $urlType;

	$newURLObjects{$urlObjectKey} = \@urlObject;
	push(@allURLObjectKeys, $urlObjectKey);

	(my $temp1, my $temp2, my $temp3) = @{$newURLObjects{$url . $wwwNm . $urlType}};
    }

    my $found = 0;
    my $urlCount = 0;

    # first, locate all unchanged URLs and eliminate them from the list
    foreach my $urlObjectKey (@allURLObjectKeys) {

	if (defined $checkedURLObjectKeys{$urlObjectKey}) { next; }

	if ((defined $oldURLObjects{$urlObjectKey}) &&
	    (defined $newURLObjects{$urlObjectKey})) {

	    $checkedURLObjectKeys{$urlObjectKey} = 1;
	    push(@comment_lines, 
		 "URL$urlCount = $oldURLObjects{$urlObjectKey}[0]");
	    push(@comment_lines, 
		 "WebTitle$urlCount = $oldURLObjects{$urlObjectKey}[1]");
	    push(@comment_lines, 
		 "URLType$urlCount = $oldURLObjects{$urlObjectKey}[2]");
	    $urlCount++;
	}
    }

    # now, for the remaining URLs, try to identify which ones are modified 
    #   ones, and which ones are not modified ones.
    foreach my $urlObjectKey (@allURLObjectKeys) {

	# skip this key, if it has already been matched to another previous 
	#   record
	if (defined $checkedURLObjectKeys{$urlObjectKey}) { next; }

	# look to for other URLs with the same URL, this suggests that it is a
	#  modification of an existing URL

	if (defined $oldURLObjects{$urlObjectKey}) {

	    foreach my $newURLObjectKey (@allURLObjectKeys) {
		if ((defined $checkedURLObjectKeys{$newURLObjectKey})
		    || ($urlObjectKey eq $newURLObjectKey)) { next; }

		if (
		    (
		     (defined $newURLObjects{$newURLObjectKey}[0]) && 
		     ($oldURLObjects{$urlObjectKey}[0] 
		      eq $newURLObjects{$newURLObjectKey}[0])
		    )
		    ||
		    (
		     ($newURLObjects{$newURLObjectKey}[2] eq
		      $oldURLObjects{$urlObjectKey}[2]) && 
		     ($newURLObjects{$newURLObjectKey}[3] eq
		      $oldURLObjects{$urlObjectKey}[3])
		    )
		   ) {
		    my ($oldUrl, $oldWWWNm, $oldURLType) = @{$oldURLObjects{$urlObjectKey}};
		    my ($newUrl, $newWWWNm, $newURLType) = @{$newURLObjects{$newURLObjectKey}};

		    print MAIL qq/-D URL$urlCount = $oldUrl/, "\n";
		    print OUT qq/-D URL$urlCount = $oldUrl/, "\n";

		    print MAIL qq/-D WebTitle$urlCount = $oldWWWNm/, "\n";
		    print OUT qq/-D WebTitle$urlCount = $oldWWWNm/, "\n";

		    print MAIL qq/-D URLType$urlCount = $oldURLType/, "\n";
		    print OUT qq/-D URLType$urlCount = $oldURLType/, "\n";

		    print MAIL qq/URL$urlCount = $newUrl/, "\n";
		    print OUT qq/URL$urlCount = $newUrl/, "\n";

		    print MAIL qq/WebTitle$urlCount = $newWWWNm/, "\n";
		    print OUT qq/WebTitle$urlCount = $newWWWNm/, "\n";

		    print MAIL qq/URLType$urlCount = $newURLType/, "\n";
		    print OUT qq/URLType$urlCount = $newURLType/, "\n";

		    $checkedURLObjectKeys{$urlObjectKey} = 1;
		    $checkedURLObjectKeys{$newURLObjectKey} = 1;

		    $urlCount++;

		    last;
		}
	    }

	    if (!defined $checkedURLObjectKeys{$urlObjectKey}) {
		if (($oldURLObjects{$urlObjectKey}[2] eq "Other")
		    || ($oldURLObjects{$urlObjectKey}[2] eq "Research summary")
		    || ($oldURLObjects{$urlObjectKey}[2] eq "Lab")){

		    # if we got here, it means that $urlObjectKey is defined in the OLD list
		    #  only, but not the NEW list of URLs.  This probably means that it
		    #  should be deleted from the database

		    my ($oldUrl, $oldWWWNm, $oldURLType) = @{$oldURLObjects{$urlObjectKey}};
		    print MAIL qq/-D URL$urlCount = $oldUrl/, "\n";
		    print OUT qq/-D URL$urlCount = $oldUrl/, "\n";
		    print MAIL qq/-D WebTitle$urlCount = $oldWWWNm/, "\n";
		    print OUT qq/-D WebTitle$urlCount = $oldWWWNm/, "\n";
		    print MAIL qq/-D URLType$urlCount = $oldURLType/, "\n";
		    print OUT qq/-D URLType$urlCount = $oldURLType/, "\n";
		    $urlCount++;
		    $checkedURLObjectKeys{$urlObjectKey} = 1;
		}
	    }
	}
	elsif (defined $newURLObjects{$urlObjectKey}) {
	    # else, if it is defined in the NEW list only then it is a 
	    #   newly-added URL
	    my ($newUrl, $newWWWNm, $newURLType) = @{$newURLObjects{$urlObjectKey}};
	    print MAIL qq/URL$urlCount = $newUrl/, "\n";
	    print OUT qq/URL$urlCount = $newUrl/, "\n";
	    print MAIL qq/WebTitle$urlCount = $newWWWNm/, "\n";
	    print OUT qq/WebTitle$urlCount = $newWWWNm/, "\n";
	    print MAIL qq/URLType$urlCount = $newURLType/, "\n";
	    print OUT qq/URLType$urlCount = $newURLType/, "\n";
	    $urlCount++;
	    $checkedURLObjectKeys{$urlObjectKey} = 1;
	}
	else {
	    # this is a case in which a urlObject is present in the list of 
	    #   allURLObjects but not in the list of NEW or OLD URL objects.
	    #   Theoretically, this case should not happen, and represents 
	    #   a bug in this script.
	}
    }

    #########
    my (@OLDpi, %oldpiCount);
    my $piRef = $collObject->piRef; 
    foreach my $rowRef (@$piRef) { 
	my($colleagueNo, $lname, $fname, $suffix) = @$rowRef;
	my $oldpi = $lname.", ".$fname;
	push(@OLDpi, $oldpi);
	$oldpiCount{"\U$oldpi"}++;
    }
    my %newpiCount;
    for (my $i = 1; $i <= 2; $i++) {
      	if (!$self->{"_pi$i"}) { next; }
	my $newpi = $self->{"_pi$i"};
	if ($newpi =~ /^(.+),([a-zA-Z].*)$/) {
	    $newpi = "${1}, ${2}";
	}
	if ($newpi !~ /\,/) {
	    my @pi_tmp = split(/ /, $newpi);
	    my $pi_ltmp = pop(@pi_tmp);
	    my $pi_ftmp = join(' ', @pi_tmp);
	    $pi_ftmp =~ s/ ([a-zA-Z]) / $1\. /g;
	    $pi_ftmp =~ s/ ([a-zA-Z])$/ $1\./g;
	    $newpi = "${pi_ltmp}, ${pi_ftmp}";
	}
	if ($newpi) { $newpiCount{"\U$newpi"}++; }
	if (!$oldpiCount{"\U$newpi"}) {
	    print MAIL qq/Head_of_Lab = $newpi/, "\n" unless (!$newpi);
	    print OUT qq/Head_of_Lab = $newpi/, "\n" unless (!$newpi);
	}
    }
    if (@OLDpi) {
	foreach my $oldpi (@OLDpi) {
	    &DeleteUnwantedChar(\$oldpi);
	    if ($newpiCount{"\U$oldpi"}) {
		push(@comment_lines, "Head_of_Lab = $oldpi");
	    }
	    else {
		print MAIL qq/-D Head_of_Lab = $oldpi/, "\n" unless (!$oldpi);
		print OUT qq/-D Head_of_Lab = $oldpi/, "\n" unless (!$oldpi);
	    }    
	}
    }
    ##########
    if (defined $self->{'_pi_noLabMembers'}) {
	print MAIL qq/PI_without_Lab_Members = true/, "\n";
	print OUT qq/PI_without_Lab_Members = true/, "\n";
    }
    ##########
    my (%newcount, @NEWassocBYpi);
    for (my $i = 1; $i <= 10; $i++) {
	my $assoc = $self->{"_associate$i"};
	&DeleteUnwantedChar(\$assoc);
	if (!$assoc) { next; }
	$newcount{"\U$assoc"}++;	
	push(@NEWassocBYpi, $assoc);
    }
    my (%oldcount, @OLDassocBYpi);   
    my $associate4piRef = $collObject->associate4piRef; 
    foreach my $rowRef (@$associate4piRef) { 
	my($colleagueNo, $lname, $fname, $suffix) = @$rowRef;
	my $assoc = $lname.", ".$fname;
	&DeleteUnwantedChar(\$assoc);
	$oldcount{"\U$assoc"}++;
	if (!$newcount{"\U$assoc"}) {
	    print MAIL "-D PI ($assoc) = ", $self->{'_lname'}, ", ", $self->{'_fname'}, "\n";
            print OUT "-D PI ($assoc) = ", $self->{'_lname'}, ", ", $self->{'_fname'}, "\n";
            push(@OLDassocBYpi, $assoc);
        }
        else {
            push(@comment_lines, "PI ($assoc) = ".$self->{'_lname'}.", ".$self->{'_fname'});
	}
    }
    foreach my $assoc (@NEWassocBYpi) {           
        if (!$oldcount{"\U$assoc"}) {
	    print MAIL "PI ($assoc) = ", $self->{'_lname'}, ", ", $self->{'_fname'}, "\n";
	    print OUT "PI ($assoc) = ", $self->{'_lname'}, ", ", $self->{'_fname'}, "\n";
        }
    }
    my @OLDassoc;
    my $associateRef = $collObject->associateRef; 
    foreach my $rowRef (@$associateRef) { 
	my($colleagueNo, $lname, $fname, $suffix) = @$rowRef;
	my $assoc = $lname.", ".$fname;
	&DeleteUnwantedChar(\$assoc);
	if (!$oldcount{"\U$assoc"}) {
            push(@OLDassoc, $assoc);
        }
    }
    my (%newcount2, %oldcount2);
    for (my $i = 11; $i <= 20; $i++) {
	my $assoc = $self->{"_associate$i"};
	&DeleteUnwantedChar(\$assoc);
	if (!$assoc) { next; }
	$newcount2{"\U$assoc"}++;	
    }
    foreach my $rowRef (@$associateRef) { 
	my($colleagueNo, $lname, $fname, $suffix) = @$rowRef;
	my $assoc = $lname.", ".$fname;
	&DeleteUnwantedChar(\$assoc);
	if (!$newcount2{"\U$assoc"}) {
	    print MAIL "-D Associate = $assoc\n";
	    print OUT "-D Associate = $assoc\n";
	}
        else {
	    push(@comment_lines, "Associate = $assoc");
        }
        $oldcount2{"\U$assoc"}++;
    }
    for (my $i = 11; $i <= 20; $i++) {
	my $assoc = $self->{"_associate$i"};
	if ($assoc && !$oldcount2{"\U$assoc"}) {
	    print MAIL "Associate = $assoc\n";
	    print OUT "Associate = $assoc\n";
	}
    }
    ###########
    if ($collObject->interest ne $self->{'_interests'}) {	
	print MAIL qq/-D Research_interest = /, $collObject->interest, "\n" unless (!$collObject->interest);
	print MAIL qq/Research_interest = /, $self->{'_interests'}, "\n" unless (!$self->{'_interests'});
	print OUT qq/-D Research_interest = /, $collObject->interest, "\n" unless (!$collObject->interest);
	print OUT qq/Research_interest = /, $self->{'_interests'}, "\n" unless (!$self->{'_interests'});
    }
    elsif ($collObject->interest) {
	push(@comment_lines, "Research_interest = ".$collObject->interest);
    }
    ###########
    my $collResearchTopics = "";
    my $rtArrayRef = $collObject->researchTopicsRef;
    foreach my $rowRef (@$rtArrayRef) {
	my ($rt) = @$rowRef;
	$collResearchTopics .= "\t" . $rt;
    }
    if (length($collResearchTopics > 0)) { $collResearchTopics .= "\t" };

    if ($collResearchTopics ne $self->{'_researchTopics'}) {	
	print MAIL qq/-D ResearchTopics = /, $collResearchTopics, "\n" unless (!$collResearchTopics);
	print MAIL qq/ResearchTopics = /, $self->{'_researchTopics'}, "\n" 
	     unless (!$self->{'_researchTopics'});
	print OUT qq/-D ResearchTopics = /, $collResearchTopics, "\n" unless (!$collResearchTopics);
	print OUT qq/ResearchTopics = /, $self->{'_researchTopics'}, "\n" 
	     unless (!$self->{'_researchTopics'});
    }
    elsif ($collResearchTopics) {
	push(@comment_lines, "ResearchTopics = ".$collResearchTopics);
    }
    ###########
    my (@NEWkeyword, %newKWcount);
    for (my $i = 1; $i <= 10; $i++) {
	my $kw = $self->{"_keyword$i"};
	if (!$kw) { next; }
	push(@NEWkeyword, $kw);
	$newKWcount{"\U$kw"}++;
    }
    my %oldKWcount;
    my $keywordRef = $collObject->keywordRef; 
    foreach my $rowRef (@$keywordRef) { 
	my ($keyword) = @$rowRef;
	if (!$newKWcount{"\U$keyword"}) {
	    print MAIL qq/-D Keyword = $keyword/, "\n";
	    print OUT qq/-D Keyword = $keyword/, "\n";
	}
	else {
	    push(@comment_lines, "Keyword = $keyword");
	}
	$oldKWcount{"\U$keyword"}++;
    }
    foreach my $kw (@NEWkeyword) {
	if ($kw && !$oldKWcount{"\U$kw"}) {
	    print MAIL qq/Keyword = $kw/, "\n";
	    print OUT qq/Keyword = $kw/, "\n";
	}
    }
    ########
    if ($self->{'_associated_loci'}) {
	print OUT qq/Associated_Loci = /, $self->{'_associated_loci'}, "\n";
	print MAIL qq/Associated_Loci = /, $self->{'_associated_loci'}, "\n";
    }
    ########
    ## KD: added dictyBase contact stuff **
    if ($collObject->is_subscribed ne $self->{'_dictyBasecontact'}) {
    print MAIL qq/-D CONTACT4dictyBase = /, $collObject->is_subscribed, "\n";
    print MAIL qq/CONTACT4dictyBase = /, $self->{'_dictyBasecontact'}, "\n";
    print OUT qq/-D CONTACT4dictyBase = /, $collObject->is_subscribed, "\n";
    print OUT qq/CONTACT4dictyBase = /, $self->{'_dictyBasecontact'}, "\n";
    }
    elsif ($collObject->is_subscribed) {
	push(@comment_lines, "CONTACT4dictyBase = ".$collObject->is_subscribed);
    }
    ########
    if ($collObject->comment ne $self->{'_Comments'}) {
        print MAIL qq/-D Comments = /, $collObject->comment, "\n" unless (!$collObject->comment);
        print MAIL qq/Comments = /, $self->{'_Comments'}, "\n" unless (!$self->{'_Comments'});
	print OUT qq/-D Comments = /, $collObject->comment, "\n" unless (!$collObject->comment);
        print OUT qq/Comments = /, $self->{'_Comments'}, "\n" unless (!$self->{'_Comments'});
    }
    elsif ($collObject->comment) {
	push(@comment_lines, "Comments = ".$collObject->comment);   
    }
    print MAIL qq/Obtained_from = Direct Submission/, "\n";
    print OUT qq/Obtained_from = Direct Submission/, "\n";
    my $date = `date`;
    my @date = split(' ', $date);
    if (length($date[2]) == 1) {
        $date[2] = "0$date[2]";
    }
    print MAIL qq/Last_Update = $date[5]-$mon2num{$date[1]}-$date[2]/, "\n";
    print OUT qq/Last_Update = $date[5]-$mon2num{$date[1]}-$date[2]/, "\n";
    if (@comment_lines) {
	print MAIL "\n";
	print OUT "\n";
	foreach my $comment_line (@comment_lines) {
	    print MAIL "\/\/ $comment_line\n";
	    print OUT "\/\/ $comment_line\n";
        }
    }
 #   print MAIL "\n\nThe file is available at :\n";
 #   print MAIL $configPath->dataDir4web."submission/colleague/$pid.MajorUpdate\n";
  #  print MAIL "You may edit this file directly.\n\n";
  #  print MAIL "Please use following url to view, edit and commit this file into database\n";
   # print MAIL $configUrl->dictyBaseCGIRoot."$dblink/colleague/CommitMajorUpdate?id=$pid\n";
    close(OUT);
    if (param('registerType')) {
	$self->createGeneRegistryFile;
    }
    close(MAIL);
    $self->removeTMP(param('pid'));
    &printEndPage;
}

########################################################################
sub createGeneRegistryFile {
########################################################################
    my ($self) = @_;
    my $dbname = $self->database;
    my $pid = param('pid');
    $dbname = "\U$dbname";
    open(OUT2, ">".$configPath->dataDir4web."submission/colleague/$pid.GeneRegistry4ace") || print "geneRegistry2: Can't open '$pid.GeneRegistry4ace' for writing:$!\n";
    if (param('registerType') =~ /Reservation/i) {
	print OUT2 qq/Type "Gene Registry"/, "\n";
    }
    else {
	print OUT2 qq/Type "Gene Update"/, "\n";
    }
    print OUT2 qq/LName "/, $self->{'_lname'}, qq/"/, "\n";
    print OUT2 qq/FName "/, $self->{'_fname'}, qq/"/, "\n";
    if ($self->{'_suffix'}) {
	 print OUT2 qq/Suffix "/, $self->{'_suffix'}, qq/"/, "\n";
    }
    if ($self->{'_oname'}) {
	print OUT2 qq/Other_Name "/, $self->{'_oname'}, qq/"/, "\n";
    }
    print OUT2 qq/Internet "/, $self->{'_email'}, qq/"/, "\n";
    print MAIL "\nGene Registry info:\n\n";
    if ($self->{'_gene'}) {
	print MAIL qq/Locus "/, $self->{'_gene'}, qq/"/, "\n";
	print OUT2 qq/Locus "/, $self->{'_gene'}, qq/"/, "\n";
    }
    if ($self->{'_genedesc'}) {
	print MAIL qq/Description "/, $self->{'_genedesc'}, qq/"/, "\n";
	print OUT2 qq/Description "/, $self->{'_genedesc'}, qq/"/, "\n"
    }
    if ($self->{'_orf'}) {
	print MAIL qq/ORF_name "/, $self->{'_orf'}, qq/"/, "\n";
	print OUT2 qq/ORF_name "/, $self->{'_orf'}, qq/"/, "\n"
    }
    if ($self->{'_othergene'}) {
	print MAIL qq/Alias "/, $self->{'_othergene'}, qq/"/, "\n";
	print OUT2 qq/Alias "/, $self->{'_othergene'}, qq/"/, "\n"
    }
    if ($self->{'_geneproduct'}) {
	print MAIL qq/Gene_product "/, $self->{'_geneproduct'}, qq/"/, "\n";
	print OUT2 qq/Gene_product "/, $self->{'_geneproduct'}, qq/"/, "\n"
    }
    if ($self->{'_nullphenotype'}) {
	print MAIL qq/Null_Phenotype "/, $self->{'_nullphenotype'}, qq/"/, "\n";
	print OUT2 qq/Null_Phenotype "/, $self->{'_nullphenotype'}, qq/"/, "\n"
    }
    if ($self->{'_otherphenotype'}) {
	print MAIL qq/Other_Phenotype "/, $self->{'_otherphenotype'}, qq/"/, "\n";
	print OUT2 qq/Other_Phenotype "/, $self->{'_otherphenotype'}, qq/"/, "\n"
    }
    for (my $i = 1; $i <= 6; $i++) {
	if (!$self->{"_author$i"}) { next; }
	print MAIL qq/Author$i "/, $self->{"_author$i"}, qq/"/, "\n";
	print OUT2 qq/Author$i "/, $self->{"_author$i"}, qq/"/, "\n";
    }
    if ($self->{'_Reftitle'}) {
	print MAIL qq/Title "/, $self->{'_Reftitle'}, qq/"/, "\n";
	print OUT2 qq/Title "/, $self->{'_Reftitle'}, qq/"/, "\n";
    }
    if ($self->{'_journal'}) {
	print MAIL qq/Journal "/, $self->{'_journal'}, qq/"/, "\n";
	print OUT2 qq/Journal "/, $self->{'_journal'}, qq/"/, "\n";
    }
    if ($self->{'_volume'}) {
	print MAIL qq/Volume "/, $self->{'_volume'}, qq/"/, "\n";
	print OUT2 qq/Volume "/, $self->{'_volume'}, qq/"/, "\n";
    }
    if ($self->{'_pages'}) {
	print MAIL qq/Page "/, $self->{'_pages'}, qq/"/, "\n";
	print OUT2 qq/Page "/, $self->{'_pages'}, qq/"/, "\n";
    }
    if ($self->{'_year'}) {
	print MAIL qq/Year "/, $self->{'_year'}, qq/"/, "\n";
	print OUT2 qq/Year "/, $self->{'_year'}, qq/"/, "\n";
    }
    if ($self->{'_pubmed'}) {
	print MAIL qq/PubMed "/, $self->{'_pubmed'}, qq/"/, "\n";
	print OUT2 qq/PubMed "/, $self->{'_pubmed'}, qq/"/, "\n";
    }
    if ($self->{'_reftype'}) {
	print MAIL qq/ref_type "/, $self->{'_reftype'}, qq/"/, "\n";
	print OUT2 qq/ref_type "/, $self->{'_reftype'}, qq/"/, "\n";
    }
    if ($self->{'_registryComment'}) {
	print MAIL qq/Comments "/, $self->{'_registryComment'}, qq/"/, "\n";
	print OUT2 qq/Comments "/, $self->{'_registryComment'}, qq/"/, "\n";
    }
    close(OUT2);
}

########################################################################
sub presentInfo2User {
########################################################################
    my ($self) = @_;

    
    my $desc = "Your submission will be processed within 1-2 business days, and you will receive a confirmation e-mail at that time. ";

    my $text;
    if (!$self->{'_institution'}) { #### reserve another gene

	$text = "Thank you for your ";

    }
    else {

	$desc .= font({-color=>'red'}, "Below is a preview of how your entry will appear in dictyBase").". If you would like to make changes to this entry, click on the \"Edit (Go Back)\" button.";

	$text = "Thank you for your submission of dictyBase colleague and ";
    }

    if (param('registerType') =~ /Reservation/i) {
	$text .= "Gene Reservation"
    }
    elsif (param('registerType')) {
	$text .= "Gene Update";
    }
    $text .= " information!"; 

    print p, table({-align=>'center', 
		    -cellspacing=>'3',
		    -border=>'0',
		    -cellpadding=>'0',
		    -width=>'600'},
		   Tr(td({-align=>'center'},
			 font({-size=>'+1'},
			      $text))).
		   Tr(td(br)).
		   Tr(td($desc)));

    if (!$self->{'_institution'}) { ### reserve another gene 

	$self->printGeneRegistryInfo2user;
	return;
    }

    
    #################### display colleague page ####################
    my $fullname;
    if (!$self->{'_suffix'}) {
	$fullname = $self->{'_fname'}." ".$self->{'_lname'};
    }
    elsif ($self->{'_suffix'} =~ /\./) {
	$fullname = $self->{'_fname'}." ".$self->{'_lname'}.", ".$self->{'_suffix'};
    }
    else {
	$fullname = $self->{'_fname'}." ".$self->{'_lname'}." ".$self->{'_suffix'};
    }
    print hr, br, table({-align=>'center',
			 -border=>'0',
			 -cellpadding=>'0',
			 -cellspacing=>'3',
			 -width=>'600'},
			Tr(td({-align=>'center'},
			      font({-size=>'+3'},
				   b($fullname))))),p;

    my @displayName;
    my @displayValue;
    #### other name
    if ($self->{'_oname'}) {
	push(@displayName, "Other Name");
	push(@displayValue, $self->{'_oname'});
    }
    #### email
    $self->{'_email'} =~ s/[,;\t]/ /g;
    $self->{'_email'} =~ s/ +/ /g;
    my @email = split(/ /, $self->{'_email'});
    my $emailValue;
    foreach my $email (@email) {
	if ($emailValue) { $emailValue .= br; }
	$emailValue .= a({-href=>"mailto:$email"}, $email);
    }
    if ($emailValue) {
	push(@displayName, "E-mail Address");
	push(@displayValue, $emailValue);
    }
    #### job title
    if ($self->{'_jobtitle'}) {
	push(@displayName, "Position");
	push(@displayValue, $self->{'_jobtitle'});
    }
    #### profession
    if ($self->{'_profession'}) {
	push(@displayName, "Profession");
	push(@displayValue, $self->{'_profession'});
    }
    #### organization
    if ($self->{'_institution'}) {
	push(@displayName, "Organization");
	push(@displayValue, $self->{'_institution'});
    }
    #### address
    my $addressValue;
    for (my $i = 1; $i <= 5; $i++) {
	if (!$self->{"_address$i"}) { next; }
	if ($addressValue) { $addressValue .= br; }
	$addressValue .= $self->{"_address$i"};
    }
    if ($self->{'_city'}) {
	if ($addressValue) { $addressValue .= br; }
	$addressValue .= $self->{'_city'};
    }
    
    if ($self->{'_state'} or $self->{'_region'} or $self->{'_zip_code'}) {
	my $state;
	if ($self->{'_state'}) { $state = $self->{'_state'}; }
	else { $state = $self->{'_region'}; }
	if ($self->{'_zip_code'}) {
	    if ($state) { $state .= " "; }
	    $state .= $self->{'_zip_code'};
	}
	if (!$addressValue) { $addressValue = $state; }
	elsif ($self->{'_city'}) {
	    $addressValue .= ", ".$state;
	}
	else {
	    $addressValue .= br.$state;
	}
    }
    if ($self->{'_country'}) {
	if ($addressValue) { $addressValue .= br; }
	$addressValue .= $self->{'_country'};
    }
    if ($addressValue) {
	push(@displayName, "Address");
	push(@displayValue, $addressValue);
    }
    #### phone
    my ($phoneValue, $faxValue, $mobileValue, $pagerValue, $telexValue);
    for (my $i = 1; $i <= 5; $i++) {
	if (!$self->{"_phone$i"}) { next; }
	my ($location, $type) = split(/ /, $self->{"_phone_type$i"});
	if (!$type) { 
	    $type = $location;
	    $location = "";
	}
	else {
	    $location = "(".$location.")";
	}    
	if ($type =~ /^phone/i) {
	    if ($phoneValue) { $phoneValue .= br; }
	    $phoneValue .= $self->{"_phone$i"}." ".$location; 
	}
	elsif ($type =~ /^fax/i) {
	    if ($faxValue) { $faxValue .= br; }
	    $faxValue .= $self->{"_phone$i"}." ".$location;
	}
	elsif ($type =~ /^mobile/i) {
	    if ($mobileValue) { $mobileValue .= br; }
	    $mobileValue .= $self->{"_phone$i"}." ".$location;
	}
	elsif ($type =~ /^pager/i) {
	    if ($pagerValue) { $pagerValue .= br; }
	    $pagerValue .= $self->{"_phone$i"}." ".$location;
	}
	elsif ($type =~ /^telex/i) {
	    if ($telexValue) { $telexValue .= br; }
	    $telexValue .= $self->{"_phone$i"}." ".$location;
	}
    }
    if ($phoneValue) {
	push(@displayName, "Phone");
	push(@displayValue, $phoneValue);
    }
    if ($faxValue) {
	push(@displayName, "Fax");
	push(@displayValue, $faxValue);
    }
    if ($mobileValue) {
	push(@displayName, "Mobile");
	push(@displayValue, $mobileValue);
    }
    if ($pagerValue) {
	push(@displayName, "Pager");
	push(@displayValue, $pagerValue);
    }
    if ($telexValue) {
	push(@displayName, "Telex");
	push(@displayValue, $telexValue);
    }
    #### url
    my ($labUrls, $researchSummaryUrls, $otherUrls);
    for (my $i = 0; $i <= 10; $i++) {
	if (!$self->{"_url$i"}) { next; }
	my $url = $self->{"_url$i"};
	if ($self->{"_url_type$i"} =~ /^Research Summary/i) {
	    $researchSummaryUrls .= a({-href=>"$url"}, "Research Summary").br;
	}
	elsif ($self->{"_url_type$i"} =~ /^Lab/i) {
	    ### if needed, the display name can be changed to page title
	    $labUrls .= a({-href=>"$url"}, $url).br;
	}
	else {
	    ### if needed, the display name can be changed to page title
	    $otherUrls .= a({-href=>"$url"}, $url).br;
	}
    }
    my $urlValue = $labUrls.$researchSummaryUrls.$otherUrls;
    if ($urlValue) {
	push(@displayName, "Web Page(s)");
	push(@displayValue, $urlValue);
    }
    #### PI
    my $PIvalue;
    foreach my $pi ($self->{'_pi1'}, $self->{'_pi2'}) {
	if (!$pi) { next; }
	my($plname, $pfname) = split(/,/, $pi);
	$pfname =~ s/^ //;
        $pi = $pfname." ".$plname;
	if ($PIvalue) { $PIvalue .= br; }
	$PIvalue .= $pi;
    }
    if ($PIvalue) {
	push(@displayName, "Head of Lab");
	push(@displayValue, $PIvalue);
    }
    #### lab members
    my $assocsBYpiValue;
    for (my $i = 1; $i <= 10; $i++) {
    	if ($self->{"_associate$i"}) {
	    my ($alname, $afname) = split(/,/, $self->{"_associate$i"});
	    $afname =~ s/^ //;
	    my $assoc = $afname." ".$alname;
	    if ($assocsBYpiValue) { $assocsBYpiValue .= br; }
	    $assocsBYpiValue .= $assoc;
    	}
    }
    if ($assocsBYpiValue) {
	push(@displayName, "Members of my Lab");
	push(@displayValue, $assocsBYpiValue);
    }

    #### Associates/Collaborators
    my $assocsValue;
    for (my $i = 11; $i <= 20; $i++) {
    	if ($self->{"_associate$i"}) {
	    my ($alname, $afname) = split(/,/, $self->{"_associate$i"});
	    $afname =~ s/^ //;
	    my $assoc = $afname." ".$alname;
	    if ($assocsValue) { $assocsValue .= br; }
	    $assocsValue .= $assoc;
    	}
    }
    if ($assocsValue) {
	push(@displayName, "Associates/Collaborators");
	push(@displayValue, $assocsValue);
    }

    my $researchTopics;
    my $rtOther;
    if ($self->{"_researchTopics"}) {
	foreach my $topic (split(/\t+/, $self->{"_researchTopics"})) {
	    if (!$topic) { next; }
	    if ($topic =~ /^Other/i) { $rtOther++; next; }
	    if ($researchTopics) { $researchTopics .= br; }
	    $researchTopics .= $topic;	
	}
    }
    if ($rtOther) {
	if ($researchTopics) { $researchTopics .= br; }
	$researchTopics .= "Other"; 
    }
    
    $self->{'_Comments'} =~ s/\\n/\<BR\>/g;

    my $keyword;
    for (my $i = 1; $i <= 10; $i++) {
	if (!$self->{"_keyword$i"}) { next; }
	if ($keyword) { $keyword .= br; }
	$keyword .= $self->{"_keyword$i"};
    }

    my $displayContent;
    for (my $i = 0; $i <=$#displayName; $i++) {
	my $line;
	if ($displayValue[$i] !~ /.br./) {
	    $line = td({-width=>'25%',
			-bgcolor=>'#a4abc2'},
		       $displayName[$i]);
        }
	else {
	    $line = td({-width=>'25%',
			-bgcolor=>'#a4abc2',
			-valign=>'top'},
		       $displayName[$i]);
        }
	$line .= td({-width=>'5%'}, br).
	         td({-width=>'40%'},
		    $displayValue[$i]);
	if ($i == 0 && ($self->{'_Comments'} ||$keyword)){
	    my $rightCell;
	    if ($self->{'_Comments'}) {
		$rightCell .= Tr(td({-align=>'center',
				    -bgcolor=>'#a4abc2'},
				 "Public Comments")).
		              Tr(td({-align=>'left',
				     -bgcolor=>'#d8d8d8'},
				    $self->{'_Comments'})).
			      Tr(td(br));
	    }
	    if ($keyword) {
		$rightCell .= Tr(td({-align=>'center',
				    -bgcolor=>'#a4abc2'},
				    "Keywords")).
			      Tr(td({-align=>'left',
				     -bgcolor=>'#d8d8d8'},
				    $keyword)).
			      Tr(td(br));
	    }  
	    $line .= td({-width=>'30%',
			 -rowspan=>'20',
			 -valign=>'top'},
			table({-border=>'0',
			       -width=>'170'},
			      $rightCell));
	}
	$displayContent .= Tr($line);
    }
    print table({-align=>'center',
	         -border=>'0',
		 -cellpadding=>'2',
		 -cellspacing=>'3',
		 -width=>'600'},
		$displayContent);

    if ($researchTopics) {
	print p, table({-align=>'center',
			-border=>'0',
			-cellpadding=>'0',
			-cellspacing=>'3',
			-width=>'600'},
		       Tr(td({-align=>'left',
			      -bgcolor=>'#a4abc2'},
			     "Research Topics"))),
		 table({-align=>'center',
			-border=>'0',
			-cellpadding=>'0',
			-cellspacing=>'3',
			-width=>'600'},
		       Tr(td({-align=>'left'},
			     $researchTopics))), br;
    }

    if ($self->{'_interests'}) {
	print p, table({-align=>'center',
			-border=>'0',
			-cellpadding=>'0',
			-cellspacing=>'3',
			-width=>'600'},
		       Tr(td({-align=>'left',
			      -bgcolor=>'#a4abc2'},
			     "Research Interests"))),
	         table({-align=>'center',
			-border=>'0',
			-cellpadding=>'0',
			-cellspacing=>'3',
			-width=>'600'},
		       Tr(td({-align=>'left'},
			     $self->{'_interests'})));
    }

    print p, table({-align=>'center',
		 -width=>'600'},
		Tr(td({-align=>'center'},
		      font({-size=>'+2'},
			   start_form.
			   hidden(-name=>'pid',
				  -value=>param('pid')).
			   hidden(-name=>'id',
				  -value=>$self->colleagueNo).
			   hidden(-name=>'back',
				  -value=>'1').
			   hidden(-name=>'registerType',
				  -value=>param('registerType')).
			   submit(-name=>'submit',
				  -value=>'Edit (Go Back)').
			   end_form))));

    $self->printGeneRegistryInfo2user;

}

##########################################################################
sub printGeneRegistryInfo2user {
##########################################################################
    my ($self) = @_;
    #################### display gene registry info ################

    if (!param('registerType')) { return; }

    if (param('registerType') =~ /Reservation/i) {
	print hr, p, center(font({-size=>'+4'}, "Gene Reservation Info")),p;
    }
    else {
	print hr, p, center(font({-size=>'+4'}, "Update Gene Info")),p;
    }    
    my $info;
    if ($self->{'_gene'}) {
	$info .= li("Proposed Gene Name = ".$self->{'_gene'});
    }
    if ($self->{'_genedesc'}) {
	$info .= li("Description of Gene Name Acronym = ".$self->{'_genedesc'});
    }
    if ($self->{'_orf'}) {
	$info .= li("ORF Name = ".$self->{'_orf'});
    }
    if ($self->{'_othergene'}) {
	$info .= li("Other Gene Name(s) = ".$self->{'_othergene'});
    }
    if ($self->{'_geneproduct'}) {
	$info .= li("Gene Product = ".$self->{'_geneproduct'});
    }
    if ($self->{'_nullphenotype'}) {
	$info .= li("Null Phenotypes = ".$self->{'_nullphenotype'});
    }
    if ($self->{'_otherphenotype'}) {
	$info .= li("Other Phenotypes = ".$self->{'_otherphenotype'});
    }
    for (my $i = 1; $i <= 6; $i++) {
	if ($self->{"_author$i"}) {
	    $info .= li("Author = ".$self->{"_author$i"});
	}
    }
    if ($self->{'_Reftitle'}) {
	$info .= li("Title = ".$self->{'_Reftitle'});
    }
    if ($self->{'_journal'}) {
	$info .= li("Journal = ".$self->{'_journal'});
    }
    if ($self->{'_volume'}) {
	$info .= li("Volume = ".$self->{'_volume'});
    }
    if ($self->{'_pages'}) {
	$info .= li("Page Numbers = ".$self->{'_pages'});
    }
    if ($self->{'_year'}) {
	$info .= li("Year = ".$self->{'_year'});
    }
    if ($self->{'_pubmed'}) {
	$info .= li("PubMed ID = ".$self->{'_pubmed'});
    }
    if ($self->{'_reftype'}) {
	$info .= li("Ref Type = ".$self->{'_reftype'});
    }
    if ($self->{'_registryComment'}) {
	$info .= li("Gene Name Comments = ".$self->{'_registryComment'});
    }
    ##############################
    print ul($info),p;

    print hr, p, b("If you want to reserve or register another gene name or submit information about another existing gene, click on 'Reserve Another Gene' button."),p;
    print table(Tr(td(b(start_form(-action=>$configUrl->dictyBaseCGIRoot."$dblink/registry/geneRegistry", 
				   -method=>'POST').
			hidden(-name=>'lname', 
			       -value=>$self->{'_lname'}).
			hidden(-name=>'fname', 
			       -value=>$self->{'_fname'}).
			hidden(-name=>'email', 
			       -value=>$self->{'_email'}).
			submit(-name=>'submit',
			       -value=>'Reserve Another Gene').
			end_form)))),p;
	      
}

########################################################################
sub writeContactInfo {
########################################################################
    my ($self) = @_;
    my $pid = $self->pid;
    open(CONTACT, ">".$configPath->tmpDir."contact.${pid}.tmp") 
	|| die "Can't open '".$configPath->tmpDir."contact.${pid}.tmp' for writing:$!\n";
    ## KD: added dictyBase contact stuff
    if (param('dictyBasecontact')) {
	print CONTACT "isdictyBasecontact = ", param('dictyBasecontact'), "\n";
	$self->{'_dictyBasecontact'} = param('dictyBasecontact');
    }
    if (param('lname')) {
	print CONTACT "last_name = ", param('lname'), "\n";
	$self->{'_lname'} = param('lname');
    }
    if (param('fname')) {
	print CONTACT "first_name = ", param('fname'), "\n";
	$self->{'_fname'} = param('fname');
    }
    if (param('suffix')) {
	print CONTACT "suffix = ", param('suffix'), "\n";
	$self->{'_suffix'} = param('suffix');
    }
    if (param('oname')) {
	print CONTACT "other_name = ", param('oname'), "\n";
	$self->{'_oname'} = param('oname');
    }
    if (param('email')) {
	print CONTACT "internet = ", param('email'), "\n";
	$self->{'_email'} = param('email');
    }
    if (param('jobtitle')) {
	print CONTACT "jobtitle = ", param('jobtitle'), "\n";
	$self->{'_jobtitle'} = param('jobtitle');
    }
    if (param('profession')) {
	print CONTACT "profession = ", param('profession'), "\n";
	$self->{'_profession'} = param('profession');
    }
    if (param('institution')) {
	print CONTACT "institution = ", param('institution'), "\n";
	$self->{'_institution'} = param('institution');
    }
    my $j;
    for (my $i = 1; $i <= 5; $i++) {
	if (param("addr$i")) {
	    $j++;
	    print CONTACT "address = ", param("addr$i"), "\n";
	    $self->{"_address$j"} = param("addr$i");
	}
    }
    if (param('city')) {
	print CONTACT "city = ", param('city'), "\n";
	$self->{'_city'} = param('city');
    }
    if (param('USAstate') && param('USAstate') !~ /USA State/i) {
	print CONTACT "state = ", param('USAstate'), "\n";
	$self->{'_state'} = param('USAstate');
    }
    elsif (param('CanadaPro') && 
	   param('CanadaPro') !~ /Canadian Province/i) {
	print CONTACT "state = ", param('CanadaPro'), "\n";
	$self->{'_state'} = param('CanadaPro');
    }
    if (param('region')) {
	print CONTACT "region = ", param('region'), "\n";
	$self->{'_region'} = param('region');
    }
    if (param('country')) {
	print CONTACT "country = ", param('country'), "\n";
	$self->{'_country'} = param('country');
    }
    elsif (param('USAstate')) {
	print CONTACT "country = USA\n";
	$self->{'_country'} = "USA";
    }
    elsif (param('CanadaPro')) {
	print CONTACT "country = Canada\n";
	$self->{'_country'} = "Canada";
    }
    if (param('zip_code')) {
	print CONTACT "zip_code = ", param('zip_code'), "\n";
	$self->{'_zip_code'} = param('zip_code');
    }
    my $j;
    for(my $i = 1; $i <= 5; $i++) {
        if (param("phone$i")) {
	    $j++;
	    print CONTACT param("phone_type$i")," = ", 
	                  param("phone$i"), "\n";
	    $self->{"_phone_type$j"} = param("phone_type$i");
	    $self->{"_phone$j"} = param("phone$i");
	}
    }

    my $urlCount = 0;
    for (my $counter = 0; $counter < $numUrls; $counter++) {
      if (param("url$counter") && (param("url_type$counter") 
				   !~ /Please specify/)) {

	# note, this line relies on that fact that the url_type field will not
        #  contain any commas in it; as the comma/space combination is used 
        #  as a delimiter between url_type and url fields
	print CONTACT "url$urlCount", " = ",
	              param("url$counter"), "\n";
	print CONTACT "url_type$urlCount", " = ",
	              param("url_type$counter"), "\n";
	$self->{"_url_type$urlCount"} = param("url_type$counter");
	$self->{"_url$urlCount"} = param("url$counter");

	$urlCount++;
      }
    }

    if (param('associated_loci')) {
	print CONTACT "associated_loci = " . param('associated_loci');
	$self->{'_associated_loci'} = param('associated_loci');
    }

    close (CONTACT);
}

########################################################################
sub writeAssociateInfo {
########################################################################
    my ($self) = @_;
    my $pid = $self->pid;
    my @pilist = (param('PILIST0'), param('PILIST1')); 
    my $pi = param('pi');
    my @assocs;
    for (my $i = 1; $i <= 20; $i++) {
	$assocs[$i] = param("associate$i");
    }
    if (!@pilist && !@assocs) { return; }
    open(ASSOCIATE, ">".$configPath->tmpDir."associate.${pid}.tmp") 
	|| die "Can't open '".$configPath->tmpDir."associate.${pid}.tmp' for writing:$!\n";
    if (@pilist) {
	my $j;
	for (my $i = 0; $i <= $#pilist; $i++) {
 	    if ($pilist[$i]) {
		$j++;
 		print ASSOCIATE "PI = $pilist[$i]\n";
		$self->{"_pi$j"} = $pilist[$i];
 	    }
 	}
    }
    if (@assocs) {
	for (my $i = 1; $i <= 20; $i++) {
	    if ($assocs[$i]) {
		print ASSOCIATE "associate$i = $assocs[$i]\n";
		$self->{"_associate$i"} = $assocs[$i];
	    }
	}
    }
    if ($pi eq "true") { # indicate if this is a PI without any students,
	                 #   post-docs or technicians
	print ASSOCIATE "primaryInvestigator_noLabMembers = true\n";
	$self->{'_pi_noLabMembers'} = 1;
    }
    close (ASSOCIATE);
}

########################################################################
sub writeInterestInfo {
########################################################################
    my ($self) = @_;
    my $pid = $self->pid;
    if (!param('interests')) { return; }
    my $pid = $self->pid;
    open(INTEREST, ">".$configPath->tmpDir."interest.${pid}.tmp") 
	|| die "Can't open '".$configPath->tmpDir."interest.${pid}.tmp' for writing:$!\n";
    print INTEREST "interests = ", param('interests'), "\n";
    $self->{'_interests'} = param('interests');
    close(INTEREST);
}

########################################################################
sub writeKeywordInfo {
########################################################################
    my ($self) = @_;
    my @kw;
    for (my $i = 1; $i <= 10; $i++) {
	push(@kw, param("keyword$i"));
    }
    if (!@kw) { return; }

    my $collResearchTopics;
    foreach my $researchTopic (split(/\t/, &getCDKeywords($dbh))) {
	if (param("$researchTopic")) {
	    $collResearchTopics .= "\t" . $researchTopic . "\t";
	}
    }
    $collResearchTopics =~ s/\t+/\t/g;
    $collResearchTopics =~ s/^\t//;

    my $pid = $self->pid;
    open(KEYWORD, ">".$configPath->tmpDir."keyword.${pid}.tmp") 
	|| die "Can't open '".$configPath->tmpDir."keyword.${pid}.tmp' for writing:$!\n";
    my $i;
    if (@kw) {
	foreach my $kw (@kw) {
	    if ($kw) {
		$i++;
		print KEYWORD "keyword = $kw\n";
		$self->{"_keyword$i"} = $kw;
	    }
	}
    }

    if ($collResearchTopics) {
	print KEYWORD "ResearchTopics = $collResearchTopics\n";
	$self->{"_researchTopics"} = $collResearchTopics;
    }
    close(KEYWORD);
}

########################################################################
sub writeCommentInfo {
########################################################################
    my ($self) = @_;
    if (!param('Comments')) { return; }
    my $userComments = param('Comments');
    $userComments =~ s/\n/\\n/g;
    my $pid = $self->pid;
    open(COMMENT, ">".$configPath->tmpDir."comment.${pid}.tmp") 
	|| die "Can't open '".$configPath->tmpDir."comment.${pid}.tmp' for writing:$!\n";
    print COMMENT "Comments = ", $userComments, "\n";
    $self->{'_Comments'} = $userComments;
    close(COMMENT);
}

#########################################################################
sub writeGeneInfo {
#########################################################################
    my ($self) = @_;
    my $pid = $self->pid;
    open(GENEINFO, ">".$configPath->tmpDir."geneinfo.${pid}.tmp") 
	|| die "Can't open '".$configPath->tmpDir."geneinfo.${pid}.tmp' for writing:$!\n";
    if (param('gene')) {
	print GENEINFO "gene = ", param('gene'), "\n";
	$self->{'_gene'} = param('gene');
    }
    if (param('orf')) {
	print GENEINFO "orf = ", param('orf'), "\n";
	$self->{'_orf'} = param('orf');
    }
    if (param('genedesc')) {
	print GENEINFO "genedesc = ", param('genedesc'), "\n";
	$self->{'_genedesc'} = param('genedesc');
    }
    if (param('othergene')) {
	print GENEINFO "othergene = ", param('othergene'), "\n";
	$self->{'_othergene'} = param('othergene');
    }
    if (param('geneproduct')) {
	print GENEINFO "geneproduct = ", param('geneproduct'), "\n";
	$self->{'_geneproduct'} = param('geneproduct');
    }
    if (param('nullphenotype')) {
	print GENEINFO "nullphenotype = ", param('nullphenotype'), "\n";
	$self->{'_nullphenotype'} = param('nullphenotype');
    }
    if (param('otherphenotype')) {
	print GENEINFO "otherphenotype = ", param('otherphenotype'), "\n";
	$self->{'_otherphenotype'} = param('otherphenotype');
    }
    close(GENEINFO);
}

####################################################################
sub writeGeneReferenceInfo {
####################################################################
    my($self) = @_;
    my $pid = $self->pid;
    open(REF, ">".$configPath->tmpDir."genereference.${pid}.tmp") 
	|| die "Can't open '".$configPath->tmpDir."genereference.${pid}.tmp' for writing:$!\n";
    for (my $i = 1; $i <= 12; $i++) {
	if (param("author$i")) {
	    print REF "author$i = ", param("author$i"), "\n";
	    $self->{"_author$i"} = param("author$i");
	}
    }
    if (param('Reftitle')) {
	print REF "Reftitle = ", param('Reftitle'), "\n";
	$self->{'_Reftitle'} = param('Reftitle');
    }
    if (param('journal')) {
	print REF "journal = ", param('journal'), "\n";
	$self->{'_journal'} = param('journal');
    }
    if (param('volume')) {
	print REF "volume = ", param('volume'), "\n";
	$self->{'_volume'} = param('volume');
    }
    if (param('pages')) {
	print REF "pages = ", param('pages'), "\n";
	$self->{'_pages'} = param('pages');
    }
    if (param('year')) {
	print REF "year = ", param('year'), "\n";
	$self->{'_year'} = param('year');
    }
    if (param('pubmed')) {
	print REF "pubmedid = ", param('pubmed'), "\n";
	$self->{'_pubmed'} = param('pubmed');
    }
    if (param('reftype')) {
	print REF "reftype = ", param('reftype'), "\n";
	$self->{'_reftype'} = param('reftype');
    }
    close(REF);
}

########################################################################
sub writeGeneCommentInfo {
########################################################################
    my($self) = @_;
    if (!param('registryComment')) { return; }
    my $pid = $self->pid;
    open(GeneComment, ">".$configPath->tmpDir."genecomment.${pid}.tmp") 
	|| die "Can't open '".$configPath->tmpDir."genecomment.${pid}.tmp' for writing:$!\n";
    print GeneComment "registryComment = ", param('registryComment'), "\n";
    $self->{'_registryComment'} = param('registryComment');
    close(GeneComment);
}

#########################################################################
sub readContactInfo {
#########################################################################
    my($self) = @_;
    my $pid = $self->pid;
    open(CONTACT, $configPath->tmpDir."contact.${pid}.tmp") 
	|| die "Can't open '".$configPath->tmpDir."contact.${pid}.tmp' for reading:$!\n";
    my ($i4addr, $i4phone);
    while(<CONTACT>) {
	chomp;
	my ($name, $value) = split(/ = /);
	&DeleteUnwantedChar(\$name);
	&DeleteUnwantedChar(\$value);
	## KD: added dictyBase contact stuff
	if ($name =~ /dictyBasecontact/i) {
	    $self->{'_dictyBasecontact'} = $value;
	}
	elsif ($name =~ /last_name/i) {
	    $self->{'_lname'} = $value;
	}
	elsif ($name =~ /first_name/i) {
	    $self->{'_fname'} = $value;
	}
	elsif ($name =~ /suffix/i) {
	    $self->{'_suffix'} = $value;
	}
	elsif ($name =~ /other_name/i) {
	    $self->{'_oname'} = $value;
	}
	elsif ($name =~ /internet/i) {
	    $self->{'_email'} = $value;
	}
        elsif ($name =~ /jobtitle/i) {
	    $self->{'_jobtitle'} = $value;
	}
        elsif ($name =~ /profession/i) {
	    $self->{'_profession'} = $value;
	}
        elsif ($name =~ /institution/i) {
	    $self->{'_institution'} = $value;
	}
        elsif ($name =~ /address/i) {
	    $i4addr++;
	    $self->{"_address$i4addr"} = $value;
	}
        elsif ($name =~ /city/i) {
	    $self->{'_city'} = $value;
	}
        elsif ($name =~ /state/i) {
	    $self->{'_state'} = $value;
	}
        elsif ($name =~ /region/i) {
	    $self->{'_region'} = $value;
	}
        elsif ($name =~ /country/i) {
	    $self->{'_country'} = $value;
	}
        elsif ($name =~ /zip_code/i) {
	    $self->{'_zip_code'} = $value;
	}
        elsif ($name =~ /url(\d)/i) {

	    # print "\n\n<!-- Encountered a url: $_ -->\n\n"; 

	    $self->{"_url$1"} = $value;
	}
        elsif ($name =~ /url_type(\d)/i) {
	    $self->{"_url_type$1"} = $value;
	}
        elsif ($name =~ /(phone|fax|mobile|pager|telex|specify)/i) {
	    $i4phone++;
	    $self->{"_phone_type$i4phone"} = $name;
	    $self->{"_phone$i4phone"} = $value;
	}
	elsif ($name =~ /associated_loci/i) {
	    $self->{'_associated_loci'} = $value;
	}
    }
    close(CONTACT);
}

####################################################################
sub readAssociateInfo {
####################################################################
    my ($self) = @_;
    my $pid = $self->pid;
    my ($i4pi, $i4assoc);
    if (open(ASSOCIATE, $configPath->tmpDir."associate.${pid}.tmp")) { 
	while(<ASSOCIATE>) {
	    chomp;
	    my ($name, $value) = split(/ = /);

	    &DeleteUnwantedChar(\$value);
	    if ($name =~ /PI/i) {
		$i4pi++;
		$self->{"_pi$i4pi"} = $value;
	    }
	    elsif ($name =~ /associate([0-9]+)/i) {
		$i4assoc = $1;
		$self->{"_associate$i4assoc"} = $value;
	    }
	    elsif ($name =~ /primaryInvestigator_noLabMembers/i) {
		$self->{"_pi_noLabMembers"} = 1;
	    }
	}
	close (ASSOCIATE);
    }
}

####################################################################
sub setAssociateInfo {
####################################################################
    my ($self) = @_;
    my $pid = $self->pid;

    for (my $i = 1; $i <= 2; $i++) {
	$self->{"_pi$i"} = param("pi$i");
    }
    for (my $i = 1; $i <= 20; $i++) {
	$self->{"_associate$i"} = param("associate$i");
	$self->{"_ORIassociate$i"} = param("ORIassociate$i");

    }
    $self->{"_pi_noLabMembers"} = param("pi");
}

######################################################################
sub readInterestInfo {
######################################################################
    my ($self) = @_;
    my $pid = $self->pid;
    if (open(INTEREST, $configPath->tmpDir."interest.${pid}.tmp")) {
	while(<INTEREST>) {
	    chomp;
	    my ($name, $value) = split(/ = /);
	    &DeleteUnwantedChar(\$value);
	    $self->{'_interests'} = $value;
	}
	close(INTEREST);
    }
}

########################################################################
sub readKeywordInfo {
########################################################################
    my ($self) = @_;
    my $pid = $self->pid;
    my $i;

    if (open(KEYWORD, $configPath->tmpDir."keyword.${pid}.tmp")) {
	while(<KEYWORD>) {
	    chomp;
	    my ($name, $value) = split(/ = /);
	    if ($name =~ /keyword/i) {
		$i++;
		$self->{"_keyword$i"} = $value;
	    }
	    if ($name =~ /ResearchTopics/i) {
		$self->{'_researchTopics'} = $value; 
	    }
	}
	close(KEYWORD);
    }
}

#########################################################################
sub readCommentInfo {
#########################################################################
    my($self) = @_;
    my $pid = $self->pid;
    if (open(COMMENT, $configPath->tmpDir."comment.${pid}.tmp")) {
	while (<COMMENT>) {
	    chomp;
	    my ($name, $value) = split(/ = /);
	    if ($name =~ /Comments/i) {
		$value =~ s/\n/\<BR\>/g;
		$self->{'_Comments'} = $value;
	    }
	}
	close(COMMENT);
    }
}

#########################################################################
sub readGeneInfo {
#########################################################################
    my($self) = @_;
    my $pid = $self->pid;
    open(GENEINFO, $configPath->tmpDir."geneinfo.${pid}.tmp")
	|| die "Can't open '".$configPath->tmpDir."geneinfo.${pid}.tmp' for reading:$!\n";
    while(<GENEINFO>) {
	chomp;
	my ($name, $value) = split(/ = /);
	&DeleteUnwantedChar(\$name);
	&DeleteUnwantedChar(\$value);
	if ($name =~ /^gene$/i) {
	    $self->{'_gene'} = $value;
	}
	if ($name =~ /^orf$/i) {
	    $self->{'_orf'} = $value;
	}
	if ($name =~ /^genedesc$/i) {
	    $self->{'_genedesc'} = $value;
	}
	if ($name =~ /^othergene$/i) {
	    $self->{'_othergene'} = $value;
	}
	if ($name =~ /^geneproduct$/i) {
	    $self->{'_geneproduct'} = $value;
	}
	if ($name =~ /^nullphenotype$/i) {
	    $self->{'_nullphenotype'} = $value;
	}
	if ($name =~ /^otherphenotype$/i) {
	    $self->{'_otherphenotype'} = $value;
	}
    }   
    close(GENEINFO);
}

###################################################################
sub readGeneReferenceInfo {
###################################################################
    my ($self) = @_;
    my $pid = $self->pid;
    if (open(REF, $configPath->tmpDir."genereference.${pid}.tmp")) {
	while(<REF>) {
	    chomp;
	    my ($name, $value) = split(/ = /);
	    &DeleteUnwantedChar(\$name);
	    &DeleteUnwantedChar(\$value);
	    if ($name =~ /^author([0-9]+)$/i) {
		my $i = $1;
		$self->{"_author$i"} = $value;
	    }
	    if ($name =~ /^Reftitle/i) {
		$self->{'_Reftitle'} = $value;
	    }
	    if ($name =~ /^journal/i) {
		$self->{'_journal'} = $value;
	    }
	    if ($name =~ /^volume/i) {
		$self->{'_volume'} = $value;
	    }
	    if ($name =~ /^pages/i) {
		$self->{'_pages'} = $value;
	    } 
	    if ($name =~ /^year/i) {
		$self->{'_year'} = $value;
	    } 
	    if ($name =~ /^pubmed/i) {
		$self->{'_pubmed'} = $value;
	    } 
	    if ($name =~ /^reftype/i) {
		$self->{'_reftype'} = $value;
	    } 
	}
	close(REF);
    }
}

####################################################################
sub readGeneCommentInfo {
####################################################################
    my ($self) = @_;
    my $pid = $self->pid;
    if (open(COMMENT, $configPath->tmpDir."genecomment.${pid}.tmp")) {
	while(<COMMENT>) {
	    chomp;
	    my ($name, $value) = split(/ = /);
	    &DeleteUnwantedChar(\$name);
	    &DeleteUnwantedChar(\$value);
	    if ($name =~ /^registryComment/i) {
		$self->{'_registryComment'} = $value;
	    }
	}
	close(COMMENT);
    }
}


########################################################################
sub err_report {
########################################################################
    my ($self, $err) = @_;
    
    if (param('registerType')) {
	$self->{'_title'} = "$self->{'_database'} Gene Registry Error Report";
    }
    else {
	$self->{'_title'} = "$self->{'_database'} Colleague Error Report";
    }
    &printStartPage($self->database, $self->title, $self->help);
   
    print b($err);
    
    &printEndPage;

    exit;
}

###########################################################################
###### hostcheck() is used to check if the hostname is valid 
###### usage : $self->hostcheck($hostname); 
###### valid if return 1, invalid if return 0 
###########################################################################
sub hostcheck {
###########################################################################
    my ($self, $hostname) = @_;
    my $hostvalid = 1;
    # open(hostchk, "/tools/net/bin/host -a $hostname|") 
    open(hostchk, $configPath->netbinDir."host $hostname|") 
	   or warn "could not open hostchk:$!\n";
    while (<hostchk>) {
	chop;
#	if ( /\tA\t/) {
#	     $hostvalid = 1;
#	     last;
#	}
	if ($_ =~ /does not exist/i) {
	     $hostvalid = 0;
	     last;
	}
    }
    return $hostvalid;
}


###########################################################################
####### getWebTitleByURL() is used to get the web page title
#########################################################################
sub getWebTitleByURL {
#########################################################################
    my ($self, $url) = @_;
    my $ua = new LWP::UserAgent;
    my $reqUrl = new HTTP::Request GET => $url;
    $reqUrl->content_type('application/x-www-form-urlencoded');
    my $resUrl = $ua->request($reqUrl);
    my $urlTitle;
    if ($resUrl->is_success) {
          my $output = $resUrl->content;
          if ($output =~ /<title>(.+)<\/title>/i) {
              $urlTitle = $1;
          }
	  else {
              $urlTitle = "";
          }
    }
    else {
          $urlTitle = "";
    }
    return $urlTitle;
}

#########################################################################
sub LoadConversionMap {
#########################################################################

    ##################################################################
    # Latin-1 to ascii conversion - modified table from MIME::Latin1 #
    ##################################################################
    my @Map = (
                     #  char decimal description
	             #--------------------------------------------------
	    "  "   , #      160   non-breaking space
	    "!!"   , #  ¡   161   inverted exclamation
	    "c/"   , #  ¢   162   cent sign
	    "L-"   , #  £   163   pound sterling
	    "ox"   , #  ¤   164   general currency sign
	    "Y-"   , #  ¥   165   yen sign
	    "||"   , #  ¦   166   broken vertical bar
	    "so"   , #  §   167   section sign
	    '""'   , #  ¨   168   umlaut (dieresis)
	    "co"   , #  ©   169   copyright
	    "-a"   , #  ª   170   feminine ordinal
	    "<<"   , #  «   171   left angle quote, guillemotleft
	    "-,"   , #  ¬   172   not sign
	    "--"   , #  ­   173   soft hyphen
	    "ro"   , #  ®   174   registered trademark
	    "^-"   , #  ¯   175   macron accent
	    "^*"   , #  °   176   degree sign
	    "+-"   , #  ±   177   plus or minus
	    "^2"   , #  ²   178   superscript two
	    "^3"   , #  ³   179   superscript three
	    "' "   , #  ´   180   acute accent
	    "/u"   , #  µ   181   micro sign
	    "P!"   , #  ¶   182   paragraph sign
	    "^."   , #  ·   183   middle dot
	    ",,"   , #  ¸   184   cedilla
	    "^1"   , #  ¹   185   superscript one
	    "_o"   , #  º   186   masculine ordinal
	    ">>"   , #  »   187   right angle quote, guillemotright
	    "14"   , #  ¼   188   fraction one-fourth
	    "12"   , #  ½   189   fraction one-half
	    "34"   , #  ¾   190   fraction three-fourths
	    "??"   , #  ¿   191   inverted question mark
	    "A"   , #  À   192   capital A, grave accent
	    "A"   , #  Á   193   capital A, acute accent
	    "A"   , #  Â   194   capital A, circumflex accent
	    "A"   , #  Ã   195   capital A, tilde
	    'A'   , #  Ä   196   capital A, dieresis or umlaut mark
	    'A'   , #  Å   197   capital A, ring
	    'AE'   , #  Æ   198   capital AE diphthong (ligature)
	    'C'   , #  Ç   199   capital C, cedilla
	    "E"   , #  È   200   capital E, grave accent
	    "E"   , #  É   201   capital E, acute accent
	    'E'   , #  Ê   202   capital E, circumflex accent
	    'E'   , #  Ë   203   capital E, dieresis or umlaut mark
	    "I"   , #  Ì   204   capital I, grave accent
	    "I"   , #  Í   205   capital I, acute accent
	    "I"   , #  Î   206   capital I, circumflex accent
	    'I'   , #  Ï   207   capital I, dieresis or umlaut mark
	    'D'   , #  Ð   208   capital Eth, Icelandic
	    'N'   , #  Ñ   209   capital N, tilde
	    "O"   , #  Ò   210   capital O, grave accent
	    "O"   , #  Ó   211   capital O, acute accent
	    "O"   , #  Ô   212   capital O, circumflex accent
	    "O"   , #  Õ   213   capital O, tilde
	    'O'   , #  Ö   214   capital O, dieresis or umlaut mark
	    'xx'   , #  ×   215   multiply sign
	    'O'   , #  Ø   216   capital O, slash
	    'U'   , #  Ù   217   capital U, grave accent
	    "U"   , #  Ú   218   capital U, acute accent
	    "U"   , #  Û   219   capital U, circumflex accent
	    'U'   , #  Ü   220   capital U, dieresis or umlaut mark
	    "Y"   , #  Ý   221   capital Y, acute accent
	    "P"   , #  Þ   222   capital THORN, Icelandic
	    "ss"   , #  ß   223   small sharp s, German (sz ligature)
	    "a"   , #  à   224   small a, grave accent
	    "a"   , #  á   225   small a, acute accent
	    "a"   , #  â   226   small a, circumflex accent
	    "a"   , #  ã   227   small a, tilde
	    'a'   , #  ä   228   small a, dieresis or umlaut mark
	    'a'   , #  å   229   small a, ring
	    'ae'   , #  æ   230   small ae diphthong (ligature)
	    'c'   , #  ç   231   small c, cedilla
	    "e"   , #  è   232   small e, grave accent
	    "e"   , #  é   233   small e, acute accent
	    "e"   , #  ê   234   small e, circumflex accent
	    'e'   , #  ë   235   small e, dieresis or umlaut mark
	    "i"   , #  ì   236   small i, grave accent
	    "i"   , #  í   237   small i, acute accent
	    "i"   , #  î   238   small i, circumflex accent
	    'i'   , #  ï   239   small i, dieresis or umlaut mark
	    'd'   , #  ð   240   small eth, Icelandic
	    'n'   , #  ñ   241   small n, tilde
	    "o"   , #  ò   242   small o, grave accent
	    "o"   , #  ó   243   small o, acute accent
	    "o"   , #  ô   244   small o, circumflex accent
	    "o"   , #  õ   245   small o, tilde
	    'o'   , #  ö   246   small o, dieresis or umlaut mark
	    '-:'   , #  ÷   247   division sign
	    'o'   , #  ø   248   small o, slash
	    "u"   , #  ù   249   small u, grave accent
	    "u"   , #  ú   250   small u, acute accent
	    "u"   , #  û   251   small u, circumflex accent
	    'u'   , #  ü   252   small u, dieresis or umlaut mark
	    "y"   , #  ý   253   small y, acute accent
	    "th"   , #  þ   254   small thorn, Icelandic
	    'y'   , #  ÿ   255   small y, dieresis or umlaut mark
    );

    return @Map;
}

#######################################################################
sub latin1_to_ascii {
#######################################################################
    my ($self, $str, $opts) = @_;
    # Extract options:
    $opts ||= '';
    my $o_encode  = ($opts =~ /\bENCODE\b/i);
    my $o_noslash = ($opts =~ /\bNOSLASH\b/i) && !$o_encode;
    my $slash = ($o_noslash ? '' : '\\');
    # Encode:
    my @Map = $self->LoadConversionMap;
    $str =~ s/\\/\\\\/g if $o_encode;
    $str =~ s/[\240-\377]/$Map[ord($&)-0240]||''/eg;
    $str;
}

#######################################################################
sub removeTMP {
#######################################################################
    my ($self, $pid) = @_;
    
#    system("/bin/rm ".$configPath->tmpDir."contact.${pid}.tmp 2>/dev/null");
#    system("/bin/rm ".$configPath->tmpDir."associate.${pid}.tmp 2>/dev/null");
#    system("/bin/rm ".$configPath->tmpDir."interest.${pid}.tmp 2>/dev/null");
#    system("/bin/rm ".$configPath->tmpDir."comment.${pid}.tmp 2>/dev/null");
#    system("/bin/rm ".$configPath->tmpDir."geneinfo.${pid}.tmp 2>/dev/null");
#    system("/bin/rm ".$configPath->tmpDir."genereference.${pid}.tmp 2>/dev/null");
#    system("/bin/rm ".$configPath->tmpDir."genecomment.${pid}.tmp 2>/dev/null");

}
########################################################################
1; #####################################################################
########################################################################



















