/* FILE ARCHIVED ON 8:05:32 May 10, 2009 AND RETRIEVED FROM THE AN OPENWAYBACK INSTANCE ON 8:44:40 Sep 14, 2024. JAVASCRIPT APPENDED BY OPENWAYBACK, COPYRIGHT INTERNET ARCHIVE. ALL OTHER CONTENT MAY ALSO BE PROTECTED BY COPYRIGHT (17 U.S.C. SECTION 108(a)(3)). */ /* Copyright© 2001 by OCLC Online Computer Library Center, Inc. OCLC proprietary information: the enclosed materials contain proprietary information of OCLC Online Computer Library Center, Inc. and shall not be disclosed in whole or in any part to any third party or used by any person for any purpose, without written consent of OCLC, Inc. Duplication of any portion of these materials shall include this legend. File: calendar.js Description: Calendar Object Scripts. Language(s): JavaScript 1.3; HTML 4.0 Revisions: See Source Code Library. */ // Define Global Calendar Object. // ------------------------------ var calendar = new Calendar(); /** * Calendar Object Constructor. */ function Calendar() { var now = new Date(); // Define Prototype Methods. Calendar.prototype.setDate = setCalendarDate; Calendar.prototype.setClosed = setCalendarClosed; Calendar.prototype.show = showCalendar; Calendar.prototype.write = writeCalendar; Calendar.prototype.isClosedDate = isCalendarClosedDate; Calendar.prototype.changeMonth = changeCalendarMonth; Calendar.prototype.changeYear = changeCalendarYear; Calendar.prototype.pick = pickCalendarDate; // Define Date Prototype Methods. Date.prototype.isLeapYear = isLeapYear; Date.prototype.getFirstWeekdayOfMonth = getFirstWeekdayOfMonth; Date.prototype.getLastDayOfMonth = getLastDayOfMonth; Date.prototype.format = formatDate; // Define Properties. this.closedDates = new Array(); this.closedDays = [ false, false, false, false, false, false, false ]; this.date = new Date( (now.getMonth()+1) + "/" + now.getDate() + "/" + now.getFullYear() ); this.days = [ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ]; this.field = null; this.format = "yyyymmdd"; this.message = ""; this.messageDelimiter = "
   - "; this.months = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ]; this.offsets = new Array( 11 ); // 5 past days, present day, & 5 future days. for( var i = 0, offset = 0 - Math.floor(this.offsets.length/2); i < this.offsets.length; i++, offset++ ) { this.offsets[i] = offset; } this.showOffset = false; this.openMax = null; this.openMin = null; this.today = new Date( (now.getMonth()+1) + "/" + now.getDate() + "/" + now.getFullYear() ); this.title = "Calendar"; this.window = null; var numberOfYears = 11; // present year & 10 future years. this.years = new Array( numberOfYears ); var firstYear = this.date.getFullYear(); for( var j = 0; j < numberOfYears; j++ ) { this.years[j] = firstYear + j; } } /** * Set Calendar Date * * @param date Date object or Date string. */ function setCalendarDate( date ) { // If Date String, Parse using Format. if( !( date instanceof Date ) ) { var dateSegments = parseDate( date, calendar.format ); date = new Date( dateSegments[0], dateSegments[1] - 1, dateSegments[2] ); } // Set Date from Date Object or Date String. calendar.date = new Date( date ); calendar.today = new Date( date ); // Set Date Year Range. for( var i = 0, year = calendar.date.getFullYear() - Math.floor(calendar.years.length/2); i < calendar.years.length; i++, year++ ) { this.years[i] = year; } } /** * Set Calendar Closed Dates * * @param closed Array of Day strings, Date strings or Date objects that represent Closed Dates. */ function setCalendarClosed( closed ) { var weekday; var at; var date; var note; // Clear Closed Days and Closed Date Table. calendar.closedDays = [ false, false, false, false, false, false, false ]; calendar.closedDates = new Array(); calendar.openMax = null; calendar.openMin = null; // If Closed Array Contains Entries. if( !isNull(closed) && (closed.length > 0 )) { for( var i = 0; i < closed.length; i++ ) { closed[i] = closed[i].replace( /^\s+/, "" ).replace( /\s+$/, "" ); // Trim. weekday = closed[i].substr( 0, 3 ).toLowerCase(); if( weekday == "sun" ) { calendar.closedDays[0] = true; } else if( weekday == "mon" ) { calendar.closedDays[1] = true; } else if( weekday == "tue" ) { calendar.closedDays[2] = true; } else if( weekday == "wed" ) { calendar.closedDays[3] = true; } else if( weekday == "thu" ) { calendar.closedDays[4] = true; } else if( weekday == "fri" ) { calendar.closedDays[5] = true; } else if( weekday == "sat" ) { calendar.closedDays[6] = true; } else if( closed[i].substr( 0, 2 ) == ">=" ) { date = new Date( closed[i].substr( 2 ) ); calendar.openMin = date.valueOf(); } else if( closed[i].substr( 0, 2 ) == "<=" ) { date = new Date( closed[i].substr( 2 ) ); calendar.openMax = date.valueOf(); } else { // Parse Date & Note using a space as delimiter. if( ( at = closed[i].indexOf( " " ) ) < 0 ) { at = closed[i].length; } date = new Date( closed[i].substring( 0, at ) ); note = closed[i].substring( at+1 ).replace( /^\s+/, "" ).replace( /\s+$/, "" ); calendar.closedDates[date] = note; } } calendar.closedDates.sort(); } } /** * Show Calendar. * * @param field Input Field object * (if not null, the Calendar will return the selected date to the field). * @param date Date string (if null, defaults to today). * @param format Date Format string (if null, defaults to yyyymmdd). * @param closed Array of Day strings, Date strings or Date objects that represent Closed Dates. */ function showCalendar( field, date, format, closed ) { // Set Properties from Parameters. if( !isNull(field) ) { calendar.field = field; } if( !isNull(closed) ) { calendar.setClosed( closed ); } if( !isNull(date) && date.length > 0 ) { calendar.setDate( date ); } else { calendar.setDate( new Date() ); } if( !isNull(format) && format.length > 0 ) { calendar.format = format.toLowerCase(); } // Show Calendar. var width = 323; var height = 195; var windowOptions = "status=no" + ",resizable=yes" + ",width=" + width + ",height=" + height; if( window.event ) { // IE Coordinates. windowOptions += ",left=" + window.event.screenX + ",top=" + window.event.screenY; } else { // NN Coordinates. windowOptions += ",screenX=" + window.screenX + ",screenY=" + window.screenY; } calendar.window = open( "", calendar.title, windowOptions ); calendar.write(); calendar.window.focus(); } /** * Close the calendar window */ function closeCalendar() { if (!isNull(calendar) && !isNull(calendar.window)) { try { calendar.window.close(); } catch (e) { //ignore any exceptions, esp. in NN6.x } } } /** * Write Calendar to Window. */ function writeCalendar() { var i; // Open/Clear Document. doc = calendar.window.document; doc.open(); // Write Head: // ----------- doc.writeln( "" ); doc.writeln( "" ); doc.writeln( "" + calendar.title + "" ); doc.writeln( "" ); doc.writeln( "" ); // Start Body. doc.writeln( "" ); doc.writeln( "" ); doc.writeln( "" ); // Start Month/Year/Offset Select Bar: // ----------------------------------- doc.writeln( "" ); doc.writeln( "" ); doc.writeln( "" ); // Start Calendar Area: // -------------------- doc.writeln( "" ); doc.writeln( "" ); doc.writeln( "" ); // End Body. doc.writeln( "" ); doc.writeln( "
" ); doc.writeln( "" ); doc.writeln( "" ); doc.writeln( "" ); // Select Month. doc.writeln( "" ); // Select Year. doc.writeln( "" ); // Select Offset. if (this.showOffset) { doc.writeln( "" ); // End Month/Year/Offset Select Bar. doc.writeln( "" ); doc.writeln( "" ); doc.writeln( "
 " ); doc.writeln( "" ); doc.writeln( "" ); doc.writeln( "" ); doc.writeln( "" ); doc.writeln( "" ); doc.writeln( " 
" ); doc.writeln( "
" ); doc.writeln( "" ); // Days of Week Bar. doc.writeln( "" ); for( i = 0; i < calendar.days.length; i++ ) { doc.writeln( "" ); } doc.writeln( "" ); // Weeks. var day = 0; var firstWeekday = calendar.date.getFirstWeekdayOfMonth(); var lastDay = calendar.date.getLastDayOfMonth(); var style = ""; var caption = ""; for( i = 0, day = 0; i < 42; i++ ) { // New Week. if( i == 0 || i % 7 == 0 ) { doc.writeln( "" ); } // Date within Range. if( ( day == 0 && i >= firstWeekday ) || ( day > 0 && day < lastDay ) ) { day++; calendar.date.setDate( day ); // Closed Date. if( calendar.isClosedDate() ) { if( calendar.closedDays[calendar.date.getDay()] ) { doc.writeln( "" ); } else if( !isNull(calendar.closedDates[calendar.date]) ) { doc.writeln( "" ); } else { doc.writeln( "" ); } } // Open Date. else { if( calendar.date.valueOf() == calendar.today.valueOf() ) { style = "Today"; } else if( calendar.date.getDay() == 0 || calendar.date.getDay() == 6 ) { style = "Weekend"; } else { style = "Weekday"; } doc.writeln( "" ); } } // Date out of Range. else { doc.writeln( "" ); } // End of the Week. if( (i+1) % 7 == 0 ) { doc.writeln( "" ); } } // End Calendar Area. doc.writeln( "
" + calendar.days[i] + "
" + day + "" + day + "      " + day + "      " + day + "       
" ); doc.writeln( "
" ); doc.writeln( "" ); doc.writeln( "" ); // Close Document. doc.close(); // Reset Calendar Date to Today. calendar.date.setDate( calendar.today.getDate() ); } /** * Determine if a Date is a Closed Date. * * @param date Date object (if null, current Calendar date is used). * @return True=Closed Date; False=Open Date. */ function isCalendarClosedDate( date ) { // If Date null, Default Date to Calendar date. if( isNull(date) ) { date = calendar.date; } // Is Date Out of Range? if( ( !isNull(calendar.openMin) && date.valueOf() < calendar.openMin.valueOf() ) || ( !isNull(calendar.openMax) && date.valueOf() > calendar.openMax.valueOf() ) ) { return true; } // Is Closed Day? if( calendar.closedDays[date.getDay()] ) { return true; } // Search Closed Table of Date Values. if( !isNull(calendar.closedDates[date]) ) { return true; } return false; } /** * Calendar Month Change. * * @param month Month index (0-11). */ function changeCalendarMonth( month ) { calendar.date.setDate( 1 ); calendar.date.setMonth( month ); calendar.write( calendar.window.document ); } /** * Calendar Year Change. * * @param year Year value (yyyy). */ function changeCalendarYear( year ) { calendar.date.setDate( 1 ); calendar.date.setFullYear( year ); calendar.write(); } /** * Pick Calendar Date. * * @param day Day or Offset value selected from the calendar. */ function pickCalendarDate( day ) { var offset = null; var i = 0; // Set Calendar Date: // ------------------ // If Day Value. if ( typeof( day ) == "number" ) { calendar.date.setDate( day ); } // Else, If Today. else if( day.toLowerCase() == "today" ) { calendar.date.setTime( calendar.today.getTime() ); } // Else, If Positive Offset Value. else if( day.charAt( 0 ) == '+' ) { calendar.date = calendar.today; offset = day * 1; if( offset > calendar.offsets[calendar.offsets.length-1] ) { offset = calendar.offsets[calendar.offsets.length-1]; } for( i = 0; i < offset; i++ ) { do { calendar.date = new Date( calendar.date.valueOf() + 86400000 ); if( !isNull(calendar.openMax) && calendar.date.valueOf() > calendar.openMax ) { if( isNull(calendar.window) || calendar.window.closed ) { break; } else { alert( "Date selected exceeds maximum date; please select another date." ); calendar.window.focus(); return; } } } while( calendar.isClosedDate() ) } } // Else, If Negative Offset Value. else if( day.charAt( 0 ) == '-' ) { calendar.date = calendar.today; offset = day * 1; if( offset < calendar.offsets[0] ) { offset = calendar.offsets[0]; } for( i = 0; i > offset; i-- ) { do { calendar.date = new Date( calendar.date.valueOf() - 86400000 ); if( !isNull(calendar.openMin) && calendar.date.valueOf() < calendar.openMin ) { if( isNull(calendar.window) || calendar.window.closed ) { break; } else { alert( "Date selected exceeds maximum date; please select another date." ); calendar.window.focus(); return; } } } while( calendar.isClosedDate() ) } } // If Input Field Defined, Format & Put Date into Field. if( !isNull(calendar.field) ) { calendar.field.value = calendar.date.format( calendar.format ); } // Close Calendar Window. if( !isNull(calendar.window) ) { calendar.window.close(); } } /***************************************************************** * DATE OBJECT - AUXILIARY METHODS * *****************************************************************/ /** * Date Prototype Function to determine leap year. * * @return True=Leap Year; False=Non-Leap Year. */ function isLeapYear() { var year = this.getFullYear(); if( year % 4 == 0 ) { if( year % 100 == 0 && year % 400 != 0 ) { return false; } return true; } return false; } /** * Date Prototype Function to get first weekday of a month. * * @return First Weekday of the Month (i.e. 0-Sun, 1-Mon, etc.); */ function getFirstWeekdayOfMonth() { var first = new Date( this ); first.setDate( 1 ); return first.getDay(); } /** * Date Prototype Function to get last day of a month. * * @return Last Day of the Month (i.e. 28, 29, 30, 31); */ function getLastDayOfMonth() { var days = null; if( this.isLeapYear() ) { days = [ 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ]; } else { days = [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ]; } return days[this.getMonth()]; } /** * Format Date String. * * @param format Date format string. * @return Formatted date string. */ function formatDate( format ) { var dateString = ""; // Read Format & Build Formatted Date String. for( var i = 0; i < format.length; ) { switch( format.charAt( i ) ) { // Year Tokens. case 'y': { if( format.substr( i, 4 ) == "yyyy" ) { dateString += this.getFullYear(); i += 4; } else if( format.substr( i, 2 ) == "yy" ) { dateString += ( this.getYear() % 100 < 10 ? "0" : "" ) + (this.getYear() % 100); i += 2; } else { dateString += ( this.getYear() % 100 < 10 ? "0" : "" ) + (this.getYear() % 100); i++; } break; } // Month Tokens. case 'm': { if( format.substr( i, 3 ) == "mon" ) { dateString += this.toString().substr( 4, 3 ); i += 3; } else if( format.substr( i, 2 ) == "mm" ) { dateString += (this.getMonth() < 9 ? "0" : "") + (this.getMonth()+1); i += 2; } else { dateString += (this.getMonth()+1); i++; } break; } // Day Tokens. case 'd': { if( format.substr( i, 3 ) == "day" ) { dateString += this.toString().substr( 0, 3 ); i += 3; } else if( format.substr( i, 2 ) == "dd" ) { dateString += (this.getDate() < 10 ? "0" : "") + this.getDate(); i += 2; } else { dateString += this.getDate(); i++; } break; } // Delimiter Token. default: { dateString += format.charAt( i ); i++; } } } return dateString; } /** * Parse Date String. * * @param dateString Date string to parse. * @param format Date format string. * @return Date array of year, month, day or empty array if non-parseable. */ function parseDate( dateString, format ) { var year = NaN; var month = NaN; var day = NaN; for( var i = 0; i < format.length; ) { switch( format.charAt( i ) ) { // Year Tokens. case 'y': { if( format.substr( i, 4 ) == "yyyy" ) { year = dateString.substr( i, 4 ) * 1; i += 4; } else { year = dateString.substr( i, 2 ) * 1; i += 2; } break; } // Month Tokens. case 'm': { if( format.substr( i, 3 ) == "mon" ) { month += dateString.substr( 4, 3 ).toLowerCase(); i += 3; if( month == "jan" ) { month = 0; } else if( month == "feb" ) { month = 1; } else if( month == "mar" ) { month = 2; } else if( month == "apr" ) { month = 3; } else if( month == "may" ) { month = 4; } else if( month == "jun" ) { month = 5; } else if( month == "jul" ) { month = 6; } else if( month == "aug" ) { month = 7; } else if( month == "sep" ) { month = 8; } else if( month == "oct" ) { month = 9; } else if( month == "nov" ) { month = 10; } else if( month == "dec" ) { month = 11; } else { month = NaN; } } else { month = dateString.substr( i, 2 ) * 1; i += 2; } break; } // Day Tokens. case 'd': { if( format.substr( i, 3 ) == "day" ) { i += 3; } else { day = dateString.substr( i, 2 ) * 1; i += 2; } break; } default: i++; } } // If Non-Parseable Date String, Return null. if( isNaN( year ) || isNaN( month ) || isNaN( day ) ) { return new Array(); } // Else, Return Date Object. else { return new Array( year, month, day ); } } /** * Date Prototype Function to validate a Date String in a specified format. * * @param element Element object containing a Date String. * @param format Format string (defaults to yyyymmdd). * @return True=Valid Date; False=Invalid Date. */ function isValidDate( element, format ) { var value = ""; var message = ""; // Get Value & Trim Leading and Trailing Spaces. value = element.value.replace( /^\s+/, "" ).replace( /\s+$/, "" ); // If Offset: if( value.charAt( 0 ) == "+" || value.charAt( 0 ) == "-" ) { if( isNaN( value.substring( 1 ) ) ) { message += calendar.messageDelimiter + "Date offsets must be a \"+\" or \"-\" followed by a number."; } else { calendar.field = element; pickCalendarDate( value ); value = element.value; } } // Parse Date String Using Format String. if( isNull(format) || format.length == 0 ) { format = "yyyymmdd"; } var dateSegments = parseDate( value, format ); var year = dateSegments[0]; var month = dateSegments[1]; var day = dateSegments[2]; var date = new Date( dateSegments[0], dateSegments[1] - 1, dateSegments[2] ); // Validate Length. // ---------------- if( value.length == 0 ) { message += calendar.messageDelimiter + "No date specified." } else if( value.length < format.length ) { message += calendar.messageDelimiter + "Missing characters in date (i.e. delimiters, leading zeros)." } else if( value.length > format.length ) { message += calendar.messageDelimiter + "Extra characters or spaces found before or after date." } // Validate Date: // -------------- if( message.length == 0 ) { // Non-Numeric Date. if( date == null ) { message += calendar.messageDelimiter + "Non-numeric characters in date."; } // Numeric Date. else { // Invalid Year, Month or Day. if( year < 0 || month < 1 || month > 12 || day < 1 ) { message += calendar.messageDelimiter + "Invalid Year, Month or Day."; } // Invalid February Day. if( month == 2 ) { if( date.isLeapYear() ) { if( day > 29 ) { message += calendar.messageDelimiter + "Maximum day for this month is 29."; } } else if( day > 28 ) { message += calendar.messageDelimiter + "Maximum day for this month is 28."; } } // Invalid 30-day Month Day. else if( ((month < 8 && month % 2 == 0) || (month > 7 && month % 2 != 0)) && day > 30 ) { message += calendar.messageDelimiter + "Maximum day for this month is 30."; } // Invalid 31-day Month Day. else if( day > 31 ) { message += calendar.messageDelimiter + "Maximum day for this month is 31."; } } } // Valid Date. if( message.length == 0 ) { calendar.message = ""; // If Closed Date. if( isCalendarClosedDate( date ) ) { calendar.message = "DATE WARNING:" + calendar.messageDelimiter + "Closed date; please select another date."; return false; } return true; } // Invalid Date. else { calendar.message = "DATE EXCEPTION:" + message; return false; } }