<?

/*
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 news/articles script
	// ========================================================================================
	
	
	$query = "select * from `".$Settings['DBPrefix']."na-Settings`";
	$result = mysql_query($query) or die (mysql_error());
	while ($row = mysql_fetch_array($result)) {
		$naSettings[$row['Name']] = $row['Value'];
	}
	
	
	if ($naSettings['Title'] == '') {
		$SectionTitle = $MsgText[7][1];
	}
	else {
		$SectionTitle = $naSettings['Title'];
	}
	
	
		
	if ($Arguments2 == 'view') {
		
		$Arguments3 = intval($Arguments3);
		
		if ($Arguments3 > 0) {		
		// displaying specific article by id
		
			ReadPermissions();
			Global $Permissions;
			
			if ($Permissions[702] == 'y') {
				$query = "select * from `".$Settings['DBPrefix']."na-Articles` where RecordNumber='".$Arguments3."' and PublishDate<='".time()."' limit 1";
			}
			else {
				$query = "select * from `".$Settings['DBPrefix']."na-Articles` where RecordNumber='".$Arguments3."' and ApprovedBy!='' AND PublishDate<='".time()."' limit 1";
			}
			$result = mysql_query($query) or die (mysql_error());
			if (mysql_num_rows($result) > 0) {
			$row = mysql_fetch_array($result);
			
			
			if ($row['Category'] > 0) {
				$query3 = "select * from `".$Settings['DBPrefix']."na-Categories` where RecordNumber='".$row['Category']."' limit 1";
				$result3 = mysql_query($query3) or die (mysql_error());
				$row3 = mysql_fetch_array($result3);
				
				$CategoryLink = ' > <a href="'.$MainURL.'/articles/'.$row['Category'].'.html">'.$row3['CategoryName'].'</a>';
			}
			
			
			function BuildNavigationLinks($StartingCategory, $LinksType) {
	
				Global $Settings, $MainURL;
		
	
				$LoopCounter = 0;
				$NavLinks = '';
		
				$CurrentCategoryID = $StartingCategory;
						
				while ($CurrentCategoryID != 0 && $LoopCounter < 10) {
					$LoopCounter++;
			
					$query100 = "select * from `".$Settings['DBPrefix']."na-Categories` where RecordNumber='".$CurrentCategoryID."' limit 1";
					$result100 = mysql_query($query100) or die (mysql_error());
					$row100 = mysql_fetch_array($result100);
					
												
					if ($LinksType == 'category' && $CurrentCategoryID == $StartingCategory) {
						// don't add anything, we're on this category already
					}
					else {
						$NavLinks = '<a href="'.$MainURL.'/articles/'.$row100['RecordNumber'].'.html">'.$row100['CategoryName'].'</a> > '.$NavLinks;
					}
					
					
					
					$CurrentCategoryID = $row100['Parent'];
			
				}
					
				return $NavLinks;
	
			}
			
			$Arguments4 = intval($Arguments4);
			if ($Arguments4 == 0) {
				$Arguments4 = $row['Category'];
			}
						
			$LocationBar = '<a href="'.$IndexURL.'">'.$MsgText[0][1].'</a> > <a href="'.$MainURL.'/articles.html">'.$SectionTitle.'</a> > '.BuildNavigationLinks(intval($Arguments4),'').$row['Title'];
			
			
			$PageTitle = '<div align="'.$AlignmentCodes[$naSettings['TitleAlignment']].'">'.$row['Title'].'</div>';
			$BrowserTitle = $row['Title'];
			//$LocationBar = '<a href="'.$IndexURL.'">'.$MsgText[0][1].'</a> > <a href="'.$MainURL.'/articles.html">'.$SectionTitle.'</a>'.$CategoryLink.' > '.$row['Title'];
			
			
			# convert email addresses to mailto links 
			//$row['Message'] = preg_replace("/([\w\.-]+)(@)([\w\.-]+)/e", "'<a href=\"mailto:\\0\">\\0</a>'", $row['Message']); 

			# convert http urls to hyperlinks 
			$row['Article'] = preg_replace("/^(src=\"|href=\")(http:\/\/)([\w\.-]+)/e", "'<a href=\"\\0\" target=\"_blank\">\\0</a>'", $row['Article']);


			$row['Article'] = str_replace('="{FlexMainURL}','="'.$MainURL,$row['Article']);


			// 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['PublishDate'])) {
				$PostDate = $MsgText[7][61].' @ '.date("g:ia", $row['PublishDate']);
			}
			else if (date("j/n/Y", (GetTimestamp()-(60*60*24))) == date("j/n/Y", $row['PublishDate'])) {
				$PostDate = $MsgText[7][62].' @ '.date("g:ia", $row['PublishDate']);
			}
			else {
				$PostDate = date("F jS, Y @ g:ia", $row['PublishDate']);
			}
			
			
			if ($row['Source'] != '') {
				if ($row['SourceLink'] != '') {
					$Source = '<br><br>'.$MsgText[7][96].': <a href="'.$row['SourceLink'].'" target="_blank">'.$row['Source'].'</a>';
				}
				else {
					$Source = '<br><br>'.$MsgText[7][96].': '.$row['Source'];
				}
			}
			
			if ($row['ArticleFooter'] != '') {
				$Footer = '<br><br><br>'.nl2br($row['ArticleFooter']);
			}
			
			
			if ($row['Subtitle'] != '') {
				$row['Subtitle'] .= '<br><img src="'.$ImagesURL.'/admin/spacer.gif" width="1" height="12" alt="" border="0"><br>';
			}
			
			
			if ($PrintableFormat != 'y') {
				$PrintEmailLinks = '
				<script>
				function EmailArticle(ArticleID) {
				
					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.'/articles/email/\'+ArticleID+\'.html\',\'EmailArticle\',WindowProperties);
								
				}			
				</script>			
				
				<div align="'.$AlignmentCodes[$naSettings['PEAlignment']].'"><table border="0" cellpadding="0" cellspacing="0">
    <tr>
      <td><a href="'.$MainURL.'/printable/articles/view/'.$row['RecordNumber'].'.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/articles/view/'.$row['RecordNumber'].'.html" target="_blank">'.$MsgText[7][63].'</a></td>
      <td><img src="'.$ImagesURL.'/admin/spacer.gif" width="15" height="1" alt="" border="0"></td>
      <td><a href="javascript:EmailArticle('.$row['RecordNumber'].');"><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:EmailArticle('.$row['RecordNumber'].');">'.$MsgText[7][64].'</a>&nbsp;&nbsp;</td>
    </tr>
</table></div><img src="'.$ImagesURL.'/admin/spacer.gif" width="1" height="14" alt="" border="0">';

					
				if ($row['Image'] != '' && $row['ImageType'] > 0) {
					$TypeExtensions[1] = '.gif';
					$TypeExtensions[2] = '.jpg';
					$TypeExtensions[3] = '.png';
					
					if ($row['ImageCaption'] != '') {
						$CaptionStuff = '<br><div align="center"><img src="'.$ImagesURL.'/admin/spacer.gif" width="1" height="2" alt="" border="0"><br>'.$row['ImageCaption'].'</div>';
					}
			
					$PhotoStuff = '<table width="1" border="0" cellpadding="5" cellspacing="0" align="right"><tr><td><font face="'.$FontFace.'" size="1"><img src="'.$ImagesURL.'/articles/'.$row['Image'].$TypeExtensions[$row['ImageType']].'" alt="'.str_replace('"','\'',$row['ImageCaption']).'" border="0">'.$CaptionStuff.'</td></tr></table>';
				}

			}

			$LineBreakFound = false;
			$TestString = strtolower($row['Article']);
			if (strpos($TestString,'<br>') !== false || strpos($TestString,'<br />') !== false || strpos($TestString,'<p>') !== false) {
				$LineBreakFound = true;
			}
			
			if ($row['PageType'] == 1 || $row['PageType'] == 2 || $LineBreakFound == true) {
				if ($row['HidePostedDate'] == 1) {
					$PageContents = '<b>'.$row['Subtitle'].'</b><font size="1">'.$Source.'<br></font><br>'.$PrintEmailLinks.'<br>'.$PhotoStuff.$row['Article'].$Footer;
				}
				else {
					$PageContents = '<b>'.$row['Subtitle'].'</b><font size="1">'.$MsgText[7][10].': '.$PostDate.$Source.'<br></font><br>'.$PrintEmailLinks.'<br>'.$PhotoStuff.$row['Article'].$Footer;
				}
			}
			else {
				if ($row['HidePostedDate'] == 1) {
					$PageContents = '<b>'.$row['Subtitle'].'</b><font size="1">'.$Source.'<br></font><br>'.$PrintEmailLinks.'<br>'.$PhotoStuff.nl2br($row['Article']).$Footer;
				}
				else {
					$PageContents = '<b>'.$row['Subtitle'].'</b><font size="1">'.$MsgText[7][10].': '.$PostDate.$Source.'<br></font><br>'.$PrintEmailLinks.'<br>'.$PhotoStuff.nl2br($row['Article']).$Footer;
				}
			}


				
			ReadPermissions();
			Global $Permissions;
		
			if ($Permissions[701] == 'y') {
				$EditLink = '<a href="'.$MainURL.'/admin/articles-edit/'.$row['RecordNumber'].'.html">'.$MsgText[0][155].'</a><br><br>';
			}
			
			$PageContents = $EditLink.$PageContents;
			

			}
					
		}

	}

	else if ($Arguments2 == 'email') {
		// email article
		
		$Arguments3 = intval($Arguments3);
		
		$query = "select * from `".$Settings['DBPrefix']."na-Articles` where RecordNumber='".$Arguments3."' and PublishDate<='".GetTimestamp()."' limit 1";
		$result = mysql_query($query) or die (mysql_error());
		$row = mysql_fetch_array($result);
		
		if ($row['Title'] != '') {
		
		
		$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">Email</font></b></div><br><form name="SubmitForm" action="'.$MainURL.'/articles/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="ArticleID" value="'.$Arguments3.'">

			<b>'.$MsgText[7][65].'*:</b><br>
			<input type="text" name="SName" size="40" style="'.$FormStyle.'">
			<br>
			<b>'.$MsgText[7][66].'*:</b><br>
			<input type="text" name="SEmail" size="40" style="'.$FormStyle.'">
			<br><br>
			<b>'.$MsgText[7][67].'*:</b><br>
			<input type="text" name="REmail" size="40" style="'.$FormStyle.'"><br>
			<br><br>
			<b>'.$MsgText[7][69].'</b><br>
			<textarea name="Comments" cols="34" rows="2" wrap="virtual" style="'.$FormStyle.'"></textarea>
			
			<br><br>
			<b>'.$MsgText[7][70].':</b><br>
			<a href="'.$MainURL.'/articles/view/'.$Arguments3.'.html" target="_blank">'.$MainURL.'/articles/view/'.$Arguments3.'.html</a>

			<br><br>
			
			<div align="center"><!-- <input type="checkbox" name="CopyMe" value="y" checked> '.$MsgText[7][71].'<br><br> --><br>
<input type="submit" value="'.$MsgText[7][72].'" style="'.$FormStyle.'"></div>
			</td></tr></table><br><br><font size="1">'.$MsgText[7][73].'</div>
			</form>';
		
		
		print '<html><head>
<title>'.$MsgText[7][64].'</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['CLContentBG'].'" 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') {
		// email article
		
		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;
		}
		
		
				
		$query = "select * from `".$Settings['DBPrefix']."na-Articles` where RecordNumber='".intval($FormArguments['ArticleID'])."' and PublishDate<='".GetTimestamp()."' 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 article: '.$row['Title'].'.'."\n\n".'You can read the full article by clicking on or pasting this link in your browser: '.$MainURL.'/articles/view/'.$FormArguments['ArticleID'].'.html'."\n\n".$CommentsAdded."\n\n\n\n".$Settings['SiteName']."\n".$BaseURL;
			$MessageHeaders .= $Message;		
			
			
			
			mail($FormArguments['REmail'], $Settings['SiteName'].' Article: '.$row['Title'], "", $MessageHeaders, '-f'.$Settings['ContactEmail']);
			
		
		
			$PageContents = '<br><br><br><br><div align="center">'.$MsgText[7][74].'<br><br><br><br><b><a href="javascript:window.close();">'.$MsgText[7][75].'</a></b></div>';

			}
			else {
				
				$PageContents = '<br><br><div align="center">'.$MsgText[7][76].'<br><br><br><a href="javascript:history.go(-1)"><b>'.$MsgText[7][77].'</b></a></div>';
			
			}


			print '<html><head>
<title>'.$MsgText[7][64].'</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['CLContentBG'].'" text="'.$Colors['Text'].'" link="'.$Colors['Link'].'" vlink="'.$Colors['VLink'].'" alink="'.$Colors['ALink'].'"><font face="'.$FontFace.'" size="'.$FontSize.'">
'.$PageContents.'
</body>
</html>';

		}


		exit();
		
		
	}
	else  {
		
		if ($Arguments2 == '') {
			// main index list
			
			
			$BrowserTitle = $SectionTitle;
			$LocationBar = '<a href="'.$IndexURL.'">'.$MsgText[0][1].'</a> > '.$SectionTitle;
			
			
			if ($naSettings['TitleImage'] != '') {
				$PageTitle = '<div align="'.$AlignmentCodes[$naSettings['TitleAlignment']].'"><img src="'.$BaseURL.$naSettings['TitleImage'].'" alt="'.$SectionTitle.'" border="0"></div>';	
			}
			else {
				$PageTitle = '<div align="'.$AlignmentCodes[$naSettings['TitleAlignment']].'">'.$SectionTitle.'</div>';
			}
					
			
			
			if ($naSettings['TopText'] != '') {
				$naSettings['TopText'] .= '<br><br>';
			}
			
			$PageContents = '<div align="'.$AlignmentCodes[$naSettings['TopTextAlignment']].'">'.$naSettings['TopText'].'</div>';
			
			
			$PageContents .= '<br>';
			
						
			$query = "select * from `".$Settings['DBPrefix']."na-Categories` where Parent='".intval($Arguments2)."' order by CategoryName asc";
			$result = mysql_query($query) or die (mysql_error());
			if (mysql_num_rows($result) > 0) {
				while ($row = mysql_fetch_array($result)) {
				
					if ($row['CategoryDescription'] != '') {
						$row['CategoryDescription'] = '<br>'.$row['CategoryDescription'];
					}
						
					$PageContents .= '<b><a href="'.$MainURL.'/articles/'.$row['RecordNumber'].'.html">'.$row['CategoryName'].'</a></b>'.$row['CategoryDescription'].'<br><br>';
				
				}
				
				$CategoriesFound = true;			
			}
			
													
			
			$query_na = "SELECT * FROM `".$Settings['DBPrefix']."na-Articles` WHERE ApprovedBy!='' AND (Category='".intval($Arguments2)."' or Category2='".intval($Arguments2)."' or Category3='".intval($Arguments2)."' or Category4='".intval($Arguments2)."' or Category5='".intval($Arguments2)."' or Category6='".intval($Arguments2)."' or Category7='".intval($Arguments2)."' or Category8='".intval($Arguments2)."' or Category9='".intval($Arguments2)."' or Category10='".intval($Arguments2)."')  and PublishDate<='".GetTimestamp()."' ORDER BY PublishDate DESC";
			$result_na = mysql_query($query_na) or die (mysql_error());
			if (mysql_num_rows($result_na) > 0) {
			
				if ($CategoriesFound == true) {
					$PageContents .= '<br><table width="100%" border="0" cellpadding="0" cellspacing="0"><tr><td bgcolor="'.$Colors['Text'].'"><img src="'.$ImagesURL.'/admin/spacer.gif" width="1" height="1" alt="" border="0"></td></tr></table><br>';
				}
				
				$ArticlesCode .= '<table width="100%" border="0" cellpadding="3" cellspacing="0">';
				
				while ($row_na = mysql_fetch_array($result_na)) {
		
					if ($ArticlesPrinted > 0) {

						$ArticlesCode .= '<tr><td colspan="2"><img src="'.$ImagesURL.'/admin/spacer.gif" width="1" height="1" alt="" border="0"></td></tr>';

					}
							
																				
					if ($row_na['Teaser'] == '') {
						$StrippedArticle = strip_tags($row_na['Article']);
																
						if (strlen($StrippedArticle) > $naSettings['TeaserLength']) {
							$TeaserSection = substr($StrippedArticle,0,$naSettings['TeaserLength']);
							while (substr($TeaserSection,strlen($TeaserSection)-1,1) != ' ') {
								$TeaserSection = substr($TeaserSection,0,strlen($TeaserSection)-1);
							}
							while (substr($TeaserSection,strlen($TeaserSection)-1,1) == ' ') {
								$TeaserSection = substr($TeaserSection,0,strlen($TeaserSection)-1);
							}
							
							$TeaserSection .= '... [<a href="'.$MainURL.'/articles/view/'.$row_na['RecordNumber'].'/'.intval($Arguments2).'.html">'.$MsgText[7][78].'</a>]';

							$row_na['Title'] = '<a href="'.$MainURL.'/articles/view/'.$row_na['RecordNumber'].'/'.intval($Arguments2).'.html">'.$row_na['Title'].'</a>';

							$ArticleLinked = 'y';
						}
						else {
							$TeaserSection = $row_na['Article'];
						}
					}
					else {
						$TeaserSection = substr($row_na['Teaser'],0,$naSettings['TeaserLength']);
						
						if (strlen($row_na['Teaser']) > strlen($TeaserSection)) {
							while (substr($TeaserSection,strlen($TeaserSection)-1,1) != ' ') {
								$TeaserSection = substr($TeaserSection,0,strlen($TeaserSection)-1);
							}
							while (substr($TeaserSection,strlen($TeaserSection)-1,1) == ' ') {
								$TeaserSection = substr($TeaserSection,0,strlen($TeaserSection)-1);
							}
						} 
						
						$TeaserSection .= '... [<a href="'.$MainURL.'/articles/view/'.$row_na['RecordNumber'].'/'.intval($Arguments2).'.html">'.$MsgText[7][78].'</a>]';
						$row_na['Title'] = '<a href="'.$MainURL.'/articles/view/'.$row_na['RecordNumber'].'/'.intval($Arguments2).'.html">'.$row_na['Title'].'</a>';
						$ArticleLinked = 'y';
					}
					
							
					
					
					if ($row_na['Image'] != '' && $row_na['ImageType'] > 0) {
						$TypeExtensions[1] = '-thumb.gif';
						$TypeExtensions[2] = '-thumb.jpg';
						$TypeExtensions[3] = '-thumb.png';
						
						if ($ArticleLinked == 'y') {				
							$PhotoStuff = '<a href="'.$MainURL.'/articles/view/'.$row_na['RecordNumber'].'/'.intval($Arguments2).'.html"><img src="'.$ImagesURL.'/articles/'.$row_na['Image'].$TypeExtensions[$row_na['ImageType']].'" alt="" border="0"></a>';
						}
						else {
							$PhotoStuff = '<img src="'.$ImagesURL.'/articles/'.$row_na['Image'].$TypeExtensions[$row_na['ImageType']].'" alt="" border="0">';
						}
					}
					else {
						$PhotoStuff = '<img src="'.$ImagesURL.'/admin/spacer.gif" width="1" height="1" alt="" border="0">';
					}
						
					
					$DatePrint = '';
					if ($row_na['HidePostedDate'] != '1') {
						$DatePrint = ' &nbsp;<font size="1">'.date('F jS, Y',$row_na['PublishDate']).'</font>';
					}					
					
					
					$ArticlesPrinted++;
					$ArticlesCode .= '<tr><td width="90%"><font face="'.$FontFace.'" size="'.$FontSize.'"><b>'.$row_na['Title'].'</b>'.$DatePrint.'<br>'.$TeaserSection.'</td><td width="10%" align="center">'.$PhotoStuff.'</td></tr>';

				} // end while
		
				$ArticlesCode .= '</table>';
						
				$PageContents .= $ArticlesCode;
		
		
			} // end if articles found
					
		}
		else {
		
			$query = "select * from `".$Settings['DBPrefix']."na-Categories` where RecordNumber='".intval($Arguments2)."' limit 1";
			$result = mysql_query($query) or die (mysql_error());
			$row = mysql_fetch_array($result);
			
			$PageTitle = '<div align="'.$AlignmentCodes[$naSettings['TitleAlignment']].'">'.$row['CategoryName'].'</div>';
			$BrowserTitle = $row['CategoryName'];
			
			if ($row['CategoryDescription'] != '') {
				$PageContents = '<div align="'.$AlignmentCodes[$naSettings['TitleAlignment']].'">'.$row['CategoryDescription'].'</div><br><br>';
			}
			else {
				$PageContents = '<br>';
			}
			
						
			if ($row['Parent'] == 0) {
							
				$LocationBar = '<a href="'.$IndexURL.'">'.$MsgText[0][1].'</a> > <a href="'.$MainURL.'/articles.html">'.$SectionTitle.'</a> > '.$row['CategoryName'];
			
			}
			else {
			
				function BuildNavigationLinks($StartingCategory, $LinksType) {
	
					Global $MainURL;
		
	
					$LoopCounter = 0;
					$NavLinks = '';
		
					$CurrentCategoryID = $StartingCategory;
		
		
					while ($CurrentCategoryID != '0' && $LoopCounter < 10) {
						$LoopCounter++;
			
						$query100 = "select * from `".$Settings['DBPrefix']."na-Categories` where RecordNumber=".$CurrentCategoryID." limit 1";
						$result100 = mysql_query($query100) or die (mysql_error());
						$row100 = mysql_fetch_array($result100);
									
						if ($LinksType == 'category' && $CurrentCategoryID == $StartingCategory) {
							// don't add anything, we're on this category already
						}
						else {
							$NavLinks = '<a href="'.$MainURL.'/articles/'.$row100['RecordNumber'].'.html">'.$row100['CategoryName'].'</a> > '.$NavLinks;
						}
						
						$CurrentCategoryID = $row100['Parent'];
			
					}
					
					return $NavLinks;
	
				}
				
				$LocationBar = '<a href="'.$IndexURL.'">'.$MsgText[0][1].'</a> > <a href="'.$MainURL.'/articles.html">'.$SectionTitle.'</a> > '.BuildNavigationLinks($row['RecordNumber'],'category').$row['CategoryName'];
			
			}
			
			
			$query = "select * from `".$Settings['DBPrefix']."na-Categories` where Parent='".intval($Arguments2)."' order by CategoryName asc";
			$result = mysql_query($query) or die (mysql_error());
			if (mysql_num_rows($result) > 0) {
				while ($row = mysql_fetch_array($result)) {
				
					if ($row['CategoryDescription'] != '') {
						$row['CategoryDescription'] = '<br>'.$row['CategoryDescription'];
					}
						
					$PageContents .= '<b><a href="'.$MainURL.'/articles/'.$row['RecordNumber'].'.html">'.$row['CategoryName'].'</a></b>'.$row['CategoryDescription'].'<br><br>';
				
				}
				
				$CategoriesFound = true;			
			}
			
													
			
			$query_na = "SELECT * FROM `".$Settings['DBPrefix']."na-Articles` WHERE ApprovedBy!='' AND (Category='".intval($Arguments2)."' or Category2='".intval($Arguments2)."' or Category3='".intval($Arguments2)."' or Category4='".intval($Arguments2)."' or Category5='".intval($Arguments2)."' or Category6='".intval($Arguments2)."' or Category7='".intval($Arguments2)."' or Category8='".intval($Arguments2)."' or Category9='".intval($Arguments2)."' or Category10='".intval($Arguments2)."')  and PublishDate<='".GetTimestamp()."' ORDER BY PublishDate DESC";
			$result_na = mysql_query($query_na) or die (mysql_error());
			if (mysql_num_rows($result_na) > 0) {
			
				if ($CategoriesFound == true) {
					$PageContents .= '<br><table width="100%" border="0" cellpadding="0" cellspacing="0"><tr><td bgcolor="'.$Colors['Text'].'"><img src="'.$ImagesURL.'/admin/spacer.gif" width="1" height="1" alt="" border="0"></td></tr></table><br>';
				}
				
				$ArticlesCode .= '<table width="100%" border="0" cellpadding="3" cellspacing="0">';
				
				while ($row_na = mysql_fetch_array($result_na)) {
		
					if ($ArticlesPrinted > 0) {

						$ArticlesCode .= '<tr><td colspan="2"><img src="'.$ImagesURL.'/admin/spacer.gif" width="1" height="1" alt="" border="0"></td></tr>';

					}
							
																				
					if ($row_na['Teaser'] == '') {
						$StrippedArticle = strip_tags($row_na['Article']);
																
						if (strlen($StrippedArticle) > $naSettings['TeaserLength']) {
							$TeaserSection = substr($StrippedArticle,0,$naSettings['TeaserLength']);
							while (substr($TeaserSection,strlen($TeaserSection)-1,1) != ' ') {
								$TeaserSection = substr($TeaserSection,0,strlen($TeaserSection)-1);
							}
							while (substr($TeaserSection,strlen($TeaserSection)-1,1) == ' ') {
								$TeaserSection = substr($TeaserSection,0,strlen($TeaserSection)-1);
							}
							
							$TeaserSection .= '... [<a href="'.$MainURL.'/articles/view/'.$row_na['RecordNumber'].'/'.intval($Arguments2).'.html">'.$MsgText[7][78].'</a>]';

							$row_na['Title'] = '<a href="'.$MainURL.'/articles/view/'.$row_na['RecordNumber'].'/'.intval($Arguments2).'.html">'.$row_na['Title'].'</a>';

							$ArticleLinked = 'y';
						}
						else {
							$TeaserSection = $row_na['Article'];
						}
					}
					else {
						$TeaserSection = substr($row_na['Teaser'],0,$naSettings['TeaserLength']);
						
						if (strlen($row_na['Teaser']) > strlen($TeaserSection)) {
							while (substr($TeaserSection,strlen($TeaserSection)-1,1) != ' ') {
								$TeaserSection = substr($TeaserSection,0,strlen($TeaserSection)-1);
							}
							while (substr($TeaserSection,strlen($TeaserSection)-1,1) == ' ') {
								$TeaserSection = substr($TeaserSection,0,strlen($TeaserSection)-1);
							}
						} 
						
						$TeaserSection .= '... [<a href="'.$MainURL.'/articles/view/'.$row_na['RecordNumber'].'/'.intval($Arguments2).'.html">'.$MsgText[7][78].'</a>]';
						$row_na['Title'] = '<a href="'.$MainURL.'/articles/view/'.$row_na['RecordNumber'].'/'.intval($Arguments2).'.html">'.$row_na['Title'].'</a>';
						$ArticleLinked = 'y';
					}
					
							
					
					
					if ($row_na['Image'] != '' && $row_na['ImageType'] > 0) {
						$TypeExtensions[1] = '-thumb.gif';
						$TypeExtensions[2] = '-thumb.jpg';
						$TypeExtensions[3] = '-thumb.png';
						
						if ($ArticleLinked == 'y') {				
							$PhotoStuff = '<a href="'.$MainURL.'/articles/view/'.$row_na['RecordNumber'].'/'.intval($Arguments2).'.html"><img src="'.$ImagesURL.'/articles/'.$row_na['Image'].$TypeExtensions[$row_na['ImageType']].'" alt="" border="0"></a>';
						}
						else {
							$PhotoStuff = '<img src="'.$ImagesURL.'/articles/'.$row_na['Image'].$TypeExtensions[$row_na['ImageType']].'" alt="" border="0">';
						}
					}
					else {
						$PhotoStuff = '<img src="'.$ImagesURL.'/admin/spacer.gif" width="1" height="1" alt="" border="0">';
					}
					
					
					$DatePrint = '';
					if ($row_na['HidePostedDate'] != '1') {
						$DatePrint = ' &nbsp;<font size="1">'.date('F jS, Y',$row_na['PublishDate']).'</font>';
					}					
					
						
					$ArticlesPrinted++;
					$ArticlesCode .= '<tr><td width="90%"><font face="'.$FontFace.'" size="'.$FontSize.'"><b>'.$row_na['Title'].'</b>'.$DatePrint.'<br>'.$TeaserSection.'</td><td width="10%" align="center">'.$PhotoStuff.'</td></tr>';

				} // end while
		
				$ArticlesCode .= '</table>';		
				
				$PageContents .= $ArticlesCode;

			} // end if articles found
			else {
			
				if ($CategoriesFound != true) {
				
					$PageContents .= '<br>[No items exist in this category]';
				
				}
			
			}
			
		}
		
		
	

	}

	

	// ========================================================================================


?>