var active = new diasmes()
var dim= active.length;

setCal()


function getTime() {
var now = new Date()
var hour = now.getHours()
var minute = now.getMinutes()
now = null
var ampm = "" 

if (hour >= 12) {
hour -= 12
ampm = "PM"
} else
ampm = "AM"
hour = (hour == 0) ? 12 : hour

if (minute < 10)
minute = "0" + minute // do not parse this number!

return hour + ":" + minute + " " + ampm
}

function leapYear(year) {
if (year % 4 == 0) // basic rule
return true // is leap year
return false // is not leap year
}

function getDays(month, year) {
var ar = new Array(12)
ar[0] = 31 // Enero
ar[1] = (leapYear(year)) ? 29 : 28 // Febrero
ar[2] = 31 // Marzo
ar[3] = 30 // Abril
ar[4] = 31 // Mayo
ar[5] = 30 // Junio
ar[6] = 31 // Julio
ar[7] = 31 // Agosto
ar[8] = 30 // Septiembre
ar[9] = 31 // Octubre
ar[10] = 30 // Noviembre
ar[11] = 31 // Diciembre

return ar[month]
}

function getMonthName(month) {
var ar = new Array(12)
ar[0] = "Enero"
ar[1] = "Febrero"
ar[2] = "Marzo"
ar[3] = "Abril"
ar[4] = "Mayo"
ar[5] = "Junio"
ar[6] = "Julio"
ar[7] = "Agosto"
ar[8] = "Septiembre"
ar[9] = "Octubre"
ar[10] = "Noviembre"
ar[11] = "Diciembre"

return ar[month]
}

function setCal() {
var now = new Date()
var year = now.getYear()
if (year < 1000)
year+=1900
var month = now.getMonth()
var monthName = getMonthName(month)
var date = now.getDate()
now = null

var firstDayInstance = new Date(year, month, 0) //aquí he modificado, el último número era un 1
var firstDay = firstDayInstance.getDay()
firstDayInstance = null

var days = getDays(month, year)

drawCal(firstDay, days, date, monthName, year)
}

function drawCal(firstDay, lastDate, date, monthName, year) {
var headerHeight = 30 // height of the table's header cell
var border = 0 // 3D height of table's border
var cellspacing = 2 // width of table's border
var headerColor = "#cc0000" // color of table's header
var headerSize = "3" // size of tables header font
var colWidth = 19 // width of columns in table
var dayCellHeight = 20 // height of cells containing days of the week
var dayColor = "darkblue" // color of font representing week days
var cellHeight = 20 // height of cells representing dates in the calendar
var todayColor = "darkblue" // color specifying today's date in the calendar
var timeColor = "purple" // color of font representing current time
var activeday = "#cc0000" // color of font representing active day

var text = "" // initialize accumulative variable to empty string
text += '<CENTER>'
text += '<TABLE  bgcolor=#FFFFFF BORDER=' + border + ' CELLSPACING=' + cellspacing + '>' // table settings
text += '<TH COLSPAN=7 HEIGHT=' + headerHeight + '>' // create table header cell
text += '<FONT COLOR="' + headerColor + '" SIZE=' + headerSize + '>' // set font for table header
text += monthName + ' ' + year 
text += '</FONT>' // close table header's font settings
text += '</TH>' // close header cell

var openCol = '<TD WIDTH=' + colWidth + ' HEIGHT=' + dayCellHeight + '>'
openCol += '<strong><FONT COLOR="' + dayColor + '"><span style=font-family:verdana;font-size:8pt >'
var closeCol = '</FONT></span></strong></TD>'

var weekDay = new Array(7)

weekDay[0] = "Lu"
weekDay[1] = "Ma"
weekDay[2] = "Mi"
weekDay[3] = "Ju"
weekDay[4] = "Vi"
weekDay[5] = "Sa"
weekDay[6] = "Do"



text += '<TR ALIGN="center" VALIGN="center">'
for (var dayNum = 0; dayNum < 7; ++dayNum) {
	text += openCol + weekDay[dayNum] + closeCol 
}
text += '</TR>'

var digit = 1
var curCell = 0 //aqui he modificado, en realidad ponía 1

for (var row = 1; row <= Math.ceil((lastDate + firstDay - 1) / 7); ++row) {
	text += '<TR ALIGN="right" VALIGN="top">'
	for (var col = 1; col <= 7; ++col) {
		if (digit > lastDate)
		break
	if (curCell < firstDay) {
		text += '<TD></TD>';
		curCell++
	} 

	else {

		flag1 = 0
		flag2 = 0

		if (digit == date) {
			for(var i=0;i<=dim;++i) {
				if (digit == active[i]) {
				text += '<TD HEIGHT=' + cellHeight + '>'
				text += '<b><a href=http://www.tecnun.es/servicios/rree/top/actual.htm style=font-family:verdana;font-size:8pt;color:#cc0000;text-decoration:underline >'
				text += digit
				text += '</a></b>'
				text += '</TD>'
				flag1 = 1
				flag2 = 1
				}
			}

			if (flag2 != 1){
			
				text += '<TD HEIGHT=' + cellHeight + '>'
				text += '<strong><FONT COLOR="' + todayColor + '"><span style=font-family:verdana;font-size:8pt >'
				text += digit
				text += '</FONT></strong></span>'
				text += '</TD>'
				flag1 = 1
				}
			
		}

		else {
			for(var i=0;i<=dim;++i) {
				if (digit == active[i]) {
				text += '<TD HEIGHT=' + cellHeight + '>'
				text += '<b><a href=http://www.tecnun.es/servicios/rree/top/actual.htm style=font-family:verdana;font-size:8pt;color:#cc0000;text-decoration:underline >'
				text += digit
				text += '</a></b>'
				text += '</TD>'
				flag1 = 1
				}
			}
			
		}
		if (flag1 != 1)			
			text += '<TD HEIGHT=' + cellHeight + '><span style=font-family:verdana;font-size:8pt>' + digit + '</span></TD>'
		digit++
	}
}
text += '</TR>'
}

text += '</TABLE>'
text += '</CENTER>'

document.write(text)

}


