var months = [	'January','February','March',
				'April','May','June',
				'July','August','September',
				'October','November','December'];

var daycounts = [31,29,31,30,31,30,31,31,30,31,30,31];

//2002 firstdays = [1,4,4,0,2,5,0,3,6,1,4,6];
//2003 firstdays = [2,5,5,1,3,6,1,4,0,2,5,0];
//2004 firstdays = [3,6,7,3,5,1,3,6,2,4,0,2];
//2005 firstdays = [5,1,1,4,6,2,4,0,3,5,1,3];
//2006 firstdays = [6,2,2,5,0,3,5,1,4,6,2,4];
//2007 firstdays = [7,3,3,6,1,4,6,2,5,7,3,5];

//Mon=7
//Tue=1
//Wed=2
//Thu=3
//Fri=4
//Sat=5
//Sun=6

var firstdays = [1,4,5,1,3,6,1,4,7,2,5,7];

// Dates. [fromday,frommonth,today,tomonth,message,link,type(trail,misc,open)]

var apps =	[	[6,1,6,1,"King Of The Glades Open #1 (Holiday Park)","2008KOTG.pdf","open"],
                [20,1,20,1,"C-16 (Ida/Osbourne)","trail.php","trail"],
                [3,2,3,2,"King Of The Glades Open #2 (Holiday Park)","2008KOTG.pdf","open"],
				[17,2,17,2,"Alligator Alley MM-41","trail.php","trail"],
                [2,3,2,3,"King Of The Glades Open #3 (Holiday Park)","2008KOTG.pdf","open"],
				[16,3,16,3,"Holy Lands","trail.php","trail"],
				[6,4,6,4,"King Of The Glades Open #4 (Holiday Park)","2008KOTG.pdf","open"],
				[6,4,6,4,"Gambler Open","http://www.gambler-bang.com/","misc"],
                [27,4,27,4,"S.A.F.E.R. Open","http://www.sfanglers.com/tournaments.htm","misc"],
                [20,4,20,4,"Holiday Park","trail.php","trail"],
				[4,5,4,5,"King Of The Glades Classic - Qualifiers Only (TBD)","2007KOTG.pdf","open"],
                [18,5,18,5,"Sawgrass","trail.php","trail"],
                [25,5,25,5,"Bass N' Fools Spring Fling (Holiday Park)","http://www.bassnfools.com","misc"],
                [1,6,1,6,"C-14","trail.php","trail"]
     		];

function CheckDate(month,dayno)
{
	var retval = new String(dayno);
	var m = month + 1;

	for(var app = 0; app < apps.length; app++)
	{
		if(m == apps[app][1] ) //first month
		{
			if(apps[app][3] - apps[app][1] > 0)
			{
				if(dayno >= apps[app][0])
				{
					retval ='<div class="' +apps[app][6] +'" title="' + apps[app][4] + '"><a href="' + apps[app][5] + '">' + dayno + '</a></div>';
				}
			}
			else
			{
				if(dayno >= apps[app][0] && dayno <= apps[app][2])
				{
					retval ='<div class="' +apps[app][6] +'" title="' + apps[app][4] + '"><a href="' + apps[app][5] + '">' + dayno + '</a></div>';
				}
			}
		}
		else if(m == apps[app][3]) // second month
		{
			if(dayno <= apps[app][2])
			{
				retval ='<div class="' +apps[app][6] +'" title="' + apps[app][4] + '"><a href="' + apps[app][5] + '">' + dayno + '</a></div>';
			}
		}
		else if( m > apps[app][1] && m < apps[app][3] )
		{    
			retval ='<div class="' +apps[app][6] +'" title="' + apps[app][4] + '"><a href="' + apps[app][5] + '">' + dayno + '</a></div>';
		}
	}
	return retval;
}

function PrintMonth(month)

{
	var done = false;
	var day = 0;

	document.write("<table class='inner'><caption><b>" + months[month] + "</b></caption><thead>");
	document.write('<td class="cal">Mo</td><td class="cal">Tu</td><td class="cal">We</td><td class="cal">Th</td><td class="cal">Fr</td><td class="cal">Sa</td><td class="cal">Su</td></tdead>');

	while(!done)
	{
		document.write("<tr>");
		PrintWeek(month,day, firstdays[month], daycounts[month]);
		document.write("</tr>");
		day = day + 7;
		if( day > daycounts[month] + firstdays[month])
		{
			done = true;
		}
	}

	document.write("</tbody></table><p>");
}

function PrintWeek(monthno,start,min,max)
{
	var d;
	var desc;
	for(var j = 0; j < 7; j++)
	{
		document.write("<td>");
		d = start + j;

		if(d >= min && d < max + min)
		{
			desc = CheckDate(monthno,d - min + 1);
			document.write(desc);
		}

		document.write("</td>");
	}
}

function PrintCalendar(rows)
{
	var mpl = 12/rows;
	var month = 0;
	
	while (month < 12)
	{
		document.write('<tr>');
		for (i=1;i<mpl+1 ;i++ )
		{
			document.write('<td class="outer" valign="top">');
			PrintMonth(month);
			document.write('</td>');
			month++;
		}
		document.write('</tr>');
	}			
}