// Implements a date picker from any HTML Input Field. // Shall be invoked: datepick("") // where is the HTML-Name attribute of the input field. // global variables var Month; var Day; var Year; var formerMonth; var formerYear; var formerDay; var delim = new Array(":","/","\\","-"," ","."); var monthNames = new makeArray0('Januar','Februar','März','April','Mai','Juni','Juli','August','September','Oktober','November','Dezember'); var daysInMonth = new makeArray0(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); var dayNames = new makeArray0('Mo','Di','Mi','Do','Fr','Sa','So'); var calWin; var openerWin; var callerField; function assignDateComponents(inDateString) { // break string representing a date to its day, month and year components. // If unsuccessful, will return false, else true. // trim date string dtString = inDateString + "" while ((dtString.charAt(0) == " ") && (dtString.length != 0)) dtString = dtString.substring(1,dtString.length - 1) while ((dtString.charAt(dtString.length - 1) == " ") && (dtString.length != 0)) dtString = dtString.substring(0,dtString.length - 1) // get date components i=0; startPos=0; pos=0; // day component do { pos = dtString.indexOf(delim[i], startPos); i++ } while ((pos == -1) && (i < delim.length)); if (pos == -1)return false; day = parseInt(dtString.substring(startPos,pos),10); startPos = pos + 1; // month component i = 0; do { pos = dtString.indexOf(delim[i], startPos); i++ } while ((pos == -1) && (i < delim.length)); if (pos == -1) return false; month = parseInt(dtString.substring(startPos,pos),10)-1; startPos = pos + 1; if ((month < 1) || (month > 12)) return false; if ((day < 1) || (day > daysInMonth[month])) return false; // year component year = parseInt(dtString.substring(startPos,dtString.length),10); // is this a leap year if ((month == 2) && (day == 29)) if ((((year % 4) == 0) && ((year % 100) != 0)) == false){ return false; } // parsing was obviously successful Year = year Month = month Day = day // save date with which datepicker has been invoked formerYear = Year formerMonth = Month formerDay = day return true; } function returnDate() { // return the date as a result value in certain date format return Day+"."+(parseInt(Month)+1)+"."+Year } function selectDay(day) { Day = day; code = "openerWin." + callerField + ".value = '" + returnDate()+"'" eval(code); calWin.close(); } function changeMonth() { ind = 0 mobj = calWin.document.forms[0].Month for (ind = 0; ind
'; output += '' + monthNames[Month] + ' ' + Year + '<\/b><\/FONT><\/NOBR><\/TD>'; output += ''; var today = new Date(); var ystart = Year; if (ystart < 100) { ystart += 1900; }; ystart = ystart - 2; var yend = ystart + 4; for (year=ystart; year<=yend; year++) { if (year == Year) output += '
'; firstDay = new Date(Year,Month,1); startDay = firstDay.getDay() -1 ; if (startDay < 0) startDay = 6; if (((Year % 4 == 0) && (Year % 100 != 0)) || (Year % 400 == 0)) daysInMonth[1] = 29; else daysInMonth[1] = 28; output += ''; for (i=0; i<6; i++) output += ''; var column = 0; var lastMonth = Month - 1; if (lastMonth == -1) lastMonth = 11; for (i=0; i' + (daysInMonth[lastMonth]-startDay+i+1) + '<\/FONT><\/TD>'; for (i=1; i<=daysInMonth[Month]; i++, column++) { if (column == 6) if ((i == today.getDate()) && (Month == today.getMonth()) && (Year == today.getYear())) output += ''; column = -1; } } if (column > 0) { for (i=1; column<6; i++, column++) output += '
' + dayNames[i] +'<\/B><\/FONT><\/TD>'; output += '' + dayNames[i] +'<\/B><\/FONT><\/TD>'; output += '<\/TR>
' + '' + i + '<\/FONT><\/A><\/B>' +'<\/TD>'; else if ((i == formerDay) && (Month == formerMonth) && (Year == formerYear)) output += '' + '' + i + '<\/FONT><\/A><\/B>' +'<\/TD>'; else output += '' + '' + i + '<\/FONT><\/A>' +'<\/TD>'; else { if ((i == today.getDate()) && (Month == today.getMonth()) && (Year == today.getYear())) output += '' + '' + i + '<\/FONT><\/A><\/B>' +'<\/TD>'; else if ((i == formerDay) && (Month == formerMonth) && (Year == formerYear)) output += '' + '' + i + '<\/FONT><\/A><\/B>' +'<\/TD>'; else output += ''+'' +i+ '<\/FONT><\/A>' +'<\/TD>'; } if (column == 6) { output += '<\/TR>
' + i + '<\/FONT><\/TD>'; output += '' + i + '<\/FONT><\/TD>'; } output += '<\/TR><\/SPAN><\/TABLE><\/TD><\/TR><\/TABLE><\/FORM><\/BODY><\/HTML>'; // return output; calWin.document.open(); calWin.document.write(output); calWin.document.close(); } function makeArray0() { for (i = 0; i