<table width="100%" class="border" cellpadding="0" style="border-collapse: collapse">
<tr align="center">
		<td class="tcat" width="20%">
		{$lang['Calendar']}</td>
	</tr>
	<tr>
		<td class="row1">
		<font class="smallfont">
<?php
		$get_now_date = getdate();
		$now_year = $get_now_date[year];
		$now_month = $get_now_date[mon];
		$now_day = $get_now_date[mday];
		$month=$PowerBB->_POST['month'];
		$year=$PowerBB->_POST['year'];

		define ("ADAY", (60*60*24));
		if (!checkdate($month,1,$year)){
			$nowArray = getdate();
			$month = $nowArray[mon];
			$year = $nowArray[year];
		}

		$start = mktime (0, 0, 0, $month, 1, $year);

		$firstDayArray = getdate($start);

	?>


	<?php
	$days = Array($PowerBB->_CONF['template']['lang']['Sun'], $PowerBB->_CONF['template']['lang']['Mon'], $PowerBB->_CONF['template']['lang']['Tue'], $PowerBB->_CONF['template']['lang']['Wed'], $PowerBB->_CONF['template']['lang']['Thu'], $PowerBB->_CONF['template']['lang']['Fri'], $PowerBB->_CONF['template']['lang']['Sat'] );
	print "<div align='center' STYLE=\"cursor:hand;cursor:pointer\" ><center>\n<table class=border cellpadding='1' cellspacing='0' width='99%' >
	<tr>\n";

	foreach ($days as $day) {
		print "\t<td class=thead align='center' width='40'>$day</td>\n";
	}

	for ($count=0; $count < (6*7); $count++){
		$dayArray = getdate($start);
		if ((($count) % 7) == 0){
			if ($dayArray[mon] != $month)
				break;
				print "</tr>\n<tr>\n";
		}

		if ($count < $firstDayArray[wday] || $dayArray[mon] != $month) {
			print "\t<td><br></td>\n";
		}
		else {

			if ($now_day == $dayArray[mday] && $now_month == $month && $now_year == $year){
				print "\t<td class=tcat title=\"Date $firstDayArray[month] $dayArray[mday] $firstDayArray[year]\" onClick=\"SetFormat('$firstDayArray[month] $dayArray[mday] $firstDayArray[year]')\" onMouseover=\"this.className='tcat';\" onMouseout=\"this.className='tcat';\" >$dayArray[mday]</td>\n";
			}
			else{
				print "\t<td class=thead title=\"Date $firstDayArray[month] $dayArray[mday] $firstDayArray[year]\" onClick=\"SetFormat('$firstDayArray[month] $dayArray[mday] $firstDayArray[year]')\" onMouseover=\"this.className='tcat';\" onMouseout=\"this.className='thead';\" >$dayArray[mday]</td>\n";
			}
			$start += ADAY;
		}
	}

	print "</tr></table></center></div><div class=thead align='center'>";
	?>
		<script language="JavaScript">

		var fixd;

		function isGregLeapYear(year)
		{
		return year%4 == 0 && year%100 != 0 || year%400 == 0;
		}


		function gregToFixed(year, month, day)
		{
		var a = Math.floor((year - 1) / 4);
		var b = Math.floor((year - 1) / 100);
		var c = Math.floor((year - 1) / 400);
		var d = Math.floor((367 * month - 362) / 12);

		if (month <= 2)
		e = 0;
		else if (month > 2 && isGregLeapYear(year))
		e = -1;
		else
		e = -2;

		return 1 - 1 + 365 * (year - 1) + a - b + c + d + e + day;
		}

		function Hijri(year, month, day)
		{
		this.year = year;
		this.month = month;
		this.day = day;
		this.toFixed = hijriToFixed;
		this.toString = hijriToString;
		}

		function hijriToFixed()
		{
		return this.day + Math.ceil(29.5 * (this.month - 1)) + (this.year - 1) * 354 +
		Math.floor((3 + 11 * this.year) / 30) + 227015 - 1;
		}

		function hijriToString()
		{
		var months = new Array("Muharram","Safar","Rabi-al Awwal","Rabi-al Thani","Jumada al-Ula","Jumada al-Thani","Rajab","Sha\'ban","Ramadhan","Shawwal","Dh ul Qa\'dah","Dhul Hijjah");
		return this.day + " " + months[this.month - 1]+ " " + this.year;
		}

		function fixedToHijri(f)
		{
		var i=new Hijri(1100, 1, 1);
		i.year = Math.floor((30 * (f - 227015) + 10646) / 10631);
		var i2=new Hijri(i.year, 1, 1);
		var m = Math.ceil((f - 29 - i2.toFixed()) / 29.5) + 1;
		i.month = Math.min(m, 12);
		i2.year = i.year;
		i2.month = i.month;
		i2.day = 1;
		i.day = f - i2.toFixed() + 1;
		return i;
		}

		var tod=new Date();
		var weekday=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
		var monthname=new Array("January","February","March","April","May"," June","July","August","September","October","Novem ber","December");

		var y = tod.getFullYear();
		var m = tod.getMonth();
		var d = tod.getDate();
		var dow = tod.getDay();
		document.write(weekday[dow] + " " + d + " " + monthname[m] + " " + y);
		m++;
		fixd=gregToFixed(y, m, d);
		var h=new Hijri(1421, 11, 28);
		h = fixedToHijri(fixd);
		document.write(" CE | " + h.toString() + " AH &nbsp;&nbsp;");

		</script>
       </div>

		</font>
		</td>
	</tr>
</table>