// JavaScript Document


function MostrarFecha()
   {
   var nombres_dias = new Array("Domingo", "Lunes", "Martes", "Miércoles", "Jueves", "Viernes", "Sábado")
   var nombres_meses = new Array("Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre")

   var fecha_actual = new Date()

   dia_mes = fecha_actual.getDate() //dia del mes
   dia_semana = fecha_actual.getDay() //dia de la semana
   mes = fecha_actual.getMonth() + 1
   anio = fecha_actual.getYear()

   if (anio < 100) //pasa el año a 4 digitos
      anio = '19' + anio
   else {
      var cadena_anio = new String(anio)
      anio = '20' + cadena_anio.substring(1,3)
   }

   //escribe en pagina
   document.write("<p>" + nombres_dias[dia_semana] + ", " + dia_mes + " de " + nombres_meses[mes - 1] + " de " + anio + "</p>")
   }


	
var dayarray=new Array("Domingo","Lunes","Martes","Miércoles","Jueves","Viernes","Sábado")
var montharray=new Array("Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre")

function getthedate()
{
var mydate=new Date()
var year=mydate.getYear()
if (year < 1000)
year+=1900
var day=mydate.getDay()
var month=mydate.getMonth()
var daym=mydate.getDate()
if (daym<10)
daym="0"+daym
var hours=mydate.getHours()
var minutes=mydate.getMinutes()
var seconds=mydate.getSeconds()
var dn="AM"
if (hours>=12)
dn="PM"
if (hours>12){
hours=hours-12
}
if (hours==0)
hours=12
if (minutes<=9)
minutes="0"+minutes
if (seconds<=9)
seconds="0"+seconds
//change font size here
var cdate="<font color='#000066' face='arial' size ='1'><b>"+dayarray[day]+" "+daym+" de "  +montharray[month]+" "+"de "+year+" "+hours+":"+minutes+":"+seconds+" "+dn

+"</b></font>"
if (document.all)
document.all.clock.innerHTML=cdate
else if (document.getElementById)
document.getElementById("clock").innerHTML=cdate
else
document.write(cdate)
}
if (!document.all&&!document.getElementById)
getthedate()
function mostrarfecha(){
if (document.all||document.getElementById)
setInterval("getthedate()",1000)
}	

			
	
function obtiene_fecha()
   {	   
   var fecha_actual = new Date()
   dia = fecha_actual.getDate()
   mes = fecha_actual.getMonth() + 1
   anio = fecha_actual.getYear()

    if (anio < 1000) //pasa el año a 4 digitos
anio+=1900
   if (mes < 10)
      mes = '0' + mes

   if (dia < 10)
      dia = '0' + dia

   return (dia + "/" + mes + "/" + anio)
   }

function calendario()
   {
var x, y, fila, valor
   var fecha_actual = new Date()
   var dia_mes = fecha_actual.getDate() //dia del mes
   var mes = fecha_actual.getMonth() + 1 //mes del año
   var anio = fecha_actual.getYear() //año
   if (anio < 1000)
     anio+=1900
   var dia_semana = fecha_actual.getDay() - 1 //dia de la semana (-1 para domingo, 0 para lunes, etc.)

//array de dias que tiene cada mes
dias_por_mes = new Array(12)
dias_por_mes[0] = 31
dias_por_mes[1] = 28
dias_por_mes[2] = 31
dias_por_mes[3] = 30
dias_por_mes[4] = 31
dias_por_mes[5] = 30
dias_por_mes[6] = 31
dias_por_mes[7] = 31
dias_por_mes[8] = 30
dias_por_mes[9] = 31
dias_por_mes[10] = 30
dias_por_mes[11] = 31

//corrige dia de la semana
if(dia_semana == -1) 
dia_semana = 6

//corrige dias de febrero si año bisiesto
if((anio % 4) == 0) 
dias_por_mes[1]++

//crea matriz de datos
matriz = new Array(6)
for (fila = 0; fila < 6; fila++) 
matriz[fila] = new Array(7)

//obtiene posición día 1
y = dia_semana + 1
for (x = dia_mes; x > 0; x--) {
y-- 
if (y < 0) 
y = 6
}

//guarda valores en variable matriz
valor = 1
for (fila = 0; fila < 6; fila++) {
for (x = 0; x < 7; x++) {
if ((fila == 0) && (x < y)) { //valores vacíos primera fila
matriz[fila][x] = ""
} else if (valor > dias_por_mes[mes - 1]) { //valores vacíos última línea
matriz[fila][x] = ""
} else if (valor == dia_mes) { //valor día actual
matriz[fila][x] = "<font color='#660000' size='5'>" + valor + "</font>"
valor++
} else {
matriz[fila][x] = valor //valores ocupados
valor++
}
}
}

//impresion del calendario
document.write("<div align='center'><center>")
document.write("")
document.write("<table border='1' width='150' height='50' cellspacing='1' cellpadding='5'>")
document.write("  <tr>")
document.write("    <td width='100%' colspan='7' align='center'><b>" + obtiene_fecha() +  "</b> </td>")
document.write("  </tr>")
document.write("  <tr>") //crea fila de nombres de días
document.write("    <td width='14%' height ='10'align='center'> <font size='1' color='#000066'>L </font></td>")
document.write("    <td width='14%' height ='10'align='center'> <font size='1' color='#000066' >M </font></td>")
document.write("    <td width='14%' height ='10'align='center'><font size='1' color='#000066' >M </font></td>")
document.write("    <td width='14%' height ='10'align='center'><font size='1' color='#000066' >J </font></td>")
document.write("    <td width='14%' height ='10'align='center'><font size='1' color='#000066'>V </font></td>")
document.write("    <td width='15%' height ='10'align='center' bgcolor='#C0C0C0'><font size='1' color='#000066' > S </font></td>")
document.write("    <td width='15%' height ='10'align='center' bgcolor='#C0C0C0'><font size='1' color='#000066' > D</font></td>")
document.write("  </tr>")

for(fila = 0; fila < 6; fila++) {
if ((matriz[fila][0] == "") && (matriz[fila][6] == "")) //no muestra ultima fila vacía
break
document.write("  <tr>") //crea fila de tabla calendario
document.write("    <td width='14%' height ='10' align='center'> <font size='1' color='#000066' >"+ matriz[fila][0] +"</font></td>")
document.write("    <td width='14%' height ='10' align='center'> <font size='1' color='#000066' >"+ matriz[fila][1] + "</font></td>")
document.write("    <td width='14%' height ='10'  align='center'> <font size='1' color='#000066' >"+ matriz[fila][2] + "</font></td>")
document.write("    <td width='14%' height ='10' align='center'> <font size='1' color='#000066' >"+ matriz[fila][3] + "</font></td>")
document.write("   <td width='14%' height ='10' align='center'> <font size='1' color='#000066' >" + matriz[fila][4] + "</font></td>")
document.write("    <td width='14%' height ='10' align='center'> <font size ='1' bgcolor='#C0C0C0'>"+ matriz[fila][5] + "</font></td>")
document.write("    <td width='14%' height ='10' align='center'> <font size ='1' bgcolor='#C0C0C0'>" + matriz[fila][6] + "</font></td>")
document.write("  </tr>")
}

document.write("</table>")
document.write("</center></div>")
}
