Template:Team:KULeuven/Common/JSLibrary

/* var monthNames = new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'); var monthLengths=[31,0,31,30,31,30,31,31,30,31,30,31];
 * @author KULeuven

var dayNames = new Array('sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat');

/* Extracts the corresponding calendar date out of the page url */ function pageDate { // Retrieve page url var urlTokens = location.href.split("/"); var urlLast = urlTokens[urlTokens.length - 1];

// Retrieve page date var wikiTokens = urlLast.split("#"); var wikiFirst = wikiTokens[0];

// Retrieve seperate date components var dateTokens = wikiFirst.split("_");

var day = parseInt(dateTokens[0]); var month; for (x in monthNames) { if(dateTokens[1] == monthNames[x]) {month = x; break;} }	var year = parseInt(dateTokens[2]);

// Construct a Date object and return the result var date = new Date; date.setFullYear(year, month, day);

return date; }

function dateDaysFrom(d, ndays) { var newDate = new Date; var ntime = d.getTime + ndays*86400*1000; newDate.setTime(ntime); return newDate; }

function getWeekMonday(d) { var dayOfWeek = d.getDay;

switch(dayOfWeek) { // case 0 is Sunday case 0: return dateDaysFrom(d, -6); break; default: return dateDaysFrom(d, -dayOfWeek + 1); break; } }

function printDate(d) { document.write(d.toUTCString); document.write(' '); }

function getLink(d) { return d.getDate + '_' + monthNames[d.getMonth] + '_' + d.getFullYear; }

function printLink(d, t) { document.write(''+t+''); }

function printDayCell(d,t, tod) { document.write(''); printLink(d,t); document.write(' '); }

function makeCalendar(mon, year, data) { var out = ""; var day = new Date; var today = new Date; var maxdays = 6 * 7; // max 6 rows in a month // calculate february's days monthLengths[1] = ( ((year%4==0) && (year%100 != 0)) || (year % 400 == 0) ) ? 29 : 28;

out += " ";

return out; }

function convertMonthnameToNumber(mn) { for(var i = 0; i < monthNames.length; i++) { if(mn == monthNames[i]) return i;       }

return -1; }   function retrieveDatesHash { var data = new Array;; var re = new RegExp("Team:KULeuven/([0-9]+)_([a-zA-Z]+)_(2009)"); var links = document.getElementById('mw-pages').getElementsByTagName('a');

for (var i=0; i < links.length; i++) {	   var m = re.exec(links[i].href); if(m != null) {

var y = parseInt(m[3]); var d = parseInt(m[1]); var m = convertMonthnameToNumber(m[2]) + 1;

var s = y * 10000 + m * 100 + d;

data[s] = 1; }	}

return data; }