function initCalendar(){ debug=false;// alert(errors) DeactivateJavaScript = true; DAYSBETWEENINANDOUT = (7*24*60*60*1000); MAXBOOKINGDAYS = (339*24*60*60*1000); days = new Array(31,28,31,30,31,30,31,31,30,31,30,31); // specify month names if(monthNames) names = monthNames; else names = new Array('January','February','March','April','May','June','July','August','September','October','November','December'); // specify day names if(dayNames) dow = dayNames; else dow = new Array('Mon','Tue','Wed','Thu','Fri','Sat','Sun'); weekDay = new Array(6,0,1,2,3,4,5); //config for first day of week today = new Date(); today = new Date(today.getFullYear(),today.getMonth(),today.getDate()); // specify active dates //selDates1 = null;//activatedDates1; //selDates2 = null;//activatedDates2; // specify calendar titles title1 = "Departure date"; if(calTitle1) title1 = calTitle1; title2 = "Return date"; if(calTitle2) title2 = calTitle2; firstTimeOpened = true; } //start the appl function run(){ // outDate = new Date(getDateFromOpener(document.getElementById(clientID + "DEPMONTH1").value-1,(document.getElementById(clientID + "DEPDAY1").value))); outDate = new Date(); if(outDate < new Date()) outDate = new Date(); //if(show2Calendars) inDate = new Date(getDateFromOpener(document.getElementById(clientID + "DEPMONTH2").value-1,(document.getElementById(clientID + "DEPDAY2").value))); if(show2Calendars) inDate = new Date; if(show2Calendars) hasChanged =false;//(inDate.getTime()-outDate.getTime()!=DAYSBETWEENINANDOUT); outBound = new Calendar("outBound",title1, outDate?outDate:(today.getTime()+(1*24*60*60*1000))); //outBound.activeDays = selDates1; //specify active days // Calendar 2 (inbound) if(show2Calendars){ inBound = new Calendar("inBound",title2,inDate?inDate:(today.getTime()+DAYSBETWEENINANDOUT)); inBound.hasChanged = hasChanged; if(outBound.selectedDate > inBound.selectedDate){ inBound.selectedDate = outBound.selectedDate; inBound.userDate = outBound.userDate; } outBound.child = inBound; //define observer DAYSBETWEENINANDOUT = inBound.selectedDate.getTime()-outBound.selectedDate.getTime(); } if(minDate != null) inBound.minDate = minDate; if(maxDate != null) inBound.maxDate = maxDate; if(minStay != null) { inBound.minStay = minStay; DAYSBETWEENINANDOUT=(1*24*60*60*1000); } //min days between out- & inbound. need parent if(maxStay != null) inBound.maxStay = maxStay; //max days "*/ outBound.draw(); //write the html code } function getDateFromOpener(month,day){ var year = today.getFullYear(); if(monthdays[month]?days[month]:day); } function Calendar(instanceName,title,selectedDate){ this.name = instanceName; this.title = title; this.hasChanged = false; this.selectedDate = new Date(selectedDate); this.userDate = new Date(selectedDate); this.minDate = null; this.maxDate = null; this.parentDate = null; this.minStay = 0; this.minStayDate = null; this.minStayWeekDay = null; this.maxStay = 0; this.maxStayDate = null; this.activeDays = null; this.child; //observable } // write the calendar Calendar.prototype.draw=function(date,hasChanged){//both parameter are optional try{ if(date && typeof(this.selectedDate)!="object" || this.selectedDate=="Invalid Date"){ throw("draw.date is invalid"); } if(date){ date = new Date(date); this.selectedDate = new Date(date); if(hasChanged==true){ this.hasChanged = true; this.userDate = new Date(date); } //if(this.parentDate){ // DAYSBETWEENINANDOUT = date.getTime()-this.parentDate.getTime(); //} } else { date = this.selectedDate; } if(this.parentDate){ DAYSBETWEENINANDOUT = date.getTime()-this.parentDate.getTime(); } var febYear = this.selectedDate.getFullYear(); if (this.selectedDate.getMonth()==1 && (((febYear % 4 == 0) && (febYear % 100 != 0)) || (febYear % 400 == 0)) ){ days[1] = 29; } else { days[1] = 28; } var firstDayOfMonth = new Date(date.getFullYear(),date.getMonth(),1); var lastDayOfMonth = new Date(date.getFullYear(),date.getMonth(),days[date.getMonth()]); var tmpDate = new Date(firstDayOfMonth); tmpDate.setDate(tmpDate.getDate()-weekDay[firstDayOfMonth.getDay()]); var htmlMonthDropdown = ""; //write the month dropdown var dropDownDate; var earliestMonth=null; var latestMonth = null for(var i=0;i<12;i++){ dropDownDate = new Date(addMonth(today,i,date.getDate())); //if(this.activeDays && this.activeDays[dropDownDate.getMonth()] && this.activeDays[dropDownDate.getMonth()].length>0){ htmlMonthDropdown += '\n'; if(earliestMonth==null)earliestMonth=dropDownDate.getMonth(); latestMonth = dropDownDate.getMonth(); //} } var htmlString = '\n'; htmlString += ''; // if(this.name == "outBound") htmlString += ''; htmlString += '\n' htmlString += '\n
 '+this.title + ' '; // else htmlString += '
\n'; htmlString += '\n'; htmlString += '\n'; htmlString +='
\n'; htmlString+=''; //write the day names for(var i=0;i'; } htmlString+='\n'; // write days for(var i=0;i<42;i++){ if(tmpDate.getDay()==1){ htmlString+=''; } //inactive dates if(tmpDatelastDayOfMonth){ style=' class="newcalendar-othermonth"'; onMouseOver=''; onMouseOut=''; onClick=''; }else if(tmpDate < today || tmpDate > (today.getTime()+MAXBOOKINGDAYS) || (this.minDate && tmpDate < this.minDate) || (this.maxDate && tmpDate > this.maxDate) || (this.minStayDate && tmpDate < this.minStayDate) || (this.maxStayDate && tmpDate > this.maxStayDate) || !this.isActiveDay(tmpDate) || (this.parentDate && tmpDate < this.parentDate) //|| (this.minStay && !this.minStayDay && tmpDate < (this.userDate.getTime()+(this.minStay*24*60*60*1000))) //|| this.maxStay && tmpDate > (this.userDate.getTime()+(this.maxStay*24*60*60*1000))) ){ style=' class="newcalendar-inactive"'; onMouseOver=''; onMouseOut=''; onClick=''; }else if(tmpDate.getDate()==this.userDate.getDate() && tmpDate.getMonth() == this.userDate.getMonth()){ //selectedDate style=' class="newcalendar-selected"'; onMouseOver=''; onMouseOut=''; onClick=''; } else if(tmpDate.getDay()==0){ //sunday style=' class="newcalendar-sunday"'; onMouseOver=' onMouseOver="this.className=\'newcalendar-selected\'"'; onMouseOut=' onMouseOut="this.className=\'newcalendar-sunday\'"'; onClick='onClick="'+this.name+'.draw('+tmpDate.getTime()+',true);updateDateField(\''+this.name+'\')"'; } else { //active dates style=' class="newcalendar-active"'; onMouseOver=' onMouseOver="this.className=\'newcalendar-selected\'"'; onMouseOut=' onMouseOut="this.className=\'newcalendar-active\'"'; onClick='onClick="'+this.name+'.draw('+tmpDate.getTime()+',true);updateDateField(\''+this.name+'\')"'; } htmlString += ''+tmpDate.getDate()+'\n'; if(tmpDate.getDay()==0){ htmlString+='\n'; } tmpDate.setDate(tmpDate.getDate()+1); } htmlString +='
'; document.getElementById(this.name+"_Calendar").innerHTML = htmlString; this.notifyObserver(); //notify child }catch(e){ handleError(e); } } //check array[month][day] for selectedDate Calendar.prototype.isActiveDay=function(date){ try{ if(!this.activeDays || this.activeDays.length==0) return true; var ca = this.activeDays[date.getMonth()]; for(var i=0;i<=ca.length;i++) if (date.getDate() == ca[i]) { return true; break; } return false; } catch(e){ if(debug)alert("Calendar.isActiveDay() throw\n"+e); } return true; } // notify child Calendar.prototype.notifyObserver=function(){ try{ if(this.child) this.child.update(this); }catch(e){ if(debug)alert("Calendar.notifyObserver() throw\n"+e); //continue without child updates, maybe without child.draw() this.child = null; } } //good moring child, do someting Calendar.prototype.update=function(parent){ //change here the child behaviour this.parentDate = new Date(parent.userDate); if(parent.hasChanged){ parent.hasChanged=false; //DAYSBETWEENINANDOUT = this.userDate.getTime()-parent.userDate.getTime(); if(parent.selectedDate>this.selectedDate){ this.selectedDate = new Date(parent.selectedDate.getTime()+DAYSBETWEENINANDOUT); this.userDate = this.selectedDate; } } if(this.minStay)this.minStayDate = new Date(parent.selectedDate.getTime()+(this.minStay*24*60*60*1000)); if(this.maxStay)this.maxStayDate = new Date(parent.selectedDate.getTime()+(this.maxStay*24*60*60*1000)); this.draw(); } //return new Date function addMonth(datum,value,selectedDay){ try{ var tmpDate = new Date(datum); if(typeof(tmpDate)!="object" || tmpDate=="Invalid Date"){ alert("ppmm"); throw("tmpDate is not a Date"); } var day = !selectedDay?tmpDate.getDate():selectedDay; var month = (tmpDate.getMonth()+value); if(month>11)month-=12; if(value==0){ tmpDate.setDate(day>days[month]?days[month]:day); } else { tmpDate.setMonth((tmpDate.getMonth()+value),day>days[month]?days[month]:day); } return tmpDate.getTime(); }catch(e){ throw("addMonth() throw\n"+e); } } function handleError(e){ if(debug)alert("Calendar.draw() throw\n"+e); //set error screen try{document.getElementById("error").style.visibility="visible";}catch(e){} } function exitCalendar(){ // updateDateField(); /* document.getElementById(clientID + "DEPDAY1").selectedIndex = outBound.userDate.getDate()-1; document.getElementById(clientID + "DEPMONTH1").selectedIndex = outBound.userDate.getMonth(); if(show2Calendars)document.getElementById(clientID + "DEPDAY2").selectedIndex = inBound.userDate.getDate()-1; if(show2Calendars)document.getElementById(clientID + "DEPMONTH2").selectedIndex = inBound.userDate.getMonth(); */ document.getElementById("DivCalendar").style.display = "none"; HideControls(false); } function updateDateField(strCal) { var updateMonth = eval(strCal + ".userDate.getMonth()") + 1; var updateDay = eval(strCal + ".userDate.getDate()"); var updateYear = eval(strCal + ".userDate.getFullYear()"); document.getElementById("txt_" + strCal).value = updateMonth + "/" + updateDay + "/" + updateYear; // close calendar if departing date chosen if (strCal=="inBound") { toggleCalendar(); } } function toggleCalendar() { if(document.getElementById('DivCalendar').style.display == "none") { document.getElementById('DivCalendar').style.display = 'block'; run(); if(firstTimeOpened) { // document.getElementById('DivCalendar').style.left = document.getElementById('DivCalendar').offsetLeft + LeftOffset; // document.getElementById('DivCalendar').style.top = document.getElementById('DivCalendar').offsetTop + TopOffset; firstTimeOpened = false; } HideControls(true); } else { document.getElementById('DivCalendar').style.display = "none"; HideControls(false); } } // For IE, hides any select-lists that are behind the calendar function HideControls(hide) { try { if (navigator.appName == 'Microsoft Internet Explorer') { var CalDiv = document.getElementById("DivCalendar"); var CalLeftX = GetTagPixels(CalDiv,"LEFT"); var CalRightX = CalLeftX + CalDiv.offsetWidth; var CalTopY = GetTagPixels(CalDiv,"TOP"); var CalBottomY; if(show2Calendars) CalBottomY = CalTopY + 500; else CalBottomY = CalTopY + 250; var FoundCalInput = false; for (var j=0;j CalTopY)) && ((ListLeftX < CalRightX) && (ListRightX > CalLeftX))); } function isActive(date, activatedDates){ try{ if(!activatedDates || activatedDates.length==0) return false; var ca = activatedDates[date.getMonth()]; for(var i=0;i<=ca.length;i++) if (date.getDate() == ca[i]) { return true; break; } return false; } catch(e){} return true; }