codice:
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Esempio</title>
<script type="text/javascript">
function Calendar (oParent) {
this.container = document.createElement("table");
this.display = document.createElement("div");
this.current = new Date();
var
nId = Calendar.instances.length, oTH, oHRow = document.createElement("tr"),
oTHead = document.createElement("thead"), oCapt = document.createElement("caption"),
oDecrYear = document.createElement("div"), oIncrYear = document.createElement("div"),
oDecrMonth = document.createElement("div"), oIncrMonth = document.createElement("div");
this.container.className = "calendar";
this.display.className = "current-month";
oDecrYear.className = "decrease-year";
oDecrMonth.className = "decrease-month";
oIncrMonth.className = "increase-month";
oIncrYear.className = "increase-year";
oDecrYear.innerHTML = "&laquo;";
oDecrMonth.innerHTML = "&lt;";
oIncrMonth.innerHTML = "&gt;";
oIncrYear.innerHTML = "&raquo;";
oDecrYear.id = "decr-year-" + nId;
oDecrMonth.id = "decr-month-" + nId;
oIncrMonth.id = "incr-month-" + nId;
oIncrYear.id = "incr-year-" + nId;
oDecrYear.onclick = oIncrYear.onclick = oDecrMonth.onclick = oIncrMonth.onclick = Calendar.browseClick;
for (var nThId = 0; nThId < 7; nThId++) {
oTH = document.createElement("th");
oTH.innerHTML = Calendar.daysNames[nThId];
oHRow.appendChild(oTH);
}
oTHead.appendChild(oHRow);
oCapt.appendChild(oDecrYear); oCapt.appendChild(oDecrMonth); oCapt.appendChild(oIncrYear); oCapt.appendChild(oIncrMonth);
oCapt.appendChild(this.display); this.container.appendChild(oCapt); this.container.appendChild(oTHead);
this.current.setDate(1);
this.writeDays();
oParent.appendChild(this.container);
Calendar.instances.push(this);
}
Calendar.monthsNames = ["Gennaio", "Febbraio", "Marzo", "Aprile", "Maggio", "Giugno", "Luglio", "Agosto", "Settembre", "Ottobre", "Novembre", "Dicembre"];
Calendar.daysNames = ["Lun", "Mar", "Mer", "Gio", "Ven", "Sab", "Dom"];
Calendar.monthLengths = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
Calendar.zeroIsMonday = true; // il primo giorno della settimana e' lunedi' o domenica?
Calendar.instances = [];
Calendar.browseClick = function () {
var bIsMonth = /\-month\-/.test(this.id), nDelta = /^decr\-/.test(this.id) ? -1 : 1, oThisCal = Calendar.instances[this.id.replace(/^\D+/, "")];
oThisCal.current[bIsMonth ? "setMonth" : "setYear"](oThisCal.current[bIsMonth ? "getMonth" : "getFullYear"]() + nDelta);
oThisCal.writeDays();
};
Calendar.prototype.writeDays = function () {
var oTD, oTR;
if (this.oTBody) { this.container.removeChild(this.oTBody); }
this.oTBody = document.createElement("tbody");
for (
var
nDay, nIter = 0, nEndBlanks = (this.current.getDay() + Calendar.zeroIsMonday * 6) % 7,
nEnd = Calendar.monthLengths[this.current.getMonth()] + nEndBlanks, nTotal = nEnd + ((7 - nEnd % 7) % 7);
nIter < nTotal;
nIter++
) {
if (nIter % 7 === 0) {
oTR = document.createElement("tr");
this.oTBody.appendChild(oTR);
}
nDay = nIter - nEndBlanks + 1;
oTD = document.createElement("td");
oTD.innerHTML = nIter < nEndBlanks || nIter + 1 > nEnd ?
"&nbsp;"
: "<a href=\"calendario.php?data=" + this.current.getFullYear() + "-" + + (this.current.getMonth() + 1) + "-" + (nDay / 100).toFixed(2).substr(-2) + "\">" + nDay + "<\/a>";
oTR.appendChild(oTD);
}
this.display.innerHTML = Calendar.monthsNames[this.current.getMonth()] + " " + this.current.getFullYear();
this.container.appendChild(this.oTBody);
};
</script>
<style type="text/css">
table.calendar {
background-color: #ffff00;
width: 500px;
}
table.calendar td {
text-align: center;
}
table.calendar caption {
background-color: #0000ff;
}
div.current-month {
width: 150px;
height: auto;
margin: 0 auto;
background-color: #aaaaaa;
}
div.decrease-month, div.decrease-year {
float: left;
margin-right: 4px;
cursor: pointer;
background-color: #00aa00;
}
div.increase-month, div.increase-year {
float: right;
margin-left: 4px;
cursor: pointer;
background-color: #00aa00;
}
</style>
</head>
<body onload="new Calendar(document.getElementById('contenitore1'));new Calendar(document.getElementById('contenitore2'));">
Blablabla</p>
<div id="contenitore1"></div>
Blablabla</p>
<div id="contenitore2"></div>
</body>
</html>