Ver Mensaje Individual
  #2 (permalink)  
Antiguo 16/09/2008, 03:48
mnv_19
 
Fecha de Ingreso: septiembre-2007
Mensajes: 101
Antigüedad: 16 años, 8 meses
Puntos: 0
Respuesta: Calendario PHP fechas no hace bien

Este es el archivo calendario.js 1 PARTE
function bisiesto(a) {
function centuriaNoBisiesta(x) {
return (x % 100 == 0) && (x % 400 > 0)
}
return (a % 4 == 0) && !centuriaNoBisiesta(a);
}

function dias(mes, aa) {
var n_dias = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
incremento = (mes == 1 && bisiesto(aa)) ? 1 : 0;
return n_dias[mes] + incremento;
}

var _dia = ["D", "L", "M", "X", "J", "V", "S", "D"];

var mes = [
"enero",
"febrero",
"marzo",
"abril",
"mayo",
"junio",
"julio",
"agosto",
"septiembre",
"octubre",
"noviembre",
"diciembre"
];

function seleccionaFecha(dd, mm, aa) {
alert("año: " + aa + "\nmes: " + mm + "\ndia: " + dd);
return false;
}

function seleccionaFecha2(e) {
if (document.all) {
dia = event.srcElement.value;
f = event.srcElement.form;
}
else {
dia = e.target.value;
f = e.target.form;
}

// alert(f.innerHTML);

// with (f) seleccionaFecha(dia, mes.value, aaaa.value);
with (f) window[resultado.value](dia, mes.value, aaaa.value);

//alert(f.resultado.getAttribute("value"));

// window[f.resultado.value](dia, f.mes.value, f.aaaa.value)
// seleccionaFecha(dia, f.mes.value, f.aaaa.value);
}

function mostrarDias(aa, mm, f) {
var nFecha = new Date();
aaaaHoy = nFecha.getFullYear();
mesHoy = nFecha.getMonth();
diaHoy = nFecha.getDate();
nFecha.setFullYear(aa);
nFecha.setMonth(--mm);
nFecha.setDate(1);

var empieza = nFecha.getDay();
empieza += (empieza == 0) ? 7 : 0;
var totaldias = dias(mm, aa);
var termina = empieza + totaldias;

diaSemana = nFecha.getDay();
//alert("año: " + aa + "\nmes: " + mm + "\ncomienza: " + _dia[diaSemana] + "\ndias:" + totaldias);
// var fechas = document.getElementById("fechasCalendario");
// var fechas = f.getElementsByTagName("tBody")[0];

fechas = document.getElementById(f).getElementsByTagName("t Body")[0];
with(fechas) {
while(fechas.hasChildNodes()) fechas.removeChild(fechas.firstChild);
style.border = "2px solid gray";
// añadimos la primera fila
fila = document.createElement("tr");
fechas.appendChild(fila);

eldia = 1;
for (var actual = 1; actual < termina; actual ++) {

if ((actual % 7) == 1) {
fila = document.createElement("tr");
fechas.appendChild(fila);
}

if (actual < empieza) fila.appendChild(document.createElement("td"));

else { esHoy = ((eldia == diaHoy) && (mm == mesHoy) && (aa == aaaaHoy));
//if (esHoy) alert("hoy");
var celda = document.createElement("td");
fila.appendChild(celda);
celda.style.textAlign = "center";

var boton = document.createElement("button");
boton.setAttribute("type", "button");
celda.appendChild(boton);
with(boton) {
appendChild(document.createTextNode(eldia));
//type = "button";
value = eldia++;
if (document.all)
attachEvent("onclick", seleccionaFecha2);
else
addEventListener("click", seleccionaFecha2, false);
className = (esHoy) ? "hoy" : (actual % 7 == 0) ? "domingo" : "normal";
}
}
}
}
}

function mesAnterior(e) {


if (document.all) {
f = event.srcElement.form;
}
else {
f = e.target.form;
}
// alert(f.name);
antMes(f.aaaa.value, f.mes.value, f);
}




function mesSiguiente(e) {


if (document.all) {
f = event.srcElement.form;
}
else {
f = e.target.form;
}
// alert(f.name);
sigMes(f.aaaa.value, f.mes.value, f);
}