F:\WEBSITES\testbed\zipped\yabb_svn_new\branches\2.5.2\cgi-bin\yabb2\Sources\InstantMessage.pl F:\WEBSITES\testbed\zipped\yabb_svn_new\trunk\cgi-bin\yabb2\Sources\InstantMessage.pm
############################################################################### ###############################################################################
# InstantMessage.pl                                                           # # InstantMessage.pm                                                           #
  # $Date: 01.05.16 $                                                           #
############################################################################### ###############################################################################
# YaBB: Yet another Bulletin Board                                            # # YaBB: Yet another Bulletin Board                                            #
# Open-Source Community Software for Webmasters                               # # Open-Source Community Software for Webmasters                               #
# Version:        YaBB 2.5.2                                                  # # Version:        YaBB 2.6.12                                                 #
# Packaged:       October 21, 2012                                            # # Packaged:       January 5, 2016                                             #
# Distributed by: http://www.yabbforum.com                                    # # Distributed by: http://www.yabbforum.com                                    #
# =========================================================================== # # =========================================================================== #
# Copyright (c) 2000-2012 YaBB (www.yabbforum.com) - All Rights Reserved.     # # Copyright (c) 2000-2016 YaBB (www.yabbforum.com) - All Rights Reserved.     #
# Software by:  The YaBB Development Team                                     # # Software by:  The YaBB Development Team                                     #
#               with assistance from the YaBB community.                      # #               with assistance from the YaBB community.                      #
############################################################################### ###############################################################################
  # use strict;
  #use warnings;
  #no warnings qw(uninitialized once redefine);
  use CGI::Carp qw(fatalsToBrowser);
  our $VERSION = '2.6.12';
   
  $instantmessagepmver = 'YaBB 2.6.12 $Revision: 1651 $';
  if ( $action eq 'detailedversion' ) { return 1; }
   
  require Sources::PostBox;
  require Sources::SpamCheck;
  LoadLanguage('FA');
  LoadLanguage('Post');
   
  get_micon();
  get_template('MyMessage');
   
$instantmessageplver = 'YaBB 2.5.2 $Revision: 1.2 $';  
if ($action eq 'detailedversion') { return 1; }  
$set_subjectMaxLength ||= 50; $set_subjectMaxLength ||= 50;
   
## create the send IM section of the screen  if (   ( $action eq 'imsend' || $action eq 'imsend2' ) 
     && $MaxIMMessLen
     && $AdMaxIMMessLen )
  {
     $MaxMessLen   = $MaxIMMessLen;
     $AdMaxMessLen = $AdMaxIMMessLen;
  }
   
####  if ( $iamadmin || $iamgmod ) { $MaxMessLen = $AdMaxMessLen; } 
# new format:  for  msg file:  
#messageid|(from)user|(touser(s))|(ccuser(s))|(bccuser(s))|  
#   subject|date|message|(parentmid)|reply#|ip|messagestatus|  
#       flags|storefolder|attachment  
   
# (optional) [placeholder]  
   
# for outbox:  
#messageid|(from)user|(touser(s))|(ccuser(s))|(bccuser(s))|  
#   subject|date|message|(parentmid)|reply#|ip|messagestatus|  
#       flags|storefolder|attachment  
   
## messagestatus = c(onfidential)/h(igh importance)/s(tandard)/a(lert)/g(uest)/(b)roadcast/(n)otify of post  
## flags = u(nread)/f(orward)/q(oute)/r(eply)/c(alled back)  
## parentmid = stays same  
## reply# = increments for replies, so we can build conversation threads  
   
## storefolder = name of storage folder. Start with in & out for everyone.  
#1  $mnum = 3;  
#2  $imnewcount = 0;  
#3  $moutnum = 17;  
#4  $storenum = 0;  
#5  $draftnum = 0;  
#6  @folders  (name1|name2|name3)  
   
# MF-B: new .ims file format  
#   ### UserIMS YaBB 2.2 Version ###  
#   '${$username}{'PMmnum'}',"value"  
#   '${$username}{'PMimnewcount'}',"value"  
#   '${$username}{'PMmoutnum'}',"value"  
#   '${$username}{'PMstorenum'}',"value"  
#   '${$username}{'PMdraftnum'}',"value"  
#   '${$username}{'PMfolders'}',"value"  
#   '${$username}{'PMfoldersCount'}',"value"  
   
#   @storecurrentin = qw/ /; # list of messages in .imstore from msg  ## create the send IM section of the screen 
#   @storecurrentout = qw/ /; # list of messages in .imstore from outbox  
   
  sub buildIMsend {
     LoadLanguage('InstantMessage');
     LoadCensorList();
   
     if ( $FORM{'previewim'} ) {
         require Sources::Post;
         Preview($error);
     }
     $mctitle = $inmes_txt{'775'};
     if ($sendBMess) { $mctitle = $inmes_txt{'775a'}; }
     ## check for a draft being opened
     if ( $INFO{'caller'} == 4 && $INFO{'id'} ) {
         if ( !-e "$memberdir/$username.imdraft" ) {
             fatal_error( 'cannot_open', "$username.imdraft" );
         }
         fopen( DRAFT, "$memberdir/$username.imdraft" );
         my @draftPM = <DRAFT>;
         fclose(DRAFT);
         chomp @draftPM;
         my $flagfound;
         foreach my $draftMess (@draftPM) {
             my ( $checkId, undef ) = split /\|/xsm, $draftMess, 2;
             if ( $checkId eq $INFO{'id'} ) {
                 (
                     $dmessageid,    $dmusername,   $userto,
                     $usernamecc,    $usernamebcc,  $subject,
                     $dmdate,        $message,      $dmpmessageid,
                     $dmreplyno,     $dmips,        $dmessageStatus,
                     $dmessageFlags, $dstoreFolder, $dmessageAttachment
                 ) = split /\|/xsm, $draftMess;
                 $flagfound = 1;
                 last;
             }
         }
         if ( !$flagfound ) { fatal_error('cannot_find_draftmess'); }
         FromHTML($message);
         FromHTML($subject);
     }
   
     my $pmicon = 'standard';
     if ( $FORM{'status'} || $INFO{'status'} ) {
         $thestatus = $FORM{'status'} || $INFO{'status'};
     }
     elsif ($dmessageStatus) { $thestatus = $dmessageStatus; }
     else                    { $thestatus = 's'; }
   
     my @ststs    = qw( s u c );
     my @ststt    = qw( sb ub cb );
     my @s_select = ();
   
     foreach my $i ( 0 .. 2 ) {
         if ( $thestatus eq $ststs[$i] ) {
             $s_select[$i] = q~ selected="selected"~;
         }
     }
   
     foreach my $i ( 0 .. 2 ) {
         if ( $thestatus eq $ststt[$i] ) {
             $s_select[$i] = q~ selected="selected"~;
             $sendBMess = 1;
         }
     }
     if (
         $sendBMess != 1
         || (
                ( $PMenableBm_level != 1 || ( !$staff ) )
             && ( $PMenableBm_level != 2 || ( !$iamadmin && !$iamgmod ) )
             && ( $PMenableBm_level != 4
                 || ( !$iamadmin && !$iamgmod && !$iamfmod ) )
             && ( $PMenableBm_level != 3 || !$iamadmin )
         )
       )
     {
         $sendBMess = 0;
     }
   
     ##########   post code   #########
     if (   !$iamadmin
         && !$iamgmod
         && !$staff
         && ${ $uid . $username }{'postcount'} < $numposts )
     {
         fatal_error('im_low_postcount');
     }
   
     if ( !$replyguest ) {
         if ($is_preview) { $post_txt{'507'} = $post_txt{'771'}; }
         $normalquot = $post_txt{'599'};
         $simpelquot = $post_txt{'601'};
         $simpelcode = $post_txt{'602'};
         $edittext   = $post_txt{'603'};
         if ( !$fontsizemax ) { $fontsizemax = 72; }
         if ( !$fontsizemin ) { $fontsizemin = 6; }
   
         # this defines what the top area of the post box will look like:
         ## if this is a reply , load the 'from' name off the message
         if ( $INFO{'reply'} || $INFO{'quote'} ) { $INFO{'to'} = $mfrom; }
         if ( !$INFO{'to'} && $FORM{'to'} ne q{} ) { $INFO{'to'} = $FORM{'to'}; }
   
         ## if cloaking is enabled, and 'to' is not a blank
         if ( $do_scramble_id && $INFO{'to'} ne q{} ) {
             decloak( $INFO{'to'} );
         }
   
         if ( !$sendBMess ) { LoadUser( $INFO{'to'} ); }
     }
   
     $message =~ s/<br.*?>/\n/igsm;
     $message =~ s/&nbsp;/ /gsm;
     ToChars($message);
     $message = Censor($message);
     ToHTML($message);
     $message =~ s/ &nbsp; &nbsp; &nbsp;/\t/igsm;
   
     if ($msubject) { $subject = $msubject; }
     ToChars($subject);
     $subject = Censor($subject);
     ToHTML($subject);
   
     if ( $action eq 'modify' || $action eq 'modify2' ) {
         $displayname = qq~$mename~;
     }
     else {
         $displayname = ${ $uid . $username }{'realname'};
     }
     require Sources::ContextHelp;
     ContextScript('post');
   
     $MCGlobalFormStart .= qq~
     $ctmain
     <script type="text/javascript">
     var displayNames = new Object();
     $template_names
     </script>
     ~;
     $my_gimsend  = q{};
     $my_tosend_a = q{};
     if ( !$replyguest ) {
         if ($prevmain) {
             $my_gimsend = $myIM_prevmain;
             $my_gimsend =~ s/{yabb prevmain}/$prevmain/sm;
         }
         $my_gimsend .= $myIM_liveprev;
     }
     else {
         $my_gimsend = $myIM_replyguest;
         $my_gimsend =~ s/{yabb guest_reply}/$guest_reply{'guesttext'}/sm;
     }
   
     if ( !$replyguest && !$sendBMess && ( $PMenable_cc || $PMenable_bcc ) ) {
         $yyjavascripttoform = q~
             <script type="text/javascript">
             function changeRecepientTab(tabto) {
                 document.getElementById('usersto').style.display = 'none';
                 document.getElementById('bnttoto').className = 'windowbg  bnttoto';
         ~;
   
         $my_tosend_a =
  qq~<div id="bnttoto" class="windowbg2 bnttoto"><a href="javascript:void(0);" onclick="changeRecepientTab('to'); return false;">$inmes_txt{'324'}:</a></div>
         ~;
   
         if ($PMenable_cc) {
             $yyjavascripttoform .= q~
                 document.getElementById('userscc').style.display = 'none';
                 document.getElementById('bnttocc').className = 'windowbg  bnttoto';
             ~;
             $my_tosend_a .= qq~
                     <div id="bnttocc" class="windowbg bnttoto"><a href="javascript:void(0);" onclick="changeRecepientTab('cc'); return false;">$inmes_txt{'325'}:</a></div>
             ~;
         }
         if ($PMenable_bcc) {
             $yyjavascripttoform .= q~
                 document.getElementById('usersbcc').style.display = 'none';
                 document.getElementById('bnttobcc').className = 'windowbg bnttoto';
             ~;
             $my_tosend_a .= qq~
                     <div id="bnttobcc" class="windowbg bnttoto"><a href="javascript:void(0);" onclick="changeRecepientTab('bcc'); return false;">$inmes_txt{'326'}:</a></div>
             ~;
         }
         $yyjavascripttoform .= q~
                 document.getElementById('users' + tabto).style.display = 'inline';
                 document.getElementById('bntto' + tabto).className = 'windowbg2 bnttoto';
             }
         </script>
         ~;
         $my_send = $my_tosend;
         $my_send =~ s/{yabb yyjavascripttoform}/$yyjavascripttoform/sm;
         $my_send =~ s/{yabb my_tosend_a}/$my_tosend_a/sm;
     }
   
     # now uses a multi-line select
     ProcIMrecs();
   
     $toname = $INFO{'forward'} ? q{} : $INFO{'to'};
   
     my $toUsersTitle = $inmes_txt{'torecepients'};
   
     if ( !$replyguest ) {
         $onchangeText = q~ onkeyup="autoPreview();"~;
   
         if ($sendBMess) { $toUsersTitle = $inmes_txt{'togroups'}; }
         if ( $PMenable_cc || $PMenable_bcc ) {
             $us_winhight = $us_winhight_cc;
         }
         else {
             $us_winhight = $us_winhight_to;
         }
   
         my $toIdtext = $sendBMess ? 'groups' : 'toshow';
   
         $imWinop = qq~
         <script type="text/javascript">
         function imWin() {
             window.open('$scripturl?action=imlist;sort=recentpm;toid=$toIdtext','imWin','status=no,height=$us_winhight,width=$us_winwidth_to,menubar=no,toolbar=no,top=50,left=50,scrollbars=no');
         }
         function imWinCC() {
             window.open('$scripturl?action=imlist;sort=recentpm;toid=toshowcc','imWin','status=no,height=$us_winhight,width=$us_winwidth_cc,menubar=no,toolbar=no,top=50,left=50,scrollbars=no');
         }
         function imWinBCC() {
             window.open('$scripturl?action=imlist;sort=recentpm;toid=toshowbcc','imWin','status=no,height=$us_winhight,width=$us_winwidth_cc,menubar=no,toolbar=no,top=50,left=50,scrollbars=no');
         }
         function removeUser(oElement) {
             var indexToRemove = oElement.options.selectedIndex;
             if (confirm("$post_txt{'768'}")) { oElement.remove(indexToRemove); }
         }
         </script>
         <div id="usersto" class="usersto">
         <b>$inmes_txt{'324'} $toUsersTitle:</b>&nbsp;<a href="javascript: void(0);" onclick="imWin();" tabindex="1"><span class="small">$inmes_txt{'clickto1'} <i>$inmes_txt{'324'}</i> $toUsersTitle $inmes_txt{'clickto2'}</span></a><br />
         <select name="toshow" id="toshow" multiple="multiple" size="6" class="width_100" ondblclick="removeUser(this);">\n~;
   
         if ( !$sendBMess ) {
             if ($toname) {
                 LoadUser($toname);
                 if ( ${ $uid . $toname }{'realname'} ) {
                     $imWinop .=
  qq~<option selected="selected" value="$useraccount{$toname}">${$uid.$toname}{'realname'}</option>\n~;
                 }
             }
             if ( $FORM{'toshow'} ) {
                 foreach my $touser ( split /,/xsm, $FORM{'toshow'} ) {
                     LoadUser($touser);
                     $imWinop .=
  qq~<option selected="selected" value="$useraccount{$touser}">${$uid.$touser}{'realname'}</option>\n~;
                 }
             }
             if ($userto) {
                 foreach my $touser ( split /,/xsm, $userto ) {
                     LoadUser($touser);
                     $imWinop .=
  qq~<option selected="selected" value="$useraccount{$touser}">${$uid.$touser}{'realname'}</option>\n~;
                 }
             }
         }
         else {
             $FORM{'toshow'} = $mto || $FORM{'toshow'};
             if ( $FORM{'toshow'} ) {
                 foreach my $touser ( split /,/xsm, $FORM{'toshow'} ) {
                     if ( $touser eq 'all' ) {
                         $imWinop .=
  qq~<option selected="selected" value="all">$inmes_txt{'bmallmembers'}</option>\n~;
                     }
                     elsif ( $touser eq 'admins' ) {
                         $imWinop .=
  qq~<option selected="selected" value="admins">$inmes_txt{'bmadmins'}</option>\n~;
                     }
                     elsif ( $touser eq 'gmods' ) {
                         $imWinop .=
  qq~<option selected="selected" value="gmods">$inmes_txt{'bmgmods'}</option>\n~;
                     }
                     elsif ( $touser eq 'fmods' ) {
                         $imWinop .=
  qq~<option selected="selected" value="fmods">$inmes_txt{'bmfmods'}</option>\n~;
                     }
                     elsif ( $touser eq 'mods' ) {
                         $imWinop .=
  qq~<option selected="selected" value="mods">$inmes_txt{'bmmods'}</option>\n~;
                     }
                     else {
                         foreach ( keys %NoPost ) {
                             my ( $title, undef ) =
                               split /\|/xsm, $NoPost{$_}, 2;
                             if ( $touser eq $_ ) {
                                 $imWinop .=
  qq~<option selected="selected" value="$_">$title</option>\n~;
                             }
                         }
                     }
                 }
             }
         }
   
         $imWinop .=
  q~            </select><input type="hidden" name="immulti" value="yes" />
             </div>
         ~;
   
         $JSandInput = q~
         <script type="text/javascript">
         // this function forces all users listed on IM mult to be selected for processing
         function selectNames() {
             var oList = document.getElementById('toshow');
             for (var i = 0; i < oList.options.length; i++) { oList.options[i].selected = true; }
         ~;
   
         if ( !$sendBMess ) {
             if ($PMenable_cc) {
                 $JSandInput .= q~
                     oList = document.getElementById('toshowcc');
                     for ( i = 0; i < oList.options.length; i++){ oList.options[i].selected = true; }
                 ~;
                 $imsend_cc .= qq~
                 <div id="userscc" class="usersto">
                 <b>$inmes_txt{'325'} $toUsersTitle:</b>&nbsp;<a href="javascript: void(0);" onclick="imWinCC();"><span class="small">$inmes_txt{'clickto1'} <i>$inmes_txt{'325'}</i> $toUsersTitle $inmes_txt{'clickto2'}</span></a><br />
                 <select name="toshowcc" id="toshowcc" multiple="multiple" size="6" class="width_100" ondblclick="removeUser(this);">\n~;
                 if ( $FORM{'toshowcc'} ) {
                     foreach my $touser ( split /\,/xsm, $FORM{'toshowcc'} ) {
                         LoadUser($touser);
                         $imsend_cc .=
  qq~<option selected="selected" value="$useraccount{$touser}">${$uid.$touser}{'realname'}</option>\n~;
                     }
                 }
                 if ($usernamecc) {
                     foreach my $touser ( split /\,/xsm, $usernamecc ) {
                         LoadUser($touser);
                         $imsend_cc .=
  qq~<option selected="selected" value="$useraccount{$touser}">${$uid.$touser}{'realname'}</option>\n~;
                     }
                 }
                 $imsend_cc .= q~               </select>
                 </div>
                 ~;
             }
   
             if ($PMenable_bcc) {
                 $JSandInput .= q~
                     oList = document.getElementById('toshowbcc');
                     for ( i = 0; i < oList.options.length; i++) { oList.options[i].selected = true; }
                 ~;
                 $imsend_cc .= qq~
                 <div id="usersbcc" class="usersto">
                 <b>$inmes_txt{'326'} $toUsersTitle:</b>&nbsp;<a href="javascript: void(0);" onclick="imWinBCC();"><span class="small">$inmes_txt{'clickto1'} <i>$inmes_txt{'326'}</i> $toUsersTitle $inmes_txt{'clickto2'}</span></a><br />
                 <select name="toshowbcc" id="toshowbcc" multiple="multiple" size="6" class="width_100" ondblclick="removeUser(this);">\n~;
                 if ( $FORM{'toshowbcc'} ) {
                     foreach my $touser ( split /\,/xsm, $FORM{'toshowbcc'} ) {
                         LoadUser($touser);
                         $imsend_cc .=
  qq~<option selected="selected" value="$useraccount{$touser}">${$uid.$touser}{'realname'}</option>\n~;
                     }
                 }
                 if ($usernamebcc) {
                     foreach my $touser ( split /\,/xsm, $usernamebcc ) {
                         LoadUser($touser);
                         $imsend_cc .=
  qq~<option selected="selected" value="$useraccount{$touser}">${$uid.$touser}{'realname'}</option>\n~;
                     }
                 }
                 $imsend_cc .= q~               </select>
                 </div>
                 ~;
             }
         }
   
         $JSandInput .= q~
             }
         </script>
         ~;
   
         my $iconopts = q{};
         for my $i ( sort keys %pmiconlist ) {
             my ( $img, $alt ) = split /[|]/xsm, $pmiconlist{$i};
             if ( $icon eq $img ) { $myic = ' selected="selected" '; }
             $iconopts .=
  qq~                            <option value="$img"$myic>$alt</option>\n~;
         }
         $imsend_send = $my_imsend_IM;
         $imsend_send =~ s/{yabb my_send}/$my_send/sm;
         $imsend_send =~ s/{yabb my_gimsend}/$my_gimsend/sm;
         $imsend_send =~ s/{yabb imWinop}/$imWinop/sm;
         $imsend_send =~ s/{yabb imsend_cc}/$imsend_cc/sm;
         $imsend_send =~ s/{yabb onchange_text2}/$onchange_text2/sm;
         $imsend_send =~ s/{yabb iconopts}/$iconopts/sm;
         $imsend_send =~ s/{yabb pmicon}/$pmicon/gsm;
         $imsend_send =~ s/{yabb pmicon_img}/$micon_bg{$pmicon}/gsm;
     }
     else {
         $imsend_send = $my_imsend_Guest;
         $imsend_send =~ s/{yabb my_gimsend}/$my_gimsend/sm;
         $imsend_send =~ s/{yabb my_send}/$my_send/sm;
         $imsend_send =~ s/{yabb toUsersTitle}/$toUsersTitle/sm;
         $imsend_send =~ s/{yabb guestName}/$guestName/gsm;
         $imsend_send =~ s/{yabb guestEmail}/$guestEmail/sm;
     }
   
     $subtitle = "<i>$subject</i>";
   
     #this is the end of the upper area of the post page.
   
     # this declares the beginning of the UBBC section
     $JSandInput .= qq~
     <script type="text/javascript">
     function Hash() {
         this.length = 0;
         this.items = new Array();
         for (var i = 0; i < arguments.length; i += 2) {
             if (typeof(arguments[i + 1]) != 'undefined') {
                 this.items[arguments[i]] = arguments[i + 1];
                 this.length++;
             }
         }
   
         this.getItem = function(in_key) {
             return this.items[in_key];
         };
     }
   
     function showimage() {
         $jsIM
         var icon_set = document.getElementById("status").options[document.getElementById("status").selectedIndex].value;
         var icon_show = jsIM.getItem(icon_set);
         document.images.status.src = icon_show;
     }
     </script>
     ~;
   
     $JSandInput .= qq~
     <input type="hidden" name="threadid" id="threadid" value="$threadid" />
     <input type="hidden" name="postid" id="postid" value="$postid" />
     <input type="hidden" name="info" id="info" value="$INFO{'id'}$FORM{'info'}" />
     <input type="hidden" name="mename" id="mename" value="$mename" />
     <input type="hidden" name="post_entry_time" id="post_entry_time" value="$date" />
     ~;
   
     if ( $FORM{'draftid'} || $INFO{'caller'} == 4 ) {
         $JSandInput .=
           q~<input type="hidden" name="draftid" id="draftid" value="~
           . ( $FORM{'draftid'} || $INFO{'id'} ) . q~" />~;
     }
   
     $my_max = ( $set_subjectMaxLength + ( $subject =~ /^Re: /sm ? 4 : 0 ) );
   
     # this is for the ubbc buttons
     if ( !$replyguest ) {
         if ( $enable_ubbc && $showyabbcbutt ) {
             $my_ubbc_yes .= qq~<b>$post_txt{'252'}:</b><br />~;
   
             # ubbc set separated out into PostBox.pm DAR 11/13/2012 #
             $my_ubbc_yes .= postbox();
         }
     }
   
     if ($replyguest) {
         $tmpmtext = qq~<b>$post_txt{'72'}:</b> ~;
     }
   
     $postbox2 = postbox2();
     $postbox3 = postbox3();
   
     if ( !$replyguest ) {
         $imsend_notguest = $my_postbox_notguest;
   
         $moresmilieslist   = q{};
         $more_smilie_array = q{};
         $i                 = 0;
         if ( $showadded == 1 ) {
             while ( $SmilieURL[$i] ) {
                 if ( $SmilieURL[$i] =~ /\//ism ) { $tmpurl = $SmilieURL[$i]; }
                 else { $tmpurl = qq~$imagesdir/$SmilieURL[$i]~; }
                 $moresmilieslist .=
  qq~             <img src="$tmpurl" alt="$SmilieDescription[$i]" onclick="javascript: MoreSmilies($i);" class="bottom cursor" />$SmilieLinebreak[$i]\n~;
                 $tmpcode = $SmilieCode[$i];
                 $tmpcode =~ s/\&quot;/"+'"'+"/gsm;
   
                 FromHTML($tmpcode);
                 $tmpcode =~ s/&\x2336;/\$/gxsm;
                 $tmpcode =~ s/&\x2364;/\@/gxsm;
                 $more_smilie_array .= qq~" $tmpcode", ~;
                 $i++;
             }
         }
   
         if ( $showsmdir == 1 ) {
             opendir DIR, "$htmldir/Smilies";
             @contents = readdir DIR;
             closedir DIR;
             foreach my $line ( sort { uc($a) cmp uc $b } @contents ) {
                 ( $name, $extension ) = split /\./xsm, $line;
                 if (   $extension =~ /gif/ism
                     || $extension =~ /jpg/ism
                     || $extension =~ /jpeg/ism
                     || $extension =~ /png/ism )
                 {
                     if ( $line !~ /banner/ism ) {
                         $moresmilieslist .=
  qq~             <img src="$yyhtml_root/Smilies/$line" alt="$name" onclick="javascript: MoreSmilies($i);" class="cursor bottom" />$SmilieLinebreak[$i]\n~;
                         $more_smilie_array .= qq~" [smiley=$line]", ~;
                         $i++;
                     }
                 }
             }
         }
   
         $more_smilie_array .= q~""~;
         if ( $smiliestyle == 1 ) {
             $smiliewinlink = qq~$scripturl?action=smilieput~;
         }
         else { $smiliewinlink = qq~$scripturl?action=smilieindex~; }
   
         $im_smilies .= $imsend_notguest . qq~
                 moresmiliecode = new Array($more_smilie_array);
                 function MoreSmilies(i) {
                     AddTxt=moresmiliecode[i];
                     AddText(AddTxt);
                 }
                     function smiliewin() {
         window.open("$smiliewinlink", 'list', 'width=$winwidth, height=$winheight, scrollbars=yes');
     }
     </script>~;
         $im_smilies .= smilies_list();
         $im_smilies .= qq~
         <span class="small"><a href="javascript: smiliewin();">$post_smiltxt{'17'}</a></span>\n~;
   
         # SpellChecker start
         if ($enable_spell_check) {
             $yyinlinestyle .= googiea();
             $userdefaultlang = ( split /-/xsm, $abbr_lang )[0];
             $userdefaultlang ||= 'en';
             $im_smilies .= googie($userdefaultlang);
         }
   
         # SpellChecker end
   
         $im_smilies .= $my_postbox_smilie;
     }
   
     # PM File Attachments Browse Box Code
     $allowAttachIM ||= 0;
     $pmFileLimit   ||= 0;
     $allowGroups = GroupPerms( $allowAttachIM, $pmAttachGroups );
     my ( $pmFileTypeInfo, $pmFileSizeInfo, $pmFileExtensions, @files,
         @fileUsers );
     if ( !$replyguest && $allowAttachIM && $allowGroups && -d "$pmuploaddir" ) {
         $pmFileExtensions = join q{ }, @pmAttachExt;
         $pmFileTypeInfo =
           $pmCheckExt == 1
           ? qq~$fatxt{'2'} $pmFileExtensions~
           : qq~$fatxt{'2'} $fatxt{'4'}~;
         $pmFileSizeInfo =
           $pmFileLimit != 0
           ? qq~$fatxt{'3'} $pmFileLimit KB~
           : qq~$fatxt{'3'} $fatxt{'5'}~;
         $FORM{'oldattach'} = decloak( $FORM{'oldattach'} );
         $mattach = $mattach || $FORM{'oldattach'};
         chomp $mattach;
         foreach my $senderFile ( split /,/xsm, $mattach ) {
             chomp $senderFile;
             my ( $forwardFileName, $forwardFileUser ) =
               split /~/xsm, $senderFile;
             push @files,     $forwardFileName;
             push @fileUsers, $forwardFileUser;
         }
         $cloakAttach = cloak($mattach);
         $my_show_FA .= $my_FA_show;
         $my_show_FA =~ s/{yabb cloakAttach}/$cloakAttach/sm;
   
         if ( $allowAttachIM > 1 ) {
             $my_allow_FA = qq~
             <img src="$imagesdir/$newload{'brd_exp'}" id="attform_add" alt="$fatxt{'80a'}" title="$fatxt{'80a'}" class="cursor" onclick="enabPrev2(1);" />
             <img src="$imagesdir/$newload{'brd_col'}" id="attform_sub" alt="$fatxt{'80s'}" title="$fatxt{'80s'}" class="cursor" style="visibility:hidden;" onclick="enabPrev2(-1);" />~;
         }
         $my_imFA = $my_FA_attach;
         $my_imFA =~ s/{yabb my_show_FA}/$my_show_FA/sm;
         $my_imFA =~ s/{yabb pmFileTypeInfo}/$pmFileTypeInfo/sm;
         $my_imFA =~ s/{yabb pmFileSizeInfo}/$pmFileSizeInfo/sm;
         $my_imFA =~ s/{yabb my_allow_FA}/$my_allow_FA/sm;
   
         my $startcount;
         if ( $allowAttachIM > 0 ) {
             for my $y ( 1 .. $allowAttachIM ) {
                 if (
                     (
                         (
                                $action eq 'imsend2' 
                             || $INFO{'forward'}
                             || $FORM{'draftid'}
                             || $INFO{'caller'} == 4
                         )
                         && !$FORM{'reply'}
                     )
                     && $files[ $y - 1 ] ne q{}
                     && -e "$pmuploaddir/$files[$y-1]" 
                   )
                 {
                     if ( $FORM{'draftid'} || $INFO{'caller'} == 4 ) {
                         $fatxt{'6d'} = $fatxt{'6f'};
                         $fatxt{'6e'} = $fatxt{'6c'};
                     }
                     $startcount++;
                     $pmAttachUser = cloak( $fileUsers[ $y - 1 ] );
                     $my_att_FA .= qq~
             <div id="attform_a_$y" class="att_lft~
                       . ( $y > 1 ? q~_b~ : q{} )
                       . qq~"><b>$fatxt{'6'} $y:</b></div>
             <div id="attform_b_$y" class="att_rgt~
                       . ( $y > 1 ? q~_b~ : q{} ) . qq~">
                 <input type="file" name="file$y" id="file$y" size="50" onchange="selectNewattach($y);" /> <span class="cursor small bold" title="$fatxt{'81'}" onclick="document.getElementById('file$y').value='';">X</span><br />
                         <span style="font-size:x-small">
                 <input type="hidden" id="w_filename$y" name="w_filename$y" value="$files[$y-1]" />
                 <input type="hidden" name="w_fileuser$y" value="$pmAttachUser" />
                 <select id="w_file$y" name="w_file$y" size="1">
                 <option value="attachold" selected="selected">$fatxt{'6d'}</option>
                 <option value="attachdel">$fatxt{'6e'}</option>
                 <option value="attachnew">$fatxt{'6b'}</option>
                 </select>&nbsp;$fatxt{'40'}: <a href="$pmuploadurl/$files[$y-1]" target="_blank">$files[$y-1]</a>
                         </span>~;
                 }
                 else {
                     $my_att_FA .= qq~
             <div id="attform_a_$y" class="att_lft"~
                       . ( $y > 1
                         ? q~ style="visibility:hidden; height:0px"~
                         : q{} )
                       . qq~><b>$fatxt{'6'} $y:</b></div>
             <div id="attform_b_$y" class="att_rgt"~
                       . ( $y > 1
                         ? q~ style="visibility:hidden; height:0px"~
                         : q{} )
                       . qq~>\n             <input type="file" name="file$y" id="file$y" size="50" /> <span class="cursor small bold" title="$fatxt{'81'}" onclick="document.getElementById('file$y').value='';">X</span>~;
                 }
                 $my_att_FA .= qq~\n            </div>\n~;
             }
             if ( !$startcount ) { $startcount = 1; }
   
             if ( $allowAttachIM > 1 ) {
                 $my_att_FA .= qq~
             <script type="text/javascript">
             var countattach = $startcount;~
                   . (
                     $startcount > 1
                     ? qq~\n         document.getElementById("attform_sub").style.visibility = "visible";~
                     : q{}
                   )
                   . qq~
             function enabPrev2(add_sub) {
                 if (add_sub == 1) {
                     countattach = countattach + add_sub;
                     document.getElementById("attform_a_" + countattach).style.visibility = "visible";
                     document.getElementById("attform_a_" + countattach).style.height = "auto";
                     document.getElementById("attform_a_" + countattach).style.paddingTop = "5px";
                     document.getElementById("attform_b_" + countattach).style.visibility = "visible";
                     document.getElementById("attform_b_" + countattach).style.height = "auto";
                     document.getElementById("attform_b_" + countattach).style.paddingTop = "5px";
                 } else {
                     document.getElementById("attform_a_" + countattach).style.visibility = "hidden";
                     document.getElementById("attform_a_" + countattach).style.height = "0px";
                     document.getElementById("attform_a_" + countattach).style.paddingTop = "0px";
                     document.getElementById("attform_b_" + countattach).style.visibility = "hidden";
                     document.getElementById("attform_b_" + countattach).style.height = "0px";
                     document.getElementById("attform_b_" + countattach).style.paddingTop = "0px";
                     countattach = countattach + add_sub;
                 }
                 if (countattach > 1) {
                     document.getElementById("attform_sub").style.visibility = "visible";
                 } else {
                     document.getElementById("attform_sub").style.visibility = "hidden";
                 }
                 if ($allowAttachIM <= countattach) {
                     document.getElementById("attform_add").style.visibility = "hidden";
                 } else {
                     document.getElementById("attform_add").style.visibility = "visible";
                 }
             }
             </script>~;
             }
             $my_imFA .= $my_FA_att;
             $my_imFA =~ s/{yabb my_att_FA}/$my_att_FA/sm;
         }
     }
   
     # /PM File Attachments Browse Box Code
   
     if ( $INFO{'quote'} || $INFO{'reply'} || $FORM{'reply'} )
     {    # if this is a reply, need to pass the reply # forward
         $my_isreply = qq~
             <input type="hidden" name="reply" id="reply" value="$INFO{'quote'}$INFO{'reply'}$FORM{'reply'}" />~;
     }
   
     if ( !$replyguest ) {
         $my_isreply .= qq~
             <input type="checkbox" name="ns" id="ns" value="NS"$nscheck onchange="autoPreview();" /> <label for="ns"><span class="small">$post_txt{'277'}</span></label><br />~;
         if ( $FORM{'draftid'} || $INFO{'caller'} == 4 ) {
             $my_isreply .= qq~
             <input type="checkbox" name="draftleave" id="draftleave" value="1" /> <span class="small"> $post_txt{'draftleave'}</span><br />~;
         }
         my $sentboxAttachInfo;
         if ( $allowAttachIM && $allowGroups ) {
             $sentboxAttachInfo = qq~<br />$inmes_txt{'321'}~;
         }
         $my_isreply .= q~
             <input type="checkbox" name="dontstoreinoutbox" id="dontstoreinoutbox" value="1"~
           . ( $FORM{'dontstoreinoutbox'} ? ' checked="checked"' : q{} )
           . qq~ /> <label for="dontstoreinoutbox"><span class="small">$inmes_txt{'320'}$sentboxAttachInfo</span></label><br />~;
     }
   
     #these are the buttons to submit
     my $sendBMessFlag;
     if ( $sendBMess || $isBMess ) {
         $sendBMessFlag =
           q~<input type="hidden" name="isBMess" id="isBMess" value="yes" />~;
     }
   
     if ($speedpostdetection) {
         $my_spdpost = q~
             <script type="text/javascript">~;
         $my_spdpost .= speedpost();
         $my_spdpost .= q~</script>~;
     }
   
     if ( !$replyguest ) {
         $my_draft =
  qq~&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" name="$draft" id="$draft" value="$inmes_txt{'savedraft'}" accesskey="d" tabindex="7" class="button" />~;
     }
   
     $smilie_url_array  = q{};
     $smilie_code_array = q{};
     $i                 = 0;
     if ( $showadded == 2 ) {
         while ( $SmilieURL[$i] ) {
             if ( $SmilieURL[$i] =~ /\//ism ) { $tmpurl = $SmilieURL[$i]; }
             else { $tmpurl = qq~$defaultimagesdir/$SmilieURL[$i]~; }
             $smilie_url_array .= qq~"$tmpurl", ~;
             $tmpcode = $SmilieCode[$i];
             $tmpcode =~ s/\&quot;/"+'"'+"/gsm;    # "' 
             FromHTML($tmpcode);
             $tmpcode =~ s/&\x2336;/\$/gxsm;
             $tmpcode =~ s/&\x2364;/\@/gxsm;
             $smilie_code_array .= qq~" $tmpcode", ~;
             $i++;
         }
     }
     if ( $showsmdir == 2 ) {
         opendir DIR, "$htmldir/Smilies";
         @contents = readdir DIR;
         closedir DIR;
         foreach my $line ( sort { uc($a) cmp uc $b } @contents ) {
             ( $name, $extension ) = split /\./xsm, $line;
             if (   $extension =~ /gif/ism
                 || $extension =~ /jpg/ism
                 || $extension =~ /jpeg/ism
                 || $extension =~ /png/ism )
             {
                 if ( $line !~ /banner/ism ) {
                     $smilie_url_array  .= qq~"$yyhtml_root/Smilies/$line", ~;
                     $smilie_code_array .= qq~" [smiley=$line]", ~;
                     $i++;
                 }
             }
         }
     }
   
     $my_browser =
       qq~<script src="$yyhtml_root/ajax.js" type="text/javascript"></script>
         <script type="text/javascript">
  ~;
   
sub buildIMsend {    if ( !$replyguest ) {
   &LoadLanguage('InstantMessage');         $my_ajxcall = 'ajximmessage'; 
   &LoadLanguage('Post');         $my_savetable .= my_liveprev(); 
   &LoadCensorList;         $my_savetable .= qq~ 
             $jsIM
   if ($FORM{'previewim'}) {            function showtpstatus() {
       require "$sourcedir/Post.pl";             var theimg = '$pmicon'; 
       if (!$error){ &Preview; $subject = $csubject; }             var objIconSelected = document.getElementById("status").selectedIndex != -1 ? document.getElementById("status").options[document.getElementById("status").selectedIndex].value : 's'; 
       else { &Preview($error); }            if (objIconSelected == 's') { theimg = 'standard'; }
       &FromHTML($message);             if (objIconSelected == 'c') { theimg = 'confidential'; } 
       &FromHTML($subject);             if (objIconSelected == 'u') { theimg = 'urgent'; } 
   }             var picon_show = jsIM.getItem(theimg); 
   $mctitle = $inmes_txt{'775'};             document.images.icons.src = picon_show; 
   ## check for a draft being opened             document.getElementById("iconholder").value = theimg; 
   if ($INFO{'caller'} == 4 && $INFO{'id'}) {             if (autoprev === true) autoPreview(); 
       if (!-e "$memberdir/$username.imdraft") { &fatal_error('cannot_open', "$username.imdraft");}         }~; 
       fopen(DRAFT, "$memberdir/$username.imdraft");         $my_savetable .= q~        showtpstatus(); 
       my @draftPM = <DRAFT>;  ~;
       fclose(DRAFT);     } 
       chomp @draftPM;  
       my $flagfound;  
       foreach my $draftMess (@draftPM) {  
           my ($checkId, undef) = split(/\|/, $draftMess, 2);  
           if ($checkId eq $INFO{'id'}){  
               ($dmessageid, $dmusername, $userto, $usernamecc, $usernamebcc, $subject, $dmdate, $message, $dmpmessageid, $dmreplyno, $dmips, $dmessageStatus, $dmessageFlags, $dstoreFolder, $dmessageAttachment) = split(/\|/, $draftMess);  
               $flagfound = 1;  
               last;  
           }  
       }  
       if (!$flagfound) { &fatal_error('cannot_find_draftmess'); }  
       &FromHTML($message);  
       &FromHTML($subject);  
   }  
   
   my $pmicon = 'standard';  
   $stselect = '';  
   $urselect = '';  
   $cnselect = '';  
   if ($FORM{'status'} || $INFO{'status'}) { $thestatus = $FORM{'status'} || $INFO{'status'}; }  
   elsif ($dmessageStatus){ $thestatus = $dmessageStatus; }  
   else { $thestatus = 's'; }  
   
   if ($thestatus eq 's') { $stselect = qq~ selected="selected"~; }  
   elsif ($thestatus eq 'u') { $urselect = qq~ selected="selected"~; }  
   elsif ($thestatus eq 'c') { $cnselect = qq~ selected="selected"~; }  
   elsif ($thestatus eq 'sb') { $stselect = qq~ selected="selected"~; $sendBMess = 1; }  
   elsif ($thestatus eq 'ub') { $urselect = qq~ selected="selected"~; $sendBMess = 1; }  
   elsif ($thestatus eq 'cb') { $cnselect = qq~ selected="selected"~; $sendBMess = 1; }  
   $sendBMess = 0 unless $sendBMess == 1 && (($PMenableBm_level == 1 && ($iamadmin || $iamgmod || $iammod)) || ($PMenableBm_level == 2 && ($iamadmin || $iamgmod)) || ($PMenableBm_level == 3 && $iamadmin));  
   
   ##########   post code   #########  
   if (!$iamadmin && !$iamgmod && !$staff && ${$uid.$username}{'postcount'} < $numposts) {  
       &fatal_error('im_low_postcount');  
   }  
   
   if (!$replyguest) {  
       if ($is_preview) { $post_txt{'507'} = $post_txt{'771'}; }  
       $normalquot = $post_txt{'599'};  
       $simpelquot = $post_txt{'601'};  
       $simpelcode = $post_txt{'602'};  
       $edittext = $post_txt{'603'};  
       if (!$fontsizemax) { $fontsizemax = 72; }  
       if (!$fontsizemin) { $fontsizemin = 6; }  
   
       # this defines what the top area of the post box will look like:  
       ## if this is a reply , load the 'from' name off the message  
       if ($INFO{'reply'} || $INFO{'quote'}) { $INFO{'to'} = $mfrom; }  
       if (!$INFO{'to'} && $FORM{'to'} ne '') { $INFO{'to'} = $FORM{'to'}; }  
   
       ## if cloaking is enabled, and 'to' is not a blank  
       if ($do_scramble_id && $INFO{'to'} ne '') {  
           &decloak($INFO{'to'});  
       }  
   
       if (!$sendBMess) { &LoadUser($INFO{'to'}); }  
   }  
   
   
   $message =~ s~<br.*?>~\n~gi;  
   $message =~ s/&nbsp;/ /g;  
   &ToChars($message);  
   $message = &Censor($message);  
   &ToHTML($message);  
   $message =~ s/ &nbsp; &nbsp; &nbsp;/\t/ig;  
   
   if ($msubject) { $subject = $msubject; }  
   &ToChars($subject);  
   $subject = &Censor($subject);  
   &ToHTML($subject);  
   
   
   if ($action eq "modify" || $action eq "modify2") {  
       $displayname = qq~$mename~;  
   } else {  
       $displayname = ${$uid.$username}{'realname'};  
   }  
   require "$sourcedir/ContextHelp.pl";  
   &ContextScript("post");  
   
   $MCGlobalFormStart .= qq~  
   $ctmain  
   <script language="JavaScript1.2" src="$yyhtml_root/yabbc.js" type="text/javascript"></script>  
   <script language="JavaScript1.2" src="$yyhtml_root/ubbc.js" type="text/javascript"></script>  
   <script language="JavaScript1.2" type="text/javascript">  
   var displayNames = new Object();  
   $template_names  
   </script>  
   ~;  
   
   if ($prevmain && !$replyguest) {  
       $imsend .= qq~  
   <tr>  
       <td class="windowbg">  
       $prevmain  
       </td>  
   </tr>  
   ~;  
   }  
   
   if (((!$enable_PMcontrols && $enable_PMActprev) || ($enable_PMcontrols && ${$uid.$username}{'pmactprev'})) && !$replyguest) {  
       $imsend .= qq~  
   <tr>  
       <td class="windowbg" valign="top">  
           <table width="95%" align="left" cellpadding="2">  
            <tr>  
             <td align="left">  
              <img name="prevwin" id="prevwin" src="$defaultimagesdir/cat_expand.gif" alt="$npf_txt{'01'}" title="$npf_txt{'01'}" border="0" style="cursor:pointer; cursor:hand;" onclick="enabPrev();" /> <b>$npf_txt{'04'}</b>  
             </td>  
            </tr>  
           </table>  
       </td>  
   </tr>  
   <tr>  
       <td class="windowbg">  
           <div id="savetable" class="bordercolor" style="height:0px; padding:1px; width:100%; margin:auto; visibility:hidden;">  
           <table border="0" width="100%" cellpadding="3" cellspacing="0" style="table-layout:fixed;">  
             <tr>  
               <td class="titlebg">  
                <div id="savetopic" style="height:0px; text-align:left; vertical-align:middle; font-weight:bold; overflow:auto;">&nbsp;</div>  
               </td>  
             </tr>  
             <tr>  
               <td class="windowbg2">  
                <div id="saveframe" class="message" style="height:0px; text-align:left; vertical-align:top; overflow:auto;">&nbsp;</div>  
               </td>  
             </tr>  
           </table>  
           </div>  
       </td>  
   </tr>  
       ~;  
   }  
   
   if ($replyguest) {  
       $imsend .= qq~  
   <tr>  
       <td class="windowbg2">  
       $guest_reply{'guesttext'}  
       </td>  
   </tr>  
       ~;  
   }  
   
   $imsend .= qq~  
   <tr>  
       <td class="windowbg" width="50%">  
           <table width="95%" align="left" cellpadding="2">~;  
   
   if (!$replyguest && !$sendBMess && ($PMenable_cc || $PMenable_bcc)) {  
       $yyjavascripttoform = qq~  
   
           <script language="JavaScript1.2" type="text/javascript">  
           <!--  
           function changeRecepientTab(tabto) {  
               document.getElementById('usersto').style.display = 'none';  
               document.getElementById('bnttoto').className = 'windowbg';  
       ~;  
   
       $imsend .= qq~  
               <tr>  
                   <td align="left">  
                   <div id="bnttoto" style="float: left; padding: 5px;" class="windowbg2"><a href="javascript:void(0);" onclick="changeRecepientTab('to'); return false;">$inmes_txt{'324'}:</a></div>  
       ~;  
       if ($PMenable_cc) {  
           $yyjavascripttoform .= qq~  
               document.getElementById('userscc').style.display = 'none';  
               document.getElementById('bnttocc').className = 'windowbg';  
           ~;  
           $imsend .= qq~  
                   <div id="bnttocc" style="float: left; padding: 5px;" class="windowbg"><a href="javascript:void(0);" onclick="changeRecepientTab('cc'); return false;">$inmes_txt{'325'}:</a></div>  
           ~;  
       }  
       if ($PMenable_bcc) {  
           $yyjavascripttoform .= qq~  
               document.getElementById('usersbcc').style.display = 'none';  
               document.getElementById('bnttobcc').className = 'windowbg';  
           ~;  
           $imsend .= qq~  
                   <div id="bnttobcc" style="float: left; padding: 5px;" class="windowbg"><a href="javascript:void(0);" onclick="changeRecepientTab('bcc'); return false;">$inmes_txt{'326'}:</a></div>  
           ~;  
       }  
       $yyjavascripttoform .= qq~  
               document.getElementById('users' + tabto).style.display = 'inline';  
               document.getElementById('bntto' + tabto).className = 'windowbg2';  
           }  
       //-->  
       </script>  
       ~;  
       $imsend .= qq~$yyjavascripttoform  
                   </td>  
               </tr>  
       ~;  
   }  
   
   $imsend .= qq~  
               <tr>  
                   <td width="60%" valign="top" align="left">\n~;  
   
   # now uses a multi-line select  
   &ProcIMrecs;  
   
   $toname = $INFO{'forward'} ? '' : $INFO{'to'};  
   
   my $toUsersTitle = $inmes_txt{'torecepients'};  
   
   my ($onchangeText, $onchangeText2);  
   if (((!$enable_PMcontrols && $enable_PMActprev) || ($enable_PMcontrols && ${$uid.$username}{'pmactprev'})) && !$replyguest) {  
       $onchangeText = qq~ onkeyup="updatTopic();"~;  
       $onchangeText2 = qq~ updatTopic();~;  
   }  
   
   if (!$replyguest) {  
       if ($sendBMess) { $toUsersTitle = $inmes_txt{'togroups'}; }  
       if ($PMenable_cc || $PMenable_bcc) {  
           $us_winhight = 370;  
       } else {  
           $us_winhight = 345;  
       }  
   
       my $toIdtext = $sendBMess ? 'groups' : 'toshow';  
   
       $imsend  .= qq~  
       <script language="JavaScript1.2" type="text/javascript">  
       <!--  
       function imWin() {  
           window.open('$scripturl?action=imlist;sort=recentpm;toid=$toIdtext','imWin','status=no,height=$us_winhight,width=464,menubar=no,toolbar=no,top=50,left=50,scrollbars=no');  
       }  
       function imWinCC() {  
           window.open('$scripturl?action=imlist;sort=recentpm;toid=toshowcc','imWin','status=no,height=$us_winhight,width=464,menubar=no,toolbar=no,top=50,left=50,scrollbars=no');  
       }  
       function imWinBCC() {  
           window.open('$scripturl?action=imlist;sort=recentpm;toid=toshowbcc','imWin','status=no,height=$us_winhight,width=464,menubar=no,toolbar=no,top=50,left=50,scrollbars=no');  
       }  
       function removeUser(oElement) {  
           var indexToRemove = oElement.options.selectedIndex;  
           if (confirm("$post_txt{'768'}")) { oElement.remove(indexToRemove); }  
       }  
       //-->  
       </script>  
       <div id="usersto" style="width: 98%; display: inline; float: left;">  
       <b>$inmes_txt{'324'} $toUsersTitle:</b>&nbsp;<a href="javascript: void(0);" onclick="imWin();" tabindex="1"><span class="small">$inmes_txt{'clickto1'} <i>$inmes_txt{'324'}</i> $toUsersTitle $inmes_txt{'clickto2'}</span></a><br />  
       <select name="toshow" id="toshow" multiple="multiple" size="6" style="width: 100%;" ondblclick="removeUser(this);">\n~;  
   
       my $usefields;  
       if (!$sendBMess) {  
           if ($toname) {  
               &LoadUser($toname);  
               if(${$uid.$toname}{'realname'}) {  
                   $imsend  .= qq~<option selected="selected" value="$useraccount{$toname}">${$uid.$toname}{'realname'}</option>\n~;  
               }  
           }  
           if ($FORM{'toshow'}) {  
               foreach my $touser (split(/,/, $FORM{'toshow'})) {  
                   &LoadUser($touser);  
                   $imsend .= qq~<option selected="selected" value="$useraccount{$touser}">${$uid.$touser}{'realname'}</option>\n~;  
               }  
           }  
           if ($userto) {  
               foreach my $touser (split(/,/, $userto)) {  
                   &LoadUser($touser);  
                   $imsend .= qq~<option selected="selected" value="$useraccount{$touser}">${$uid.$touser}{'realname'}</option>\n~;  
               }  
           }  
   
       } else {  
           $FORM{'toshow'} = $mto || $FORM{'toshow'};  
           if ($FORM{'toshow'}) {  
               foreach my $touser (split(/,/, $FORM{'toshow'})) {  
                   if ($touser eq 'all') { $imsend .= qq~<option selected="selected" value="all">$inmes_txt{'bmallmembers'}</option>\n~;  
                   } elsif ($touser eq 'admins') { $imsend .= qq~<option selected="selected" value="admins">$inmes_txt{'bmadmins'}</option>\n~;  
                   } elsif ($touser eq 'gmods') { $imsend .= qq~<option selected="selected" value="gmods">$inmes_txt{'bmgmods'}</option>\n~;  
                   } elsif ($touser eq 'mods') { $imsend .= qq~<option selected="selected" value="mods">$inmes_txt{'bmmods'}</option>\n~;  
                   } else {  
                       foreach (keys %NoPost) {  
                           my ($title, undef) = split(/\|/, $NoPost{$_}, 2);  
                           if ($touser eq $_) { $imsend .= qq~<option selected="selected" value="$_">$title</option>\n~; }  
                       }  
                   }  
               }  
           }  
       }  
   
       $imsend .= qq~            </select><input type="hidden" name="immulti" value="yes" />  
           </div>  
       ~;  
   
       $JSandInput = qq~  
       <script language="JavaScript1.2" type="text/javascript">  
       <!--  
       // this function forces all users listed on IM mult to be selected for processing  
       function selectNames() {  
           var oList = document.getElementById('toshow')  
           for (var i = 0; i < oList.options.length; i++) { oList.options[i].selected = true; }  
       ~;  
   
       if (!$sendBMess) {  
           if ($PMenable_cc) {  
               $JSandInput .= qq~  
                   var oList = document.getElementById('toshowcc')  
                   for (var i = 0; i < oList.options.length; i++){ oList.options[i].selected = true; }  
               ~;  
               $imsend .= qq~  
               <div id="userscc" style="width: 98%; display: none; float: left;">  
               <b>$inmes_txt{'325'} $toUsersTitle:</b>&nbsp;<a href="javascript: void(0);" onclick="imWinCC();"><span class="small">$inmes_txt{'clickto1'} <i>$inmes_txt{'325'}</i> $toUsersTitle $inmes_txt{'clickto2'}</span></a><br />  
               <select name="toshowcc" id="toshowcc" multiple="multiple" size="6" style="width: 100%;" ondblclick="removeUser(this);">\n~;  
               if ($FORM{'toshowcc'}) {  
                   foreach my $touser (split(/\,/, $FORM{'toshowcc'})) {  
                       &LoadUser($touser);  
                       $imsend .= qq~<option selected="selected" value="$useraccount{$touser}">${$uid.$touser}{'realname'}</option>\n~;  
                   }  
               }  
               if ($usernamecc) {  
                   foreach my $touser (split(/\,/, $usernamecc)) {  
                       &LoadUser($touser);  
                       $imsend .= qq~<option selected="selected" value="$useraccount{$touser}">${$uid.$touser}{'realname'}</option>\n~;  
                   }  
               }  
               $imsend .= qq~                </select>  
               </div>  
               ~;  
           }  
   
           if ($PMenable_bcc) {  
               $JSandInput .= qq~  
                   var oList = document.getElementById('toshowbcc')  
                   for (var i = 0; i < oList.options.length; i++) { oList.options[i].selected = true; }  
               ~;  
               $imsend .= qq~  
               <div id="usersbcc" style="width: 98%; display: none; float: left;">  
               <b>$inmes_txt{'326'} $toUsersTitle:</b>&nbsp;<a href="javascript: void(0);" onclick="imWinBCC();"><span class="small">$inmes_txt{'clickto1'} <i>$inmes_txt{'326'}</i> $toUsersTitle $inmes_txt{'clickto2'}</span></a><br />  
               <select name="toshowbcc" id="toshowbcc" multiple="multiple" size="6" style="width: 100%;" ondblclick="removeUser(this);">\n~;  
               if ($FORM{'toshowbcc'}) {  
                   foreach my $touser (split(/\,/, $FORM{'toshowbcc'})) {  
                       &LoadUser($touser);  
                       $imsend .= qq~<option selected="selected" value="$useraccount{$touser}">${$uid.$touser}{'realname'}</option>\n~;  
                   }  
               }  
               if ($usernamebcc) {  
                   foreach my $touser (split(/\,/, $usernamebcc)) {  
                       &LoadUser($touser);  
                       $imsend .= qq~<option selected="selected" value="$useraccount{$touser}">${$uid.$touser}{'realname'}</option>\n~;  
                   }  
               }  
               $imsend .= qq~                </select>  
               </div>  
               ~;  
           }  
       }  
   
       $JSandInput .= qq~  
           }  
       //-->  
       </script>  
       ~;  
   
       $imsend .= qq~  
                   </td>  
                   <td width="40%" valign="top" align="left">  
                       <label for="status"><b>$inmes_txt{'status'}:</b></label><br />  
                       <select name="status" id="status" tabindex="2" size="3" onchange="showtpstatus();$onchangeText2">  
                       <option value="s"$stselect>$im_message_status{'standard'}</option>  
                       <option value="c"$cnselect>$im_message_status{'confidential'}</option>  
                       <option value="u"$urselect>$im_message_status{'urgent'}</option>  
                       </select><img src="$imagesdir/$pmicon.gif" name="icons" border="0" hspace="10" alt="$im_message_status{'$pmicon'}" title="$im_message_status{'$pmicon'}" />  
                   </td>  
                   </tr>  
               </table>  
           </td>  
       </tr>  
       ~;  
   
   } else {  
   
       $imsend .= qq~                        <b>$inmes_txt{'324'} $toUsersTitle:</b> <input type="text" name="toguest" id="toguest" value="$guestName" size="50" maxlength="25" style="width: 95%;" /><input type="hidden" name="toshow" id="toshow" value="$guestName" />  
                   </td>  
                   <td width="40%" valign="top" align="left">  
                       &nbsp;  
                   </td>  
               </tr>  
               <tr>  
                   <td width="60%" valign="top" align="left">  
                       <b>$post_txt{'69'}:</b> <input type="text" name="guestemail" id="guestemail" value="$guestEmail" size="50" maxlength="40" style="width: 95%;" />  
                       <input type="hidden" name="replyguest" id="replyguest" value="1" />  
                   </td>  
                   <td width="40%" valign="top" align="left">  
                       &nbsp;  
                   </td>  
               </tr>  
               </table>  
           </td>  
       </tr>  
       ~;  
   }  
   
   $subtitle = "<i>$subject</i>";  
   #this is the end of the upper area of the post page.  
   
   # this declares the beginning of the UBBC section  
   $JSandInput .= qq~  
   <script language="JavaScript1.2" type="text/javascript">  
   <!--  
   function showimage() {  
       document.images.status.src=document.postmodify.status.options[document.postmodify.images.status.selectedIndex].value;  
   }  
   //-->  
   </script>  
   ~;  
   
   $JSandInput .= qq~  
   <input type="hidden" name="threadid" id="threadid" value="$threadid" />  
   <input type="hidden" name="postid" id="postid" value="$postid" />  
   <input type="hidden" name="info" id="info" value="$INFO{'id'}$FORM{'info'}" />  
   <input type="hidden" name="mename" id="mename" value="$mename" />  
   <input type="hidden" name="post_entry_time" id="post_entry_time" value="$date" />  
   ~;  
   
   if ($FORM{'draftid'} || $INFO{'caller'} == 4) {  
       $JSandInput .= qq~<input type="hidden" name="draftid" id="draftid" value="~ . ($FORM{'draftid'} || $INFO{'id'}) . qq~" />~;  
   }  
   
   $imsend .= qq~  
   <tr>  
       <td align="left" class="windowbg2">  
           $JSandInput  
           <label for="subject"><b>$inmes_txt{'70'}:</b></label><br /><input type="text" name="subject" id="subject" value="$subject" size="50" maxlength="~ . ($set_subjectMaxLength + ($subject =~ /^Re: / ? 4 : 0)) . qq~" tabindex="3" style="width: 437px;"$onchangeText />  
       </td>  
   
   </tr>  
   <tr>  
       <td class="windowbg2">  
   ~;  
   
   # this is for the ubbc buttons  
   if (!$replyguest) {  
       if ($enable_ubbc && $showyabbcbutt) {  
           $imsend .= qq~<b>$post_txt{'252'}:</b><br />  
           <div style="float: left; width: 440px;">  
           <script language="JavaScript1.2" type="text/javascript">  
           <!--  
           HAND = "style='cursor: pointer;'";  
           HAND += " onmouseover='contextTip(event, this.alt)' onmouseout='contextTip(event, this.alt)' oncontextmenu='if(!showcontexthelp(this.src, this.alt)) return false;'";  
           document.write('<div style="width: 437px; float: left;">');  
           document.write("<img src='$imagesdir/url.gif' onclick='hyperlink();' "+HAND+" align='top' width='23' height='22' alt='$post_txt{'257'}' title='$post_txt{'257'}' border='0' />");  
           document.write("<img src='$imagesdir/ftp.gif' onclick='ftp();' "+HAND+" align='top' width='23' height='22' alt='$post_txt{'434'}' title='$post_txt{'434'}' border='0' />");  
           document.write("<img src='$imagesdir/img.gif' onclick='image();' "+HAND+" align='top' width='23' height='22' alt='$post_txt{'435'}' title='$post_txt{'435'}' border='0' />");  
           document.write("<img src='$imagesdir/email2.gif' onclick='emai1();' "+HAND+" align='top' width='23' height='22' alt='$post_txt{'258'}' title='$post_txt{'258'}' border='0' />");  
           document.write("<img src='$imagesdir/media.gif' onclick='flash();' "+HAND+" align='top' width='23' height='22' alt='$post_txt{'433'}' title='$post_txt{'433'}' border='0' />");  
           document.write("<img src='$imagesdir/table.gif' onclick='table();' "+HAND+" align='top' width='23' height='22' alt='$post_txt{'436'}' title='$post_txt{'436'}' border='0' />");  
           document.write("<img src='$imagesdir/tr.gif' onclick='trow();' "+HAND+" align='top' width='23' height='22' alt='$post_txt{'449'}' title='$post_txt{'449'}' border='0' />");  
           document.write("<img src='$imagesdir/td.gif' onclick='tcol();' "+HAND+" align='top' width='23' height='22' alt='$post_txt{'437'}' title='$post_txt{'437'}' border='0' />");  
           document.write("<img src='$imagesdir/hr.gif' onclick='hr();' "+HAND+" align='top' width='23' height='22' alt='$post_txt{'531'}' title='$post_txt{'531'}' border='0' />");  
           document.write("<img src='$imagesdir/tele.gif' onclick='teletype();' "+HAND+" align='top' width='23' height='22' alt='$post_txt{'440'}' title='$post_txt{'440'}' border='0' />");  
           document.write("<img src='$imagesdir/code.gif' onclick='selcodelang();' "+HAND+" align='top' width='23' height='22' alt='$post_txt{'259'}' title='$post_txt{'259'}' border='0' />");  
           document.write("<img src='$imagesdir/quote2.gif' onclick='quote();' "+HAND+" align='top' width='23' height='22' alt='$post_txt{'260'}' title='$post_txt{'260'}' border='0' />");  
           document.write("<img src='$imagesdir/edit.gif' onclick='edit();' "+HAND+" align='top' width='23' height='22' alt='$post_txt{'603'}' title='$post_txt{'603'}' border='0' />");  
           document.write("<img src='$imagesdir/sup.gif' onclick='superscript();' "+HAND+" align='top' width='23' height='22' alt='$post_txt{'447'}' title='$post_txt{'447'}' border='0' />");  
           document.write("<img src='$imagesdir/sub.gif' onclick='subscript();' "+HAND+" align='top' width='23' height='22' alt='$post_txt{'448'}' title='$post_txt{'448'}' border='0' />");  
   
           document.write("<img src='$imagesdir/list.gif' onclick='bulletset();' "+HAND+" align='top' width='23' height='22' alt='$post_txt{'261'}' title='$post_txt{'261'}' border='0' />");  
           document.write("<img src='$imagesdir/me.gif' onclick='me();' "+HAND+" align='top' width='23' height='22' alt='$post_txt{'604'}' title='$post_txt{'604'}' border='0' />");  
           document.write("<img src='$imagesdir/move.gif' onclick='move();' "+HAND+" align='top' width='23' height='22' alt='$post_txt{'439'}' title='$post_txt{'439'}' border='0' />");  
           document.write("<img src='$imagesdir/timestamp.gif' onclick='timestamp($date);' "+HAND+" align='top' width='23' height='22' alt='$post_txt{'245'}' title='$post_txt{'245'}' border='0' /><br />");  
           document.write('</div>');  
           document.write('<div style="width: 115px; float: left;">');  
           document.write("<img src='$imagesdir/bold.gif' onclick='bold();' "+HAND+" align='top' width='23' height='22' alt='$post_txt{'253'}' title='$post_txt{'253'}' border='0' />");  
           document.write("<img src='$imagesdir/italicize.gif' onclick='italicize();' "+HAND+" align='top' width='23' height='22' alt='$post_txt{'254'}' title='$post_txt{'254'}' border='0' />");  
           document.write("<img src='$imagesdir/underline.gif' onclick='underline();' "+HAND+" align='top' width='23' height='22' alt='$post_txt{'255'}' title='$post_txt{'255'}' border='0' />");  
           document.write("<img src='$imagesdir/strike.gif' onclick='strike();' "+HAND+" align='top' width='23' height='22' alt='$post_txt{'441'}' title='$post_txt{'441'}' border='0' />");  
           document.write("<img src='$imagesdir/highlight.gif' onclick='highlight();' "+HAND+" align='top' width='23' height='22' alt='$post_txt{'246'}' title='$post_txt{'246'}' border='0' />");  
           document.write('</div>');  
           document.write('<div style="width: 139px; float: left; text-align: center;">');  
           document.write('<select name="fontface" id="fontface" onchange="if(this.options[this.selectedIndex].value) fontfce(this.options[this.selectedIndex].value);" style="width: 90px; margin-top: 2px; margin-left: 2px; margin-right: 1px; font-size: 9px;">');  
           document.write('<option value="">Verdana</option>');  
           document.write('<option value="">-\\-\\-\\-\\-\\-\\-\\-\\-</option>');  
           document.write('<option value="Arial" style="font-family: Arial">Arial</option>');  
           document.write('<option value="Bitstream Vera Sans Mono" style="font-family: Bitstream Vera Sans Mono">Bitstream</option>');  
           document.write('<option value="Bradley Hand ITC" style="font-family: Bradley Hand ITC">Bradley Hand ITC</option>');  
           document.write('<option value="Comic Sans MS" style="font-family: Comic Sans MS">Comic Sans MS</option>');  
           document.write('<option value="Courier" style="font-family: Courier">Courier</option>');  
           document.write('<option value="Courier New" style="font-family: Courier New">Courier New</option>');  
           document.write('<option value="Georgia" style="font-family: Georgia">Georgia</option>');  
           document.write('<option value="Impact" style="font-family: Impact">Impact</option>');  
           document.write('<option value="Lucida Sans" style="font-family: Lucida Sans">Lucida Sans</option>');  
           document.write('<option value="Microsoft Sans Serif" style="font-family: Microsoft Sans Serif">MS Sans Serif</option>');  
           document.write('<option value="Papyrus" style="font-family: Papyrus">Papyrus</option>');  
           document.write('<option value="Tahoma" style="font-family: Tahoma">Tahoma</option>');  
           document.write('<option value="Tempus Sans ITC" style="font-family: Tempus Sans ITC">Tempus Sans ITC</option>');  
           document.write('<option value="Times New Roman" style="font-family: Times New Roman">Times New Roman</option>');  
           document.write('<option value="Verdana" style="font-family: Verdana" selected="selected">Verdana</option>');  
           document.write('</select>');  
           var fntoptions = ["6", "7", "8", "9", "10", "11", "12", "14", "16", "18", "20", "22", "24", "36", "48", "56", "72"]  
           document.write('<select name="fontsize" id="fontsize" onchange="if(this.options[this.selectedIndex].value) fntsize(this.options[this.selectedIndex].value);" style="width: 39px; margin-top: 2px; margin-left: 1px; margin-right: 2px; font-size: 9px;">');  
           document.write('<option value="">11</option>');  
           document.write('<option value="">-\\-</option>');  
           for(var i = 0; i < fntoptions.length; i++) {  
               if(fntoptions[i] >= $fontsizemin && fntoptions[i] <= $fontsizemax) {  
                   if(fntoptions[i] == 11) document.write('<option value="11" selected="selected">11</option>');  
                   else document.write('<option value=' + fntoptions[i] + '>' + fntoptions[i] + '</option>');  
               }  
           }  
           document.write('</select>');  
           document.write('</div>');  
   
   
           function selcodelang() {  
               if (document.getElementById("codelang").style.display == "none")  
               document.getElementById("codelang").style.display = "inline-block";  
               else  
               document.getElementById("codelang").style.display = "none";  
               document.getElementById("codelang").style.zIndex = "100";  
   
               var openbox = document.getElementsByTagName("div");  
               for (var i = 0; i < openbox.length; i++) {  
                   if (openbox[i].className == "ubboptions" && openbox[i].id != "codelang") {  
                       openbox[i].style.display = "none";  
                   }  
               }  
           }  
   
           function syntaxlang(lang, optnum) {  
               AddSelText("[code"+lang+"]","[/code]");  
               document.getElementById("codesyntax").options[optnum].selected = false;  
               document.getElementById("codelang").style.display = "none";  
           }  
   
           function bulletset() {  
               if (document.getElementById("bullets").style.display == "none")  
               document.getElementById("bullets").style.display = "block";  
               else  
               document.getElementById("bullets").style.display = "none";  
               document.getElementById("bullets").style.zIndex = "100";  
   
               var openbox = document.getElementsByTagName("div");  
               for (var i = 0; i < openbox.length; i++) {  
                   if (openbox[i].className == "ubboptions" && openbox[i].id != "bullets") {  
                       openbox[i].style.display = "none";  
                   }  
               }  
           }  
   
           function showbullets(bullet) {  
               AddSelText("[list "+bullet+"][*]", "\\n[/list]");  
           }  
   
           function olist() {  
               AddSelText("[olist][*]", "\\n[/olist]");  
           }  
           function ulist() {  
                 AddSelText("[list][*]", "\\n[/list]");  
           }  
   
           // Palette  
           var thistask = 'post';  
           function tohex(i) {  
               a2 = ''   
               ihex = hexQuot(i);  
               idiff = eval(i + '-(' + ihex + '*16)')  
               a2 = itohex(idiff) + a2;  
               while( ihex >= 16) {  
                   itmp = hexQuot(ihex);  
                   idiff = eval(ihex + '-(' + itmp + '*16)');  
                   a2 = itohex(idiff) + a2;  
                   ihex = itmp;  
               }  
               a1 = itohex(ihex);  
               return a1 + a2 ;  
           }  
   
           function hexQuot(i) {  
               return Math.floor(eval(i +'/16'));  
           }  
   
           function itohex(i) {  
               if( i == 0) { aa = '0' }  
               else { if( i == 1 ) { aa = '1' }  
               else { if( i == 2 ) { aa = '2' }  
               else { if( i == 3 ) { aa = '3' }  
               else { if( i == 4 ) { aa = '4' }  
               else { if( i == 5 ) { aa = '5' }  
               else { if( i == 6 ) { aa = '6' }  
               else { if( i == 7 ) { aa = '7' }  
               else { if( i == 8 ) { aa = '8' }  
               else { if( i == 9 ) { aa = '9' }  
               else { if( i == 10) { aa = 'a' }  
               else { if( i == 11) { aa = 'b' }  
               else { if( i == 12) { aa = 'c' }  
               else { if( i == 13) { aa = 'd' }  
               else { if( i == 14) { aa = 'e' }  
               else { if( i == 15) { aa = 'f' }  
               }}}}}}}}}}}}}}}  
               return aa;  
           }  
   
           function ConvShowcolor(color) {  
               if ( c=color.match(/rgb\\((\\d+?)\\, (\\d+?)\\, (\\d+?)\\)/i) ) {  
                   var rhex = tohex(c[1]);  
                   var ghex = tohex(c[2]);  
                   var bhex = tohex(c[3]);  
                   var newcolor = '#'+rhex+ghex+bhex;  
               }  
               else {  
                   var newcolor = color;  
               }  
               if(thistask == "post") showcolor(newcolor);  
               if(thistask == "templ") previewColor(newcolor);  
           }  
           //-->  
           </script>  
           <div style="float: left; height: 22px; width: 91px;">  
           <div class="bordercolor" style="height: 20px; width: 66px; padding-left: 1px; padding-top: 1px; margin-top: 1px; float: left;">  
               <span style="float: left; background-color: #000000; width: 10px; height: 9px; margin-right: 1px; margin-bottom: 1px; border: 0px; font-size: 5px; cursor: pointer; cursor: hand;" onclick="ConvShowcolor('#000000')">&nbsp;</span>  
               <span style="float: left; background-color: #333333; width: 10px; height: 9px; margin-right: 1px; margin-bottom: 1px; border: 0px; font-size: 5px; cursor: pointer; cursor: hand;" onclick="ConvShowcolor('#333333')">&nbsp;</span>  
               <span style="float: left; background-color: #666666; width: 10px; height: 9px; margin-right: 1px; margin-bottom: 1px; border: 0px; font-size: 5px; cursor: pointer; cursor: hand;" onclick="ConvShowcolor('#666666')">&nbsp;</span>  
               <span style="float: left; background-color: #999999; width: 10px; height: 9px; margin-right: 1px; margin-bottom: 1px; border: 0px; font-size: 5px; cursor: pointer; cursor: hand;" onclick="ConvShowcolor('#999999')">&nbsp;</span>  
               <span style="float: left; background-color: #cccccc; width: 10px; height: 9px; margin-right: 1px; margin-bottom: 1px; border: 0px; font-size: 5px; cursor: pointer; cursor: hand;" onclick="ConvShowcolor('#cccccc')">&nbsp;</span>  
               <span style="float: left; background-color: #ffffff; width: 10px; height: 9px; margin-right: 1px; margin-bottom: 1px; border: 0px; font-size: 5px; cursor: pointer; cursor: hand;" onclick="ConvShowcolor('#ffffff')">&nbsp;</span>  
               <span id="defaultpal1" style="float: left; background-color: $pallist[0]; width: 10px; height: 9px; margin-right: 1px; margin-bottom: 1px; border: 0px; font-size: 5px; cursor: pointer; cursor: hand;" onclick="ConvShowcolor(this.style.backgroundColor)">&nbsp;</span>  
               <span id="defaultpal2" style="float: left; background-color: $pallist[1]; width: 10px; height: 9px; margin-right: 1px; margin-bottom: 1px; border: 0px; font-size: 5px; cursor: pointer; cursor: hand;" onclick="ConvShowcolor(this.style.backgroundColor)">&nbsp;</span>  
               <span id="defaultpal3" style="float: left; background-color: $pallist[2]; width: 10px; height: 9px; margin-right: 1px; margin-bottom: 1px; border: 0px; font-size: 5px; cursor: pointer; cursor: hand;" onclick="ConvShowcolor(this.style.backgroundColor)">&nbsp;</span>  
               <span id="defaultpal4" style="float: left; background-color: $pallist[3]; width: 10px; height: 9px; margin-right: 1px; margin-bottom: 1px; border: 0px; font-size: 5px; cursor: pointer; cursor: hand;" onclick="ConvShowcolor(this.style.backgroundColor)">&nbsp;</span>  
               <span id="defaultpal5" style="float: left; background-color: $pallist[4]; width: 10px; height: 9px; margin-right: 1px; margin-bottom: 1px; border: 0px; font-size: 5px; cursor: pointer; cursor: hand;" onclick="ConvShowcolor(this.style.backgroundColor)">&nbsp;</span>  
               <span id="defaultpal6" style="float: left; background-color: $pallist[5]; width: 10px; height: 9px; margin-right: 1px; margin-bottom: 1px; border: 0px; font-size: 5px; cursor: pointer; cursor: hand;" onclick="ConvShowcolor(this.style.backgroundColor)">&nbsp;</span>  
           </div>  
           <div style="height: 22px; width: 23px; padding-left: 1px; float: right;">  
               <img src="$imagesdir/palette1.gif" style="cursor: pointer" onclick="window.open('$scripturl?action=palette;task=post', '', 'height=308,width=302,menubar=no,toolbar=no,scrollbars=no')" alt="" border="0" />  
           </div>  
           </div>  
           <script language="JavaScript1.2" type="text/javascript">  
           <!--  
           HAND = "style='cursor: pointer;'";  
           HAND += " onmouseover='contextTip(event, this.alt)' onmouseout='contextTip(event, this.alt)' oncontextmenu='if(!showcontexthelp(this.src, this.alt)) return false;'";  
           document.write('<div style="width: 92px; float: left;">');  
           document.write("<img src='$imagesdir/pre.gif' onclick='pre();' "+HAND+" align='top' width='23' height='22' alt='$post_txt{'444'}' title='$post_txt{'444'}' border='0' />");  
           document.write("<img src='$imagesdir/left.gif' onclick='left();' "+HAND+" align='top' width='23' height='22' alt='$post_txt{'445'}' title='$post_txt{'445'}' border='0' />");  
           document.write("<img src='$imagesdir/center.gif' onclick='center();' "+HAND+" align='top' width='23' height='22' alt='$post_txt{'256'}' title='$post_txt{'256'}' border='0' />");  
           document.write("<img src='$imagesdir/right.gif' onclick='right();' "+HAND+" align='top' width='23' height='22' alt='$post_txt{'446'}' title='$post_txt{'446'}' border='0' />");  
           document.write('</div>');  
           //-->  
           </script>  
           <noscript>  
           <span class="small">$maintxt{'noscript'}</span>  
           </noscript>  
           </div><div id="spell_container" style="float: left;"></div>  
           ~;  
       }  
   }  
   
   if ($replyguest) {  
       $tmpmtext =qq~<b>$post_txt{'72'}:</b> ~;  
   }  
   
   # set size of messagebox and text  
   if (!${$uid.$username}{'postlayout'}) { $pheight = 130; $pwidth = 425; $textsize = 10; }  
   else { ($pheight, $pwidth, $textsize, $col_row) = split(/\|/, ${$uid.$username}{'postlayout'}); }  
   if(!$textsize || $textsize < 6) { $textsize = 6; }  
   if($textsize > 16) { $textsize = 16; }  
   if($pheight > 400) { $pheight = 400; }  
   if($pheight < 130) { $pheight = 130; }  
   if($pwidth > 855) { $pwidth = 855; }  
   if($pwidth < 425) { $pwidth = 425; }  
   $mtextsize = $textsize . "pt";  
   $mheight = $pheight . "px";  
   $mwidth = $pwidth . "px";  
   $dheight = ($pheight + 12) . "px";  
   $dwidth = ($pwidth + 12) . "px";  
   $jsdragwpos = $pwidth - 425;  
   $dragwpos = ($pwidth - 425) . "px";  
   $jsdraghpos = $pheight - 130;  
   $draghpos = ($pheight - 130) . "px";  
   
   $imsend .= qq~  
       <div style="float: left; width: 99%;">  
       <div style="float: left; text-align: left;">  
       <input type="hidden" name="col_row" value="$col_row" />  
       <input type="hidden" name="messagewidth" id="messagewidth" value="$pwidth" />  
       <input type="hidden" name="messageheight" id="messageheight" value="$pheight" />  
       <div id="dragcanvas" style="position: relative; top: 0px; left: 0px; height: $dheight; width: $dwidth; border: 0; z-index: 1;">  
       <textarea name="message" id="message" rows="8" cols="68" style="position: absolute; top: 0px; left: 0px; z-index: 2; height: $mheight; width: $mwidth; font-size: $mtextsize; padding: 5px; margin: 0px; visibility: visible;" onclick="storeCaret(this);" onkeyup="storeCaret(this);" onchange="storeCaret(this);" tabindex="4">$message</textarea>  
       <div id="dragbgw" style="position: absolute; top: 0px; left: 437px; width: 3px; height: $dheight; border: 0; z-index: 3;">  
       <img id="dragImg1" src="$defaultimagesdir/resize_wb.gif" class="drag" style="position: absolute; top: 0px; left: $dragwpos; z-index: 4; width: 3px; height: $dheight; cursor: e-resize;" alt="resize_wb" />  
       </div>  
   
       <div id="dragbgh" style="position: absolute; top: 142px; left: 0px; width: $dwidth; height: 3px; border: 0; z-index: 3;">  
       <img id="dragImg2" src="$defaultimagesdir/resize_hb.gif" class="drag" style="position: absolute; top: $draghpos; left: 0px; z-index: 4; width: $dwidth; height: 3px; cursor: n-resize;"  alt="resize_hb" />  
       </div>  
       <div class="ubboptions" id="bullets" style="position: absolute; top: -22px; left: 345px; width: 63px; border: 1px solid #666666; padding: 2px; text-align: center; background-color: #CCCCCC; display: none;">  
           <input type="button" value="$npf_txt{'default'}" style="width: 56px; margin: 3px 0px 0px 0px; font-size: 9px; padding: 0px; text-align: center;" onclick="ulist(), bulletset()" /><br />  
           <input type="button" value="$npf_txt{'ordered'}" style="width: 56px; margin: 3px 0px 3px 0px; font-size: 9px; padding: 0px; text-align: center;" onclick="olist(), bulletset()" /><br />  
           <img src="$defaultimagesdir/bull-redball.gif" style="width: 8px; height: 8px; background-color: #CCCCCC; margin: 3px; cursor: pointer;" onclick="showbullets('bull-redball'), bulletset()" /><img src="$defaultimagesdir/bull-greenball.gif" style="width: 8px; height: 8px; background-color: #CCCCCC; margin: 3px; cursor: pointer;" onclick="showbullets('bull-greenball'), bulletset()" /><img src="$defaultimagesdir/bull-blueball.gif" style="width: 8px; height: 8px; background-color: #CCCCCC; margin: 3px; cursor: pointer;" onclick="showbullets('bull-blueball'), bulletset()" /><img src="$defaultimagesdir/bull-blackball.gif" style="width: 8px; height: 8px; background-color: #CCCCCC; margin: 3px; cursor: pointer;" onclick="showbullets('bull-blackball'), bulletset()" /><br />  
           <img src="$defaultimagesdir/bull-redsq.gif" style="width: 8px; height: 8px; background-color: #CCCCCC; margin: 3px; cursor: pointer;" onclick="showbullets('bull-redsq'), bulletset()" /><img src="$defaultimagesdir/bull-greensq.gif" style="width: 8px; height: 8px; background-color: #CCCCCC; margin: 3px; cursor: pointer;" onclick="showbullets('bull-greensq'), bulletset()" /><img src="$defaultimagesdir/bull-bluesq.gif" style="width: 8px; height: 8px; background-color: #CCCCCC; margin: 3px; cursor: pointer;" onclick="showbullets('bull-bluesq'), bulletset()" /><img src="$defaultimagesdir/bull-blacksq.gif" style="width: 8px; height: 8px; background-color: #CCCCCC; margin: 3px; cursor: pointer;" onclick="showbullets('bull-blacksq'), bulletset()" /><br />  
           <img src="$defaultimagesdir/bull-redpin.gif" style="width: 8px; height: 8px; background-color: #CCCCCC; margin: 3px; cursor: pointer;" onclick="showbullets('bull-redpin'), bulletset()" /><img src="$defaultimagesdir/bull-greenpin.gif" style="width: 8px; height: 8px; background-color: #CCCCCC; margin: 3px; cursor: pointer;" onclick="showbullets('bull-greenpin'), bulletset()" /><img src="$defaultimagesdir/bull-bluepin.gif" style="width: 8px; height: 8px; background-color: #CCCCCC; margin: 3px; cursor: pointer;" onclick="showbullets('bull-bluepin'), bulletset()" /><img src="$defaultimagesdir/bull-blackpin.gif" style="width: 8px; height: 8px; background-color: #CCCCCC; margin: 3px; cursor: pointer;" onclick="showbullets('bull-blackpin'), bulletset()" /><br />  
           <img src="$defaultimagesdir/bull-redcheck.gif" style="width: 8px; height: 8px; background-color: #CCCCCC; margin: 3px; cursor: pointer;" onclick="showbullets('bull-redcheck'), bulletset()" /><img src="$defaultimagesdir/bull-greencheck.gif" style="width: 8px; height: 8px; background-color: #CCCCCC; margin: 3px; cursor: pointer;" onclick="showbullets('bull-greencheck'), bulletset()" /><img src="$defaultimagesdir/bull-bluecheck.gif" style="width: 8px; height: 8px; background-color: #CCCCCC; margin: 3px; cursor: pointer;" onclick="showbullets('bull-bluecheck'), bulletset()" /><img src="$defaultimagesdir/bull-blackcheck.gif" style="width: 8px; height: 8px; background-color: #CCCCCC; margin: 3px; cursor: pointer;" onclick="showbullets('bull-blackcheck'), bulletset()" /><br />  
           <img src="$defaultimagesdir/bull-redarrow.gif" style="width: 8px; height: 8px; background-color: #CCCCCC; margin: 3px; cursor: pointer;" onclick="showbullets('bull-redarrow'), bulletset()" /><img src="$defaultimagesdir/bull-greenarrow.gif" style="width: 8px; height: 8px; background-color: #CCCCCC; margin: 3px; cursor: pointer;" onclick="showbullets('bull-greenarrow'), bulletset()" /><img src="$defaultimagesdir/bull-bluearrow.gif" style="width: 8px; height: 8px; background-color: #CCCCCC; margin: 3px; cursor: pointer;" onclick="showbullets('bull-bluearrow'), bulletset()" /><img src="$defaultimagesdir/bull-blackarrow.gif" style="width: 8px; height: 8px; background-color: #CCCCCC; margin: 3px; cursor: pointer;" onclick="showbullets('bull-blackarrow'), bulletset()" /><br />  
       </div>  
       <div class="ubboptions" id="codelang" style="position: absolute; top: -22px; left: 230px; width: 92px; padding: 0px; background-color: #CCCCCC; display: none;">  
           <select size="10" name="codesyntax" id="codesyntax" onchange="syntaxlang(this.options[this.selectedIndex].value, this.selectedIndex);" style="margin:0px; font-size: 9px; width: 92px;">  
           <option value="" title="$npf_txt{'default'}">$npf_txt{'default'}</option>  
           <option value=" c++" title="C++">C++</option>  
           <option value=" css" title="CSS">CSS</option>  
           <option value=" html" title="HTML">HTML</option>  
           <option value=" java" title="Java">Java</option>  
           <option value=" javascript" title="Javascript">Javascript</option>  
           <option value=" pascal" title="Pascal">Pascal</option>  
           <option value=" perl" title="Perl">Perl</option>  
           <option value=" php" title="PHP">PHP</option>  
           <option value=" sql" title="SQL">SQL</option>  
           </select>  
       </div>  
       </div>  
       <div style="float: left; width: 315px; text-align: left;">  
       <img src="$imagesdir/green1.gif" name="chrwarn" height="8" width="8" border="0" vspace="0" hspace="0" alt="" align="middle" />  
       <span class="small">$npf_txt{'03'} <input value="$MaxMessLen" size="3" name="msgCL" class="windowbg2" style="border: 0px; font-size: 11px; width: 40px; padding: 1px" readonly="readonly" /></span>  
       </div>  
       <div style="float: left; width: 127px; text-align: right;">  
       <span class="small">$post_txt{'textsize'} <input value="$textsize" size="2" name="txtsize" id="txtsize" class="windowbg2" style="border: 0px; font-size: 11px; width: 15px; padding: 1px" readonly="readonly" />pt <img src="$imagesdir/smaller.gif" height="11" width="11" border="0" alt="" align="middle" onclick="sizetext(-1);" /><img src="$imagesdir/larger.gif" height="11" width="11" border="0" alt="" align="middle" onclick="sizetext(1);" /></span>  
       </div>  
       </div>  
       </div>  
       <script type="text/javascript" language="JavaScript1.2">  
       <!--  
   
       // set size of messagebox and text  
   
       var oldwidth = parseInt(document.getElementById('message').style.width) - $jsdragwpos;  
       var olddragwidth = parseInt(document.getElementById('dragbgh').style.width) - $jsdragwpos;  
       var oldheight = parseInt(document.getElementById('message').style.height) - $jsdraghpos;  
       var olddragheight = parseInt(document.getElementById('dragbgw').style.height) - $jsdraghpos;  
   
       var skydobject={  
       x: 0, y: 0, temp2 : null, temp3 : null, targetobj : null, skydNu : 0, delEnh : 0,  
   
       initialize:function() {  
           document.onmousedown = this.skydeKnap  
           document.onmouseup=function(){  
               this.skydNu = 0;  
               document.getElementById('messagewidth').value = parseInt(document.getElementById('message').style.width);  
               document.getElementById('messageheight').value = parseInt(document.getElementById('message').style.height);  
           }  
       },  
       changeSize:function(deleEnh, knapId) {  
           if (knapId == "dragImg1") {  
               newwidth = oldwidth+parseInt(deleEnh);  
               newdragwidth = olddragwidth+parseInt(deleEnh);  
               document.getElementById('message').style.width = newwidth+'px';  
               document.getElementById('dragbgh').style.width = newdragwidth+'px';  
               document.getElementById('dragImg2').style.width = newdragwidth+'px';  
           }  
           if (knapId == "dragImg2") {  
               newheight = oldheight+parseInt(deleEnh);  
               newdragheight = olddragheight+parseInt(deleEnh);  
               document.getElementById('message').style.height = newheight+'px';  
               document.getElementById('dragbgw').style.height = newdragheight+'px';  
               document.getElementById('dragImg1').style.height = newdragheight+'px';  
               document.getElementById('dragcanvas').style.height = newdragheight+'px';  
           }  
       },  
   
       flytKnap:function(e) {  
           var evtobj = window.event ? window.event : e  
           if (this.skydNu == 1) {  
               sizestop = f_clientWidth()  
               maxstop = parseInt(((sizestop*66)/100)-427)  
               if(maxstop > 413) maxstop = 413  
               if(maxstop < 60) maxstop = 60  
   
               glX = parseInt(this.targetobj.style.left)  
               this.targetobj.style.left = this.temp2 + evtobj.clientX - this.x + "px"   
               nyX = parseInt(this.temp2 + evtobj.clientX - this.x)  
               if (nyX > glX) retning = "vn"; else retning = "hj";  
               if (nyX < 1 && retning == "hj") { this.targetobj.style.left = 0 + "px"; nyX = 0; retning = "vn"; }  
               if (nyX > maxstop && retning == "vn") { this.targetobj.style.left = maxstop + "px"; nyX = maxstop; retning = "hj"; }  
               delEnh = parseInt(nyX)  
               var knapObj = this.targetobj.id  
               skydobject.changeSize(delEnh, knapObj)  
               return false  
           }  
           if (this.skydNu == 2) {  
               glY = parseInt(this.targetobj.style.top)  
               this.targetobj.style.top = this.temp3 + evtobj.clientY - this.y + "px"   
               nyY = parseInt(this.temp3 + evtobj.clientY - this.y)  
               if (nyY > glY) retning = "vn"; else retning = "hj";  
               if (nyY < 1 && retning == "hj") { this.targetobj.style.top = 0 + "px"; nyY = 0; retning = "vn"; }  
               if (nyY > 270 && retning == "vn") { this.targetobj.style.top = 270 + "px"; nyY = 270; retning = "hj"; }  
               delEnh = parseInt(nyY)  
               var knapObj = this.targetobj.id  
               skydobject.changeSize(delEnh, knapObj)  
               return false  
           }  
       },  
       skydeKnap:function(e) {  
           var evtobj = window.event ? window.event : e  
           this.targetobj = window.event ? event.srcElement : e.target  
           if (this.targetobj.className == "drag") {  
               if(this.targetobj.id == "dragImg1") this.skydNu = 1  
               if(this.targetobj.id == "dragImg2") this.skydNu = 2  
               this.knapObj = this.targetobj  
               if (isNaN(parseInt(this.targetobj.style.left))) this.targetobj.style.left = 0  
               if (isNaN(parseInt(this.targetobj.style.top))) this.targetobj.style.top = 0  
               this.temp2 = parseInt(this.targetobj.style.left)  
               this.temp3 = parseInt(this.targetobj.style.top)  
               this.x = evtobj.clientX  
               this.y = evtobj.clientY  
               if (evtobj.preventDefault) evtobj.preventDefault()  
               document.onmousemove = skydobject.flytKnap  
           }  
       }  
       } // End of: var skydobject={  
   
       function f_clientWidth() {  
           return f_filterResults (  
               window.innerWidth ? window.innerWidth : 0,  
               document.documentElement ? document.documentElement.clientWidth : 0,  
               document.body ? document.body.clientWidth : 0  
           );  
       }  
   
       function f_filterResults(n_win, n_docel, n_body) {  
           var n_result = n_win ? n_win : 0;  
           if (n_docel && (!n_result || (n_result > n_docel))) n_result = n_docel;  
           return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;  
       }  
   
       var orgsize = $textsize;  
   
       function sizetext(sizefact) {  
           orgsize = orgsize + sizefact;  
           if(orgsize < 6) orgsize = 6;  
           if(orgsize > 16) orgsize = 16;  
           document.getElementById('message').style.fontSize = orgsize+'pt';  
           document.getElementById('txtsize').value = orgsize;  
       }  
   
       skydobject.initialize()  
       //-->  
       </script>  
       </td>  
   </tr>  
   ~;  
   
   if ($img_greybox) {  
       $yyinlinestyle .= qq~<link href="$yyhtml_root/greybox/gb_styles.css" rel="stylesheet" type="text/css" />\n~;  
       $yyjavascript .= qq~  
var GB_ROOT_DIR = "$yyhtml_root/greybox/";  
// -->  
</script>  
<script type="text/javascript" src="$yyhtml_root/AJS.js"></script>  
<script type="text/javascript" src="$yyhtml_root/AJS_fx.js"></script>  
<script type="text/javascript" src="$yyhtml_root/greybox/gb_scripts.js"></script>  
<script type="text/javascript">  
<!--~;  
   }  
   
   if (!$replyguest) {  
       $imsend .= qq~  
   <tr>  
       <td valign="middle" class="windowbg2">  
           <script language="JavaScript1.2" type="text/javascript">  
           <!--  
       ~;  
   
       $moresmilieslist = '';  
       $more_smilie_array = '';  
       $i = 0;  
       if ($showadded == 1) {  
           while ($SmilieURL[$i]) {  
               if ($SmilieURL[$i] =~ /\//i) { $tmpurl = $SmilieURL[$i]; }  
               else { $tmpurl = qq~$imagesdir/$SmilieURL[$i]~; }  
               $moresmilieslist .= qq~                document.write('<img src="$tmpurl" align="bottom" alt="$SmilieDescription[$i]" border="0" onclick="javascript: MoreSmilies($i);" style="cursor: pointer;" />$SmilieLinebreak[$i] ');\n~;  
               $tmpcode = $SmilieCode[$i];  
               $tmpcode =~ s/\&quot;/"+'"'+"/g;    #" Adding that because if not it screws up my syntax view'   
               &FromHTML($tmpcode);  
               $tmpcode =~ s/&#36;/\$/g;  
               $tmpcode =~ s/&#64;/\@/g;  
               $more_smilie_array .= qq~" $tmpcode", ~;  
               $i++;  
           }  
       }  
   
       if ($showsmdir == 1) {  
           opendir(DIR, "$smiliesdir");  
           @contents = readdir(DIR);  
           closedir(DIR);  
           foreach $line (sort { uc($a) cmp uc($b) } @contents) {  
               ($name, $extension) = split(/\./, $line);  
               if ($extension =~ /gif/i || $extension =~ /jpg/i || $extension =~ /jpeg/i || $extension =~ /png/i) {  
                   if ($line !~ /banner/i) {  
                       $moresmilieslist .= qq~                document.write('<img src="$smiliesurl/$line" align="bottom" alt="$name" border="0" onclick="javascript: MoreSmilies($i);" style="cursor: pointer; cursor: hand;" />$SmilieLinebreak[$i] ');\n~;  
                       $more_smilie_array .= qq~" [smiley=$line]", ~;  
                       $i++;  
                   }  
               }  
           }  
       }  
   
       $more_smilie_array .= qq~""~;  
   
       $imsend .= qq~  
               moresmiliecode = new Array($more_smilie_array)  
               function MoreSmilies(i) {  
                   AddTxt=moresmiliecode[i];  
                   AddText(AddTxt);  
               }  
   
               HAND = "style='cursor: pointer;'"; // non valid css 'cursor: hand;' removed by the ContextHelp mod  
               document.write("<img src='$imagesdir/smiley.gif' onclick='smiley();' "+HAND+" align='bottom' alt='$post_txt{'287'}' title='$post_txt{'287'}' border='0'> ");  
               document.write("<img src='$imagesdir/wink.gif' onclick='wink();' "+HAND+" align='bottom' alt='$post_txt{'292'}' title='$post_txt{'292'}' border='0'> ");  
               document.write("<img src='$imagesdir/cheesy.gif' onclick='cheesy();' "+HAND+" align='bottom' alt='$post_txt{'289'}' title='$post_txt{'289'}' border='0'> ");  
               document.write("<img src='$imagesdir/grin.gif' onclick='grin();' "+HAND+" align='bottom' alt='$post_txt{'293'}' title='$post_txt{'293'}' border='0'> ");  
               document.write("<img src='$imagesdir/angry.gif' onclick='angry();' "+HAND+" align='bottom' alt='$post_txt{'288'}' title='$post_txt{'288'}' border='0'> ");  
               document.write("<img src='$imagesdir/sad.gif' onclick='sad();' "+HAND+" align='bottom' alt='$post_txt{'291'}' title='$post_txt{'291'}' border='0'> ");  
               document.write("<img src='$imagesdir/shocked.gif' onclick='shocked();' "+HAND+" align='bottom' alt='$post_txt{'294'}' title='$post_txt{'294'}' border='0'> ");  
               document.write("<img src='$imagesdir/cool.gif' onclick='cool();' "+HAND+" align='bottom' alt='$post_txt{'295'}' title='$post_txt{'295'}' border='0'> ");  
               document.write("<img src='$imagesdir/huh.gif' onclick='huh();' "+HAND+" align='bottom' alt='$post_txt{'296'}' title='$post_txt{'296'}' border='0'> ");  
               document.write("<img src='$imagesdir/rolleyes.gif' onclick='rolleyes();' "+HAND+" align='bottom' alt='$post_txt{'450'}' title='$post_txt{'450'}' border='0'> ");  
               document.write("<img src='$imagesdir/tongue.gif' onclick='tongue();' "+HAND+" align='bottom' alt='$post_txt{'451'}' title='$post_txt{'451'}' border='0'> ");  
               document.write("<img src='$imagesdir/embarassed.gif' onclick='embarassed();' "+HAND+" align='bottom' alt='$post_txt{'526'}' title='$post_txt{'526'}' border='0'> ");  
               document.write("<img src='$imagesdir/lipsrsealed.gif' onclick='lipsrsealed();' "+HAND+" align='bottom' alt='$post_txt{'527'}' title='$post_txt{'527'}' border='0'> ");  
               document.write("<img src='$imagesdir/undecided.gif' onclick='undecided();' "+HAND+" align='bottom' alt='$post_txt{'528'}' title='$post_txt{'528'}' border='0'> ");  
               document.write("<img src='$imagesdir/kiss.gif' onclick='kiss();' "+HAND+" align='bottom' alt='$post_txt{'529'}' title='$post_txt{'529'}' border='0'> ");  
               document.write("<img src='$imagesdir/cry.gif' onclick='cry();' "+HAND+" align='bottom' alt='$post_txt{'530'}' title='$post_txt{'530'}' border='0'> ");$moresmilieslist  
           //-->  
           </script>\n~;  
   
       if (($showadded == 3 && $showsmdir != 2) || ($showsmdir == 3 && $showadded != 2)) {  
           $imsend .= qq~  
           <a href="javascript: smiliewin();">$post_smiltxt{'1'}</a>~;  
       }  
   
       # SpellChecker start  
       if ($enable_spell_check) {  
           $yyinlinestyle .= qq~<link href="$yyhtml_root/googiespell/googiespell.css" rel="stylesheet" type="text/css" />  
   
<script type="text/javascript" src="$yyhtml_root/AJS.js"></script>  
<script type="text/javascript" src="$yyhtml_root/googiespell/googiespell.js"></script>  
<script type="text/javascript" src="$yyhtml_root/googiespell/cookiesupport.js"></script>~;  
           my $userdefaultlang = (split(/-/, $abbr_lang))[0];  
           $userdefaultlang ||= 'en';  
           $imsend .= qq~  
           <script type="text/javascript">  
           <!--  
               GOOGIE_DEFAULT_LANG = '$userdefaultlang';  
               var googie1 = new GoogieSpell("$yyhtml_root/googiespell/", "$boardurl/Sources/SpellChecker.pl?lang=");  
               googie1.lang_chck_spell = '$spell_check{'chck_spell'}';  
               googie1.lang_revert = '$spell_check{'revert'}';  
               googie1.lang_close = '$spell_check{'close'}';  
               googie1.lang_rsm_edt = '$spell_check{'rsm_edt'}';  
               googie1.lang_no_error_found = '$spell_check{'no_error_found'}';  
               googie1.lang_no_suggestions = '$spell_check{'no_suggestions'}';  
               googie1.setSpellContainer("spell_container");  
               googie1.decorateTextarea("message");  
           //-->  
           </script>~;  
       }  
       # SpellChecker end  
   
       $imsend .= qq~  
           <noscript>  
               <span class="small">$maintxt{'noscript'}</span>  
           </noscript>  
       </td>  
   </tr>~;  
   }  
   
   $imsend .= qq~  
   <tr>  
       <td class="windowbg">~;  
   
   if ($INFO{'quote'} || $INFO{'reply'} || $FORM{'reply'}) { # if this is a reply, need to pass the reply # forward  
       $imsend .= qq~  
           <input type="hidden" name="reply" id="reply" value="$INFO{'quote'}$INFO{'reply'}$FORM{'reply'}" />~;  
   }  
   
   if (!$replyguest) {  
       $imsend .= qq~  
           <input type="checkbox" name="ns" id="ns" value="NS"$nscheck /> <label for="ns"><span class="small">$post_txt{'277'}</span></label><br />~;  
       if ($FORM{'draftid'} || $INFO{'caller'} == 4) {  
           $imsend .= qq~  
           <input type="checkbox" name="draftleave" id="draftleave" value="1" /> <span class="small"> $post_txt{'draftleave'}</span><br />~;  
       }  
       $imsend .= qq~  
           <input type="checkbox" name="dontstoreinoutbox" id="dontstoreinoutbox" value="1"~ . ($FORM{'dontstoreinoutbox'} ? ' checked="checked"' : '') . qq~ /> <label for="dontstoreinoutbox"><span class="small">$inmes_txt{'320'}</span></label><br />~;  
   }  
   
   $imsend .= qq~  
           <div id="enable_iecopy" style="display: none;">  
           <input type="checkbox" name="iecopy" id="iecopy"$iecopycheck /> <span class="small"> $post_txt{'iecopycheck'}</span>  
           </div>  
           <script language="JavaScript1.2" type="text/javascript">  
           <!--  
           if (navigator.appName == "Microsoft Internet Explorer") {  
               document.getElementById('enable_iecopy').style.display = 'inline';  
           }  
           //-->  
           </script>  
       </td>  
   </tr>  
   ~;  
   
   #these are the buttons to submit  
   my $sendBMessFlag;  
   if ($sendBMess || $isBMess) {  
       $sendBMessFlag = qq~<input type="hidden" name="isBMess" id="isBMess" value="yes" />~;  
   }  
   
   $imsend .= qq~  
   <tr>  
       <td align="center" class="titlebg">  
           $hidestatus  
           $sendBMessFlag  
           <br />  
           <input type="submit" name="$post" value="$submittxt" accesskey="s" tabindex="5" class="button" />~;  
   
   if ($speedpostdetection) {  
       $imsend .= qq~  
           <script language="JavaScript1.2" type="text/javascript">  
           <!--  
           var postdelay = $min_post_speed*1000;  
           document.postmodify.$post.value = '$post_txt{"delay"}';  
           document.postmodify.$post.disabled = true;  
           document.postmodify.$post.style.cursor = 'default';  
           var delay = window.setInterval('releasepost()',postdelay);  
           function releasepost() {  
               document.postmodify.$post.value = '$submittxt';  
               document.postmodify.$post.disabled = false;  
               document.postmodify.$post.style.cursor = 'pointer';  
               window.clearInterval(delay);  
           }  
           //-->  
           </script>~;  
   }  
   
   my %accesskey;  
   if (!$replyguest) {  
       $imsend .= qq~&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" name="$draft" id="$draft" value="$inmes_txt{'savedraft'}" accesskey="d" tabindex="7" class="button" />~;  
       $accesskey{'MSIE_Safari'}     = $post_txt{'329b'};  
       $accesskey{'FireFox'}         = $post_txt{'330b'};  
       $accesskey{'Browsers_on_Mac'} = $post_txt{'331b'};  
       if ((!$enable_PMcontrols && $enable_PMprev) || ($enable_PMcontrols && ${$uid.$username}{'pmmessprev'})) {  
           $imsend .= qq~&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" name="$preview" id="$preview" value="$inmes_txt{'507'}" accesskey="p" tabindex="6" class="button" />~;  
           $accesskey{'MSIE_Safari'}     = $post_txt{'329c'};  
           $accesskey{'FireFox'}         = $post_txt{'330c'};  
           $accesskey{'Browsers_on_Mac'} = $post_txt{'331c'};  
       }  
   }  
   
   $smilie_url_array  = "";  
   $smilie_code_array = "";  
   $i = 0;  
   if ($showadded eq 2) {  
       while ($SmilieURL[$i]) {  
           if ($SmilieURL[$i] =~ /\//i) { $tmpurl = $SmilieURL[$i]; }  
           else { $tmpurl = qq~$defaultimagesdir/$SmilieURL[$i]~; }  
           $smilie_url_array .= qq~"$tmpurl", ~;  
           $tmpcode = $SmilieCode[$i];  
           $tmpcode =~ s/\&quot;/"+'"'+"/g; # "'   
           &FromHTML($tmpcode);  
           $tmpcode =~ s/&#36;/\$/g;  
           $tmpcode =~ s/&#64;/\@/g;  
           $smilie_code_array .= qq~" $tmpcode", ~;  
           $i++;  
       }  
   }  
   if ($showsmdir eq 2) {  
       opendir(DIR, "$smiliesdir");  
       @contents = readdir(DIR);  
       closedir(DIR);  
       foreach $line (sort { uc($a) cmp uc($b) } @contents) {  
           ($name, $extension) = split(/\./, $line);  
           if ($extension =~ /gif/i || $extension =~ /jpg/i || $extension =~ /jpeg/i || $extension =~ /png/i) {  
               if ($line !~ /banner/i) {  
                   $smilie_url_array  .= qq~"$smiliesurl/$line", ~;  
                   $smilie_code_array .= qq~" [smiley=$line]", ~;  
                   $i++;  
               }  
           }  
       }  
   }  
   
   $imsend .= qq~  
       <script type="text/javascript" language="JavaScript">  
       <!--  
           if (/Opera/.test(navigator.userAgent) == false) {  
               if (/mac/i.test(navigator.platform)) {  
                   document.write("<br /><span class='small'>$accesskey{'Browsers_on_Mac'}</span>");  
               } else if (/MSIE [7-9]/.test(navigator.userAgent) || /\\/[3-9]\\.\\d+\\.\\d+ Safari/.test(navigator.userAgent)) {  
                   document.write("<br /><span class='small'>$accesskey{'MSIE_Safari'}</span>");  
               } else if (/Firefox\\/[2-9]/.test(navigator.userAgent) || /Chrome/.test(navigator.userAgent)) {  
                   document.write("<br /><span class='small'>$accesskey{'FireFox'}</span>");  
               }  
           }  
   
           var noalert = true, gralert = false, rdalert = false, clalert = false;  
           var prevsec = 5;  
           var prevtxt;  
           var cntsec = 0;  
           function tick() {  
               cntsec++;  
               calcCharLeft();  
               timerID = setTimeout("tick()",1000);  
           }  
           var autoprev = false;  
           var topicfirst = true;\n~;  
   
   if (((!$enable_PMcontrols && $enable_PMActprev) || ($enable_PMcontrols && ${$uid.$username}{'pmactprev'})) && !$replyguest) {  
       $imsend .= qq~  
           post_txt_807 = "$post_txt{'807'}";  
   
           function enabPrev() {  
               if ( autoprev == false ) {  
                   autoprev = true  
                   topicfirst = true  
                   document.getElementById("savetable").style.visibility = "visible";  
                   document.getElementById("savetable").style.height = "auto";  
                   document.getElementById("savetopic").style.height = "auto";  
                   document.getElementById("saveframe").style.height = "0px";  
                   document.images.prevwin.alt = "$npf_txt{'02'}";  
                   document.images.prevwin.title = "$npf_txt{'02'}";  
                   document.images.prevwin.src="$defaultimagesdir/cat_collapse.gif";  
                   autoPreview();  
               } else {  
                   autoprev = false;  
                   ubbstr = '';  
                   document.getElementById("savetable").style.visibility = "hidden";  
                   document.getElementById("savetable").style.height = "0px";  
                   document.getElementById("savetopic").style.height = "0px";  
                   document.getElementById("saveframe").style.height = "0px";  
                   document.postmodify.message.focus();  
                   document.images.prevwin.alt = "$npf_txt{'01'}";  
                   document.images.prevwin.title = "$npf_txt{'01'}";  
                   document.images.prevwin.src="$defaultimagesdir/cat_expand.gif";  
               }  
               calcCharLeft();  
           }\n~;  
   }  
   
   $imsend .= qq~  
           function calcCharLeft() {  
               if (document.postmodify.message.value.length > 0) document.getElementById("saveframe").style.height = "auto";    
               clipped = false;  
               maxLength = $MaxMessLen;  
               if (document.postmodify.message.value.length > maxLength) {  
                   document.postmodify.message.value = document.postmodify.message.value.substring(0,maxLength);  
                   charleft = 0;  
                   clipped = true;  
               } else {  
                   charleft = maxLength - document.postmodify.message.value.length;  
               }  
               prevsec++  
               if(autoprev && prevsec > 5 && prevtxt != document.postmodify.message.value) {  
                   autoPreview();  
                   prevtxt = document.postmodify.message.value;  
               }  
               document.postmodify.msgCL.value = charleft;  
               if (charleft >= 100 && noalert) { noalert = false; gralert = true; rdalert = true; clalert = true; document.images.chrwarn.src="$defaultimagesdir/green1.gif"; }  
               if (charleft < 100 && charleft >= 50 && gralert) { noalert = true; gralert = false; rdalert = true; clalert = true; document.images.chrwarn.src="$defaultimagesdir/green0.gif"; }  
               if (charleft < 50 && charleft > 0 && rdalert) { noalert = true; gralert = true; rdalert = false; clalert = true; document.images.chrwarn.src="$defaultimagesdir/red0.gif" }  
               if (charleft == 0 && clalert) { noalert = true; gralert = true; rdalert = true; clalert = false; document.images.chrwarn.src="$defaultimagesdir/red1.gif"; }  
               return clipped;  
           }  
   
           var codestr = '$simpelcode';  
           var quotstr = '$normalquot';  
           var squotstr = '$simpelquot';  
           var fontsizemax = '$fontsizemax';  
           var fontsizemin = '$fontsizemin';  
           var edittxt = '$edittext';  
           var dispname = '$displayname';  
           var scrpurl = '$scripturl';  
           var imgdir = '$defaultimagesdir';  
           var ubsmilieurl = '$smiliesurl';  
           var parseflash = '$parseflash';  
           var autolinkurl = '$autolinkurls';  
           var Month = new Array($jsmonths);  
           var timeselected = '$jstimeselected';  
           var splittext = "$maintxt{'107'}";  
           var dontusetoday = '';  
           var todaytext = "$maintxt{'769'}";  
           var yesterdaytext = "$maintxt{'769a'}";  
           var timetext1 = "$timetxt{'1'}";  
           var timetext2 = "$timetxt{'2'}";  
           var timetext3 = "$timetxt{'3'}";  
           var timetext4 = "$timetxt{'4'}";  
           var jsmilieurl = new Array($smilie_url_array"");  
           var jsmiliecode = new Array($smilie_code_array"");  
   
           function autoPreview() {  
               if (topicfirst)  { updatTopic(); }  
               var scrlto = parseInt(180) + 5;  
               vismessage = document.postmodify.message.value;  
               while ( c=vismessage.match(/date=(\\d+?)\\]/i) ) {  
                   var qudate=c[1];  
                   qudate=qudate * 1000;  
                   qdate=new Date();  
                   qdate.setTime(qudate);  
                   qdate=qdate.toLocaleString();  
                   vismessage=vismessage.replace(/(date=)\\d+?(\\])/i, "\$1"+qdate+"\$2");  
               }  
               if($enable_ubbc) {  
                   var ubbstr = jsDoUbbc(vismessage,codestr,quotstr,squotstr,edittxt,dispname,scrpurl,imgdir,ubsmilieurl,parseflash,fontsizemax,fontsizemin,autolinkurl,Month,timeselected,splittext,dontusetoday,todaytext,yesterdaytext,timetext1,timetext2,timetext3,timetext4,jsmilieurl,jsmiliecode);  
               } else {  
                   var ubbstr = vismessage;  
               }  
               document.getElementById("saveframe").innerHTML=ubbstr;  
               sh_highlightDocument();  
               LivePrevImgResize();  
               scrlto += parseInt(document.getElementById("saveframe").scrollTop) + parseInt(document.getElementById("saveframe").offsetHeight);  
               document.getElementById("saveframe").scrollTop = scrlto;  
               prevsec = 0;  
           }  
   
           function LivePrevImgResize() {  
               var max_w = $max_post_img_width;  
               var max_h = $max_post_img_height;  
               var images = document.getElementById("saveframe").getElementsByTagName("img");  
               for (var i = 0; i < images.length; i++) {  
                   if (max_w != 0 && images[i].width > max_w) {  
                       images[i].height = images[i].height * max_w / images[i].width;  
                       images[i].width = max_w;  
                   }  
                   if (max_h != 0 && images[i].height > max_h) {  
                       images[i].width  = images[i].width * max_h / images[i].height;  
                       images[i].height = max_h;  
                   }  
               }  
           }\n~;  
   
   if (((!$enable_PMcontrols && $enable_PMActprev) || ($enable_PMcontrols && ${$uid.$username}{'pmactprev'})) && !$replyguest) {  
       $imsend .= qq~  
           var visikon = '';  
           function updatTopic() {  
               topicfirst = false;  
   
               var visicon = document.images.icons.src;  
               visicon=visicon.replace(/http\\:\\/\\/.*\\/(.*?)\\.gif/g, "\$1");  
               visicon=visicon.replace(/[^A-Za-z]/g, "");  
               visicon=visicon.replace(/\\\\/g, "");  
               visicon=visicon.replace(/\\//g, "");  
               if (visicon != "standard" && visicon != "confidential" && visicon != "urgent") {  
                   visicon = "xx";  
               }  
               visikon = "<img border='0' src='$defaultimagesdir/"+visicon+".gif' alt='"+visicon+"' /> ";  
   
               var vistopic = document.postmodify.subject.value;  
               var htmltopic = jsDoTohtml(vistopic);  
               document.getElementById("savetopic").innerHTML=visikon+htmltopic;  
               //document.postmodify.message.focus();  
           }\n~;  
   }  
   
   if (!$replyguest) {  
       $imsend .= qq~  
           function showtpstatus() {  
               var theimg = '$pmicon';  
               var objIconSelected = document.postmodify.status[document.postmodify.status.selectedIndex].value;  
               if (objIconSelected == 's') { theimg = 'standard'; }  
               if (objIconSelected == 'c') { theimg = 'confidential'; }  
               if (objIconSelected == 'u') { theimg = 'urgent'; }  
               document.images.icons.src='$imagesdir/'+theimg+'.gif';  
               if (autoprev == true) updatTopic();  
           }  
           showtpstatus();\n~;  
   }  
   
   $imsend .= qq~  
           tick();  
   
           // -->  
           </script>  
           <br /><br />  
       </td>  
   </tr>\n~;  
   
   if ($action eq 'modify' || $action eq 'modify2') {  
       $displayname = $mename;  
   } else {  
       $displayname = ${$uid.$username}{'realname'};  
   }  
   
   require "$templatesdir/$usedisplay/Display.template";  
   
   foreach (@months) { $jsmonths .= qq~'$_',~; }  
   $jsmonths =~ s~\,\Z~~;  
   $jstimeselected = ${$uid.$username}{'timeselect'} || $timeselected;  
   
   ##########  end post code     if ( $action eq 'modify' || $action eq 'modify2' ) { 
         $displayname = $mename;
     }
     else {
         $displayname = ${ $uid . $username }{'realname'};
     }
   
     get_template('Display');
   
     foreach (@months) { $jsmonths .= qq~'$_',~; }
     $jsmonths =~ s/\,\Z//xsm;
     $jstimeselected = ${ $uid . $username }{'timeselect'} || $timeselected;
   
     $imsend .= $imsend_send;
     $imsend .= $my_imsend_jsin;
     $imsend .= $my_ubbc_yes;
     $imsend .= $my_postbox;
     $imsend .= $im_smilies;
     $imsend .= $my_imFA;
     $imsend .= $my_FA_browse;
     $imsend =~ s/{yabb JSandInput}/$JSandInput/sm;
     $imsend =~ s/{yabb my_max}/$my_max/sm;
     $imsend =~ s/{yabb subject}/$subject/sm;
     $imsend =~ s/{yabb onchangeText}/$onchangeText/sm;
     $imsend =~ s/{yabb postbox2}/$postbox2/sm;
     $imsend =~ s/{yabb postbox3}/$postbox3/sm;
     $imsend =~ s/{yabb my_ispreview}/$my_ispreview/sm;
     $imsend =~ s/{yabb my_isreply}/$my_isreply/sm;
     $imsend =~ s/{yabb post}/$post/sm;
     $imsend =~ s/{yabb hidestatus}/$hidestatus/sm;
     $imsend =~ s/{yabb submittxt}/$submittxt/sm;
     $imsend =~ s/{yabb sendBMessFlag}/$sendBMessFlag/sm;
     $imsend =~ s/{yabb my_spdpost}/$my_spdpost/sm;
     $imsend =~ s/{yabb my_draft}/$my_draft/sm;
     $imsend =~ s/{yabb my_browser}/$my_browser/sm;
     $imsend =~ s/{yabb my_savetable}/$my_savetable/sm;
     $imsend =~ s/{yabb my_chars}/$my_chars/sm;
     ##########  end post code
     return $imsend;
} }
   
##  process and send the IM to whomever ##  process and send the IM to whomever
sub IMsendMessage { sub IMsendMessage {
   # This is only for update, when comming from YaBB lower or equal version 2.2.3  
   # I think it can be deleted around version 2.4.0 without causing mayor issues (deti).  
   if ($enable_notifications eq '') { $enable_notifications = $enable_notification ? 3 : 0; }  
   # End update workaround  
   
   &LoadLanguage('Post');  
   &LoadLanguage('InstantMessage');  
   ##  load error strings  
   &LoadLanguage('Error');  
   
   ##  sorry - no guests  
   if ($iamguest) { &fatal_error("im_members_only"); }  
   
   my (@ignore, $igname, $messageid, $subject, $message, @recipient, $ignored, $memnums);  
   $isBMess = $FORM{'isBMess'};  
   
   # set size of messagebox and text  
   ${$uid.$username}{'postlayout'} = qq~$FORM{'messageheight'}|$FORM{'messagewidth'}|$FORM{'txtsize'}|$FORM{'col_row'}~;  
   
   # receipts for IM are now handled by "toshow" only, so we need to switch to the right  
   # test for no recipient. also switch on flag to stop us going back to the form all the time  
   # if there is only the one (intended) recipient, 'to' must contain the name  
   if ((!$FORM{'toshow'} && !$INFO{'to'}) && !$FORM{'draft'}) { $error = $error_txt{'no_recipient'}; }  
   $toshow = $FORM{'toshow'} || $INFO{'to'};  
   # if there are several intended - can be one of course ;)  
   
   $subject = $FORM{'subject'};  
   $subject =~ s/^\s+|\s+$//g;  
   
   $message = $FORM{'message'};  
   $message =~ s/^\s+|\s+$//g;  
   
   # no subject/no message are bad!  
   $error = $error_txt{'no_subject'} if !$subject;  
   $error = $error_txt{'no_message'} if !$message;  
   
   &FromChars($subject);  
   &FromChars($message);  
   
   &ToHTML($subject);  
   &ToHTML($message);  
   
   # manage line returns and tabs  
   $subject =~ s/\s+/ /g;  
   $message =~ s~\n~<br />~g;  
   $message =~ s~\t~ \&nbsp; \&nbsp; \&nbsp;~g;  
   
   # Check Length  
   $convertstr = $subject;  
   $convertcut = $set_subjectMaxLength + ($subject =~ /^Re: / ? 4 : 0);  
   &CountChars;  
   $subject = $convertstr;  
   
   $convertstr = $message;  
   $convertcut = $MaxMessLen;  
   &CountChars;  
   if ($cliped) { $error = "$inmes_txt{'536'} " . (length($message) - length($convertstr)) . " $inmes_txt{'537'}"; }  
   $message = $convertstr;  
   
   if ($FORM{'ns'} eq 'NS') { $message .= "#nosmileys"; }  
   
   if ($error) {  
       $IM_box = $inmes_txt{'148'};  
       $FORM{'previewim'} = 1;  
       &IMPost;  
       &buildIMsend;  
       return;  
   }  
   
   undef @multiple;  
   fopen(MEMLIST, "$memberdir/memberlist.txt");  
   my @memberlist = <MEMLIST>;  
   my $allmems = @memberlist;  
   fclose(MEMLIST);  
   
   &ProcIMrecs;  
   
   $memnums = $#multiple + 1;  
   ## no need to check for spam if its a broadcast, as this only creates the one post  
   if ($imspam ne "off" && !$isBMess) {  
       $checkspam = 100 / $allmems * $memnums;  
       if ($memnums == 1) { $checkspam = 0; }  
       if ($checkspam > $imspam && !$iamadmin) { &fatal_error("im_spam_alert"); }  
   }  
   
   # go through each member in list  
   # add to each msg (inbox) but only one to outbox  
   # Create unique Message ID  
   $messageid = &getnewid;  
   $actlang = $language;  
   my $UserTo;  
   if (!$FORM{'draft'} && !$isBMess && !$replyguest) {  
       foreach $UserTo (@allto) {  
           $addnr++;  
           chomp $UserTo;  
           my($status, $UserTo) = split(/:/, $UserTo);  
           my $ignored = 0;  
           $UserTo =~ s/\A\s+//;  
           $UserTo =~ s/\s+\Z//;  
           $UserTo =~ s/[^0-9A-Za-z#%+,-\.@^_]//g;  
   
           # Check Ignore-List, unless sender is FA  
           &LoadUser($UserTo);  
           if (!$isBMess) {  
               if (${$uid.$UserTo}{'im_ignorelist'} && !$iamadmin && !$iamgmod) {  
                   # Build Ignore-List  
                   @ignore = split(/\|/, ${$uid.$UserTo}{'im_ignorelist'});  
   
                   # If User is on Recipient's Ignore-List, show Error Message  
                   foreach $igname (@ignore) {  
                       # adds ignored user's name to array which error list will be built from later  
                       chomp $igname;  
                       if ($igname eq $username) { push(@nouser, $UserTo); $ignored = 1; }  
                       if ($igname eq '*') { push(@nouser, "$inmes_txt{'761'} $UserTo $inmes_txt{'762'};"); $ignored = 1; }  
                   }  
               }  
           }  
           ## check and see if 1) username is marked 'away' 2) they left a message 3) you haven't already had an auto-reply  
           my $sendAutoReply = 1;  
           if (${$uid.$UserTo}{'offlinestatus'} eq 'away' && ${$uid.$UserTo}{'awayreply'} ne '' && ${$uid.$UserTo}{'awaysubj'} ne '') {  
               if (${$uid.$UserTo}{'awayreplysent'} eq '') {  
                   ${$uid.$UserTo}{'awayreplysent'} = $username;  
                   &UserAccount($UserTo, 'update');  
               } else {  
                   foreach my $replyListName (split(/,/ ,${$uid.$UserTo}{'awayreplysent'})) {  
                       if ($replyListName eq $username) {  
                           $sendAutoReply = 0;  
                           last;  
                       }  
                   }  
                   if ($sendAutoReply) {  
                       ${$uid.$UserTo}{'awayreplysent'} .= qq~,$username~;  
                       &UserAccount($UserTo, 'update');  
                   }  
               }  
           } else { $sendAutoReply = 0; }  
   
           if (!-e ("$memberdir/$UserTo.vars")) {  
               # adds invalid user's name to array which error list will be built from later  
               push(@nouser, $UserTo);  
               $ignored = 1;  
           }  
   
           if (!$ignored) {  
               # Send message to user  
               fopen(INBOX, "$memberdir/$UserTo.msg");  
               my @inmessages = <INBOX>;  
               fclose(INBOX);  
               fopen(INBOX, ">$memberdir/$UserTo.msg");  
               print INBOX "$messageid|$username|$FORM{'toshow'}|$FORM{'toshowcc'}|$FORM{'toshowbcc'}|$subject|$date|$message|$messageid|0|$ENV{'REMOTE_ADDR'}|$FORM{'status'}|u||\n";  
               print INBOX @inmessages;  
               fclose(INBOX);  
   
               # we've added the msg to the inbox, now update the ims file  
               &updateIMS($UserTo, $messageid, 'messagein');  
               ## if we need to drop the 'away' reply in....  
               if ($sendAutoReply) {  
                   my $rmessageid = &getnewid;  
                   fopen(INBOX, "$memberdir/$username.msg");  
                   my @myinmessages = <INBOX>;  
                   fclose(INBOX);  
                   fopen(INBOX, ">$memberdir/$username.msg");  
                   print INBOX "$rmessageid|$UserTo|$username|||${$uid.$UserTo}{'awaysubj'}|$date|${$uid.$UserTo}{'awayreply'}|$messageid|1|$ENV{'REMOTE_ADDR'}|s|u||\n";  
                   print INBOX @myinmessages;  
                   fclose(INBOX);  
               }  
               ## relocated sender msg out of the loop  
   
               # Send notification (Will only work if Admin has allowed the Email Notification)  
               if (${$uid.$UserTo}{'notify_me'} > 1 && $enable_notifications > 1) {  
                   require "$sourcedir/Mailer.pl";  
                   $language = ${$uid.$UserTo}{'language'};  
                   &LoadLanguage('Email');  
                   &LoadLanguage('Notify');  
                   &LoadCensorList;  
                   $useremail = ${$uid.$UserTo}{'email'};  
                   $useremail =~ s/[\n\r]//g;  
                   if ($useremail ne '') {  
                       my $msubject = $subject ? $subject : $inmes_txt{'767'};  
                       $fromname = ${$uid.$username}{'realname'};  
                       &FromHTML($msubject);  
                       &ToChars($msubject);  
                       $msubject = &Censor($msubject);  
                       my $chmessage = $message;  
                       &FromHTML($chmessage);  
                       &ToChars($chmessage);  
                       $chmessage = &Censor($chmessage);  
                       $chmessage =~ s~<br.*?>~\n~gi;  
                       $chmessage =~ s~\[b\](.*?)\[/b\]~*$1*~isg;  
                       $chmessage =~ s~\[i\](.*?)\[/i\]~/$1/~isg;  
                       $chmessage =~ s~\[u\](.*?)\[/u\]~_$1_~isg;  
                       $chmessage =~ s~\[.*?\]~~g;  
                       &sendmail($useremail, $notify_txt{'145'}, &template_email($privatemessagenotificationemail, {'sender' => $fromname, 'subject' => $msubject, 'message' => $chmessage}), '', $emailcharset);  
                   }  
               }  
           }    #end add PM to outbox  
       }    #end foreach loop  
       if ($#allto == $#nouser) {  
           my $badusers;  
           foreach my $baduser (@nouser) {  
               &LoadUser($baduser);  
               $badusers .= qq~<a href="$scripturl?action=viewprofile;username=$useraccount{$baduser}">${$uid.$baduser}{'realname'}</a>, ~;  
           }  
           $badusers =~ s/, \Z//;  
           &fatal_error('im_bad_users', $badusers);  
       }  
   }  
   
   ##  moved sender's reply marker here, open the sender's inbox and mark 'replied'  
   if (!$FORM{'draft'} && $isBMess) {  
       fopen(INBOX, "$memberdir/broadcast.messages");  
       my @inmessages = <INBOX>;  
       fclose(INBOX);  
       fopen(INBOX, ">$memberdir/broadcast.messages");  
       print INBOX "$messageid|$username|$FORM{'toshow'}|||$subject|$date|$message|$messageid|0|$ENV{'REMOTE_ADDR'}|$FORM{'status'}b|u||\n";  
       print INBOX @inmessages;  
       fclose(INBOX);  
   }  
   
   if ($FORM{'reply'} && $FORM{'info'}) { # mark msg replied  
       &updateMessageFlag($username, $FORM{'info'}, 'msg', '', 'r');  
   }  
   
   ## this now outside the foreach, to allow just one write in the outbox  
   # Add message to outbox, read outbox  
   
   @outmessages = ();  
   my $savetofile = 'outbox';  
   if ($FORM{'draft'}) { $savetofile = 'imdraft'; }  
   fopen(OUTBOX, "$memberdir/$username.$savetofile");  
   @outmessages = <OUTBOX>;  
   fclose(OUTBOX);  
   
   # add the PM to the outbox  
   # the sep users now live together  
   my $messFlag = '';  
   if ($isBMess) { $messFlag = 'b'; }  
   if ($replyguest) {  
       $messFlag = 'gr';  
   
       $FORM{'toguest'} =~ s/ /%20/g;  
       $FORM{'toshow'} = $FORM{'toguest'} . ' ' . $FORM{'guestemail'};  
       $FORM{'toshow'} =~ s/[\n\r]//g;  
       $FORM{'guestemail'} =~ s/[\n\r]//g;  
   
       $fromname = ${$uid.$username}{'realname'};  
   
       my $msubject = $subject;  
       &FromHTML($msubject);  
       &ToChars($msubject);  
   
       $chmessage = $message;  
       &FromHTML($chmessage);  
       &ToChars($chmessage);  
       $chmessage =~ s~<br.*?>~\n~gi;  
       $chmessage =~ s~\[b\](.*?)\[/b\]~*$1*~isg;  
       $chmessage =~ s~\[i\](.*?)\[/i\]~/$1/~isg;  
       $chmessage =~ s~\[u\](.*?)\[/u\]~_$1_~isg;  
       $chmessage =~ s~\[.*?\]~~g;  
       $chmessage =~ s/\r(?=\n*)//g;  
   
       require "$sourcedir/Mailer.pl";  
       &sendmail($FORM{'guestemail'}, $msubject, $chmessage, ${$uid.$username}{'email'});  
   }  
   
   if (!$FORM{'dontstoreinoutbox'} || $FORM{'draft'}) {  
       fopen(OUTBOX, "+>$memberdir/$username.$savetofile") || &fatal_error('cannot_open',"+>$memberdir/$username.$savetofile",1);  
       ## all but drafts being resaved just get added to their file  
       if (!$FORM{'draft'} || ($FORM{'draft'} && !$FORM{'draftid'})) {  
           print OUTBOX "$messageid|$username|$FORM{'toshow'}|$FORM{'toshowcc'}|$FORM{'toshowbcc'}|$subject|$date|$message|$messageid|$FORM{'reply'}|$ENV{'REMOTE_ADDR'}|$FORM{'status'}$messFlag|||\n";  
           print OUTBOX @outmessages;  
   
       } elsif ($FORM{'draft'} && $FORM{'draftid'}) {  
           ## resaving draft - find draft message id and amend the entry  
           foreach my $outmessage (@outmessages) {  
               chomp $outmessage;  
               if ((split /\|/, $outmessage)[0] != $FORM{'draftid'}) {  
                   print OUTBOX "$outmessage\n";  
               } else {  
                   print OUTBOX "$messageid|$username|$FORM{'toshow'}|$FORM{'toshowcc'}|$FORM{'toshowbcc'}|$subject|$date|$message|$messageid|$FORM{'reply'}|$ENV{'REMOTE_ADDR'}|$FORM{'status'}$messFlag|||\n";  
               }  
           }  
       }  
       fclose(OUTBOX);  
   
       ## pdate ims for sent  
       if (!$FORM{'draft'}) { &updateIMS($username, $messageid, 'messageout'); }  
       elsif (!$FORM{'draftid'}) { &updateIMS($username, $messageid, 'draftadd'); }  
   }  
   
   ## if this is a draft being sent, remove it from the draft file  
   if ($FORM{'draftid'} && $FORM{'draft'} ne $inmes_txt{'savedraft'}) {  
       &updateIMS($username, $messageid, 'draftsend');  
       fopen(DRAFTFILE, "$memberdir/$username.imdraft");  
       my @draftPM = <DRAFTFILE>;  
       fclose(DRAFTFILE);  
       fopen(DRAFTFILE, ">$memberdir/$username.imdraft");  
       seek DRAFTFILE,0,0;  
       foreach my $draftmess (@draftPM) {  
           chomp $draftmess;  
           if ((split /\|/, $draftmess)[0] != $FORM{'draftid'}) {  
               print DRAFTFILE "$draftmess\n";  
           } elsif ($FORM{'draftleave'}) {  
               print DRAFTFILE "$messageid|$username|$FORM{'toshow'}|$FORM{'toshowcc'}|$FORM{'toshowbcc'}|$subject|$date|$message|$messageid|$FORM{'reply'}|$ENV{'REMOTE_ADDR'}|$FORM{'status'}$messFlag|||\n";  
           }  
       }  
       fclose(DRAFTFILE);  
   }  
   # invalid users  
   #if there were invalid usernames in the recipient list, these names are listed after all valid users have been IMed  
   if (!$FORM{'draft'}) {  
       if (@nouser) {  
           my $badusers;  
           foreach my $baduser (@nouser) {  
               &LoadUser($baduser);  
               $badusers .= qq~<a href="$scripturl?action=viewprofile;username=$useraccount{$baduser}">${$uid.$baduser}{'realname'}</a>, ~;  
           }  
           $badusers =~ s/, \Z//;  
           &fatal_error('im_bad_users', $badusers);  
       }  
   }  
   
   ## saving a draft doesn't count as sending  
   if (!$FORM{'draft'}) { &UserAccount($username, 'update', 'lastim'); }  
   &UserAccount($username, 'update', 'lastonline');  
   
   if ($FORM{'dontstoreinoutbox'}) { $yySetLocation = qq~$scripturl?action=im~; }  
   elsif ($FORM{'draft'}) { $yySetLocation = qq~$scripturl?action=imdraft~; }  
   else { $yySetLocation = qq~$scripturl?action=imoutbox~; }  
   &redirectexit;  
}  
   
     LoadLanguage('InstantMessage');
     LoadLanguage('Error');
   
     ##  sorry - no guests
     if ($iamguest) { fatal_error('im_members_only'); }
   
     my (
         @ignore,  $igname,   $messageid,  $subject,
         $message, $ignored,  $memnums,    $file,
         $fixfile, @filelist, %filesizekb, $pmAttachUrl
     );
     $isBMess = $FORM{'isBMess'};
   
     # set size of messagebox and text
     ${ $uid . $username }{'postlayout'} =
  qq~$FORM{'messageheight'}|$FORM{'messagewidth'}|$FORM{'txtsize'}|$FORM{'col_row'}~;
   
  # receipts for IM are now handled by "toshow" only, so we need to switch to the right
  # test for no recipient. also switch on flag to stop us going back to the form all the time
  # if there is only the one (intended) recipient, 'to' must contain the name
     if ( ( !$FORM{'toshow'} && !$INFO{'to'} ) && !$FORM{'draft'} ) {
         $error = $error_txt{'no_recipient'};
     }
     $toshow = $FORM{'toshow'} || $INFO{'to'};
   
     # if there are several intended - can be one of course ;)
   
     $subject = $FORM{'subject'};
     $subject =~ s/^\s+|\s+$//gsm;
   
     $message = $FORM{'message'};
     $message =~ s/^\s+|\s+$//g;
   
     #above regex cannot use /s or /m flags. IT WILL BREAK!
   
     # no subject/no message are bad!
     if ( !$subject ) { $error = $error_txt{'no_subject'}; }
     if ( !$message ) { $error = $error_txt{'no_message'}; }
   
     FromChars($subject);
     FromChars($message);
   
     ToHTML($subject);
     ToHTML($message);
   
     # manage line returns and tabs
     $subject =~ s/\s+/ /gsm;
     $message =~ s/\n/<br \/>/gsm;
     $message =~ s/\t/ \&nbsp; \&nbsp; \&nbsp;/gsm;
   
     # Check Length
     $convertstr = $subject;
     $convertcut = $set_subjectMaxLength + ( $subject =~ /^Re: /sm ? 4 : 0 );
     CountChars();
     $subject = $convertstr;
   
     $convertstr = $message;
     $convertcut = $MaxMessLen;
     CountChars();
     if ($cliped) {
         $error =
             "$inmes_txt{'536'} " 
           . ( length($message) - length $convertstr )
           . " $inmes_txt{'537'}";
     }
     $message = $convertstr;
   
     if ( $FORM{'ns'} eq 'NS' ) { $message .= '#nosmileys'; }
   
     if ($error) {
         $IM_box = $inmes_txt{'148'};
         $FORM{'previewim'} = 1;
         IMPost();
         buildIMsend();
         return;
     }
   
     undef @multiple;
     fopen( MEMLIST, "$memberdir/memberlist.txt" );
     my @memberlist = <MEMLIST>;
     my $allmems    = @memberlist;
     fclose(MEMLIST);
   
     ProcIMrecs();
   
     $memnums = $#multiple + 1;
     ## no need to check for spam if its a broadcast, as this only creates the one post
     if ( $imspam eq 'off' ) { $imspam = 0; }
     $imspam ||= 0;
     if ( $imspam > 0 && !$isBMess ) {
         $checkspam = 100 / $allmems * $memnums;
         if ( $memnums == 1 ) { $checkspam = 0; }
         if ( $checkspam > $imspam && !$iamadmin ) {
             fatal_error('im_spam_alert');
         }
     }
   
     # Create unique Message ID
     $messageid = getnewid();
     $allowAttachIM ||= 0;
     $allowGroups = GroupPerms( $allowAttachIM, $pmAttachGroups );
     if ( $allowAttachIM && $allowGroups ) {
         for my $y ( 1 .. $allowAttachIM ) {
             if ($CGI_query) { $file = $CGI_query->upload("file$y"); }
             if ($file) {
                 $fixfile = $file;
                 $fixfile =~ s/.+\\([^\\]+)$|.+\/([^\/]+)$/$1/xsm;
                 if ( $fixfile =~ /[^0-9A-Za-z\+\-\.:_]/xsm )
                 {    # replace all inappropriate characters
                         # Transliteration
  ## Arrays moved to Main.lng ##
                     my $x = 0;
                     foreach ( @uploadtranlist )
                     {
                         $fixfile =~ s/$_/$ISO_8859_1[$x]/igxsm;
                         $x++;
                     }
   
               # END Transliteration. Thanks to "Velocity" for this contribution.
                     $fixfile =~ s/[^0-9A-Za-z\+\-\.:_]/_/gxsm;
                 }
   
                 # replace . with _ in the filename except for the extension
                 my $fixname = $fixfile;
                 if ( $fixname =~ s/(.+)(\..+?)$/$1/xsm ) {
                     $fixext = $2;
                 }
   
                 $spamdetected = spamcheck("$fixname");
                 if ( !$staff ) {
                     if ( $spamdetected == 1 ) {
                         ${ $uid . $username }{'spamcount'}++;
                         ${ $uid . $username }{'spamtime'} = $date;
                         UserAccount( $username, 'update' );
                         $spam_hits_left_count = $post_speed_count -
                           ${ $uid . $username }{'spamcount'};
                         foreach (@filelist) { unlink "$pmuploaddir/$_"; }
                         fatal_error('tsc_alert');
                     }
                 }
                 if ( $use_guardian && $string_on ) {
                     @bannedstrings = split /\|/xsm, $banned_strings;
                     foreach (@bannedstrings) {
                         chomp $_;
                         if ( $fixname =~ m/$_/ism ) {
                             fatal_error( 'attach_name_blocked', "($_)" );
                         }
                     }
                 }
                 $fixext =~ s/\.(pl|pm|cgi|php)/._$1/ixsm;
                 $fixname =~ s/\.(?!tar$)/_/gxsm;
                 $fixfile = qq~$fixname$fixext~;
                 if ( $fixfile eq 'index.html' || $fixfile eq '.htaccess' ) {
                     fatal_error('attach_file_blocked');
                 }
   
                 if ( !$pmFileOverwrite ) {
                     $fixfile = check_existence( $pmuploaddir, $fixfile );
                 }
                 elsif ( $pmFileOverwrite == 2 && -e "$pmuploaddir/$fixfile" ) {
                     foreach (@filelist) { unlink "$pmuploaddir/$_"; }
                     fatal_error('file_overwrite');
                 }
   
                 my $match = 0;
                 if ( !$pmCheckExt ) { $match = 1; }
                 else {
                     foreach my $ext (@pmAttachExt) {
                         if ( grep { /$ext$/ixsm } $fixfile ) {
                             $match = 1;
                             last;
                         }
                     }
                 }
                 if ($match) {
                     if ( $allowAttachIM == 0 ) {
                         foreach (@filelist) { unlink "$pmuploaddir/$_"; }
                         fatal_error('no_perm_att');
                     }
                 }
                 else {
                     foreach (@filelist) { unlink "$pmuploaddir/$_"; }
                     fatal_error( q{}, "$fixfile $fatxt{'20'} @pmAttachExt" );
                 }
   
                 my ( $size, $buffer, $filesize, $file_buffer );
                 while ( $size = read $file, $buffer, 512 ) {
                     $filesize += $size;
                     $file_buffer .= $buffer;
                 }
                 $pmFileLimit ||= 0;
                 if ( $pmFileLimit > 0 && $filesize > ( 1024 * $pmFileLimit ) ) {
                     foreach (@filelist) { unlink "$pmuploaddir/$_"; }
                     fatal_error( q{},
                             "$fatxt{'21'} $fixfile (" 
                           . int( $filesize / 1024 )
                           . " KB) $fatxt{'21b'} " 
                           . $pmFileLimit );
                 }
                 $pmDirLimit ||= 0;
                 if ( $pmDirLimit > 0 ) {
                     my $dirsize = dirsize($pmuploaddir);
                     if ( $filesize > ( ( 1024 * $pmDirLimit ) - $dirsize ) ) {
                         foreach (@filelist) { unlink "$pmuploaddir/$_"; }
                         fatal_error(
                             q{},
                             "$fatxt{'22'} $fixfile (" 
                               . (
                                 int( $filesize / 1024 ) -
                                   $pmDirLimit +
                                   int( $dirsize / 1024 )
                               )
                               . " KB) $fatxt{'22b'}" 
                         );
                     }
                 }
   
  # create a new file on the server using the formatted ( new instance ) filename
                 if ( fopen( NEWFILE, ">$pmuploaddir/$fixfile" ) ) {
                     binmode NEWFILE;
   
                    # needed for operating systems (OS) Windows, ignored by Linux
                     print {NEWFILE} $file_buffer
                       or croak "$croak{'print'} NEWFILE"; # write new file on HD
                     fclose(NEWFILE);
                 }
                 else
                 { # return the server's error message if the new file could not be created
                     foreach (@filelist) { unlink "$pmuploaddir/$_"; }
                     fatal_error( 'file_not_open', "$pmuploaddir" );
                 }
   
      # check if file has actually been uploaded, by checking the file has a size
                 $filesizekb{$fixfile} = -s "$pmuploaddir/$fixfile";
                 if ( !$filesizekb{$fixfile} ) {
                     foreach (qw("@filelist" $fixfile)) {
                         unlink "$pmuploaddir/$_";
                     }
                     fatal_error( 'file_not_uploaded', $fixfile );
                 }
                 $filesizekb{$fixfile} = int( $filesizekb{$fixfile} / 1024 );
   
                 if ( $fixfile =~ /\.(jpg|gif|png|jpeg)$/ism ) {
                     my $okatt = 1;
                     if ( $fixfile =~ /gif$/ism ) {
                         my $header;
                         fopen( ATTFILE, "$pmuploaddir/$fixfile" );
                         read ATTFILE, $header, 10;
                         my $giftest;
                         ( $giftest, undef, undef, undef, undef, undef ) =
                           unpack 'a3a3C4', $header;
                         fclose(ATTFILE);
                         if ( $giftest ne 'GIF' ) { $okatt = 0; }
                     }
                     fopen( ATTFILE, "$pmuploaddir/$fixfile" );
                     while ( read ATTFILE, $buffer, 1024 ) {
                         if ( $buffer =~ /<(html|script|body)/igxsm ) {
                             $okatt = 0;
                             last;
                         }
                     }
                     fclose(ATTFILE);
                     if ( !$okatt )
                     {    # delete the file as it contains illegal code
                         foreach (qw("@filelist" $fixfile)) {
                             unlink "$pmuploaddir/$_";
                         }
                         fatal_error( 'file_not_uploaded',
                             "$fixfile $fatxt{'20a'}" );
                     }
                 }
   
                 $logFixfile = $fixfile;
                 push @logfilelist, $logFixfile;
                 $fixfile .= q{~} . $username;
                 push @filelist, $fixfile;
   
             }
   
             if ( $FORM{"w_filename$y"} && $FORM{"w_file$y"} eq 'attachold' ) {
                 $pmAttachUser = decloak( $FORM{"w_fileuser$y"} );
                 $FORM{"w_filename$y"} .= q{~} . $pmAttachUser;
                 push @filelist, $FORM{"w_filename$y"};
             }
         }
   
         # Create the list of files
         $fixfile    = join q{,}, @filelist;
         $logFixfile = join q{,}, @logfilelist;
         if (@filelist) {
             fopen( PMATTACHLOG, ">>$vardir/pm.attachments" )
               or fatal_error( 'cannot_open', "$vardir/pm.attachments" );
             foreach my $logFixfile (@logfilelist) {
                 print {PMATTACHLOG}
  qq~$messageid|$date|$filesizekb{$logFixfile}|$logFixfile|${$uid.$username}{'realname'}|$username\n~
                   or croak "$croak{'print'} PMATTACHLOG";
             }
             fclose(PMATTACHLOG);
         }
     }
   
     # go through each member in list
     # add to each msg (inbox) but only one to outbox
   
     $actlang = $language;
     if ( !$FORM{'draft'} && !$isBMess && !$replyguest ) {
         foreach my $UserTo (@allto) {
             $addnr++;
             chomp $UserTo;
             my ( $status, $UserTo ) = split /:/xsm, $UserTo;
             $ignored = 0;
             $UserTo =~ s/\A\s+//xsm;
             $UserTo =~ s/\s+\Z//xsm;
             $UserTo =~ s/[^0-9A-Za-z#%+,-\.@^_]//gsm;
   
             # Check Ignore-List, unless sender is FA
             LoadUser($UserTo);
             if ( !$isBMess ) {
                 if (   ${ $uid . $UserTo }{'im_ignorelist'}
                     && !$iamadmin
                     && !$iamgmod )
                 {
   
                     # Build Ignore-List
                     @ignore =
                       split /\|/xsm, ${ $uid . $UserTo }{'im_ignorelist'};
   
                     # If User is on Recipient's Ignore-List, show Error Message
                     foreach my $igname (@ignore) {
   
    # adds ignored user's name to array which error list will be built from later
                         chomp $igname;
                         if ( $igname eq $username ) {
                             push @nouser, $UserTo;
                             $ignored = 1;
                         }
                         if ( $igname eq q{*} ) {
                             push @nouser,
                               "$inmes_txt{'761'} $UserTo $inmes_txt{'762'};";
                             $ignored = 1;
                         }
                     }
                 }
             }
             ## check and see if 1) username is marked 'away' 2) they left a message 3) you have not already had an auto-reply
             my $sendAutoReply = 1;
             if (   ${ $uid . $UserTo }{'offlinestatus'} eq 'away' 
                 && ${ $uid . $UserTo }{'awayreply'} ne q{}
                 && ${ $uid . $UserTo }{'awaysubj'} ne q{} )
             {
                 if ( ${ $uid . $UserTo }{'awayreplysent'} eq q{} ) {
                     ${ $uid . $UserTo }{'awayreplysent'} = $username;
                     UserAccount( $UserTo, 'update' );
                 }
                 else {
                     foreach my $replyListName ( split /,/xsm,
                         ${ $uid . $UserTo }{'awayreplysent'} )
                     {
                         if ( $replyListName eq $username ) {
                             $sendAutoReply = 0;
                             last;
                         }
                     }
                     if ($sendAutoReply) {
                         ${ $uid . $UserTo }{'awayreplysent'} .= qq~,$username~;
                         UserAccount( $UserTo, 'update' );
                     }
                 }
             }
             else { $sendAutoReply = 0; }
   
             if ( !-e ("$memberdir/$UserTo.vars") ) {
   
    # adds invalid user's name to array which error list will be built from later
                 push @nouser, $UserTo;
                 $ignored = 1;
             }
   
             if ( !$ignored ) {
   
                 # Send message to user
                 fopen( INBOX, "$memberdir/$UserTo.msg" );
                 my @inmessages = <INBOX>;
                 fclose(INBOX);
                 fopen( INBOX, ">$memberdir/$UserTo.msg" );
                 print {INBOX}
  "$messageid|$username|$FORM{'toshow'}|$FORM{'toshowcc'}|$FORM{'toshowbcc'}|$subject|$date|$message|$messageid|0|$ENV{'REMOTE_ADDR'}|$FORM{'status'}|u||$fixfile\n" 
                   or croak "$croak{'print'} INBOX";
                 print {INBOX} @inmessages or croak "$croak{'print'} INBOX";
                 fclose(INBOX);
   
                 # we've added the msg to the inbox, now update the ims file
                 updateIMS( $UserTo, $messageid, 'messagein' );
                 ## if we need to drop the 'away' reply in....
                 if ($sendAutoReply) {
                     my $rmessageid = getnewid();
                     fopen( INBOX, "$memberdir/$username.msg" );
                     my @myinmessages = <INBOX>;
                     fclose(INBOX);
                     fopen( INBOX, ">$memberdir/$username.msg" );
                     print {INBOX}
  "$rmessageid|$UserTo|$username|||${$uid.$UserTo}{'awaysubj'}|$date|${$uid.$UserTo}{'awayreply'}|$messageid|1|$ENV{'REMOTE_ADDR'}|s|u||$fixfile\n" 
                       or croak "$croak{'print'} INBOX";
                     print {INBOX} @myinmessages
                       or croak "$croak{'print'} INBOX";
                     fclose(INBOX);
                 }
                 ## relocated sender msg out of the loop
   
  # Send notification (Will only work if Admin has allowed the Email Notification)
                 if ( ${ $uid . $UserTo }{'notify_me'} > 1
                     && $enable_notifications > 1 )
                 {
                     require Sources::Mailer;
                     $language = ${ $uid . $UserTo }{'language'};
                     LoadLanguage('Email');
                     LoadLanguage('Notify');
                     LoadCensorList();
                     $useremail = ${ $uid . $UserTo }{'email'};
                     $useremail =~ s/[\n\r]//gxsm;
                     if ( $useremail ne q{} ) {
                         my $msubject = $subject ? $subject : $inmes_txt{'767'};
                         $fromname = ${ $uid . $username }{'realname'};
                         FromHTML($msubject);
                         ToChars($msubject);
                         $msubject = Censor($msubject);
                         my $chmessage = $message;
                         FromHTML($chmessage);
                         ToChars($chmessage);
                         $chmessage = Censor($chmessage);
                         $chmessage = regex_4($chmessage);
   
                         $pmAttachUrl = q{};
                         if ( $fixfile ne q{} ) {
                             foreach ( split /,/xsm, $fixfile ) {
                                 my ( $pmAttachFile, undef ) = split /~/xsm, $_;
                                 $pmAttachUrl .=
                                   qq~$pmuploadurl/$pmAttachFile\n~;
                             }
                             $pmAttachTxt = qq~\n$fatxt{'80'}:\n~;
                             $mailattach  = $pmAttachTxt . $pmAttachUrl;
                         }
                         sendmail(
                             $useremail,
                             qq~$notify_txt{'145'} $fromname ($msubject)~,
                             template_email(
                                 $privatemessagenotificationemail,
                                 {
                                     'sender'      => $fromname,
                                     'subject'     => $msubject,
                                     'message'     => $chmessage,
                                     'attachments' => $mailattach
                                 }
                             ),
                             q{},
                             $emailcharset
                         );
                     }
                 }
             }    #end add PM to outbox
         }    #end foreach loop
         if ( $#allto == $#nouser ) {
             my $badusers;
             foreach my $baduser (@nouser) {
                 LoadUser($baduser);
                 $badusers .=
  qq~<a href="$scripturl?action=viewprofile;username=$useraccount{$baduser}">$format_unbold{$baduser}</a>, ~;
             }
             $badusers =~ s/, \Z//sm;
             fatal_error( 'im_bad_users', $badusers );
         }
     }
   
     if ( !$FORM{'draft'} && $isBMess ) {
         fopen( INBOX, "<$memberdir/broadcast.messages" );
         my @inmessages = <INBOX>;
         fclose(INBOX);
         fopen( INBOX, ">$memberdir/broadcast.messages" );
         print {INBOX}
  "$messageid|$username|$FORM{'toshow'}|||$subject|$date|$message|$messageid|0|$ENV{'REMOTE_ADDR'}|$FORM{'status'}b|u||$fixfile\n" 
           or croak "$croak{'print'} INBOX";
         print {INBOX} @inmessages or croak "$croak{'print'} INBOX";
         fclose(INBOX);
     }
   
     if ( $FORM{'reply'} && $FORM{'info'} ) {    # mark msg replied
         updateMessageFlag( $username, $FORM{'info'}, 'msg', q{}, 'r' );
     }
   
     ## this now outside the foreach, to allow just one write in the outbox
     # Add message to outbox, read outbox
   
     @outmessages = ();
     my $savetofile = 'outbox';
     if ( $FORM{'draft'} ) { $savetofile = 'imdraft'; }
     fopen( OUTBOX, "$memberdir/$username.$savetofile" );
     @outmessages = <OUTBOX>;
     fclose(OUTBOX);
   
     # add the PM to the outbox
     # the sep users now live together
     my $messFlag = q{};
     if ($isBMess) { $messFlag = 'b'; }
     if ($replyguest) {
         $messFlag = 'gr';
   
         $FORM{'toguest'} =~ s/ /%20/gsm;
         $FORM{'toshow'} = $FORM{'toguest'} . q{ } . $FORM{'guestemail'};
         $FORM{'toshow'} =~ s/[\n\r]//gsm;
         $FORM{'guestemail'} =~ s/[\n\r]//gsm;
   
         $fromname = ${ $uid . $username }{'realname'};
   
         my $msubject = $subject;
         FromHTML($msubject);
         ToChars($msubject);
   
         $chmessage = $message;
         FromHTML($chmessage);
         ToChars($chmessage);
         $chmessage = regex_4($chmessage);
         $chmessage =~ s/\r(?=\n*)//gsm;
   
         require Sources::Mailer;
         sendmail( $FORM{'guestemail'}, $msubject, $chmessage,
             ${ $uid . $username }{'email'} );
     }
   
     if (  !$FORM{'dontstoreinoutbox'}
         || $FORM{'draft'}
         || ( $FORM{'dontstoreinoutbox'} && $fixfile ne q{} ) )
     {
         fopen( OUTBOX, "+>$memberdir/$username.$savetofile" )
           or
           fatal_error( 'cannot_open', "+>$memberdir/$username.$savetofile", 1 );
         ## all but drafts being resaved just get added to their file
         if ( !$FORM{'draft'} || ( $FORM{'draft'} && !$FORM{'draftid'} ) ) {
             print {OUTBOX}
  "$messageid|$username|$FORM{'toshow'}|$FORM{'toshowcc'}|$FORM{'toshowbcc'}|$subject|$date|$message|$messageid|$FORM{'reply'}|$ENV{'REMOTE_ADDR'}|$FORM{'status'}$messFlag|||$fixfile\n" 
               or croak "$croak{'print'} OUTBOX";
             print {OUTBOX} @outmessages or croak "$croak{'print'} OUTBOX";
   
         }
         elsif ( $FORM{'draft'} && $FORM{'draftid'} ) {
             ## resaving draft - find draft message id and amend the entry
             foreach my $outmessage (@outmessages) {
                 chomp $outmessage;
                 if ( ( split /\|/xsm, $outmessage )[0] != $FORM{'draftid'} ) {
                     print {OUTBOX} "$outmessage\n" 
                       or croak "$croak{'print'} OUTBOX";
                 }
                 else {
                     print {OUTBOX}
  "$messageid|$username|$FORM{'toshow'}|$FORM{'toshowcc'}|$FORM{'toshowbcc'}|$subject|$date|$message|$messageid|$FORM{'reply'}|$ENV{'REMOTE_ADDR'}|$FORM{'status'}$messFlag|||$fixfile\n" 
                       or croak "$croak{'print'} OUTBOX";
                 }
             }
         }
         fclose(OUTBOX);
   
         ## update ims for sent
         if ( !$FORM{'draft'} ) {
             updateIMS( $username, $messageid, 'messageout' );
         }
         elsif ( !$FORM{'draftid'} ) {
             updateIMS( $username, $messageid, 'draftadd' );
         }
     }
   
     ## if this is a draft being sent, remove it from the draft file
     if ( $FORM{'draftid'} && $FORM{'draft'} ne $inmes_txt{'savedraft'} ) {
         updateIMS( $username, $messageid, 'draftsend' );
         fopen( DRAFTFILE, "$memberdir/$username.imdraft" );
         my @draftPM = <DRAFTFILE>;
         fclose(DRAFTFILE);
         fopen( DRAFTFILE, ">$memberdir/$username.imdraft" );
         seek DRAFTFILE, 0, 0;
         foreach my $draftmess (@draftPM) {
             chomp $draftmess;
             if ( ( split /\|/xsm, $draftmess )[0] != $FORM{'draftid'} ) {
                 print {DRAFTFILE} "$draftmess\n" 
                   or croak "$croak{'print'} DRAFTFILE";
             }
             elsif ( $FORM{'draftleave'} ) {
                 print {DRAFTFILE}
  "$messageid|$username|$FORM{'toshow'}|$FORM{'toshowcc'}|$FORM{'toshowbcc'}|$subject|$date|$message|$messageid|$FORM{'reply'}|$ENV{'REMOTE_ADDR'}|$FORM{'status'}$messFlag|||$fixfile\n" 
                   or croak "$croak{'print'} DRAFTFILE";
             }
         }
         fclose(DRAFTFILE);
     }
   
  # invalid users
  #if there were invalid usernames in the recipient list, these names are listed after all valid users have been IMed
     if ( !$FORM{'draft'} ) {
         if (@nouser) {
             my $badusers;
             foreach my $baduser (@nouser) {
                 LoadUser($baduser);
                 $badusers .=
  qq~<a href="$scripturl?action=viewprofile;username=$useraccount{$baduser}">$format_unbold{$baduser}</a>, ~;
             }
             $badusers =~ s/, \Z//sm;
             fatal_error( 'im_bad_users', $badusers );
         }
     }
   
     ## saving a draft does not count as sending
     if ( !$FORM{'draft'} ) { UserAccount( $username, 'update', 'lastim' ); }
     UserAccount( $username, 'update', 'lastonline' );
   
     if ( $FORM{'dontstoreinoutbox'} && $fixfile eq q{} ) {
         $yySetLocation = qq~$scripturl?action=im~;
     }
     elsif ( $FORM{'draft'} ) { $yySetLocation = qq~$scripturl?action=imdraft~; }
     else { $yySetLocation = qq~$scripturl?action=imoutbox~; }
     redirectexit();
     return;
  }
   
##  process the to/cc/bcc lists ##  process the to/cc/bcc lists
sub ProcIMrecs { sub ProcIMrecs {
   $FORM{'toshow'} =~ s/ //g;     $FORM{'toshow'} =~ s/ //gsm; 
   
   if (!$isBMess) {    if ( !$isBMess ) {
       my $countMulti = 0;        $countMulti = 0;
       @multiple = split(/\,/, $FORM{'toshow'});         @multiple = split /\,/xsm, $FORM{'toshow'}; 
       foreach my $multiUser (@multiple) {        foreach my $multiUser (@multiple) {
           if ($do_scramble_id) { $multiple[$countMulti] = &decloak($multiUser); }             if ($do_scramble_id) { 
           $countMulti++ ;                 $multiple[$countMulti] = decloak($multiUser); 
       }            }
       $toshowList = join(',', @multiple);             $countMulti++; 
       $toshowList = qq~to:$toshowList~;         } 
       $toshowList =~ s/,/,to:/g;         $toshowList = join q{,}, @multiple; 
       push(@allto, split(/\,/,$toshowList));         $toshowList = qq~to:$toshowList~; 
       $FORM{'toshow'} = join(',', @multiple);         $toshowList =~ s/,/,to:/gsm; 
       $FORM{'toshowcc'} =~ s/ //g;         push @allto, ( split /\,/xsm, $toshowList ); 
       $FORM{'toshowbcc'} =~ s/ //g;         $FORM{'toshow'} = join q{,}, @multiple; 
         $FORM{'toshowcc'} =~ s/ //gsm;
       if ($FORM{'toshowcc'}) {         $FORM{'toshowbcc'} =~ s/ //gsm; 
           my $countMulti = 0;  
           @multiplecc = split(/\,/, $FORM{'toshowcc'});         if ( $FORM{'toshowcc'} ) { 
           foreach my $multiUser (@multiplecc) {             my $countMulti = 0; 
               $multiUser =~ s/ //g;             @multiplecc = split /\,/xsm, $FORM{'toshowcc'}; 
               if ($do_scramble_id) { $multiplecc[$countMulti] = &decloak($multiUser); }             foreach my $multiUser (@multiplecc) { 
               else { $multiplecc[$countMulti] = $multiUser; }                 $multiUser =~ s/ //gsm; 
               $countMulti++ ;                 if ($do_scramble_id) { 
           }                     $multiplecc[$countMulti] = decloak($multiUser); 
           $toshowccList = join(',', @multiplecc);                 } 
           $toshowccList = qq~cc:$toshowccList~;                 else { $multiplecc[$countMulti] = $multiUser; } 
           $toshowccList =~ s/,/,cc:/g;                 $countMulti++; 
           push(@allto, split(/\,/,$toshowccList));             } 
           $FORM{'toshowcc'} = join(',', @multiplecc);             $toshowccList = join q{,}, @multiplecc; 
       }             $toshowccList = qq~cc:$toshowccList~; 
       if ($FORM{'toshowbcc'}) {             $toshowccList =~ s/,/,cc:/gsm; 
           my $countMulti = 0;             push @allto, ( split /\,/xsm, $toshowccList ); 
           @multiplebcc = split(/\,/, $FORM{'toshowbcc'});             $FORM{'toshowcc'} = join q{,}, @multiplecc; 
           foreach my $multiUser (@multiplebcc) {         } 
               $multiUser =~ s/ //g;         if ( $FORM{'toshowbcc'} ) { 
               if ($do_scramble_id) { $multiplebcc[$countMulti] = &decloak($multiUser); }             my $countMulti = 0; 
               else{$multiplebcc[$countMulti] = $multiUser;}             @multiplebcc = split /\,/xsm, $FORM{'toshowbcc'}; 
               $countMulti++ ;             foreach my $multiUser (@multiplebcc) { 
           }                 $multiUser =~ s/ //gsm; 
           $toshowbccList = join(',', @multiplebcc);                 if ($do_scramble_id) { 
           $toshowbccList = qq~bcc:$toshowbccList~;                     $multiplebcc[$countMulti] = decloak($multiUser); 
           $toshowbccList =~ s/,/,bcc:/g;                 } 
           push(@allto, split(/\,/,$toshowbccList));                 else { $multiplebcc[$countMulti] = $multiUser; } 
           $FORM{'toshowbcc'} = join(',', @multiplebcc);                 $countMulti++; 
       }            }
   }             $toshowbccList = join q{,}, @multiplebcc; 
             $toshowbccList = qq~bcc:$toshowbccList~;
             $toshowbccList =~ s/,/,bcc:/gsm;
             push @allto, ( split /\,/xsm, $toshowbccList );
             $FORM{'toshowbcc'} = join q{,}, @multiplebcc;
         }
     }
     return;
} }
   
sub pageLinksList { sub pageLinksList {
   # Build the page links list.  
   $maxmessagedisplay ||= 10;     # Build the page links list. 
   my $userthreadpage = (split /\|/, ${$uid.$username}{'pageindex'})[3];     $maxmessagedisplay ||= 10; 
   my ($pagetxtindex, $pagetextindex, $pagedropindex1, $pagedropindex2, $all, $allselected, $bmesslink);     my $userthreadpage = 
   $postdisplaynum = 3; # max number of pages to display       ( split /\|/xsm, ${ $uid . $username }{'pageindex'} )[3]; 
   $dropdisplaynum = 10;     my ( $pagetxtindex, $pagedropindex1, $pagedropindex2, $all, $allselected, 
   $startpage = 0;         $bmesslink ); 
   if ($INFO{'viewfolder'} ne '') { $viewfolderinfo = qq~;viewfolder=$INFO{'viewfolder'}~; }     $postdisplaynum = 3;    # max number of pages to display 
   if ($INFO{'focus'} eq 'bmess') { $bmesslink = qq~;focus=bmess~;}     $dropdisplaynum = 10; 
   my @tempim = @dimmessages;     $startpage      = 0; 
   if ($action eq 'imstorage') {    if ( $INFO{'viewfolder'} ne q{} ) {
       my $i = 0;         $viewfolderinfo = qq~;viewfolder=$INFO{'viewfolder'}~; 
       foreach (@dimmessages) {     } 
           if ((split(/\|/, $_))[13] ne $INFO{'viewfolder'}) {     if ( $INFO{'focus'} eq 'bmess' ) { $bmesslink = q~;focus=bmess~; } 
               splice(@tempim,$i,1);     my @tempim = @dimmessages; 
               next;     if ( $action eq 'imstorage' ) { 
           }         my $i = 0; 
           $i++;         foreach (@dimmessages) { 
       }             if ( ( split /\|/xsm, $_ )[13] ne $INFO{'viewfolder'} ) { 
   }                 splice @tempim, $i, 1; 
   $max = $#tempim + 1;                 next; 
   if ($INFO{'start'} eq "all") { $maxmessagedisplay = $max; $all = 1; $allselected = qq~ selected="selected"~; $start = 0; }            }
   else { $start = $INFO{'start'} || 0; }             $i++; 
   $start = $start > $#tempim ? $#tempim : $start;         } 
   $start = (int($start / $maxmessagedisplay)) * $maxmessagedisplay;     } 
   $tmpa = 1;    $max = $#tempim + 1;
   $pagenumb = int(($max - 1) / $maxmessagedisplay) + 1;     if ( $INFO{'start'} eq 'all' ) { 
   if ($start >= (($postdisplaynum - 1) * $maxmessagedisplay)) {         $maxmessagedisplay = $max; 
       $startpage = $start - (($postdisplaynum - 1) * $maxmessagedisplay);         $all               = 1; 
       $tmpa = int($startpage / $maxmessagedisplay) + 1;         $allselected       = q~ selected="selected"~; 
   }         $start             = 0; 
   if ($max >= $start + ($postdisplaynum * $maxmessagedisplay)) { $endpage = $start + ($postdisplaynum * $maxmessagedisplay); }    }
   else { $endpage = $max; }    else { $start = $INFO{'start'} || 0; }
   $lastpn = int($#tempim / $maxmessagedisplay) + 1;     $start    = $start > $#tempim ? $#tempim : $start; 
   $lastptn = ($lastpn - 1) * $maxmessagedisplay;    $start    = ( int( $start / $maxmessagedisplay ) ) * $maxmessagedisplay;
   $pageindex1 = qq~<span class="small" style="float: left; height: 21px; margin: 0px; margin-top: 2px;"><img src="$imagesdir/index_togl.gif" border="0" alt="$display_txt{'19'}" title="$display_txt{'19'}" style="vertical-align: middle;" /> $display_txt{'139'}: $pagenumb</span>~;     $tmpa     = 1; 
   if ($pagenumb > 1 || $all) {     $pagenumb = int( ( $max - 1 ) / $maxmessagedisplay ) + 1; 
       if ($userthreadpage == 1 ) {    if ( $start >= ( ( $postdisplaynum - 1 ) * $maxmessagedisplay ) ) {
           $pagetxtindexst = qq~<span class="small" style="float: left; height: 21px; margin: 0px; margin-top: 2px;">~;         $startpage = $start - ( ( $postdisplaynum - 1 ) * $maxmessagedisplay ); 
           $pagetxtindexst .= qq~<a href="$scripturl?pmaction=$action$bmesslink;start=$start;action=pmpagetext$viewfolderinfo"><img src="$imagesdir/index_togl.gif" border="0" alt="$display_txt{'19'}" title="$display_txt{'19'}" style="vertical-align: middle;" /></a> $display_txt{'139'}: ~;         $tmpa = int( $startpage / $maxmessagedisplay ) + 1; 
           if ($startpage > 0) { $pagetxtindex = qq~<a href="$scripturl?action=$action$bmesslink/0$viewfolderinfo" style="font-weight: normal;">1</a>&nbsp;...&nbsp;~; }    }
           if ($startpage == $maxmessagedisplay) { $pagetxtindex = qq~<a href="$scripturl?action=$action$bmesslink;start=0$viewfolderinfo" style="font-weight: normal;">1</a>&nbsp;~; }     if ( $max >= $start + ( $postdisplaynum * $maxmessagedisplay ) ) { 
           for ($counter = $startpage; $counter < $endpage; $counter += $maxmessagedisplay) {         $endpage = $start + ( $postdisplaynum * $maxmessagedisplay ); 
               $pagetxtindex .= $start == $counter ? qq~<b>$tmpa</b>&nbsp;~ : qq~<a href="$scripturl?action=$action$bmesslink;start=$counter$viewfolderinfo" style="font-weight: normal;">$tmpa</a>&nbsp;~;     } 
               $tmpa++;     else { $endpage = $max; } 
           }     $lastpn  = int( $#tempim / $maxmessagedisplay ) + 1; 
           if ($endpage < $max - ($maxmessagedisplay)) { $pageindexadd = qq~...&nbsp;~; }     $lastptn = ( $lastpn - 1 ) * $maxmessagedisplay; 
           if ($endpage != $max) { $pageindexadd .= qq~<a href="$scripturl?action=$action$bmesslink;start=$lastptn$viewfolderinfo" style="font-weight: normal;">$lastpn</a>~; }     $pageindex1 = 
           $pagetxtindex .= qq~$pageindexadd~;  qq~<span class="small pgindex"><img src="$index_togl{'index_togl'}" alt="$display_txt{'19'}" title="$display_txt{'19'}" /> $display_txt{'139'}: $pagenumb</span>~; 
           $pageindex1 = qq~$pagetxtindexst$pagetxtindex</span>~;     if ( $pagenumb > 1 || $all ) { 
           $pageindex2 = $pageindex1;         if ( $userthreadpage == 1 ) { 
       } else {             $pagetxtindexst = q~<span class="small pgindex">~; 
           $pagedropindex1 = qq~<span style="float: left; width: 350px; margin: 0px; margin-top: 2px; border: 0px;">~;             $pagetxtindexst .= 
           $pagedropindex1 .= qq~<span style="float: left; height: 21px; margin: 0; margin-right: 4px;"><a href="$scripturl?pmaction=$action$bmesslink;start=$start;action=pmpagedrop$viewfolderinfo"><img src="$imagesdir/index_togl.gif" border="0" alt="$display_txt{'19'}" title="$display_txt{'19'}" /></a></span>~;  qq~<a href="$scripturl?pmaction=$action$bmesslink;start=$start;action=pmpagetext$viewfolderinfo"><img src="$index_togl{'index_togl'}" alt="$display_txt{'19'}" title="$display_txt{'19'}" /></a> $display_txt{'139'}: ~; 
           $pagedropindex2 = $pagedropindex1;             if ( $startpage > 0 ) { 
           $tstart = $start;                 $pagetxtindex = 
           if (substr($INFO{'start'}, 0, 3) eq "all") { ($tstart, $start) = split(/\-/, $INFO{'start'}); }  qq~<a href="$scripturl?action=$action$bmesslink/0$viewfolderinfo"><span class="small">1</span></a>&nbsp;...&nbsp;~; 
           $d_indexpages = $pagenumb / $dropdisplaynum;             } 
           $i_indexpages = int($pagenumb / $dropdisplaynum);             if ( $startpage == $maxmessagedisplay ) { 
           if ($d_indexpages > $i_indexpages) { $indexpages = int($pagenumb / $dropdisplaynum) + 1; }                 $pagetxtindex = 
           else { $indexpages = int($pagenumb / $dropdisplaynum) }  qq~<a href="$scripturl?action=$action$bmesslink;start=0$viewfolderinfo"><span class="small">1</span></a>&nbsp;~; 
           $selectedindex = int(($start / $maxmessagedisplay) / $dropdisplaynum);             } 
           if ($pagenumb > $dropdisplaynum) {            foreach my $counter ( $startpage .. ( $endpage - 1 ) ) {
               $pagedropindex1 .= qq~<span style="float: left; height: 21px; margin: 0;"><select size="1" name="decselector1" id="decselector1" style="font-size: 9px; border: 2px inset;" onchange="if(this.options[this.selectedIndex].value) SelDec(this.options[this.selectedIndex].value, 'xx')">\n~;                 if ( $counter % $maxmessagedisplay == 0 ) { 
               $pagedropindex2 .= qq~<span style="float: left; height: 21px; margin: 0;"><select size="1" name="decselector2" id="decselector2" style="font-size: 9px; border: 2px inset;" onchange="if(this.options[this.selectedIndex].value) SelDec(this.options[this.selectedIndex].value, 'xx')">\n~;                     $pagetxtindex .= 
           }                       $start == $counter 
           for ($i = 0; $i < $indexpages; $i++) {                       ? qq~<b>[$tmpa]</b>&nbsp;~ 
               $indexpage = ($i * $dropdisplaynum) * $maxmessagedisplay;                       : qq~<a href="$scripturl?action=$action$bmesslink;start=$counter$viewfolderinfo"><span class="small">$tmpa</span></a>&nbsp;~; 
               $indexstart = ($i * $dropdisplaynum) + 1;                     $tmpa++; 
               $indexend = $indexstart + ($dropdisplaynum - 1);                 } 
               if ($indexend > $pagenumb) { $indexend   = $pagenumb; }            }
               if ($indexstart == $indexend) { $indxoption = qq~$indexstart~; }             if ( $endpage < $max - ($maxmessagedisplay) ) { 
               else { $indxoption = qq~$indexstart-$indexend~; }                 $pageindexadd = q~...&nbsp;~; 
               $selected = "";             } 
               if ($i == $selectedindex) {            if ( $endpage != $max ) {
                   $selected    = qq~ selected="selected"~;                 $pageindexadd .= 
                   $pagejsindex = qq~$indexstart|$indexend|$maxmessagedisplay|$indexpage~;  qq~<a href="$scripturl?action=$action$bmesslink;start=$lastptn$viewfolderinfo"><span class="small">$lastpn</span></a>~; 
               }            }
               if ($pagenumb > $dropdisplaynum) {             $pagetxtindex .= qq~$pageindexadd~; 
                   $pagedropindex1 .= qq~<option value="$indexstart|$indexend|$maxmessagedisplay|$indexpage"$selected>$indxoption</option>\n~;             $pageindex1 = qq~$pagetxtindexst$pagetxtindex</span>~; 
                   $pagedropindex2 .= qq~<option value="$indexstart|$indexend|$maxmessagedisplay|$indexpage"$selected>$indxoption</option>\n~;             $pageindex2 = $pageindex1; 
               }        }
           }         else { 
           if ($pagenumb > $dropdisplaynum) {             $pagedropindex1 = q~<span class="pagedropindex">~; 
               $pagedropindex1 .= qq~</select>\n</span>~;             $pagedropindex1 .= 
               $pagedropindex2 .= qq~</select>\n</span>~;  qq~<span class="pagedropindex_inner"><a href="$scripturl?pmaction=$action$bmesslink;start=$start;action=pmpagedrop$viewfolderinfo"><img src="$index_togl{'index_togl'}" alt="$display_txt{'19'}" title="$display_txt{'19'}" /></a></span>~; 
           }             $pagedropindex2 = $pagedropindex1; 
           $pagedropindex1 .= qq~<span id="ViewIndex1" class="droppageindex" style="height: 14px; visibility: hidden;">&nbsp;</span>~;             $tstart         = $start; 
           $pagedropindex2 .= qq~<span id="ViewIndex2" class="droppageindex" style="height: 14px; visibility: hidden;">&nbsp;</span>~;             if ( substr( $INFO{'start'}, 0, 3 ) eq 'all' ) { 
           $tmpmaxmessagedisplay = $maxmessagedisplay;                 ( $tstart, $start ) = split /\-/xsm, $INFO{'start'}; 
           if (substr($INFO{'start'}, 0, 3) eq "all") { $maxmessagedisplay = $maxmessagedisplay * $dropdisplaynum; }            }
           $prevpage = $start - $tmpmaxmessagedisplay;             $d_indexpages = $pagenumb / $dropdisplaynum; 
           $nextpage = $start + $maxmessagedisplay;             $i_indexpages = int( $pagenumb / $dropdisplaynum ); 
           $pagedropindexpvbl = qq~<img src="$imagesdir/index_left0.gif" height="14" width="13" border="0" alt="" style="margin: 0px; display: inline; vertical-align: middle;" />~;             if ( $d_indexpages > $i_indexpages ) { 
           $pagedropindexnxbl = qq~<img src="$imagesdir/index_right0.gif" height="14" width="13" border="0" alt="" style="margin: 0px; display: inline; vertical-align: middle;" />~;                 $indexpages = int( $pagenumb / $dropdisplaynum ) + 1; 
           if ($start < $maxmessagedisplay) { $pagedropindexpv .= qq~<img src="$imagesdir/index_left0.gif" height="14" width="13" border="0" alt="" style="display: inline; vertical-align: middle;" />~; }            }
           else { $pagedropindexpv .= qq~<img src="$imagesdir/index_left.gif" border="0" height="14" width="13" alt="$pidtxt{'02'}" title="$pidtxt{'02'}" style="display: inline; vertical-align: middle; cursor: pointer;" onclick="location.href=\\'$scripturl?action=$action$bmesslink;start=$prevpage\\'" ondblclick="location.href=\\'$scripturl?action=$action$bmesslink;start=0\\'" />~; }            else { $indexpages = int( $pagenumb / $dropdisplaynum ) }
           if ($nextpage > $lastptn) { $pagedropindexnx .= qq~<img src="$imagesdir/index_right0.gif" border="0" height="14" width="13" alt="" style="display: inline; vertical-align: middle;" />~; }             $selectedindex = 
           else { $pagedropindexnx .= qq~<img src="$imagesdir/index_right.gif" height="14" width="13" border="0" alt="$pidtxt{'03'}" title="$pidtxt{'03'}" style="display: inline; vertical-align: middle; cursor: pointer;" onclick="location.href=\\'$scripturl?action=$action$bmesslink;start=$nextpage\\'" ondblclick="location.href=\\'$scripturl?action=$action$bmesslink;start=$lastptn\\'" />~; }               int( ( $start / $maxmessagedisplay ) / $dropdisplaynum ); 
           $pageindex1 = qq~$pagedropindex1</span>~;             if ( $pagenumb > $dropdisplaynum ) { 
           $pageindexjs = qq~                 $pagedropindex1 .= 
           <script language="JavaScript1.2" type="text/javascript">  qq~<span class="decselector"><select size="1" name="decselector1" id="decselector1" class="decselector_sel" onchange="if(this.options[this.selectedIndex].value) SelDec(this.options[this.selectedIndex].value, 'xx')">\n~; 
           <!--                 $pagedropindex2 .= 
           function SelDec(decparam, visel) {  qq~<span class="decselector"><select size="1" name="decselector2" id="decselector2" class="decselector_sel" onchange="if(this.options[this.selectedIndex].value) SelDec(this.options[this.selectedIndex].value, 'xx')">\n~; 
               splitparam = decparam.split("|");             } 
               var vistart = parseInt(splitparam[0]);             for my $i ( 0 .. ( $indexpages - 1 ) ) { 
               var viend = parseInt(splitparam[1]);                 $indexpage  = ( $i * $dropdisplaynum ) * $maxmessagedisplay; 
               var maxpag = parseInt(splitparam[2]);                 $indexstart = ( $i * $dropdisplaynum ) + 1; 
               var pagstart = parseInt(splitparam[3]);                 $indexend   = $indexstart + ( $dropdisplaynum - 1 ); 
               var allpagstart = parseInt(splitparam[3]);                 if ( $indexend > $pagenumb ) { $indexend = $pagenumb; } 
               if (visel == 'xx' && decparam == '$pagejsindex') visel = '$tstart';                 if ( $indexstart == $indexend ) { 
               var pagedropindex = '<table border="0" cellpadding="0" cellspacing="0"><tr>';                     $indxoption = qq~$indexstart~; 
               for (i=vistart; i<=viend; i++) {                 } 
                   if (visel == pagstart) pagedropindex += '<td class="titlebg" height="14" style="height: 14px; padding-left: 1px; padding-right: 1px; font-size: 9px; font-weight: bold;">' + i + '</td>';                 else { $indxoption = qq~$indexstart-$indexend~; } 
                   else pagedropindex += '<td height="14" class="droppages"><a href="$scripturl?action=$action$bmesslink;start=' + pagstart + '">' + i + '</a></td>';                 $selected = q{}; 
                   pagstart += maxpag;                 if ( $i == $selectedindex ) { 
               }                     $selected = q~ selected="selected"~; 
               ~;                     $pagejsindex = 
               if ($showpageall) {                       qq~$indexstart|$indexend|$maxmessagedisplay|$indexpage~; 
                   $pageindexjs .= qq~                 } 
                   if (vistart != viend) {                if ( $pagenumb > $dropdisplaynum ) {
                       if(visel == 'all') pagedropindex += '<td class="titlebg" height="14" style="height: 14px; padding-left: 1px; padding-right: 1px; font-size: 9px; font-weight: normal;"><b>$pidtxt{"01"}</b></td>';                     $pagedropindex1 .= 
                       else pagedropindex += '<td height="14" class="droppages"><a href="$scripturl?action=$action$bmesslink;start=all-' + allpagstart + '">$pidtxt{"01"}</a></td>';  qq~<option value="$indexstart|$indexend|$maxmessagedisplay|$indexpage"$selected>$indxoption</option>\n~; 
                   }                     $pagedropindex2 .= 
                   ~;  qq~<option value="$indexstart|$indexend|$maxmessagedisplay|$indexpage"$selected>$indxoption</option>\n~; 
               }                }
               $pageindexjs .= qq~             } 
               if (visel != 'xx') pagedropindex += '<td height="14" class="small" style="height: 14px; padding-left: 4px;">$pagedropindexpv$pagedropindexnx</td>';             if ( $pagenumb > $dropdisplaynum ) { 
               else pagedropindex += '<td height="14" class="small" style="height: 14px; padding-left: 4px;">$pagedropindexpvbl$pagedropindexnxbl</td>';                 $pagedropindex1 .= qq~</select>\n</span>~; 
               pagedropindex += '</tr></table>';                 $pagedropindex2 .= qq~</select>\n</span>~; 
               document.getElementById('ViewIndex1').innerHTML=pagedropindex;             } 
               document.getElementById('ViewIndex1').style.visibility = 'visible';             $pagedropindex1 .= 
               ~;  q~<span id="ViewIndex1" class="droppageindex viewindex_hid">&nbsp;</span>~; 
               if ($pagenumb > $dropdisplaynum) {             $pagedropindex2 .= 
               $pageindexjs .= qq~  q~<span id="ViewIndex2" class="droppageindex viewindex_hid">&nbsp;</span>~; 
               document.getElementById('decselector1').value = decparam;             $tmpmaxmessagedisplay = $maxmessagedisplay; 
               ~;             if ( substr( $INFO{'start'}, 0, 3 ) eq 'all' ) { 
           }                 $maxmessagedisplay = $maxmessagedisplay * $dropdisplaynum; 
           $pageindexjs .= qq~             } 
       }             $prevpage = $start - $tmpmaxmessagedisplay; 
       SelDec('$pagejsindex', '$tstart');             $nextpage = $start + $maxmessagedisplay; 
       //-->             $pagedropindexpvbl = 
       </script>  qq~<img src="$index_togl{'index_left0'}" height="14" width="13" alt="" />~; 
       ~;             $pagedropindexnxbl = 
       }  qq~<img src="$index_togl{'index_right0'}" height="14" width="13" alt="" />~; 
   }             if ( $start < $maxmessagedisplay ) { 
                 $pagedropindexpv .=
  qq~<img src="$index_togl{'index_left0'}" height="14" width="13" alt="" />~;
             }
             else {
                 $pagedropindexpv .=
  qq~<img src="$index_togl{'index_left'}" height="14" width="13" alt="$pidtxt{'02'}" title="$pidtxt{'02'}" class="cursor" onclick="location.href=\\'$scripturl?action=$action$bmesslink;start=$prevpage\\'" ondblclick="location.href=\\'$scripturl?action=$action$bmesslink;start=0\\'" />~;
             }
             if ( $nextpage > $lastptn ) {
                 $pagedropindexnx .=
  qq~<img src="$index_togl{'index_right0'}" height="14" width="13" alt="" />~;
             }
             else {
                 $pagedropindexnx .=
  qq~<img src="$index_togl{'index_right'}" height="14" width="13" alt="$pidtxt{'03'}" title="$pidtxt{'03'}" class="cursor"" onclick="location.href=\\'$scripturl?action=$action$bmesslink;start=$nextpage\\'" ondblclick="location.href=\\'$scripturl?action=$action$bmesslink;start=$lastptn\\'" />~;
             }
             $pageindex1  = qq~$pagedropindex1</span>~;
             $pageindexjs = qq~
             <script type="text/javascript">
             function SelDec(decparam, visel) {
                 splitparam = decparam.split("|");
                 var vistart = parseInt(splitparam[0]);
                 var viend = parseInt(splitparam[1]);
                 var maxpag = parseInt(splitparam[2]);
                 var pagstart = parseInt(splitparam[3]);
                 var allpagstart = parseInt(splitparam[3]);
                 if (visel == 'xx' && decparam == '$pagejsindex') visel = '$tstart';
                 var pagedropindex = '$visel_0';
                 for (i=vistart; i<=viend; i++) {
                     if (visel == pagstart) pagedropindex += '$visel_1a<b>' + i + '</b>$visel_1b';
                     else pagedropindex += '$visel_2a<a href="$scripturl?action=$action$bmesslink;start=' + pagstart + '">' + i + '</a>$visel_1b';
                     pagstart += maxpag;
                 }
                 ~;
             if ($showpageall) {
                 $pageindexjs .= qq~
                     if (vistart != viend) {
                         if(visel == 'all') pagedropindex += '$visel_1a<b>$pidtxt{"01"}</b></td>';
                         else pagedropindex += '$visel_2a<a href="$scripturl?action=$action$bmesslink;start=all-' + allpagstart + '">$pidtxt{"01"}</a>$visel_1b';
                     }
                     ~;
             }
             $pageindexjs .= qq~
                 if (visel != 'xx') pagedropindex += '$visel_3a$pagedropindexpv$pagedropindexnx$visel_1b';
                 else pagedropindex += '$visel_3a$pagedropindexpvbl$pagedropindexnxbl$visel_1b';
                 pagedropindex += '$visel_4';
                 document.getElementById('ViewIndex1').innerHTML=pagedropindex;
                 document.getElementById('ViewIndex1').style.visibility = 'visible';
                 ~;
             if ( $pagenumb > $dropdisplaynum ) {
                 $pageindexjs .= q~
                 document.getElementById('decselector1').value = decparam;
                 ~;
             }
             $pageindexjs .= qq~
         }
         SelDec('$pagejsindex', '$tstart');
         </script>
         ~;
         }
     }
     return;
} }
   
##  output one or all IM - detailed view ##  output one or all IM - detailed view
sub DoShowIM { sub DoShowIM {
   $messfound = 0;     my ($inp) = @_; 
   if ($callerid < 5) { &updateIMS($username, $_[0], 'inread'); }     $messfound = 0; 
     if ( $callerid < 5 ) { updateIMS( $username, $inp, 'inread' ); }
   my ($showIM, $fromTitle, $toTitle, $toTitleCC, $toTitleBCC, $usernamelinkfrom, $usernamelinkto, $usernamelinkcc, $usernamelinkbcc, $userOnline, $prevMessId, $nextMessid, $PMnav);  
   $messcount = 0;     my ( 
   foreach my $messagesim (@dimmessages) {         $showIM,           $fromTitle,      $toTitle, 
       $nextMessid = $messageid;         $toTitleCC,        $toTitleBCC,     $usernamelinkfrom, 
       ($messageid, $musername, $mtousers, $mccusers, $mbccusers, $msub, $mdate, $immessage, $mpmessageid, $mreplyno, $imip, $mstatus, $mflags, $mstorefolder, $mattach) = split(/\|/, $messagesim);         $usernamelinkto,   $usernamelinkcc, $usernamelinkbcc, 
       $messcount++;         $prevMessId,       $nextMessid,     $PMnav, 
       if ($messageid == $_[0]) { $messfound = 1; last; }         $attachDeleteWarn, $pmAttachment,   $pmShowAttach, 
   }         %attach_gif 
     );
   if (!$messfound) {     $messcount = 0; 
       my $redirect;     foreach my $messagesim (@dimmessages) { 
       if ($INFO{'caller'} == 1) { $redirect = 'im'; }         $nextMessid = $messageid; 
       elsif ($INFO{'caller'} == 2) { $redirect = 'imoutbox'; }         ( 
       elsif ($INFO{'caller'} == 3) { $redirect = 'imstorage'; }             $messageid,   $musername,    $mtousers, $mccusers, 
       elsif ($INFO{'caller'} == 4) { $redirect = 'imdraft'; }             $mbccusers,   $msub,         $mdate,    $immessage, 
       elsif ($INFO{'caller'} == 5) { $redirect = 'im;focus=bmess'; }             $mpmessageid, $mreplyno,     $imip,     $mstatus, 
       $yySetLocation = qq~$scripturl?action=$redirect~;             $mflags,      $mstorefolder, $mattach, 
       &redirectexit;         ) = split /\|/xsm, $messagesim; 
   }         $messcount++; 
         if ( $messageid == $inp ) { $messfound = 1; last; }
   ## if not at the end of the list, catch the 'previoous' id     } 
   if ($messcount <= $#dimmessages){  
       ($prevMessId, undef) = split(/\|/, $dimmessages[$messcount]);     if ( !$messfound ) { 
   }         my $redirect; 
   ## wrap the URL in         my @redrect = 
   if ($INFO{'id'} ne 'all' && $prevMessId ne '') { $previd = qq~&laquo; <a href="$scripturl?action=imshow;caller=$INFO{'caller'};id=$prevMessId">$inmes_imtxt{'40'}</a>~; }           ( q{}, 'im', 'imoutbox', 'imstorage', 'imdraft', 'im;focus=bmess', ); 
   if ($INFO{'id'} ne 'all' && $nextMessid ne '') { $nextid = qq~<a href="$scripturl?action=imshow;caller=$INFO{'caller'};id=$nextMessid">$inmes_imtxt{'41'}</a> &raquo;~; }  
   if ($INFO{'id'} ne 'all' && $#dimmessages > 0) { $allid = qq~<a href="$scripturl?action=imshow;caller=$INFO{'caller'};id=all">$inmes_txt{'190'}</a>~; }         foreach my $i ( 1 .. 5 ) { 
             if ( $INFO{'caller'} == $i + 1 ) {
   my $mydate = &timeformat($mdate);                 $redirect = $redrect[$i]; 
   if ($INFO{'caller'} == 1) {             } 
       if ($mtousers) {         } 
           foreach my $uname (split(/,/, $mtousers)) {         $yySetLocation = qq~$scripturl?action=$redirect~; 
               &LoadValidUserDisplay($uname);         redirectexit(); 
               $usernamelinkto .= (${$uid.$uname}{'realname'} ? &CreateUserDisplayLine($uname) : ($uname ? qq~$uname ($maintxt{'470a'})~ : $maintxt{'470a'})) . ', '; # 470a == Ex-Member     } 
           }  
           $usernamelinkto =~ s/, $//;     ## if not at the end of the list, catch the 'previous' id 
           $toTitle = qq~$inmes_txt{'324'}:~;     if ( $messcount <= $#dimmessages ) { 
       }         ( $prevMessId, undef ) = split /\|/xsm, $dimmessages[$messcount]; 
       if ($mccusers) {     } 
           foreach my $uname (split(/,/, $mccusers)) {     ## wrap the URL in 
               &LoadValidUserDisplay($uname);     if ( $INFO{'id'} ne 'all' && $prevMessId ne q{} ) { 
               $usernamelinkcc .= (${$uid.$uname}{'realname'} ? &CreateUserDisplayLine($uname) : ($uname ? qq~$uname ($maintxt{'470a'})~ : $maintxt{'470a'})) . ', ';         $previd = 
           }  qq~&laquo; <a href="$scripturl?action=imshow;caller=$INFO{'caller'};id=$prevMessId">$inmes_imtxt{'40'}</a>~; 
           $usernamelinkcc =~ s/, $//;     } 
           $toTitleCC = qq~$inmes_txt{'325'}:~;     if ( $INFO{'id'} ne 'all' && $nextMessid ne q{} ) { 
       }         $nextid = 
       if ($mbccusers) {  qq~<a href="$scripturl?action=imshow;caller=$INFO{'caller'};id=$nextMessid">$inmes_imtxt{'41'}</a> &raquo;~; 
           foreach my $uname (split(/,/, $mbccusers)) {     } 
               if ($uname eq $username) {    if ( $INFO{'id'} ne 'all' && $#dimmessages > 0 ) {
                   &LoadValidUserDisplay($uname);         $allid = 
                   $usernamelinkbcc = ${$uid.$uname}{'realname'} ? &CreateUserDisplayLine($uname) : ($uname ? qq~$uname ($maintxt{'470a'})~ : $maintxt{'470a'});  qq~<a href="$scripturl?action=imshow;caller=$INFO{'caller'};id=all">$inmes_txt{'190'}</a>~; 
               }    }
           }  
           if ($usernamelinkbcc) {     my $mydate = timeformat( $mdate, 0, 0, 0, 1 ); 
               $toTitleBCC = qq~$inmes_txt{'326'}:~;     if ( $INFO{'caller'} == 1 ) { 
           }         if ($mtousers) { 
       }             foreach my $uname ( split /,/xsm, $mtousers ) { 
                 LoadValidUserDisplay($uname);
       if ($mstatus eq 'g') {                 $usernamelinkto .= ( 
           my ($guestName, $guestEmail) = split(/ /, $musername);                     ${ $uid . $uname }{'realname'} 
           $guestName =~ s/%20/ /g;                     ? CreateUserDisplayLine($uname) 
           $usernamelinkfrom = qq~$guestName (<a href="mailto:$guestEmail">$guestEmail</a>)~;                     : ( 
       } else {                           $uname ? qq~$uname ($maintxt{'470a'})~ 
           &LoadValidUserDisplay($musername);                         : $maintxt{'470a'} 
           $usernamelinkfrom = ${$uid.$musername}{'realname'} ? &CreateUserDisplayLine($musername) : ($musername ? qq~$musername ($maintxt{'470a'})~ : $maintxt{'470a'}); # 470a == Ex-Member                     ) 
       }                 ) . q{, };    # 470a == Ex-Member 
       $fromTitle = qq~$inmes_txt{'318'}:~;             } 
             $usernamelinkto =~ s/, $//sm;
   } elsif ($INFO{'caller'} == 2) {             $toTitle = qq~$inmes_txt{'324'}:~; 
       &LoadValidUserDisplay($musername);         } 
       $usernamelinkfrom = ${$uid.$musername}{'realname'} ? &CreateUserDisplayLine($musername) : ($musername ? qq~$musername ($maintxt{'470a'})~ : $maintxt{'470a'}); # 470a == Ex-Member         if ($mccusers) { 
       $fromTitle = qq~$inmes_txt{'318'}:~;             foreach my $uname ( split /,/xsm, $mccusers ) { 
                 LoadValidUserDisplay($uname);
       if ($mstatus !~ /b/) {                 $usernamelinkcc .= ( 
           if ($mstatus !~ /gr/) {                     ${ $uid . $uname }{'realname'} 
               foreach my $uname (split(/,/, $mtousers)) {                     ? CreateUserDisplayLine($uname) 
                   &LoadValidUserDisplay($uname);                     : ( 
                   $usernamelinkto .= (${$uid.$uname}{'realname'} ? &CreateUserDisplayLine($uname) : ($uname ? qq~$uname ($maintxt{'470a'})~ : $maintxt{'470a'})) . ', '; # 470a == Ex-Member                           $uname ? qq~$uname ($maintxt{'470a'})~ 
               }                         : $maintxt{'470a'} 
           } else {                     ) 
               my ($guestName, $guestEmail) = split(/ /, $mtousers);                 ) . q{, }; 
               $guestName =~ s/%20/ /g;             } 
               $usernamelinkto = qq~$guestName (<a href="mailto:$guestEmail">$guestEmail</a>)~;             $usernamelinkcc =~ s/, $//sm; 
           }             $toTitleCC = qq~$inmes_txt{'325'}:~; 
           $toTitle = qq~$inmes_txt{'324'}:~;         } 
       } else {        if ($mbccusers) {
           foreach my $uname (split(/,/, $mtousers)) {            foreach my $uname ( split /,/xsm, $mbccusers ) {
               if ($uname eq 'all') { $usernamelinkto .= qq~<b>$inmes_txt{'bmallmembers'}</b>~ . ', ';                 if ( $uname eq $username ) { 
               } elsif ($uname eq 'mods') { $usernamelinkto .= qq~<b>$inmes_txt{'bmmods'}</b>~ . ', ';                     LoadValidUserDisplay($uname); 
               } elsif ($uname eq 'gmods') { $usernamelinkto .= qq~<b>$inmes_txt{'bmgmods'}</b>~ . ', ';                     $usernamelinkbcc = 
               } elsif ($uname eq 'admins') { $usernamelinkto .= qq~<b>$inmes_txt{'bmadmins'}</b>~ . ', ';                       ${ $uid . $uname }{'realname'} 
               } else {                       ? CreateUserDisplayLine($uname) 
                   my ($title, undef) = split(/\|/, $NoPost{$uname}, 2);                       : ( 
                   $usernamelinkto .= qq~<b>$title</b>~ . ', ';                           $uname ? qq~$uname ($maintxt{'470a'})~ 
               }                         : $maintxt{'470a'} 
           }                       ); 
           $toTitle = qq~$inmes_txt{'324'} $inmes_txt{'327'}:~;                 } 
       }            }
       $usernamelinkto =~ s/, $//;             if ($usernamelinkbcc) { 
       if ($mccusers) {                 $toTitleBCC = qq~$inmes_txt{'326'}:~; 
           foreach my $uname (split(/,/, $mccusers)) {             } 
               &LoadValidUserDisplay($uname);         } 
               $usernamelinkcc .= (${$uid.$uname}{'realname'} ? &CreateUserDisplayLine($uname) : ($uname ? qq~$uname ($maintxt{'470a'})~ : $maintxt{'470a'})) . ', '; # 470a == Ex-Member  
           }         if ( $mstatus eq 'g' || $mstatus eq 'ga' ) { 
           $usernamelinkcc =~ s/, $//;             my ( $guestName, $guestEmail ) = split / /sm, $musername; 
           $toTitleCC = qq~$inmes_txt{'325'}:~;             $guestName =~ s/%20/ /gsm; 
       }             $usernamelinkfrom = 
       if ($mbccusers) {               qq~$guestName (<a href="mailto:$guestEmail">$guestEmail</a>)~; 
           foreach my $uname (split(/,/, $mbccusers)) {         } 
               &LoadValidUserDisplay($uname);         else { 
               $usernamelinkbcc .= (${$uid.$uname}{'realname'} ? &CreateUserDisplayLine($uname) : ($uname ? qq~$uname ($maintxt{'470a'})~ : $maintxt{'470a'})) . ', '; # 470a == Ex-Member             LoadValidUserDisplay($musername); 
           }             $usernamelinkfrom = 
           $usernamelinkbcc =~ s/, $//;               ${ $uid . $musername }{'realname'} 
           $toTitleBCC = qq~$inmes_txt{'326'}:~;               ? CreateUserDisplayLine($musername) 
       }               : ( 
                   $musername ? qq~$musername ($maintxt{'470a'})~
   } elsif ($INFO{'caller'} == 3) {                 : $maintxt{'470a'} 
       if ($mstatus !~ /b/) {               );    # 470a == Ex-Member 
           if ($mstatus !~ /gr/) {         } 
               foreach my $uname (split(/,/, $mtousers)) {         $fromTitle = qq~$inmes_txt{'318'}:~; 
                   &LoadValidUserDisplay($uname);  
                   $usernamelinkto .= (${$uid.$uname}{'realname'} ? &CreateUserDisplayLine($uname) : ($uname ? qq~$uname ($maintxt{'470a'})~ : $maintxt{'470a'})) . ', '; # 470a == Ex-Member     } 
               }     elsif ( $INFO{'caller'} == 2 ) { 
           } else {         LoadValidUserDisplay($musername); 
               my ($guestName, $guestEmail) = split(/ /, $mtousers);         $usernamelinkfrom = 
               $guestName =~ s/%20/ /g;           ${ $uid . $musername }{'realname'} 
               $usernamelinkto = qq~$guestName (<a href="mailto:$guestEmail">$guestEmail</a>)~;           ? CreateUserDisplayLine($musername) 
           }           : ( 
           $toTitle = qq~$inmes_txt{'324'}:~;             $musername ? qq~$musername ($maintxt{'470a'})~ : $maintxt{'470a'} ); 
           if ($mccusers && $musername eq $username) {  
               foreach my $uname (split(/,/, $mccusers)) {         # 470a == Ex-Member 
                   &LoadValidUserDisplay($uname);         $fromTitle = qq~$inmes_txt{'318'}:~; 
                   $usernamelinkcc .= (${$uid.$uname}{'realname'} ? &CreateUserDisplayLine($uname) : ($uname ? qq~$uname ($maintxt{'470a'})~ : $maintxt{'470a'})) . ', '; # 470a == Ex-Member  
               }         if ( $mstatus !~ /b/sm ) { 
               $usernamelinkcc =~ s/, $//;             if ( $mstatus !~ /gr/sm ) { 
               $toTitleCC = qq~$inmes_txt{'325'}:~;                 foreach my $uname ( split /,/xsm, $mtousers ) { 
           }                     LoadValidUserDisplay($uname); 
           if ($mbccusers && $musername eq $username) {                     $usernamelinkto .= ( 
               foreach my $uname (split(/,/, $mbccusers)) {                         ${ $uid . $uname }{'realname'} 
                   &LoadValidUserDisplay($uname);                         ? CreateUserDisplayLine($uname) 
                   $usernamelinkbcc .= (${$uid.$uname}{'realname'} ? &CreateUserDisplayLine($uname) : ($uname ? qq~$uname ($maintxt{'470a'})~ : $maintxt{'470a'})) . ', '; # 470a == Ex-Member                         : ( 
               }                               $uname ? qq~$uname ($maintxt{'470a'})~ 
               $usernamelinkbcc =~ s/, $//;                             : $maintxt{'470a'} 
               $toTitleBCC = qq~$inmes_txt{'326'}:~;                         ) 
           }                     ) . q{, };    # 470a == Ex-Member 
       } else {                 } 
           foreach my $uname (split(/,/, $mtousers)) {             } 
               if ($uname eq 'all') { $usernamelinkto .= qq~<b>$inmes_txt{'bmallmembers'}</b>~ . ', ';             else { 
               } elsif ($uname eq 'mods') { $usernamelinkto .= qq~<b>$inmes_txt{'bmmods'}</b>~ . ', ';                 my ( $guestName, $guestEmail ) = split / /sm, $mtousers; 
               } elsif ($uname eq 'gmods') { $usernamelinkto .= qq~<b>$inmes_txt{'bmgmods'}</b>~ . ', ';                 $guestName =~ s/%20/ /gsm; 
               } elsif ($uname eq 'admins') { $usernamelinkto .= qq~<b>$inmes_txt{'bmadmins'}</b>~ . ', ';                 $usernamelinkto = 
               } else {                   qq~$guestName (<a href="mailto:$guestEmail">$guestEmail</a>)~; 
                   my ($title, undef) = split(/\|/, $NoPost{$uname}, 2);             } 
                   $usernamelinkto .= qq~<b>$title</b>~ . ', ';             $toTitle = qq~$inmes_txt{'324'}:~; 
               }        }
           }         else { 
           $toTitle = qq~$inmes_txt{'324'} $inmes_txt{'327'}:~;             foreach my $uname ( split /,/xsm, $mtousers ) { 
       }                 $usernamelinkto .= links_to($uname); 
       $usernamelinkto =~ s/, $//;             } 
             $toTitle = qq~$inmes_txt{'324'} $inmes_txt{'327'}:~;
       if ($mstatus eq 'g') {         } 
           my ($guestName, $guestEmail) = split(/ /, $musername);         $usernamelinkto =~ s/, $//sm; 
           $guestName =~ s/%20/ /g;         if ($mccusers) { 
           $usernamelinkfrom = qq~$guestName (<a href="mailto:$guestEmail">$guestEmail</a>)~;             foreach my $uname ( split /,/xsm, $mccusers ) { 
       } else {                 LoadValidUserDisplay($uname); 
           &LoadValidUserDisplay($musername);                 $usernamelinkcc .= ( 
           $usernamelinkfrom = ${$uid.$musername}{'realname'} ? &CreateUserDisplayLine($musername) : ($musername ? qq~$musername ($maintxt{'470a'})~ : $maintxt{'470a'}); # 470a == Ex-Member                     ${ $uid . $uname }{'realname'} 
       }                     ? CreateUserDisplayLine($uname) 
       $fromTitle = qq~$inmes_txt{'318'}:~;                     : ( 
                           $uname ? qq~$uname ($maintxt{'470a'})~
   } elsif ($INFO{'caller'} == 5 && $mstatus eq 'g') {                         : $maintxt{'470a'} 
       my ($guestName, $guestEmail) = split(/ /, $musername);                     ) 
       $guestName =~ s/%20/ /g;                 ) . q{, };    # 470a == Ex-Member 
       $usernamelinkfrom = qq~$guestName (<a href="mailto:$guestEmail">$guestEmail</a>)~;             } 
       $fromTitle = qq~$inmes_txt{'318'}:~;             $usernamelinkcc =~ s/, $//sm; 
             $toTitleCC = qq~$inmes_txt{'325'}:~;
   } elsif ($INFO{'caller'} == 5 && $mstatus =~ /b/) {         } 
       if ($mtousers) {        if ($mbccusers) {
           foreach my $uname (split(/,/, $mtousers)) {            foreach my $uname ( split /,/xsm, $mbccusers ) {
               if ($uname eq 'all') { $usernamelinkto .= qq~<b>$inmes_txt{'bmallmembers'}</b>~ . ', ';                 LoadValidUserDisplay($uname); 
               } elsif ($uname eq 'mods') { $usernamelinkto .= qq~<b>$inmes_txt{'bmmods'}</b>~ . ', ';                 $usernamelinkbcc .= ( 
               } elsif ($uname eq 'gmods') { $usernamelinkto .= qq~<b>$inmes_txt{'bmgmods'}</b>~ . ', ';                     ${ $uid . $uname }{'realname'} 
               } elsif ($uname eq 'admins') { $usernamelinkto .= qq~<b>$inmes_txt{'bmadmins'}</b>~ . ', ';                     ? CreateUserDisplayLine($uname) 
               } else {                     : ( 
                   my ($title, undef) = split(/\|/, $NoPost{$uname}, 2);                           $uname ? qq~$uname ($maintxt{'470a'})~ 
                   $usernamelinkto .= qq~<b>$title</b>~ . ', ';                         : $maintxt{'470a'} 
               }                     ) 
           }                 ) . q{, };    # 470a == Ex-Member 
           $usernamelinkto =~ s/, $//;             } 
           $toTitle = qq~$inmes_txt{'324'} $inmes_txt{'327'}:~;             $usernamelinkbcc =~ s/, $//sm; 
       }             $toTitleBCC = qq~$inmes_txt{'326'}:~; 
         }
       &LoadValidUserDisplay($musername);     } 
       $usernamelinkfrom = ${$uid.$musername}{'realname'} ? &CreateUserDisplayLine($musername) : ($musername ? qq~$musername ($maintxt{'470a'})~ : $maintxt{'470a'}); # 470a == Ex-Member     elsif ( $INFO{'caller'} == 3 ) { 
         if ( $mstatus !~ /b/sm ) {
       $fromTitle = qq~$inmes_txt{'318'}:~;             if ( $mstatus !~ /gr/sm ) { 
   }                 foreach my $uname ( split /,/xsm, $mtousers ) { 
                     LoadValidUserDisplay($uname);
   $PMnav = &buildPMNavigator;                     $usernamelinkto .= ( 
                         ${ $uid . $uname }{'realname'}
   &ToChars($msub);                         ? CreateUserDisplayLine($uname) 
   $msub = &Censor($msub);                         : ( 
                               $uname ? qq~$uname ($maintxt{'470a'})~
   $message = $immessage;                             : $maintxt{'470a'} 
   &wrap;                         ) 
   if ($enable_ubbc) {                     ) . q{, };    # 470a == Ex-Member 
       if (!$yyYaBBCloaded) { require "$sourcedir/YaBBC.pl"; }                }
       &DoUBBC;             } 
   }             else { 
   &wrap2;                 my ( $guestName, $guestEmail ) = split / /sm, $mtousers; 
   &ToChars($message);                 $guestName =~ s/%20/ /gsm; 
   $message = &Censor($message);                 $usernamelinkto = 
                   qq~$guestName (<a href="mailto:$guestEmail">$guestEmail</a>)~;
   $avstyle = '';             } 
             $toTitle = qq~$inmes_txt{'324'}:~;
   $showIM = qq~             if ( $mccusers && $musername eq $username ) { 
<table border="0" width="100%" cellspacing="1" cellpadding="1" class="bordercolor" style="table-layout: fixed">                 foreach my $uname ( split /,/xsm, $mccusers ) { 
<tr>                     LoadValidUserDisplay($uname); 
   <td class="windowbg" align="left" valign="top" colspan="2">                     $usernamelinkcc .= ( 
       <div style="width: 99%; padding: 2px; margin: 2px;">                         ${ $uid . $uname }{'realname'} 
   ~;                         ? CreateUserDisplayLine($uname) 
                         : (
   if ($fromTitle) {                               $uname ? qq~$uname ($maintxt{'470a'})~ 
       $showIM .= qq~                             : $maintxt{'470a'} 
       <span class="small" style="width: 99%;">                         ) 
       <b>$fromTitle</b> $usernamelinkfrom                     ) . q{, };    # 470a == Ex-Member 
       </span><br />                 } 
       ~;                 $usernamelinkcc =~ s/, $//sm; 
   }                 $toTitleCC = qq~$inmes_txt{'325'}:~; 
             }
   if ($toTitle) {            if ( $mbccusers && $musername eq $username ) {
       $showIM .= qq~                 foreach my $uname ( split /,/xsm, $mbccusers ) { 
       <span class="small" style="width: 99%;">                     LoadValidUserDisplay($uname); 
       <b>$toTitle</b> $usernamelinkto                     $usernamelinkbcc .= ( 
       </span><br />                         ${ $uid . $uname }{'realname'} 
       ~;                         ? CreateUserDisplayLine($uname) 
   }                         : ( 
                               $uname ? qq~$uname ($maintxt{'470a'})~
   if ($toTitleCC) {                             : $maintxt{'470a'} 
       $showIM .= qq~                         ) 
       <span class="small" style="width: 99%;">                     ) . q{, };    # 470a == Ex-Member 
       <b>$toTitleCC</b> $usernamelinkcc                 } 
       </span><br />                 $usernamelinkbcc =~ s/, $//sm; 
       ~;                 $toTitleBCC = qq~$inmes_txt{'326'}:~; 
   }            }
         }
   if ($toTitleBCC) {        else {
       $showIM .= qq~             foreach my $uname ( split /,/xsm, $mtousers ) { 
       <span class="small" style="width: 99%;">                 $usernamelinkto .= links_to($uname); 
       <b>$toTitleBCC</b> $usernamelinkbcc             } 
       </span><br />             $toTitle = qq~$inmes_txt{'324'} $inmes_txt{'327'}:~; 
       ~;         } 
   }         $usernamelinkto =~ s/, $//sm; 
   
   $showIM .= qq~         if ( $mstatus eq 'g' || $mstatus eq 'ga' ) { 
       </div>             my ( $guestName, $guestEmail ) = split / /sm, $musername; 
   </td>             $guestName =~ s/%20/ /gsm; 
</tr>             $usernamelinkfrom = 
<tr>               qq~$guestName (<a href="mailto:$guestEmail">$guestEmail</a>)~; 
   <td class="windowbg2" align="left" valign="top" colspan="2">         } 
       <div style="width: 99%; padding: 2px; margin: 2px;">         else { 
       <span class="small" style="width: 99%;">             LoadValidUserDisplay($musername); 
       <b>$inmes_txt{'70'}: $msub</b><br />             $usernamelinkfrom = 
       <b>$inmes_txt{'317'}:</b> $mydate               ${ $uid . $musername }{'realname'} 
       </span>               ? CreateUserDisplayLine($musername) 
       </div>               : ( 
   </td>                   $musername ? qq~$musername ($maintxt{'470a'})~ 
</tr>                 : $maintxt{'470a'} 
<tr>               );    # 470a == Ex-Member 
   <td class="windowbg2" align="left" valign="top" colspan="2">         } 
       <div style="width: 99%; padding: 2px; margin: 2px;">         $fromTitle = qq~$inmes_txt{'318'}:~; 
       <span class="message" style="float: left; width: 99%; overflow: auto; padding-bottom: 10px; margin-bottom: 10px;">  
       $message     } 
       </span>     elsif ( $INFO{'caller'} == 5 && ( $mstatus eq 'g' || $mstatus eq 'ga' ) ) { 
       </div>         my ( $guestName, $guestEmail ) = split / /sm, $musername; 
   </td>         $guestName =~ s/%20/ /gsm; 
</tr>         $usernamelinkfrom = 
~;           qq~$guestName (<a href="mailto:$guestEmail">$guestEmail</a>)~; 
         $fromTitle = qq~$inmes_txt{'318'}:~;
   
     }
     elsif ( $INFO{'caller'} == 5 && $mstatus =~ /b/sm ) {
         if ($mtousers) {
             foreach my $uname ( split /,/xsm, $mtousers ) {
                 $usernamelinkto .= links_to($uname);
             }
             $usernamelinkto =~ s/, $//sm;
             $toTitle = qq~$inmes_txt{'324'} $inmes_txt{'327'}:~;
         }
   
         LoadValidUserDisplay($musername);
         $usernamelinkfrom =
           ${ $uid . $musername }{'realname'}
           ? CreateUserDisplayLine($musername)
           : (
             $musername ? qq~$musername ($maintxt{'470a'})~ : $maintxt{'470a'} );
   
         # 470a == Ex-Member
   
         $fromTitle = qq~$inmes_txt{'318'}:~;
     }
   
     $PMnav = buildPMNavigator();
   
     ToChars($msub);
     $msub = Censor($msub);
   
     $message = $immessage;
     wrap();
     if ($enable_ubbc) {
         enable_yabbc();
         DoUBBC();
     }
     wrap2();
     ToChars($message);
     $message = Censor($message);
   
     $avstyle  = q{};
     $my_title = q{};
     $my_sig   = q{};
     if ($fromTitle) {
         $my_title = qq~
         <span class="small totitle">
         <b>$fromTitle</b> $usernamelinkfrom
         </span><br />
         ~;
     }
   
     if ($toTitle) {
         $my_title .= qq~
         <span class="small totitle">
         <b>$toTitle</b> $usernamelinkto
         </span><br />
         ~;
     }
   
     if ($toTitleCC) {
         $my_title .= qq~
         <span class="small totitle">
         <b>$toTitleCC</b> $usernamelinkcc
         </span><br />
         ~;
     }
   
     if ($toTitleBCC) {
         $my_title .= qq~
         <span class="small totitle">
         <b>$toTitleBCC</b> $usernamelinkbcc
         </span><br />
         ~;
     }
     if ( $mstatus ne 'ga' && $mstatus ne 'g' && $signature ) {
         $my_sig = $show_my_sig;
         $my_sig =~ s/{yabb signature}/$signature/sm;
     }
   
     # Do we have an attachment file?
     chomp $mattach;
     if ( $mattach ne q{} ) {
         foreach ( split /,/xsm, $mattach ) {
             my ( $pmAttachFile, undef ) = split /~/xsm, $_;
             if ( $pmAttachFile =~ /\.(.+?)$/xsm ) {
                 $ext = lc $1;
             }
             if ( !exists $attach_gif{$ext} ) {
                 $attach_gif{$ext} =
                   ( $ext && -e "$htmldir/Templates/Forum/$useimages/$ext.gif" )
                   ? "$imagesdir/$ext.gif" 
                   : "$micon_bg{'paperclip'}";
             }
             my $filesize = -s "$pmuploaddir/$pmAttachFile";
             if ($filesize) {
                 if (   $pmAttachFile =~ /\.(bmp|jpe|jpg|jpeg|gif|png)$/ixsm
                     && $pmDisplayPics == 1 )
                 {
                     $pmShowAttach .=
  qq~<div class="small attbox"><a href="$pmuploadurl/$pmAttachFile" target="_blank"><img src="$attach_gif{$ext}" class="bottom" alt="" /> $pmAttachFile</a> (~
                       . int( $filesize / 1024 )
                       . q~ KB)<br />~
                       . (
                         $img_greybox
                         ? (
                             $img_greybox == 2
                             ? qq~<a href="$pmuploadurl/$pmAttachFile" data-rel="gb_imageset[nice_pics]" title="$pmAttachFile">~
                             : qq~<a href="$pmuploadurl/$pmAttachFile" data-rel="gb_image[nice_pics]" title="$pmAttachFile">~
                           )
                         : qq~<a href="$pmuploadurl/$pmAttachFile" target="_blank">~
                       )
                       . qq~<img src="$pmuploadurl/$pmAttachFile" name="attach_img_resize" alt="$pmAttachFile" title="$pmAttachFile" style="display:none" /></a></div>\n~;
                 }
                 else {
                     $pmAttachment .=
  qq~<div class="small"><a href="$pmuploadurl/$pmAttachFile"><img src="$attach_gif{$ext}" class="bottom" alt="" /> $pmAttachFile</a> (~
                       . int( $filesize / 1024 )
                       . q~ KB)</div>~;
                 }
             }
             else {
                 $pmAttachment .=
  qq~<div class="small"><img src="$attach_gif{$ext}" class="bottom" alt="" />  $pmAttachFile ($fatxt{'1'})</div>~;
             }
         }
         if ( $pmShowAttach && $pmAttachment ) {
             $pmAttachment =~
               s/<div class="small">/<div class="small attbox_b">/gsm;
         }
         $my_attach .= $show_my_attach;
         $my_attach =~ s/{yabb pmAttachment}/$pmAttachment/sm;
         $my_attach =~ s/{yabb pmShowAttach}/$pmShowAttach/sm;
     }
   
     my $lookupIP =
       ($ipLookup)
       ? qq~<a href="$scripturl?action=iplookup;ip=$imip">$imip</a>~
       : qq~$imip~;
     if ( $iamadmin || $iamgmod && $gmod_access2{'ipban2'} eq 'on' ) {
         $imip = $lookupIP;
     }
     else { $imip = $inmes_txt{'511'}; }
   
     my $postMenuTemp = q{};
     if ( $mstatus ne 'ga' && $mstatus ne 'g' ) {
         $postMenuTemp = $sendEmail . $sendPM . $membAdInfo . '&nbsp;';
         $postMenuTemp =~ s/\Q$menusep//ism;
     }
   
     $mreplyno++;
     $showIM_link = q{};
     if (   $INFO{'caller'} == 1
         || ( $INFO{'caller'} == 3 && $musername ne q{} )
         || ( $INFO{'caller'} == 5 && $musername ne q{} ) )
     {    ## inbox / stored inbox can reply/quote
         if ( $mstatus eq 'g' || $mstatus eq 'ga' ) {
             $showIM_link .=
  qq~<a href="$scripturl?action=imsend;caller=$INFO{'caller'};quote=$mreplyno;replyguest=1;id=$messageid">$img{'reply_ims'}</a>~;
         }
         else {
             $showIM_link .= qq~
             <a href="$scripturl?action=imsend;caller=$INFO{'caller'};quote=$mreplyno;to=$useraccount{$musername};id=$messageid">$img{'quote'}</a>$menusep
             <a href="$scripturl?action=imsend;caller=$INFO{'caller'};reply=$mreplyno;to=$useraccount{$musername};id=$messageid">$img{'reply_ims'}</a>$menusep~;
         }
     }
   
     if ( $INFO{'caller'} != 5 && $mstatus ne 'ga' && $mstatus ne 'g' ) {
         $showIM_link .= qq~
             <a href="$scripturl?action=imsend;caller=$INFO{'caller'};quote=$mreplyno;forward=1;id=$messageid">$img{'forward'}</a>$menusep~;
     }
   
     if ( $INFO{'caller'} != 5
         || ( $INFO{'caller'} == 5 && ( $iamadmin || $username eq $musername ) )
       )
     {
         chomp $mattach;
         if (   $INFO{'caller'} == 2
             || $INFO{'caller'} == 3
             || $INFO{'caller'} == 5 && $mattach ne q{} )
         {
             foreach ( split /,/xsm, $mattach ) {
                 my ( $pmAttachFile, $pmAttachUser ) = split /~/xsm, $_;
                 if ( $username eq $pmAttachUser
                     && -e "$pmuploaddir/$pmAttachFile" )
                 {
                     $attachDeleteWarn = $inmes_txt{'770a'};
                 }
             }
         }
         $showIM_link .= qq~
             <a href="$scripturl?action=deletemultimessages;caller=$INFO{'caller'};deleteid=$messageid" onclick="return confirm('$inmes_txt{'770'}$attachDeleteWarn');">$img{'im_remove'}</a>
         ~;
     }
     $showIM_link .= qq~
             $menusep<a href="javascript:void(window.open('$scripturl?action=imprint;caller=$INFO{'caller'};id=$messageid','printwindow'))">$img{'print_im'}</a>
         ~;
     $my_notme = q{};
     if    ( $mstatus =~ m/c/sm ) { $messIconName = 'confidential'; }
     elsif ( $mstatus =~ m/u/sm ) { $messIconName = 'urgent'; }
     elsif ( $mstatus =~ m/a/sm || $messStatus =~ m/ga/sm ) {
         $messIconName = 'alertmod';
     }
     elsif ( $mstatus =~ m/gr/sm ) {
         $messIconName = 'guestpmreply';
     }
     elsif ( $mstatus =~ m/g/sm ) { $messIconName = 'guestpm'; }
     else                         { $messIconName = 'standard'; }
   
     if ( $mstatus ne 'ga' && $mstatus ne 'g' ) {
         $notme    = $musername eq $username ? $mtousers : $musername;
         $notme    = ${ $uid . $notme }{'realname'};
         $my_notme = (
             $notme
             ? qq~<a href="$scripturl?action=pmsearch;searchtype=user;search=$notme">$inmes_imtxt{'42'} <i>$notme</i></a>~
             : '&nbsp;' 
         );
     }
   
     $showIM .= $myIM_show;
     $showIM =~ s/{yabb my_title}/$my_title/sm;
     $showIM =~ s/{yabb msub}/$msub/sm;
     $showIM =~ s/{yabb msimg}/$micon{$messIconName}/sm;
     $showIM =~ s/{yabb mydate}/$mydate/sm;
     $showIM =~ s/{yabb message}/$message/sm;
     $showIM =~ s/{yabb my_sig}/$my_sig/sm;
     $showIM =~ s/{yabb my_showIP}/$my_showIP/sm;
     $showIM =~ s/{yabb imip}/$imip/sm;
     $showIM =~ s/{yabb my_attach}/$my_attach/sm;
     $showIM =~ s/{yabb postMenuTemp}/$postMenuTemp/sm;
     $showIM =~ s/{yabb showIM_link}/$showIM_link/sm;
     $showIM =~ s/{yabb my_notme}/$my_notme/sm;
     $showIM =~ s/{yabb PMnav}/$PMnav/sm;
   
   if ($signature) {     return $showIM; 
       $showIM .= qq~  
<tr>  
   <td class="windowbg2" align="right" colspan="2">  
   <div style="float: left; width: 99%; padding-top: 2px; margin-top: 2px; text-align: left;">  
       <span class="small">$signature</span>  
   </div>  
   </td>  
</tr>~;  
   }  
   
   if ($iamadmin || $iamgmod && $gmod_access2{'ipban2'} eq 'on') { $imip = $imip; }  
   else { $imip = $inmes_txt{'511'}; }  
   
   my $postMenuTemp = $sendEmail . $sendPM . $membAdInfo . "&nbsp;";  
   $postMenuTemp =~ s/\Q$menusep//i;  
   
   $showIM .= qq~  
<tr>  
   <td class="windowbg" align="right" colspan="2">  
   <div style="float: left; width: 99%; padding-top: 5px; margin-top: 2px; text-align: right;">  
       <span class="small"><img src="$imagesdir/ip.gif" border="0" alt="" /> $imip</span>  
   </div>  
   </td>  
</tr>  
<tr>  
   <td class="windowbg2" align="left" valign="middle" colspan="2">  
   <div style="float: left; text-align: left; width: 55%; padding: 2px; margin: 2px;">  
       <span class="small">$postMenuTemp</span>  
   </div>  
   <div style="float: right; text-align: right; width: 40%; padding: 2px; margin: 2px;">  
   <span class="small">~;  
   
   $mreplyno++;  
   if ($INFO{'caller'} == 1 || ($INFO{'caller'} == 3 && $musername ne '') || ($INFO{'caller'} == 5 && $musername ne '')) { ## inbox / stored inbox can reply/quote  
       if ($mstatus eq 'g') {  
           $showIM .= qq~<a href="$scripturl?action=imsend;caller=$INFO{'caller'};quote=$mreplyno;replyguest=1;id=$messageid">$img{'reply_ims'}</a>~;  
       } else {  
           $showIM .= qq~  
           <a href="$scripturl?action=imsend;caller=$INFO{'caller'};quote=$mreplyno;to=$useraccount{$musername};id=$messageid">$img{'quote'}</a>$menusep  
           <a href="$scripturl?action=imsend;caller=$INFO{'caller'};reply=$mreplyno;to=$useraccount{$musername};id=$messageid">$img{'reply_ims'}</a>$menusep~;  
       }  
   }  
   
   if ($INFO{'caller'} != 5) {  
       $showIM .= qq~  
           <a href="$scripturl?action=imsend;caller=$INFO{'caller'};quote=$mreplyno;forward=1;id=$messageid">$img{'forward'}</a>$menusep~;  
   }  
   
   if ($INFO{'caller'} != 5 || ($INFO{'caller'} == 5 && ($iamadmin || $username eq $musername))) {  
       $showIM .= qq~  
           <a href="$scripturl?action=deletemultimessages;caller=$INFO{'caller'};deleteid=$messageid" onclick="return confirm('$inmes_txt{'770'}');">$img{'im_remove'}</a>  
       ~;  
   }  
   
   my $notme = $musername eq $username ? $mtousers : $musername;  
   $notme = ${$uid.$notme}{'realname'};  
   $showIM .= qq~  
   </span>  
   </div>  
   </td>  
</tr>  
<tr>  
<td align="right" class="windowbg2" colspan="2">  
   <div style="float: left; text-align: left; padding: 2px; margin: 2px;"><span class="small">~ . ($notme ? qq~<a href="$scripturl?action=pmsearch;searchtype=user;search=$notme">$inmes_imtxt{'42'} <i>$notme</i></a>~ : "&nbsp;") . qq~</span></div>  
   <div style="float: right; text-align: right; padding: 2px; margin: 2px;"><span class="small">$PMnav</span></div>  
</td>  
</tr>  
</table>  
   
</div>  
~;  
   
   return $showIM;  
} }
   
## build the links for single PM display ## build the links for single PM display
sub buildPMNavigator { sub buildPMNavigator {
   if ($previd ne '') { $PMnav = qq~$previd~; }    if ( $previd ne q{} ) { $PMnav = qq~$previd~; }
   if ($allid ne '' && $previd ne '') { $PMnav .= qq~ | $allid~; }    if ( $allid ne q{} && $previd ne q{} ) { $PMnav .= qq~ | $allid~; }
   elsif ($allid ne '') { $PMnav = qq~$allid~; }    elsif ( $allid ne q{} ) { $PMnav = qq~$allid~; }
   if ($nextid ne '' && $allid ne '') { $PMnav .= qq~ | $nextid~; }    if ( $nextid ne q{} && $allid ne q{} ) { $PMnav .= qq~ | $nextid~; }
   return $PMnav;    return $PMnav;
} }
   
## show original PM/BM or the PM/BM before Preview at the bottom of the massage field ## show original PM/BM or the PM/BM before Preview at the bottom of the message field
sub doshowims { sub doshowims {
   my $tempdate;    my $tempdate;
   if ($INFO{'id'} && !$INFO{'replyguest'}) {    if ( $INFO{'id'} && !$INFO{'replyguest'} ) {
       my $messageCount = 0;        my $messageCount     = 0;
       my $messageFoundFlag = 0;        my $messageFoundFlag = 0;
       foreach my $message (@messages) {        foreach my $message (@messages) {
           my $tmnum = (split /\|/, $message)[0];             my $tmnum = ( split /\|/xsm, $message )[0]; 
           if ($tmnum == $INFO{'id'}) { $messageFoundFlag = 1; last; }            if ( $tmnum == $INFO{'id'} ) { $messageFoundFlag = 1; last; }
           else    {$messageCount ++;}             else                         { $messageCount++; } 
       }        }
       ## as a backup, if its not found that way, revert to the list member        ## as a backup, if it is not found that way, revert to the list member
       if (!$messageFoundFlag) { $messageCount = $INFO{'num'}; }        if ( !$messageFoundFlag ) { $messageCount = $INFO{'num'}; }
       ($messageid, $musername, $mto, $mtocc, $mtobcc, $msub, $mdate, $message, $mparid, $mreplyno, $mip, $mstatus, $mflags, $mstore, $mattach) = split(/\|/, $messages[$messageCount]);         ( 
       $tempdate = &timeformat($mdate);             $messageid, $musername, $mto,     $mtocc,  $mtobcc, 
             $msub,      $mdate,     $message, $mparid, $mreplyno,
   } else {             $mip,       $mstatus,   $mflags,  $mstore, $mattach 
       return;         ) = split /\|/xsm, $messages[$messageCount]; 
   }         $tempdate = timeformat($mdate); 
     }
   &ToChars($msub);     else { 
   $msub = &Censor($msub);         return; 
     }
   &wrap;  
   if ($enable_ubbc) {     ToChars($msub); 
       if (!$yyYaBBCloaded) { require "$sourcedir/YaBBC.pl"; }     $msub = Censor($msub); 
       &DoUBBC;  
   }     wrap(); 
   &wrap2;     if ($enable_ubbc) { 
   &ToChars($message);         enable_yabbc(); 
   $message = &Censor($message);         DoUBBC(); 
     }
   if (!${$uid.$musername}{'password'}) { &LoadUser($musername); }     wrap2(); 
   my $musernameRealName = ${$uid.$musername}{'realname'};     ToChars($message); 
   if(!$musernameRealName) { $musernameRealName = $musername; }     $message = Censor($message); 
   
   $imsend .= qq~     if ( !${ $uid . $musername }{'password'} ) { LoadUser($musername); } 
   <tr>     my $musernameRealName = ${ $uid . $musername }{'realname'}; 
     <td class="windowbg">     if ( !$musernameRealName ) { $musernameRealName = $musername; } 
       <table cellspacing="1" cellpadding="0" width="100%" align="center" class="bordercolor"><tr><td>     $my_save_draft = ( 
           <table class="windowbg" cellspacing="0" cellpadding="2" width="100%" align="center" style="table-layout:fixed">         ( $INFO{'id'} && $INFO{'caller'} != 4 ) 
               <tr><td class="titlebg" colspan="2"><b>$inmes_txt{'70'}: $msub</b></td></tr>         ? "$inmes_txt{'30'}: " 
               <tr><td align="left" class="catbg"><span class="small">$inmes_txt{'318'}: $musernameRealName</span></td><td class="catbg" align="right"><span class="small">~ . (($INFO{'id'} && $INFO{'caller'} != 4) ? "$inmes_txt{'30'}: " : ($INFO{'id'} ? "$inmes_txt{'savedraft'} $inmes_txt{'30'}: " : "")) . qq~$tempdate</span></td></tr>         : ( $INFO{'id'} ? "$inmes_txt{'savedraft'} $inmes_txt{'30'}: " : q{} ) 
               <tr><td class="windowbg2" colspan="2"><div class="message" style="float:left; width:100%;">$message</div></td></tr>     ); 
           </table></td></tr>  
       </table>     $imsend .= $my_savedraft; 
     </td>     $imsend =~ s/{yabb msub}/$msub/sm; 
   </tr>\n     $imsend =~ s/{yabb musernameRealName}/$musernameRealName/sm; 
   ~;     $imsend =~ s/{yabb my_save_draft}/$my_save_draft/sm; 
     $imsend =~ s/{yabb tempdate}/$tempdate/sm;
     $imsend =~ s/{yabb message}/$message/sm;
     return $imsend;
  }
   
  sub links_to {
     my ($uname) = @_;
     my @opts2 = (
         [ 'all', 'admins', 'gmods', 'fmods', 'mods', ],
         [
             qq~<b>$inmes_txt{'bmallmembers'}</b>~,
             qq~<b>$inmes_txt{'bmadmins'}</b>~,
             qq~<b>$inmes_txt{'bmgmods'}</b>~,
             qq~<b>$inmes_txt{'bmfmods'}</b>~,
             qq~<b>$inmes_txt{'bmmods'}</b>~,
         ],
     );
   
     if (   $uname eq 'all' 
         || $uname eq 'admins' 
         || $uname eq 'gmods' 
         || $uname eq 'fmods' 
         || $uname eq 'mods' )
     {
         foreach my $i ( 0 .. 4 ) {
             my $opt0 = $opts2[0]->[$i];
             my $opt1 = $opts2[1]->[$i];
   
             if ( $uname eq $opt0 ) {
                 $usernamelinkto = $opt1 . q{, };
             }
         }
     }
     else {
         my ( $title, undef ) = split /\|/xsm, $NoPost{$uname}, 2;
         $usernamelinkto = qq~<b>$title</b>~ . q{, };
     }
     return $usernamelinkto;
} }
   
1; 1;