var kECC={calendars:{},addCalendar:function(o){this.calendars[o.id]=o;},defaults:{display:'small',previousButton:'&lt;',nextButton:'&gt',months:['January','February','March','April','May','June','July','August','September','October','November','December'],weekdays:['Sun','Mon','Tue','Wed','Thu','Fri','Sat']}};function kEventCalendar(o){this.container=(!o['container'])?document.body:(typeof o['container']=="string")?document.getElementById(o.container):o.container;this.datasrc=o['datasrc'];this.display=(o['display'])?o.display:kECC.defaults.display;this.previousButton=(o['previousButton'])?o.previousButton:kECC.defaults.previousButton;this.nextButton=(o['nextButton'])?o.nextButton:kECC.defaults.nextButton;this.months=(o['months'])?o.months:kECC.defaults.months;this.weekdays=(o['weekdays'])?o.weekdays:kECC.defaults.weekdays;this.includeHolidays=(typeof o['includeHolidays']=="string")?o.includeHolidays:"1";this.currentPage=new Date();this.visiblePopup=null;this.events={};this.isDrawn=false;this.id=Math.random()+"";this.id=this.id.substring(this.id.indexOf('.')+1,this.id.length);kECC.addCalendar(this);this.ref="kECC.calendars['"+this.id+"']";this.insert();}kEventCalendar.prototype.insert=function(){if(!this.datasrc||!window['kAjax'])return;var div=document.createElement("div");div.className="kecTopContainer"+(this.display=="large"?"large":"small");this.container.appendChild(div);div.appendChild(this.getMonthDisplay(true,this.display!="small3",0));for(var x=1;x<(this.display=="small3"?3:1);x++){div.appendChild(this.getMonthDisplay(false,x==2,x));}var clear=document.createElement("div");clear.style.clear="both";div.appendChild(clear);this.repaint();kAjax.request({url:this.datasrc,onSuccess:this.ondataload,onError:this.ondataerror,eventContext:this});};kEventCalendar.prototype.getMonthDisplay=function(showPrev,showNext,index){var html="";html+='<table cellspacing="0" cellpadding="0" class="kecMonthHeader">';html+='<tr><td class="kecPreviousNavCell">';if(showPrev){html+='<a class="kecNavButton" href="#" onclick="'+this.ref+'.previousMonth();return false;">'+this.previousButton+'</a>';}html+='</td><td class="kecTitleCell" id="'+this.id+'month'+index+'title"></td><td class="kecNextNavCell">';if(showNext){html+='<a class="kecNavButton" href="#" onclick="'+this.ref+'.nextMonth();return false;">'+this.nextButton+'</a>';}html+='</td></tr>';html+='</table>';html+='<table cellspacing="0" cellpadding="0" class="kecMonthTable" id="'+this.id+'month'+index+'table">';html+='<tr>';for(var i=0;i<this.weekdays.length;i++){html+='<td class="kecWeekdayTitle">'+this.weekdays[i]+'</td>';}html+='</tr>';for(var i=0;i<6;i++){html+='<tr>';for(var x=0;x<7;x++){html+='<td></td>';}html+='</tr>';}html+='</table>';var div=document.createElement("div");div.className="kecMonthContainer";div.innerHTML=html;return div;};kEventCalendar.prototype.nextMonth=function(){var m=this.currentPage.getMonth();var y=this.currentPage.getFullYear();this.currentPage.setFullYear((m==11)?y+1:y,(m==11)?0:m+1,1);this.repaint();};kEventCalendar.prototype.previousMonth=function(){var m=this.currentPage.getMonth();var y=this.currentPage.getFullYear();this.currentPage.setFullYear((m==0)?y-1:y,(m==0)?11:m-1,1);this.repaint();};kEventCalendar.prototype.getStatHoliday=function(date){if(this.includeHolidays!="1"){return null;}var y=date.getFullYear(),d=date.getDate(),m=date.getMonth();var returnDate=null;if(m==0&&d==1){returnDate={title:"New Year's Day"};}else if(m==1&&d==14){}else if(m==2||m==3){var g=y%19;var c=Math.floor(y/100);var h=(c-Math.floor(c/4)-Math.floor((8*c+13)/25)+19*g+15)%30;var i=h-Math.floor(h/28)*(1-Math.floor(h/28)*Math.floor(29/(h+1)*Math.floor((21-g)/11)));var j=(y+Math.floor(y/4)+i+2-c+Math.floor(c/4))%7;var p=i-j+28;easterDay=p;easterMonth=4;(p>31)?easterDay=p-31:easterMonth=3;if(m+1==easterMonth&&d==easterDay-2){returnDate={title:"Good Friday"};}else if(m+1==easterMonth&&d==easterDay){returnDate={title:"Easter Sunday"};}}else if(m==4){var testDate=new Date(y,m,25);var dayOfWeek=testDate.getDay();var victoriaDate=(dayOfWeek==0)?19:(dayOfWeek==1)?18:25-dayOfWeek+1;if(victoriaDate==d){returnDate={title:"Victoria Day"};}}else if(m==6&&d==1){returnDate={title:"Canada Day"};}else if(m==7){var testDate=new Date(y,m,1);var dow=testDate.getDay();var firstMonday=-1;if(dow==0){firstMonday=2;}else if(dow==1){firstMonday=1;}else if(dow>1){firstMonday=9-dow;}if(firstMonday==d){returnDate={title:"Civic Holiday"};}}else if(m==8){var testDate=new Date(y,m,1);var dow=testDate.getDay();var firstMonday=-1;if(dow==0){firstMonday=2;}else if(dow==1){firstMonday=1;}else if(dow>1){firstMonday=9-dow;}if(firstMonday==d){returnDate={title:"Labour Day"};}}else if(m==9){var testDate=new Date(y,m,1);var dow=testDate.getDay();var secondMonday=-1;if(dow==0){secondMonday=9;}else if(dow==1){secondMonday=8;}else if(dow>1){secondMonday=16-dow;}if(secondMonday==d){returnDate={title:"Thanksgiving"};}if(d==31){}}else if(m==10&&d==11){returnDate={title:"Remembrance Day"};}else if(m==11&&d==25){returnDate={title:"Christmas Day"};}if(returnDate){returnDate.isHoliday=true;}return returnDate;};kEventCalendar.prototype.paintMonth=function(index,month,year,today){var title=document.getElementById(this.id+'month'+index+'title');title.innerHTML=this.months[month]+" "+year;var table=document.getElementById(this.id+'month'+index+'table');var eachDay=new Date();eachDay.setFullYear(year,month,1);eachDay.setTime(eachDay.getTime()-(86400000*eachDay.getDay()));for(var i=1;i<table.rows.length;i++){var tr=table.rows[i];for(var x=0;x<tr.cells.length;x++){var td=tr.cells[x];var isEnabled=eachDay.getMonth()==month&&eachDay.getFullYear()==year;var isToday=eachDay.getMonth()==today.getMonth()&&eachDay.getFullYear()==today.getFullYear()&&eachDay.getDate()==today.getDate();var mm="0"+(eachDay.getMonth()+1);mm=mm.substr(mm.length-2,2);var dd="0"+eachDay.getDate();dd=dd.substr(dd.length-2,2);var holiday=this.getStatHoliday(eachDay);var hasEvents=this.events[eachDay.getFullYear()+"-"+mm+"-"+dd];td.className="kecDayCell"+(!isEnabled?' kecDisabledDay':'')+(isToday?' kecCurrentDate':'')+(hasEvents?' kecEventDay':'')+(holiday?' kecHoliday':'');if(this.display=="small"||this.display=="small3"){td.innerHTML=this.getSmallMonthDay(eachDay,isEnabled,isToday,i,x,holiday);}else{td.innerHTML=this.getLargeMonthDay(eachDay,isEnabled,isToday,i,x,holiday);}eachDay.setTime(eachDay.getTime()+86400000);}}};kEventCalendar.prototype.getLargeMonthDay=function(date,isEnabled,isToday,rowIndex,cellIndex,holiday){var mm="0"+(date.getMonth()+1);mm=mm.substr(mm.length-2,2);var dd="0"+date.getDate();dd=dd.substr(dd.length-2,2);var events=this.events[date.getFullYear()+"-"+mm+"-"+dd];var html="";html+='<div class="kecDay'+(!isEnabled?' kecDisabledDay':'')+(isToday?' kecCurrentDate':'')+(events?' kecEventDay':'')+(holiday?' kecHoliday':'')+'">'+date.getDate()+'</div>';if(holiday){holiday=[holiday];if(events){events=holiday.concat(events);}else{events=holiday;}}if(events){var popup="";html+='<div class="kecEventListContainer" style="overflow-y:auto;overflow-x:hidden;">';for(var i=0;i<events.length;i++){var mouseEvents=' onmouseover="'+this.ref+'.showPopup(this,'+rowIndex+','+cellIndex+','+i+');" onmouseout="'+this.ref+'.beginHidePopup(this);"';html+='<div class="kecEventListItem'+(events[i]['isHoliday']?' kecEventListItemHoliday':'')+'">';popup+='<div class="kecEventItemPopup" id="'+this.id+'-'+rowIndex+'-'+cellIndex+'-'+i+'" style="display:none;position:absolute;"'+mouseEvents+'>';popup+='<div class="kecEventTitle">'+events[i].title+'</div>';if(events[i].text){popup+='<div class="kecEventText">'+events[i].text+'</div>';}if(events[i].link){popup+='<a class="kecEventLink" href="'+events[i].link+'">Click to open event</a>';}popup+='</div>';html+='<a href="#" onclick="return false;" class="kecEventTitle"'+mouseEvents+'>'+events[i].title+'</a>';html+='</div>';}html+='</div>';html+=popup;}return html;};kEventCalendar.prototype.getSmallMonthDay=function(date,isEnabled,isToday,rowIndex,cellIndex,holiday){var html="",mouseEvents="";var mm="0"+(date.getMonth()+1);mm=mm.substr(mm.length-2,2);var dd="0"+date.getDate();dd=dd.substr(dd.length-2,2);var events=this.events[date.getFullYear()+"-"+mm+"-"+dd];var hasEvents=events;if(holiday){holiday=[holiday];if(events){events=holiday.concat(events);}else{events=holiday;}}if(events){mouseEvents=' onmouseover="'+this.ref+'.showPopup(this);" onmouseout="'+this.ref+'.beginHidePopup(this);"';html+='<div class="kecEventListPopup" style="display:none;position:absolute;"'+mouseEvents+'>';html+='<div class="kecEventListTitle">'+this.months[date.getMonth()]+' '+date.getDate()+', '+date.getFullYear()+'</div>';html+='<div class="kecEventListContainer" style="overflow-y:auto;overflow-x:hidden;">';for(var i=0;i<events.length;i++){html+='<div class="kecEventListItem">';html+='<div class="kecEventTitle">'+events[i].title+'</div>';if(events[i].text){html+='<div class="kecEventText">'+events[i].text+'</div>';}if(events[i].link){html+='<a class="kecEventLink" href="'+events[i].link+'">Click to open event</a>';}html+='</div>';}html+='</div>';html+='</div>';}html+='<div'+mouseEvents+' class="kecDay'+(!isEnabled?' kecDisabledDay':'')+(isToday?' kecCurrentDate':'')+(hasEvents?' kecEventDay':'')+(holiday?' kecHoliday':'')+'">'+date.getDate()+'</div>';return html;};kEventCalendar.prototype.beginHidePopup=function(div){this.hideTimer=setTimeout(this.ref+".hidePopup()",300);};kEventCalendar.prototype.hidePopup=function(){if(this.visiblePopup){this.visiblePopup.style.display="none";this.visiblePopup=null;}};kEventCalendar.prototype.showPopup=function(div,rowIndex,cellIndex,eventIndex){if(this.hideTimer){clearTimeout(this.hideTimer);}var popup=(typeof rowIndex=="undefined")?div.parentNode.childNodes[0]:document.getElementById(this.id+'-'+rowIndex+'-'+cellIndex+'-'+eventIndex);if(popup.style.display=="block"){return;}if(this.visiblePopup){this.visiblePopup.style.display="none";this.visiblePopup=null;}popup.style.display="block";var pos=this.getPopupPosition(div,popup);popup.style.top=pos.y+'px';popup.style.left=pos.x+'px';this.visiblePopup=popup;};kEventCalendar.prototype.getPopupPosition=function(hoverElement,popupElement){var x=0;var y=hoverElement.offsetHeight;var o=hoverElement;while(o){x+=o.offsetLeft||0;y+=o.offsetTop||0;o=o.offsetParent;}var o=hoverElement;while(o){x-=(o.scrollLeft||0);y-=(o.scrollTop||0);o=o.parentNode;if(o&&o['tagName']){if(o.tagName.toLowerCase()=="body"){o=null;}}}var flipLeft=(x+popupElement.offsetWidth>document.body.clientWidth+document.body.scrollLeft);var flipUp=(y+popupElement.offsetHeight>document.body.clientHeight+document.body.scrollTop);if(flipLeft){x=x-popupElement.offsetWidth;}if(flipUp){y=y-popupElement.offsetHeight-(!flipLeft?hoverElement.offsetHeight:0);}return{x:x,y:y};};kEventCalendar.prototype.ondataerror=function(errCode,responseStatus){var err='<span style="color:red;">Due to an error, this event calendar did not load properly ('+errCode+','+responseStatus+')</span>';this.container.innerHTML+=err;};kEventCalendar.prototype.ondataload=function(xmlNode,xmlText){if(xmlText.indexOf('<html')!=-1){this.ondataerror(50,200);return;}if(xmlText.toLowerCase().indexOf('<h2>no documents found</h2>')==-1){var events=eval("("+xmlText+")");for(var x=0;x<events.length-1;x++){var e=events[x];for(var i=0;i<e.dates.length;i++){var o={title:e.title,text:e.text,link:e.link,date:e.dates[i],allDates:e.dates};var d=e.dates[i];if(d.indexOf(" (")!=-1){d=d.substring(0,d.indexOf(" ("));}d=d.substr(6,4)+"-"+d.substr(0,2)+"-"+d.substr(3,2);if(typeof this.events[d]=="undefined"){this.events[d]=[o];}else{this.events[d].push(o);}}}}this.repaint();};kEventCalendar.prototype.repaint=function(){var dt=this.currentPage;var today=new Date();var m=dt.getMonth(),y=dt.getFullYear();this.paintMonth(0,m,y,today);for(var x=1;x<(this.display=="small3"?3:1);x++){y=(m==11?y+1:y);m=(m==11?0:m+1);this.paintMonth(x,m,y,today);}}