<?php

if ($spellcheck == 1)
{
    $query = "INSERT INTO $spelltable (strName, memPost, intTopicId) values( '$gfcookie[1]', '$reply', '$topicid')";
    mysql_query( $query, $link ) or die ( "Error! : ".mysql_error() );

    header("Location: spellcheck.php?topicid=$topicid");
    exit;
}


$file = __FILE__;
include ("inc/inc_common.php");
include ("inc/inc_connect.php");
include ("inc/inc_admincheck.php");
include ("inc/inc_getdate.php");

// Get a forum ID

$result = mysql_query( "SELECT * FROM $forumtable WHERE intTopicId = '$topicid' AND ynTopicRow = 'YES'" );
$num_rows = mysql_num_rows( $result );
while ( $a_row = mysql_fetch_object( $result ) )
{
    if ($groupid == "")
    {
        $groupid = $a_row->intForumId;
    }
    if ($a_row->ynGalleryRow == "Yes")
    {
        header("Location: gallery.php?topicid=$a_row->intTopicId&groupid=$groupid");
        exit;
    }
}


//if this group has a password, do a check...
$result = mysql_query( "SELECT * FROM $grouptable WHERE intId = '$groupid'" );
$num_rows = mysql_num_rows( $result );
while ( $a_row = mysql_fetch_object( $result ) )
{
    if ($a_row->strPassword != "NONE")
    {
        $resultb = mysql_query( "SELECT * FROM $passwordtable WHERE intTopicId = '$groupid' AND strName = '$gfcookie[1]'" );
        $bnum_rows = mysql_num_rows( $resultb );
        while ( $b_row = mysql_fetch_object( $resultb ) )
        {
            $password1 = $b_row->strPassword;
        }
        if ($password1 != $a_row->strPassword)
        {
            header("Location:forums.php");
            exit;
        }
        //double check
        if ($bnum_rows < 1)
        {
            header("Location:forums.php");
            exit;
        }

    }
}


include ("inc/inc_forumname.php");
$page = "Show Topic \"$name4\" ($topicid)";
$pagelink = $file."?topicid=".$topicid;
include("inc/inc_setonline.php");
$title = "$name1 - $name2 - $name3 - $name4";
include ("inc/inc_head.php");
include ("inc/inc_body.php");
$title = $name4;
include ("inc/inc_title.php");

print "</centeR><table border=0 width=\"100%\" cellpadding=1 cellspacing=0><tr><td  width=\"20%\">
<table border=0 cellpadding=1 cellspacing=0><tr><td>
<font face=\"$font\" size=$fontsize><image src=\"images/folder_icon.gif\">&nbsp;<a href=\"index.php\">$name1&nbsp;Home</a>
</td></tr>
<tr><td><image src=\"images/folder_line.gif\">
<font face=\"$font\" size=$fontsize><image src=\"images/folder_icon.gif\">&nbsp;<a href=\"forums.php\">$name2</a></td></tr>
<tr><td><font face=\"$font\" size=$fontsize>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<image src=\"images/folder_line.gif\">
<image src=\"images/folder_icon.gif\">&nbsp;<a href=\"topics.php?groupid=$groupid\">$name3</a></td></tr>
</table>
</td><td><center>";

include ("inc/inc_navigation.php");
//add some icons to the navigation...

if (isset($gfcookie[1]))
{
    print "&nbsp;&nbsp;&nbsp;&nbsp;
    <a href=\"#replyhere\"><img border=0 src=\"images/post_reply.gif\"></a>

    <a href=\"new_topic.php?groupid=$groupid\"><img border=0 src=\"images/new_post.gif\"></a>";
}

print "&nbsp;<a href=\"topics.php?groupid=$groupid\"><img border=0 src=\"images/topics.gif\"></a>";
include ("inc/inc_newmailsdisplay.php");
print "</td></tr></table><br><center>";


//end of include files...
if ($nonmod == 1)
{
    $cAdminLevel = 0;
}
// Add one to the number of views...

$result=mysql_query("SELECT * FROM $forumtable WHERE intTopicId = '$topicid' AND ynTopicRow = 'Yes'");
$num_rows = mysql_num_rows( $result );
while ( $a_row = mysql_fetch_object( $result ) )
{
    if ( $a_row->strTopicName != "" )
    {
        $thistitle = $a_row->strTopicName;
    }
    $thisid = $a_row->intId;
    $topicid = $a_row->intTopicId;
    $thisviews = $a_row->intViews;
    $vote = $a_row->intVoteId;
    $hbh = $a_row->intHbhForum;
    $hbhname = $a_row->strName;
    $openforum = $a_row->intOpenForum;
}
if ($thisviews == "")
{
    $thisviews = "0";
}
$thisviews ++;
$query = "UPDATE $forumtable SET intViews = '$thisviews' WHERE intTopicId = '$topicid'";
mysql_query( $query, $link ) or die ( "Error with $query   --   $link  : ".mysql_error() );



//start active topics code - tell the database that this user looked at this topic at this time...

if (isset($gfcookie[1]))
{
    //purge any older records

    $query = "DELETE FROM $topicsreadtable WHERE strName = '$gfcookie[1]' AND intTopicId = '$topicid'";
    mysql_query( $query, $link )
    or die ( "Could not add data to \"tblactivetopics\" table: "
    .mysql_error() );

    //now add the new one...

    $query = "INSERT INTO $topicsreadtable
    ( strName, intTopicId, datLastTime )
    values( '$gfcookie[1]', '$topicid', '$epoch' )";

    mysql_query( $query, $link )
    or die ( "Could not add data to \"tblactivetopics\" table: ".mysql_error() );
}


//Draw a vote at the top of the page (if there is one, obviously).
if ($vote != 0)
{
    include ("inc/inc_vote.php");
    print "<br>";
}

//Dispay Posts
if ($postsperpage == 0)
{
    $result = mysql_query( "SELECT * FROM $forumtable WHERE intTopicId = '$topicid' AND intFromEdit = '0' ORDER BY intId" );
}
else
{
    if (!isset($limitstart))
    {
        $limitstart = 0;
    }
    $result = mysql_query( "SELECT * FROM $forumtable WHERE intTopicId = '$topicid' AND intFromEdit = '0' ORDER BY intId LIMIT $limitstart, $postsperpage" );
}
$num_rows = mysql_num_rows( $result );
$topicposts = $num_rows;
while ( $a_row = mysql_fetch_object( $result ) )
{
    //check to show hidden posts to moderators...
    $hide = "no";
    if ($a_row->intPostHidden > 0)
    {
        if ($cAdminLevel == 0)
        {
            continue;
        }
        else
        {
            if ($a_row->intPostHidden == 1)
            {
                $hide = "Deleted by $a_row->strHider";
            }
            else
            {
                $hide = "Original post";
            }
        }
    }

    //need to set a 'sucess' string to 0 to stop a deleted user inheriting the details of the person before them...

    $sucess = 0;

    print "
    <table border=1 cellpadding=0 cellspacing=0 style=\"border-collapse: collapse; font-family: $font; font-size: $fontpoint\tpt\" bordercolor=\"$bordercolor\" width=\"$postwidth\">
    <tr><td width=100%>

    <table border=1 cellpadding=0 cellspacing=0 style=\"border-collapse: collapse; font-family: $font; font-size: $fontpoint\tpt\" bordercolor=\"$bordercolor\" width=100% height=20%>
    <tr>";

    $resultb = mysql_query( "SELECT * FROM $userstable WHERE strName = '$a_row->strName'" );
    $num_rowsb = mysql_num_rows( $result );
    while ( $b_row = mysql_fetch_object( $resultb ) )
    {
        $posts = $b_row->intPosts;
        $forumcomment = $b_row->strForumComment;
        $forumnumber = $b_row->intId;
        $avatar = $b_row->strAvatar;
        $location = $b_row->strLocation;
        $msn = $b_row->strMsnName;
        $yahoo = $b_row->strYahooId;
        $icq = $b_row->strIcqNumber;
        $adlevel = $b_row->intAdminLevel;
        $profile1 = $b_row->strProfile1Answer;
        $profile2 = $b_row->strProfile2Answer;
        $profile3 = $b_row->strProfile3Answer;
        $profile4 = $b_row->strProfile4Answer;
        $homepage = $b_row->strHomepage;
    }
    $sucess = 1;

    if ( $sucess == 0 )
    {
        $posts = 0;
        $forumcomment = "Deleted";
        $forumnumber = 0;
    }

    // left hand pane...

    print "<td width=200 valign=top><center>
    <font size=$fontsizeb><b>$a_row->strName</b>
    <font size=$fontsizea color=black><br>$forumcomment<br>";

    if ($showavatars == 1)
    {
        if ($avatar != "NONE")
        {

            print "<img alt=\"$a_row->strName's Avatar\" border=0 src=\"$avatar\">";

        }
        print "<font size=\"1\"><br>";
    }

    //work out how many stars to give the user...

    if ($posts >  ($stars5 - 1) )
    {
        $stars = 5;
    }

    if ($posts < $stars5 )
    {
        $stars = 4;
    }

    if ($posts < $stars4 )
    {

        $stars = 3;
    }

    if ($posts < $stars3 )
    {
        $stars = 2;
    }


    if ($posts < $stars2 )
    {
        $stars = 1;
    }
    if ($showstars == 1)
    {
        print "<br><img border=0 alt=\" $a_row->strName has posted $posts times \" src=\"images/".$stars."_star_rating.gif\"><br>";
    }
    if ($showmodlevel == 1)
    {
        //figure admin level (if any)
        if ($adlevel > 0)
        {
            if ($adlevel == 1)
            {
                $adname = "$adlevel1";
            }
            if ($adlevel == 2)
            {
                $adname = "$adlevel2";
            }
            if ($adlevel == 3)
            {
                $adname = "$adlevel3";
            }
            if ($adlevel == 4)
            {
                $adname = "$adlevel4";
            }
            if ($adlevel == 5)
            {
                $adname = "$adlevel5";
            }
            if ($adlevel == 6)
            {
                $adname = "$adlevel6";
            }
            if ($adlevel > 6)
            {
                $adname = "$adlevel7";
            }

            print "$adname<br>";
        }
    }

    print "<font size=$fontsizea>";
    if ($showpostid == 1 AND $cAdminLevel > 0)
    {
        print "Post $a_row->intId<br>";
    }
    if ($showprofile1 == 1)
    {
        if ($profile1 != "")
        {
            $postthis = $profile1;
            include ("formatpostssmall.php");
            print "$postthis<br>";
        }
    }
    if ($showprofile2 == 1)
    {
        if ($profile2 != "")
        {
            $postthis = $profile2;
            include ("formatpostssmall.php");
            print "$postthis<br>";
        }
    }
    if ($showprofile3 == 1)
    {
        if ($profile3 != "")
        {
            $postthis = $profile3;
            include ("formatpostssmall.php");
            print "$postthis<br>";
        }
    }
    if ($showprofile4 == 1)
    {
        if ($profile4 != "")
        {
            $postthis = $profile4;
            include ("formatpostssmall.php");
            print "$postthis<br>";
        }
    }
    print "<br><font size=$fontsize color=\"$fontcolor\">";
    if ($showlocation == 1)
    {
        if ($location != "")
        {
            $postthis = $location;
            include ("formatpostssmall.php");
            print "<br>$postthis";
        }
    }



    if ($showposts == "1")
    {
        //see if you have one 'post' or many 'posts'...
        if ($posts == 1)
        {
            print "<br>1 Post";
        }
        else
        {
            print "<br>$posts Posts";
        }
    }
    else
    {
        print "<br>";
    }

    $time = $a_row->strTime;
    include ("inc/inc_time.php");

    print "<br><font size=$fontsizea>Posted at $time$am on the $a_row->strDate</td>";





    //main outer table

    print "<td width=75% valign=top>
    <table border=0 cellpadding=0 cellspacing=0 style=\"border-collapse: collapse; font-family: $font; font-size: $fontpoint\tpt\" bordercolor=\"$bordercolor\" width=100%  bordercolorlight=\"$bordercolorlight\" bordercolordark=\"$bordercolordark\">";





    //top bar

    print "<tr>
    <td width=85% valign=top>
    <p style=margin-top: 0; margin-bottom: 0><font face=$font size=$fontsizea>";
    $yesedit = 0;
    if ($cAdminLevel > 0)
    {
        $yesedit = 1;
    }
    if ($gfcookie[1] == "$a_row->strName")
    {
        $yesedit = 1;
    }
    if ($hbh == 1 AND $hbhname == "$gfcookie[1]")
    {
        $yesedit = 1;
    }
    if ($openforum == 1)
    {
        $yesedit = 1;
    }
    if ($hide != "no")
    {
        $yesedit = 0;
    }

    if ($yesedit == 1)
    {
        print "<a title=\"Edit your post\" href=\"editpost.php?postid=$a_row->intId&topicid=$a_row->intTopicId&groupid=$groupid\"><img border=0 src=\"images/edit_post_icon.gif\"></a>";
    }



    if ($cAdminLevel > 1)
    {
        if ($hide == "no")
        {
            print "<a title=\"Delete $a_row->strName's post\" OnClick=\"return confirm('Are you sure you want to delete $a_row->strName&acute;s post?')\" href=\"deletepost.php?delid=$a_row->intId&topicid=$a_row->intTopicId&groupid=$groupid\"><img border=0 src=\"images/delete_sm.gif\"></a>";
        }
        else
        {
            //Give Option To Undelete
            print "<a title=\"Undelete $a_row->strName's post\" OnClick=\"return confirm('Are you sure you want to UNdelete $a_row->strName&acute;s post?')\" href=\"deletepost.php?delid=$a_row->intId&topicid=$a_row->intTopicId&groupid=$groupid&undelete=1\"><img border=0 src=\"images/delete_sm.gif\"></a>";
        }
    }


    if ( $sucess == 1 )
    {
        if ($hide == "no")
        {
            if (isset($gfcookie[1]))
            {
                print "<a title=\"Add $a_row->strName to your buddy list\" href=\"addbuddy.php?name=$gfcookie[1]&buddyname=$a_row->strName&topicid=$a_row->intTopicId&groupid=$groupid\"><img border=0 src=\"images/add_buddy_sm.gif\"></a>
                <a title=\"Send an instant message to $a_row->strName\" href=\"inbox_create.php?to=$a_row->strName\">
                <img border=0 src=\"images/pm_icon.gif\"></a>";
            }

            print "<a title=\"See $a_row->strName's Profile\" href=\"profile.php?userid=$a_row->strName&groupid=$groupid\"><img border=0 src=\"images/profile_icon.gif\"></a>";

            if ( $icq != "" AND $showpmicon == 1)
            {
                print "<a title=\"$a_row->strName's ICQ# is $icq\" href=\"http://wwp.icq.com/scripts/search.dll?to=$icq\"><img border=0 src=\"images/p_icq.GIF\"></a>";
            }

            if ( $msn != "" AND $showpmicon == 1)
            {
                print "<a title=\"$a_row->strName's MSN contact is $msn\" href=\"http://members.msn.com/$msn\" target=\"_blank\"><img border=0 src=\"images/p_msn.GIF\"></a>";
            }

            if ( $yahoo != "" AND $showpmicon == 1)
            {
                print "<a title=\"$a_row->strName's Yahoo ID is $yahoo\" href=\"http://members.yahoo.com/interests?.kw=$yahoo&.oc=t&.sb=1&SEARCH=Find+People&.cb=1\" target=\"_blank\"><img border=0 src=\"images/p_yim.GIF\"></a>";
            }

            if ( $homepage != "" AND $showwwwicon == 1)
            {
                print "<a title=\"Visit $a_row->strName's homepage\" href=\"$homepage\" target=\"_blank\"><img border=0 src=\"images/home_icon.gif\"></a>";
            }
        }
    }


    print "</td><td width=15% valign=center><font size=$fontsizea>";

    //check for sufficent admin level to see IP:
    if ($cAdminLevel > 1)
    {
        print "<centeR>IP=$a_row->strIp&nbsp;";
    }
    else
    {
        if (isset($gfcookie[1]))
        {
            if ($a_row->intId == $reportid)
            {
                print "<centeR><font size=$fontsizea>Thankyou&nbsp;";
            }
            else
            {
                print "<centeR><font size=$fontsizea>
                <a href=\"report.php?topic=$topicid&postid=$a_row->intId&groupid=$groupid\">
                Report Post
                </a>&nbsp;";
            }
        }
    }
    if ($hide != "no")
    {
        print "</td><td width=7% valign=top>";
    }
    else
    {

        if (isset($gfcookie[1]))
        {
            print "</td><td width=7% valign=top>
            <a title=\"Quote $a_row->strName in your post\" href=\"quote.php?postid=$a_row->intId&groupid=$groupid\">
            <img border=0 src=\"images/quote_icon.gif\">
            </a></font>";
        }
    }

    //main post window


    print "</tr><tr><table width=100% height=20% style=\"border-collapse: collapse; font-family: $font;\" bordercolor=\"$bordercolor\" cellpadding=8 cellspacing=0 background=\"";
    if ($hide == "no")
    {
        print "images/forum_background.gif\">";
    }
    else
    {
        print "images/forum_background2.gif\">";
    }
    print "<tr><td valign=top>
    <p style=\"margin-top: 0; margin-bottom: 0\">
    <font size=$fontsize>";

    if ($hide != "no")
    {
        print "<b>$hide</b><br>";
    }

    //start rate topic code - added 20/3/03...

    if ($a_row->intRateTopic == 1)
    {
        print "<table border=0 cellpadding=0 cellspacing=0 width=\"100%\"><tr><td>
        <font size=$fontsizea color=\"$ratecolor\">";
        $ratethis = ucwords(strtolower($a_row->strRateThis));
        if (!isset($gfcookie[1]))
        {
            print "Log in to Rate $ratethis!";
        }
        else
        {
            //has this person already rated?
            $resultb=mysql_query("SELECT * FROM $ratedtable WHERE strName = '$gfcookie[1]' AND intRateId = '$a_row->intId'");
            $num_rowsrate = mysql_num_rows( $resultb );
            if ($num_rowsrate == 0)
            {
               print "Rate $ratethis: &nbsp;<a href=\"ratetopic.php?topicid=$a_row->intId&rate=bad&gobackto=$topicid\"><font color=\"$ratecolor\">I don't like it</a> * <a href=\"ratetopic.php?topicid=$a_row->intId&rate=okay&gobackto=$topicid\"><font color=\"$ratecolor\">It's okay</a> * <a href=\"ratetopic.php?topicid=$a_row->intId&rate=good&gobackto=$topicid\"><font color=\"$ratecolor\">I like it</a>";
            }
            else
            {
                if ($gfcookie[1] == $a_row->strName)
                {
                    print "Current Rating of $ratethis: $a_row->intRating";
                }
                else
                {
                    print "You have already rated $ratethis.";
                }
            }
        }
        print "</td>

        <td align=\"right\" valign=\"center\"><font size=$fontsizea color=\"$ratecolor\">Current Rating:&nbsp;";

        if ($a_row->intRating < -24)
        {
            print "<IMG SRC=\"images/smilies/cry-anim[1].gif\">";
        }
        if ($a_row->intRating < 0 AND $a_row->intRating > -25)
        {
            print "<IMG SRC=\"images/smilies/worry[1].gif\">";
        }
        if ($a_row->intRating == 0)
        {
            print "<IMG SRC=\"images/smilies/indiff[1].gif\">";
        }
        if ($a_row->intRating < 5 AND $a_row->intRating > 0)
        {
            print "<IMG SRC=\"images/smilies/smile[1].gif\">";
        }
        if ($a_row->intRating > 5)
        {
            print "<IMG SRC=\"images/smilies/teeth[1].gif\">";
        }

        print "</td></tr></table>";
    }

    //end rate topic code.

    //check for edited post
    if ($a_row->intEdited == 1)
    {
        //post has been edited - find new post
        $resultb=mysql_query("SELECT * FROM $forumtable WHERE intId = '$a_row->intNewId'");
        $num_rowsb = mysql_num_rows( $resultb );
        while ( $b_row = mysql_fetch_object( $resultb ) )
        {
            $time = $b_row->strEditTime;
            include ("inc/inc_time.php");
            if ($cAdminLevel > 0)
            {
                $postthis = $b_row->memPost."[EDITBOX]Edited by $a_row->strEditor on the $b_row->strEditDate at $time$am\t[br][br]Original:[br][br]".$a_row->memPost."[/EDITBOX]";
            }
            else
            {
                if ($showeditinfo == 1)
                {
                    $postthis = $b_row->memPost."[br][br][size1][green]&lt;Edited by $a_row->strEditor on the $b_row->strEditDate at $time$am&gt;";
                }
                else
                {
                    $postthis = $b_row->memPost;
                }

            }
        }
    }
    else
    {
        $postthis = $a_row->memPost;
    }


    include ("formatposts.php");
    print "$postthis";

    //html close tags in case someone left one open!

    print "</a></i></b></u><font size=2 face=$font color=\"$fontcolor\"><left></li></ul>";

    if ( $a_row->memSig != "")
    {
        //browser break issue...
        $browser = $HTTP_USER_AGENT;
        $pos = strpos($browser, "MSIE");
        if ($pos === false)
        {
           print "<br>";
        }
        print " $sigseperator<br>";

        //format the signature...

        $postthis = $a_row->memSig;
        include ("formatposts.php");

        print "$postthis";
    }



    //shut everything...

    print "</font></p></td></tr></table>
    </td></tr></table>
    </td></tr></table>
    </td></tr></table>
    <br><a name=\"post$a_row->intId\"></a>";

    $locked = $a_row->ynLocked;
    $locker = $a_row->strLockedBy;
    $threadid = $a_row->intTopicId;
}

//check for multiple pages
if ($postsperpage != 0)
{
    $result = mysql_query( "SELECT * FROM $forumtable WHERE intTopicId = '$topicid' AND intFromEdit = '0' ORDER BY intId" );
    $num_rows = mysql_num_rows( $result );

    //$top = $num_rows;
    $pages = floor($num_rows / $postsperpage);

    if ($pages > 1)
    {
        if (!isset($pagenum))
        {
            $pagenum = 1;
        }

        $nextpage = $pagenum + 1;
        $prevpage = $pagenum - 1;

        print "<br><br>";
        if ($pagenum != 1 AND $pagenum != 2)
        {
            print "<a href=\"topic.php?topicid=$topicid&limitstart=0\">First Page</a> ";
        }
        if ($pagenum != 1)
        {
            $limstart = $limitstart - $postsperpage;
            print "<a href=\"topic.php?topicid=$topicid&limitstart=$limstart&pagenum=$prevpage\">Previous Page</a> ";
        }
        $count = 0;
        while ($count < $pages)
        {
            $limstart = $count * $postsperpage;
            $count++;

            if ($count == $pagenum)
            {
                print "$count ";
            }
            else
            {
                print "<a href=\"topic.php?topicid=$topicid&limitstart=$limstart&pagenum=$count\">$count</a> ";
            }
        }
        if ($pagenum < $pages)
        {
            $limstartb = $limitstart + $postsperpage + 1;
            print "<a href=\"topic.php?topicid=$topicid&limitstart=$limstartb&pagenum=$nextpage\">Next Page</a> ";
        }
        if ($pagenum < ($pages - 1))
        {
            print "<a href=\"topic.php?topicid=$topicid&limitstart=$limstart&pagenum=$count\">Last Page</a>";
        }
        print "<br><br>";
    }
}


$thistitle = str_Replace ("<font color=\"Black\">", "", $thistitle);
$thistitle = str_Replace ("<font color=\"RED\">", "", $thistitle);

print "<br><a name=\"replyhere\"></a>";

if ($name4 == "?")
{
    $locked = "Yes";
    print "<br><font face=$font size=3><center>Sorry, an unknown error has occured.<br><br><br><br>";
}

if ($locked == "Yes")
{
    print "<br><font face=$font size=3><center>This thread has been locked by $locker. You cannot post a reply.<br><br><br><br>";
}
else
{
    if (!isset($gfcookie[1]))
    {
        print "<br><font face=$font size=3><center>You must log in or register to post a reply!<br><br>";
        print "<br><br>";
    }
    else
    {
        print "<table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse\" width=\"60%\" bgcolor=\"$fgcolour\">
        <tr>
        <td width=\"100%\">
        <p align=\"center\"><br><b>
        <font face=\"$font\">
        Post Reply
        </font></b></p>
        <form method=\"POST\" action=\"add_reply.php\" name=\"post\">
        <table border=0 cellpadding=0 cellspacing=0 width=\"100%\">
        <tr><td width=\"40%\">";

        include("inc_smilies.php");

        print "<td><script language=javascript><!--

        function markSelection ( txtObj ) {
        if ( txtObj.createTextRange ) {
        txtObj.caretPos = document.selection.createRange().duplicate();
        isSelected = true;
        }
        }

        function insertTag ( txtName, tag, enclose ) {
        var closeTag = tag;
        if ( enclose ) {
        var attribSplit = tag.indexOf ( ' ' );
        if ( tag.indexOf ( ' ' ) > -1 )
        closeTag = tag.substring ( 0, attribSplit );
        }
        if ( isSelected ) {
        var txtObj = eval ( \"document.forms[0].\" + txtName );
        if (txtObj.createTextRange && txtObj.caretPos) {
        var caretPos = txtObj.caretPos;
        caretPos.text = ( ( enclose ) ? \"[\"+tag+\"]\"+caretPos.text+\"[/\"+closeTag+\"]\" : \"\"+tag+\"\"+caretPos.text );
        markSelection ( txtObj );
        if ( txtObj.caretPos.text=='' ) {
        isSelected=false;
        txtObj.focus();
        }
        }
        } else {
        // placeholder for loss of focus handler
        }
        }

        //-->
        </script>

        <textarea onfocus=\"document.onkeypress=function(){};\" rows=\"11\" cols=\"36\" style=\"background-image: url('images/big_area_background.gif')\" name=\"tsttxt\" ONSELECT=\"markSelection(this);\" ONCLICK=\"markSelection(this);\" ONKEYUP=\"markSelection(this);\">";

        if (isset($wrong))
        {
            $result=mysql_query("SELECT * FROM $spelltable WHERE strName = '$gfcookie[1]' AND intTopicId = '$topicid'");
            $num_rows = mysql_num_rows( $result );
            while ( $a_row = mysql_fetch_object( $result ) )
            {
                print "$a_row->memOrigPost";
            }
        }


        print "</textarea><br>";

        include ("inc_buttons.php");
        if ($usespellcheck == 1)
        {

            print "<br><font size=$fontsizea>Use Spell Checking <input type=\"checkbox\" value=\"1\" name=\"spellcheck\"><br>";

        }
        print "<input type=\"hidden\" name=\"topicid\" value=\"$topicid\">
        <input type=\"hidden\" name=\"groupid\" value=\"$groupid\">
        <input type=\"hidden\" name=\"topictitle\" value=\"$thistitle\">
        <br>
        <p align=\"center\">

        <input type=\"submit\" name=\"submit\" value=\"Post This!\"></p>

        </td>
        <td width=\"20%\">&nbsp;</td>
        </tr>
        </table>

        </form>
        <p align=\"center\">&nbsp;</td>
        </tr>
        </table>";
    }
}




if ($wrong == "0")
{
    print "<br>
    <table border=1 cellpadding=3 cellspacing=0 style=\"border-collapse: collapse\" bordercolor=\"$bordercolor\" width=60% style=\"font-family: $font; font-size: $fontpoint\" bgcolor=\"$fgcolour\"><tr><td align=\"center\"><br>No badly spelled words found!<bR><br></td></tr></table><br>";


    $query = "DELETE FROM $spelltable WHERE memOrigPost != 'Spelling Suggestion' AND strName = '$gfcookie[1]'";
    mysql_query( $query, $link ) or die ( "Error! : ".mysql_error() );
}

if ($wrong > 0)
{
    print "<br>
    <table border=1 cellpadding=3 cellspacing=0 style=\"border-collapse: collapse\" bordercolor=\"$bordercolor\" width=60% style=\"font-family: $font; font-size: $fontpoint\" bgcolor=\"$fgcolour\"><tr><td align=\"center\"><br>You have spelt the following words incorrectly:<br><br>";

    $result=mysql_query("SELECT * FROM $spelltable WHERE intTopicId = '$topicid' AND strName = '$gfcookie[1]'");
    $num_rows = mysql_num_rows( $result );
    while ( $a_row = mysql_fetch_object( $result ) )
    {
        $spellings = $a_row->memPost;
    }

    $query = "DELETE FROM $spelltable WHERE memOrigPost != 'Spelling Suggestion' AND strName = '$gfcookie[1]'";
    mysql_query( $query, $link ) or die ( "Error! : ".mysql_error() );

    // $spellings = str_replace("..", "<br>", "$spellings");
    // print "$spellings<br><bR></td></tr></table><br>";





    $spelling = explode("..", "$spellings");
    $counter = count($spelling);
    $count = 0;
    print "<table border=0 cellpadding=3 cellspacing=1 style=\"font-family: $font; font-size: $fontpoint\">";
    while ($count != $counter)
    {
        if ($spelling[$count] == "")
        {
            $count ++;
            continue;
        }

        print "<tr><td align=\"center\">\"$spelling[$count]\"</td><td><font size=$fontsizea><a href=\"spell_suggest.php?word=$spelling[$count]\" target=\"_blank\">Suggest</a> - <a href=\"spell_add.php?word=$spelling[$count]\" target=\"_blank\">Add</a><font size=$fontsize></td></tr>";
        $count ++;
    }
    print "</table><br></td></tr></table><br>";



    $query = "DELETE FROM $spelltable WHERE memOrigPost != 'Spelling Suggestion' AND intTopicId = '$topicid' AND strName = '$gfcookie[1]'";
    mysql_query( $query, $link ) or die ( "Error! : ".mysql_error() );
}




include ("inc/inc_admincheck.php");
if ($cAdminLevel > 0)
{
    print "<font face=\"$font\" size=$fontsize><br>Moderator Options<br><br>
    ";
    if ($nonmod == 1)
    {
        print "<a href=\"topic.php?topicid=$topicid&groupid=$groupid\">View Post As Moderator</a>";
    }
    else
    {
        print "<a href=\"topic.php?topicid=$topicid&groupid=$groupid&nonmod=1\">View Post As Non-Moderator</a>";
    }

/* On the 'To Do' list...

    print "&nbsp;&nbsp; Lock Topic &nbsp;&nbsp;
    Post Reply & Lock Topic &nbsp;&nbsp;
    Unlock Topic";
    if ($vote != 0)
    {
        print "&nbsp;&nbsp;&nbsp;
        Lock Vote&nbsp;&nbsp;&nbsp;
        Unlock Vote";
    } */

    print "<form method=\"post\" action=\"movethread.php?id=$threadid&groupid=$groupid\">
    Move Thread To : <select size=1 name=\"move\">";
    $result = mysql_query( "SELECT * FROM $grouptable ORDER BY intGroupId" );
    $num_rows = mysql_num_rows( $result );

    while ( $a_row = mysql_fetch_object( $result ) )
    {
        if ($a_row->ynGroupMaster == "2")
        {
            print "<OPTION VALUE=\"0\">Location:</option>\n";
            continue;
        }

        if ($a_row->ynGroupMaster == "1")
        {
            print "<OPTION VALUE=\"0\">$a_row->strName</option>\n";
            continue;
        }

        if ($a_row->ynGroupMaster == "0")
        {
            print "<OPTION VALUE=\"$a_row->intId\">-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$a_row->strName</option>\n";
        }
    }
    print "</select>&nbsp;&nbsp;<input type=\"submit\" value=\"Move\"></form>";
}



if ($showteleporter == 1)
{
    print "<bR><br>";
    include("inc/inc_teleporter.php");
}
include("inc/inc_footer.php");

$topicposts--;
$query = "UPDATE $forumtable SET intReplies = $topicposts WHERE intTopicId = '$topicid'";
mysql_query( $query, $link ) or die ( "Could not add data to \"tblForum\" table: "
.mysql_error() );
mysql_close( $link);
?>