function init()
{
var DefaultDate = new Date();
if (document.forms.question.month.value == "0" &&
    document.forms.question.year.value  == "0" )
	{document.forms.question.month.value = DefaultDate.getMonth() + 1;
	 document.forms.question.year.value = DefaultDate.getFullYear()};
CheckDate();
}
function CheckDate()
{
var findDate = new Date();
var firstyear=2009;
var firstmonth=8;
var checkmonth = document.forms.question.month.value - 1;
var checkyear = document.forms.question.year.value;
var current_month = findDate.getMonth();
var current_year = findDate.getFullYear();
if (checkyear > current_year) return;
if (checkyear == current_year && checkmonth > current_month) return;
if (checkyear < firstyear) return;
if (checkyear == firstyear && checkmonth < firstmonth) return;
document.getElementById("previousmonth").style.visibility="visible";
document.getElementById("nextmonth").style.visibility="visible";
if (checkyear == current_year && checkmonth == current_month)
	document.getElementById("nextmonth").style.visibility="hidden";
if (checkyear == firstyear && checkmonth == firstmonth)
	document.getElementById("previousmonth").style.visibility="hidden";
MakeCalendar();
}
function MakeCalendar()
{
// set variables for thumbnail name as strings
var picmonth="";
var picyear="";
var picdate="";
var cal='<TABLE cellspacing="5"><TR>';

// set arrays for months
var month_of_year = new Array('January','February','March','April','May','June','July','August','September','October','November','December');
var days_in_month = new Array(31,28,31,30,31,30,31,31,30,31,30,31);

// set variables 
var month = window.document.question.month.value - 1;
var year = window.document.question.year.value;
if (year % 4 == 0) days_in_month[1] = 29; 		// for leap year
var Calendar = new Date();
var today = Calendar.getDate();
var thismonth = Calendar.getMonth();
var thisyear = Calendar.getFullYear();
Calendar.setMonth(month);
Calendar.setYear(year);
Calendar.setDate(1);
var firstDay = Calendar.getDay();
if (thismonth == month && thisyear == year)
	var currentmonth = true; else currentmonth = false;

// determine number of boxes needed
var squares = days_in_month[month] + firstDay;
if (squares != 28)
   {if (squares > 35) squares = 42; else squares = 35};

// start loop to draw boxes
for (var i = 1; i <= squares; i++)
{
var realdate = i - firstDay;
if (i <= firstDay || realdate > days_in_month[month])
   cal +='<TD id="photobox">&nbsp;</TD>';
   else	
{	// create the file name for the thumbnail
	picdate = realdate.toString();
	if (picdate.length == 1) picdate = "0" + picdate;
	var newmonth = Calendar.getMonth() + 1;
	picmonth = newmonth.toString();	
	if (picmonth.length == 1) picmonth = "0" + picmonth;
	picyear = year.charAt(2) + year.charAt(3);
	var pic = picmonth+picdate+picyear;
 	if (currentmonth == true && realdate > today)
	cal+='<TD id="photobox"><div id="empty">'+realdate+'&nbsp;</div></TD>';	
 	else
	cal+='<TD id="photobox" background="http://www.daytondancers.com/photo_cal/thumbnails/' + pic + '.jpg"><a href="http://www.daytondancers.com/photo_cal/images/' + pic +'.jpg" rel="lightbox">'+realdate+'&nbsp;</a></TD>';	
}
if (i % 7 == 0)
  cal+='</TR><TR>';
}
  cal+='</TR></TABLE>';
    document.getElementById("cal_layer").innerHTML = cal;
}

function PreviousMonth()
{if (document.forms.question.month.value == 1)
{ document.forms.question.month.value = 12; document.forms.question.year.value--;}
else document.forms.question.month.value-- ;
CheckDate();
}

function NextMonth()
{if (document.forms.question.month.value == 12)
{ document.forms.question.month.value = 1; document.forms.question.year.value++;}
else document.forms.question.month.value++ ;
CheckDate();
}