<?

/*
FlexCMS (http://www.flexcms.com)
Flexible, Powerful, Affordable.

Contents of this file are protected by the copyright
notice found at http://www.flexcms.com/flex/pages/copyright.html,
and its usage is subject to the terms of the licensing agreement 
available at http://www.flexcms.com/flex/pages/license.html
*/



	// ========================================================================================
	// main forum page
	// ========================================================================================
	
	$query = "select * from `".$Settings['DBPrefix']."mb-Settings`";
	$result = mysql_query($query) or die (mysql_error());
	while ($row = mysql_fetch_array($result)) {
		$mbSettings[$row['Name']] = $row['Value'];
	}
	
	
	$OverridesArray = explode('%%',$mbSettings['ColorOverrides']);
	
	
	if ($OverridesArray[1] != '') { 
	$Colors['MBBorder'] = $OverridesArray[1];			// main border
	}
	if ($OverridesArray[2] != '') {
	$Colors['MBBG'] = $OverridesArray[2];				// main background
	}
	if ($OverridesArray[3] != '') {
	$Colors['MBAlternateBG'] = $OverridesArray[3];				// alternate background color
	}
	if ($OverridesArray[4] != '') {
	$Colors['MBSpacerLine'] = $OverridesArray[4];		// spacer line between categories and messages in a thread
	}
	if ($OverridesArray[5] != '') {
	$Colors['MBHeadingText'] = $OverridesArray[5];		// top headings text
	}
	if ($OverridesArray[6] != '') {
	$Colors['MBHeadingBG'] = $OverridesArray[6];			// top headings background
	}
	if ($OverridesArray[7] != '') {
	$Colors['MBText'] = $OverridesArray[7];				// main text
	}
	if ($OverridesArray[8] != '') {
	$Colors['MBQCBorder'] = $OverridesArray[8];			// quote/code sections border
	}
	if ($OverridesArray[9] != '') {
	$Colors['MBQCBG'] = $OverridesArray[9];			// quote/code sections background
	}
	if ($OverridesArray[10] != '') {
	$Colors['MBQCText'] = $OverridesArray[10];				// quote/code sections text
	}
	


	if ($mbSettings['PageTitle'] == '') {
		$mbSettings['PageTitle'] = $MsgText[2][1];
	}
	
	

	$AlignmentCodes[''] = 'left';
	$AlignmentCodes['L'] = 'left';
	$AlignmentCodes['C'] = 'center';
	$AlignmentCodes['R'] = 'right';


	if ($mbSettings['MessagesPerPage'] < 1) {
		$mbSettings['MessagesPerPage'] = 20;
	}
	
	if ($mbSettings['ThreadsPerPage'] < 1) {
		$mbSettings['ThreadsPerPage'] = 50;
	}

	
	
	
	if ($mbSettings['URLDisplayLength'] <= 0) {
		$mbSettings['URLDisplayLength'] = 70;
	}
	function FormatLongURL($URLToShorten) {
		Global $mbSettings;
		
		$HalfLength = intval($mbSettings['URLDisplayLength']/2);
	
		if (strlen($URLToShorten) > $mbSettings['URLDisplayLength']) {
			return substr($URLToShorten,0,$HalfLength).'...'.substr($URLToShorten,strlen($URLToShorten)-$HalfLength,$HalfLength);
		}
		else {
			return $URLToShorten;
		}
	}
	
	
	
	if ($dir = @opendir('./images/avatars')) {
		while (($file = readdir($dir)) !== false) {
			if (!is_dir('./templates/'.$file) && $file != '.' && $file != '..') {
				$ActiveAvatars[$file] = true;
	  		}
		}
		closedir($dir);
	}
	
	
	
	
	$GroupsListSQL = '';
	
	
	
	// read usernames from the database
	$query = "select * from `".$Settings['DBPrefix']."core-Users`";
	$result = mysql_query($query) or die (mysql_error());
	while ($row = mysql_fetch_array($result)) {
		
	
		if ($row['Username'] == $CookieUsername) {
			$ThisUserNumber = $row['RecordNumber'];
						
			if ($row['GroupsList'] != '') {
				$GroupsListSplit = explode('-',substr($row['GroupsList'],1,strlen($row['GroupsList'])-2));
					
				for ($x = 0; $x < count($GroupsListSplit); $x++) {
					if ($GroupsListSQL != '') {
						$GroupsListSQL .= ' OR ';
					}
					
					$GroupsListSQL .= 'GroupsList LIKE \'%-'.$GroupsListSplit[$x].'-%\'';
				}
				
				$GroupsListSQL = ' OR ('.$GroupsListSQL.')';			
			}
		}
	
		$Usernames[$row['RecordNumber']] = $row['Username'];
		$PostsCount[$row['RecordNumber']] = $row['ForumPosts'];
		
		if ($row['ForumAvatar'] != '' && $ActiveAvatars[$row['ForumAvatar']] == true) {
			$AvatarURLs[$row['RecordNumber']] = $ImagesURL.'/avatars/'.$row['ForumAvatar'];			
		}
		else if ($row['CustomAvatar'] != '') {
			$AvatarURLs[$row['RecordNumber']] = $ImagesURL.'/user_avatars/'.$row['CustomAvatar'];	
		}
		
		
		if ($row['ForumSignature'] != '') {
		
			
			$row['ForumSignature'] = str_replace('<', '&lt;', $row['ForumSignature']);
			
			$row['ForumSignature'] = str_replace("\n", '[br]', $row['ForumSignature']);
			$row['ForumSignature'] = str_replace("\r", '', $row['ForumSignature']);
		
		
			// font faces and sizes
			$row['ForumSignature'] = preg_replace("/(\[font=)(.*?)(\])/i", "<font face=\"\\2\">", $row['ForumSignature']);
			$row['ForumSignature'] = preg_replace("/(\[size=)(.*?)(\])/i", "<font size=\"\\2\">", $row['ForumSignature']);
				
			$row['ForumSignature'] = str_replace('[/font]', '</font>', $row['ForumSignature']);
			$row['ForumSignature'] = str_replace('[/size]', '</font>', $row['ForumSignature']);
				
				
			// bold, italic, underline
			$row['ForumSignature'] = preg_replace("/(\[b\])(.*?)(\[\/b\])/i", "<b>\\2</b>", $row['ForumSignature']);
			$row['ForumSignature'] = preg_replace("/(\[i\])(.*?)(\[\/i\])/i", "<i>\\2</i>", $row['ForumSignature']);
			$row['ForumSignature'] = preg_replace("/(\[u\])(.*?)(\[\/u\])/i", "<u>\\2</u>", $row['ForumSignature']);
				
				
			// colors
			$ColorCodes['black'] = '#000000';
			$ColorCodes['white'] = '#ffffff';
			$ColorCodes['red'] = '#ff0000';
			$ColorCodes['yellow'] = '#ffff00';
			$ColorCodes['green'] = '#008000';
			$ColorCodes['grey'] = '#888888';
			$ColorCodes['burgundy'] = '#990000';
			$ColorCodes['orange'] = '#ff9900';
			$ColorCodes['purple'] = '#9900ff';
			$ColorCodes['cream'] = '#ffffcc';
			$ColorCodes['teal'] = '#008080';
			$ColorCodes['salmon'] = '#ffcccc';
			$ColorCodes['blue'] = '#0000ff';
			$ColorCodes['pink'] = '#ff33cc';
			$ColorCodes['navy'] = '#003399';
			$ColorCodes['lightblue'] = '#33ccff';
			$ColorCodes['mauve'] = '#666699';
			$ColorCodes['limegreen'] = '#00ff00';
			
			//$row['Message'] = preg_replace("/(\[color\=)([a-zA-Z]+)(\])/i", "<font color=\"\\2\">", $row['Message']);
			$StringMatches = substr_count($row['ForumSignature'],'[color=');
			for ($i = 1; $i <= $StringMatches; $i++) {				
				$row['ForumSignature'] = preg_replace("/(\[color\=)(.*?)(\])(.*?)(\[\/color\])/ie", "'<font color='.\$ColorCodes['\\2'].'>'.stripslashes('\\4').'</font>'", $row['ForumSignature']);
			}
				 
			 
			// urls
			$row['ForumSignature'] = preg_replace("/(\[url=\")(.*?)(\"\])(.*?)(\[\/url\])/ie", "'<a href=\"\\2\" target=\"_blank\"><font color=\"'.\$Colors['MBText'].'\">\\4</font></a>'", $row['ForumSignature']);
				
			// urls
			$row['ForumSignature'] = preg_replace("/(\[url=)(.*?)(\])(.*?)(\[\/url\])/ie", "'<a href=\"\\2\" target=\"_blank\"><font color=\"'.\$Colors['MBText'].'\">\\4</font></a>'", $row['ForumSignature']);			
				
			$row['ForumSignature'] = preg_replace("/(\[url\])(.*?)(\[\/url\])/ie", "'<a href=\"\\2\" target=\"_blank\"><font color=\"'.\$Colors['MBText'].'\">'.FormatLongURL('\\2').'</font></a>'", $row['ForumSignature']);
				
			
			
			// images
			$row['ForumSignature'] = preg_replace("/(\[img\])(.*?)(\[\/img\])/i", "<img src=\"\\2\" border=\"0\" alt=\"\">", $row['ForumSignature']);
						
				
						
			// convert URLs in text to clickable tags
			$row['ForumSignature'] = preg_replace("/(?<!\"|\>)(http:\/\/)([\w\.\-\/]+)/e", "'<a href=\"\\0\" target=\"_blank\"><font color=\"'.\$Colors['MBText'].'\">\\0</font></a>'", $row['ForumSignature']);
				
				
			
			$row['ForumSignature'] = str_replace('[br]', '<br>', $row['ForumSignature']);
						
			
			$UserSignatures[$row['RecordNumber']] = $row['ForumSignature'];
		
		
		}
		
		
		
		if ($row['DisplayName'] == '') {
			$DisplayNames[$row['RecordNumber']] = $row['Username'];
		}
		else {
			$DisplayNames[$row['RecordNumber']] = $row['DisplayName'];
		}
		
		
		if ($row['Level'] > 1) {
		
			$PermissionsCheck = '';
			
		
			$query44 = "select Permissions from `".$Settings['DBPrefix']."core-Permissions` where Level=".$row['Level']." LIMIT 1";
  			$result44 = mysql_query($query44) or die (mysql_error());
			
			$row44 = mysql_fetch_array($result44);
			
			if ($row44['Permissions'] == 'a') {
				for ($i = 1; $i <= 1000; $i++) {
					$PermissionsCheck[$i] = 'y';
				}
			}
			else {
				$PA = split('-',$row44['Permissions']);
				
				for ($i = 0; $i < count($PA); $i++) {
					if ($PA[$i] > 0) {
						$PermissionsCheck[$PA[$i]] = 'y';
					}
				}
			}
		
		
			if ($PermissionsCheck[204] == 'y') {
				$UserTitles[$row['RecordNumber']] = $MsgText[2][106];
			}
			else if ($PermissionsCheck[202] == 'y') {
				$UserTitles[$row['RecordNumber']] = $MsgText[2][107];
			}
			else {
				$UserTitles[$row['RecordNumber']] = '';
			}
		
		}
		
		
	}
	// set "Guest" for user number 0
	$DisplayNames[0] = $MsgText[2][65];
	
	
	
	
	// main list of categories and boards
	if ($Arguments2 == '') {
	
	
		if ($mbSettings['TopText'] != '') {
			$TopTextInsert = '<div align="'.$AlignmentCodes[$mbSettings['TopTextAlignment']].'">'.$mbSettings['TopText'].'</div><br>';
		}
		if ($mbSettings['BottomText'] != '') {
			$BottomTextInsert = '<br><div align="'.$AlignmentCodes[$mbSettings['BottomTextAlignment']].'">'.$mbSettings['BottomText'].'</div><br>';
		}
	
	
		if ($mbSettings['TitleImage'] != '') {
			$PageTitle = '<div align="'.$AlignmentCodes[$mbSettings['TitleAlignment']].'"><img src="'.$BaseURL.$mbSettings['TitleImage'].'" alt="'.$mbSettings['PageTitle'].'" border="0"></div>';	
		}
		else {
			$PageTitle = '<div align="'.$AlignmentCodes[$mbSettings['TitleAlignment']].'">'.$mbSettings['PageTitle'].'</div>';
		}
	
			
		$BrowserTitle = $mbSettings['PageTitle'];
		$LocationBar = '<a href="'.$IndexURL.'">'.$MsgText[0][1].'</a> > '.$mbSettings['PageTitle'];
		
		
				
		
		$query = "select * from `".$Settings['DBPrefix']."mb-Categories` where (MinLevel<=".$UserLevel."".$GroupsListSQL.") order by CategoryOrder asc, Title asc";
		$result = mysql_query($query) or die (mysql_error());
		while ($row = mysql_fetch_array($result)) {
			$CategoryViewable[$row['RecordNumber']] = 'y';
			$CategoryIDs[] = $row['RecordNumber'];
			$CategoryTitle[$row['RecordNumber']] = $row['Title'];
			$CategoryDescription[$row['RecordNumber']] = $row['Description'];
		}
		
		
		$query = "select * from `".$Settings['DBPrefix']."mb-Boards` where (MinLevel<=".$UserLevel."".$GroupsListSQL.") order by BoardOrder asc, Title asc";
		$result = mysql_query($query) or die (mysql_error());
		while ($row = mysql_fetch_array($result)) {
			if ($CategoryViewable[$row['Category']] == 'y') {
			
			$BoardsShown = 'y';
			
			$BoardID[$row['Category']][] = $row['RecordNumber'];
			$BoardTitle[$row['Category']][] = $row['Title'];
			$BoardDescription[$row['Category']][] = $row['Description'];
			
			$Threads[$row['Category']][] = $row['Threads'];
			$Messages[$row['Category']][] = $row['Messages'];
			
			
			if ($row['LastReply'] > 0) {
				if (date("j/n/Y",GetTimestamp()) == date("j/n/Y",$row['LastReply'])) {
					$LastPostDate = '<b>'.$MsgText[2][66].'</b> @ '.date("g:ia",$row['LastReply']);
				}
				else if (date("j/n/Y",(GetTimestamp()-(60*60*24))) == date("j/n/Y",$row['LastReply'])) {
					$LastPostDate = $MsgText[2][67].' @ '.date("g:ia",$row['LastReply']);
				}
				else {
					$LastPostDate = date("j-",$row['LastReply']).$MsgText[0][283+date("n",$row['LastReply'])].date("-Y @ g:ia",$row['LastReply']);
				}
				
				
				if ($Usernames[$row['LastUser']] != '') {
					if ($LoggedIn == 'y' && $row['LastUser'] > 0) {
						$LastMessageLink = '<a href="'.$MainURL.'/profile/'.$Usernames[$row['LastUser']].'.html"><font color="'.$Colors['MBText'].'">'.$DisplayNames[$row['LastUser']].'</font></a>';
					}
					else {
						$LastMessageLink = $DisplayNames[$row['LastUser']];
					}
				}
				else {
					$LastMessageLink = $MsgText[2][65];
				}
									
				
				//$LastMessage = $LastPostDate . ' by ' . $LastMessageLink. ' &nbsp; <a href="#">&gt;|</a>';
				$LastMessage = $LastPostDate . ' '.$MsgText[2][78].' ' . $LastMessageLink;
			}
			else {
				$LastMessage = $MsgText[2][108];
			}
			
			
			$LastMessages[$row['Category']][] = $LastMessage;
			
			} // end if viewable
			
		}
		
		
		$BoardsList .= '<table width="100%" border="0" cellspacing="1" cellpadding="0">';
		
		
		for ($i = 0; $i < count($CategoryIDs); $i++) {
			if (count($BoardTitle[$CategoryIDs[$i]]) > 0) {
			
				
				$BoardsList .= '<tr><td><table width="100%" border="0" cellspacing="0" cellpadding="1"><tr><td bgcolor="'.$Colors['MBBorder'].'"><table width="100%" border="0" cellspacing="1" cellpadding="0"><tr><td bgcolor="'.$Colors['BG'].'"><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr>

				<td bgcolor="'.$Colors['MBHeadingBG'].'" width="55%" height="100%"><table width="100%" height="100%" border="0" cellspacing="0" cellpadding="4"><tr><td valign="middle"><a name="'.$CategoryIDs[$i].'" style="text-decoration:none;"><font face="'.$FontFace.'" size="'.$FontSize.'" color="'.$Colors['MBHeadingText'].'"><b>'.$CategoryTitle[$CategoryIDs[$i]].'</b><br><font size="'.($FontSize-1).'">'.$CategoryDescription[$CategoryIDs[$i]].'</font></td></tr></table></td>

				<td bgcolor="'.$Colors['MBHeadingBG'].'" width="15%" height="100%"><table width="100%" height="100%" border="0" cellspacing="0" cellpadding="4"><tr><td align="center" valign="middle"><font face="'.$FontFace.'" size="'.$FontSize.'" color="'.$Colors['MBHeadingText'].'">'.$MsgText[2][109].'</td></tr></table></td>

				<td bgcolor="'.$Colors['MBHeadingBG'].'" width="15%" height="100%"><table width="100%" height="100%" border="0" cellspacing="0" cellpadding="4"><tr><td align="center" valign="middle"><font face="'.$FontFace.'" size="'.$FontSize.'" color="'.$Colors['MBHeadingText'].'">'.$MsgText[2][110].'</td></tr></table></td>

				<td bgcolor="'.$Colors['MBHeadingBG'].'" width="15%" height="100%"><table width="100%" height="100%" border="0" cellspacing="0" cellpadding="4"><tr><td align="center" valign="middle"><font face="'.$FontFace.'" size="'.$FontSize.'" color="'.$Colors['MBHeadingText'].'">'.$MsgText[2][111].'</td></tr></table></td>

				</tr>

				<tr><td colspan="4" height="2" bgcolor="'.$Colors['MBBorder'].'"><img src="'.$TemplateImagesURL.'/admin/spacer.gif" border="0" width="1" height="2" alt=""></td></tr>';
			

				$BGColor = $Colors['MBBG'];
			
				for ($j = 0; $j < count($BoardTitle[$CategoryIDs[$i]]); $j++) {
	
	
					$BoardsList .= '<tr>
					
					<td height="100%" width="55%" bgcolor="'.$BGColor.'"><table width="100%" height="100%" border="0" cellspacing="0" cellpadding="4"><tr><td valign="middle"><font face="'.$FontFace.'" size="'.$FontSize.'" color="'.$Colors['MBText'].'"><b><a href="'.$MainURL.'/forum/'.$BoardID[$CategoryIDs[$i]][$j].'.html"><font color="'.$Colors['MBText'].'">'.$BoardTitle[$CategoryIDs[$i]][$j].'</font></a></b><br><font size="'.($FontSize-1).'" color="'.$Colors['MBText'].'">'.$BoardDescription[$CategoryIDs[$i]][$j].'</font></font></td></tr></table></td>

					<td height="100%" width="15%" bgcolor="'.$BGColor.'"><table width="100%" height="100%" border="0" cellspacing="0" cellpadding="4"><tr><td align="center" valign="middle"><font face="'.$FontFace.'" size="'.$FontSize.'" color="'.$Colors['MBText'].'">'.number_format($Threads[$CategoryIDs[$i]][$j]).'</font></td></tr></table></td>

					<td height="100%" width="15%" bgcolor="'.$BGColor.'"><table width="100%" height="100%" border="0" cellspacing="0" cellpadding="4"><tr><td align="center" valign="middle"><font face="'.$FontFace.'" size="'.$FontSize.'" color="'.$Colors['MBText'].'">'.number_format($Messages[$CategoryIDs[$i]][$j]).'</font></td></tr></table></td>

					<td height="100%" width="15%" bgcolor="'.$BGColor.'"><table width="100%" height="100%" border="0" cellspacing="0" cellpadding="4"><tr><td align="center" valign="middle"><font face="'.$FontFace.'" size="'.($FontSize-1).'" color="'.$Colors['MBText'].'">'.$LastMessages[$CategoryIDs[$i]][$j].'</font></td></tr></table></td>

					</tr>';
					
					
					if ($BGColor == $Colors['MBBG']) {
						$BGColor = $Colors['MBAlternateBG'];
					}
					else {
						$BGColor = $Colors['MBBG'];
					}
			
				}
				
				$BoardsList .= '</table></td></tr></table></td></tr></table></td></tr>';
				
				
				if ($i < (count($CategoryIDs)-1)) {
					$BoardsList .= '<tr><td height="1" align="center"><table width="98%" border="0" cellpadding="0" cellspacing="0"><tr><td height="1" bgcolor="'.$Colors['MBSpacerLine'].'"><img src="'.$TemplateImagesURL.'/admin/spacer.gif" border="0" width="1" height="1" alt=""></td></tr></table></td></tr>';
				}
			
			}
		}
	
	
		$BoardsList .= '</table><br>';
	
		if ($BoardsShown == 'y') {
			$RecentMessagesLink = '<b><a href="'.$MainURL.'/forum/recent.html">'.$MsgText[2][88].'</a></b>';
		}
		
		$PageContents = $TopTextInsert . $RecentMessagesLink . '<br><br>' . $BoardsList . $BottomTextInsert;
		
		
	} // end if $Arguments2 == '';
	
	
	else if ($Arguments2 == 'message-compose') {
	
		include_once('./inc-mb-message_compose.php');
	
	}
	else if ($Arguments2 == 'message-post') {
	
		include_once('./inc-mb-message_post.php');
	
	}
	
	
	else if ($Arguments2 == 'thread-compose') {
	
		include_once('./inc-mb-thread_compose.php');
	
	}
	else if ($Arguments2 == 'thread-post') {
	
		include_once('./inc-mb-thread_post.php');
	
	}
	
	
	else if ($Arguments2 == 'thread-move') {
	
		include_once('./inc-mb-thread_move.php');
	
	}
	else if ($Arguments2 == 'thread-move-save') {
	
		include_once('./inc-mb-thread_move_save.php');
	
	}
	
	else if ($Arguments2 == 'thread-lock') {
	
		include_once('./inc-mb-thread_lock.php');
	
	}
	
	else if ($Arguments2 == 'thread-sticky') {
	
		include_once('./inc-mb-thread_sticky.php');
	
	}
	
	else if ($Arguments2 == 'thread-delete') {
	
		include_once('./inc-mb-thread_delete.php');
	
	}
	else if ($Arguments2 == 'thread-delete-confirm') {
	
		include_once('./inc-mb-thread_delete_confirm.php');
	
	}
	
		
	else if ($Arguments2 == 'message-edit') {
	
		include_once('./inc-mb-message_edit.php');
	
	}
	else if ($Arguments2 == 'message-edit-save') {
	
		include_once('./inc-mb-message_edit_save.php');
	
	}
	
	else if ($Arguments2 == 'message-delete') {
	
		include_once('./inc-mb-message_delete.php');
	
	}
	else if ($Arguments2 == 'message-delete-confirm') {
	
		include_once('./inc-mb-message_delete_confirm.php');
	
	}
	
	else if ($Arguments2 == 'recent') {
	
		include_once('./inc-mb-recent.php');
	
	}
	
	else if ($Arguments2 == 'usermessages') {
	
		include_once('./inc-mb-usermessages.php');
	
	}
		
	
	else if ($Arguments2 == 'board-track') {
	
		include_once('./inc-mb-board_track.php');
	
	}
	else if ($Arguments2 == 'thread-track') {
	
		include_once('./inc-mb-thread_track.php');
	
	}
	
	else if ($Arguments2 == 'email') {
	
		$A6 = intval(GetTimestamp()/60/60/24);
		$A7 = substr($Settings['lks'],10,5);
		
		$JSCode[1] = 'document.forms["SubmitForm"].elements["A4"].value = (parseInt(document.forms["SubmitForm"].elements["A2"].value)*parseInt(document.forms["SubmitForm"].elements["A3"].value)); document.forms["SubmitForm"].elements["A5"].value = (parseInt(document.forms["SubmitForm"].elements["A2"].value)+parseInt(document.forms["SubmitForm"].elements["A3"].value));';
		$JSCode[2] = 'document.forms["SubmitForm"].elements["A4"].value = (parseInt(document.forms["SubmitForm"].elements["A2"].value)-parseInt(document.forms["SubmitForm"].elements["A3"].value)); document.forms["SubmitForm"].elements["A5"].value = (parseInt(document.forms["SubmitForm"].elements["A2"].value)+(parseInt(document.forms["SubmitForm"].elements["A3"].value)*parseInt(document.forms["SubmitForm"].elements["A2"].value)));';
		$JSCode[3] = 'document.forms["SubmitForm"].elements["A4"].value = (parseInt(document.forms["SubmitForm"].elements["A2"].value)*parseInt(document.forms["SubmitForm"].elements["A2"].value)*parseInt(document.forms["SubmitForm"].elements["A3"].value)); document.forms["SubmitForm"].elements["A5"].value = (parseInt(document.forms["SubmitForm"].elements["A3"].value)*parseInt(document.forms["SubmitForm"].elements["A3"].value));';
		$JSCode[4] = 'document.forms["SubmitForm"].elements["A4"].value = (Math.pow(parseInt(document.forms["SubmitForm"].elements["A2"].value),2)); document.forms["SubmitForm"].elements["A5"].value = (Math.floor(Math.PI*parseInt(document.forms["SubmitForm"].elements["A2"].value)));';
		$JSCode[5] = 'document.forms["SubmitForm"].elements["A4"].value = ((parseInt(document.forms["SubmitForm"].elements["A2"].value)*parseInt(document.forms["SubmitForm"].elements["A3"].value))-parseInt(document.forms["SubmitForm"].elements["A2"].value)); document.forms["SubmitForm"].elements["A5"].value = ((parseInt(document.forms["SubmitForm"].elements["A2"].value)*47)+parseInt(document.forms["SubmitForm"].elements["A3"].value));';
		
		$A1 = rand(1,5); $A2 = rand(10,99);	$A3 = rand(100,999);
		
	
		$PageContents = '<div align="center"><table width="350" border="0" cellpadding="0" cellspacing="0"><tr><td>
			<font face="'.$FontFace.'" size="'.$FontSize.'">
			<div align="center"><b><font size="4">'.$MsgText[2][153].'</font></b></div><br><form name="SubmitForm" action="'.$MainURL.'/forum/email-submit" method="post">
			<input type="hidden" name="A1" value="'.$A1.'"><input type="hidden" name="A2" value="'.$A2.'"><input type="hidden" name="A3" value="'.$A3.'"><input type="hidden" name="A4" value=""><input type="hidden" name="A5" value=""><input type="hidden" name="A6" value="'.dechex($A6).'"><input type="hidden" name="A7" value="'.$A7.'"><script>'.$JSCode[$A1].'</script><noscript><br><br><b>'.$MsgText[0][633].'</b><br><br></noscript>

			<input type="hidden" name="TopicString" value="'.$Arguments3.'">

			<b>'.$MsgText[2][139].'*:</b><br>
			<input type="text" name="SName" size="40" style="'.$FormStyle.'">
			<br>
			<b>'.$MsgText[2][140].'*:</b><br>
			<input type="text" name="SEmail" size="40" style="'.$FormStyle.'">
			<br><br>
			<b>'.$MsgText[2][141].'*:</b><br>
			<input type="text" name="REmail" size="40" style="'.$FormStyle.'"><br>
			<!-- '.$MsgText[2][142].' --><br><br>
			<b>'.$MsgText[2][143].'</b><br>
			<textarea name="Comments" cols="34" rows="2" wrap="virtual" style="'.$FormStyle.'"></textarea>
			
			<br><br>
			<b>'.$MsgText[2][144].':</b><br>
			<a href="'.$MainURL.'/forum/'.str_replace('-','/',$Arguments3).'.html" target="_blank">'.$MainURL.'/forum/'.str_replace('-','/',$Arguments3).'.html</a>

			<br><br>
			
			<div align="center"><!-- <input type="checkbox" name="CopyMe" value="y" checked> '.$MsgText[2][145].'<br><br> --><br>
<input type="submit" value="'.$MsgText[2][146].'" style="'.$FormStyle.'"></div>
			</td></tr></table><br><br><font size="1">'.$MsgText[2][147].'</div>
			</form>';
		
		
		print '<html><head>
<title>'.$MsgText[2][153].'</title>
<meta name="Description" content="">
<meta name="Keywords" content="">
<meta name="Author" content="">
<meta name="Generator" content="FlexCMS">
<meta name="MSSmartTagsPreventParsing" content="TRUE">
</head>
<body bgcolor="'.$Colors['BG'].'" text="'.$Colors['Text'].'" link="'.$Colors['Link'].'" vlink="'.$Colors['VLink'].'" alink="'.$Colors['ALink'].'"><font face="'.$FontFace.'" size="'.$FontSize.'">
'.$PageContents.'
</body>
</html>';

		exit();
	
	}
	else if ($Arguments2 == 'email-submit') {
	
		ReadFormArguments();
		Global $FormArguments;
		
		
		$FormValidated1 = false;
		if ($FormArguments['A1'] == 1) {
			if (($FormArguments['A4'] == ($FormArguments['A2']*$FormArguments['A3'])) && ($FormArguments['A5'] == ($FormArguments['A2']+$FormArguments['A3']))) {
				$FormValidated1 = true;
			}
		}
		else if ($FormArguments['A1'] == 2) {
			if (($FormArguments['A4'] == ($FormArguments['A2']-$FormArguments['A3'])) && ($FormArguments['A5'] == ($FormArguments['A2']+($FormArguments['A3']*$FormArguments['A2'])))) {
				$FormValidated1 = true;
			}
		}
		else if ($FormArguments['A1'] == 3) {
			if (($FormArguments['A4'] == ($FormArguments['A2']*$FormArguments['A2']*$FormArguments['A3'])) && ($FormArguments['A5'] == ($FormArguments['A3']*$FormArguments['A3']))) {
				$FormValidated1 = true;
			}
		}
		else if ($FormArguments['A1'] == 4) {
			if (($FormArguments['A4'] == ($FormArguments['A2']*$FormArguments['A2'])) && ($FormArguments['A5'] == floor(M_PI*$FormArguments['A2']))) {
				$FormValidated1 = true;
			}
		}
		else if ($FormArguments['A1'] == 5) {
			if (($FormArguments['A4'] == ($FormArguments['A2']*$FormArguments['A3'])-$FormArguments['A2']) && ($FormArguments['A5'] == ($FormArguments['A2']*47)+$FormArguments['A3'])) {
				$FormValidated1 = true;
			}
		}
		
		$FormValidated2 = false;
		if (hexdec($FormArguments['A6']) <= (intval(GetTimestamp()/60/60/24)+2) && $FormArguments['A7'] == substr($Settings['lks'],10,5)) {
			$FormValidated2 = true;
		}
		
		
		list($BoardID,$ThreadID,$PageNumber) = explode('-',$FormArguments['TopicString']);
		$ThreadStringPrint = str_replace('-','/',$FormArguments['TopicString']);
				
		$query = "select * from `".$Settings['DBPrefix']."mb-Threads` where RecordNumber='".$ThreadID."' limit 1";
		$result = mysql_query($query) or die (mysql_error());
		$row = mysql_fetch_array($result);
		
		
		$FormArguments['SName'] = VerifyCleanString($FormArguments['SName'],2);
		$FormArguments['SEmail'] = VerifyCleanString($FormArguments['SEmail'],1);
		$FormArguments['REmail'] = VerifyCleanString($FormArguments['REmail'],1);
		
		if ($row['Title'] != '') {
		
			if ($FormArguments['SName'] != '' && $FormArguments['SEmail'] != '' && $FormArguments['REmail'] != '' && $FormValidated1 == true && $FormValidated2 == true) {
		
			$FormArguments['SName'] = stripslashes($FormArguments['SName']);
			$FormArguments['Comments'] = stripslashes($FormArguments['Comments']);
			
			if ($FormArguments['Comments'] != '') {
				$CommentsAdded = $FormArguments['SName']." included the following comments: \n\n".$FormArguments['Comments'];
			}
		
			$MessageHeaders = 'From: '.$FormArguments['SName'].' <'.$FormArguments['SEmail'].'>';
			
			$Message = "\nGreetings from ".$Settings['SiteName']."!\n\n".$FormArguments['SName'].' thought you would like to read this topic: '.$row['Title'].'.'."\n\n".'You can read it by clicking on or pasting this link in your browser: '.$MainURL.'/forum/'.$ThreadStringPrint.'.html'."\n\n".$CommentsAdded."\n\n\n\n".$Settings['SiteName']."\n".$BaseURL;
			$MessageHeaders .= $Message;		
			
			
			//if (strpos($FormArguments['REmail'],',') === false) {
				mail($FormArguments['REmail'], $Settings['SiteName'].' Topic: '.$row['Title'], "", $MessageHeaders, '-f'.$Settings['ContactEmail']);
			//}
			//else {
			//	$RAddresses = explode(',',$FormArguments['REmail']);
			//	
			//	for ($i = 0; $i < count($RAddresses); $i++) {
			//		if ($RAddresses[$i] != '') {
			//			$RAddresses[$i] = str_replace(' ','',$RAddresses[$i]);
			//			mail($RAddresses[$i], $Settings['SiteName'].' Topic: '.$row['Title'], "", $MessageHeaders, '-f'.$Settings['ContactEmail']);
			//		}
			//	}
			//
			//}
			
			
			//if ($FormArguments['CopyMe'] == 'y') {
			//	mail($FormArguments['SEmail'], $Settings['SiteName'].' Topic: '.$row['Title'], "", $MessageHeaders, '-f'.$Settings['ContactEmail']);			
			//}
		
		
			$PageContents = '<br><br><br><br><div align="center">'.$MsgText[2][148].'<br><br><br><br><b><a href="javascript:window.close();">'.$MsgText[2][149].'</a></b></div>';

			}
			else {
				
				$PageContents = '<br><br><div align="center">'.$MsgText[2][150].'<br><br><br><a href="javascript:history.go(-1)"><b>'.$MsgText[2][151].'</b></a></div>';
			
			}
		
		
			print '<html><head>
<title>'.$MsgText[2][153].'</title>
<meta name="Description" content="">
<meta name="Keywords" content="">
<meta name="Author" content="">
<meta name="Generator" content="FlexCMS">
<meta name="MSSmartTagsPreventParsing" content="TRUE">
</head>
<body bgcolor="'.$Colors['BG'].'" text="'.$Colors['Text'].'" link="'.$Colors['Link'].'" vlink="'.$Colors['VLink'].'" alink="'.$Colors['ALink'].'"><font face="'.$FontFace.'" size="'.$FontSize.'">
'.$PageContents.'
</body>
</html>';

		}


		exit();
	
	}
	
	else if ($Arguments2 == 'search') {
	
		include_once('./inc-mb-search.php');
	
	}
	
	
	
	// list of list of messages in a thread
	else if ($Arguments2 == 'thread' && $Arguments3 != '') {
	
		//$Arguments2 = intval($Arguments2);
		$Arguments3 = intval($Arguments3);
		$Arguments4 = intval($Arguments4);
		
		$mbSettings['MessagesPerPage'] = intval($mbSettings['MessagesPerPage']);
		
		
		if ($PrintableFormat != 'y') {
				if ($Arguments4 > 0) {
					$Arguments4Print = '-'.$Arguments4;
					$Arguments4Print2 = '/'.$Arguments4;
				}
		
				$PrintEmailLinks = '
				<script>
				function EmailTopic(TopicID) {
				
					var WindowProperties = \'width=450,height=500,left=\' + (screen.width-450)/2 + \',top=\' + (screen.height-500)/2 + \',location=no,menubar=no,directories=no,toolbar=no,status=no,scrollbars=no,resizable=yes\';

					var EmailWindowCode = window.open(\''.$MainURL.'/forum/email/\'+TopicID+\'.html\',\'EmailTopic\',WindowProperties);
								
				}			
				</script>			
				
				<div align="'.$AlignmentCodes[$mbSettings['PEAlignment']].'"><table border="0" cellpadding="0" cellspacing="0">
    <tr>
      <td><a href="'.$MainURL.'/printable/forum/thread/'.$Arguments3.$Arguments4Print2.'.html" target="_blank"><img src="'.$ImagesURL.'/admin/icon_print.gif" width="16" height="16" alt="" border="0"></a></td>
      <td><font face="'.$FontFace.'" size="1">&nbsp;<a href="'.$MainURL.'/printable/forum/thread/'.$Arguments3.$Arguments4Print2.'.html" target="_blank">'.$MsgText[2][152].'</a></td>
      <td><img src="'.$ImagesURL.'/admin/spacer.gif" width="15" height="1" alt="" border="0"></td>
      <td><a href="javascript:EmailTopic(\''.$Arguments2.'-'.$Arguments3.$Arguments4Print.'\');"><img src="'.$ImagesURL.'/admin/icon_email.gif" width="16" height="16" alt="" border="0"></a></td>
      <td><font face="'.$FontFace.'" size="1">&nbsp;<a href="javascript:EmailTopic(\''.$Arguments2.'-'.$Arguments3.$Arguments4Print.'\');">'.$MsgText[2][153].'</a>&nbsp;&nbsp;</td>
    </tr>
</table></div><img src="'.$ImagesURL.'/admin/spacer.gif" width="1" height="14" alt="" border="0">';

		}
		
		/*
		$query8 = "select BoardID from `".$Settings['DBPrefix']."mb-Threads` where RecordNumber=".$Arguments3." limit 1";
		$result8 = mysql_query($query8) or die (mysql_error());
		$row8 = mysql_fetch_array($result8);
		
		
		$query = "select `".$Settings['DBPrefix']."mb-Boards`.MinLevel as BMinLevel,`".$Settings['DBPrefix']."mb-Categories`.MinLevel as CMinLevel from `".$Settings['DBPrefix']."mb-Boards` left join `".$Settings['DBPrefix']."mb-Categories` on `".$Settings['DBPrefix']."mb-Categories`.RecordNumber=`".$Settings['DBPrefix']."mb-Boards`.Category where `".$Settings['DBPrefix']."mb-Boards`.RecordNumber='".$row8['BoardID']."' limit 1";		
		$result = mysql_query($query) or die (mysql_error());
		$row = mysql_fetch_array($result);
			
		if ($row['BMinLevel'] <= $UserLevel && $row['CMinLevel'] <= $UserLevel) {
		*/
		
		
		
		
		$query = "select * from `".$Settings['DBPrefix']."mb-Threads` where RecordNumber=".$Arguments3." limit 1";
		$result = mysql_query($query) or die (mysql_error());
		if (mysql_num_rows($result) > 0) {
			
		
			$row = mysql_fetch_array($result);
		
		
		$BoardExists = false;
		$BoardViewable = false;
		
		
		$query222 = "select * from `".$Settings['DBPrefix']."mb-Boards` where RecordNumber='".$row['BoardID']."' and (MinLevel<=".$UserLevel."".$GroupsListSQL.") limit 1";
		$result222 = mysql_query($query222) or die (mysql_error());
		if (mysql_num_rows($result222) > 0) {
			$row222 = mysql_fetch_array($result222);
						
			$BoardTitle = $row222['Title'];
			$BoardDescription = $row222['Description'];
			$CategoryID = $row222['Category'];
			
						
			$query222 = "select Title,Description from `".$Settings['DBPrefix']."mb-Categories` where RecordNumber=".$CategoryID." and (MinLevel<=".$UserLevel."".$GroupsListSQL.") limit 1";
			$result222 = mysql_query($query222) or die (mysql_error());
			if (mysql_num_rows($result222) > 0) {
				$row222 = mysql_fetch_array($result222);
			
				$CategoryTitle = $row222['Title'];
				//$CategoryDescription = $row['Description'];
				
				$BoardViewable = true;
				$BoardExists = true;
			}
			else {
				$query222 = "select * from `".$Settings['DBPrefix']."mb-Boards` where RecordNumber='".$row['BoardID']."' limit 1";
				$result222 = mysql_query($query222) or die (mysql_error());
				if (mysql_num_rows($result222) > 0) {
					$BoardExists = true;
				}
			}
			
		}
		else {
			$query222 = "select * from `".$Settings['DBPrefix']."mb-Boards` where RecordNumber='".$row['BoardID']."' limit 1";
			$result222 = mysql_query($query222) or die (mysql_error());
			if (mysql_num_rows($result222) > 0) {
				$BoardExists = true;
			}
		}
			
			
		
		if ($BoardExists == true && $BoardViewable == true) {
		
			
		
		
			
			
			$MessagesCount = ($row['Replies'] + 1);
			$ThreadTitle = $row['Title'];
			$ThreadStatus = $row['Status'];
			$StickyStatus = $row['Sticky'];
			$ThreadStartedDate = $row['StartedDate'];			
			$ViewsCount = $row['Views'];
			$RepliesCount = $row['Replies'];
			
			
			$query = "update `".$Settings['DBPrefix']."mb-Threads` set Views=Views+1 where RecordNumber=".$Arguments3." limit 1";
			$result = mysql_query($query) or die (mysql_error());
			
			
			//$PageTitle = '<div align="'.$AlignmentCodes[$mbSettings['TitleAlignment']].'">'.$mbSettings['PageTitle'].'</div>';
			
			if ($mbSettings['TitleImage'] != '') {
				$PageTitle = '<div align="'.$AlignmentCodes[$mbSettings['TitleAlignment']].'"><img src="'.$BaseURL.$mbSettings['TitleImage'].'" alt="'.$mbSettings['PageTitle'].'" border="0"></div>';	
			}
			else {
				$PageTitle = '<div align="'.$AlignmentCodes[$mbSettings['TitleAlignment']].'">'.$mbSettings['PageTitle'].'</div>';
			}
			
			$BrowserTitle = $mbSettings['PageTitle'] . ' - ' . $BoardTitle . ' - ' . $ThreadTitle;
			$LocationBar = '<a href="'.$IndexURL.'">'.$MsgText[0][1].'</a> > <a href="'.$MainURL.'/forum.html">'.$mbSettings['PageTitle'].'</a> > <a href="'.$MainURL.'/forum.html#'.$CategoryID.'">'.$CategoryTitle.'</a> > <a href="'.$MainURL.'/forum/'.$row['BoardID'].'.html">'.$BoardTitle.'</a> > '.$ThreadTitle;
			
			
			
			ReadPermissions();
			Global $Permissions;
			
						
			for ($i = 33; $i <= 126; $i++) {
				$HTMLCodes[chr($i)] = $i;
			}
					
			
			
			$CharsToReplaceArray[';'] = 1;
			
			$SearchChars[] = '[';
			$ReplacementChars[] = '&#'.$HTMLCodes['['].';';
			$CharsToReplaceArray['['] = 1;
			
			$SearchChars[] = '/';
			$ReplacementChars[] = '&#'.$HTMLCodes['/'].';';
			$CharsToReplaceArray['/'] = 1;
			
			$SearchChars[] = ']';
			$ReplacementChars[] = '&#'.$HTMLCodes[']'].';';
			$CharsToReplaceArray[']'] = 1;
			
			$CharsToReplaceArray['&'] = 1;
			
			$CharsToReplaceArray['#'] = 1;
			
			$CharsToReplaceArray['l'] = 1;
			$CharsToReplaceArray['t'] = 1;
			
			
			for ($w = 0; $w <= 9; $w++) {
				$CharsToReplaceArray[$w] = 1;			
			}
			
			
			
					
			
			// smilies setup
				$query8 = "select * from `".$Settings['DBPrefix']."core-Smilies` where Enabled=1";
				$result8 = mysql_query($query8) or die (mysql_error());
				while ($row8 = mysql_fetch_array($result8)) {
				
					if ($row8['InsertCode'] != '') {
						$SmiliesCount++;
						$SmilieCodes[] = $row8['InsertCode'];
						$SmilieFiles[$row8['InsertCode']] = $row8['ImageLink'];
						$SmilieDescriptions[$row8['InsertCode']] = $row8['Description'];
					}
					if ($row8['InsertCode2'] != '') {
						$SmiliesCount++;
						$SmilieCodes[] = $row8['InsertCode2'];
						$SmilieFiles[$row8['InsertCode2']] = $row8['ImageLink'];
						$SmilieDescriptions[$row8['InsertCode2']] = $row8['Description'];
					}
					if ($row8['InsertCode3'] != '') {
						$SmiliesCount++;
						$SmilieCodes[] = $row8['InsertCode3'];
						$SmilieFiles[$row8['InsertCode3']] = $row8['ImageLink'];
						$SmilieDescriptions[$row8['InsertCode3']] = $row8['Description'];
					}
					if ($row8['InsertCode4'] != '') {
						$SmiliesCount++;
						$SmilieCodes[] = $row8['InsertCode4'];
						$SmilieFiles[$row8['InsertCode4']] = $row8['ImageLink'];
						$SmilieDescriptions[$row8['InsertCode4']] = $row8['Description'];
					}
					if ($row8['InsertCode5'] != '') {
						$SmiliesCount++;
						$SmilieCodes[] = $row8['InsertCode5'];
						$SmilieFiles[$row8['InsertCode5']] = $row8['ImageLink'];
						$SmilieDescriptions[$row8['InsertCode5']] = $row8['Description'];
					}
									
				}
				
				if ($SmiliesCount > 0) {
				
					for ($i = 0; $i < $SmiliesCount; $i++) {
						for ($h = 0; $h < ($SmiliesCount-1); $h++) {
						
							if (strlen($SmilieCodes[$h]) < strlen($SmilieCodes[$h+1])) {
									
								$Swap1 = $SmilieCodes[$h+1];
																	
								$SmilieCodes[$h+1] = $SmilieCodes[$h];
																
								$SmilieCodes[$h] = $Swap1;
									
							}
									
						}
					}
				
				
				
					for ($i = 0; $i < $SmiliesCount; $i++) {
									
						for ($x = 0; $x < strlen($SmilieCodes[$i]); $x++) {
						
							$CurrentChar = substr($SmilieCodes[$i], $x, 1);
		
							if ($CharsToReplaceArray[$CurrentChar] != 1) {
							
								$SearchChars[] = $CurrentChar;
								$ReplacementChars[] = '&#'.$HTMLCodes[$CurrentChar].';';
							
							}
						
						}
					
					}
				
				
				
					for ($i = 0; $i < $SmiliesCount; $i++) {
					
						/*
						$SmiliesSearchArray[] = ' '.$SmilieCodes[$i];
						$SmiliesSearchArray[] = '>'.$SmilieCodes[$i];
						
						if (substr($SmilieFiles[$SmilieCodes[$i]],0,4) != 'http') {
							$SmilieFiles[$SmilieCodes[$i]] = $ImagesURL . '/smilies/' . $SmilieFiles[$SmilieCodes[$i]]; 
						}
						
						$SmiliesReplaceArray[] = ' <img src="'.$SmilieFiles[$SmilieCodes[$i]].'" alt="'.$SmilieDescriptions[$SmilieCodes[$i]].'">';
						$SmiliesReplaceArray[] = '><img src="'.$SmilieFiles[$SmilieCodes[$i]].'" alt="'.$SmilieDescriptions[$SmilieCodes[$i]].'">';
						*/
						
						
						$SmiliesSearchArray[] = ' ' . $SmilieCodes[$i];
						
						if (substr($SmilieFiles[$SmilieCodes[$i]],0,4) != 'http') {
							$SmilieFiles[$SmilieCodes[$i]] = $ImagesURL . '/smilies/' . $SmilieFiles[$SmilieCodes[$i]]; 
						}
						
						$SmiliesReplaceArray[] = '<img src="'.$SmilieFiles[$SmilieCodes[$i]].'" alt="'.$SmilieDescriptions[$SmilieCodes[$i]].'"> ';
												
					
					}
				
				}
				else {
				
					$DoSmilies = false;
				
				}
			// end smilies setup
			
			
			
			
			if ($Usernames[$row['StartedBy']] != '') {
				if ($LoggedIn == 'y' && $row['StartedBy'] > 0) {
					$StartedByLink = '<a href="'.$MainURL.'/profile/'.$Usernames[$row['StartedBy']].'.html">'.$DisplayNames[$row['StartedBy']].'</a>';
				}
				else {
					$StartedByLink = $DisplayNames[$row['StartedBy']];
				}
			}
			else {
				$StartedByLink = $MsgText[2][65];
			}
				
		
			if ($Arguments4 < 1) {
				$Arguments4 = 1;			
			}
			
			$MaxPages = intval($MessagesCount / $mbSettings['MessagesPerPage']);
			if (($MessagesCount / $mbSettings['MessagesPerPage']) != intval($MessagesCount / $mbSettings['MessagesPerPage'])) {
				$MaxPages++;
			}
			//print $MaxPages;
			
			if ($Arguments4 > $MaxPages) {
				$Arguments4 = $MaxPages;
			}
			
			
			if ($MessagesCount > $mbSettings['MessagesPerPage']) {		
				$MessagesLimit = 'limit '.(($Arguments4 - 1) * $mbSettings['MessagesPerPage']).','.$mbSettings['MessagesPerPage'];
				//print $MessagesLimit;
			}
			else {
				$MessagesLimit = '';
			}
			
			
			if ($MaxPages > 1) {
				
				//if ($Arguments4 > 1) {
				//	$PageLinks = '<a href="'.$MainURL.'/forum/'.$Arguments2.'/'.$Arguments3.'/1.html">First</a> &nbsp;';
				//}
				//else {
				//	$PageLinks = 'First &nbsp;';
				//}
				
				//if ($Arguments4 > 1) {
				//	$PageLinks .= '<a href="'.$MainURL.'/forum/'.$Arguments2.'/'.$Arguments3.'/'.($Arguments4 - 1).'.html">Previous</a> | ';
				//}
				
				for ($i = 1; $i <= $MaxPages; $i++) {
					if ($i == $Arguments4) {
						$PageLinks .= '[' . $i . '] &nbsp;';
					}
					else {
						$PageLinks .= '<a href="'.$MainURL.'/forum/thread/'.$Arguments3.'/'.$i.'.html">'.$i.'</a> &nbsp;';
					}
				}
					
				//if ($Arguments4 < $MaxPages) {
				//	$PageLinks .= '<a href="'.$MainURL.'/forum/'.$Arguments2.'/'.$Arguments3.'/'.($Arguments4 + 1).'.html">Next</a> | ';
				//}
				
				//if ($Arguments4 < $MaxPages) {
				//	$PageLinks .= '<a href="'.$MainURL.'/forum/'.$Arguments2.'/'.$Arguments3.'/'.$MaxPages.'.html">Last</a>';
				//}
				//else {
				//	$PageLinks .= 'Last';
				//}
			
			}
			
			
			$query = "select * from `".$Settings['DBPrefix']."mb-Messages` where ThreadID=".$Arguments3." order by DateCode asc ".$MessagesLimit;
			$result = mysql_query($query) or die (mysql_error());
			
			if (mysql_num_rows($result) == 0) {
			
				$PageContents .= '<br><br><b>['.$MsgText[2][122].']</b>';
			
			}
			else {
				$MessagesList .= '<table width="100%" border="0" cellspacing="1" cellpadding="0">';
			
				
				$MessagesList .= '<tr><td><table width="100%" border="0" cellspacing="0" cellpadding="1"><tr><td bgcolor="'.$Colors['MBBorder'].'"><table width="100%" border="0" cellspacing="1" cellpadding="0"><tr><td bgcolor="'.$Colors['BG'].'"><table width="100%" border="0" cellspacing="0" cellpadding="0">';
			
			$RowsReturned = mysql_num_rows($result);
			//print '<br><br>'.$RowsReturned.'<br><br>';
			
			
			
			$BGColor = $Colors['MBBG'];
		

			for ($MessageCounter = 1; $MessageCounter <= $RowsReturned; $MessageCounter++) {
				$row = mysql_fetch_array($result);
				
				
				
				// fix old forum thread links in forum posts
				$row['Message'] = preg_replace("/(\/forum\/)([0-9]+)(\/)([0-9]+)(\.html)/ie", "'/forum/thread/\\4.html'", $row['Message']);
				
				
				
				
				//if ($UserLevel >= 50) {
				//	print '<br><br>'.$row['RecordNumber'].'<br>';
				//}

			
				// set up the posting user display (just the name for guests, link to profile for members)
				if ($Usernames[$row['Poster']] != '') {
					if ($LoggedIn == 'y' && $row['Poster'] > 0) {
						$PosterLink = '<a href="'.$MainURL.'/profile/'.$Usernames[$row['Poster']].'.html"><font color="'.$Colors['MBText'].'">'.$DisplayNames[$row['Poster']].'</font></a>';
					}
					else {
						$PosterLink = $DisplayNames[$row['Poster']];
					}
				}
				else {
					$PosterLink = $MsgText[2][65];
				}
				
				// set up the date display ("today", "yesterday", or the actual date, followed by the time)
				if (date("j/n/Y", GetTimestamp()) == date("j/n/Y", $row['DateCode'])) {
					$PostDate = $MsgText[2][66].' @ '.date("g:ia", $row['DateCode']);
				}
				else if (date("j/n/Y", (GetTimestamp()-(60*60*24))) == date("j/n/Y", $row['DateCode'])) {
					$PostDate = $MsgText[2][67].' @ '.date("g:ia", $row['DateCode']);
				}
				else {
					$PostDate = $MsgText[0][33+date("n",$row['DateCode'])].' '.date("j, Y @ g:ia", $row['DateCode']);
				}
				
	
				$row['Message'] = str_replace('<', '&lt;', $row['Message']);
				//$row['Message'] = str_replace("\n", '<br>', $row['Message']);
				//$row['Message'] = str_replace("\r", '', $row['Message']);
				
								
				$LowerCaseMessage = strtolower($row['Message']);
				
				
				// code -- do first
										
				// if [code] exists in message
				if (strpos($LowerCaseMessage,'[code]',0) !== false) {
				
					$Subject = $LowerCaseMessage;
					
					$OpenTags = '';
					$OpenTagsCount = 0;
					$CloseTags = '';
					$CloseTagsCount = 0;
					$AllTags = '';
					$AllTagsPos = '';
					$TotalTagsCount = 0;
					$AllTagsLevels = '';
					
					
					$Position = 0;
					$CurrentPos = 0;
										
					while (strpos($Subject,'[code]',$CurrentPos) !== false) {
						
						$Position = strpos($Subject,'[code]',$CurrentPos);
					
						$OpenTags[] = $Position;
						$OpenTagsCount++;
						$CurrentPos = $Position+strlen('[code]');
					
					}
					
		
					
					$Position = 0;
					$CurrentPos = 0;
					$Subject = strtolower($row['Message']);
					
					while (strpos($Subject,'[/code]',$CurrentPos) !== false) {
						
						$Position = strpos($Subject,'[/code]',$CurrentPos);
					
						$CloseTags[] = $Position;
						$CloseTagsCount++;
						$CurrentPos = $Position+strlen('[/code]');				
					}
					
					
					for ($i = 1; $i <= $OpenTagsCount; $i++) {
						$AllTags[] = 'open';
						$AllTagsPos[] = $OpenTags[$i-1];
					}
					for ($i = 1; $i <= $CloseTagsCount; $i++) {
						$AllTags[] = 'close';
						$AllTagsPos[] = $CloseTags[$i-1];
					}
									
					$TotalTagsCount = ($OpenTagsCount+$CloseTagsCount);
					
					
					for ($g = 0; $g < $TotalTagsCount; $g++) {
						for ($h = 0; $h < ($TotalTagsCount-1); $h++) {
	
							if ($AllTagsPos[$h] > $AllTagsPos[$h+1]) {
										
								$Swap1 = $AllTagsPos[$h+1];
								$Swap2 = $AllTags[$h+1];
																	
								$AllTagsPos[$h+1] = $AllTagsPos[$h];
								$AllTags[$h+1] = $AllTags[$h];
																	
								$AllTagsPos[$h] = $Swap1;
								$AllTags[$h] = $Swap2;
								
										
							}
						
						}
					}
				
					
					$Level = 1;
					for ($g = 0; $g < $TotalTagsCount; $g++) {
					
						if ($g > 0) {
						
							if ($AllTags[$g] == 'open' && $AllTags[$g-1] == 'open') {
								$Level++;
							}
							if ($AllTags[$g] == 'close' && $AllTags[$g-1] == 'close') {
								$Level--;
							}
						
						}
						
						$AllTagsLevels[$g] = $Level;
					
					}	
					
					
					
					
					for ($g = 0; $g < $TotalTagsCount; $g++) {
						for ($h = 0; $h < ($TotalTagsCount-1); $h++) {
	
							if ($AllTagsLevels[$h] > $AllTagsLevels[$h+1]) {
										
								$Swap1 = $AllTagsPos[$h+1];
								$Swap2 = $AllTags[$h+1];
								$Swap3 = $AllTagsLevels[$h+1];
																	
								$AllTagsPos[$h+1] = $AllTagsPos[$h];
								$AllTags[$h+1] = $AllTags[$h];
								$AllTagsLevels[$h+1] = $AllTagsLevels[$h];
																	
								$AllTagsPos[$h] = $Swap1;
								$AllTags[$h] = $Swap2;
								$AllTagsLevels[$h] = $Swap3;
								
										
							}
						
						}
					}
					
					
					
					// using the real version now, not the one converted to lower case for pattern matching:
					$Subject = $row['Message'];
												
					
					for ($g = 0; $g < $TotalTagsCount; $g=$g+2) {
										
						$FirstHalfBefore = substr($Subject,0,($AllTagsPos[$g]+6));
						$SecondHalfBefore = substr($Subject,$AllTagsPos[$g+1]);
						
						$LengthBefore = strlen($Subject);
						
						$Subject = $FirstHalfBefore . str_replace($SearchChars, $ReplacementChars, substr($Subject,($AllTagsPos[$g]+6), (($AllTagsPos[$g+1])-($AllTagsPos[$g]+6)) ) ) . $SecondHalfBefore;

						$LengthAfter = strlen($Subject);
					
						
						$AdditionalLength = ($LengthAfter-$LengthBefore);
					
						
						for ($h = ($g+2); $h < $TotalTagsCount; $h++) {
							$AllTagsPos[$h] = ($AllTagsPos[$h] + $AdditionalLength);			
						}
					
					}	
				
				
					$row['Message'] = $Subject;
								
				
					$row['Message'] = preg_replace("/(\[code\])(.*?)(\[\/code\])/sie", "'<img src=\"'.\$TemplateImagesURL.'/admin/spacer.gif\" border=\"0\" width=\"1\" height=\"10\" alt=\"\"><br><table width=\"90%\" border=\"0\" cellpadding=\"1\" cellspacing=\"0\"><tr><td bgcolor=\"'.\$Colors['MBQCBorder'].'\"><table width=\"100%\" border=\"0\" cellpadding=\"5\" cellspacing=\"0\"><tr><td bgcolor=\"'.\$Colors['MBQCBG'].'\"><font face=\"'.\$FontFace.'\" size=\"'.\$FontSize.'\" color=\"'.\$Colors['MBQCText'].'\"><b>Code</b><br><br>'.stripslashes('\\2').'</font></td></tr></table></td></tr></table>'", $row['Message']);


				} // end if [code] found in message
				
				
				
				// smilies
				//if ($DoSmilies != false) {		
					$row['Message'] = str_replace($SmiliesSearchArray, $SmiliesReplaceArray, $row['Message']);
				//}
				
				
				
				$row['Message'] = str_replace("\n", '[br]', $row['Message']);
				$row['Message'] = str_replace("\r", '', $row['Message']);
				
				
				// horizontal rule (hr)
				$row['Message'] = str_replace('[hr]', '<hr>', $row['Message']);
				
				
				// font faces and sizes
				$row['Message'] = preg_replace("/(\[font=)(.*?)(\])/i", "<font face=\"\\2\">", $row['Message']);
				$row['Message'] = preg_replace("/(\[size=)(.*?)(\])/i", "<font size=\"\\2\">", $row['Message']);
				
				$row['Message'] = str_replace('[/font]', '</font>', $row['Message']);
				$row['Message'] = str_replace('[/size]', '</font>', $row['Message']);
				
				
				// bold
				$row['Message'] = preg_replace("/(\[b\])(.*?)(\[\/b\])/i", "<b>\\2</b>", $row['Message']);
				//$row['Message'] = str_replace('[b]', '<b>', $row['Message']);
				//$row['Message'] = str_replace('[/b]', '</b>', $row['Message']);
				//$row['Message'] = preg_replace("/\[b\]/i", "<b>", $row['Message']); 
				//$row['Message'] = preg_replace("/\[\/b\]/i", "</b>", $row['Message']); 
				
				// italics
				$row['Message'] = preg_replace("/(\[i\])(.*?)(\[\/i\])/i", "<i>\\2</i>", $row['Message']);
				//$row['Message'] = str_replace('[i]', '<i>', $row['Message']);
				//$row['Message'] = str_replace('[/i]', '</i>', $row['Message']);
				//$row['Message'] = preg_replace("/\[i\]/i", "<i>", $row['Message']); 
				//$row['Message'] = preg_replace("/\[\/i\]/i", "</i>", $row['Message']);
				
				// underline
				$row['Message'] = preg_replace("/(\[u\])(.*?)(\[\/u\])/i", "<u>\\2</u>", $row['Message']);
				//$row['Message'] = str_replace('[u]', '<u>', $row['Message']);
				//$row['Message'] = str_replace('[/u]', '</u>', $row['Message']); 
				//$row['Message'] = preg_replace("/\[\/u\]/i", "</u>", $row['Message']);
				
				
				// colors
				$ColorCodes['black'] = '#000000';
				$ColorCodes['white'] = '#ffffff';
				$ColorCodes['red'] = '#ff0000';
				$ColorCodes['yellow'] = '#ffff00';
				$ColorCodes['green'] = '#008000';
				$ColorCodes['grey'] = '#888888';
				$ColorCodes['burgundy'] = '#990000';
				$ColorCodes['orange'] = '#ff9900';
				$ColorCodes['purple'] = '#9900ff';
				$ColorCodes['cream'] = '#ffffcc';
				$ColorCodes['teal'] = '#008080';
				$ColorCodes['salmon'] = '#ffcccc';
				$ColorCodes['blue'] = '#0000ff';
				$ColorCodes['pink'] = '#ff33cc';
				$ColorCodes['navy'] = '#003399';
				$ColorCodes['lightblue'] = '#33ccff';
				$ColorCodes['mauve'] = '#666699';
				$ColorCodes['limegreen'] = '#00ff00';
				
				//$row['Message'] = preg_replace("/(\[color\=)([a-zA-Z]+)(\])/i", "<font color=\"\\2\">", $row['Message']);
				$StringMatches = substr_count($row['Message'],'[color=');
				for ($i = 1; $i <= $StringMatches; $i++) {				
					$row['Message'] = preg_replace("/(\[color\=)(.*?)(\])(.*?)(\[\/color\])/ie", "'<font color='.\$ColorCodes['\\2'].'>'.stripslashes('\\4').'</font>'", $row['Message']);
				}
				 
				//$row['Message'] = preg_replace("/(\[\/color\])/", "</font>", $row['Message']); 
				  
				
				
				// urls
				$row['Message'] = preg_replace("/(\[url=\")(.*?)(\"\])(.*?)(\[\/url\])/ie", "'<a href=\"\\2\" target=\"_blank\"><font color=\"'.\$Colors['MBText'].'\">\\4</font></a>'", $row['Message']);
				
				// urls
				$row['Message'] = preg_replace("/(\[url=)(.*?)(\])(.*?)(\[\/url\])/ie", "'<a href=\"\\2\" target=\"_blank\"><font color=\"'.\$Colors['MBText'].'\">\\4</font></a>'", $row['Message']);			
				
				$row['Message'] = preg_replace("/(\[url\])(.*?)(\[\/url\])/ie", "'<a href=\"\\2\" target=\"_blank\"><font color=\"'.\$Colors['MBText'].'\">'.FormatLongURL('\\2').'</font></a>'", $row['Message']);
				
				
									
				// images
				$row['Message'] = preg_replace("/(\[img\])(.*?)(\[\/img\])/i", "<img src=\"\\2\" border=\"0\" alt=\"\">", $row['Message']);
				
				
				
				
		
				// convert URLs in text to clickable tags
				$row['Message'] = preg_replace("/(?<!\"|\>)(http:\/\/)([\w\.\-\/]+)/e", "'<a href=\"\\0\" target=\"_blank\"><font color=\"'.\$Colors['MBText'].'\">\\0</font></a>'", $row['Message']);
				
				
								
				$row['Message'] = str_replace('[br]', '<br>', $row['Message']);
				
				
				
				// emails
				
				// if [email] exists in the message
				if (strpos($LowerCaseMessage,'[email]',0) !== false) {
				
					$StringLength1 = rand(8, 14);
					$StringLength2 = rand(6, 15);
					$CharactersArray = array ('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','1','2','3','4','5','6','7','8','9','0');								
					$Random1 = 'a';
					$Random2 = 'b';
					for ($i = 1; $i <= $StringLength1; $i++) {
						$RandomNum = rand(1, 62);
						$Random1 .= $CharactersArray[$RandomNum];
					}
					for ($i = 1; $i <= $StringLength2; $i++) {
						$RandomNum = rand(1, 62);
						$Random2 .= $CharactersArray[$RandomNum];
					}
				
				
					$row['Message'] = preg_replace("/(\[email\])(.*?)(@)(.*?)(\[\/email\])/ie", "'<script language=\"JavaScript\">var '.\$Random1.' = \'\\2\'; var '.\$Random2.' = \'\\4\'; document.write(\'<a href=\"mai\'+\'lto:\'+'.\$Random1.'+String.fromCharCode(64)+'.\$Random2.'+\'\"><font color=\"'.\$Colors['MBText'].'\">\'+'.\$Random1.'+String.fromCharCode(64)+'.\$Random2.'+\'</font></a>\');</script>'", $row['Message']);			
				
				} // end if [email] found in message
				
				
				// alignment
				/*
				$row['Message'] = str_replace('[left]', '<div align="left">', $row['Message']);
				$row['Message'] = str_replace('[/left]', '</div>', $row['Message']);
				$row['Message'] = str_replace('[center]', '<div align="center">', $row['Message']);
				$row['Message'] = str_replace('[/center]', '</div>', $row['Message']);
				$row['Message'] = str_replace('[right]', '<div align="right">', $row['Message']);
				$row['Message'] = str_replace('[/right]', '</div>', $row['Message']);
				*/
				$row['Message'] = preg_replace("/(\[left\])(.*?)(\[\/left\])/i", "<div align=\"left\">\\2</div>", $row['Message']);
				$row['Message'] = preg_replace("/(\[center\])(.*?)(\[\/center\])/i", "<div align=\"center\">\\2</div>", $row['Message']);
				$row['Message'] = preg_replace("/(\[right\])(.*?)(\[\/right\])/i", "<div align=\"right\">\\2</div>", $row['Message']);
				
				
				
				// quotes -- do last
				
				$row['Message'] = str_replace('[quote=][/quote]','',$row['Message']);
				
				// if [quote exists in the message
				if (strpos($LowerCaseMessage,'[quote',0) !== false) {
				
					// quotes with a user
					$StringMatches = substr_count($row['Message'],'[quote=');
					for ($i = 1; $i <= $StringMatches; $i++) {				
						//$row['Message'] = preg_replace("/(\[quote=)(.*?)(\])(.*?)(\[\/quote\])/ie", "'<img src=\"'.\$TemplateImagesURL.'/admin/spacer.gif\" border=\"0\" width=\"1\" height=\"10\" alt=\"\"><br><table width=\"90%\" border=\"0\" cellpadding=\"1\" cellspacing=\"0\"><tr><td bgcolor=\"'.\$Colors['MBQCBorder'].'\"><table width=\"100%\" border=\"0\" cellpadding=\"5\" cellspacing=\"0\"><tr><td bgcolor=\"'.\$Colors['MBQCBG'].'\"><font face=\"'.\$FontFace.'\" size=\"'.\$FontSize.'\" color=\"'.\$Colors['MBQCText'].'\"><b>Quote ('.stripslashes(\$DisplayNames[\\2]).')</b><br><br>'.stripslashes('\\4').'</font></td></tr></table></td></tr></table>'", stripslashes($row['Message']));
						$row['Message'] = preg_replace("/(\[quote=)([0-9]*?)(\])(.*?)(\[\/quote\])/ie", "'<img src=\"'.\$TemplateImagesURL.'/admin/spacer.gif\" border=\"0\" width=\"1\" height=\"10\" alt=\"\"><br><table width=\"90%\" border=\"0\" cellpadding=\"1\" cellspacing=\"0\"><tr><td bgcolor=\"'.\$Colors['MBQCBorder'].'\"><table width=\"100%\" border=\"0\" cellpadding=\"5\" cellspacing=\"0\"><tr><td bgcolor=\"'.\$Colors['MBQCBG'].'\"><font face=\"'.\$FontFace.'\" size=\"'.\$FontSize.'\" color=\"'.\$Colors['MBQCText'].'\"><b>Quote ('.stripslashes(\$DisplayNames[\\2]).')</b><br><br>'.stripslashes('\\4').'</font></td></tr></table></td></tr></table>'", stripslashes($row['Message']));
					}
					// quotes without a user
					$StringMatches = substr_count($row['Message'],'[quote]');
					for ($i = 1; $i <= $StringMatches; $i++) {				
						$row['Message'] = preg_replace("/(\[quote\])(.*?)(\[\/quote\])/ie", "'<img src=\"'.\$TemplateImagesURL.'/admin/spacer.gif\" border=\"0\" width=\"1\" height=\"10\" alt=\"\"><br><table width=\"90%\" border=\"0\" cellpadding=\"1\" cellspacing=\"0\"><tr><td bgcolor=\"'.\$Colors['MBQCBorder'].'\"><table width=\"100%\" border=\"0\" cellpadding=\"5\" cellspacing=\"0\"><tr><td bgcolor=\"'.\$Colors['MBQCBG'].'\"><font face=\"'.\$FontFace.'\" size=\"'.\$FontSize.'\" color=\"'.\$Colors['MBQCText'].'\"><b>Quote</b><br><br>'.stripslashes('\\2').'</font></td></tr></table></td></tr></table>'", $row['Message']);
					}
				
				
				} // end if [quote exists in the message
				
				
				
				// smilies				
				//$row['Message'] = str_replace($SmiliesSearchArray, $SmiliesReplaceArray, $row['Message']);
				
				
				
				
				
				
				// end of pattern matching
				
				
				
				if ($PosterLink != $MsgText[2][65]) {
					$Avatar = '';
					if ($AvatarURLs[$row['Poster']] != '') {
						$Avatar = '<br><br><img src="'.$AvatarURLs[$row['Poster']].'" width="100" height="100" alt="" border="0">';
					}				
				
					$UserInformation = $PosterLink.'<br>'.$UserTitles[$row['Poster']].$Avatar.'<br><br><font size="'.($FontSize-1).'">Posts: '.number_format($PostsCount[$row['Poster']],0).'</font>';
				}
				else {
					$UserInformation = $MsgText[2][65];
				}
				
				
				$SignatureSection = '';
				if ($UserSignatures[$row['Poster']] != '') {
					$SignatureSection = '<br><img src="'.$ImagesURL.'/admin/spacer.gif" width="1" height="45" alt="" border="0"><br><table width="40%" cellpadding="0" cellspacing="0" border="0"><tr><td bgcolor="'.$Colors['MBText'].'"><img src="'.$ImagesURL.'/admin/spacer.gif" width="1" height="1" alt="" border="0"></td></tr></table><img src="'.$ImagesURL.'/admin/spacer.gif" width="1" height="12" alt="" border="0"><br>'.$UserSignatures[$row['Poster']];
				}
				
							
				$MessagesList .= '<tr>
						
				<td width="19%" height="100%"><table width="100%" height="100%" border="0" cellspacing="0" cellpadding="4"><tr><td valign="top" bgcolor="'.$BGColor.'"><a name="'.$MessageCounter.'"></a><a name="msg'.$row['RecordNumber'].'"></a><font face="'.$FontFace.'" size="'.$FontSize.'" color="'.$Colors['MBText'].'">'.$UserInformation.'</font></td></tr></table></td>

				<td width="1%" height="100%" bgcolor="'.$BGColor.'"><table width="100%" height="100%" border="0" cellspacing="0" cellpadding="4"><tr><td align="center" valign="middle">&nbsp;</td></tr></table></td>

				<td width="80%" height="100%" bgcolor="'.$BGColor.'"><table width="100%" height="100%" border="0" cellspacing="0" cellpadding="4"><tr><td valign="top"><font face="'.$FontFace.'" size="'.$FontSize.'" color="'.$Colors['MBText'].'"><b>'.$row['Subject'].'</b></td><td valign="top" align="right"><font face="'.$FontFace.'" size="'.$FontSize.'" color="'.$Colors['MBText'].'">'.$PostDate.'</td></tr><tr><td colspan="2" valign="top"><font face="'.$FontFace.'" size="'.$FontSize.'" color="'.$Colors['MBText'].'">'.$row['Message'].$SignatureSection.'</font></td></tr></table></td>
												
				</tr>';
				
								
				
				if ($Permissions[202] == 'y' || ($row['Poster'] == $ThisUserNumber && $ThreadStatus != 'L')) {
					$ManagementLinks = '[ <a href="'.$MainURL.'/forum/message-compose/'.$Arguments3.'/'.$row['RecordNumber'].'.html"><font color="'.$Colors['MBText'].'">'.$MsgText[2][87].'</font></a> | <a href="'.$MainURL.'/forum/message-edit/'.$row['RecordNumber'].'.html"><font color="'.$Colors['MBText'].'">'.$MsgText[0][155].'</font></a> | <a href="'.$MainURL.'/forum/message-delete/'.$row['RecordNumber'].'.html"><font color="'.$Colors['MBText'].'">'.$MsgText[0][156].'</font></a> ]';
				}
				else if ($LoggedIn == 'y' && $ThreadStatus != 'L') {
					$ManagementLinks = '[ <a href="'.$MainURL.'/forum/message-compose/'.$Arguments3.'/'.$row['RecordNumber'].'.html"><font color="'.$Colors['MBText'].'">'.$MsgText[2][87].'</font></a> ]';
				}
				else {
					$ManagementLinks = '';
				}
				
				
				if ($row['LastEditTime'] > 0) {
				
					if ($Usernames[$row['LastEditUser']] != '') {
						if ($LoggedIn == 'y') {
							$LastEditLink = '<a href="'.$MainURL.'/profile/'.$Usernames[$row['LastEditUser']].'.html"><font color="'.$Colors['MBText'].'">'.$DisplayNames[$row['LastEditUser']].'</font></a>';
						}
						else {
							$LastEditLink = $DisplayNames[$row['LastEditUser']];
						}
					}
					else {
						$LastEditLink = $MsgText[2][65];
					}
				

					if (date("j/n/Y", GetTimestamp()) == date("j/n/Y", $row['LastEditTime'])) {
						$LastEditTime = $MsgText[2][66].' @ '.date("g:ia", $row['LastEditTime']);
					}
					else if (date("j/n/Y", (GetTimestamp()-(60*60*24))) == date("j/n/Y", $row['LastEditTime'])) {
						$LastEditTime = $MsgText[2][67].' @ '.date("g:ia", $row['LastEditTime']);
					}
					else {
						$LastEditTime = $MsgText[0][33+date("n",$row['LastEditTime'])].' '.date("j, Y @ g:ia", $row['LastEditTime']);
					}
				
				
					$LastEditInfo = '<br><i>'.$MsgText[2][123].': '.$LastEditTime.' '.$MsgText[2][78].' '.$LastEditLink.'</i>';
				}
				else {
					$LastEditInfo = '';
				}
				
				
				$IPAddressPrint = '';
				if ($Permissions[203] == 'y') {
					$IPAddressPrint = hexdec(substr($row['PosterIP'],0,2)) . '.' . hexdec(substr($row['PosterIP'],2,2)) . '.' . hexdec(substr($row['PosterIP'],4,2)) . '.' . hexdec(substr($row['PosterIP'],6,2));

					if ($IPAddressPrint == '0.0.0.0') {
						$IPAddressPrint = '';
					}
				}
				
				
				
				$MessagesList .= '<tr>
						
				<td width="19%" height="100%" bgcolor="'.$BGColor.'"><table width="100%" height="100%" border="0" cellspacing="0" cellpadding="4"><tr><td valign="bottom"><font face="'.$FontFace.'" size="'.($FontSize-1).'" color="'.$Colors['MBText'].'">'.$IPAddressPrint.'</font></font></td></tr></table></td>

				<td width="1%" height="100%" bgcolor="'.$BGColor.'"><table width="100%" height="100%" border="0" cellspacing="0" cellpadding="4"><tr><td align="center" valign="middle">&nbsp;</td></tr></table></td>

				<td width="80%" height="100%" bgcolor="'.$BGColor.'"><table width="100%" height="100%" border="0" cellspacing="0" cellpadding="4"><tr><td width="50%"><font face="'.$FontFace.'" size="'.($FontSize-1).'" color="'.$Colors['MBText'].'">'.$LastEditInfo.'</font></td><td valign="bottom" width="50%" align="right"><font face="'.$FontFace.'" size="'.$FontSize.'" color="'.$Colors['MBText'].'">'.$ManagementLinks.'</td></tr></table></td>
								
				</tr>';
				
				
						
				
				if ($MessageCounter < $RowsReturned) {
						$MessagesList .= '</table></td></tr></table></td></tr></table></td></tr><tr><td height="1" align="center"><table width="98%" border="0" cellpadding="0" cellspacing="0"><tr><td height="1" bgcolor="'.$Colors['MBSpacerLine'].'"><img src="'.$TemplateImagesURL.'/admin/spacer.gif" border="0" width="1" height="1" alt=""></td></tr></table></td></tr><tr><td><table width="100%" border="0" cellspacing="0" cellpadding="1"><tr><td bgcolor="'.$Colors['MBBorder'].'"><table width="100%" border="0" cellspacing="1" cellpadding="0"><tr><td bgcolor="'.$Colors['MBBG'].'"><table width="100%" border="0" cellspacing="0" cellpadding="0">';
				}		
				
				
				
					if ($BGColor == $Colors['MBBG']) {
						$BGColor = $Colors['MBAlternateBG'];
					}
					else {
						$BGColor = $Colors['MBBG'];
					}
				
						
				}
				
				
				$MessagesList .= '</table></td></tr></table></td></tr></table></td></tr>';
				
				
				$MessagesList .= '</table>';
				
			}	
			
			
			if ($ThreadStatus == 'L') {
				if ($Permissions[202] == 'y') {
					$ReplyLink = '<a href="'.$MainURL.'/forum/message-compose/'.$Arguments3.'.html"><b>'.$MsgText[2][73].' ('.$MsgText[2][116].')</b></a>';
				}
				else {
					$ReplyLink = '('.$MsgText[2][124].')';
				}
			}
			else {
				$ReplyLink = '<a href="'.$MainURL.'/forum/message-compose/'.$Arguments3.'.html"><b>'.$MsgText[2][73].'</b></a>';
			}
			
			
			
			$PageContents = $PrintEmailLinks.'<table width="100%" border="0" cellpadding="0" cellspacing="0"><tr>
    		<td><font face="'.$FontFace.'" size="'.$FontSize.'"><b>'.$ThreadTitle.'</b><br><font size="'.($FontSize-1).'">'.$MsgText[2][125].' '.$MsgText[0][33+date("n",$ThreadStartedDate)].' '.date("j, Y @ g:ia", $ThreadStartedDate).' '.$MsgText[2][78].' '.$StartedByLink.'<br></font><img src="'.$TemplateImagesURL.'/admin/spacer.gif" border="0" width="1" height="10" alt=""></td>
			<td align="right"><font face="'.$FontFace.'" size="'.$FontSize.'">'.$ReplyLink.'&nbsp;</td>
			</tr></table>';
			
			
			if ($MaxPages > 1) {
			
				$PageContents .= '<table width="100%" border="0" cellpadding="0" cellspacing="0"><tr>
    			<td><font face="'.$FontFace.'" size="'.$FontSize.'"><div align="center"><b>'.$MsgText[2][126].': &nbsp;'.$PageLinks.'</b></div></td>
				</tr></table><img src="'.$TemplateImagesURL.'/admin/spacer.gif" border="0" width="1" height="8" alt=""><br>';
			
			}
			
			
			$PageContents .=  $MessagesList;
			
			
			if ($MaxPages > 1) {
			
				$PageContents .= '<img src="'.$TemplateImagesURL.'/admin/spacer.gif" border="0" width="1" height="8" alt=""><br><table width="100%" border="0" cellpadding="0" cellspacing="0"><tr>
    			<td><font face="'.$FontFace.'" size="'.$FontSize.'"><div align="center"><b>'.$MsgText[2][126].': &nbsp;'.$PageLinks.'</b></div></td>
				</tr></table>';
			
			}
			
			
			if ($LoggedIn == 'y') {
			
				$query55 = "select RecordNumber from `".$Settings['DBPrefix']."core-Users` where Username='".$CookieUsername."' and NotifyThreads like '%-".$Arguments3."-%' limit 1";
				$result55 = mysql_query($query55) or die (mysql_error());
				if (mysql_num_rows($result55) == 0) {
			
					$TrackingAndModeratorLinks = '<font face="'.$FontFace.'" size="'.$FontSize.'">&nbsp;<a href="'.$MainURL.'/forum/thread-track/'.$Arguments3.'.html"><b>'.$MsgText[2][127].'</b></a>';

				}
				else {
				
					$TrackingAndModeratorLinks = '<font face="'.$FontFace.'" size="'.$FontSize.'">&nbsp;<a href="'.$MainURL.'/forum/thread-track/'.$Arguments3.'.html"><b>'.$MsgText[2][128].'</b></a>';
				
				}
			
			}
			
			
			if ($Permissions[202] == 'y') {
				$TrackingAndModeratorLinks .= '<br><br><font face="'.$FontFace.'" size="1">&nbsp;<a href="'.$MainURL.'/forum/thread-move/'.$Arguments3.'.html"><b>'.$MsgText[2][101].'</b></a> | <a href="'.$MainURL.'/forum/thread-delete/'.$Arguments3.'.html"><b>'.$MsgText[2][97].'</b></a>';

				if ($ThreadStatus == 'L') {
					$TrackingAndModeratorLinks .= ' | <a href="'.$MainURL.'/forum/thread-lock/'.$Arguments3.'.html"><b>'.$MsgText[2][129].'</b></a>';
				}
				else {
					$TrackingAndModeratorLinks .= ' | <a href="'.$MainURL.'/forum/thread-lock/'.$Arguments3.'.html"><b>'.$MsgText[2][130].'</b></a>';
				}
				
				
				if ($StickyStatus == 'y') {
					$TrackingAndModeratorLinks .= ' | <a href="'.$MainURL.'/forum/thread-sticky/'.$Arguments3.'.html"><b>'.$MsgText[2][131].'</b></a>';
				}
				else {
					$TrackingAndModeratorLinks .= ' | <a href="'.$MainURL.'/forum/thread-sticky/'.$Arguments3.'.html"><b>'.$MsgText[2][132].'</b></a>';
				}
			
			}
			
			
			$PageContents .= '<img src="'.$TemplateImagesURL.'/admin/spacer.gif" border="0" width="1" height="10" alt=""><br><table width="100%" border="0" cellpadding="0" cellspacing="0"><tr><td>'.$TrackingAndModeratorLinks.'</td><td align="right"><font face="'.$FontFace.'" size="'.$FontSize.'">'.$ReplyLink.'&nbsp;</td></tr></table>';

			
			
			
		} // allowed to view board & category
		else if ($BoardExists == true) {
				
			//$PageTitle = '<div align="'.$AlignmentCodes[$mbSettings['TitleAlignment']].'">'.$mbSettings['PageTitle'].'</div>';
			
			if ($mbSettings['TitleImage'] != '') {
				$PageTitle = '<div align="'.$AlignmentCodes[$mbSettings['TitleAlignment']].'"><img src="'.$BaseURL.$mbSettings['TitleImage'].'" alt="'.$mbSettings['PageTitle'].'" border="0"></div>';	
			}
			else {
				$PageTitle = '<div align="'.$AlignmentCodes[$mbSettings['TitleAlignment']].'">'.$mbSettings['PageTitle'].'</div>';
			}
			
			$BrowserTitle = $mbSettings['PageTitle'];
			$LocationBar = '<a href="'.$IndexURL.'">'.$MsgText[0][1].'</a> > '.$mbSettings['PageTitle'];
			
			$PageContents = '<br>'.$MsgText[2][135];
			
			if ($LoggedIn != 'y') {
				$PageContents .= '<br><br>'.$MsgText[2][61].': <a href="'.$MainURL.'/login/forum+++thread+++'.$Arguments3.'.html">'.$MsgText[0][192].'</a>';
			}
			
		
		} // not allowed to view board or category
		else {
		
			//$PageTitle = '<div align="'.$AlignmentCodes[$mbSettings['TitleAlignment']].'">'.$mbSettings['PageTitle'].'</div>';
			if ($mbSettings['TitleImage'] != '') {
				$PageTitle = '<div align="'.$AlignmentCodes[$mbSettings['TitleAlignment']].'"><img src="'.$BaseURL.$mbSettings['TitleImage'].'" alt="'.$mbSettings['PageTitle'].'" border="0"></div>';	
			}
			else {
				$PageTitle = '<div align="'.$AlignmentCodes[$mbSettings['TitleAlignment']].'">'.$mbSettings['PageTitle'].'</div>';
			}
			
			
			$BrowserTitle = $mbSettings['PageTitle'];
			$LocationBar = '<a href="'.$IndexURL.'">'.$MsgText[0][1].'</a> > <a href="'.$MainURL.'/forum.html">'.$mbSettings['PageTitle'].'</a> > '.$MsgText[2][120];
			
			$PageContents = '<br>'.$MsgText[2][121];
		
		} // board or category doesn't exist
		
		
		} // thread exists
		else {
			
			//$PageTitle = '<div align="'.$AlignmentCodes[$mbSettings['TitleAlignment']].'">'.$mbSettings['PageTitle'].'</div>';
			
			if ($mbSettings['TitleImage'] != '') {
				$PageTitle = '<div align="'.$AlignmentCodes[$mbSettings['TitleAlignment']].'"><img src="'.$BaseURL.$mbSettings['TitleImage'].'" alt="'.$mbSettings['PageTitle'].'" border="0"></div>';	
			}
			else {
				$PageTitle = '<div align="'.$AlignmentCodes[$mbSettings['TitleAlignment']].'">'.$mbSettings['PageTitle'].'</div>';
			}
				
				
			$BrowserTitle = $mbSettings['PageTitle'] . ' - ' . $BoardTitle . ' - ' . $ThreadTitle;
			$LocationBar = '<a href="'.$IndexURL.'">'.$MsgText[0][1].'</a> > <a href="'.$MainURL.'/forum.html">'.$mbSettings['PageTitle'].'</a> > '.$MsgText[2][133];
			
			$PageContents = '<br>'.$MsgText[2][134];
			
		} // thread doesn't exist
	
		
	} // end if $Arguments2 == 'thread' && $Arguments3 != '' (view messages in a thread)
	
	
	// list of threads in a board
	else if ($Arguments2 != '') {
	
		$Arguments2 = intval($Arguments2);
		$Arguments3 = intval($Arguments3);
		
		$mbSettings['ThreadsPerPage'] = intval($mbSettings['ThreadsPerPage']);
		
				
		/*		
		$query = "select `".$Settings['DBPrefix']."mb-Boards`.MinLevel as BMinLevel,`".$Settings['DBPrefix']."mb-Categories`.MinLevel as CMinLevel from `".$Settings['DBPrefix']."mb-Boards` left join `".$Settings['DBPrefix']."mb-Categories` on `".$Settings['DBPrefix']."mb-Categories`.RecordNumber=`".$Settings['DBPrefix']."mb-Boards`.Category where `".$Settings['DBPrefix']."mb-Boards`.RecordNumber='".$Arguments2."' limit 1";
		$result = mysql_query($query) or die (mysql_error());
		
		if (mysql_num_rows($result) > 0) {
		// board exists
		
			$row = mysql_fetch_array($result);
		
		if ($row['BMinLevel'] <= $UserLevel && $row['CMinLevel'] <= $UserLevel) {
		*/
		
		
		$BoardExists = false;
		$BoardViewable = false;
		
		
		$query = "select * from `".$Settings['DBPrefix']."mb-Boards` where RecordNumber='".$Arguments2."' and (MinLevel<=".$UserLevel."".$GroupsListSQL.") limit 1";
		$result = mysql_query($query) or die (mysql_error());
		if (mysql_num_rows($result) > 0) {
			$row = mysql_fetch_array($result);
						
			$BoardTitle = $row['Title'];
			$BoardDescription = $row['Description'];
			$CategoryID = $row['Category'];
			
						
			$query = "select Title,Description from `".$Settings['DBPrefix']."mb-Categories` where RecordNumber=".$CategoryID." and (MinLevel<=".$UserLevel."".$GroupsListSQL.") limit 1";
			$result = mysql_query($query) or die (mysql_error());
			if (mysql_num_rows($result) > 0) {
				$row = mysql_fetch_array($result);
			
				$CategoryTitle = $row['Title'];
				//$CategoryDescription = $row['Description'];
				
				$BoardViewable = true;
				$BoardExists = true;
			}
			else {
				$query = "select * from `".$Settings['DBPrefix']."mb-Boards` where RecordNumber='".$Arguments2."' limit 1";
				$result = mysql_query($query) or die (mysql_error());
				if (mysql_num_rows($result) > 0) {
					$BoardExists = true;
				}
			}
			
		}
		else {
			$query = "select * from `".$Settings['DBPrefix']."mb-Boards` where RecordNumber='".$Arguments2."' limit 1";
			$result = mysql_query($query) or die (mysql_error());
			if (mysql_num_rows($result) > 0) {
				$BoardExists = true;
			}
		}
			
			
		
		if ($BoardExists == true) {
		
		if ($BoardViewable == true) {
			
			
			//$PageTitle = '<div align="'.$AlignmentCodes[$mbSettings['TitleAlignment']].'">'.$mbSettings['PageTitle'].'</div>';
			
			if ($mbSettings['TitleImage'] != '') {
				$PageTitle = '<div align="'.$AlignmentCodes[$mbSettings['TitleAlignment']].'"><img src="'.$BaseURL.$mbSettings['TitleImage'].'" alt="'.$mbSettings['PageTitle'].'" border="0"></div>';	
			}
			else {
				$PageTitle = '<div align="'.$AlignmentCodes[$mbSettings['TitleAlignment']].'">'.$mbSettings['PageTitle'].'</div>';
			}
			
			
			$BrowserTitle = $mbSettings['PageTitle'] . ' - ' . $BoardTitle;
			$LocationBar = '<a href="'.$IndexURL.'">'.$MsgText[0][1].'</a> > <a href="'.$MainURL.'/forum.html">'.$mbSettings['PageTitle'].'</a> > <a href="'.$MainURL.'/forum.html#'.$CategoryID.'">'.$CategoryTitle.'</a> > '.$BoardTitle;
			
			
			//$PageContents = '<b>'.$BoardTitle.'</b><br><font size="'.($FontSize-1).'">'.$BoardDescription.'<br></font><img src="'.$TemplateImagesURL.'/admin/spacer.gif" border="0" width="1" height="10" alt="">';
			$PageContents = '<table width="100%" border="0" cellpadding="0" cellspacing="0"><tr>
			<td><font face="'.$FontFace.'" size="'.$FontSize.'"><b>'.$BoardTitle.'</b><br><font size="'.($FontSize-1).'">'.$BoardDescription.'<br></font><img src="'.$TemplateImagesURL.'/admin/spacer.gif" border="0" width="1" height="10" alt=""></td>
			<td align="right"><font face="'.$FontFace.'" size="'.$FontSize.'"><a href="'.$MainURL.'/forum/thread-compose/'.$Arguments2.'.html"><b>'.$MsgText[2][94].'</b></a>&nbsp;</td>
			</tr></table>';
			
			
			
			
			$query = "select * from `".$Settings['DBPrefix']."mb-Threads` where BoardID=".$Arguments2;
			$result = mysql_query($query) or die (mysql_error());
			$ThreadsCount = mysql_num_rows($result);
				
			
			if ($ThreadsCount > 0) {
			
			
			
			
			if ($Arguments3 < 1) {
				$Arguments3 = 1;			
			}
				
			$MaxPages = intval($ThreadsCount / $mbSettings['ThreadsPerPage']);
			if (($ThreadsCount / $mbSettings['ThreadsPerPage']) != intval($ThreadsCount / $mbSettings['ThreadsPerPage'])) {
				$MaxPages++;
			}
						
			if ($Arguments3 > $MaxPages) {
				$Arguments3 = $MaxPages;
			}
			
			
			if ($ThreadsCount > $mbSettings['ThreadsPerPage']) {		
				$ThreadsLimit = 'limit '.(($Arguments3 - 1) * $mbSettings['ThreadsPerPage']).','.$mbSettings['ThreadsPerPage'];				
			}
			else {
				$ThreadsLimit = '';
			}
			
			
			if ($MaxPages > 1) {
				
				
				for ($i = 1; $i <= $MaxPages; $i++) {
					if ($i == $Arguments3) {
						$PageLinks .= '[' . $i . '] &nbsp;';
					}
					else {
						$PageLinks .= '<a href="'.$MainURL.'/forum/'.$Arguments2.'/'.$i.'.html">'.$i.'</a> &nbsp;';
					}
				}
								
				
			}
			
			
			
			
			$query = "select * from `".$Settings['DBPrefix']."mb-Threads` where BoardID=".$Arguments2." order by Sticky desc, LastReply desc ".$ThreadsLimit;
			$result = mysql_query($query) or die (mysql_error());
			
			
			
				$ThreadsList .= '<table width="100%" border="0" cellspacing="1" cellpadding="0">';
			
				
				$ThreadsList .= '<tr><td><table width="100%" border="0" cellspacing="0" cellpadding="1"><tr><td bgcolor="'.$Colors['MBBorder'].'"><table width="100%" border="0" cellspacing="1" cellpadding="0"><tr><td bgcolor="'.$Colors['BG'].'"><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr>

				<td bgcolor="'.$Colors['MBHeadingBG'].'" height="100%"><table width="100%" height="100%" border="0" cellspacing="0" cellpadding="4"><tr><td valign="middle"><font face="'.$FontFace.'" size="'.$FontSize.'" color="'.$Colors['MBHeadingText'].'">'.$MsgText[2][71].'</font></td></tr></table></td>


				<td bgcolor="'.$Colors['MBHeadingBG'].'" height="100%"><table width="100%" height="100%" border="0" cellspacing="0" cellpadding="4"><tr><td align="center" valign="middle"><font face="'.$FontFace.'" size="'.$FontSize.'" color="'.$Colors['MBHeadingText'].'">'.$MsgText[2][113].'</td></tr></table></td>

				<td bgcolor="'.$Colors['MBHeadingBG'].'" height="100%"><table width="100%" height="100%" border="0" cellspacing="0" cellpadding="4"><tr><td align="center" valign="middle"><font face="'.$FontFace.'" size="'.$FontSize.'" color="'.$Colors['MBHeadingText'].'">'.$MsgText[2][114].'</td></tr></table></td>

				<td bgcolor="'.$Colors['MBHeadingBG'].'" height="100%"><table width="100%" height="100%" border="0" cellspacing="0" cellpadding="4"><tr><td align="center" valign="middle"><font face="'.$FontFace.'" size="'.$FontSize.'" color="'.$Colors['MBHeadingText'].'">'.$MsgText[2][115].'</td></tr></table></td>

				<td bgcolor="'.$Colors['MBHeadingBG'].'" height="100%"><table width="100%" height="100%" border="0" cellspacing="0" cellpadding="4"><tr><td align="center" valign="middle"><font face="'.$FontFace.'" size="'.$FontSize.'" color="'.$Colors['MBHeadingText'].'">'.$MsgText[2][111].'</td></tr></table></td>

				</tr>

				<tr><td colspan="5" height="2" bgcolor="'.$Colors['MBBorder'].'"><img src="'.$TemplateImagesURL.'/admin/spacer.gif" border="0" width="1" height="2" alt=""></td></tr>';

				
				
				$BGColor = $Colors['MBBG'];
				


				while ($row = mysql_fetch_array($result)) {
				
					if ($Usernames[$row['StartedBy']] != '') {
						if ($LoggedIn == 'y' && $row['StartedBy'] > 0) {
							$StartedByLink = '<a href="'.$MainURL.'/profile/'.$Usernames[$row['StartedBy']].'.html"><font color="'.$Colors['MBText'].'">'.$DisplayNames[$row['StartedBy']].'</font></a>';
						}
						else {
							$StartedByLink = $DisplayNames[$row['StartedBy']];
						}
					}
					else {
						$StartedByLink = $MsgText[2][65];
					}
					
					
					if (strlen($row['Title']) > 100) {
						$row['Title'] = substr($row['Title'],0,100) . '...';
					}
					
					if ($row['LastReply'] > 0) {
						if (date("j/n/Y",GetTimestamp()) == date("j/n/Y",$row['LastReply'])) {
							$LastPostDate = '<b>'.$MsgText[2][66].'</b> @ '.date("g:ia",$row['LastReply']);
						}
						else if (date("j/n/Y",(GetTimestamp()-(60*60*24))) == date("j/n/Y",$row['LastReply'])) {
							$LastPostDate = $MsgText[2][67].' @ '.date("g:ia",$row['LastReply']);
						}
						else {
							$LastPostDate = date("j-",$row['LastReply']).$MsgText[0][283+date("n",$row['LastReply'])].date("-Y @ g:ia",$row['LastReply']);
						}
						
						
						if ($Usernames[$row['LastUser']] != '') {
							if ($LoggedIn == 'y' && $row['LastUser'] > 0) {
								$LastMessageLink = '<a href="'.$MainURL.'/profile/'.$Usernames[$row['LastUser']].'.html"><font color="'.$Colors['MBText'].'">'.$DisplayNames[$row['LastUser']].'</a>';
							}
							else {
								$LastMessageLink = $DisplayNames[$row['LastUser']];
							}
						}
						else {
							$LastMessageLink = $MsgText[2][65];
						}
											
						
						$LastMessage = $LastPostDate . ' '.$MsgText[2][78].' ' . $LastMessageLink;
					}
					else {
						$LastMessage = $MsgText[2][108];
					}
					
					
					if ($row['Title'] == '') {
						$row['Title'] = '('.$MsgText[2][10].')';
					}
					
					
					if ($row['Sticky'] == 'y') {
						$row['Title'] = '<b>'.$row['Title'].'</b>';
					}
					
					
					if ($row['Status'] == 'L') {
						$StatusPrint = ' ('.$MsgText[2][116].')';
					}
					else {
						$StatusPrint = '';
					}
					
					
					$ThreadsList .= '<tr>
						
					<td height="100%" bgcolor="'.$BGColor.'"><table width="100%" height="100%" border="0" cellspacing="0" cellpadding="4"><tr><td valign="middle" bgcolor="'.$BGColor.'"><font face="'.$FontFace.'" size="'.$FontSize.'" color="'.$Colors['MBText'].'"><a href="'.$MainURL.'/forum/thread/'.$row['RecordNumber'].'.html"><font color="'.$Colors['MBText'].'">'.$row['Title'].'</font></a>'.$StatusPrint.'</font></font></td></tr></table></td>

					<td height="100%" bgcolor="'.$BGColor.'"><table width="100%" height="100%" border="0" cellspacing="0" cellpadding="4"><tr><td align="center" valign="middle" bgcolor="'.$BGColor.'"><font face="'.$FontFace.'" size="'.$FontSize.'" color="'.$Colors['MBText'].'">'.$StartedByLink.'</font></td></tr></table></td>

					<td height="100%" bgcolor="'.$BGColor.'"><table width="100%" height="100%" border="0" cellspacing="0" cellpadding="4"><tr><td align="center" valign="middle" bgcolor="'.$BGColor.'"><font face="'.$FontFace.'" size="'.$FontSize.'" color="'.$Colors['MBText'].'">'.number_format($row['Replies']).'</font></td></tr></table></td>

					<td height="100%" bgcolor="'.$BGColor.'"><table width="100%" height="100%" border="0" cellspacing="0" cellpadding="4"><tr><td align="center" valign="middle" bgcolor="'.$BGColor.'"><font face="'.$FontFace.'" size="'.$FontSize.'" color="'.$Colors['MBText'].'">'.number_format($row['Views']).'</font></td></tr></table></td>

					<td height="100%" bgcolor="'.$BGColor.'"><table width="100%" height="100%" border="0" cellspacing="0" cellpadding="4"><tr><td align="center" valign="middle" bgcolor="'.$BGColor.'"><font face="'.$FontFace.'" size="'.($FontSize-1).'" color="'.$Colors['MBText'].'">'.$LastMessage.'</font></td></tr></table></td>

				
					</tr>';
					
					
					if ($BGColor == $Colors['MBBG']) {
						$BGColor = $Colors['MBAlternateBG'];
					}
					else {
						$BGColor = $Colors['MBBG'];
					}
					
						
				}
								
				$ThreadsList .= '</table></td></tr></table></td></tr></table></td></tr>';
				
				
				
			
				
				
				
				
							
				if ($LoggedIn == 'y') {
			
					$query55 = "select RecordNumber from `".$Settings['DBPrefix']."core-Users` where Username='".$CookieUsername."' and NotifyBoards like '%-".$Arguments2."-%' limit 1";
					$result55 = mysql_query($query55) or die (mysql_error());
					if (mysql_num_rows($result55) == 0) {
				
						$TrackingLink = '<font face="'.$FontFace.'" size="'.$FontSize.'">&nbsp;<a href="'.$MainURL.'/forum/board-track/'.$Arguments2.'.html"><b>'.$MsgText[2][117].'</b></a>';

					}
					else {
				
						$TrackingLink = '<font face="'.$FontFace.'" size="'.$FontSize.'">&nbsp;<a href="'.$MainURL.'/forum/board-track/'.$Arguments2.'.html"><b>'.$MsgText[2][118].'</b></a>';
				
					}
			
				}
				
				
				$ThreadsList .= '</table>';
				
				
				
		
			if ($MaxPages > 1) {
			
				$PageContents .= '<table width="100%" border="0" cellpadding="0" cellspacing="0"><tr>
    			<td><font face="'.$FontFace.'" size="'.$FontSize.'"><div align="center"><b>'.$MsgText[2][126].': &nbsp;'.$PageLinks.'</b></div></td>
				</tr></table><img src="'.$TemplateImagesURL.'/admin/spacer.gif" border="0" width="1" height="8" alt=""><br>';
			
			}
			
			
			$PageContents .=  $ThreadsList;
			
			
			if ($MaxPages > 1) {
			
				$PageContents .= '<img src="'.$TemplateImagesURL.'/admin/spacer.gif" border="0" width="1" height="8" alt=""><br><table width="100%" border="0" cellpadding="0" cellspacing="0"><tr>
    			<td><font face="'.$FontFace.'" size="'.$FontSize.'"><div align="center"><b>'.$MsgText[2][126].': &nbsp;'.$PageLinks.'</b></div></td>
				</tr></table>';
			
			}
			
			
				
			}
			else {
			
				
				$PageContents .= '<br><br><b>['.$MsgText[2][112].']</b>';
				
			
			}
			
			
			$PageContents .= '<br>'.$TrackingLink;
			
			
			
		} // allowed to view board
		else {
		
			if ($mbSettings['TitleImage'] != '') {
				$PageTitle = '<div align="'.$AlignmentCodes[$mbSettings['TitleAlignment']].'"><img src="'.$BaseURL.$mbSettings['TitleImage'].'" alt="'.$mbSettings['PageTitle'].'" border="0"></div>';	
			}
			else {
				$PageTitle = '<div align="'.$AlignmentCodes[$mbSettings['TitleAlignment']].'">'.$mbSettings['PageTitle'].'</div>';
			}
			//$PageTitle = '<div align="'.$AlignmentCodes[$mbSettings['TitleAlignment']].'">'.$mbSettings['PageTitle'].'</div>';
			
			$BrowserTitle = $mbSettings['PageTitle'];
			$LocationBar = '<a href="'.$IndexURL.'">'.$MsgText[0][1].'</a> > '.$mbSettings['PageTitle'];
			
			
			$PageContents = '<br>'.$MsgText[2][119];
			
			if ($LoggedIn != 'y') {
				$PageContents .= '<br><br>'.$MsgText[2][61].': <a href="'.$MainURL.'/login/forum+++'.$Arguments2.'.html">'.$MsgText[0][192].'</a>';
			}
						
		
		} // not allowed to view board
		
		
		} // board exists
		else {
		
		
			//$PageTitle = '<div align="'.$AlignmentCodes[$mbSettings['TitleAlignment']].'">'.$mbSettings['PageTitle'].'</div>';
			if ($mbSettings['TitleImage'] != '') {
				$PageTitle = '<div align="'.$AlignmentCodes[$mbSettings['TitleAlignment']].'"><img src="'.$BaseURL.$mbSettings['TitleImage'].'" alt="'.$mbSettings['PageTitle'].'" border="0"></div>';	
			}
			else {
				$PageTitle = '<div align="'.$AlignmentCodes[$mbSettings['TitleAlignment']].'">'.$mbSettings['PageTitle'].'</div>';
			}
			
			
			$BrowserTitle = $mbSettings['PageTitle'];
			$LocationBar = '<a href="'.$IndexURL.'">'.$MsgText[0][1].'</a> > <a href="'.$MainURL.'/forum.html">'.$mbSettings['PageTitle'].'</a> > '.$MsgText[2][120];
			
			$PageContents = '<br>'.$MsgText[2][121];
		
		
		}
		
		
	} // end if $Arguments2 != '' (list of threads in a board)
	
	
	
	
	// ========================================================================================




?>
