function jsCalendar(formId) { this.init(formId); } jsCalendar.prototype.init = function(formId) { // Form Object Identifiers this.formId = formId; this.triggerId = 't_'+formId; this.displayId = 'd_'+formId; this.objectId = 'o_'+formId; // Calendar Settings this.currentDate = new Date(); this.selectedDate = new Date(); this.startDay = 0; //Sun=0, Mon=1, Tue=2, Wed=3, Thu=4, Fri=5, Sat=6 this.monthBrowse = 'on'; this.yearBrowse = 'on'; // Grpahic Settings this.nextMonthG = ''; this.prevMonthG = ''; this.nextYearG = ''; this.prevYearG = ''; // Table Settings this.tableWidth = '200px'; this.tableBorder1 = '1px solid #4682B4'; this.tableBorder2 = '2px solid #4682B4'; this.tableFont = ''; this.headerBorder = ''; this.headerHeight = '23px'; this.headerBG = '#4682B4'; this.headerFontColor = 'white'; this.headerFontSize = '10pt'; this.headerFontWeight = 'bold'; this.headerFontFamily = 'Verdana'; this.dayBorder = '1px solid #4682B4'; this.dayHeight = ''; this.dayWidth = '14.28%'; this.dayBG = '#87CEFA'; this.dayFontColor = 'white'; this.dayFontSize = '8pt'; this.dayFontWeight = 'bold'; this.dayFontFamily = 'Verdana'; this.selectedColor = '#FF9696'; this.weekendColor = '#A596FF'; this.nonmonthColor = '#E1E1E1'; this.defaultColor = 'white'; // Calendar Data this.lShDays = new Array('Su','Mo','Tu','We','Th','Fr','Sa'); this.lLhDays = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'); this.lShMonths = new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'); this.lLhMonths = new Array('January','Febuary','March','April','May','June','July','August','September','October','November','December'); this.daysPerMonth = new Array(31,28,31,30,31,30,31,31,30,31,30,31); // Regular Expressions this.slash = new RegExp('/'); this.dash = new RegExp('-'); this.dateCheck = /^(\d\d?)[\/-](\d\d?)[\/-](\d{2,4})$/; } jsCalendar.prototype.triggerTable = function() { if(document.getElementById(this.formId).value != '') this.initializeValue(document.getElementById(this.formId).value); if(document.getElementById(this.displayId).innerHTML != '') this.closeTable(); else this.buildTable(); } jsCalendar.prototype.checkValue = function(initValue) { if(initValue!='' && !initValue.match(this.dateCheck)) { document.getElementById(this.formId).value = ''; alert('The date format you entered is invalid'+"\r\n"+'Please use the MM/DD/YYYY format'); } else document.getElementById(this.formId).value = initValue.replace(/-/g,'/'); } jsCalendar.prototype.initializeValue = function(initValue) { if(initValue.match(this.slash)) initValueArray = initValue.split('/'); else if(initValue.match(this.dash)) initValueArray = initValue.split('-'); if(typeof(initValueArray[1])!='undefined') { this.selectedDate.setDate(initValueArray[1]); this.currentDate.setDate(initValueArray[1]); } if(typeof(initValueArray[0])!='undefined') { this.selectedDate.setMonth(initValueArray[0]-1); this.currentDate.setMonth(initValueArray[0]-1); } if(typeof(initValueArray[2])!='undefined') { this.selectedDate.setYear(initValueArray[2]); this.currentDate.setYear(initValueArray[2]); } } jsCalendar.prototype.buildTable = function() { displayCal = '' + this.generateTitle() + this.generateDaysOfWeek() + this.generateDaysOfMonth() +'
'; document.getElementById(this.displayId).innerHTML = displayCal; } jsCalendar.prototype.generateTitle = function() { // Values tDay = this.currentDate.getDate(); tMonth = this.currentDate.getMonth(); tYear = this.currentDate.getFullYear(); // Init var leftData = ''; var rightData = ''; var displayedDate = ''; var outputData = ''; // toggle month Browse if(this.monthBrowse == 'on') { leftData = ''+this.prevMonthG+' '; rightData = ' '+this.nextMonthG+''; } // toggle month Browse if(this.yearBrowse == 'on') { leftData = ''+this.prevYearG+'  '+leftData; rightData = rightData+'  '+this.nextYearG+''; } // Displayed Date displayedDate = this.lShMonths[tMonth]+' '+tDay+', '+tYear; outputData = '' +'' +'' +'' +'' +'' +'' +'' +'
'+leftData+''+displayedDate+''+rightData+'
' +'' +''; return outputData; } jsCalendar.prototype.generateDaysOfWeek = function() { for(i=0,j=this.startDay,outputData=''; i<7; i++) { if(j>6) j=0; outputData = outputData+''+this.lShDays[j]+''; j++; } outputData = ''+outputData+''; return outputData; } jsCalendar.prototype.generateDaysOfMonth = function() { var isLeapMonth = new Date(); isLeapMonth.setMonth(this.currentDate.getMonth()); isLeapMonth.setYear(this.currentDate.getFullYear()); isLeapMonth.setDate(29); var newDate = new Date(); newDate.setMonth(this.currentDate.getMonth()); newDate.setYear(this.currentDate.getFullYear()); newDate.setDate(1); monthStarts = newDate.getDay(); if(newDate.getMonth()==1 && isLeapMonth.getDate()!=1) monthEnds = 29; else monthEnds = this.daysPerMonth[newDate.getMonth()]; for(i=0,counter=0,outputData=''; i6) k=0; if(k==0||k==6) bgColor=this.weekendColor; else bgColor=this.defaultColor; if(counter==0) { if(monthStarts==k) { counter=1; dateVal=i+1; } else dateVal=''; } else { if(i>=monthEnds) dateVal=''; else dateVal=i+1; } if(this.selectedDate.getDate() == dateVal && this.selectedDate.getMonth() == this.currentDate.getMonth()) bgColor=this.selectedColor; if(dateVal!='') outputLine = outputLine+''+dateVal+''; else outputLine = outputLine+' '; if(counter==1) i++; k++; } outputData = outputData+''+outputLine+''; } return outputData; } jsCalendar.prototype.hideTable = function() { document.getElementById(this.displayId).innerHTML = ''; } jsCalendar.prototype.nextMonth = function() { this.currentDate.setDate(1); this.currentDate.setMonth(this.currentDate.getMonth()+1); this.buildTable(); } jsCalendar.prototype.prevMonth = function() { this.currentDate.setDate(1); this.currentDate.setMonth(this.currentDate.getMonth()-1); this.buildTable(); } jsCalendar.prototype.nextYear = function() { this.currentDate.setDate(1); this.currentDate.setYear(this.currentDate.getFullYear()+1); this.buildTable(); } jsCalendar.prototype.prevYear = function() { this.currentDate.setDate(1); this.currentDate.setYear(this.currentDate.getFullYear()-1); this.buildTable(); } jsCalendar.prototype.closeTable = function() { document.getElementById(this.displayId).innerHTML = ''; } jsCalendar.prototype.setVal = function(dateVal) { monthVal = this.currentDate.getMonth(); yearVal = this.currentDate.getFullYear(); document.getElementById(this.formId).value = (monthVal+1)+'/'+dateVal+'/'+yearVal; this.closeTable(); }