//Llamar donde se desee a setCal() para mostrar el calendario en esa posición

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 // January
ar[1] = (leapYear(year)) ? 29 : 28 // February
ar[2] = 31 // March
ar[3] = 30 // April
ar[4] = 31 // May
ar[5] = 30 // June
ar[6] = 31 // July
ar[7] = 31 // August
ar[8] = 30 // September
ar[9] = 31 // October
ar[10] = 30 // November
ar[11] = 31 // December

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(PaginaDestino,Anio,Mes,Dia,DiasActivos) {
//Los meses comienzan en 0
Mes=Mes-1;
//------------------------
//Miro si el día del mes no se sale del rango
var days = getDays(Mes, Dia);
if (Dia<1)
  Dia=1;
if (Dia>days)
  Dia=days;
//-------------------------------------------
var now = new Date(Anio, Mes, Dia);//new Date()
var year = now.getYear()
if (year < 1000)
year+=1900
var month = now.getMonth()
var day = now.getDate()
now = null

var firstDayInstance = new Date(year, month, 1)
var firstDay = firstDayInstance.getDay()
//Para que pueda ser domingo día 1
if (firstDay == 0) firstDay = 7;
//--------------------------------
firstDayInstance = null

drawCal(firstDay, days, day, month, year, PaginaDestino, DiasActivos)
}

function drawCal(firstDay, lastDate, day, month, year, PaginaDestino, DiasActivos) {
var headerHeight = 52 // height of the table's header cell
var border = 0 // 3D height of table's border
var cellspacing = 0 // width of table's border
var colWidth = 20 // width of columns in table
var dayCellHeight = 22 // height of cells containing days of the week
var cellHeight = 20 // height of cells representing dates in the calendar

var FondoTablaColor = "#9C3932"
var TituloCellColor = "#A5726E" // size of tables header font
var DiaSemanaCellColor = "#D7B1AD" // size of tables header font
var HoyCellColor = "black" // color de la celda del día seleccionado
var RestoDiasCellColor = "#9C3932" // color de la celda de los días no seleccionados
var DiaActivoCellColor = "#BA7570" //NUEVO, PARA MARCAR LOS DÍAS "ESPECIALES"
//FUENTES, se meterá en un style
var StyleTitulo='font-family:Verdana, Arial, Helvetica, sans-serif;font-size:7pt;font-style: normal;font-weight: normal;text-decoration: none;color: #FFFFFF;'
var StyleDiaSemana='font-family:Verdana, Arial, Helvetica, sans-serif;font-size:7pt;font-style: normal;font-weight: normal;color: #000000;text-decoration: none;'
var StyleDias='font-family:Verdana, Arial, Helvetica, sans-serif;font-size:7pt;font-style: normal;font-weight: normal;vertical-align:middle;text-align:center;text-decoration: none;color: white;'
var StyleHoy='font-family:Verdana, Arial, Helvetica, sans-serif;font-size:7pt;font-style: normal;font-weight: normal;vertical-align:middle;text-align:center;text-decoration: none;color: white;'


var text = "" // initialize accumulative variable to empty string
//text += '<CENTER>'
text += '<TABLE style="background-color:'+FondoTablaColor+';" BORDER=' + border + ' CELLSPACING=' + cellspacing + '>' // table settings
text += '<TR>'
text += '<TD width="15" bgcolor="#A5726E">&nbsp;</TD>'
text += '<TD align="left" COLSPAN=7 style="background-color:'+TituloCellColor+';'+StyleTitulo+'" HEIGHT="' + headerHeight + '">' // create table header cell
text += 'Año: '+ year
//Anterior MES
text += '<TABLE width="140" height="16" border="0" cellspacing="0" cellpadding="0">'
text += '<TR><TD align="left" style="background-color:'+TituloCellColor+';'+StyleTitulo+'" valign="bottom">'

var AnteriorMes=month;
var AnteriorAnio=year;
var SiguienteMes=month;
var SiguienteAnio=year;

if (AnteriorMes<=0)
  {
  AnteriorAnio--;
  AnteriorMes=12;
  }
if (SiguienteMes>=11)
  {
  SiguienteAnio++;
  SiguienteMes=1;
  }
else SiguienteMes=SiguienteMes+2;
  
text += '<a href="AgendaS.php?Anio='+AnteriorAnio+'&Mes='+AnteriorMes+'&Dia='+day+'">'
text += '<img src="Archivos/Fijos/Cal_Anterior.gif" width="18" height="7" border="0"></a>'
text += getMonthName(month)
text += '<a href="AgendaS.php?Anio='+SiguienteAnio+'&Mes='+SiguienteMes+'&Dia='+day+'">'
text += '<img src="Archivos/Fijos/Cal_Siguiente.gif" width="18" height="7" border="0"></a>'

text += '</TD>'
text += '<TD align="right" valign="bottom">'
var hoy = new Date();//new Date()
text += '<a href="'+ PaginaDestino+'?Anio='+hoy.getYear()+'&Mes='+(hoy.getMonth()+1)+'&Dia='+hoy.getDate()+'" style="'+StyleTitulo+'">'
text += 'Hoy'
text += '</a>'
text += '</TD></TR>'
text += '</TABLE>'


text += '</TD>' // close header cell
text += '<TD width="14" bgcolor="#A5726E">&nbsp;</TD>'
text += '</TR>'

var openCol = '<TD WIDTH="' + colWidth + '" HEIGHT="' + dayCellHeight + '" style="background-color:'+DiaSemanaCellColor+';'+StyleDiaSemana+'">'
var closeCol = '</TD>'

var weekDay = new Array(7)

weekDay[0] = "L"
weekDay[1] = "M"
weekDay[2] = "X"
weekDay[3] = "J"
weekDay[4] = "V"
weekDay[5] = "S"
weekDay[6] = "D"

text += '<TR ALIGN="center" VALIGN="center">'
text += '<TD bgcolor="#D7B1AD">&nbsp;</TD>'
for (var dayNum = 0; dayNum < 7; ++dayNum) {
text += openCol + weekDay[dayNum] + closeCol 
}
text += '<TD bgcolor="#D7B1AD">&nbsp;</TD>'
text += '</TR>'

text += '<TR><TD COLSPAN=9><img src="Archivos/Fijos/Burdeos_08.gif" width="1" height="6"></TD></TR>'

var digit = 1
var curCell = 1

for (var row = 1; row <= Math.ceil((lastDate + firstDay - 1) / 7); ++row) {
text += '<TR ALIGN="right" VALIGN="top"><TD bgcolor="#9C3932">&nbsp;</TD>'
for (var col = 1; col <= 7; ++col) {
if (digit > lastDate)
break
if (curCell < firstDay) {
text += '<TD></TD>';
curCell++
} else {
if (digit == hoy.getDate() && month == hoy.getMonth() && year == hoy.getYear()) { // current cell represent today's date
text += '<TD HEIGHT=' + cellHeight + ' style="background-color:'+HoyCellColor+';'+StyleHoy+'">'
text += '<a href="'+ PaginaDestino+'?Anio='+year+'&Mes='+(month+1)+'&Dia='+digit+'" style="'+StyleDias+'">'
text += digit
text += '</a>'
text += '</TD>'
} 
else
{
//Nuevo
if (DiasActivos.charAt(digit-1)=='0')//Miro si es un día activo o no	
  text += '<TD HEIGHT=' + cellHeight + ' style="background-color:'+RestoDiasCellColor+';'+StyleDias+'" align="center">'
else text += '<TD HEIGHT=' + cellHeight + ' style="background-color:'+DiaActivoCellColor+';'+StyleDias+'" align="center">'  
text += '<a href="'+ PaginaDestino+'?Anio='+year+'&Mes='+(month+1)+'&Dia='+digit+'" style="'+StyleDias+'">'
text += digit 
text += '</a>'
text += '</TD>'

//text += '<TD HEIGHT=' + cellHeight + ' style="background-color:'+RestoDiasCellColor+';'+StyleDias+'" align="center">'
//text += '<a href="'+ PaginaDestino+'?Anio='+year+'&Mes='+(month+1)+'&Dia='+digit+'" style="'+StyleDias+'">'
//text += digit 
//text += '</a>'
//text += '</TD>'
}
digit++
}
}
text += '<TD bgcolor="#9C3932">&nbsp;</TD></TR>'
}
text += '<TR><TD COLSPAN=9><img src="Archivos/Fijos/Burdeos_08.gif" width="1" height="10"></TD></TR>'
text += '</TABLE>'
//text += '</CENTER>'

document.write(text) 
}
