[script language = "Javascript"] //CLIENT SIDE AUXILIARY FUNCTIONS /*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--* * PURPOSE: Test if a particular year is a leap year * DOCUMENTED AT: http://www.geocities.com/matth3wbishop/eg/asp/fnDatePicker.doc * DEPENDENCIES: [none] * SOURCE CODE: http://www.geocities.com/matth3wbishop/eg/asp/fnDatePicker.txt * STATUS: working --*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*/ function fnIsLeapYear(iYear) { var regYear = /\d{4}/gi; var bIsLeapYear = new Boolean(); if ((iYear % 4) == 0) { if ((iYear % 100) != 0) {bIsLeapYear = true;} } /* if */ return bIsLeapYear; } /* fnIsLeapYear */ /*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--* * PURPOSE: to keep the HIDDEN html element which is attached to the three date boxes in synch when the values of any of those boxes change * DOCUMENTED AT: http://www.geocities.com/matth3wbishop/eg/asp/ * STATUS: working --*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*/ function fnSynchronizeHidden(sName) { var lbxDay = eval("document.forms[0]." + sName + "day"); var lbxMonth = eval("document.forms[0]." + sName + "month"); var lbxYear = eval("document.forms[0]." + sName + "year"); var iDay = lbxDay.options[lbxDay.selectedIndex].value; var iMonth = lbxMonth.options[lbxMonth.selectedIndex].value; var iYear = lbxYear.options[lbxYear.selectedIndex].value; var hidden = eval("document.forms[0]." + sName); //alert(iDay + " " + iMonth + " " + iYear + " " + fnIsLeapYear(iYear)); if ((iDay == "null") || (iMonth == "null") || (iYear == "null")) {hidden.value = "null";} else { iMonthVal = parseInt(iMonth) + 1; hidden.value = iMonthVal + "/" + iDay + "/" + iYear; //alert(hidden.value); } } /* fnSynchronizeHidden */ /*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--* * PURPOSE: To prevent the selection of illegal dates in the datepicker eg 'Feb 30 1999' * DOCUMENTED AT:(203.62.157.45) http://www.geocities.com/matth3wbishop/eg/asp/ * SOURCE: (203.62.157.45) http://www.geocities.com/matth3wbishop/eg/asp/ * STATUS: working --*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*/ function fnStopIllegalDates(sName) { var lbxDay = eval("document.forms[0]." + sName + "day"); var lbxMonth = eval("document.forms[0]." + sName + "month"); var lbxYear = eval("document.forms[0]." + sName + "year"); var iDay = lbxDay.options[lbxDay.selectedIndex].value; var iMonth = lbxMonth.options[lbxMonth.selectedIndex].value; var iYear = lbxYear.options[lbxYear.selectedIndex].value; //alert(iDay + " " + iMonth + " " + iYear + " " + fnIsLeapYear(iYear)); if ((iDay > 29) && (iMonth == 1)) { lbxDay.options[0].selected = true; } if ((iDay > 28) && (iMonth == 1) && (fnIsLeapYear(iYear) == false)) { lbxDay.options[0].selected = true; } if (((iMonth == 3) || (iMonth == 5) || (iMonth == 8) ||(iMonth == 10)) && (iDay > 30)) { lbxDay.options[0].selected = true; } } /* fnLegalDate() */ [/script] [script language = "Jscript" runat = "Server"] /*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--* * FUNCTION: fnDatePicker() * PURPOSE: to provide a simple element for selecting date values * DOCUMENTED AT: http://www.geocities.com/matth3wbishop/eg/asp/ * DEPENDENCIES: * STATUS: working --*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*/ function fnDatePicker(sName, sValue, sYearRange, bHasBlanks) { var dToday = new Date(); var sReturn = new String(); var regParseYear = /(\d{4})\D{1,2}(\d{4})/gi; var iYearA; //***Values parsed from the Year Range var iYearB; //***Defaults if (sValue == null) { dValue = dToday; } /* if */ else { dValue = new Date(sValue); } if (sName == null) { sName = "DatePicker"; } /* if */ if (bHasBlanks == null) { bHasBlanks = true; } /* if */ if (sYearRange != null) { if (regParseYear.test(sYearRange) == false) { iYearA = 1990; iYearB = 2100; } /* if */ else { iYearA = parseInt(sYearRange.replace(regParseYear, "$1")); iYearB = parseInt(sYearRange.replace(regParseYear, "$2")); } /* if, else Bad Format*/ } else { iYearA = 1990; iYearB = 2100; } /* if, else Range is Null*/ //***The Day Box sReturn += "<select size = '1'\n" + " name = '" + sName + "day'\n" + " onchange = \"fnStopIllegalDates('" + sName + "');fnSynchronizeHidden('" + sName + "');\">\n"; if (bHasBlanks) { sReturn += " <option value = 'null'></option>\n"; } /* if bHasBlanks */ for (var ii = 1; ii < 32; ii++) { sReturn += " <option value = '" + ii + "' "; if (dValue.getDate() == ii) { sReturn += " SELECTED"; } /* if */ sReturn += ">" + ii + "</option>\n"; } /* for */ sReturn += "</select>\n"; //***The Month Box sReturn += "<select size = '1' \n" + " name = '" + sName + "month'\n" + " onchange = \"fnStopIllegalDates('" + sName + "');fnSynchronizeHidden('" + sName + "');\">\n"; if (bHasBlanks) { sReturn += " <option value = 'null'></option>\n"; } /* if bHasBlanks */ var aaMonths = new Array( "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"); for (var ii = 0; ii < aaMonths.length; ii++) { sReturn += " <option value = '" + ii + "' "; if (dValue.getMonth() == ii) { sReturn += " SELECTED"; } /* if */ sReturn += ">" + aaMonths[ii] + "</option>\n"; } /* for */ sReturn += "</select>\n"; //***The Year Box sReturn += "<select size = '1' \n" + " name = '" + sName + "year' \n" + " onchange = \"fnStopIllegalDates('" + sName + "');fnSynchronizeHidden('" + sName + "');\"> \n"; if (bHasBlanks) { sReturn += " <option value = 'null'></option>\n"; } /* if bHasBlanks */ for (var ii = iYearA; ii < iYearB+1; ii++) { sReturn += " <option value = '" + ii + "' "; if (dValue.getFullYear() == ii) {sReturn += " SELECTED";} sReturn += ">" + ii + "</option>\n"; } /* for */ sReturn += "</select>\n"; sReturn += "<input type = 'hidden'\n" + " name = '" + sName + "'\n" + " value = '" + parseInt(dValue.getMonth() + 1) + "/" + dValue.getDate() + "/" + dValue.getFullYear() + "'>\n"; return sReturn; } /* fnDatePicker */ [/script]