// Event Calendar

// copyright Stephen Chapman, 10th June 2006, 22nd January 2010



var tb = 't'; // top or bottom (t or b)

var headbg = '#cccccc';  // table heading background colour

var todaybg = '#99cccc'; // current selected date background colour

var textclr = '#000000'; // text colour

var linkclr = '#ff9999'; // link text colour

var noMessage =  'No event messages to display for today'; // message to display when no entry in array



var dA = new Array(); var x = 0;

// first 8 characters in ccyymmdd format for single date events

// first 8 characters in 0000mmdd format for every year events

//dA[x++] = "00000101 New Year";

//dA[x++] = "00000214 Valentine's day";

//dA[x++] = "00000709 Steve's Birthday";

//dA[x++] = "00000919 Site Anniversary";

//dA[x++] = "00001206 St Nicholas' Day";

// dA[x++] = "20060610 New Event Calendar Started today";

dA[x++] = "20110220 Dedication Service-Reformed Church";
dA[x++] = "20110225 Mothers Morning Tea";
dA[x++] = "20110316 Senior Camp";
dA[x++] = "20110317 Senior Camp";
dA[x++] = "20110325 Mothers Morning Tea";
dA[x++] = "20110330 Years 5-7 Show excursion";
dA[x++] = "20110331 Toowoomba Show Holiday";
dA[x++] = "20110401 Prep - Year 3 Show Excursion";
dA[x++] = "20110402 Working Bee";
dA[x++] = "20110408 Term 1 concludes";
dA[x++] = "20110408 Glenvale Cross Country";
dA[x++] = "20110422 Good Friday";
dA[x++] = "20110425 Anzac Day";
dA[x++] = "20110426 Easter Monday Holiday";
dA[x++] = "20110427 Term 2 Commences";
dA[x++] = "20110427 Anzac Day Ceremony";
dA[x++] = "20110429 Mothers Morning Tea";
dA[x++] = "20110502 Labour Day Holiday";
dA[x++] = "20110505 Mothers Day Stall";
dA[x++] = "20110508 Mothers Day";
dA[x++] = "20110510 NAPLAN";
dA[x++] = "20110511 NAPLAN";
dA[x++] = "20110512 NAPLAN";
dA[x++] = "20110513 Emu Gully Air and Land Spectacular Excursion";
dA[x++] = "20110527 Mothers Morning Tea";
dA[x++] = "20110610 Athletics Carnival - Track Events";
dA[x++] = "20110613 Queens Birthday Holiday";
dA[x++] = "20110614 TCPCDSA - AGM";
dA[x++] = "20110615 State of Origin Night";
dA[x++] = "20110624 Term 2 Concludes";
dA[x++] = "20110624 Athletics Carnival - Rotations";
dA[x++] = "20110624 Mothers Morning Tea";
dA[x++] = "20110718 Term 3 Commences";
dA[x++] = "20110729 Mothers Morning Tea";
dA[x++] = "20110730 Working Bee";
dA[x++] = "20110815 Prep - Year 3 Sister City Excursion ";
dA[x++] = "20110818 Prep & Year 1 Darling Downs Zoo Excursion";
dA[x++] = "20110822 Scholastic Book Fair";
dA[x++] = "20110823 Scholastic Book Fair";
dA[x++] = "20110826 Mothers Morning Tea";
dA[x++] = "20110901 Fathers Day Stall";
dA[x++] = "20110904 Fathers Day";
dA[x++] = "20110905 Child Protection Week Pantomime";
dA[x++] = "20110907 Year 6 & 7 Excursion to Agricultural Show";
dA[x++] = "20110910 Association Dinner & Art Auction";
dA[x++] = "20110913 Road Safety Excursion";
dA[x++] = "20110914 Road Safety Lesson";
dA[x++] = "20110915 Road Safety Excursion";
dA[x++] = "20110916 Term 3 Concludes";
dA[x++] = "20110916 Mothers Morning Tea";
dA[x++] = "20111003 Term 4 Commences";
dA[x++] = "20111004 Australian Youth Choir visit";
dA[x++] = "20111007 Cows Create Careers Awards Ceremony";
dA[x++] = "20111007 School Open Day";
dA[x++] = "20111017 Statewide Pupil Free Day";
dA[x++] = "20111028 Mothers Morning Tea";
dA[x++] = "20111028 School Photos Day";
dA[x++] = "20111029 Car Rally";
dA[x++] = "20111107 Beginning of Swimming Lessons Block";
dA[x++] = "20111111 Remembrance Day Chapel";
dA[x++] = "20111116 End of Swimming Lessons Block";
dA[x++] = "20111118 Swimming Lesson";
dA[x++] = "20111118 Mothers Morning Tea";
dA[x++] = "20111118 New Student Orientation Day";
dA[x++] = "20111122 Book Fair";
dA[x++] = "20111123 Volunteers Thank You Chapel";
dA[x++] = "20111124 Grade 7 Graduation Dinner";
dA[x++] = "20111125 Swimming Carnival";
dA[x++] = "20111130 End of Year Awards Ceremony";
dA[x++] = "20111202 Term 4 Concludes";
dA[x++] = "20120101 New Years Day";
dA[x++] = "20120102 New Years Day Holiday";
dA[x++] = "20120121 Working Bee";
dA[x++] = "20120123 First Day Term 1";
dA[x++] = "20120125 Australia Day Service";
dA[x++] = "20120126 Australia Day Holiday";
dA[x++] = "20120129 School Dedication Service";
dA[x++] = "20120207 Curriculum Information Evening";
dA[x++] = "20120323 Cross Country";
dA[x++] = "20120328 Last Day Term 1";
dA[x++] = "20120329 Toowoomba Show Holiday";
dA[x++] = "20120406 Good Friday";
dA[x++] = "20120407 Easter Saturday";
dA[x++] = "20120409 Easter Monday";
dA[x++] = "20120416 Term 2 Commences";
dA[x++] = "20120423 Senior Camp";
dA[x++] = "20120424 Senior Camp";
dA[x++] = "20120425 Anzac Day Holiday";
dA[x++] = "20120426 Anzac Day Service";
dA[x++] = "20120507 Labour Day Holiday";
dA[x++] = "20120510 Mothers Day Stall";
dA[x++] = "20120513 Mothers Day";
dA[x++] = "20120515 NAPLAN";
dA[x++] = "20120516 NAPLAN";
dA[x++] = "20120517 NAPLAN";
dA[x++] = "20120525 Athletics Carnival Track Events";
dA[x++] = "20120601 Athletics Carnival Rotations";
dA[x++] = "20120611 Queens Birthday Jubilee Holiday";
dA[x++] = "20120622 Last Day Term 2";
dA[x++] = "20120716 First Day Term 3";
dA[x++] = "20120811 Working Bee";
dA[x++] = "20120817 School Open Day";
dA[x++] = "20120830 Fathers Day Stall";
dA[x++] = "20120902 Fathers Day";
dA[x++] = "20120921 Last Day Term 3";
dA[x++] = "20121001 Queens Birthday Holiday";
dA[x++] = "20121008 First Day Term 4";
dA[x++] = "20121112 Remembrance Day Service";
dA[x++] = "20121112 Swimming Block Commences";
dA[x++] = "20121123 Prep Orientation Day";
dA[x++] = "20121123 Swimming Block Finishes";
dA[x++] = "20121128 Volunteers Chapel";
dA[x++] = "20121129 Year 7 Graduation Dinner";
dA[x++] = "20121130 Swimming Carnival";
dA[x++] = "20121205 End of Year Awards Ceremony";
dA[x++] = "20121207 Last Day Term 4";
dA[x++] = "20121225 Christmas Day";
dA[x++] = "20121226 Boxing Day";




// permission is granted to use this javascript provided that the below code is not altered

var pageLoaded = 0; window.onload = function() {pageLoaded = 1;}

function loaded(i,f) {if (document.getElementById && document.getElementById(i) != null) f(); else if (!pageLoaded) setTimeout('loaded(\''+i+'\','+f+')',100);

}

function monthlength(month,year) {var dd = new Date(year, month, 0);return dd.getDate();}



var moy = ['January','February','March','April','May','June','July','August','September','October','November','December'];

var today = new Date();

var selDate = today.getFullYear()+getmmdd(today.getMonth()+1,today.getDate());



function dispCal(yy,mm) {

	if (mm < 0 || mm > 12) { alert('month must be between 1 and 12'); return false;} 

	if (yy != 0 && (yy < 1901 || yy > 2100)) {alert('year must be after 1900 and before 2101'); return false;} 

	var dow = ['Sun','Mon','Tue','Wed','Thu','Fri','Sat']; var calendar = new Date();  var today = calendar.getDate(); calendar.setDate(1); 

	if (yy > 1900) calendar.setFullYear(yy); 

	if (mm > 0) calendar.setMonth(mm - 1); 

	var yy = year = calendar.getFullYear(); 

	var month = calendar.getMonth(); 

	calendar.setDate(today); 

	var weekday = calendar.getDay(); 

	var daysInMonth = monthlength(month+1,year); 

	var hilite_start = '<td width="30" style="background:' + todaybg + '" align="center"><b>'; 

	var td_start = '<td width="30" align="center">'; 

	var cal = '<div id="cal"><div style="border:1pt solid #cccccc;width:182px"><table border="0" cellspacing="0" cellpadding="2" align="center"><tr><td colspan="7" style="background:' + headbg + '" align="center"><b>' + moy[month]  + ' ' + year + '<\/b><\/td><\/tr><tr>'; 

	for(dex=0; dex < 7; dex++) {cal += td_start + dow[dex] + '</td>';} 

	cal += '<\/tr><tr>'; 

	var day2 = today; 

	for (dex = today; dex > 6; dex -=7) day2 = dex; 

	weekday -= day2 - 1; 

	while (weekday < 0) weekday += 7; 

	for(dex=0; dex < weekday; dex++) cal += td_start + ' <\/td>'; 

	for(dex=1; dex <= daysInMonth; dex++) {

		if(weekday == 7) {cal += '</tr><tr>'; weekday = 0;} 

		if(selDate==year+getmmdd(month+1,dex)) cal += hilite_start +'<span '+clickDate(dex,month,year) + '>'+ dex + '<\/span><\/b><\/td>'; 

			else cal += td_start + '<span '+clickDate(dex,month,year) + '>' + dex + '<\/span><\/td>'; weekday += 1;

	} 

	for(dex=weekday; dex < 7; dex++) cal += td_start + ' <\/td>'; 

	cal += '<\/tr><\/table><\/div>';

	if (document.getElementById) {

		var mmb = month;  

		mm = month + 1; 

		var yya = yyb = yy; 

		if (mmb <1) { mmb += 12; yyb--; } 

		var mma = month + 2; 

		if (mma > 12) { mma -= 12; yya++;} 

		var yb = yy -1; 

		var ya = yy +1; 

		cal += '<table border="0" cellspacing="0" cellpadding="2" width="154"><tr><td><a href="#" onclick="if (cala = dispCal('+yb+','+mm+')) {document.getElementById(\'cal\').innerHTML = cala; return false;}"><<</a></td><td><a href="#" onclick="if (cala = dispCal('+yyb+','+mmb+')) {document.getElementById(\'cal\').innerHTML = cala; return false;}"><</a></td><td align="right"><a href="#" onclick="if (cala = dispCal('+yya+','+mma+')) {document.getElementById(\'cal\').innerHTML = cala; return false;}">></a></td><td align="right"><a href="#" onclick="if (cala = dispCal('+ya+','+mm+')) {document.getElementById(\'cal\').innerHTML = cala; return false;}">>></a></td></tr></table>';

	} else {

		cal += '<div> </div>';

	} 

	cal += '</div>'; 

	return cal;

}



function start() {

	var x = '<div id="calDate" style="border:1pt solid #cccccc;width:182px"><\/div>'; 

	var y = ''; 

	if (tb == 't') y = x + dispCal(0,0); 

		else y = dispCal(0,0) + x; 

	document.getElementById('calendar').innerHTML = y; 

	ev();

}

loaded('calendar',start);



function clickDate(day, month, year) {

	var ct = nextDate(year + getmmdd(month+1,day));

	if (ct == '') ct = nextDate('0000' + getmmdd(month+1,day));

	if (ct == '') return 'style="color:'+textclr+'"'; 

		else return 'style="cursor:pointer;color:'+linkclr+'" onclick="selDate = '+year+ getmmdd(month+1,day)+';isDate(' + day + ',' + month + ',' + year + ');return false;"';

}

function isDate(dayVal,monthVal,yearVal) {

	var ct = nextDate(yearVal + getmmdd(monthVal+1,dayVal));

	if (ct == '') ct = nextDate('0000' + getmmdd(monthVal+1,dayVal));

	if (ct == '') ct = noMessage;document.getElementById('calDate').innerHTML = selDate + ':<br \/>' +ct; 

	return false;

}



function nextDate(yymmdd) {

	var x = dA.length;

	for (var i = 0; i < x; i++) {

		if (dA[i].substr(0,8) == yymmdd) return dA[i].substr(8);

	}

	return '';

}



function getmmdd(mm,dd) { return (mm > 9 ? '' + mm : '0' + mm) + (dd > 9 ? dd : '0' + dd);}



function ev() {

	var ct = nextDate(selDate);

	var ct = nextDate(selDate);

	if (ct == '') ct = nextDate('0000' + selDate.substr(4));

	if (ct == '') ct = noMessage; document.getElementById('calDate').innerHTML = selDate + ':<br \/> ' +ct;

}

