function buildCal(m, y, cM, cH, cDW, cD, brdr, booked, fld, alink){
var mn=['Januar','Februar','Mars','April','Mai','Juni','Juli','August','September','Oktober','November','Desember'];
var dim=[31,0,31,30,31,30,31,31,30,31,30,31];

var oD = new Date(y, m-1, 1); //DD replaced line to fix date bug when current day is 31st
oD.od=oD.getDay()+1; //DD replaced line to fix date bug when current day is 31st

var todaydate=new Date() //DD added
var scanfortoday=(y==todaydate.getFullYear() && m==todaydate.getMonth()+1)? todaydate.getDate() : 0 //DD added

dim[1]=(((oD.getFullYear()%100!=0)&&(oD.getFullYear()%4==0))||(oD.getFullYear()%400==0))?29:28;
var t='<div class="'+cM+'"><table class="'+cM+'" cols="7" cellpadding="1" border="'+brdr+'" cellspacing="0"><tr align="center">';
t+='<td colspan="8" align="center" class="'+cH+'">'+mn[m-1]+' - '+y+'</td></tr><tr align="center">';
for(s=0;s<8;s++)t+='<td class="'+cDW+'">'+" SMTOTFL".substr(s,1)+'</td>';
t+='</tr><tr align="center">';
var myDate=new Date();
for(i=1;i<=42;i++){
var x=((i-oD.od>=0)&&(i-oD.od<dim[m-1]))? i-oD.od+1 : '&nbsp;';
if(i%7==1 || i==1) {
  myDate.setFullYear(y,m-1,i);
  yearWeek=getYearWeek(myDate);
//  if (booked.inArray(yearWeek) == true) { cD = 'caldaysbooked' } else { cD = 'caldays'; }
//  t+='<td class="'+cDW+'"><a class="'+cDW+'" href=#" href="javascript:setWeek('+yearWeek+','+fld+ ')">'+yearWeek.substr(4,2)+'</a></td>';
  t+='<td class="'+cDW+'">'+yearWeek.substr(4,2)+'</td>';
}
var currentDay = y.toString() + m.toString().replace(/\b(\d)\b/g, '0$1') + x.toString().replace(/\b(\d)\b/g, '0$1');
var currentMonth = mn[m-1];
var currentDate = x.toString().replace(/\b(\d)\b/g, '0$1');

cD = 'caldays';
for (j=0; j < booked.length; j++) {
  //alert(booked[j]);
  if (booked[j]) {
    from = booked[j];
    from = from.substr(0,8);
    //alert(from);
    to = booked[j];
    to = to.substr(9,8);
    if (from <= currentDay && to >= currentDay)  { cD = 'caldaysbooked' }
  }
}

if (x==scanfortoday) //DD added
x='<span id="today">'+x+'</span>' //DD added
if (cD == 'caldaysbooked') {
  t+='<td class="'+cD+'"><a title="Aktiviteter for '+currentDate+'.'+currentMonth+'" class="thickbox" href="'+alink+'&amp;Date='+currentDay+'&amp;TB_iframe=true&amp;height=150&amp;width=200"><b>'+x+'</b></a></td>';
} else {
  t+='<td class="'+cD+'">'+x+'</td>';
}
if(((i)%7==0)&&(i<36))t+='</tr><tr align="center">';
}
return t+='</tr></table></div>';
}

function setWeek(yearWeek,fld) {
  eval(document.forms[0].fld).value = yearWeek;
}

function getYearWeek(date){
var today = date;
Year = getYear(today);
Month = today.getMonth();
Day = today.getDate();
now = Date.UTC(Year,Month,Day+1,0,0,0);
var Firstday = new Date();
Firstday.setYear(Year);
Firstday.setMonth(0);
Firstday.setDate(1);
then = Date.UTC(Year,0,1,0,0,0);
var Compensation = Firstday.getDay();
if (Compensation > 3) Compensation -= 4;
else Compensation += 3;
NumberOfWeek =  Math.round((((now-then)/86400000)+Compensation)/7);
if (NumberOfWeek < 10) {
  return Year + "0" + NumberOfWeek; }
else {
  return Year + "" + NumberOfWeek;
  }
}

function getYear(theDate){
  x = theDate.getYear();
  var y = x % 100;
  y += (y < 38) ? 2000 : 1900;
  return y;
}

Array.prototype.inArray = function (value)
// Returns true if the passed value is found in the
// array.  Returns false if it is not.
{
  var i;
  for (i=0; i < this.length; i++) {
      // Matches identical (===), not just similar (==).
      if (this[i] === value) {
          return true;
      }
  }
  return false;
};
