<?php
// Version: 1.0.3; Display

function template_main()
{
	global $context, $settings, $options, $txt, $scripturl, $modSettings;
	if(isset($_REQUEST['debuggg'])) print_r($context);
	// Show the anchor for the top and for the first message.  If the first message is new, say so.
	echo '
<a name="top"></a>
<a name="msg', $context['first_message'], '"></a>', $context['first_new_message'] ? '<a name="new"></a>' : '';

	// Show the linktree as well as the "Who's Viewing" information.
	echo '
<table width="100%" cellpadding="3" cellspacing="0">
	<tr>
		<td valign="bottom">', theme_linktree(), '</td>';
	if (!empty($settings['display_who_viewing']))
	{
		echo '
		<td align="center" class="smalltext">';

		// Show just numbers...?
		if ($settings['display_who_viewing'] == 1)
			echo count($context['view_members']), ' ', count($context['view_members']) == 1 ? $txt['who_member'] : $txt[19];
		// Or show the actual people viewing the topic?
		else
			echo empty($context['view_members_list']) ? '0 ' . $txt[19] : implode(', ', $context['view_members_list']) . (empty($context['view_num_hidden']) || $context['can_moderate_forum'] ? '' : ' (+ ' . $context['view_num_hidden'] . ' ' . $txt['hidden'] . ')');

		// Now show how many guests are here too.
		echo $txt['who_and'], $context['view_num_guests'], ' ', $context['view_num_guests'] == 1 ? $txt['guest'] : $txt['guests'], $txt['who_viewing_topic'], '</td>';
	}

	// Show the previous/next links.
	echo '
		<td valign="bottom" align="right" class="smalltext">
			<span class="nav">', $context['previous_next'], '</span>
		</td>
	</tr>
</table>';

	// Is there any related topics?
	if (!empty($context['related_topics']))
	{
		echo '
<table cellspacing="0" width="0">
	<tr>
		<td>&nbsp;</td>
	</tr>
	<tr>
	<tr>
		<td><b>',$txt['related_topics'],'</b></td>
	</tr>';
		foreach($context['related_topics'] as $rt)
		{
		    echo'
	<tr>
		<td><a href="', $scripturl, '?topic=',$rt['id'],'.new;topicseen#new">',$rt['subj'],'</a></td>
	</tr>';
		}
		echo '
	<tr>
		<td>&nbsp;</td>
	</tr>
</table>';
	}
	
	// Is this topic also a poll?
	if ($context['is_poll'])
	{
		echo '
<table cellpadding="3" cellspacing="1" border="0" width="100%" class="tborder" style="margin-bottom: 2ex;">
	<tr class="titlebg">
		<td colspan="2" valign="middle" align="left" style="padding-left: 6px;">
			<img src="', $settings['images_url'], '/topic/', $context['poll']['is_locked'] ? 'normal_poll_locked' : 'normal_poll', '.gif" alt="" align="top" /> ', $txt['smf43'], '
		</td>
	</tr>
	<tr class="windowbg">
		<td width="5%" valign="top"><b>', $txt['smf21'], ':</b></td>
		<td>
			', $context['poll']['question'];
		if (!empty($context['poll']['expire_time']))
			echo '
			&nbsp;(', ($context['poll']['is_expired'] ? $txt['poll_expired_on'] : $txt['poll_expires_on']), ': ', $context['poll']['expire_time'], ')';

		// Are they not allowed to vote but allowed to view the options?
		if (!$context['allow_vote'])
		{
			echo '
			<table>
				<tr>
					<td style="padding-top: 2ex;">
						<table border="0" cellpadding="0" cellspacing="0">';

			// Show each option with its corresponding percentage bar.
			foreach ($context['poll']['options'] as $option)
				echo '
							<tr>
								<td style="padding-right: 2ex;">', $option['option'], '</td>', $context['allow_poll_view'] ? '
								<td nowrap="nowrap">' . $option['bar'] . ' ' . $option['votes'] . ' (' . $option['percent'] . '%)</td>' : '', '
							</tr>';

			echo '
						</table>
					</td>
					<td valign="bottom" style="padding-left: 15px;">';

			// If they are allowed to revote - show them a link!
			if ($context['allow_change_vote'])
				echo '
						<a href="', $scripturl, '?action=vote;topic=', $context['current_topic'], '.', $context['start'], ';poll=', $context['poll']['id'], ';sesc=', $context['session_id'], '">', $txt['poll_change_vote'], '</a><br />';

			// If they're allowed to lock the poll, show a link!
			if ($context['poll']['lock'])
				echo '
						<a href="', $scripturl, '?action=lockVoting;topic=', $context['current_topic'], '.', $context['start'], ';sesc=', $context['session_id'], '">', !$context['poll']['is_locked'] ? $txt['smf30'] : $txt['smf30b'], '</a><br />';

			// If they're allowed to edit the poll... guess what... show a link!
			if ($context['poll']['edit'])
				echo '
						<a href="', $scripturl, '?action=editpoll;topic=', $context['current_topic'], '.', $context['start'], '">', $txt['smf39'], '</a>';

			echo '
					</td>
				</tr>', $context['allow_poll_view'] ? '
				<tr>
					<td colspan="2"><b>' . $txt['smf24'] . ': ' . $context['poll']['total_votes'] . '</b></td>
				</tr>' : '', '
			</table><br />';
		}
		// They are allowed to vote!  Go to it!
		else
		{
			echo '
			<form action="', $scripturl, '?action=vote;topic=', $context['current_topic'], '.', $context['start'], ';poll=', $context['poll']['id'], '" method="post" style="margin: 0px;">
				<table>
					<tr>
						<td colspan="2">';

			// Show a warning if they are allowed more than one option.
			if ($context['poll']['allowed_warning'])
				echo '
							', $context['poll']['allowed_warning'], '
						</td>
					</tr><tr>
						<td>';

			// Show each option with its button - a radio likely.
			foreach ($context['poll']['options'] as $option)
				echo '
							', $option['vote_button'], ' ', $option['option'], '<br />';

			echo '
						</td>
						<td valign="bottom" style="padding-left: 15px;">';

			// Allowed to view the results? (without voting!)
			if ($context['allow_poll_view'])
				echo '
							<a href="', $scripturl, '?topic=', $context['current_topic'], '.', $context['start'], ';viewResults">', $txt['smf29'], '</a><br />';

			// Show a link for locking the poll as well...
			if ($context['poll']['lock'])
				echo '
							<a href="', $scripturl, '?action=lockVoting;topic=', $context['current_topic'], '.', $context['start'], ';sesc=', $context['session_id'], '">', (!$context['poll']['is_locked'] ? $txt['smf30'] : $txt['smf30b']), '</a><br />';

			// Want to edit it?  Click right here......
			if ($context['poll']['edit'])
				echo '
							<a href="', $scripturl, '?action=editpoll;topic=', $context['current_topic'], '.', $context['start'], '">', $txt['smf39'], '</a>';

			echo '
						</td>
					</tr><tr>
						<td colspan="2"><input type="submit" value="', $txt['smf23'], '" /></td>
					</tr>
				</table>
				<input type="hidden" name="sc" value="', $context['session_id'], '" />
			</form>';
		}

		echo '
		</td>
	</tr>
</table>';
	}

	// Show the page index... "Pages: [1]".
	echo '
<table width="100%" cellpadding="0" cellspacing="1" border="0" class="tborder" style="margin-bottom: 1ex;">
	<tr>
		<td align="left" class="catbg" width="100%" height="20">
			<table cellpadding="2" cellspacing="0" width="100%">
				<tr>
					<td>
						<b>', $txt[139], ':</b> ', $context['page_index'];

	// Show a "go down" link?
	if (!empty($modSettings['topbottomEnable']))
		echo $context['menu_separator'], '<a href="#bot">', $settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/go_down.gif" alt="' . $txt['topbottom5'] . '" border="0" align="top" />' : $txt['topbottom5'], '</a>';

	echo '
					</td>
					<td align="right" style="font-size: smaller;">';

	$buttonArray = array();
	if ($context['can_reply'])
		$buttonArray[] = '<a href="' . $scripturl . '?action=post;topic=' . $context['current_topic'] . '.' . $context['start'] . ';num_replies=' . $context['num_replies'] . '">' . ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/reply.gif" alt="' . $txt[146] . '" border="0" />' : $txt[146]) . '</a>';
	if ($context['can_mark_notify'])
		$buttonArray[] = '<a href="' . $scripturl . '?action=notify;sa=' . ($context['is_marked_notify'] ? 'off' : 'on') . ';topic=' . $context['current_topic'] . '.' . $context['start'] . ';sesc=' . $context['session_id'] . '" onclick="return confirm(\'' . ($context['is_marked_notify'] ? $txt['notification_disable_topic'] : $txt['notification_enable_topic']) . '\');">' . ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/notify.gif" alt="' . $txt[131] . '" border="0" />' : $txt[131]) . '</a>';

	// This is a special case; if they can see mark unread, put it at the top... otherwise show add poll.
	if ($context['user']['is_logged'] && $settings['show_mark_read'])
		$buttonArray[] = '<a href="' . $scripturl . '?action=markasread;sa=topic;topic=' . $context['current_topic'] . '.' . $context['start'] . '">' . ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/markunread.gif" alt="' . $txt['mark_unread'] . '" border="0" />' : $txt['mark_unread']) . '</a>';
	elseif ($context['can_add_poll'])
		$buttonArray[] = '<a href="' . $scripturl . '?action=post;poll;msg=' . $context['topic_first_message'] . ';topic=' . $context['current_topic'] . '.' . $context['start'] . ';sesc=' . $context['session_id'] . '">' . ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/addpoll.gif" alt="' . $txt['add_poll'] . '" border="0" />' : $txt['add_poll']) . '</a>';

	if ($context['can_send_topic'])
		$buttonArray[] = '<a href="' . $scripturl . '?action=sendtopic;topic=' . $context['current_topic'] . '.0">' . ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/sendtopic.gif" alt="' . $txt[707] . '" border="0" />' : $txt[707]) . '</a>';
	$buttonArray[] = '<a href="' . $scripturl . '?action=printpage;topic=' . $context['current_topic'] . '.0" target="_blank">' . ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/print.gif" alt="' . $txt[465] . '" border="0" />' : $txt[465]) . '</a>';

	echo implode($context['menu_separator'], $buttonArray);

	echo '</td>
				</tr>
			</table>
		</td>
	</tr>
</table>';

	// Show the topic information - icon, subject, etc.
	echo '
<table width="100%" cellpadding="3" cellspacing="0" border="0" class="tborder" style="border-bottom: 0;">
	<tr class="titlebg">
		<td valign="middle" align="left" width="15%" style="padding-left: 6px;">
			<img src="', $settings['images_url'], '/topic/', $context['class'], '.gif" alt="" align="middle" /> ', $txt[29], '
		</td>
		<td valign="middle" align="left" width="85%" style="padding-left: 6px;">
			', $txt[118], ': ', $context['subject'], ' &nbsp;(', $txt[641], ' ', $context['num_views'], ' ', $txt[642], ')
		</td>
	</tr>
</table>';

	if (!empty($options['display_quick_mod']) && $options['display_quick_mod'] == 1)
		echo '
<form action="', $scripturl, '?action=quickmod2;topic=', $context['current_topic'], '.', $context['start'], '" method="post" name="quickModForm" style="margin: 0;">';

	echo '
<table cellpadding="0" cellspacing="0" border="0" width="100%" class="bordercolor">';

	// Get all the messages...
	while ($message = $context['get_message']())
	{
		echo '
	<tr><td style="padding: 1px 1px 0 1px;">';

		// Show the message anchor and a "new" anchor if this message is new.
		if ($message['id'] != $context['first_message'])
			echo '
		<a name="msg', $message['id'], '"></a>', $message['first_new'] ? '<a name="new"></a>' : '';

		echo '
		<table width="100%" cellpadding="0" cellspacing="0" border="0">
			<tr><td class="', $message['alternate'] == 0 ? 'windowbg' : 'windowbg2', '">';

		// Show information about the poster of this message.

		// pink nickname for Diana ////////////////////////
/*		if($message['member']['name'] == 'Diana')
			$_special_color = 'style="color: violet"';
		else $_special_color = '';*/
		///////////////////////////////////////////////////
		echo '
				<table width="100%" cellpadding="5" cellspacing="0" style="table-layout: fixed;">
					<tr>
						<td valign="top" width="16%" rowspan="2" style="overflow: hidden; border-right: solid 1px #000000;">';
		// Show the member's gender icon?
		if (!empty($settings['show_gender']) && $message['member']['gender']['image'] != '')
			echo '
						',$message['member']['gender']['image'];
		if (empty($context['user']['is_guest'])) {
			$_special_color="";
		    if(isset($message['member']['group']) && $message['member']['group'] != '' && isset($message['member']['group_color']))
		    	$_special_color='style="color: '.$message['member']['group_color'].';"';
		    echo '								
						<b><a ', $_special_color, ' href="javascript:emoticon(\'[b]', $message['member']['name'], '[/b], \')">',$message['member']['name'],'</a></b>
						<div class="smalltext">';
		    unset($_special_color);
		}    
		else
			echo '								
						<b>',$message['member']['name'],'</b>			
						<div class="smalltext">';	
		
		// Show the member's custom title, if they have one.
		if (isset($message['member']['title']) && $message['member']['title'] != '')
			echo '
								', $message['member']['title'], '<br />';

		// Show the member's primary group (like 'Administrator') if they have one.
		if (isset($message['member']['group']) && $message['member']['group'] != '')
			echo '
								', $message['member']['group'];
		if (!$context['user']['is_guest'] && isset($message['member']['warning']['link']) && $message['member']['warning']['link'] != '')
			echo'
								', $message['member']['warning']['link'];

        echo '<br />';
		// Don't show these things for guests.
		if (!$message['member']['is_guest'] && !$context['user']['is_guest'])
		{
			// Show the post group if and only if they have no other group or the option is on, and they are in a post group.
/*			if ((empty($settings['hide_post_group']) || $message['member']['group'] == '') && $message['member']['post_group'] != '')
				echo '
								', $message['member']['post_group'], '<br />';
			echo '
								', $message['member']['group_stars'], '<br />';*/


			// Show avatars, images, etc.?
			if (empty($context['user']['is_guest']) && !empty($settings['show_user_images']) && empty($options['show_no_avatars']) && !empty($message['member']['avatar']['image']))
				echo '
								<div style="overflow: auto; width: 100%;">', $message['member']['avatar']['image'], '</div>';

			// Show their personal text?
			if (!empty($settings['show_blurb']) && $message['member']['blurb'] != '')
				echo '
								', $message['member']['blurb'], '<br /><br />
								';
			else 
				echo '<br />';

			// Show online and offline buttons?
			if (!empty($modSettings['onlineEnable']) && !$message['member']['is_guest'] && $message['member']['online']['is_online'])
				echo '
								', /*$context['can_send_pm'] ? '<a href="' . $message['member']['online']['href'] . '" title="' . $message['member']['online']['label'] . '">' : '', $settings['use_image_buttons'] ? '<img src="' . $message['member']['online']['image_href'] . '" alt="' . $message['member']['online']['text'] . '" border="0" align="middle" />' : $message['member']['online']['text'], $context['can_send_pm'] ? '</a>' : '', $settings['use_image_buttons'] ?*/ '<span class="smalltext" style="color:lightgreen; font-weight: bold;"> ' . $message['member']['online']['text'] . '</span>' /*: ''*/, ' - ';

			// Show how many posts they have made.
//			echo '
//								', $txt[26], ': ', $message['member']['posts'], '<br />
//								<br />';

			// This shows the popular messaging icons.
/*			echo '
								', $message['member']['icq']['link'], '
								', $message['member']['msn']['link'], '
								', $message['member']['aim']['link'], '
								', $message['member']['yim']['link'], '<br />';
*/

			// Show the profile, website, email address, and personal message buttons.
			if ($settings['show_profile_buttons'])
			{
				// Don't show the profile button if you're not allowed to view the profile.
				if ($message['member']['can_view_profile'])
					echo '
						<a class="karma" href="', $message['member']['href'], '">', (/*$settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/icons/profile_sm.gif" alt="' . $txt[27] . '" title="' . $txt[27] . '" border="0" />' : */$txt[27]), '</a>';
/*
				// Don't show an icon if they haven't specified a website.
				if ($message['member']['website']['url'] != '')
					echo '
								<a href="', $message['member']['website']['url'], '" title="' . $message['member']['website']['title'] . '" target="_blank">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/www_sm.gif" alt="' . $txt[515] . '" border="0" />' : $txt[515]), '</a>';

				// Don't show the email address if they want it hidden.
				if (empty($message['member']['hide_email']))
					echo '
								<a href="mailto:', $message['member']['email'], '">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/email_sm.gif" alt="' . $txt[69] . '" title="' . $txt[69] . '" border="0" />' : $txt[69]), '</a>';
*/
				// Since we know this person isn't a guest, you *can* message them.
				if ($context['can_send_pm'])
					echo ' - <a class="karma" href="', $scripturl, '?action=pm;sa=send;u=', $message['member']['id'], '" title="', $message['member']['online']['label'], '">', /*$settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/im_' . ($message['member']['online']['is_online'] ? 'on' : 'off') . '.gif" alt="' . $message['member']['online']['label'] . '" border="0" />' : $message['member']['online']['label'],*/  $txt['online4'], '</a>';
			}
/*		}
		// Otherwise, show the guest's email.
		else
			echo '
								<br />
								<br />
								<a href="mailto:', $message['member']['email'], '">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/email_sm.gif" alt="' . $txt[69] . '" title="' . $txt[69] . '" border="0" />' : $txt[69]), '</a>';
 */

		// Is karma display enabled?  Total or +/-?
		if ($modSettings['karmaMode'] == '1')
			echo '
							<br /><a href="',$scripturl,'?action=ownkarma;u=', $message['member']['id'],'" class="karma">', $modSettings['karmaLabel'], '</a> '/*, '<br />'*/;
		/*elseif ($modSettings['karmaMode'] == '2')
			echo '
							<br />
							', $modSettings['karmaLabel'], ' +', $message['member']['karma']['good'], '/-', $message['member']['karma']['bad'], '<br />';*/

		// Is this user allowed to modify this member's karma?
		if ($message['member']['karma']['allow'])
			echo '&nbsp;
			<a href="', $scripturl, '?action=modifykarma;sa=applaud;uid=', $message['member']['id'], ';topic=', $context['current_topic'], '.' . $context['start'], ';m=', $message['id'], '"><img src="', $settings['images_url'],'/icons/rep_plus.gif" border="0" /></a> [ ', $message['member']['karma']['good'] - $message['member']['karma']['bad'],' ] <a href="', $scripturl, '?action=modifykarma;sa=smite;uid=', $message['member']['id'], ';topic=', $context['current_topic'], '.', $context['start'], ';m=', $message['id'], '"><img src="', $settings['images_url'],'/icons/rep_minus.gif" border="0" /></a><br />';
		else 
			echo $message['member']['karma']['good'] - $message['member']['karma']['bad'], '<br />';


                // Show how many posts they have made.
                         echo '
		                                                  <br />', $txt[26], ': ', $message['member']['posts'], '
                                                                  <br />';

		}
		// Done with the information about the poster... on to the post itself.
		echo '
							</div>
						</td>
						<td valign="top" width="85%" height="100%">
							<table width="100%" border="0"><tr>
								<td align="left" valign="middle"><a href="', $message['href'], '"><img src="', $settings['images_url'], '/post/' . $message['icon'] . '.gif" alt="" border="0" /></a></td>
								<td align="left" valign="middle">
									<b><a href="', $message['href'], '" class="nav">', $message['subject'], '</a></b>';

		// If this is the first post, (#0) just say when it was posted - otherwise give the reply #.
		echo '
									<div class="smalltext">', !($message['id'] == $context['topic_first_message']) ? $txt['post_no']. $message['counter'] : '', ' ', $txt[30], ': ', $message['time'], '</div></td>
								<td align="right" valign="bottom" height="20" nowrap="nowrap" style="font-size: smaller;">';

		// Can they reply?  Have they turned on quick reply?
		if ($context['can_reply'] && !empty($options['display_quick_reply']))
			echo '
									<a href="', $scripturl, '?action=post;quote=', $message['id'], ';topic=', $context['current_topic'], '.', $context['start'], ';num_replies=', $context['num_replies'], ';sesc=', $context['session_id'], '" onclick="if (!currentSwap) doQuote(', $message['id'], '); else window.location.href = this.href; return false;">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/quote.gif" alt="' . $txt[145] . '" border="0" />' : $txt[145]), '</a>';
		// So... quick reply is off, but they *can* reply?
		elseif ($context['can_reply'])
			echo '
									<a href="', $scripturl, '?action=post;quote=', $message['id'], ';topic=', $context['current_topic'], '.', $context['start'], ';num_replies=', $context['num_replies'], ';sesc=', $context['session_id'], '">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/quote.gif" alt="' . $txt[145] . '" border="0" />' : $txt[145]), '</a>';

		// Can the user modify the contents of this post?
		if ($message['can_modify'])
			echo '
									<a href="', $scripturl, '?action=post;msg=', $message['id'], ';topic=', $context['current_topic'], '.', $context['start'], ';sesc=', $context['session_id'], '">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/modify.gif" alt="' . $txt[66] . '" border="0" />' : $txt[17]), '</a>';

		// How about... even... remove it entirely?!
		if ($message['can_remove'])
			echo '
									<a href="', $scripturl, '?action=deletemsg;topic=', $context['current_topic'], '.', $context['start'], ';msg=', $message['id'], ';sesc=', $context['session_id'], '" onclick="return confirm(\'', $txt[154], '?\');">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/delete.gif" alt="' . $txt[121] . '" border="0" />' : $txt[31]), '</a>';
	if ($context['can_warn'])
			echo '
									<a href="', $scripturl, '?action=warnadd;topic=', $context['current_topic'], ';start=', $context['start'], ';user=', $message['member']['id'], ';msg=', $message['id'], '">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/im_visualw.gif" alt="' . $txt['visual_raise'] . '" border="0" />' : $txt['visual_warn']), '</a>';


		// What about splitting it off the rest of the topic?
		if ($context['can_split'])
			echo '
									<a href="', $scripturl, '?action=splittopics;topic=', $context['current_topic'], '.0;at=', $message['id'], '">', ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/split.gif" alt="' . $txt['smf251'] . '" border="0" />' : $txt['smf251']), '</a>';

		// Show a checkbox for quick moderation?
		if (!empty($options['display_quick_mod']) && $options['display_quick_mod'] == 1 && $message['can_remove'])
			echo '
									<input type="checkbox" name="msgs[]" value="', $message['id'], '" class="check" />';

		// Show the post itself, finally!
		echo '
								</td>
							</tr></table>
							<hr width="100%" size="1" class="hrcolor" />
							<div style="overflow: auto; width: 100%;">', $message['body'];
							/*if($modSettings['nowplayingEnabled'] && $message['nowplaying'] != '')
							{
								if(isset($modSettings['nowplaying_image']) && $modSettings['nowplaying_image'] != '')
									$nowplayingstring = '<img src="'. $settings['images_url'] . '/'. $modSettings['nowplaying_image'] . '" alt="" border="0" />';
								else
									$nowplayingstring = '<img src="'. $settings['images_url'] . '/cddisc.gif" alt="" border="0" />';
								if(isset($modSettings['nowplaying_text']) && $modSettings['nowplaying_text'] != '')
									$nowplayingstring .= '&nbsp;' . $modSettings['nowplaying_text'];
								echo '<br /><br />', $nowplayingstring, '&nbsp;<b>', $message['nowplaying'], '</b>';
							}*/
							echo '</div>
						</td>
					</tr>';

		// Now for the attachments, signature, ip logged, etc...
		echo '
					<tr>
						<td valign="bottom" class="smalltext" width="85%">
							<table width="100%" border="0" style="table-layout: fixed;"><tr>
								<td align="left" colspan="2" class="smalltext" width="100%">';

		// Assuming there are attachments...
		if (!empty($message['attachment']))
		{
			echo '
									<hr width="100%" size="1" class="hrcolor" />
									<div style="overflow: auto; width: 100%;">';

			foreach ($message['attachment'] as $attachment)
			{
				if (isset($attachment['image']))
					echo '
										<a href="' . $attachment['href'] . ';image" target="_blank" border="0">
											', $attachment['image'], '
										</a><br />';
				echo '
										<a href="' . $attachment['href'] . '"><img src="' . $settings['images_url'] . '/icons/clip.gif" align="middle" alt="*" border="0" />&nbsp;' . $attachment['name'] . '</a> (', $attachment['size'], ($attachment['is_image'] ? ', ' . $attachment['width'] . 'x' . $attachment['height'] . ' - ' . $txt['attach_viewed'] : ' - ' . $txt['attach_downloaded']) . ' ' . $attachment['downloads'] . ' ' . $txt['attach_times'] . '.)<br />';
			}

			echo '
									</div>';
		}

		echo '
								</td>
							</tr><tr>
								<td align="left" valign="bottom" class="smalltext">';

		// Show "? Last Edit: Time by Person ?" if this post was edited.
		if ($settings['show_modify'] && !empty($message['modified']['name']))
			echo '
									&#171; <i>', $txt[211], ': ', $message['modified']['time'], ' ', $txt[525], ' ', $message['modified']['name'], '</i> &#187;';
		if($modSettings['nowplayingEnabled'] && $message['nowplaying'] != '' && !$context['user']['is_guest'])
		{
			if(isset($modSettings['nowplaying_image']) && $modSettings['nowplaying_image'] != '')
				$nowplayingstring = '<img src="'. $settings['images_url'] . '/'. $modSettings['nowplaying_image'] . '" alt="" border="0" />';
			else
				$nowplayingstring = '<img src="'. $settings['images_url'] . '/cddisc.gif" alt="" border="0" />';
			if(isset($modSettings['nowplaying_text']) && $modSettings['nowplaying_text'] != '')
				$nowplayingstring .= '&nbsp;' . $modSettings['nowplaying_text'];
			echo '<br /><br />', $nowplayingstring, '&nbsp;<b>', $message['nowplaying'], '</b>';
		}

		echo '
								</td>
								<td align="right" valign="bottom" class="smalltext">';

		// put to site
		if($context['user']['is_admin'])
			echo'
                                                                <a href="/addpub.php?id=',$message['id'],'">На сайт</a>&nbsp;';

		// quick quote
		if (!$context['user']['is_guest'])
			echo '
								<a href="#quickreply" onmousedown="javascript:quoteSelection();return false" onmouseover="getMsgInfo(\'',addslashes($message['member']['name']),'\',',$context['current_topic'],',',$message['id'],',',$message['timestamp'],');">Быстрая цитата</a>&nbsp;';	
		
		// Maybe they want to report this post to the moderator(s)?
		if ($context['can_report_moderator'])
			echo '
									<a href="', $scripturl, '?action=reporttm;topic=', $context['current_topic'], '.', $message['counter'], ';msg=', $message['id'], '">', $txt['rtm1'], '</a> &nbsp;';
									
		/*echo '
									<img src="', $settings['images_url'], '/ip.gif" alt="" border="0" />';*/
		// Show the IP to this user for this post - because you can moderate?
		if ($context['can_moderate_forum'] && !empty($message['member']['ip']))
			echo '
									<a href="', $scripturl, '?action=trackip;searchip=', $message['member']['ip'], '">', $message['member']['ip'], '</a> <a href="', $scripturl, '?action=helpadmin;help=see_admin_ip" onclick="return reqWin(this.href);" class="help">(?)</a>';
		// Or, should we show it because this is you?
		elseif ($message['can_see_ip'])
			echo '
									<a href="', $scripturl, '?action=helpadmin;help=see_member_ip" onclick="return reqWin(this.href);" class="help">', $message['member']['ip'], '</a>';
		// Okay, are you at least logged in?  Then we can show something about why IPs are logged...
/*		elseif (!$context['user']['is_guest'])
			echo '
									<a href="', $scripturl, '?action=helpadmin;help=see_member_ip" onclick="return reqWin(this.href);" class="help">', $txt[511], '</a>';*/
		// Otherwise, you see NOTHING!
		else
			echo '
									'/*, $txt[511]*/;

		echo '
								</td>
							</tr></table>';

		// Show the member's signature?
		if (!empty($message['member']['signature']) && empty($options['show_no_signatures']) && !$context['user']['is_guest'])
			echo '
							<hr width="100%" size="1" class="hrcolor" />
							<div style="overflow: hidden; max-height: 70px; width: 100%; padding-bottom: 3px;" class="signature">', $message['member']['signature'], '</div>';

		echo '
						</td>
					</tr>
				</table>
			</td></tr>
		</table>
	</td></tr>';
	if(($context['is_sticky'] || $context['is_first_sticky']) && ($message['id']==$context['topic_first_message'])) {
		echo '<tr><td class="titlebg" style="padding: 3px 0px;">&nbsp;</td></tr>';
	}
	
	}
	echo '
	<tr><td style="padding: 0 0 1px 0;"></td></tr>
</table>
<a name="lastPost"></a>

<table width="100%" cellpadding="0" cellspacing="1" border="0" class="tborder" style="margin-top: 1ex;">
	<tr>
		<td align="left" class="catbg" width="100%" height="20">
			<table cellpadding="3" cellspacing="0" width="100%">
				<tr>
					<td>
						<a name="bot"></a><b>', $txt[139], ':</b> ', $context['page_index'], ($modSettings['topbottomEnable'] ? $context['menu_separator'] . '<a href="#top">' . ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/go_up.gif" alt="' . $txt['topbottom4'] . '" border="0" align="top" />' : $txt['topbottom4']) . '</a>' : ''), '
					</td>
					<td align="right" style="font-size: smaller;">';

	$buttonArray = array();
	if ($context['can_reply'])
		$buttonArray[] = '<a href="' . $scripturl . '?action=post;topic=' . $context['current_topic'] . '.' . $context['start'] . ';num_replies=' . $context['num_replies'] . '">' . ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/reply.gif" alt="' . $txt[146] . '" border="0" />' : $txt[146]) . '</a>';
	if ($context['can_mark_notify'])
		$buttonArray[] = '<a href="' . $scripturl . '?action=notify;sa=' . ($context['is_marked_notify'] ? 'off' : 'on') . ';topic=' . $context['current_topic'] . '.' . $context['start'] . ';sesc=' . $context['session_id'] . '" onclick="return confirm(\'' . ($context['is_marked_notify'] ? $txt['notification_disable_topic'] : $txt['notification_enable_topic']) . '\');">' . ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/notify.gif" alt="' . $txt[131] . '" border="0" />' : $txt[131]) . '</a>';

	// Another special case, similar to above but reversed.  Show "add poll" unless they can't - then show unread here too.
	if ($context['can_add_poll'])
		$buttonArray[] = '<a href="' . $scripturl . '?action=post;poll;msg=' . $context['topic_first_message'] . ';topic=' . $context['current_topic'] . '.' . $context['start'] . ';sesc=' . $context['session_id'] . '">' . ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/addpoll.gif" alt="' . $txt['add_poll'] . '" border="0" />' : $txt['add_poll']) . '</a>';
	elseif ($context['user']['is_logged'] && $settings['show_mark_read'])
		$buttonArray[] = '<a href="' . $scripturl . '?action=markasread;sa=topic;topic=' . $context['current_topic'] . '.' . $context['start'] . '">' . ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/markunread.gif" alt="' . $txt['mark_unread'] . '" border="0" />' : $txt['mark_unread']) . '</a>';

	if ($context['can_send_topic'])
		$buttonArray[] = '<a href="' . $scripturl . '?action=sendtopic;topic=' . $context['current_topic'] . '.0">' . ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/sendtopic.gif" alt="' . $txt[707] . '" border="0" />' : $txt[707]) . '</a>';
	$buttonArray[] = '<a href="' . $scripturl . '?action=printpage;topic=' . $context['current_topic'] . '.0" target="_blank">' . ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/print.gif" alt="' . $txt[465] . '" border="0" />' : $txt[465]) . '</a>';

	echo implode($context['menu_separator'], $buttonArray);

	echo '&nbsp;
					</td>
				</tr>
			</table>
		</td>
	</tr>
</table>
<script language="JavaScript1.2" type="text/javascript"><!--';

	if (!empty($options['display_quick_reply']))
		echo '
	var currentSwap = ', $options['display_quick_reply'] == 2 ? 'false' : 'true', ';

	function swapOptions()
	{
		document.getElementById("quickReplyExpand").src = smf_images_url + "/" + (currentSwap ? "collapse.gif" : "expand.gif");
		document.getElementById("quickReplyOptions").style.display = currentSwap ? "" : "none";

		currentSwap = !currentSwap;
	}

	setTimeout("fetchSession();", 600000);
	function fetchSession()
	{
		document.getElementById("fetchSessionTemp").src = "', $scripturl, '?action=jsoption;sesc=', $context['session_id'], ';" + (new Date().getTime());
		setTimeout("fetchSession();", 600000);
	}';
	else
		echo '
	var currentSwap = true';

	echo '

	function doQuote(messageid)
	{
		if (currentSwap)
			window.location.href = "', $scripturl, '?action=post;quote=" + messageid + ";topic=', $context['current_topic'], '.', $context['start'], ';sesc=', $context['session_id'], '";
		else
		{
			window.open("', $scripturl, '?action=quotefast;quote=" + messageid + ";sesc=', $context['session_id'], '", "quote", "toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,top=40,left=40,width=240,height=90,resizable=no;");
			if (navigator.appName == "Microsoft Internet Explorer")
				window.location.hash = "quickreply";
			else
				window.location.hash = "#quickreply";
		}
	}
// --></script>
<table border="0" width="100%" cellpadding="0" cellspacing="0">
	<tr>';
	if ($settings['linktree_inline'])
		echo '
		<td valign="top" align="left">', theme_linktree(), '</td> ';
	echo '
		<td valign="top" align="right" class="smalltext"> <span class="nav"> ', $context['previous_next'], '</span></td>
	</tr>
</table>
<div style="padding-top: 4px; padding-bottom: 4px;">', theme_show_mod_buttons(), '</div>';

	if (!empty($options['display_quick_mod']) && $options['display_quick_mod'] == 1 && $context['can_remove_post'])
		echo '
	<input type="hidden" name="sc" value="', $context['session_id'], '" />
</form>';

	echo '
<div align="right" style="margin-bottom: 1ex;">
	<form action="', $scripturl, '" method="get" name="jumptoForm">
		<span class="smalltext">' . $txt[160] . ':</span>
		<select name="jumpto" onchange="if (this.options[this.selectedIndex].value) window.location.href=\'', $scripturl, '\' + this.options[this.selectedIndex].value;">
			<option value="">' . $txt[251] . ':</option>';
	foreach ($context['jump_to'] as $category)
	{
		echo '
			<option value="" disabled="disabled">-----------------------------</option>
			<option value="#', $category['id'], '">', $category['name'], '</option>
			<option value="" disabled="disabled">-----------------------------</option>';
		foreach ($category['boards'] as $board)
			echo '
			<option value="?board=', $board['id'], '.0"', $board['is_current'] ? ' selected="selected"' : '', '> ' . str_repeat('==', $board['child_level']) . '=> ' . $board['name'] . '</option>';
	}
	echo '
		</select>&nbsp;
		<input type="button" value="', $txt[161], '" onclick="if (document.jumptoForm.jumpto.options[document.jumptoForm.jumpto.selectedIndex].value) window.location.href = \'', $scripturl, '\' + document.jumptoForm.jumpto.options[document.jumptoForm.jumpto.selectedIndex].value;" />
	</form>
</div>
<br />';

	if ($context['can_reply'] && !empty($options['display_quick_reply']))
	{
		if ($context['show_spellchecking'])
			echo '
<script language="JavaScript1.2" type="text/javascript" src="' . $settings['default_theme_url'] . '/spellcheck.js"></script>';

		echo '
<a name="quickreply"></a>
<table border="0" cellspacing="1" cellpadding="3" class="bordercolor" width="100%" style="clear: both;">
	<tr>
		<td colspan="2" class="catbg"><a href="javascript:swapOptions();"><img src="', $settings['images_url'], '/', $options['display_quick_reply'] == 2 ? 'collapse' : 'expand', '.gif" alt="+" border="0" id="quickReplyExpand" /></a> <a href="javascript:swapOptions();">', $txt['quick_reply_1'], '</a></td>
	</tr>
	<tr id="quickReplyOptions"', $options['display_quick_reply'] == 2 ? '' : ' style="display: none"', '>
		<td class="windowbg" width="25%" valign="top">', $txt['quick_reply_2'], $context['is_locked'] ? '<br /><br /><b>' . $txt['quick_reply_warning'] . '</b>' : '', '
	</td>
		<td class="windowbg" width="75%" align="center"><table border="0" cellspacing="0" cellpadding="0" width="100%">
                                ', template_enhanced_quick_reply() ,'
                                <tr>
                                        <td colspan="2">

			<form action="', $scripturl, '?action=post2" method="post" name="postmodify" onsubmit="submitonce(this);" style="margin: 0;" enctype="multipart/form-data">
				<input type="hidden" name="topic" value="' . $context['current_topic'] . '" />
				<input type="hidden" name="subject" value="' . $txt['response_prefix'] . $context['subject'] . '" />
				<input type="hidden" name="icon" value="xx" />
				<input type="hidden" name="notify" value="', $context['is_marked_notify'] || !empty($options['auto_notify']) ? '1' : '0', '" />
				<input type="hidden" name="goback" value="', empty($options['return_to_post']) ? '0' : '1', '" />
				<input type="hidden" name="num_replies" value="', $context['num_replies'], '" />
				<textarea cols="75" rows="7" style="width: 95%; height: 100px;" name="message" tabindex="1"></textarea><br />
				';
				if($modSettings['nowplayingEnabled'])
				{
					echo $txt['nowplaying2'] . '<br /><input type="text" style="width:95%" name="nowplaying" tabindex="2" /><br />';
				}
				echo '

				<input type="submit" name="post" value="' . $txt[105] . '" onclick="return submitThisOnce(this);" accesskey="s" tabindex="2" />
				<input type="submit" name="preview" value="' . $txt[507] . '" onclick="return submitThisOnce(this);" accesskey="p" tabindex="4" />';
		if ($context['show_spellchecking'])
			echo '
				<input type="button" value="', $txt['spell_check'], '" onclick="spellCheck(\'postmodify\', \'message\');" />';
		echo '
				<input type="hidden" name="sc" value="' . $context['session_id'] . '" />
				<input type="hidden" name="seqnum" value="', $context['form_sequence_number'], '" />
			</form>
		</td>
	</tr
	</table></td></tr>
</table>';
		if ($context['show_spellchecking'])
			echo '
<form name="spell_form" id="spell_form" method="post" target="spellWindow" action="', $scripturl, '?action=spellcheck"><input type="hidden" name="spell_formname" value="" /><input type="hidden" name="spell_fieldname" value="" /><input type="hidden" name="spellstring" value="" /></form>';

		echo '
</div>';
	}

	echo '<img src="', $settings['images_url'], '/blank.gif" alt="" id="fetchSessionTemp" />';
}

function theme_show_mod_buttons()
{
	global $context, $settings, $options, $txt, $scripturl, $modSettings;

	$moderationButtons = array();

	if ($context['can_move'])
		$moderationButtons[] = '<a href="' . $scripturl . '?action=movetopic;topic=' . $context['current_topic'] . '.0">' . ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/admin_move.gif" alt="' . $txt[132] . '" border="0" />' : $txt[132]) . '</a>';
	if ($context['can_delete'])
		$moderationButtons[] = '<a href="' . $scripturl . '?action=removetopic2;topic=' . $context['current_topic'] . '.0;sesc=' . $context['session_id'] . '" onclick="return confirm(\'' . $txt[162] . '\');">' . ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/admin_rem.gif" alt="' . $txt[63] . '" border="0" />' : $txt[63]) . '</a>';
	if ($context['can_lock'])
		$moderationButtons[] = '<a href="' . $scripturl . '?action=lock;topic=' . $context['current_topic'] . '.' . $context['start'] . ';sesc=' . $context['session_id'] . '">' . ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/admin_lock.gif" alt="' . (empty($context['is_locked']) ? $txt['smf279'] : $txt['smf280']) . '" border="0" />' : (empty($context['is_locked']) ? $txt['smf279'] : $txt['smf280'])) . '</a>';
	if ($context['can_sticky'])
		$moderationButtons[] = '<a href="' . $scripturl . '?action=sticky;topic=' . $context['current_topic'] . '.' . $context['start'] . ';sesc=' . $context['session_id'] . '">' . ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/admin_sticky.gif" alt="' . (empty($context['is_sticky']) ? $txt['smf277'] : $txt['smf278']) . '" border="0" />' : (empty($context['is_sticky']) ? $txt['smf277'] : $txt['smf278'])) . '</a>';
	if ($context['can_merge']){
		$moderationButtons[] = '<a href="' . $scripturl . '?action=mergetopics;board=' . $context['current_board'] . '.0;from=' . $context['current_topic'] . '">' . ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/merge.gif" alt="' . $txt['smf252'] . '" border="0" />' : $txt['smf252']) . '</a>';
		$moderationButtons[] = '<a href="' . $scripturl . '?action=linktopics;board=' . $context['current_board'] . '.0;from=' . $context['current_topic'] . '">' . ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/link.gif" alt="' . $txt['smf252lnk'] . '" border="0" />' : $txt['smf252lnk']) . '</a>';
	}
	if ($context['can_remove_poll'])
		$moderationButtons[] = '<a href="' . $scripturl . '?action=removepoll;topic=' . $context['current_topic'] . '.' . $context['start'] . '" onclick="return confirm(\'' . $txt['poll_remove_warn'] . '\');">' . ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/admin_remove_poll.gif" alt="' . $txt['poll_remove'] . '" border="0" />' : $txt['poll_remove']) . '</a>';

	if ($context['calendar_post'])
		$moderationButtons[] = '<a href="' . $scripturl . '?action=post;calendar;msg=' . $context['topic_first_message'] . ';topic=' . $context['current_topic'] . '.0;sesc=' . $context['session_id'] . '">' . ($settings['use_image_buttons'] ? '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/linktocal.gif" alt="' . $txt['calendar37'] . '" border="0" />' : $txt['calendar37']) . '</a>';

	if ($context['can_remove_post'] && !empty($options['display_quick_mod']) && $options['display_quick_mod'] == 1)
		$moderationButtons[] = $settings['use_image_buttons'] ? '<input type="image" name="submit" src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/delete_selected.gif" alt="' . $txt['quickmod_delete_selected'] . '" onclick="return confirm(\'' . $txt['quickmod_confirm'] . '\');" />' : '<a href="javascript:document.quickModForm.submit();" onclick="return confirm(\'' . $txt['quickmod_confirm'] . '\');">' . $txt['quickmod_delete_selected'] . '</a>';

	if ($context['can_sticky'])
                $moderationButtons[] = '<a href="' . $scripturl . '?action=firststicky;topic=' . $context['current_topic'] . '.' . $context['start'] . ';sesc=' . $context['session_id'] . '"><img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/post_top.gif" alt="' .$txt['make_first_sticky']. '" border="0" /></a>';


	return implode($context['menu_separator'], $moderationButtons);
}

// Show an enhanced quick reply box for those that want everything.
function template_enhanced_quick_reply()
{
	global $context, $modSettings, $settings, $txt, $options, $scripturl, $db_prefix;
	
      loadLanguage('Post');
	// Initialize smiley array...
	$context['smileys'] = array(
		'postform' => array(),
		'popup' => array(),
	);

	// Load smileys - don't bother to run a query if we're not using the database's ones anyhow.
	if (empty($modSettings['smiley_enable']) && $context['user']['smiley_set'] != 'none')
		$context['smileys']['postform'][] = array(
			'smileys' => array(
				array('code' => ':)', 'filename' => 'default/smiley.gif', 'description' => $txt[287]),
				array('code' => ';)', 'filename' => 'wink.gif', 'description' => $txt[292]),
				array('code' => ':D', 'filename' => 'cheesy.gif', 'description' => $txt[289]),
				array('code' => ';D', 'filename' => 'grin.gif', 'description' => $txt[293]),
				array('code' => '>:(', 'filename' => 'angry.gif', 'description' => $txt[288]),
				array('code' => ':(', 'filename' => 'sad.gif', 'description' => $txt[291]),
				array('code' => ':o', 'filename' => 'shocked.gif', 'description' => $txt[294]),
				array('code' => '8)', 'filename' => 'cool.gif', 'description' => $txt[295]),
				array('code' => '???', 'filename' => 'huh.gif', 'description' => $txt[296]),
				array('code' => '::)', 'filename' => 'rolleyes.gif', 'description' => $txt[450]),
				array('code' => ':P', 'filename' => 'tongue.gif', 'description' => $txt[451]),
				array('code' => ':-[', 'filename' => 'embarrassed.gif', 'description' => $txt[526]),
				array('code' => ':-X', 'filename' => 'lipsrsealed.gif', 'description' => $txt[527]),
				array('code' => ':-\\', 'filename' => 'undecided.gif', 'description' => $txt[528]),
				array('code' => ':-*', 'filename' => 'kiss.gif', 'description' => $txt[529]),
				array('code' => ':\'(', 'filename' => 'cry.gif', 'description' => $txt[530])
			),
			'last' => true,
		);
	elseif ($context['user']['smiley_set'] != 'none')
	{
		//if (($temp = cache_get_data('posting_smileys', 480)) == null)
		{
			$request = db_query("
				SELECT code, filename, description, smileyRow, hidden
				FROM {$db_prefix}smileys
				WHERE hidden IN (0, 2)
				ORDER BY smileyRow, smileyOrder", __FILE__, __LINE__);
			while ($row = mysql_fetch_assoc($request))
			{
				$row['code'] = htmlspecialchars($row['code']);
				$row['filename'] = htmlspecialchars($row['filename']);
				$row['description'] = htmlspecialchars($row['description']);

				$context['smileys'][empty($row['hidden']) ? 'postform' : 'popup'][$row['smileyRow']]['smileys'][] = $row;
			}
			mysql_free_result($request);

			//cache_put_data('posting_smileys', $context['smileys'], 480);
		}
		/*else
			$context['smileys'] = $temp;*/
	}

	// Clean house... add slashes to the code for javascript.
	foreach (array_keys($context['smileys']) as $location)
	{
		foreach ($context['smileys'][$location] as $j => $row)
		{
			$n = count($context['smileys'][$location][$j]['smileys']);
			for ($i = 0; $i < $n; $i++)
			{
				$context['smileys'][$location][$j]['smileys'][$i]['code'] = addslashes($context['smileys'][$location][$j]['smileys'][$i]['code']);
				$context['smileys'][$location][$j]['smileys'][$i]['js_description'] = addslashes($context['smileys'][$location][$j]['smileys'][$i]['description']);
			}

			$context['smileys'][$location][$j]['smileys'][$n - 1]['last'] = true;
		}
		if (!empty($context['smileys'][$location]))
			$context['smileys'][$location][count($context['smileys'][$location]) - 1]['last'] = true;
	}
//	$settings['smileys_url'] = $settings['smileys_url']. '/' . $context['user']['smiley_set'];
	$settings['smileys_url'] = "/Smileys/default";

	// Allow for things to be overridden.
	if (!isset($context['post_box_columns']))
		$context['post_box_columns'] = 75;
	if (!isset($context['post_box_rows']))
		$context['post_box_rows'] = 7;
	if (!isset($context['post_box_name']))
		$context['post_box_name'] = 'message';
	if (!isset($context['post_form']))
		$context['post_form'] = 'postmodify';

	// Generate a list of buttons that shouldn't be shown - this should be the fastest way to do this.
	if (!empty($modSettings['disabledBBC']))
	{
		$disabled_tags = explode(',', $modSettings['disabledBBC']);
		foreach ($disabled_tags as $tag)
			$context['disabled_tags'][trim($tag)] = true;
	}

	// Assuming BBC code is enabled then print the buttons and some javascript to handle it.
	if (!empty($modSettings['enableBBC']) && !empty($settings['show_bbc']))
	{
		echo '
				<tr>
					<td align="right"></td>
					<td valign="middle">
						<script language="JavaScript" type="text/javascript"><!-- // --><![CDATA[
							function bbc_highlight(something, mode)
							{
								something.style.backgroundImage = "url(" + smf_images_url + (mode ? "/bbc/bbc_hoverbg.gif)" : "/bbc/bbc_bg.gif)");
							}
						// ]]></script>';

		// The below array makes it dead easy to add images to this page. Add it to the array and everything else is done for you!
		$context['bbc_tags'] = array();
		$context['bbc_tags'][] = array(
			'bold' => array('code' => 'b', 'before' => '[b]', 'after' => '[/b]', 'description' => $txt[253]),
			'italicize' => array('code' => 'i', 'before' => '[i]', 'after' => '[/i]', 'description' => $txt[254]),
			'underline' => array('code' => 'u', 'before' => '[u]', 'after' => '[/u]', 'description' => $txt[255]),
			'strike' => array('code' => 's', 'before' => '[s]', 'after' => '[/s]', 'description' => $txt[441]),
			array(),
			'glow' => array('code' => 'glow', 'before' => '[glow=red,2,300]', 'after' => '[/glow]', 'description' => $txt[442]),
			'shadow' => array('code' => 'shadow', 'before' => '[shadow=red,left]', 'after' => '[/shadow]', 'description' => $txt[443]),
			'move' => array('code' => 'move', 'before' => '[move]', 'after' => '[/move]', 'description' => $txt[439]),
			array(),
			'pre' => array('code' => 'pre', 'before' => '[pre]', 'after' => '[/pre]', 'description' => $txt[444]),
			'left' => array('code' => 'left', 'before' => '[left]', 'after' => '[/left]', 'description' => $txt[445]),
			'center' => array('code' => 'center', 'before' => '[center]', 'after' => '[/center]', 'description' => $txt[256]),
			'right' => array('code' => 'right', 'before' => '[right]', 'after' => '[/right]', 'description' => $txt[446]),
			array(),
			'hr' => array('code' => 'hr', 'before' => '[hr]', 'description' => $txt[531]),
			array(),
			'size' => array('code' => 'size', 'before' => '[size=10pt]', 'after' => '[/size]', 'description' => $txt[532]),
			'face' => array('code' => 'font', 'before' => '[font=Verdana]', 'after' => '[/font]', 'description' => $txt[533]),
		);
		$context['bbc_tags'][] = array(
			'flash' => array('code' => 'flash', 'before' => '[flash=200,200]', 'after' => '[/flash]', 'description' => $txt[433]),
			'img' => array('code' => 'img', 'before' => '[img]', 'after' => '[/img]', 'description' => $txt[435]),
			'url' => array('code' => 'url', 'before' => '[url]', 'after' => '[/url]', 'description' => $txt[257]),
			'email' => array('code' => 'email', 'before' => '[email]', 'after' => '[/email]', 'description' => $txt[258]),
			'ftp' => array('code' => 'ftp', 'before' => '[ftp]', 'after' => '[/ftp]', 'description' => $txt[434]),
			array(),
			'table' => array('code' => 'table', 'before' => '[table]', 'after' => '[/table]', 'description' => $txt[436]),
			'tr' => array('code' => 'td', 'before' => '[tr]', 'after' => '[/tr]', 'description' => $txt[449]),
			'td' => array('code' => 'td', 'before' => '[td]', 'after' => '[/td]', 'description' => $txt[437]),
			array(),
			'sup' => array('code' => 'sup', 'before' => '[sup]', 'after' => '[/sup]', 'description' => $txt[447]),
			'sub' => array('code' => 'sub', 'before' => '[sub]', 'after' => '[/sub]', 'description' => $txt[448]),
			'tele' => array('code' => 'tt', 'before' => '[tt]', 'after' => '[/tt]', 'description' => $txt[440]),
			array(),
			'code' => array('code' => 'code', 'before' => '[code]', 'after' => '[/code]', 'description' => $txt[259]),
			'quote' => array('code' => 'quote', 'before' => '[quote]', 'after' => '[/quote]', 'description' => $txt[260]),
			array(),
			'list' => array('code' => 'list', 'before' => '[list]\n[li]', 'after' => '[/li]\n[li][/li]\n[/list]', 'description' => $txt[261]),
		);
		// Here loop through the array, printing the images/rows/separators!
		foreach ($context['bbc_tags'][0] as $image => $tag)
		{
			// Is there a "before" part for this bbc button? If not, it can't be a button!!
			if (isset($tag['before']))
			{
				// Is this tag disabled?
				if (!empty($context['disabled_tags'][$tag['code']]))
					continue;

				// If there's no after, we're just replacing the entire selection in the post box.
				if (!isset($tag['after']))
					echo '<a href="javascript:void(0);" onclick="replaceText(\'', $tag['before'], '\', document.', $context['post_form'], '.', $context['post_box_name'], '); return false;">';
				// On the other hand, if there is one we are surrounding the selection ;).
				else
					echo '<a href="javascript:void(0);" onclick="surroundText(\'', $tag['before'], '\', \'', $tag['after'], '\', document.', $context['post_form'], '.', $context['post_box_name'], '); return false;">';

				// Okay... we have the link. Now for the image and the closing </a>!
				echo '<img onmouseover="bbc_highlight(this, true);" onmouseout="if (window.bbc_highlight) bbc_highlight(this, false);" src="', $settings['images_url'], '/bbc/', $image, '.gif" align="bottom" border="0" width="23" height="22" alt="', $tag['description'], '" title="', $tag['description'], '" style="background-image: url(', $settings['images_url'], '/bbc/bbc_bg.gif); margin: 1px 2px 1px 1px;" /></a>';
			}
			// I guess it's a divider...
			else
				echo '<img src="', $settings['images_url'], '/bbc/divider.gif" alt="|" style="margin: 0 3px 0 3px;" />';
		}

		// Print a drop down list for all the colors we allow!
		if (!isset($context['disabled_tags']['color']))
			echo ' <select onchange="surroundText(\'[color=\' + this.options[this.selectedIndex].value.toLowerCase() + \']\', \'[/color]\', document.', $context['post_form'], '.', $context['post_box_name'], '); this.selectedIndex = 0; document.', $context['post_form'], '.', $context['post_box_name'], '.focus(document.', $context['post_form'], '.', $context['post_box_name'], '.caretPos);" style="margin-bottom: 1ex;">
								<option value="" selected="selected">', $txt['change_color'], '</option>
								<option value="Black">', $txt[262], '</option>
								<option value="Red">', $txt[263], '</option>
								<option value="Yellow">', $txt[264], '</option>
								<option value="Pink">', $txt[265], '</option>
								<option value="Green">', $txt[266], '</option>
								<option value="Orange">', $txt[267], '</option>
								<option value="Purple">', $txt[268], '</option>
								<option value="Blue">', $txt[269], '</option>
								<option value="Beige">', $txt[270], '</option>
								<option value="Brown">', $txt[271], '</option>
								<option value="Teal">', $txt[272], '</option>
								<option value="Navy">', $txt[273], '</option>
								<option value="Maroon">', $txt[274], '</option>
								<option value="LimeGreen">', $txt[275], '</option>
							</select>';
		echo '<br />';

		// Print the buttom row of buttons!
		foreach ($context['bbc_tags'][1] as $image => $tag)
		{
			if (isset($tag['before']))
			{
				// Is this tag disabled?
				if (!empty($context['disabled_tags'][$tag['code']]))
					continue;

				// If there's no after, we're just replacing the entire selection in the post box.
				if (!isset($tag['after']))
					echo '<a href="javascript:void(0);" onclick="replaceText(\'', $tag['before'], '\', document.', $context['post_form'], '.', $context['post_box_name'], '); return false;">';
				// On the other hand, if there is one we are surrounding the selection ;).
				else
					echo '<a href="javascript:void(0);" onclick="surroundText(\'', $tag['before'], '\', \'', $tag['after'], '\', document.', $context['post_form'], '.', $context['post_box_name'], '); return false;">';

				// Okay... we have the link. Now for the image and the closing </a>!
				echo '<img onmouseover="bbc_highlight(this, true);" onmouseout="if (window.bbc_highlight) bbc_highlight(this, false);" src="', $settings['images_url'], '/bbc/', $image, '.gif" align="bottom" border="0" width="23" height="22" alt="', $tag['description'], '" title="', $tag['description'], '" style="background-image: url(', $settings['images_url'], '/bbc/bbc_bg.gif); margin: 1px 2px 1px 1px;" /></a>';
			}
			// I guess it's a divider...
			else
				echo '<img src="', $settings['images_url'], '/bbc/divider.gif" alt="|" style="margin: 0 3px 0 3px;" />';
		}

		echo '
					</td>
				</tr>';
	}

	// Now start printing all of the smileys.
	if (!empty($context['smileys']['postform']))
	{
		echo '
				<tr>
					<td align="right"></td>
					<td valign="middle">';

		// Show each row of smileys ;).
		foreach ($context['smileys']['postform'] as $smiley_row)
		{
			foreach ($smiley_row['smileys'] as $smiley)
				echo '
						<a href="javascript:void(0);" onclick="replaceText(\' ', $smiley['code'], '\', document.', $context['post_form'], '.', $context['post_box_name'], '); return false;"><img src="', $settings['smileys_url'], '/', $smiley['filename'], '" align="bottom" alt="', $smiley['description'], '" title="', $smiley['description'], '" border="0" /></a>';

			// If this isn't the last row, show a break.
			if (empty($smiley_row['last']))
				echo '<br />';
		}

		// If the smileys popup is to be shown... show it!
		if (!empty($context['smileys']['popup']))
			echo '
						<a href="javascript:moreSmileys();">[', $txt['more_smileys'], ']</a>';

		echo '
					</td>
				</tr>';
	}

	// If there are additional smileys then ensure we provide the javascript for them.
	if (!empty($context['smileys']['popup']))
	{
		echo '
				<script language="JavaScript" type="text/javascript"><!-- // --><![CDATA[
					var smileys = [';

		foreach ($context['smileys']['popup'] as $smiley_row)
		{
			echo '
						[';
			foreach ($smiley_row['smileys'] as $smiley)
			{
				echo '
							["', $smiley['code'], '","', $smiley['filename'], '","', $smiley['js_description'], '"]';
				if (empty($smiley['last']))
					echo ',';
			}

			echo ']';
			if (empty($smiley_row['last']))
				echo ',';
		}

		echo '];
					var smileyPopupWindow;
	
					function moreSmileys()
					{
						var row, i;
	
						if (smileyPopupWindow)
							smileyPopupWindow.close();
	
						smileyPopupWindow = window.open("", "add_smileys", "toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,width=480,height=220,resizable=yes");
						smileyPopupWindow.document.write(\'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n<html>\');
						smileyPopupWindow.document.write(\'\n\t<head>\n\t\t<title>', $txt['more_smileys_title'], '</title>\n\t\t<link rel="stylesheet" type="text/css" href="', $settings['theme_url'], '/style.css" />\n\t</head>\');
						smileyPopupWindow.document.write(\'\n\t<body style="margin: 1ex;">\n\t\t<table width="100%" cellpadding="5" cellspacing="0" border="0" class="tborder">\n\t\t\t<tr class="titlebg"><td align="left">', $txt['more_smileys_pick'], '</td></tr>\n\t\t\t<tr class="windowbg"><td align="left">\');
	
						for (row = 0; row < smileys.length; row++)
						{
							for (i = 0; i < smileys[row].length; i++)
							{
								smileys[row][i][2] = smileys[row][i][2].replace(/"/g, \'&quot;\');
								smileyPopupWindow.document.write(\'<a href="javascript:void(0);" onclick="window.opener.replaceText(&quot; \' + smileys[row][i][0] + \'&quot;, window.opener.document.', $context['post_form'], '.', $context['post_box_name'], '); window.focus(); return false;"><img src="', $settings['smileys_url'], '/\' + smileys[row][i][1] + \'" alt="\' + smileys[row][i][2] + \'" title="\' + smileys[row][i][2] + \'" style="padding: 4px;" border="0" /></a> \');
							}
							smileyPopupWindow.document.write("<br />");
						}
	
						smileyPopupWindow.document.write(\'</td></tr>\n\t\t\t<tr><td align="center" class="windowbg"><a href="javascript:window.close();\\">', $txt['more_smileys_close_window'], '</a></td></tr>\n\t\t</table>\n\t</body>\n</html>\');
						smileyPopupWindow.document.close();
					}
				// ]]></script>';
	}

	// Finally the most important bit - the actual text box to write in!
	echo '
				<tr>
					<td valign="top" align="right"></td>
					<td>
						<!--<textarea class="editor" name="', $context['post_box_name'], '" rows="', $context['post_box_rows'], '" cols="', $context['post_box_columns'], '" onselect="storeCaret(this);" onclick="storeCaret(this);" onkeyup="storeCaret(this);" onchange="storeCaret(this);" tabindex="6"></textarea>
						-->
					</td>
				</tr>';
}
?>
