function datePicker(name,maxy,maxm,maxd,targetelement,miny,minm,mind) { var self = this; function calConfig() { miny = typeof(miny) != 'undefined' ? miny : 2006; minm = typeof(minm) != 'undefined' ? minm : 0; mind = typeof(mind) != 'undefined' ? mind : 1; self.displayYearInitial = self.curDate.getFullYear(); self.displayMonthInitial = self.curDate.getMonth(); self.displayYear = self.displayYearInitial; self.displayMonth = self.displayMonthInitial; self.minDate = new Date(miny,minm,mind); self.maxDate = new Date(maxy*1,(maxm-1)*1,maxd*1); self.startDay = 0; } function setLang() { self.daylist = new Array('Sun','Mon','Tue','Wed','Thu','Fri','Sat','Sun','Mon','Tue','Wed','Thu','Fri','Sat'); self.months_sh = new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'); self.monthup_title = 'Go to the next month'; self.monthdn_title = 'Go to the previous month'; self.maxrange_caption = 'This is the maximum range'; self.closebtn_caption = 'Close'; self.closebtn_title = 'Close the Calendar'; } function setDays() { self.daynames = new Array(); var j=0; for(var i=self.startDay;i'); monthUp.setAttribute('title',self.monthup_title); monthDn.setAttribute('type','button'); monthDn.setAttribute('value','<'); monthDn.setAttribute('title',self.monthdn_title); setClass(monthUp,'whitegrad'); setClass(monthDn,'whitegrad'); self.monthSelect.owner = self.yearSelect.owner = monthUp.owner = monthDn.owner = self; function selectonchange() { if(self.goToMonth(self.yearSelect.value,self.monthSelect.value)) { self.displayMonth = self.monthSelect.value; self.displayYear = self.yearSelect.value; } else { self.monthSelect.value = self.displayMonth; self.yearSelect.value = self.displayYear; } } addEventHandler(monthUp,'click',function(){self.nextMonth();}); addEventHandler(monthDn,'click',function(){self.prevMonth();}); addEventHandler(self.monthSelect,'change',selectonchange); addEventHandler(self.yearSelect,'change',selectonchange); container.appendChild(monthDn); container.appendChild(self.monthSelect); container.appendChild(self.yearSelect); container.appendChild(monthUp); return container; } function createFooter() { var container = document.createElement('div'); var closeBtn = document.createElement('input'); closeBtn.setAttribute('type','button') closeBtn.setAttribute('value',self.closebtn_caption); closeBtn.setAttribute('title',self.closebtn_title); addEventHandler(closeBtn,'click',function(){self.hide();}); setClass(closeBtn,'closeBtn whitegrad'); container.appendChild(closeBtn); return container; } function createDayHeading() { self.calHeading = document.createElement('thead'); setClass(self.calHeading,'caldayheading'); var tr = document.createElement('tr'), th; self.cols = new Array(false,false,false,false,false,false,false); for(var dow=0;dow<7;dow++) { th = document.createElement('th'); th.appendChild(document.createTextNode(self.daynames[dow])); tr.appendChild(th); } self.calHeading.appendChild(tr); return self.calHeading; } function createCalCells() { self.rows = new Array(false,false,false,false,false,false); self.cells = new Array(); var row = -1, totalCells = 42; var beginDate = new Date(self.displayYear,self.displayMonth,1); var endDate = new Date(self.displayYear,self.displayMonth,self.monthDayCount[self.displayMonth]); var sdt = new Date(beginDate); sdt.setDate(sdt.getDate() + (self.startDay - beginDate.getDay()) - (self.startDay - beginDate.getDay() > 0 ? 7 : 0) ); self.calCells = document.createElement('tbody'); var tr,td; var cellIdx = 0, cell, week, dayval; for(var i=0;i -1) { date = self.dates[idx]; cell.date.selected = date.selected || false; cell.date.type = date.type; cell.date.canSelect = date.canSelect; } else { cell.date.selected = false; } if(cell.date.getTime() < self.minDate.getTime() || cell.date.getTime() > self.maxDate.getTime()) { cell.date.canSelect = false; } cell.setClass(); } function cal_onmouseover() { self.mousein = true; } function cal_onmouseout() { self.mousein = false; } self.dateInArray = function(arr,searchVal,startIndex) { startIndex = (startIndex != null ? startIndex : 0); for(var i=startIndex;i 0) { month--; } else { month = 11; year--; } return self.goToMonth(year,month); }; self.goToMonth = function (year,month) { var testdatemin = new Date(year, month, 31); var testdatemax = new Date(year, month, 1); if(testdatemin >= self.minDate && testdatemax <= self.maxDate) { self.monthSelect.value = self.displayMonth = month; self.yearSelect.value = self.displayYear = year; createCalCells(); deleteCells(); self.calendar.celltable.appendChild(self.calCells); return true; } else { if (self.maxrange_caption.length>0) alert(self.maxrange_caption); return false; } }; self.updatePos = function (target) { self.calendar.style.top = getTop(target) + self.topOffset + 'px'; self.calendar.style.left = getLeft(target) + self.leftOffset + 'px'; }; self.show = function () { self.updatePos(self.tgt); self.calendar.style.display = 'block'; self.visible = true; }; self.hide = function () { self.calendar.style.display = 'none'; self.visible = false; }; self.toggle = function () { self.visible ? self.hide() : self.show(); }; self.selectDates = function (inpdates,redraw) { var i, idx; for(i=0;i 0 && self.dayOfWeek < 6) { self.cellClass = 'notmnth wkday'; } else { self.cellClass = 'notmnth wkend'; } } else if(self.date.type == 'holiday') { self.cellClass = 'hlday'; } else if(self.dayOfWeek > 0 && self.dayOfWeek < 6) { self.cellClass = 'wkday'; } else { self.cellClass = 'wkend'; } } else { self.cellClass = 'noselect'; } if(self.date.getUeDay() == owner.curDate.getUeDay()) { self.cellClass = self.cellClass + ' curdate'; } tableCell.setAttribute('class',self.cellClass); tableCell.setAttribute('className',self.cellClass); }; self.cellClass; self.tableRow = row; self.tableCell = tableCell; self.date = new Date(dateObj); self.date.canSelect = true; self.date.type = 'normal'; self.date.selected = false; self.dayOfWeek = self.date.getDay(); self.week = week; addEventHandler(tableCell,'click', calCellonclick); addEventHandler(tableCell,'mouseover', calCellonmouseover); addEventHandler(tableCell,'mouseout', calCellonmouseout); self.setClass(); } Date.prototype.getWeek = function (dowOffset) { dowOffset = typeof(dowOffset) == 'int' ? dowOffset : 0; var newYear = new Date(this.getFullYear(),0,1); var day = newYear.getDay() - dowOffset; day = (day >= 0 ? day : day + 7); var weeknum, daynum = Math.floor((this.getTime() - newYear.getTime() - (this.getTimezoneOffset()-newYear.getTimezoneOffset())*60000)/86400000) + 1; if(day < 4) { weeknum = Math.floor((daynum+day-1)/7) + 1; if(weeknum > 52) { nYear = new Date(this.getFullYear() + 1,0,1); nday = nYear.getDay() - dowOffset; nday = nday >= 0 ? nday : nday + 7; weeknum = nday < 4 ? 1 : 53; } } else { weeknum = Math.floor((daynum+day-1)/7); } return weeknum; }; Date.prototype.getUeDay = function () { return parseInt(Math.floor((this.getTime() - this.getTimezoneOffset() * 60000)/86400000)); }; Date.prototype.dateFormat = function(format) { if(!format) { format = 'm/d/Y'; } LZ = function(x) {return(x < 0 || x > 9 ? '' : '0') + x}; var MONTH_NAMES = new Array('January','February','March','April','May','June','July','August','September','October','November','December','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'); var DAY_NAMES = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sun','Mon','Tue','Wed','Thu','Fri','Sat'); var result=""; var i_format=0; var c=""; var token=""; var y=this.getFullYear().toString(); var M=this.getMonth()+1; var d=this.getDate(); var E=this.getDay(); var H=this.getHours(); var m=this.getMinutes(); var s=this.getSeconds(); value = { Y: y.toString(), y: y.substring(2), n: M, m: LZ(M), F: MONTH_NAMES[M-1], M: MONTH_NAMES[M+11], j: d, d: LZ(d), D: DAY_NAMES[E+7], l: DAY_NAMES[E], G: H, H: LZ(H) }; if (H==0) {value['g']=12;} else if (H>12){value['g']=H-12;} else {value['g']=H;} value['h']=LZ(value['g']); if (H > 11) {value['a']='pm'; value['A'] = 'PM';} else { value['a']='am'; value['A'] = 'AM';} value['i']=LZ(m); value['s']=LZ(s); while (i_format < format.length) { c=format.charAt(i_format); token=""; while ((format.charAt(i_format)==c) && (i_format < format.length)) { token += format.charAt(i_format++); } if (value[token] != null) { result=result + value[token]; } else { result=result + token; } } return result; }; function addEventHandler(element, type, func) { if(element.addEventListener) { element.addEventListener(type,func,false); } else if (element.attachEvent) { element.attachEvent('on'+type,func); } } function removeEventHandler(element, type, func) { if(element.removeEventListener) { element.removeEventListener(type,func,false); } else if (element.attachEvent) { element.detachEvent('on'+type,func); } } function getTop(element) { var oNode = element; var iTop = 0; while(oNode.tagName != 'HTML') { iTop += oNode.offsetTop || 0; if(oNode.offsetParent) { oNode = oNode.offsetParent; } else { break; } } return iTop; } function getLeft(element) { var oNode = element; var iLeft = 0; while(oNode.tagName != 'HTML') { iLeft += oNode.offsetLeft || 0; if(oNode.offsetParent) { oNode = oNode.offsetParent; } else { break; } } return iLeft; } function changedatepicker2 (f,m,d) { document.getElementById(f+'_date').value = d; document.getElementById(f+'_monthyear').value = m; setdeparturedate (f,'numnight'); /*document.forms["bookinggetdates"].submit();*/ } function checknotearly(f,l) { if (f && l) { dateObjf = new Date(); dateObjf.setFullYear(document.getElementById(f+'_year').value); dateObjf.setMonth(document.getElementById(f+'_month').value-1); dateObjf.setDate(document.getElementById(f+'_date').value); dateObjl = new Date(); dateObjl.setFullYear(document.getElementById(l+'_year').value); dateObjl.setMonth(document.getElementById(l+'_month').value-1); dateObjl.setDate(document.getElementById(l+'_date').value); //alert (dateObjf + " to " + dateObjl); if (dateObjl < dateObjf) { document.getElementById(l+'_year').value=document.getElementById(f+'_year').value; document.getElementById(l+'_month').value=document.getElementById(f+'_month').value; document.getElementById(l+'_date').value=document.getElementById(f+'_date').value; } } } function setdeparturedate (f,n) { var weekday=new Array(7); weekday[0]="Sun"; weekday[1]="Mon"; weekday[2]="Tue"; weekday[3]="Wed"; weekday[4]="Thu"; weekday[5]="Fri"; weekday[6]="Sat"; var month_name=new Array(12); month_name[0]="Jan"; month_name[1]="Feb"; month_name[2]="Mar"; month_name[3]="Apr"; month_name[4]="May"; month_name[5]="Jun"; month_name[6]="Jul"; month_name[7]="Aug"; month_name[8]="Sep"; month_name[9]="Oct"; month_name[10]="Nov"; month_name[11]="Dec"; d = document.getElementById(f+'_date').value; my = document.getElementById(f+'_monthyear').value; num = document.getElementById(n).value; y = my.substr(0,4); m = my.substr(5,2); dd = new Date(); dd.setDate(1); dd.setFullYear(y); dd.setMonth(parseInt(m)-1); dd.setDate(parseInt(d)+parseInt(num)); //document.getElementById('departingdate').innerHTML = weekday[dd.getDay()] + ' ' + dd.getDate()+ ' ' + month_name[dd.getMonth()] + ' ' + dd.getFullYear(); document.getElementById('departingdate').innerHTML = weekday[dd.getDay()] + ' ' + dd.getDate()+ ' ' + month_name[dd.getMonth()]; } function checkthebox(i) { document.getElementById(i).checked=true; }