<!--
/*
	Calendar for use on websites
	Modified by Doogle to work with Firefox and for multiple instances and different months.
*/
function cally(values){

var day_of_week = new Array('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
var month_of_year = new Array('January','February','March','April','May','June','July','August','September','October','November','December');

var Calendar = new Date();

var year = Calendar.getFullYear();
var month = Calendar.getMonth();
var today = Calendar.getDate();
var weekday = Calendar.getDay();

if(values==0){ // wanting previous month
	if(month==0){ // currently january
		year=year-1; // set previous month to last year in december
		month=11;
	}else{
		month=month-1;
	}
}else if(values==2){ // wanting next month
	if(month==11){ // currently december
		year=year+1; // set next month to next year in january
		month=0;
	}else{
		month=month+1;
	}
}

var DAYS_OF_WEEK = 7;
var DAYS_OF_MONTH = 31;
var cal;

Calendar.setDate(1); // Set first day of the month
Calendar.setMonth(month); // Set the current month to be displayed
Calendar.setYear(year); // Set the current year of the month to be displayed (used for previous/next month if not same year as current month)

var TR_start = '<TR>';
var TR_end = '</TR>';
var highlight_start = '<TD><TABLE CELLSPACING=0 id="Highlight"><TR><TD width=15px>';
var highlight_end   = '</TD></TR></TABLE>';
var TD_start = '<TD id="tdstart">';
var TD_start2 = '<TD id="tdstart2">';
var TD_end = '</TD>';

cal =  '<div id="calendar" style="position:relative; align:center;"><TABLE CELLSPACING=0 id="Regular"><TR><TD>';
cal += '<TABLE id="Maintable" CELLSPACING=0>' + TR_start;
cal += '<TD COLSPAN="' + DAYS_OF_WEEK + '" id="TitleBg"><span id='+month_of_year[month]+'><div id=txt>';
cal += month_of_year[month]  + '   ' + year + '</div></span>' + TD_end + TR_end;
cal += TR_start;

for(index=0; index < DAYS_OF_WEEK; index++){
	if(weekday == index && values==1) // make sure only to display highlighted date for this month
		cal += TD_start2 + '' + day_of_week[index].bold() + '' + TD_end;
	else
		cal += TD_start + day_of_week[index] + TD_end;
}

cal += TD_end + TR_end;
cal += TR_start;

for(index=0; index < Calendar.getDay(); index++)
	cal += TD_start + '  ' + TD_end;

for(index=0; index < DAYS_OF_MONTH; index++){
	if( Calendar.getDate() > index ){
		week_day =Calendar.getDay();
		if(week_day == 0)
			cal += TR_start;
		if(week_day != DAYS_OF_WEEK){
			var day  = Calendar.getDate();
			if( today==Calendar.getDate() && values==1) // only display highlighted date if current month
				cal += highlight_start + day + highlight_end + TD_end;
			else
				cal += TD_start + day + TD_end;
		}
		if(week_day == DAYS_OF_WEEK)
			cal += TR_end;
	}
	Calendar.setDate(Calendar.getDate()+1);
}

cal += '</TD></TR></TABLE></TABLE></div>';

document.write(cal);
}

//cally(0); // last month
cally(1); // this month
//cally(2); // next month
//-->
