function buildCal(m, y, cM, cH, cDW, cD, brdr, specialDays) {
	var mn = [ 'Gener', 'Febrer', 'Març', 'Abril', 'Maig', 'Juny', 'Juliol', 'Agost', 'Septembre', 'Octubre', 'Novembre', 'Decembre' ];
	var dim = [ 31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ];
	var days = [ 'dl', 'dt', 'dm', 'dj', 'dv', 'ds', 'dm'];
	
	//var specialDays = [2,5,12,15,24,28];

	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="0" border="' + brdr + '" cellspacing="0"><tr align="center">';
	
	t += '<td class="' + cH + '"><a href="javascript:prevMonth()" class="paginatorBg" title="Mes anterior"><img src="imagenes/btnCalendarPrev.png" style="vertical-align:bottom;"/></a></td><td colspan="5" align="center" class="' + cH + '">' + mn[m - 1]
			+ ' - ' + y + '</td><td class="' + cH + '"><a href="javascript:nextMonth()" class="paginatorBg" title="Mes següent"><img src="imagenes/btnCalendarNext.png" style="vertical-align:bottom;"/></a></td></tr><tr align="center">';
	
	for (s = 0; s < 7; s++)
	{
		//t += '<td class="' + cDW + '">' + "SMTWTFS".substr(s, 1) + '</td>';

		t += '<td class="' + cDW + '">' + days[s] + '</td>';
	}
	
	t += '</tr><tr align="center">';
	
	for (i = 1; i <= 42; i++) 
	{
		var x = ((i + 1 - oD.od >= 0) && (i + 1 - oD.od < dim[m - 1])) ? i - oD.od + 2 : '&nbsp;';
		
		if (x == scanfortoday) // DD added
		{
			x = '<span id="today">' + x + '</span>' // DD added
		}
		else if (containsValue(x, m, y, specialDays))
		{
			x = '<span class="special">' + x + '</span>' // DD added
		}
		
		t += '<td class="' + cD + '">' + x + '</td>';
		
		if (((i) % 7 == 0) && (i < 36))
		{
			t += '</tr><tr align="center">';
		}
	}
	return t += '</tr></table></div>';
}

function containsValue(day, month, year, specialDays)
{
	for (var i=0; i<specialDays.length; i++)
	{
		//console.log(day + "==" + specialDays[i] + " : " + (day == specialDays[i]).toString());
		
		if (day == specialDays[i].day && month == specialDays[i].month && year == specialDays[i].year)
		{
			return true;
		}
	}
	
	return false;
}
