<?

/*
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 calendar page
	// ========================================================================================
	
	$query = "select * from `".$Settings['DBPrefix']."cl-Settings`";
	$result = mysql_query($query) or die (mysql_error());
	while ($row = mysql_fetch_array($result)) {
		$clSettings[$row['Name']] = $row['Value'];
	}
	
	
	
	$OverridesArray = explode('%%',$clSettings['ColorOverrides']);
	
	
	if ($OverridesArray[1] != '') { 
	$Colors['CLBorder'] = $OverridesArray[1];			// main calendar border
	}
	if ($OverridesArray[2] != '') {
	$Colors['CLTitleBG'] = $OverridesArray[2];			// top title (month and year, next/prev month links) background
	}
	if ($OverridesArray[3] != '') {
	$Colors['CLTitleText'] = $OverridesArray[3];			// top title text
	}
	if ($OverridesArray[4] != '') {
	$Colors['CLDaysBG'] = $OverridesArray[4];			// day names background
	}
	if ($OverridesArray[5] != '') {
	$Colors['CLDaysText'] = $OverridesArray[5];			// day names text
	}
	if ($OverridesArray[6] != '') {
	$Colors['CLCalDaysBG'] = $OverridesArray[6];			// grid squares that are a calendar day
	}
	if ($OverridesArray[7] != '') {
	$Colors['CLFillerDaysBG'] = $OverridesArray[7];		// grid squares that are fillers (not a day)
	}
	if ($OverridesArray[8] != '') {
	$Colors['CLCurrentDayBG'] = $OverridesArray[8];		// grid square that is today's date
	}
	if ($OverridesArray[9] != '') {
	$Colors['CLDayNumbersText'] = $OverridesArray[9];	// day numbers text
	}
	if ($OverridesArray[10] != '') {
	$Colors['CLEventTitleText'] = $OverridesArray[10];	// event title link text
	}
	if ($OverridesArray[11] != '') {
	$Colors['CLEventDetailsText'] = $OverridesArray[11];	// event details text
	}
	if ($OverridesArray[12] != '') {
	$Colors['CLContentBG'] = $OverridesArray[12];	// content pages bg
	}
	
	
	
	$query55 = "select * from `".$Settings['DBPrefix']."core-Settings` where Name='TimezoneOffset' limit 1";
	$result55 = mysql_query($query55) or die (mysql_error());
	$row55 = mysql_fetch_array($result55);
	if ($row55['Value'] != '') {		
		$TZO = (($row55['Value']+5)*3600);
	}
	
		
	

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

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

		
	
	if ($Arguments2 == 'day' && ($Arguments3 > 0 && $Arguments4 > 0 && $Arguments5 > 0)) {
		
		
		
		$Day = intval($Arguments3);
		$Month = intval($Arguments4);
		$Year = intval($Arguments5);
		
		$DayTimestamp = mktime(0,0,0,$Month,$Day,$Year);
		
		
			// double border
			$BorderTableTop['1'] = '<table width="55%" border="0" cellpadding="2" cellspacing="0"><tr><td bgcolor="'.$Colors['CLBorder'].'">
			<table width="100%" border="0" cellpadding="3" cellspacing="0"><tr><td bgcolor="'.$Colors['CLContentBG'].'">
			<table width="100%" border="0" cellpadding="1" cellspacing="0"><tr><td bgcolor="'.$Colors['CLBorder'].'">
			<table width="100%" border="0" cellpadding="10" cellspacing="0"><tr><td bgcolor="'.$Colors['CLContentBG'].'">';
			$BorderTableBottom['1'] = '</td></tr></table>
			</td></tr></table>
			</td></tr></table>
			</td></tr></table>';
		
			// thick border
			$BorderTableTop['2'] = '<table width="55%" border="0" cellpadding="2" cellspacing="0"><tr><td bgcolor="'.$Colors['CLBorder'].'">
			<table width="100%" border="0" cellpadding="10" cellspacing="0"><tr><td bgcolor="'.$Colors['CLContentBG'].'">';
			$BorderTableBottom['2'] = '</td></tr></table>
			</td></tr></table>';
			
			// thin border
			$BorderTableTop['3'] = '<table width="55%" border="0" cellpadding="1" cellspacing="0"><tr><td bgcolor="'.$Colors['CLBorder'].'">
			<table width="100%" border="0" cellpadding="10" cellspacing="0"><tr><td bgcolor="'.$Colors['CLContentBG'].'">';
			$BorderTableBottom['3'] = '</td></tr></table>
			</td></tr></table>';
			
			// no border
			$BorderTableTop['4'] = '<table width="55%" border="0" cellpadding="10" cellspacing="0"><tr><td bgcolor="'.$Colors['CLContentBG'].'">';
			$BorderTableBottom['4'] = '</td></tr></table>';
		
		
		
		$PageContents .= '<div align="'.$AlignmentCodes[$clSettings['DetailsAlignment']].'">'.$BorderTableTop[$clSettings['BorderStyle']].'
		<img src="'.$ImagesURL.'/admin/spacer.gif" border="0" width="400" height="1" alt=""><br>
		<div align="center"><b>'.$MsgText[0][27+date("w",$DayTimestamp)].', '.$MsgText[0][33+date("n",$DayTimestamp)].' '.date("j, Y",$DayTimestamp).'</b></div>
		<table width="100%" border="0" cellpadding="2" cellspacing="0">';
		
		
		
		if ($clSettings['TitleImage'] != '') {
			$PageTitle = '<div align="'.$AlignmentCodes[$clSettings['TitleAlignment']].'"><img src="'.$BaseURL.$clSettings['TitleImage'].'" alt="'.$clSettings['PageTitle'].'" border="0"></div>';	
		}
		else {
			$PageTitle = '<div align="'.$AlignmentCodes[$clSettings['TitleAlignment']].'">'.$clSettings['PageTitle'].'</div>';
		}
		
		
		//$PageTitle = '<div align="'.$AlignmentCodes[$clSettings['TitleAlignment']].'">'.$clSettings['PageTitle'].' - '.$MsgText[0][33+date("n",$DayTimestamp)].' '.date("j, Y",$DayTimestamp).'</div>';
		
		$BrowserTitle = $clSettings['PageTitle'];
		$LocationBar = '<a href="'.$IndexURL.'">'.$MsgText[0][1].'</a> > <a href="'.$MainURL.'/calendar.html">'.$clSettings['PageTitle'].'</a> > <a href="'.$MainURL.'/calendar/'.$Month.'/'.$Year.'.html">'.$MsgText[0][33+date("n",mktime(0,0,0,$Month,1,$Year))].date(" Y",mktime(0,0,0,$Month,1,$Year)).'</a> > '.$MsgText[1][83];
		
		
		
		$query55 = "select * from `".$Settings['DBPrefix']."cl-EventDates` where DateCode>=".($DayTimestamp+$TZO)." and DateCode<".($DayTimestamp+86400+$TZO)." order by DateCode asc";
		$result55 = mysql_query($query55) or die (mysql_error());
		if (mysql_num_rows($result55) > 0) {
			
			while ($row55 = mysql_fetch_array($result55)) {
								
				$query5 = "select * from `".$Settings['DBPrefix']."cl-Events` where RecordNumber='".$row55['EventID']."' and MinLevel<='".$UserLevel."' limit 1";
				$result5 = mysql_query($query5) or die (mysql_error());
				if (mysql_num_rows($result5) > 0) {
					$row5 = mysql_fetch_array($result5);
				
					$query6 = "select count(RecordNumber) as OtherDatesCount from `".$Settings['DBPrefix']."cl-EventDates` where EventID='".$row55['EventID']."' and DateCode>=".($DayTimestamp+$TZO)." and DateCode<".($DayTimestamp+($clSettings['ForwardPeriod']*60*60*24)+$TZO);
					$result6 = mysql_query($query6) or die (mysql_error());
					//$OtherDates = mysql_num_rows($result6);
					$row6 = mysql_fetch_array($result6);	
					
					$OtherDatesCount = 0;
					$OtherDatesCount = ($row6['OtherDatesCount']-1);
					
				
					$IDs[] = $row55['EventID'];
					
					$EventTitle[$row55['EventID']] = $row5['Title'];
					$EventText[$row55['EventID']] = $row5['Text'];
					$EventUsername[$row55['EventID']] = $row5['Username'];
					$EventStart[$row55['EventID']] = $row5['StartTime'];
					$EventEnd[$row55['EventID']] = $row5['EndTime'];
					$EventLink[$row55['EventID']] = $row5['Link'];
					$EventType[$row55['EventID']] = $row5['EventType'];
					$Priority[$row55['EventID']] = $row5['Priority'];
					$OtherDates[$row55['EventID']] = $OtherDatesCount;
				
				}
			}
		
		
		
			
				if (count($IDs) > 1) {
					
					// sort the events by title
					for ($k = 0; $k < count($IDs); $k++) {
						for ($j = 0; $j < (count($IDs)-1); $j++) {
					
							if ($EventTitle[$IDs[$j]] > $EventTitle[$IDs[$j+1]]) {
							
								$Swap = $IDs[$j+1];
								
								$IDs[$j+1] = $IDs[$j];
								
								$IDs[$j] = $Swap;
							
							}
							
						}
					}
					
					// sort the events by starting time
					for ($k = 0; $k < count($IDs); $k++) {
						for ($j = 0; $j < (count($IDs)-1); $j++) {										
						
							if ($EventStart[$IDs[$j]] > $EventStart[$IDs[$j+1]]) {
							
								$Swap = $IDs[$j+1];
								
								$IDs[$j+1] = $IDs[$j];
								
								$IDs[$j] = $Swap;
							
							}	
						
						}
					}
					
					// sort the events by priority number
					for ($k = 0; $k < count($IDs); $k++) {
						for ($j = 0; $j < (count($IDs)-1); $j++) {										
						
							if ($Priority[$IDs[$j]] > $Priority[$IDs[$j+1]]) {
							
								$Swap = $IDs[$j+1];
								
								$IDs[$j+1] = $IDs[$j];
								
								$IDs[$j] = $Swap;
							
							}
						
						}
					}
					
					// sort the holidays or events to the top, depending on the settings
					if ($clSettings['SortOrder'] == '2') {
						for ($k = 0; $k < count($IDs); $k++) {
							for ($j = 0; $j < (count($IDs)-1); $j++) {
								
								if ($EventType[$IDs[$j]] < $EventType[$IDs[$j+1]]) {
							
									$Swap = $IDs[$j+1];
									
									$IDs[$j+1] = $IDs[$j];
									
									$IDs[$j] = $Swap;
								
								} 
											
							}
						}
					}	
					else {
						for ($k = 0; $k < count($IDs); $k++) {
							for ($j = 0; $j < (count($IDs)-1); $j++) {
								
								if ($EventType[$IDs[$j]] > $EventType[$IDs[$j+1]]) {
								
									$Swap = $IDs[$j+1];
									
									$IDs[$j+1] = $IDs[$j];
									
									$IDs[$j] = $Swap;
								
								}
											
							}
						}				
					}
						
				}
			
		
			
			
			
			for ($i = 0; $i < count($IDs); $i++) {
				
				$TimePrint = '';
				
				
				if ($EventStart[$IDs[$i]] >= 0) {
				
					$Hours = 0;
					$Minutes = 0;
					
					$Seconds = $EventStart[$IDs[$i]];
					while ($Seconds >= 3600) {
						$Seconds = $Seconds - 3600;
						$Hours++;					
					}
					while ($Seconds >= 60) {
						$Seconds = $Seconds - 60;
						$Minutes++;					
					}
					
					
					$Suffix = 'am';
					if ($Hours >= 12) {
						$Hours -= 12;
						$Suffix = 'pm';
					}
					if ($Hours == 0) {
						$Hours = 12;
					}
					
					if ($Minutes < 10) {
						$Minutes = '0' . $Minutes;
					}
						
					$TimePrint = $Hours . ':' . $Minutes . $Suffix;

					//if ($EventEnd[$IDs[$i]] >= 0 && $EventEnd[$IDs[$i]] > $EventStart[$IDs[$i]]) {
					if ($EventEnd[$IDs[$i]] >= 0) {
						
						$Hours = 0;
						$Minutes = 0;
					
						$Seconds = $EventEnd[$IDs[$i]];
						while ($Seconds >= 3600) {
							$Seconds = $Seconds - 3600;
							$Hours++;					
						}
						while ($Seconds >= 60) {
							$Seconds = $Seconds - 60;
							$Minutes++;					
						}
						
						
						$Suffix = 'am';
						if ($Hours >= 12) {
							$Hours -= 12;
							$Suffix = 'pm';
						}
						if ($Hours == 0) {
							$Hours = 12;
						}
						
						if ($Minutes < 10) {
							$Minutes = '0' . $Minutes;
						}
						
						$TimePrint .= ' - ' . $Hours . ':' . $Minutes . $Suffix;
							
					}
					$TimeDatesSpacer = '<br>';
								
				}
				else {
					$TimePrint = '';
				}
				
				
				$OtherDatesPrint = '';
				if ($OtherDates[$IDs[$i]] > 0) {
					if ($OtherDates[$IDs[$i]] == 1) {
						$OtherDatesPrint = $TimeDatesSpacer.'(<a href="'.$MainURL.'/calendar/details/'.$IDs[$i].'.html">'.$MsgText[1][84].'</a>)';
					}
					else {
						$OtherDatesPrint = $TimeDatesSpacer.'(<a href="'.$MainURL.'/calendar/details/'.$IDs[$i].'.html">'.$OtherDates[$IDs[$i]].' '.$MsgText[1][85].'</a>)';
					}				
				}
				
			
				$PageContents .= '<tr><td colspan="2" bgcolor="'.$Colors['CLContentBG'].'"><img src="'.$TemplateImagesURL.'/admin/spacer.gif" border="0" width="1" height="14" alt=""></td></tr><tr><td><font face="'.$FontFace.'" size="'.$FontSize.'"><b><a href="'.$MainURL.'/calendar/details/'.$IDs[$i].'.html">'.$EventTitle[$IDs[$i]].'</a></b></td><td align="right" bgcolor="'.$Colors['CLContentBG'].'"><font face="'.$FontFace.'" size="'.$FontSize.'">'.$TimePrint.''.$OtherDatesPrint.'</td></tr>';
				
				
				
					if ($clSettings['ConvertReturns'] == 'y') {
						//$EventText[$IDs[$i]] = nl2br($EventText[$IDs[$i]]);
						$EventText[$IDs[$i]] = str_replace("\n",'<br>',$EventText[$IDs[$i]]);
					}
					
					
					if ($EventText[$IDs[$i]] != '') {
						if (strlen($EventText[$IDs[$i]]) > $clSettings['DayViewDescriptionLength']) {
							$TextDisplay = substr($EventText[$IDs[$i]],0,$clSettings['DayViewDescriptionLength']) . '... <br>[<a href="'.$MainURL.'/calendar/details/'.$IDs[$i].'.html">'.$MsgText[1][86].'</a>]';
						}
						else {
							$TextDisplay = $EventText[$IDs[$i]];
														
							
							if (strpos($TextDisplay,'@',0) !== false && strpos($TextDisplay,'mailto:',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 ($ii = 1; $ii <= $StringLength1; $ii++) {
									$RandomNum = rand(1, 62);
									$Random1 .= $CharactersArray[$RandomNum];
								}
								for ($ii = 1; $ii <= $StringLength2; $ii++) {
									$RandomNum = rand(1, 62);
									$Random2 .= $CharactersArray[$RandomNum];
								}
							
									
								$TextDisplay = preg_replace("/([\w\.-]+)(@)([\w\.-]+)/ie", "'<script language=\"JavaScript\">var '.\$Random1.' = \'\\1\'; var '.\$Random2.' = \'\\3\'; document.write(\'<a href=\"mai\'+\'lto:\'+'.\$Random1.'+String.fromCharCode(64)+'.\$Random2.'+\'\">\'+'.\$Random1.'+String.fromCharCode(64)+'.\$Random2.'+\'</a>\');</script>'", $TextDisplay);			
						
							} // end if @ found in contents
							
			
							// convert http urls to hyperlinks 
							//$TextDisplay = preg_replace("/(http:\/\/)([\w\.-]+)/e", "'<a href=\"\\0\" target=\"_blank\">\\0</a>'", $TextDisplay);
							//$row55['Text'] = preg_replace("/([^\">]http:\/\/)([a-zA-Z0-9-.\/]+)([,.]?[ ]?)/e", "'<a href=\"\\0\" target=\"_blank\">\\0</a>'", $row55['Text']);
							$row55['Text'] = preg_replace("/(?<!\")(http:\/\/)([\w\.\-\/]+)/e", "'<a href=\"\\0\" target=\"_blank\">\\0</a>'", $row55['Text']);
							
							
							
						}
					}
					else {
						$TextDisplay = '';
					}
				
				
				
				if ($clSettings['ShowPoster'] != 'n' && $EventUsername[$IDs[$i]] != '') {
					$query25 = "select DisplayName from `".$Settings['DBPrefix']."core-Users` where Username='".$EventUsername[$IDs[$i]]."' limit 1";
					$result25 = mysql_query($query25) or die (mysql_error());
					$row25 = mysql_fetch_array($result25);
					
					if ($row25['DisplayName'] == '') {
						$EventUsername[$IDs[$i]] = $row25['DisplayName'];
					}
					
														
					
					if ($LoggedIn == 'y') {
						$PageContents .= '<tr><td colspan="2" bgcolor="'.$Colors['CLContentBG'].'"><font face="'.$FontFace.'" size="'.$FontSize.'">'.$TextDisplay.'<br><div align="right"><font size="-2">'.$MsgText[1][87].': <a href="'.$MainURL.'/profile/'.$EventUsername[$IDs[$i]].'.html">'.$row25['DisplayName'].'</a></font></div><img src="'.$TemplateImagesURL.'/admin/spacer.gif" border="0" width="1" height="5" alt=""></td></tr>';
					}
					else {
						$PageContents .= '<tr><td colspan="2" bgcolor="'.$Colors['CLContentBG'].'"><font face="'.$FontFace.'" size="'.$FontSize.'">'.$TextDisplay.'<br><div align="right"><font size="-2">'.$MsgText[1][87].': '.$row25['DisplayName'].'</font></div><img src="'.$TemplateImagesURL.'/admin/spacer.gif" border="0" width="1" height="5" alt=""></td></tr>';
					}
					
				}
				else {
					$PageContents .= '<tr><td colspan="2" bgcolor="'.$Colors['CLContentBG'].'"><font face="'.$FontFace.'" size="'.$FontSize.'">'.$TextDisplay.'<br><br><br></td></tr>';
				}
	
			}
			
			$PageContents .= '</table>';
			
		}
		else {
			$PageContents .= '<tr><td colspan="2" bgcolor="'.$Colors['CLContentBG'].'"><font face="'.$FontFace.'" size="'.$FontSize.'">['.$MsgText[1][88].']</td></tr></table>';
		
		}
		
		
		$PageContents .= $BorderTableBottom[$clSettings['BorderStyle']] . '</div>';	
		
			
	} // end if showing a day's events
	
	else if ($Arguments2 == 'details') {
	// showing the details of a specific event

											
		$query55 = "select * from `".$Settings['DBPrefix']."cl-Events` where RecordNumber=".intval($Arguments3)." and MinLevel<='".$UserLevel."' limit 1";
		$result55 = mysql_query($query55) or die (mysql_error());
		if (mysql_num_rows($result55) > 0) {
			
			$row55 = mysql_fetch_array($result55);
			
			//$DatePieces = getdate($row55['DateCode']);
			
			
			if ($clSettings['TitleImage'] != '') {
				$PageTitle = '<div align="'.$AlignmentCodes[$clSettings['TitleAlignment']].'"><img src="'.$BaseURL.$clSettings['TitleImage'].'" alt="'.$clSettings['PageTitle'].'" border="0"></div>';	
			}
			else {
				$PageTitle = '<div align="'.$AlignmentCodes[$clSettings['TitleAlignment']].'">'.$clSettings['PageTitle'].'</div>';
			}	
			
			//$PageTitle = '<div align="'.$AlignmentCodes[$clSettings['TitleAlignment']].'">'.$clSettings['PageTitle'].' - '.$MsgText[1][89].'</div>';
			$BrowserTitle = $clSettings['PageTitle'];
			$LocationBar = '<a href="'.$IndexURL.'">'.$MsgText[0][1].'</a> > <a href="'.$MainURL.'/calendar.html">'.$clSettings['PageTitle'].'</a> > '.$MsgText[1][89];
			
			
			// double border
			$BorderTableTop['1'] = '<table width="55%" border="0" cellpadding="2" cellspacing="0"><tr><td bgcolor="'.$Colors['CLBorder'].'">
			<table width="100%" border="0" cellpadding="3" cellspacing="0"><tr><td bgcolor="'.$Colors['CLContentBG'].'">
			<table width="100%" border="0" cellpadding="1" cellspacing="0"><tr><td bgcolor="'.$Colors['CLBorder'].'">
			<table width="100%" border="0" cellpadding="10" cellspacing="0"><tr><td bgcolor="'.$Colors['CLContentBG'].'">';
			$BorderTableBottom['1'] = '</td></tr></table>
			</td></tr></table>
			</td></tr></table>
			</td></tr></table>';
		
			// thick border
			$BorderTableTop['2'] = '<table width="55%" border="0" cellpadding="2" cellspacing="0"><tr><td bgcolor="'.$Colors['CLBorder'].'">
			<table width="100%" border="0" cellpadding="10" cellspacing="0"><tr><td bgcolor="'.$Colors['CLContentBG'].'">';
			$BorderTableBottom['2'] = '</td></tr></table>
			</td></tr></table>';
			
			// thin border
			$BorderTableTop['3'] = '<table width="55%" border="0" cellpadding="1" cellspacing="0"><tr><td bgcolor="'.$Colors['CLBorder'].'">
			<table width="100%" border="0" cellpadding="10" cellspacing="0"><tr><td bgcolor="'.$Colors['CLContentBG'].'">';
			$BorderTableBottom['3'] = '</td></tr></table>
			</td></tr></table>';
			
			// no border
			$BorderTableTop['4'] = '<table width="55%" border="0" cellpadding="10" cellspacing="0"><tr><td bgcolor="'.$Colors['CLContentBG'].'">';
			$BorderTableBottom['4'] = '</td></tr></table>';
			
			
			$PageContents .= '<div align="'.$AlignmentCodes[$clSettings['DetailsAlignment']].'">'.$BorderTableTop[$clSettings['BorderStyle']].'
		<img src="'.$ImagesURL.'/admin/spacer.gif" border="0" width="400" height="1" alt=""><br>
		<font face="'.$FontFace.'" size="'.($FontSize+1).'"><b>'.$row55['Title'].'</b>
		</td></tr>
		<tr><td bgcolor="'.$Colors['CLContentBG'].'">
		<table width="100%" border="0" cellpadding="2" cellspacing="0">';
			

				$TimePrint = '';
				
				
				if ($row55['StartTime'] >= 0) {
				
					$Hours = 0;
					$Minutes = 0;
					
					$Seconds = $row55['StartTime'];
					while ($Seconds >= 3600) {
						$Seconds = $Seconds - 3600;
						$Hours++;					
					}
					while ($Seconds >= 60) {
						$Seconds = $Seconds - 60;
						$Minutes++;					
					}
					
					
					$Suffix = 'am';
					if ($Hours >= 12) {
						$Hours -= 12;
						$Suffix = 'pm';
					}
					if ($Hours == 0) {
						$Hours = 12;
					}
					
					if ($Minutes < 10) {
						$Minutes = '0' . $Minutes;
					}
						
					$TimePrint = $Hours . ':' . $Minutes . $Suffix;

					//if ($row55['EndTime'] >= 0 && $row55['EndTime'] > $row55['StartTime']) {
					if ($row55['EndTime'] >= 0) {
						
						$Hours = 0;
						$Minutes = 0;
					
						$Seconds = $row55['EndTime'];
						while ($Seconds >= 3600) {
							$Seconds = $Seconds - 3600;
							$Hours++;					
						}
						while ($Seconds >= 60) {
							$Seconds = $Seconds - 60;
							$Minutes++;					
						}
						
						
						$Suffix = 'am';
						if ($Hours >= 12) {
							$Hours -= 12;
							$Suffix = 'pm';
						}
						if ($Hours == 0) {
							$Hours = 12;
						}
						
						if ($Minutes < 10) {
							$Minutes = '0' . $Minutes;
						}
						
						$TimePrint .= ' - ' . $Hours . ':' . $Minutes . $Suffix;
							
					}
								
				}
				else {
					$TimePrint = '';
				}
				
				
				
				$CurrentDatePieces = getdate(GetTimestamp());
				$DayStartTimestamp = mktime(0,0,0,$CurrentDatePieces['mon'],$CurrentDatePieces['mday'],$CurrentDatePieces['year']);
				
				
				if ($Arguments4 == 'past') {
					$query155 = "select * from `".$Settings['DBPrefix']."cl-EventDates` where EventID=".intval($Arguments3)." and DateCode<".($DayStartTimestamp+$TZO)." order by DateCode asc";
					$FinalDateString = '</b>'.$MsgText[1][90].':<b><br>';
					$DateLinks = '<a href="'.$MainURL.'/calendar/details/'.$Arguments3.'.html">'.$MsgText[1][91].'</a>';
					
					$query6 = "select count(RecordNumber) as OtherDatesCount from `".$Settings['DBPrefix']."cl-EventDates` where EventID='".intval($Arguments3)."' and DateCode>".($DayStartTimestamp+($clSettings['ForwardPeriod']*60*60*24)+$TZO)." limit 1";
					$result6 = mysql_query($query6) or die (mysql_error());
					$row6 = mysql_fetch_array($result6);
					
					if ($row6['OtherDatesCount'] > 0) {
						$DateLinks .= ' | <a href="'.$MainURL.'/calendar/details/'.$Arguments3.'/future.html">'.$MsgText[1][92].'</a>';
					}
				
				}
				else if ($Arguments4 == 'future') {
					$query6 = "select count(RecordNumber) as OtherDatesCount from `".$Settings['DBPrefix']."cl-EventDates` where EventID='".intval($Arguments3)."' and DateCode<".($DayStartTimestamp+$TZO)." limit 1";
					$result6 = mysql_query($query6) or die (mysql_error());
					$row6 = mysql_fetch_array($result6);
					
					if ($row6['OtherDatesCount'] > 0) {
						$DateLinks = '<a href="'.$MainURL.'/calendar/details/'.$Arguments3.'/past.html">'.$MsgText[1][93].'</a>';
					}
				
					$query155 = "select * from `".$Settings['DBPrefix']."cl-EventDates` where EventID=".intval($Arguments3)." and DateCode>=".($DayStartTimestamp+$TZO)." order by DateCode asc";
					$FinalDateString = '</b>'.$MsgText[1][94].':<b><br>';
					
					if ($DateLinks != '') {
						$DateLinks .= ' | ';
					}
					$DateLinks .= '<a href="'.$MainURL.'/calendar/details/'.$Arguments3.'.html">'.$MsgText[1][91].'</a>';
					
					
				}
				else if ($Arguments4 == 'allcurrent') {
					$query155 = "select * from `".$Settings['DBPrefix']."cl-EventDates` where EventID=".intval($Arguments3)." and DateCode>=".($DayStartTimestamp-($clSettings['ReversePeriod']*60*60*24)+$TZO)." and DateCode<".($DayStartTimestamp+($clSettings['ForwardPeriod']*60*60*24)+$TZO)." order by DateCode asc";

					
					
					$query6 = "select count(RecordNumber) as OtherDatesCount from `".$Settings['DBPrefix']."cl-EventDates` where EventID='".intval($Arguments3)."' and DateCode<".($DayStartTimestamp+$TZO)." limit 1";
					$result6 = mysql_query($query6) or die (mysql_error());
					$row6 = mysql_fetch_array($result6);
					
					if ($row6['OtherDatesCount'] > 0) {
						$DateLinks = '<a href="'.$MainURL.'/calendar/details/'.$Arguments3.'/past.html">'.$MsgText[1][93].'</a>';
					}
					
					$query6 = "select count(RecordNumber) as OtherDatesCount from `".$Settings['DBPrefix']."cl-EventDates` where EventID='".$Arguments3."' and DateCode>".($DayStartTimestamp+($clSettings['ForwardPeriod']*60*60*24)+$TZO)." limit 1";
					$result6 = mysql_query($query6) or die (mysql_error());
					$row6 = mysql_fetch_array($result6);
					
					if ($row6['OtherDatesCount'] > 0) {
						if ($DateLinks != '') {
							$DateLinks .= ' | ';
						}
						$DateLinks .= '<a href="'.$MainURL.'/calendar/details/'.$Arguments3.'/future.html">'.$MsgText[1][92].'</a>';
					}
					
					
				}
				else {
					$query155 = "select * from `".$Settings['DBPrefix']."cl-EventDates` where EventID=".$Arguments3." and DateCode>=".($DayStartTimestamp-($clSettings['ReversePeriod']*60*60*24)+$TZO)." and DateCode<".($DayStartTimestamp+($clSettings['ForwardPeriod']*60*60*24)+$TZO)." order by DateCode asc";

					
					
					$query6 = "select count(RecordNumber) as OtherDatesCount from `".$Settings['DBPrefix']."cl-EventDates` where EventID='".$Arguments3."' and DateCode<".($DayStartTimestamp+$TZO)." limit 1";
					$result6 = mysql_query($query6) or die (mysql_error());
					$row6 = mysql_fetch_array($result6);
					
					if ($row6['OtherDatesCount'] > 0) {
						$DateLinks = '<a href="'.$MainURL.'/calendar/details/'.$Arguments3.'/past.html">'.$MsgText[1][93].'</a>';
					}
					
					$query6 = "select count(RecordNumber) as OtherDatesCount from `".$Settings['DBPrefix']."cl-EventDates` where EventID='".$Arguments3."' and DateCode>".($DayStartTimestamp+($clSettings['ForwardPeriod']*60*60*24))." limit 1";
					$result6 = mysql_query($query6) or die (mysql_error());
					$row6 = mysql_fetch_array($result6);
					
					if ($row6['OtherDatesCount'] > 0) {
						if ($DateLinks != '') {
							$DateLinks .= ' | ';
						}
						$DateLinks .= '<a href="'.$MainURL.'/calendar/details/'.$Arguments3.'/future.html">'.$MsgText[1][92].'</a>';
					}
					
					
				}
								
				$result155 = mysql_query($query155) or die (mysql_error());
				if (mysql_num_rows($result155) > 0) {
					while ($row155 = mysql_fetch_array($result155)) {
						$DatesArray[] = $row155['DateCode'];
					}
					
					$DatesArrayCount = count($DatesArray);
					if ($DatesArrayCount > $clSettings['DatesToShow'] && ($Arguments4 != 'allcurrent' && $Arguments4 != 'future')) {
						$DatesArrayCount = $clSettings['DatesToShow'];
						
						if ($DateLinks != '') {
							$DateLinks = ' | ' . $DateLinks;
						}
						$DateLinks = '<a href="'.$MainURL.'/calendar/details/'.$Arguments3.'/allcurrent.html">'.$MsgText[1][95].'</a>' . $DateLinks;
					}
						
					for ($i = 0; $i < $DatesArrayCount; $i++) {
					
						if ($i == 0) {
						
							$FinalDateString .= $MsgText[0][27+date("w",$DatesArray[$i]-$TZO)].', '.$MsgText[0][33+date("n",$DatesArray[$i]-$TZO)].' '.date("j, Y",$DatesArray[$i]-$TZO);
						
						}
						else {
						
							$FinalDateString .= '<br>' . $MsgText[0][27+date("w",$DatesArray[$i]-$TZO)].', '.$MsgText[0][33+date("n",$DatesArray[$i]-$TZO)].' '.date("j, Y",$DatesArray[$i]-$TZO);;
							
						}
						
						/*if ($i == 0) {
						
							$FinalDateString = date("F j",$DatesArray[$i]);
						
						}
						else {
													
							$TempDateSplit = getdate($DatesArray[$i]);
							$LastTempDateSplit = getdate($DatesArray[$i-1]);
								
							if ($TempDateSplit['year'] != $LastTempDateSplit['year']) {
								// this and last aren't the same year
								$FinalDateString .= ' ' . date("j", $DatesArray[($i-1)]) . ', ' . $TempDateSplit['year'];
							}
							else {
								// this and last are the same year
								if ($TempDateSplit['mon'] != $LastTempDateSplit['mon']) {
									// this and last aren't the same month
									$FinalDateString .= ', ' . date("j", $DatesArray[($i-1)]) . ', ' . date("F", $DatesArray[$i]);
									
									if ($i == (count($DatesArray)-1)) {
										$FinalDateString .= ' ' . date("j", $DatesArray[$i]) . ', ' . $TempDateSplit['year'];
									}
									
								}
								else {
									// this and last are the same month
									//$FinalDateString .= ',' . date("j", $DatesArray[$i]);
									
									if ($i == (count($DatesArray)-1)) {
										$FinalDateString .= ', ' . date("j", $DatesArray[$i]) . ', ' . $TempDateSplit['year'];;
									}
									
								}
							} 
							
							
							
						}*/
						
					
					}
					
					
				}
				else {
					$FinalDateString = '['.$MsgText[1][96].']';
				}
				
				$FinalDateString .= '<br></b><font size="'.($FontSize-1).'">'.$DateLinks.'</font><b>';
				
			
				$PageContents .= '<tr><td bgcolor="'.$Colors['CLContentBG'].'"><font face="'.$FontFace.'" size="'.$FontSize.'"><b>'.$FinalDateString.'</b></td><td align="right"><font face="'.$FontFace.'" size="'.$FontSize.'">'.$TimePrint.'</td></tr>';
				
				
				if ($clSettings['ConvertReturns'] == 'y') {
					$row55['Text'] = nl2br($row55['Text']);
				}
				
				
					if (strpos($row55['Text'],'@',0) !== false && strpos($row55['Text'],'mailto:',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];
						}
					
					
						$row55['Text'] = preg_replace("/([\w\.-]+)(@)([\w\.-]+)/ie", "'<script language=\"JavaScript\">var '.\$Random1.' = \'\\1\'; var '.\$Random2.' = \'\\3\'; document.write(\'<a href=\"mai\'+\'lto:\'+'.\$Random1.'+String.fromCharCode(64)+'.\$Random2.'+\'\">\'+'.\$Random1.'+String.fromCharCode(64)+'.\$Random2.'+\'</a>\');</script>'", $row55['Text']);						
				
					} // end if @ found in contents
					

					# convert http urls to hyperlinks 
					//$row55['Text'] = preg_replace("/(http:\/\/)([a-zA-Z0-9-.\/]+)([,.]?[ ]?)/e", "'<a href=\"\\0\" target=\"_blank\">\\0</a>'", $row55['Text']);
					//$row55['Text'] = preg_replace("/([^\">]http:\/\/)([a-zA-Z0-9-.\/]+)([,.]?[ ]?)/e", "'<a href=\"\\0\" target=\"_blank\">\\0</a>'", $row55['Text']);
					$row55['Text'] = preg_replace("/(?<!\")(http:\/\/)([\w\.\-\/]+)/e", "'<a href=\"\\0\" target=\"_blank\">\\0</a>'", $row55['Text']);
				
	
				
				
				if ($clSettings['ShowPoster'] != 'n' && $row55['Username'] != '') { 
								
					$query5 = "select DisplayName from `".$Settings['DBPrefix']."core-Users` where Username='".$row55['Username']."' limit 1";
					$result5 = mysql_query($query5) or die (mysql_error());
					$row5 = mysql_fetch_array($result5);
					
					if ($row5['DisplayName'] == '') {
						$row5['DisplayName'] = $row55['Username'];
					}
					
								
				
					if ($LoggedIn == 'y') {
						$PageContents .= '<tr><td colspan="2" bgcolor="'.$Colors['CLContentBG'].'"><font face="'.$FontFace.'" size="'.$FontSize.'"><br>'.$row55['Text'].'<br><br><br><br><div align="right"><font size="-2">'.$MsgText[1][87].': <a href="'.$MainURL.'/profile/'.$row55['Username'].'.html">'.$row5['DisplayName'].'</a></font></div></td></tr></table>';
					}
					else {
						$PageContents .= '<tr><td colspan="2" bgcolor="'.$Colors['CLContentBG'].'"><font face="'.$FontFace.'" size="'.$FontSize.'"><br>'.$row55['Text'].'<br><br><br><br><div align="right"><font size="-2">'.$MsgText[1][87].': '.$row5['DisplayName'].'</font></div></td></tr></table>';
					}

				}
				else {
					$PageContents .= '<tr><td colspan="2" bgcolor="'.$Colors['CLContentBG'].'"><font face="'.$FontFace.'" size="'.$FontSize.'"><br>'.$row55['Text'].'<br><br><br></td></tr></table>';
				}
		
		
		$PageContents .= $BorderTableBottom[$clSettings['BorderStyle']] . '</div>';	
			
			
		}
		else {
			$PageTitle = '<div align="'.$AlignmentCodes[$clSettings['TitleAlignment']].'">'.$clSettings['PageTitle'].' - '.$MsgText[1][89].'</div>';
			$BrowserTitle = $clSettings['PageTitle'];
			$LocationBar = '<a href="'.$IndexURL.'">'.$MsgText[0][1].'</a> > <a href="'.$MainURL.'/calendar.html">'.$clSettings['PageTitle'].'</a> > '.$MsgText[1][89];
		
			$PageContents .= $MsgText[1][97];
		
		}
		
				
	} // end if showing a specific event's details
	
	else if ($Arguments2 == 'details-pop') {
	// showing the details of a specific event, in a pop up window

				
		$query55 = "select * from `".$Settings['DBPrefix']."cl-Events` where RecordNumber=".$Arguments3." and MinLevel<='".$UserLevel."' limit 1";
		$result55 = mysql_query($query55) or die (mysql_error());
		if (mysql_num_rows($result55) > 0) {
			
			$row55 = mysql_fetch_array($result55);
			
			
			if ($clSettings['ConvertReturns'] == 'y') {
				$row55['Text'] = nl2br($row55['Text']);
			}
			
			
			//$DatePieces = getdate($row55['DateCode']);
			
			//$PageTitle = '<div align="'.$AlignmentCodes[$clSettings['TitleAlignment']].'">'.$clSettings['PageTitle'].' - Details</div>';
			$BrowserTitle = $clSettings['PageTitle'];
			
			
			
			$PageContents .= '<div align="center"><table width="95%" border="0" cellpadding="3" cellspacing="0"><tr><td bgcolor="'.$Colors['CLContentBG'].'">
		<br>
		<font face="'.$FontFace.'" size="'.($FontSize+2).'"><b>'.$row55['Title'].'</b><br><img src="'.$ImagesURL.'/admin/spacer.gif" border="0" width="1" height="10" alt=""></td></tr>
		<tr><td bgcolor="'.$Colors['CLContentBG'].'">
		<table width="100%" border="0" cellpadding="2" cellspacing="0">';
			

				$TimePrint = '';
				
				
				if ($row55['StartTime'] >= 0) {
				
					$Hours = 0;
					$Minutes = 0;
					
					$Seconds = $row55['StartTime'];
					while ($Seconds >= 3600) {
						$Seconds = $Seconds - 3600;
						$Hours++;					
					}
					while ($Seconds >= 60) {
						$Seconds = $Seconds - 60;
						$Minutes++;					
					}
					
					
					$Suffix = 'am';
					if ($Hours >= 12) {
						$Hours -= 12;
						$Suffix = 'pm';
					}
					if ($Hours == 0) {
						$Hours = 12;
					}
					
					if ($Minutes < 10) {
						$Minutes = '0' . $Minutes;
					}
						
					$TimePrint = $Hours . ':' . $Minutes . $Suffix;

					//if ($row55['EndTime'] >= 0 && $row55['EndTime'] > $row55['StartTime']) {
					if ($row55['EndTime'] >= 0) {
						
						$Hours = 0;
						$Minutes = 0;
					
						$Seconds = $row55['EndTime'];
						while ($Seconds >= 3600) {
							$Seconds = $Seconds - 3600;
							$Hours++;					
						}
						while ($Seconds >= 60) {
							$Seconds = $Seconds - 60;
							$Minutes++;					
						}
						
						
						$Suffix = 'am';
						if ($Hours >= 12) {
							$Hours -= 12;
							$Suffix = 'pm';
						}
						if ($Hours == 0) {
							$Hours = 12;
						}
						
						if ($Minutes < 10) {
							$Minutes = '0' . $Minutes;
						}
						
						$TimePrint .= ' - ' . $Hours . ':' . $Minutes . $Suffix;
							
					}
								
				}
				else {
					$TimePrint = '';
				}
				
				
				
				$CurrentDatePieces = getdate(GetTimestamp());
				$DayStartTimestamp = mktime(0,0,0,$CurrentDatePieces['mon'],$CurrentDatePieces['mday'],$CurrentDatePieces['year']);
				
				//$query155 = "select * from `".$Settings['DBPrefix']."cl-EventDates` where EventID=".$Arguments3." order by DateCode asc";
				
				/*if ($Arguments4 == 'past') {
					$query155 = "select * from `".$Settings['DBPrefix']."cl-EventDates` where EventID=".$Arguments3." and DateCode<".$DayStartTimestamp." order by DateCode asc";
					$FinalDateString = '</b>Past Dates:<b><br>';
					$DateLinks = '<a href="'.$MainURL.'/calendar/details-pop/'.$Arguments3.'.html">Show Current Dates</a>';
					
					$query6 = "select count(RecordNumber) as OtherDatesCount from `".$Settings['DBPrefix']."cl-EventDates` where EventID='".$Arguments3."' and DateCode>".($DayStartTimestamp+($clSettings['ForwardPeriod']*60*60*24))." limit 1";
					$result6 = mysql_query($query6) or die (mysql_error());
					$row6 = mysql_fetch_array($result6);
					
					if ($row6['OtherDatesCount'] > 0) {
						$DateLinks .= ' | <a href="'.$MainURL.'/calendar/details-pop/'.$Arguments3.'/future.html">Show Future Dates</a>';
					}
				
				}
				else if ($Arguments4 == 'future') {
					$query6 = "select count(RecordNumber) as OtherDatesCount from `".$Settings['DBPrefix']."cl-EventDates` where EventID='".$Arguments3."' and DateCode<".$DayStartTimestamp." limit 1";
					$result6 = mysql_query($query6) or die (mysql_error());
					$row6 = mysql_fetch_array($result6);
					
					if ($row6['OtherDatesCount'] > 0) {
						$DateLinks = '<a href="'.$MainURL.'/calendar/details-pop/'.$Arguments3.'/past.html">Show Past Dates</a>';
					}
				
					$query155 = "select * from `".$Settings['DBPrefix']."cl-EventDates` where EventID=".$Arguments3." and DateCode>=".$DayStartTimestamp." order by DateCode asc";
					$FinalDateString = '</b>Future Dates:<b><br>';
					
					if ($DateLinks != '') {
						$DateLinks .= ' | ';
					}
					$DateLinks .= '<a href="'.$MainURL.'/calendar/details-pop/'.$Arguments3.'.html">Show Current Dates</a>';
					
					
				}
				else {
					$query155 = "select * from `".$Settings['DBPrefix']."cl-EventDates` where EventID=".$Arguments3." and DateCode>=".($DayStartTimestamp-($clSettings['ReversePeriod']*60*60*24))." and DateCode<".($DayStartTimestamp+($clSettings['ForwardPeriod']*60*60*24))." order by DateCode asc limit ".$clSettings['DatesToShow'];

					
					
					$query6 = "select count(RecordNumber) as OtherDatesCount from `".$Settings['DBPrefix']."cl-EventDates` where EventID='".$Arguments3."' and DateCode<".$DayStartTimestamp." limit 1";
					$result6 = mysql_query($query6) or die (mysql_error());
					$row6 = mysql_fetch_array($result6);
					
					if ($row6['OtherDatesCount'] > 0) {
						$DateLinks = '<a href="'.$MainURL.'/calendar/details-pop/'.$Arguments3.'/past.html">Show Past Dates</a>';
					}
					
					$query6 = "select count(RecordNumber) as OtherDatesCount from `".$Settings['DBPrefix']."cl-EventDates` where EventID='".$Arguments3."' and DateCode>".($DayStartTimestamp+($clSettings['ForwardPeriod']*60*60*24))." limit 1";
					$result6 = mysql_query($query6) or die (mysql_error());
					$row6 = mysql_fetch_array($result6);
					
					if ($row6['OtherDatesCount'] > 0) {
						if ($DateLinks != '') {
							$DateLinks .= ' | ';
						}
						$DateLinks .= '<a href="'.$MainURL.'/calendar/details-pop/'.$Arguments3.'/future.html">Show Future Dates</a>';
					}
					
					
				}
				
				
				$result155 = mysql_query($query155) or die (mysql_error());
				if (mysql_num_rows($result155) > 0) {
					while ($row155 = mysql_fetch_array($result155)) {
						$DatesArray[] = $row155['DateCode'];
					}
										
					for ($i = 0; $i < count($DatesArray); $i++) {
					
						if ($i == 0) {
						
							$FinalDateString = date("l, F j, Y",$DatesArray[$i]);
						
						}
						else {
						
							$FinalDateString .= '<br>' . date("l, F j, Y",$DatesArray[$i]);
							
						}
						
										
					
					}
				}
				else {
					$FinalDateString = '[No Dates Found]';
				}
				
				$FinalDateString .= '<br></b><font size="'.($FontSize-1).'">'.$DateLinks.'</font><b>';
				*/
				
				
				if ($Arguments4 == 'past') {
					$query155 = "select * from `".$Settings['DBPrefix']."cl-EventDates` where EventID=".intval($Arguments3)." and DateCode<".($DayStartTimestamp+$TZO)." order by DateCode asc";
					$FinalDateString = '</b>'.$MsgText[1][90] .':<b><br>';
					$DateLinks = '<a href="'.$MainURL.'/calendar/details-pop/'.$Arguments3.'.html">'.$MsgText[1][91].'</a>';
					
					$query6 = "select count(RecordNumber) as OtherDatesCount from `".$Settings['DBPrefix']."cl-EventDates` where EventID='".intval($Arguments3)."' and DateCode>".($DayStartTimestamp+($clSettings['ForwardPeriod']*60*60*24)+$TZO)." limit 1";
					$result6 = mysql_query($query6) or die (mysql_error());
					$row6 = mysql_fetch_array($result6);
					
					if ($row6['OtherDatesCount'] > 0) {
						$DateLinks .= ' | <a href="'.$MainURL.'/calendar/details-pop/'.$Arguments3.'/future.html">'.$MsgText[1][92].'</a>';
					}
				
				}
				else if ($Arguments4 == 'future') {
					$query6 = "select count(RecordNumber) as OtherDatesCount from `".$Settings['DBPrefix']."cl-EventDates` where EventID='".intval($Arguments3)."' and DateCode<".($DayStartTimestamp+$TZO)." limit 1";
					$result6 = mysql_query($query6) or die (mysql_error());
					$row6 = mysql_fetch_array($result6);
					
					if ($row6['OtherDatesCount'] > 0) {
						$DateLinks = '<a href="'.$MainURL.'/calendar/details-pop/'.$Arguments3.'/past.html">'.$MsgText[1][93].'</a>';
					}
				
					$query155 = "select * from `".$Settings['DBPrefix']."cl-EventDates` where EventID=".intval($Arguments3)." and DateCode>=".($DayStartTimestamp+$TZO)." order by DateCode asc";
					$FinalDateString = '</b>'.$MsgText[1][94].':<b><br>';
					
					if ($DateLinks != '') {
						$DateLinks .= ' | ';
					}
					$DateLinks .= '<a href="'.$MainURL.'/calendar/details-pop/'.$Arguments3.'.html">'.$MsgText[1][91].'</a>';
					
					
				}
				else if ($Arguments4 == 'allcurrent') {
					$query155 = "select * from `".$Settings['DBPrefix']."cl-EventDates` where EventID=".intval($Arguments3)." and DateCode>=".($DayStartTimestamp-($clSettings['ReversePeriod']*60*60*24)+$TZO)." and DateCode<".($DayStartTimestamp+($clSettings['ForwardPeriod']*60*60*24)+$TZO)." order by DateCode asc";

					
					
					$query6 = "select count(RecordNumber) as OtherDatesCount from `".$Settings['DBPrefix']."cl-EventDates` where EventID='".intval($Arguments3)."' and DateCode<".($DayStartTimestamp+$TZO)." limit 1";
					$result6 = mysql_query($query6) or die (mysql_error());
					$row6 = mysql_fetch_array($result6);
					
					if ($row6['OtherDatesCount'] > 0) {
						$DateLinks = '<a href="'.$MainURL.'/calendar/details-pop/'.$Arguments3.'/past.html">'.$MsgText[1][93].'</a>';
					}
					
					$query6 = "select count(RecordNumber) as OtherDatesCount from `".$Settings['DBPrefix']."cl-EventDates` where EventID='".$Arguments3."' and DateCode>".($DayStartTimestamp+($clSettings['ForwardPeriod']*60*60*24)+$TZO)." limit 1";
					$result6 = mysql_query($query6) or die (mysql_error());
					$row6 = mysql_fetch_array($result6);
					
					if ($row6['OtherDatesCount'] > 0) {
						if ($DateLinks != '') {
							$DateLinks .= ' | ';
						}
						$DateLinks .= '<a href="'.$MainURL.'/calendar/details-pop/'.$Arguments3.'/future.html">'.$MsgText[1][92].'</a>';
					}
					
					
				}
				else {
					$query155 = "select * from `".$Settings['DBPrefix']."cl-EventDates` where EventID=".$Arguments3." and DateCode>=".($DayStartTimestamp-($clSettings['ReversePeriod']*60*60*24)+$TZO)." and DateCode<".($DayStartTimestamp+($clSettings['ForwardPeriod']*60*60*24)+$TZO)." order by DateCode asc";

					
					
					$query6 = "select count(RecordNumber) as OtherDatesCount from `".$Settings['DBPrefix']."cl-EventDates` where EventID='".$Arguments3."' and DateCode<".($DayStartTimestamp+$TZO)." limit 1";
					$result6 = mysql_query($query6) or die (mysql_error());
					$row6 = mysql_fetch_array($result6);
					
					if ($row6['OtherDatesCount'] > 0) {
						$DateLinks = '<a href="'.$MainURL.'/calendar/details-pop/'.$Arguments3.'/past.html">'.$MsgText[1][93].'</a>';
					}
					
					$query6 = "select count(RecordNumber) as OtherDatesCount from `".$Settings['DBPrefix']."cl-EventDates` where EventID='".$Arguments3."' and DateCode>".($DayStartTimestamp+($clSettings['ForwardPeriod']*60*60*24)+$TZO)." limit 1";
					$result6 = mysql_query($query6) or die (mysql_error());
					$row6 = mysql_fetch_array($result6);
					
					if ($row6['OtherDatesCount'] > 0) {
						if ($DateLinks != '') {
							$DateLinks .= ' | ';
						}
						$DateLinks .= '<a href="'.$MainURL.'/calendar/details-pop/'.$Arguments3.'/future.html">'.$MsgText[1][92].'</a>';
					}
					
					
				}
								
				$result155 = mysql_query($query155) or die (mysql_error());
				if (mysql_num_rows($result155) > 0) {
					while ($row155 = mysql_fetch_array($result155)) {
						$DatesArray[] = $row155['DateCode'];
					}
					
					$DatesArrayCount = count($DatesArray);
					if ($DatesArrayCount > $clSettings['DatesToShow'] && ($Arguments4 != 'allcurrent' && $Arguments4 != 'future')) {
						$DatesArrayCount = $clSettings['DatesToShow'];
						
						if ($DateLinks != '') {
							$DateLinks = ' | ' . $DateLinks;
						}
						$DateLinks = '<a href="'.$MainURL.'/calendar/details-pop/'.$Arguments3.'/allcurrent.html">'.$MsgText[1][95].'</a>' . $DateLinks;
					}
						
					for ($i = 0; $i < $DatesArrayCount; $i++) {
					
						if ($i == 0) {
						
							$FinalDateString .= $MsgText[0][27+date("w",$DatesArray[$i]-$TZO)].', '.$MsgText[0][33+date("n",$DatesArray[$i]-$TZO)].' '.date("j, Y",$DatesArray[$i]-$TZO);;
						
						}
						else {
						
							$FinalDateString .= '<br>' . $MsgText[0][27+date("w",$DatesArray[$i]-$TZO)].', '.$MsgText[0][33+date("n",$DatesArray[$i]-$TZO)].' '.date("j, Y",$DatesArray[$i]-$TZO);;
							
						}
						
						/*if ($i == 0) {
						
							$FinalDateString = date("F j",$DatesArray[$i]);
						
						}
						else {
													
							$TempDateSplit = getdate($DatesArray[$i]);
							$LastTempDateSplit = getdate($DatesArray[$i-1]);
								
							if ($TempDateSplit['year'] != $LastTempDateSplit['year']) {
								// this and last aren't the same year
								$FinalDateString .= ' ' . date("j", $DatesArray[($i-1)]) . ', ' . $TempDateSplit['year'];
							}
							else {
								// this and last are the same year
								if ($TempDateSplit['mon'] != $LastTempDateSplit['mon']) {
									// this and last aren't the same month
									$FinalDateString .= ', ' . date("j", $DatesArray[($i-1)]) . ', ' . date("F", $DatesArray[$i]);
									
									if ($i == (count($DatesArray)-1)) {
										$FinalDateString .= ' ' . date("j", $DatesArray[$i]) . ', ' . $TempDateSplit['year'];
									}
									
								}
								else {
									// this and last are the same month
									//$FinalDateString .= ',' . date("j", $DatesArray[$i]);
									
									if ($i == (count($DatesArray)-1)) {
										$FinalDateString .= ', ' . date("j", $DatesArray[$i]) . ', ' . $TempDateSplit['year'];;
									}
									
								}
							} 
							
							
							
						}*/
						
					
					}
					
					
				}
				else {
					$FinalDateString = '['.$MsgText[1][96].']';
				}
				
				$FinalDateString .= '<br></b><font size="'.($FontSize-1).'">'.$DateLinks.'</font><b>';
				
			
				
			
				$PageContents .= '<tr><td bgcolor="'.$Colors['CLContentBG'].'"><font face="'.$FontFace.'" size="'.$FontSize.'"><b>'.$FinalDateString.'</b></td><td align="right" bgcolor="'.$Colors['CLContentBG'].'"><font face="'.$FontFace.'" size="'.$FontSize.'">'.$TimePrint.'</td></tr>';
				
				
				if ($row55['Text'] != '') {
					if (strlen($row55['Text']) > $clSettings['DetailsPopDescriptionLength']) {
						$row55['Text'] = substr($row55['Text'],0,$clSettings['DetailsPopDescriptionLength']) . '... <br>[<a href="'.$MainURL.'/calendar/details/'.$row55['RecordNumber'].'.html" target="_blank">'.$MsgText[1][86].'</a>]';
					}
					else {
					
						if (strpos($row55['Text'],'@',0) !== false && strpos($row55['Text'],'mailto:',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];
							}
						
						
							$row55['Text'] = preg_replace("/([^:>][\w\.-]+)(@)([\w\.-]+)/ie", "'<script language=\"JavaScript\">var '.\$Random1.' = \'\\1\'; var '.\$Random2.' = \'\\3\'; document.write(\'<a href=\"mai\'+\'lto:\'+'.\$Random1.'+String.fromCharCode(64)+'.\$Random2.'+\'\">\'+'.\$Random1.'+String.fromCharCode(64)+'.\$Random2.'+\'</a>\');</script>'", $row55['Text']);			
				
						} // end if @ found in contents
					

						# convert http urls to hyperlinks 
						//$row55['Text'] = preg_replace("/(http:\/\/)([\w\.-]+)/e", "'<a href=\"\\0\" target=\"_blank\">\\0</a>'", $row55['Text']);
						//$row55['Text'] = preg_replace("/([^\">]http:\/\/)([a-zA-Z0-9-.\/]+)([,.]?[ ]?)/e", "'<a href=\"\\0\" target=\"_blank\">\\0</a>'", $row55['Text']);
						$row55['Text'] = preg_replace("/(?<!\")(http:\/\/)([\w\.\-\/]+)/e", "'<a href=\"\\0\" target=\"_blank\">\\0</a>'", $row55['Text']);
					
					}
				}
				
				
								
				if ($clSettings['ShowPoster'] != 'n' && $row55['Username'] != '') { 
								
					$query5 = "select DisplayName from `".$Settings['DBPrefix']."core-Users` where Username='".$row55['Username']."' limit 1";
					$result5 = mysql_query($query5) or die (mysql_error());
					$row5 = mysql_fetch_array($result5);
					
					if ($row5['DisplayName'] == '') {
						$row5['DisplayName'] = $row55['Username'];
					}
					
				
					if ($LoggedIn == 'y') {
						$PageContents .= '<tr><td colspan="2" bgcolor="'.$Colors['CLContentBG'].'"><font face="'.$FontFace.'" size="'.$FontSize.'"><br>'.$row55['Text'].'<br><br><br><br><div align="right"><font size="-2">'.$MsgText[1][87].': <a href="'.$MainURL.'/profile/'.$row55['Username'].'.html" target="_blank">'.$row5['DisplayName'].'</a></font></div></td></tr>';
					}
					else {
						$PageContents .= '<tr><td colspan="2" bgcolor="'.$Colors['CLContentBG'].'"><font face="'.$FontFace.'" size="'.$FontSize.'"><br>'.$row55['Text'].'<br><br><br><br><div align="right"><font size="-2">'.$MsgText[1][87].': '.$row5['DisplayName'].'</font></div></td></tr>';
					}

				}
				else {
					$PageContents .= '<tr><td colspan="2" bgcolor="'.$Colors['CLContentBG'].'"><font face="'.$FontFace.'" size="'.$FontSize.'"><br>'.$row55['Text'].'<br><br><br></td></tr>';
				}
				
	
		if ($Arguments4 != '') {
			$DateOptions = '/' . $Arguments4;
		}
		
		$PageContents .= '</table>
		</td></tr></table></div><br><table width="100%" border="0" cellpadding="7" cellspacing="0"><tr>
      <td width="50%" align="center" bgcolor="'.$Colors['CLContentBG'].'"><font face="'.$FontFace.'" size="'.$FontSize.'"><a href="'.$MainURL.'/printable/calendar/details/'.$Arguments3.$DateOptions.'.html" target="_blank">'.$MsgText[1][98].'</a></td>
      <td width="50%" align="center" bgcolor="'.$Colors['CLContentBG'].'"><font face="'.$FontFace.'" size="'.$FontSize.'"><a href="javascript:window.close();">'.$MsgText[1][99].'</a></td>
    </tr></table>&nbsp;';	
			
			
		}
		else {
			//$PageTitle = '<div align="'.$AlignmentCodes[$clSettings['TitleAlignment']].'">'.$clSettings['PageTitle'].' - Details</div>';
			$BrowserTitle = $clSettings['PageTitle'];
					
			$PageContents .= $MsgText[1][97];
		
		}
		
			
		
		print '<html><head>
<title>'.$BrowserTitle.'</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'].'" leftmargin="0" marginwidth="0" topmargin="0" marginheight="0" rightmargin="0" style="margin:0">
'.$PageContents.'
</body>
</html>';

		exit();
		
				
	} // end if showing a specific event's details, in a pop up window
	
	else {
	// showing the full calendar view
	
	
		if ($clSettings['TitleImage'] != '') {
			$PageTitle = '<div align="'.$AlignmentCodes[$clSettings['TitleAlignment']].'"><img src="'.$BaseURL.$clSettings['TitleImage'].'" alt="'.$clSettings['PageTitle'].'" border="0"></div>';	
		}
		else {
			$PageTitle = '<div align="'.$AlignmentCodes[$clSettings['TitleAlignment']].'">'.$clSettings['PageTitle'].'</div>';
		}
		
		//$PageTitle = '<div align="'.$AlignmentCodes[$clSettings['TitleAlignment']].'">'.$clSettings['PageTitle'].'</div>';
		$BrowserTitle = $clSettings['PageTitle'];
		$LocationBar = '<a href="'.$IndexURL.'">'.$MsgText[0][1].'</a> > '.$clSettings['PageTitle'];
		
		
		if ($clSettings['DayNamesStyle'] == 1 || $clSettings['DayNamesStyle'] == '') {		
			$DayNames = array ('',$MsgText[0][27],$MsgText[0][28],$MsgText[0][29],$MsgText[0][30],$MsgText[0][31],$MsgText[0][32],$MsgText[0][33]);
		}
		else if ($clSettings['DayNamesStyle'] == 2) {
			$DayNames = array ('',$MsgText[0][71],$MsgText[0][72],$MsgText[0][73],$MsgText[0][74],$MsgText[0][75],$MsgText[0][76],$MsgText[0][77]);
		}
				
	
		$Arguments2++; $Arguments2--;
		if ($Arguments2 != '0') {
			$Month = $Arguments2;
		}
		else {
			$Month = date('n',GetTimestamp());
		}
		
		$Arguments3++; $Arguments3--;
		if ($Arguments3 != '0') {
			$Year = $Arguments3;
		}
		else {
			$Year = date('Y',GetTimestamp());
		}
		
		
		
		$MonthStartTimestamp = mktime(0,0,0,$Month,1,$Year);
		
		$LastMonthTimestamp = mktime(0,0,0,($Month-1),1,$Year);
		$NextMonthTimestamp = mktime(0,0,0,($Month+1),1,$Year);
		
		$DaysInMonth = date('t',$MonthStartTimestamp);
		//print $DaysInMonth.'<br>';
		
		$GetDateArray = getdate($MonthStartTimestamp);
		$TodayDateArray = getdate(GetTimestamp()+$TZO);
		
		$GetLastMonthDateArray = getdate($LastMonthTimestamp);
		$GetNextMonthDateArray = getdate($NextMonthTimestamp);
		
			
			
		
		if ($clSettings['TopText'] != '') {
			$TopTextInsert = '<div align="'.$AlignmentCodes[$clSettings['TopTextAlignment']].'">'.$clSettings['TopText'].'</div><br>';
		}
		if ($clSettings['BottomText'] != '') {
			$BottomTextInsert = '<br><div align="'.$AlignmentCodes[$clSettings['BottomTextAlignment']].'">'.$clSettings['BottomText'].'</div><br>';
		}
		
		
		
		if ($clSettings['NumberLocation'] < 1) {
			$clSettings['NumberLocation'] = 1;
		}
	
		// top
		$AlignmentCodes[1] = 'left';
		$AlignmentCodes[2] = 'center';
		$AlignmentCodes[3] = 'right';
		
		// bottom
		$AlignmentCodes[4] = 'left';
		$AlignmentCodes[5] = 'center';
		$AlignmentCodes[6] = 'right';
		
	
		
		DBConnect();
		
		
		$query551 = "select * from `".$Settings['DBPrefix']."cl-Events` where MinLevel<='".$UserLevel."'";
		$result551 = mysql_query($query551) or die (mysql_error());
		while ($row551 = mysql_fetch_array($result551)) {
		
			$EventTitle[$row551['RecordNumber']] = $row551['Title'];
			$EventText[$row551['RecordNumber']] = $row551['Text'];
			$EventUsername[$row551['RecordNumber']] = $row551['Username'];
			$EventStart[$row551['RecordNumber']] = $row551['StartTime'];
			$EventEnd[$row551['RecordNumber']] = $row551['EndTime'];
			$EventLink[$row551['RecordNumber']] = $row551['Link'];
			$EventType[$row551['RecordNumber']] = $row551['EventType'];
			$Priority[$row551['RecordNumber']] = $row551['Priority'];
			
		}
			
											
		$query55 = "select * from `".$Settings['DBPrefix']."cl-EventDates` where DateCode>=".($MonthStartTimestamp+$TZO)." and DateCode<".($NextMonthTimestamp-1+$TZO)." order by DateCode asc";
		$result55 = mysql_query($query55) or die (mysql_error());
		while ($row55 = mysql_fetch_array($result55)) {
			$DateSplit = getdate($row55['DateCode']-$TZO);
			
			if (isset($EventTitle[$row55['EventID']])) {
			
				$IDs[$DateSplit['year']][$DateSplit['mon']][$DateSplit['mday']][] = $row55['EventID'];
				//print $DateSplit['mday'].' '.$EventTitle[$row55['EventID']].' '.$row55['EventID'].'<br>';
		
				
							
				if ($EventStart[$row55['EventID']] >= 0) {
					
					$ThisStartTimePrint = '';
									
					if ($EventStart[$row55['EventID']] >= 0) {
					
						$Hours = 0;
						$Minutes = 0;
						
						$Seconds = $EventStart[$row55['EventID']];
						while ($Seconds >= 3600) {
							$Seconds = $Seconds - 3600;
							$Hours++;					
						}
						while ($Seconds >= 60) {
							$Seconds = $Seconds - 60;
							$Minutes++;					
						}
						
						
						$Suffix = 'am';
						if ($Hours >= 12) {
							$Hours -= 12;
							$Suffix = 'pm';
						}	
						if ($Hours == 0) {
							$Hours = 12;
						}
						
						if ($Minutes < 10) {
							$Minutes = '0' . $Minutes;
						}
							
						$ThisStartTimePrint = ' (' . $Hours . ':' . $Minutes . $Suffix;
	
						//if ($EventEnd[$row55['EventID']] >= 0 && $EventEnd[$row55['EventID']] > $EventStart[$row55['EventID']]) {
						if ($EventEnd[$row55['EventID']] >= 0) {
							
							$Hours = 0;
							$Minutes = 0;
						
							$Seconds = $EventEnd[$row55['EventID']];
							while ($Seconds >= 3600) {
								$Seconds = $Seconds - 3600;
								$Hours++;					
							}
							while ($Seconds >= 60) {
								$Seconds = $Seconds - 60;
								$Minutes++;					
							}
						
							
							$Suffix = 'am';
							if ($Hours >= 12) {
								$Hours -= 12;
								$Suffix = 'pm';
							}
							if ($Hours == 0) {
								$Hours = 12;
							}
							
							if ($Minutes < 10) {
								$Minutes = '0' . $Minutes;
							}
						
							$ThisStartTimePrint .= ' - ' . $Hours . ':' . $Minutes . $Suffix . ')';
							
						}
						else {
							$ThisStartTimePrint .= ')';
						}
					
				
						$StartTimePrint[$row55['EventID']] = $ThisStartTimePrint;
									
					}
					else {
						$StartTimePrint[$row55['EventID']] = '';
					}
				
				}	
			}
		}
		
		
		for ($i = 1; $i <= $DaysInMonth; $i++) {
			if (count($IDs[$Year][$Month][$i]) > 1) {
			//print $i.'<br>';	
			//print '-'.count($IDs[$Year][$Month][$i]).'<br><br>';
				
				// sort the events by title
				for ($k = 0; $k < count($IDs[$Year][$Month][$i]); $k++) {
					for ($j = 0; $j < (count($IDs[$Year][$Month][$i])-1); $j++) {
				
						if ($EventTitle[$IDs[$Year][$Month][$i][$j]] > $EventTitle[$IDs[$Year][$Month][$i][$j+1]]) {
						
							$Swap = $IDs[$Year][$Month][$i][$j+1];
							
							$IDs[$Year][$Month][$i][$j+1] = $IDs[$Year][$Month][$i][$j];
							
							$IDs[$Year][$Month][$i][$j] = $Swap;
						
						}
						
					}
				}
				
				// sort the events by starting time
				for ($k = 0; $k < count($IDs[$Year][$Month][$i]); $k++) {
					for ($j = 0; $j < (count($IDs[$Year][$Month][$i])-1); $j++) {										
					
						if ($EventStart[$IDs[$Year][$Month][$i][$j]] > $EventStart[$IDs[$Year][$Month][$i][$j+1]]) {
						
							$Swap = $IDs[$Year][$Month][$i][$j+1];
							
							$IDs[$Year][$Month][$i][$j+1] = $IDs[$Year][$Month][$i][$j];
							
							$IDs[$Year][$Month][$i][$j] = $Swap;
						
						}
					
					}
				}
				
				// sort the events by priority number
				for ($k = 0; $k < count($IDs[$Year][$Month][$i]); $k++) {
					for ($j = 0; $j < (count($IDs[$Year][$Month][$i])-1); $j++) {										
					
						if ($Priority[$IDs[$Year][$Month][$i][$j]] > $Priority[$IDs[$Year][$Month][$i][$j+1]]) {
						
							$Swap = $IDs[$Year][$Month][$i][$j+1];
							
							$IDs[$Year][$Month][$i][$j+1] = $IDs[$Year][$Month][$i][$j];
							
							$IDs[$Year][$Month][$i][$j] = $Swap;
						
						}
					
					}
				}
				
				// sort the holidays or events to the top, depending on the settings
				if ($clSettings['SortOrder'] == '2') {
					for ($k = 0; $k < count($IDs[$Year][$Month][$i]); $k++) {
						for ($j = 0; $j < (count($IDs[$Year][$Month][$i])-1); $j++) {
							
							if ($EventType[$IDs[$Year][$Month][$i][$j]] < $EventType[$IDs[$Year][$Month][$i][$j+1]]) {
							
								$Swap = $IDs[$Year][$Month][$i][$j+1];
								
								$IDs[$Year][$Month][$i][$j+1] = $IDs[$Year][$Month][$i][$j];
								
								$IDs[$Year][$Month][$i][$j] = $Swap;
							
							} 
										
						}
					}
				}
				else {
					for ($k = 0; $k < count($IDs[$Year][$Month][$i]); $k++) {
						for ($j = 0; $j < (count($IDs[$Year][$Month][$i])-1); $j++) {
							
							if ($EventType[$IDs[$Year][$Month][$i][$j]] > $EventType[$IDs[$Year][$Month][$i][$j+1]]) {
							
								$Swap = $IDs[$Year][$Month][$i][$j+1];
								
								$IDs[$Year][$Month][$i][$j+1] = $IDs[$Year][$Month][$i][$j];
								
								$IDs[$Year][$Month][$i][$j] = $Swap;
							
							}
										
						}
					}				
				}
					
			}
		}
		
		
		if ($clSettings['DetailsDisplay'] == '2') {
		
			$PageContents .= "<script language=\"JavaScript\"><!--

				function DisplayDetails(EventID) {

					var WindowID = window.open('" . $MainURL . "/calendar/details-pop/'+EventID+'.html','CalendarDetails','width=".$clSettings['PopWidth'].",height=".$clSettings['PopHeight'].",left='+(screen.width-".$clSettings['PopWidth'].")/2+',top='+(screen.height-".$clSettings['PopHeight'].")/2+',scrollbars=yes,resizable=yes');

				}

			//--></script>";
				
		}
		
		if ($Arguments2 == '0') {
			$JumpBoxesMonthSelected[date('n',GetTimestamp())] = ' selected';
			$JumpBoxesYearSelected[date('Y',GetTimestamp())] = ' selected';
		}
		else {
			$JumpBoxesMonthSelected[$Arguments2] = ' selected';
			$JumpBoxesYearSelected[$Arguments3] = ' selected';
		}
		
		
		$PageContents .= $TopTextInsert . '<div align="center"><table width="98%" border="0" cellpadding="0" cellspacing="0"><tr><td align="right"><form name="CalendarJump"><select name="Month" style="'.$FormStyle.'">
			<option value="1"'.$JumpBoxesMonthSelected[1].'> '.$MsgText[0][34].'</option>
			<option value="2"'.$JumpBoxesMonthSelected[2].'> '.$MsgText[0][35].'</option>
			<option value="3"'.$JumpBoxesMonthSelected[3].'> '.$MsgText[0][36].'</option>
			<option value="4"'.$JumpBoxesMonthSelected[4].'> '.$MsgText[0][37].'</option>
			<option value="5"'.$JumpBoxesMonthSelected[5].'> '.$MsgText[0][38].'</option>
			<option value="6"'.$JumpBoxesMonthSelected[6].'> '.$MsgText[0][39].'</option>
			<option value="7"'.$JumpBoxesMonthSelected[7].'> '.$MsgText[0][40].'</option>
			<option value="8"'.$JumpBoxesMonthSelected[8].'> '.$MsgText[0][41].'</option>
			<option value="9"'.$JumpBoxesMonthSelected[9].'> '.$MsgText[0][42].'</option>
			<option value="10"'.$JumpBoxesMonthSelected[10].'> '.$MsgText[0][43].'</option>
			<option value="11"'.$JumpBoxesMonthSelected[11].'> '.$MsgText[0][44].'</option>
			<option value="12"'.$JumpBoxesMonthSelected[12].'> '.$MsgText[0][45].'</option>
		</select> <select name="Year" style="'.$FormStyle.'">
			<option value="2004"'.$JumpBoxesYearSelected[2004].'> 2004</option>
			<option value="2005"'.$JumpBoxesYearSelected[2005].'> 2005</option>
			<option value="2006"'.$JumpBoxesYearSelected[2006].'> 2006</option>
			<option value="2007"'.$JumpBoxesYearSelected[2007].'> 2007</option>
			<option value="2008"'.$JumpBoxesYearSelected[2008].'> 2008</option>
			<option value="2009"'.$JumpBoxesYearSelected[2009].'> 2009</option>
			<option value="2010"'.$JumpBoxesYearSelected[2010].'> 2010</option>
			<option value="2011"'.$JumpBoxesYearSelected[2011].'> 2011</option>
			<option value="2012"'.$JumpBoxesYearSelected[2012].'> 2012</option>
			<option value="2013"'.$JumpBoxesYearSelected[2013].'> 2013</option>
			<option value="2014"'.$JumpBoxesYearSelected[2014].'> 2014</option>
			<option value="2015"'.$JumpBoxesYearSelected[2015].'> 2015</option>
			<option value="2016"'.$JumpBoxesYearSelected[2016].'> 2016</option>
			<option value="2017"'.$JumpBoxesYearSelected[2017].'> 2017</option>
			<option value="2018"'.$JumpBoxesYearSelected[2018].'> 2018</option>
			<option value="2019"'.$JumpBoxesYearSelected[2019].'> 2019</option>
			<option value="2020"'.$JumpBoxesYearSelected[2020].'> 2020</option>
		</select> <input type="button" value="Go" style="'.$FormStyle.'" onClick="window.location=\''.$MainURL.'/calendar/\'+document.forms[\'CalendarJump\'].Month.value+\'/\'+document.forms[\'CalendarJump\'].Year.value+\'.html\'">
</td></tr></form></table><img src="'.$ImagesURL.'/admin/spacer.gif" border="0" width="1" height="5" alt=""></div><div align="center"><table width="98%" cellpadding=1 cellspacing=0 border=0><tr><td bgcolor="'.$Colors['CLBorder'].'">
		
		<!-- <table width="100%" cellpadding=1 cellspacing=0 border=0><tr><td width="100%"><img src="'.$ImagesURL.'/admin/spacer.gif" border="0" width="1" height="1" alt=""></td></tr></table> -->
	
	
		<table width="100%" cellpadding=3 cellspacing=1 border=0><tr>
	
		<!-- <td width="1%" bgcolor="'.$Colors['CLBorder'].'"><img src="'.$ImagesURL.'/admin/spacer.gif" border="0" width="1" height="1" alt=""></td> -->
		<td colspan="7" width="100%" bgcolor="'.$Colors['CLTitleBG'].'">
	
		<table width="100%" cellpadding=3 cellspacing=0 border=0>
		<tr>
		<td width="28%" align="center" valign="middle"><font face="'.$FontFace.'" size="'.$FontSize.'"><font size="2"><a href="'.$MainURL.'/calendar/'.$GetLastMonthDateArray['mon'].'/'.$GetLastMonthDateArray['year'].'.html"><font color="'.$Colors['CLTitleText'].'">'.$MsgText[0][33+date('n',$LastMonthTimestamp)].'</a></font></td>
		<td width="44%" align="center" valign="middle"><font face="'.$FontFace.'" size="'.$FontSize.'" color="'.$Colors['CLTitleText'].'"><font size="4"><b>'.$MsgText[0][33+date('n',$MonthStartTimestamp)].' '.date('Y',$MonthStartTimestamp).'</b></font></td>
		<td width="28%" align="center" valign="middle"><font face="'.$FontFace.'" size="'.$FontSize.'"><font size="2"><a href="'.$MainURL.'/calendar/'.$GetNextMonthDateArray['mon'].'/'.$GetNextMonthDateArray['year'].'.html"><font color="'.$Colors['CLTitleText'].'">'.$MsgText[0][33+date('n',$NextMonthTimestamp)].'</a></font></td>
		</tr>
		</table>
		
		</td>
		<!-- <td width="1%" bgcolor="'.$Colors['CLBorder'].'"><img src="'.$ImagesURL.'/admin/spacer.gif" border="0" width="1" height="1" alt=""></td> -->
		
		</tr>';
			
	
		$PageContents .= '<tr><!-- <td width="1%" bgcolor="'.$Colors['CLBorder'].'"><img src="'.$ImagesURL.'/admin/spacer.gif" border="0" width="1" height="1" alt=""></td> -->';
		
		
		$ColWidths = Array(0,15,14,14,14,14,14,15);
		
		for ($col = 1; $col <= 7; $col++) {
			
			$PageContents .= '<td width="'.$ColWidths[$col].'%" bgcolor="'.$Colors['CLDaysBG'].'"><div align="center"><font face="'.$FontFace.'" size="'.$FontSize.'" color="'.$Colors['CLDaysText'].'"><b>'.$DayNames[$col].'</b></div></td>';
			
		}
		
		$PageContents .= '<!-- <td width="1%" bgcolor="'.$Colors['CLBorder'].'"><img src="'.$ImagesURL.'/admin/spacer.gif" border="0" width="1" height="1" alt=""></td> --></tr>';
		
		
		
		
		$row = 0;
		while (($MonthDay + 1) <= $DaysInMonth) {
			
			$row++;
			$PageContents .= '<tr><!-- <td width="1%" bgcolor="'.$Colors['CLBorder'].'"><img src="'.$ImagesURL.'/admin/spacer.gif" border="0" width="1" height="1" alt=""></td> -->';
		
			
			for ($col = 1; $col <= 7; $col++) {
			
				$Cell = (($row - 1) * 7) + $col;
				
				$CalendarDay = 'n';
				
				if (($MonthDay + 1) > $DaysInMonth) {
					$CalendarDay = 'n';		
				}
				else {
				
					if (!$FirstDayFound) {
						if (($GetDateArray['wday'] + 1) == $Cell) {
							$MonthDay = 1;
							$FirstDayFound = 'y';
							
							$CalendarDay = 'y';					
						}
						else {
							$CalendarDay = 'n';
						}
					}
					else {
						$MonthDay++;
						
						$CalendarDay = 'y';
						
					}
				
				} // end if still not past the end of the month
			
				if ($CalendarDay == 'y') {
				
					$CellContents = '';
					if ($clSettings['ItemFontFace'] != '') {
						$CellContents .= '<font face="'.$clSettings['ItemFontFace'].'">';
					}
					if ($clSettings['ItemFontSize'] != '') {
						$CellContents .= '<font size="'.$clSettings['ItemFontSize'].'">';
					} 
					
					
					if (count($IDs[$Year][$Month][$MonthDay]) > 0) {
						for ($e = 0; $e < count($IDs[$Year][$Month][$MonthDay]); $e++) {
							if ($EventText[$IDs[$Year][$Month][$MonthDay][$e]] != '') {
								if ($clSettings['DetailsDisplay'] == '1') {
									$CellContents .= $clSettings['GridPrefix'].'<a href="' . $MainURL . '/calendar/details/' . $IDs[$Year][$Month][$MonthDay][$e] . '.html"><font color="'.$Colors['CLEventTitleText'].'">' . $EventTitle[$IDs[$Year][$Month][$MonthDay][$e]] . '</font></a><font size="'.($FontSize-1).'" color="'.$Colors['CLEventDetailsText'].'">'.$StartTimePrint[$IDs[$Year][$Month][$MonthDay][$e]].'<br></font>';
								}
								else if ($clSettings['DetailsDisplay'] == '2') {
									$CellContents .= $clSettings['GridPrefix'].'<a href="javascript:DisplayDetails(' . $IDs[$Year][$Month][$MonthDay][$e] . ');"><font color="'.$Colors['CLEventTitleText'].'">' . $EventTitle[$IDs[$Year][$Month][$MonthDay][$e]] . '</font></a><font size="'.($FontSize-1).'" color="'.$Colors['CLEventDetailsText'].'">'.$StartTimePrint[$IDs[$Year][$Month][$MonthDay][$e]].'<br></font>';
								}
							}
							else {
								$CellContents .= $clSettings['GridPrefix'] . '<font color="'.$Colors['CLEventTitleText'].'">' . $EventTitle[$IDs[$Year][$Month][$MonthDay][$e]] . '</font><font size="'.($FontSize-1).'" color="'.$Colors['CLEventDetailsText'].'">'.$StartTimePrint[$IDs[$Year][$Month][$MonthDay][$e]].'<br></font>';
							}
						}		
					}
					else {
						$CellContents = '<br><br><br>';
					}
					
					if ($Month == $TodayDateArray['mon'] && $Year == $TodayDateArray['year'] && $MonthDay == $TodayDateArray['mday']) {
						$BGColor = $Colors['CLCurrentDayBG'];
					}
					else {
						$BGColor = $Colors['CLCalDaysBG'];
					}
					
									
					if ($clSettings['NumberLocation'] <= 3) {
						if ($CellContents != '<br><br><br>') {
							$PageContents .= '<td bgcolor="'.$BGColor.'" valign="top"><div align="'.$AlignmentCodes[$clSettings['NumberLocation']].'"><font face="'.$FontFace.'" size="'.$FontSize.'"><b><a href="'.$MainURL.'/calendar/day/' . $MonthDay . '/'.$Month.'/'.$Year.'.html"><font color="'.$Colors['CLDayNumbersText'].'">' . $MonthDay . '</font></a></b></div>' . $CellContents . '</td>';
						}
						else {
							$PageContents .= '<td bgcolor="'.$BGColor.'" valign="top"><div align="'.$AlignmentCodes[$clSettings['NumberLocation']].'"><font face="'.$FontFace.'" size="'.$FontSize.'" color="'.$Colors['CLDayNumbersText'].'"><b>' . $MonthDay . '</a></b></div>' . $CellContents . '</td>';
						}
					}
					else {
						if ($CellContents != '<br><br><br>') {
							$PageContents .= '<td height="100%" bgcolor="'.$BGColor.'" valign="top"><table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0"><tr><td height="100%" valign="top"><font face="'.$FontFace.'" size="'.$FontSize.'">' . $CellContents . '</td></tr><tr><td height="10" valign="bottom"><div align="'.$AlignmentCodes[$clSettings['NumberLocation']].'"><font face="'.$FontFace.'" size="'.$FontSize.'"><b><a href="'.$MainURL.'/calendar/day/' . $MonthDay . '/'.$Month.'/'.$Year.'.html">' . $MonthDay . '</a></b></div></td></tr></table></td>';
						}
						else {
							$PageContents .= '<td height="100%" bgcolor="'.$BGColor.'" valign="top"><table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0"><tr><td height="100%" valign="top"><font face="'.$FontFace.'" size="'.$FontSize.'">' . $CellContents . '</td></tr><tr><td height="10" valign="bottom"><div align="'.$AlignmentCodes[$clSettings['NumberLocation']].'"><font face="'.$FontFace.'" size="'.$FontSize.'"><b>' . $MonthDay . '</b></div></td></tr></table></td>';
						}
					}
						
				}
				else {
					$PageContents .= '<td bgcolor="'.$Colors['CLFillerDaysBG'].'"><font face="'.$FontFace.'" size="'.$FontSize.'">&nbsp;<br><br><br>&nbsp;</td>';
				}
			
			} // end for (column cells)
			
			
			$PageContents .= '<!-- <td width="1%" bgcolor="'.$Colors['CLBorder'].'"><img src="'.$ImagesURL.'/admin/spacer.gif" border="0" width="1" height="1" alt=""></td> --></tr>';
		
		} // end while (rows)
		
		
		$PageContents .= '</table>
		<!-- <table width="100%" cellpadding=1 cellspacing=0 border=0><tr>
		<td><img src="'.$ImagesURL.'/admin/spacer.gif" border="0" width="1" height="1" alt=""></td>
		</tr></table> -->
		</td></tr></table></div>'.$BottomTextInsert; 
	
	} // end if showing the main calendar
			
	
	// ========================================================================================




?>
