var docHTML ;
var dateField ;
var arrayDays ;
var arrayMonth ;
var posX, posY;
var layerIDGlobal ;
// window.onload = initCalendar ;
function initCalendar() {
if (document.captureEvents) document.captureEvents(Event.MOUSEUP) ;
document.onmouseup = initCalendarCoordinates ;
}
function initCalendarCoordinates (e) {
// IE4
if (document.all) {
posX = event.clientX ;
posY = event.clientY ;
}
else {
// Netscape und W3C compatible
posX = parseInt(e.pageX+10) ;
posY = parseInt(e.pageY) ;
}
}
function showCalendar(layerID, sField) {
// Der Kalender wird aktiviert oder deaktiviert
layerIDGlobal = layerID ;
dateField = sField ;
if (document.getElementById) {
// W3C compatible
if (document.getElementById(layerID).style.visibility == "visible") document.getElementById(layerID).style.visibility = "hidden" ;
else {
document.getElementById(layerID).style.visibility = "visible" ;
document.getElementById(layerID).style.left = parseInt(posX)+10 ;
document.getElementById(layerID).style.top = parseInt(posY);
}
}
else if (document.layers) {
// Netscape compatible
if (document.layers[layerID].visibility == "visible" | document.layers[layerID].visibility == "show") document.layers[layerID].visibility = "hide" ;
else {
document.layers[layerID].visibility = "show" ;
document.layers[layerID].left = posX ;
document.layers[layerID].top = posY ;
}
}
else if (document.all) {
// IE4 und IE5 compatible
if (document.all[layerID].style.visibility == "visible") document.all[layerID].style.visibility = "hidden" ;
else {
document.all[layerID].style.visibility = "visible" ;
document.all[layerID].style.left = parseInt(posX)+10 ;
document.all[layerID].style.top = parseInt(posY) ;
}
}
}
function drawCalendar(cYear, cMonth) {
// Der Kalender wird gezeichnet
var myMonth = buildCalendar(cYear, cMonth)
var showMonth = arrayMonth[parseInt(cMonth)] ;
docHTML = "
" ;
docHTML = docHTML + "" ;
docHTML = docHTML + "| << | " ;
docHTML = docHTML + "< | " ;
docHTML = docHTML + "" + showMonth + " " + cYear + " | " ;
docHTML = docHTML + "> | " ;
docHTML = docHTML + ">> | " ;
docHTML = docHTML + "
" ;
docHTML = docHTML + "" ;
for (w=0; w<7; w++) {
docHTML = docHTML + "| " + myMonth[0][w] + " | " ;
}
docHTML = docHTML + "
" ;
for (w=1; w<7; w++) {
docHTML = docHTML + "" ;
for (d=0; d<7; d++) {
docHTML = docHTML + "| " ;
if ( !isNaN(myMonth[w][d]) ) {
docHTML = docHTML + "" + myMonth[w][d] + "" ;
}
else docHTML = docHTML + " " ;
docHTML = docHTML + " | " ;
}
docHTML = docHTML + "
" ;
}
docHTML = docHTML + "
" ;
return docHTML;
}
function buildCalendar(aYear, aMonth) {
// Diese Funktion bestimmt eine Monats-Matrix
var tMonth = new Array() ;
var tDate1 = new Date(aYear, aMonth, 1) ;
var tDate28 = new Date(aYear, aMonth, 28) ;
var tDate29 = new Date(aYear, aMonth, 29) ;
var tDate30 = new Date(aYear, aMonth, 30) ;
var tDate31 = new Date(aYear, aMonth, 31) ;
var tFirstDay = tDate1.getDay() ;
var tDays = 0 ;
if ( tDate31.getMonth() == tDate1.getMonth() ) tDays = tDate31.getDate() ;
else if ( tDate30.getMonth() == tDate1.getMonth() ) tDays = tDate30.getDate() ;
else if ( tDate29.getMonth() == tDate1.getMonth() ) tDays = tDate29.getDate() ;
else if ( tDate28.getMonth() == tDate1.getMonth() ) tDays = tDate28.getDate() ;
var tVar = 1 ;
tMonth[0] = arrayDays ;
tMonth[1] = new Array(7) ;
tMonth[2] = new Array(7) ;
tMonth[3] = new Array(7) ;
tMonth[4] = new Array(7) ;
tMonth[5] = new Array(7) ;
tMonth[6] = new Array(7) ;
if (tFirstDay == 0) {
tMonth[1][6] = tVar ;
tVar++ ;
}
else {
for (d=tFirstDay-1; d<7; d++) {
tMonth[1][d] = tVar ;
tVar++ ;
}
}
for (w=2; w<7; w++) {
for (d=0; d<7; d++) {
if (tVar <= tDays) {
tMonth[w][d] = tVar ;
tVar++ ;
}
}
}
return tMonth ;
}
function clickCalendar(sDay, sMonth, sYear) {
// Ein bestimmtes Datum wird ausgewählt
if (sDay < 10) sDay = "0" + sDay ;
if (sMonth < 10) sMonth = "0" + sMonth ;
document.forms[0].elements[dateField].value = sDay + "." + sMonth + "." + sYear ;
showCalendar(layerIDGlobal, "") ;
}
function changeCalendar(nYear, nMonth) {
// Monat oder Jahr des Kalenders werden geändert
if (document.getElementById) {
// W3C compatible
drawCalendar(nYear, nMonth) ;
document.getElementById(layerIDGlobal).innerHTML = docHTML ;
}
else if (document.layers) {
// Netscape compatible
document.layers["DatePicker"].document.open() ;
drawCalendar(nYear, nMonth) ;
document.write("")
document.write(docHTML) ;
document.write("
")
document.layers["DatePicker"].document.close() ;
}
else if (document.all) {
// IE4 und IE5 compatible
drawCalendar(nYear, nMonth) ;
document.all["DatePicker"].innerHTML = docHTML ;
}
}