// safari work around function for Date.setDate(); function addDays(daysToAdd,date) { var x = new Date(2000,1,1); var y = new Date(2000,1,1); if(x.setDate(128) > y.valueOf()) { date.setDate(date.getDate()+daysToAdd); return date; } // Safari setDate(uint8) workaround if(daysToAdd < 0) { for(var i= -97; daysToAdd < i; daysToAdd-= i) { date.setDate(date.getDate()+i); } } else { for(var i= 96; daysToAdd > i; daysToAdd-= i) { date.setDate(date.getDate()+i); } } date.setDate(date.getDate()+daysToAdd); return date; } // declare and set module variables var moCalendarManagerCiCo = new CalendarManager(); // Static date constants for today (not overwritten by functions) var mcCalsToDisplay = 2; var mcMaxBookDays = 30; var mcDisplayLimit = 549; var mcToday = new Date(); mcToday = new Date(mcToday.getFullYear(),mcToday.getMonth(),mcToday.getDate()); var mcMaxDisplay = new Date(); // safari fix // mcMaxDisplay = mcMaxDisplay.setDate(mcToday.getDate() + mcDisplayLimit); //today + 549 days = 550 days to display mcMaxDisplay = addDays(mcDisplayLimit, mcMaxDisplay) //today + 549 days = 550 days to display var moMonthDayCountArrayCiCo = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); var moLeftArrow = new Image(); var moRightArrow = new Image(); var moCloseX = new Image(); /* set up language object to display the correct strings on the cal for internationalization (can and should be overwritten on calling page) default to english and get populated on the page with the translated strings */ var moLanguageObjCiCo = { calendarErrorArray : [ "Your stay cannot be more than one month.", "You can only book up to 550 days in advance.", "Arrival date cannot be earlier than today.", "Departure date cannot be earlier than arrival date.", "Arrival and departure date cannot be on the same day.", "Please select a check-in and checkout date.", "Please select a checkout date." ], calendarMonthNameArray : ["January","February","March","April","May","June","July","August","September","October","November","December"], calendarShortMonthArray : ["JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC"], calendarDayNameArray : ["Su","M","Tu","W","Th","F","Sa"], menuNotSelected : "Not Selected", menuNoLOS : "--", menuTravelDatesTo : "to", menuLOSUnit : "nights", calendarClose : "Close", calendarInstructionLabel : '', calendarInstructionText : "Click your check-in date, and then click on your check-out date.", calendarClear : "Clear Calendar", calendarPrev : "Previous", calendarNext : "Next", menuTravelDates : "Travel Dates:", menuLengthOfStay : "Length of Stay:", calendarContinue : "Continue" }; // function to determine the offsetLeft of an element that is passed in function fnGetOffsetLeftCiCo (pElement) { var lsLeftOffset = pElement.offsetLeft; while ((pElement = pElement.offsetParent) != null){ lsLeftOffset += pElement.offsetLeft; } return lsLeftOffset; } // function to determine the offsetTop of an element that is passed in function fnGetOffsetTopCiCo (pElement) { var lsTopOffset = pElement.offsetTop; while ((pElement = pElement.offsetParent) != null){ lsTopOffset +=pElement.offsetTop; } return lsTopOffset; } var moCalendarObjCiCo = null; function CalendarManager(){ this.calArray = new Array(); } //Calendar Manager method to add a new calendar to the array CalendarManager.prototype.addCalendar = function(pCalendarObj){ this.calArray[pCalendarObj.calendarId] = pCalendarObj; } // Availability Calendar Constructor - takes in an id as a handle, a date string for ci and a date string for co in yyyy-mm-dd format function multiDisplayCalendar(pCalendarId, pCIDate, pCODate, pReturnFunction){ this.isRendered = 0; this.isCreated = 0; if(moCalendarManagerCiCo.calArray[pCalendarId]){ var loCalendarObj = moCalendarManagerCiCo.calArray[pCalendarId]; this.getCIDateFunction = pCIDate; this.getCODateFunction = pCODate; loCalendarObj.ciDateInitial = this.getCIDateFunction(); loCalendarObj.coDateInitial = this.getCODateFunction(); loCalendarObj.initializeObject(); return loCalendarObj; } else{ this.calendarId = pCalendarId; this.returnFunction = pReturnFunction; this.getCIDateFunction = pCIDate; this.getCODateFunction = pCODate; this.calLocation = "bottomRight"; this.ciDateInitial = this.getCIDateFunction(); this.coDateInitial = this.getCODateFunction(); this.ciDate = null; this.coDate = null; this.calStartDate = null; this.selectedLOS = null; this.dateDisplayMode = null; this.display = 'none'; this.calendarDivMonth = new Array(); this.calendarTravelDates = null; this.calendarLengthOfStay = null; this.calendarTravelDates = null; this.calendarLengthOfStay = null; this.errorMessageDiv = null; this.calendarContinue = null; this.calendarPrevious = null; this.calendarPreviousAction = null; this.calendarNext = null; this.calendarNextAction = null; this.hasError = null; this.errorArray = null; this.initializeObject(); this.ciCocalendarIframe = null; this.ciCocalendarContainer = null; moCalendarManagerCiCo.addCalendar(this); } } multiDisplayCalendar.prototype.initializeObject = function(){ //this.ciDate = this.formatDateOnImport(this.ciDateInitial); //this.coDate = this.formatDateOnImport(this.coDateInitial); this.ciDateInitial = this.getCIDateFunction(); this.coDateInitial = this.getCODateFunction(); this.ciDate = this.ciDateInitial; this.coDate = this.coDateInitial; this.calStartDate = this.getCalStartDate(); this.dateDisplayMode = this.getDisplayMode(); this.selectedLOS = this.getLengthOfStay(); this.hasError = false; } multiDisplayCalendar.prototype.getCalStartDate = function(){ var loStartDate = (this.ciDate) ? new Date(this.ciDate.getFullYear(),this.ciDate.getMonth(), 1) : new Date(mcToday.getFullYear(), mcToday.getMonth(), 1); //alert("loStartDate: " + loStartDate); return loStartDate; } multiDisplayCalendar.prototype.getDisplayMode = function(){ var lsDisplayMode; if(this.ciDateInitial != null && this.coDateInitial != null){ lsDisplayMode = 2; } else if(this.ciDateInitial != null && this.coDateInitial == null){ lsDisplayMode = 1; } else{ lsDisplayMode = 0; } return lsDisplayMode; } //Availability Calendar method to show and hide the coresponding div multiDisplayCalendar.prototype.toggleDisplay = function(){ this.display = (this.display == 'none') ? 'block' : 'none'; this.ciCocalendarContainer.style.display = this.display; // set the iframe dimensions, needs to be done after the calendar is displayed if(this.display == 'block'){ this.ciCocalendarIframe.width = this.ciCocalendarContainer.offsetWidth; this.ciCocalendarIframe.height = this.ciCocalendarContainer.offsetHeight; this.ciCocalendarIframe.style.zIndex = this.ciCocalendarContainer.style.zIndex - 1; } this.ciCocalendarIframe.style.display = this.display; } //Availability Calendar method to show and hide the coresponding div multiDisplayCalendar.prototype.show = function(pCalendarIcon, calLocation){ this.initializeObject(); if(!this.isCreated) { this.ciCocalendarContainer = this.createFramework(); this.isCreated = 1; } if(!this.isRendered) { this.renderCalDisplay(); this.isRendered = 1; } this.display = 'block'; this.ciCocalendarContainer.style.display = this.display; // set the iframe dimensions, needs to be done after the calendar is displayed if(this.display == 'block'){ this.ciCocalendarIframe.width = this.ciCocalendarContainer.offsetWidth; this.ciCocalendarIframe.height = this.ciCocalendarContainer.offsetHeight; this.ciCocalendarIframe.style.zIndex = this.ciCocalendarContainer.style.zIndex - 1; } this.ciCocalendarIframe.style.display = this.display; if(pCalendarIcon!=undefined) this.setCalendarPosition(pCalendarIcon, calLocation); } //Availability Calendar method to show and hide the coresponding div multiDisplayCalendar.prototype.hide = function(event){ this.display = 'none'; this.ciCocalendarContainer.style.display = this.display; this.ciCocalendarIframe.style.display = this.display; } multiDisplayCalendar.prototype.setCalendarPosition = function(pCalendarIcon, calLocation){ this.calLocation = calLocation; if (this.calLocation == "topLeft") { // display to the top left of the icon this.ciCocalendarContainer.style.top = (fnGetOffsetTopCiCo(pCalendarIcon, this.ciCocalendarContainer) - this.ciCocalendarContainer.offsetHeight) + 'px'; this.ciCocalendarContainer.style.left = (fnGetOffsetLeftCiCo(pCalendarIcon, this.ciCocalendarContainer) - this.ciCocalendarContainer.offsetWidth) + 'px'; } else if (this.calLocation == "topRight") { // display to the top left of the icon this.ciCocalendarContainer.style.top = (fnGetOffsetTopCiCo(pCalendarIcon, this.ciCocalendarContainer) - this.ciCocalendarContainer.offsetHeight) + 'px'; this.ciCocalendarContainer.style.left = fnGetOffsetLeftCiCo(pCalendarIcon, this.ciCocalendarContainer) + 'px'; } else if (this.calLocation == "bottomRight") { // display below and to the right of the icon this.ciCocalendarContainer.style.top = fnGetOffsetTopCiCo(pCalendarIcon, this.ciCocalendarContainer) + 'px'; this.ciCocalendarContainer.style.left = fnGetOffsetLeftCiCo(pCalendarIcon, this.ciCocalendarContainer) + 'px'; } else if (this.calLocation == "bottomLeft") { // display below and to the right of the icon this.ciCocalendarContainer.style.top = fnGetOffsetTopCiCo(pCalendarIcon, this.ciCocalendarContainer) + 'px'; this.ciCocalendarContainer.style.left = (fnGetOffsetLeftCiCo(pCalendarIcon, this.ciCocalendarContainer) - this.ciCocalendarContainer.offsetWidth) + 'px'; } else { // the user tells it where to be placed // expecting a string with x and y seperated by a comma var laUserLocation = this.calLocation.split(","); this.ciCocalendarContainer.style.top = laUserLocation[1] + 'px'; this.ciCocalendarContainer.style.left = laUserLocation[0] + 'px'; } this.ciCocalendarIframe.style.top = this.ciCocalendarContainer.style.top; this.ciCocalendarIframe.style.left = this.ciCocalendarContainer.style.left; } //Availability Calendar method to clear the calendar object, used in "Reset" multiDisplayCalendar.prototype.clearObject = function(){ this.ciDateInitial = ''; this.coDateInitial = ''; this.ciDate = null; this.coDate = null; this.dateDisplayMode = 0; this.selectedLOS = null; this.hasError = null; this.errorArray = null; //this.returnFunction(this.ciDate, this.coDate, false); } multiDisplayCalendar.prototype.createFramework = function(){ var lsText; var loTextNode; //create the iframe to sit behind the layer - workaround for IE and select boxes var loCalenderHolderIframe = document.createElement("iframe"); loCalenderHolderIframe.name = "ciCocalendarHolder_Iframe"; loCalenderHolderIframe.id = "ciCocalendarHolder_Iframe"; loCalenderHolderIframe.width = 0; loCalenderHolderIframe.height = 0; loCalenderHolderIframe.className = "ciCocalendarHolderIframe"; loCalenderHolderIframe.src = "blank.htm"; this.ciCocalendarIframe = loCalenderHolderIframe; document.body.appendChild(this.ciCocalendarIframe); // create main calendar div var loCalenderHolder = document.createElement("div"); loCalenderHolder.style.zIndex = "2000"; loCalenderHolder.className = "ciCocalendarHolder"; loCalenderHolder.id = "ciCocalendarHolder"; document.body.appendChild(loCalenderHolder); // create close button var loClose = document.createElement("div"); loClose.className = "ciCocloseButton"; var loCloseAction = document.createElement("a"); loCloseAction.href = "javascript:fnCloseCalendarCiCo('" + this.calendarId + "');"; loCloseAction.title = moLanguageObjCiCo.calendarClose; lsText = moLanguageObjCiCo.calendarClose; loTextNode = document.createTextNode(lsText); loCloseAction.appendChild(loTextNode); var loCloseActionImg = document.createElement("img"); loCloseActionImg.src = moCloseX.src; loCloseActionImg.border = '0'; loCloseActionImg.alt = moLanguageObjCiCo.calendarClose; loCloseAction.appendChild(loCloseActionImg); loClose.appendChild(loCloseAction); loCalenderHolder.appendChild(loClose); // create instruction header var loInstructions = document.createElement("div"); loInstructions.className = "ciCocalendarInstructions"; var loInstructionLabel = document.createElement("div"); loInstructionLabel.className = "ciCocalendarInstructionsLabel"; lsText = moLanguageObjCiCo.calendarInstructionLabel; loTextNode = document.createTextNode(lsText); loInstructionLabel.appendChild(loTextNode); loInstructions.appendChild(loInstructionLabel); var loInstructionText = document.createElement("div"); lsText = moLanguageObjCiCo.calendarInstructionText; loTextNode = document.createTextNode(lsText); loInstructionText.appendChild(loTextNode); loInstructions.appendChild(loInstructionText); loCalenderHolder.appendChild(loInstructions); // create the main calendar portion var loCalendarContainer = document.createElement("div"); loCalendarContainer.className = "ciCocalendarOuterContainer"; // Prev button var loPreviousButton = document.createElement("div"); loPreviousButton.className = "ciCocalendarNavigation"; var loPrevActionHolder = document.createElement("div"); loPrevActionHolder.id = "ciCocalendarNavigationPrev"; var loPrevAction = document.createElement("a"); this.calendarPreviousAction = "javascript:fnChangeMonthCiCo('" + this.calendarId + "',-1);"; loPrevAction.className = "ciCocalendarNavigationPrevActive" loPrevAction.href = this.calendarPreviousAction; loPrevAction.title = moLanguageObjCiCo.calendarPrev; this.calendarPrevious = loPrevAction; var loPrevActionImg = document.createElement("img"); loPrevActionImg.src = moLeftArrow.src; loPrevActionImg.border = '0'; loPrevActionImg.alt = moLanguageObjCiCo.calendarPrev; loPrevAction.appendChild(loPrevActionImg); loPrevActionHolder.appendChild(loPrevAction); loPreviousButton.appendChild(loPrevActionHolder); //this.calendarPrevious = loPreviousButton; loCalendarContainer.appendChild(loPreviousButton); // container var loCalendarInnerContainer = document.createElement("div"); loCalendarInnerContainer.className = "ciCocalendarInnerContainer"; /* ****************CAL BODY HERE******************* */ // left cal var loLeftCal = document.createElement("div"); loLeftCal.className = "ciCocalendarDiv"; loCalendarInnerContainer.appendChild(loLeftCal); this.calendarDivMonth[0] = loLeftCal; // spacer div var loSpacerDiv = document.createElement("div"); loSpacerDiv.className = "ciCospacerDiv"; loCalendarInnerContainer.appendChild(loSpacerDiv); // right cal var loRightCal = document.createElement("div"); loRightCal.className = "ciCocalendarDiv"; loCalendarInnerContainer.appendChild(loRightCal); this.calendarDivMonth[1] = loRightCal; // clear div var loClearDiv1 = document.createElement("div"); loClearDiv1.className = "ciCodivClear"; loCalendarInnerContainer.appendChild(loClearDiv1); // clear calendar var loClearCal = document.createElement("div"); loClearCal.className = "ciCoresetDates"; var loResetAction = document.createElement("a"); loResetAction.href = "javascript:fnResetCalendarCiCo('" + this.calendarId + "');"; loResetAction.title = moLanguageObjCiCo.calendarClear; lsText = moLanguageObjCiCo.calendarClear; loTextNode = document.createTextNode(lsText); loResetAction.appendChild(loTextNode); loClearCal.appendChild(loResetAction); loCalendarInnerContainer.appendChild(loClearCal); loCalendarContainer.appendChild(loCalendarInnerContainer); /* ****************END CAL BODY******************** */ // Next button var loNextButton = document.createElement("div"); loNextButton.className = "ciCocalendarNavigation"; var loNextActionHolder = document.createElement("div"); loNextActionHolder.id = "ciCocalendarNavigationNext"; var loNextAction = document.createElement("a"); this.calendarNextAction = "javascript:fnChangeMonthCiCo('" + this.calendarId + "',1);"; loNextAction.href = this.calendarNextAction; loNextAction.className = "ciCocalendarNavigationNextActive" loNextAction.title = moLanguageObjCiCo.calendarNext; this.calendarNext = loNextAction; var loNextActionImg = document.createElement("img"); loNextActionImg.src = moRightArrow.src; loNextActionImg.border = '0'; loNextActionImg.alt = moLanguageObjCiCo.calendarNext; loNextAction.appendChild(loNextActionImg); loNextActionHolder.appendChild(loNextAction); loNextButton.appendChild(loNextActionHolder); //this.calendarNext = loNextButton; loCalendarContainer.appendChild(loNextButton); // clear div var loClearDiv2 = document.createElement("div"); loClearDiv2.className = "ciCodivClear"; loCalendarContainer.appendChild(loClearDiv2); loCalenderHolder.appendChild(loCalendarContainer); // create travel dates display var loMenuHolder = document.createElement("div"); loMenuHolder.className = 'ciComenuHolder'; var loTravelDateHolder = document.createElement("div"); loTravelDateHolder.className = "ciCotravelDateHolder"; var loTravelDateLabel = document.createElement("div"); loTravelDateLabel.className = "ciCotravelDateLabel"; lsText = moLanguageObjCiCo.menuTravelDates + ' '; loTextNode = document.createTextNode(lsText); loTravelDateLabel.appendChild(loTextNode); loTravelDateHolder.appendChild(loTravelDateLabel); var loTravelDates = document.createElement("div"); loTravelDates.className = "ciCotravelDates"; loTravelDates.id = "ciCotravelDates"; this.calendarTravelDates = loTravelDates; loTravelDateHolder.appendChild(loTravelDates); var loClearDiv3 = document.createElement("div"); loClearDiv3.className = "ciCodivClear"; loTravelDateHolder.appendChild(loClearDiv3); var loLengthOfStayLabel = document.createElement("div"); loLengthOfStayLabel.className = "ciCotravelDateLabel"; lsText = moLanguageObjCiCo.menuLengthOfStay + ' '; loTextNode = document.createTextNode(lsText); loLengthOfStayLabel.appendChild(loTextNode); loTravelDateHolder.appendChild(loLengthOfStayLabel); var loLengthOfStay = document.createElement("div"); loLengthOfStay.className = "ciColengthOfStay"; loLengthOfStay.id = "ciColengthOfStay"; this.calendarLengthOfStay = loLengthOfStay; loTravelDateHolder.appendChild(loLengthOfStay); loMenuHolder.appendChild(loTravelDateHolder); // create close button var loContinueButton = document.createElement("div"); loContinueButton.className = "ciCocontinueButton"; var loContinueAction = document.createElement("a"); loContinueAction.className = "ciCobutton_a"; loContinueAction.href = "javascript:fnContinueCiCo('" + this.calendarId + "');"; loContinueAction.title = moLanguageObjCiCo.calendarContinue; lsText = moLanguageObjCiCo.calendarContinue; loTextNode = document.createTextNode(lsText); loContinueAction.appendChild(loTextNode); loContinueButton.appendChild(loContinueAction); this.calendarContinue = loContinueButton; loMenuHolder.appendChild(loContinueButton); var loClearDiv4 = document.createElement("div"); loClearDiv4.className = "ciCodivClear"; loMenuHolder.appendChild(loClearDiv4); loCalenderHolder.appendChild(loMenuHolder); // create error display var loError = document.createElement("div"); loError.className = "ciCocalendarError"; loError.id = "ciCocalendarError"; this.errorMessageDiv = loError; loCalenderHolder.appendChild(loError); return loCalenderHolder; } //Availability Calendar method to render the calendar, different results are shown based on the display mode multiDisplayCalendar.prototype.renderCalendar = function(){ for(var calIndex=0; calIndex'; } // Calendar Days lsOutput += '
 
'; // Figure out if it is a leap year and set accordingly moMonthDayCountArrayCiCo[1] = (((loCurrentYear % 4 == 0) && (loCurrentYear % 100 != 0)) || (loCurrentYear % 400 == 0)) ? 29 : 28; for (i=0; i' + loCurrentDate.getDate() +''; } else{ //day is past the book limit lsTempOutput = '
' + loCurrentDate.getDate() +'
'; } if(loCurrentDate < mcToday){ // day is less than today lsTempOutput = '
' + loCurrentDate.getDate() +'
'; } lsOutput += lsTempOutput; if (lvColumnIndex == 6) { lsOutput += '
 
'; lvColumnIndex = -1; } } break; case 1: var loSelectedCheckInDate = this.ciDate; for (var i=0; i<=moMonthDayCountArrayCiCo[loCurrentMonth]-1; i++, lvColumnIndex++) { var loCurrentDate = new Date(loCurrentYear,loCurrentMonth,1); loCurrentDate = new Date(loCurrentDate.setDate(loCurrentDate.getDate() + i)); var lsTempOutput = ''; if(loCurrentDate < mcMaxDisplay){ // day is valid lsTempOutput = ''; } else{ //day is past the book limit lsTempOutput = '
' + loCurrentDate.getDate() +'
'; } if(loCurrentDate.getTime() == loSelectedCheckInDate.getTime()){ lsTempOutput = ''; } if(loCurrentDate < mcToday){ // day is less than today lsTempOutput = '
' + loCurrentDate.getDate() +'
'; } lsOutput += lsTempOutput; if (lvColumnIndex == 6) { lsOutput += '
 
'; lvColumnIndex = -1; } } break; case 2: var loSelectedCheckInDate = this.ciDate; var loSelectedCheckOutDate = this.coDate; ////alert("loSelectedCheckInDate: " + loSelectedCheckInDate); ////alert("loSelectedCheckOutDate: " + loSelectedCheckOutDate); for (var i=0; i<=moMonthDayCountArrayCiCo[loCurrentMonth]-1; i++, lvColumnIndex++) { var loCurrentDate = new Date(loCurrentYear,loCurrentMonth,1); loCurrentDate = new Date(loCurrentDate.setDate(loCurrentDate.getDate() + i)); var lsTempOutput = ''; if (loCurrentDate.getTime() == loSelectedCheckInDate.getTime()){ // day is check in date lsTempOutput = ''; } else if (loCurrentDate.getTime() == loSelectedCheckOutDate.getTime()){ // day is check out date lsTempOutput = ''; } else if (loCurrentDate.getTime() > loSelectedCheckInDate.getTime() && loCurrentDate.getTime() < loSelectedCheckOutDate.getTime() ){ // day is a booked date lsTempOutput = ''; } else{ if(loCurrentDate < mcMaxDisplay){ // day is valid lsTempOutput = ''; } else{ //day is past the book limit lsTempOutput = '
' + loCurrentDate.getDate() +'
'; } } if(loCurrentDate < mcToday){ // day is less than today lsTempOutput = '
' + loCurrentDate.getDate() +'
'; } lsOutput += lsTempOutput; if (lvColumnIndex == 6) { lsOutput += '
 
'; lvColumnIndex = -1; } } break; } if (lvColumnIndex > 0) { for (i=1; lvColumnIndex<7; i++, lvColumnIndex++){ lsOutput += '
 
'; } } lsOutput += ''; //Write the newly constructed table to the div on the page this.calendarDivMonth[calIndex].innerHTML = lsOutput; } } multiDisplayCalendar.prototype.renderTravelDates = function(){ var lsOutput = ''; var lsCIDisplay = fnGetDisplayDateCiCo(this.ciDate); var lsCODisplay = fnGetDisplayDateCiCo(this.coDate); //alert("this.ciDate: " + this.ciDate); //alert("this.coDate: " + this.coDate); lsOutput += (lsCIDisplay) ? lsCIDisplay : moLanguageObjCiCo.menuNotSelected; lsOutput += '
 ' + moLanguageObjCiCo.menuTravelDatesTo + ' 
'; lsOutput += (lsCODisplay) ? lsCODisplay : moLanguageObjCiCo.menuNotSelected; // ouput the Travel Dates to the div this.calendarTravelDates.innerHTML = lsOutput; } multiDisplayCalendar.prototype.renderStayLength = function(){ var lsOutput = (this.selectedLOS) ? this.selectedLOS + ' ' + moLanguageObjCiCo.menuLOSUnit : moLanguageObjCiCo.menuNoLOS; this.calendarLengthOfStay.innerHTML = lsOutput; } multiDisplayCalendar.prototype.renderErrors = function(pFromContinue){ this.validateCalendar(pFromContinue); if(this.hasError){ var lsOutput = ''; for(var i=0; i' } this.errorMessageDiv.innerHTML = lsOutput; this.errorMessageDiv.style.display = 'block'; } else{ this.errorMessageDiv.style.display = 'none'; this.errorMessageDiv.innerHTML = ''; } } multiDisplayCalendar.prototype.validateCalendar = function(pFromContinue){ this.hasError = false; this.errorArray = new Array(); if(this.ciDate){ if(this.selectedLOS > mcMaxBookDays){ this.errorArray[this.errorArray.length] = moLanguageObjCiCo.calendarErrorArray[0]; this.hasError = true; } if(this.ciDate > mcMaxDisplay){ this.errorArray[this.errorArray.length] = moLanguageObjCiCo.calendarErrorArray[1]; this.hasError = true; } if(this.ciDate < mcToday){ this.errorArray[this.errorArray.length] = moLanguageObjCiCo.calendarErrorArray[2]; this.hasError = true; } } if(this.coDate){ if(this.coDate > mcMaxDisplay && this.ciDate < mcMaxDisplay){ this.errorArray[this.errorArray.length] = moLanguageObjCiCo.calendarErrorArray[1]; this.hasError = true; } if(this.coDate < this.ciDate){ this.errorArray[this.errorArray.length] = moLanguageObjCiCo.calendarErrorArray[3]; this.hasError = true; } if(this.ciDate == this.coDate){ this.errorArray[this.errorArray.length] = moLanguageObjCiCo.calendarErrorArray[4]; this.hasError = true; } } if(pFromContinue){ if(!this.ciDate){ this.errorArray[this.errorArray.length] = moLanguageObjCiCo.calendarErrorArray[5]; this.hasError = true; } else if(!this.coDate){ this.errorArray[this.errorArray.length] = moLanguageObjCiCo.calendarErrorArray[6]; this.hasError = true; } } } multiDisplayCalendar.prototype.setNavigation = function(){ var lvWorkingDate = new Date(this.calStartDate); lvWorkingDate = new Date(lvWorkingDate.setMonth(lvWorkingDate.getMonth() + 1)); var loMaxDisplay = new Date(mcMaxDisplay); var loDisableArray = new Array(false, false); // Prev button if(this.calStartDate.getMonth() == mcToday.getMonth() && this.calStartDate.getFullYear() == mcToday.getFullYear()){ this.calendarPrevious.className = 'ciCocalendarNavigationPrevDisabled'; this.calendarPrevious.href = "javascript:void(0);"; } else{ this.calendarPrevious.className = 'ciCocalendarNavigationPrevActive'; this.calendarPrevious.href = this.calendarPreviousAction; } // next button if(lvWorkingDate.getMonth() == loMaxDisplay.getMonth() && lvWorkingDate.getFullYear() == loMaxDisplay.getFullYear()){ this.calendarNext.className = 'ciCocalendarNavigationNextDisabled'; this.calendarNext.href = "javascript:void(0);"; } else{ this.calendarNext.className = 'ciCocalendarNavigationNextActive'; this.calendarNext.href = this.calendarNextAction; } } multiDisplayCalendar.prototype.renderCalDisplay = function(){ this.renderCalendar(); this.setNavigation(); this.renderTravelDates(); this.renderStayLength(); this.renderErrors(); } multiDisplayCalendar.prototype.formatDateOnImport = function(pDate){ var loDateObj = null; if(pDate != ''){ var lsDateString = pDate; var loDateArray = new Array(); loDateArray = lsDateString.split("-"); loDateObj = new Date(loDateArray[1] + "/" + loDateArray[2] + "/" + new Number(loDateArray[0])); } return loDateObj; } multiDisplayCalendar.prototype.getLengthOfStay = function(){ var lnLengthOfStay = null; if(this.ciDate && this.coDate){ lnLengthOfStay = fnGetDateDifferenceCiCo(this.ciDate,this.coDate); } return lnLengthOfStay; } function fnCloseCalendarCiCo(pCalendarId){ var loCalendarObj = moCalendarManagerCiCo.calArray[pCalendarId]; //loCalendarObj.clearObject(); //loCalendarObj.initializeObject(); loCalendarObj.toggleDisplay(); } // function to select the day, different actions are taken based on the display mode (0-select check in, 1-select checkout, 2-detwermine if new date is Checkin or Checkout) function fnSelectDayCiCo(pCalendarId, pNewDate) { var loCalendarObj = moCalendarManagerCiCo.calArray[pCalendarId]; //alert("pNewDate: " + pNewDate); var loSelectedDate = new Date(pNewDate); var lvMode = loCalendarObj.dateDisplayMode; switch(lvMode) { case 0: loCalendarObj.ciDate = loSelectedDate; loCalendarObj.dateDisplayMode = 1; break; case 1: if(loSelectedDate < loCalendarObj.ciDate){ loCalendarObj.ciDate = loSelectedDate; loCalendarObj.dateDisplayMode = 1; } else{ loCalendarObj.coDate = loSelectedDate; loCalendarObj.dateDisplayMode = 2; } break; case 2: if(loSelectedDate < loCalendarObj.ciDate){ loCalendarObj.ciDate = loSelectedDate; } else if(loSelectedDate > loCalendarObj.coDate){ loCalendarObj.coDate = loSelectedDate; } else{ var loMidPoint = loCalendarObj.selectedLOS / 2; var loDateDifference = fnGetDateDifferenceCiCo(loCalendarObj.ciDate, loSelectedDate); if(loDateDifference >= loMidPoint){ loCalendarObj.coDate = loSelectedDate; } else{ loCalendarObj.ciDate = loSelectedDate; } } loCalendarObj.dateDisplayMode = 2; break; } loCalendarObj.selectedLOS = loCalendarObj.getLengthOfStay(); //alert("loCalendarObj.selectedLOS: " + loCalendarObj.selectedLOS); loCalendarObj.renderCalDisplay(); } function fnGetDateDifferenceCiCo(pCIDay, pCODay){ var loStartDate = new Date(pCIDay); var loEndDate = new Date(pCODay); var lnDayDiff = Math.round((loEndDate.getTime() - loStartDate.getTime()) / (1000 * 60 * 60 * 24)); return Math.abs(lnDayDiff); } // function to change the month. The month buttons pass pDirection to tell the function to move up or down one month and a new calendar is drawn function fnChangeMonthCiCo(pCalendarId,pDirection){ var loCalendarObj = moCalendarManagerCiCo.calArray[pCalendarId]; var loNewStart = new Date(loCalendarObj.calStartDate); var newMonth = loNewStart.getMonth() + pDirection; // safari fix if(newMonth < 0) { loNewStart.setFullYear(loNewStart.getFullYear()-1); newMonth = 11; } loCalendarObj.calStartDate = new Date(loNewStart.setMonth(newMonth)); loCalendarObj.renderCalDisplay(); } // function to select today. Reset day/month/year to today from the constants above and call fnChangeDay to reset the styles function fnResetCalendarCiCo(pCalendarId){ var loCalendarObj = moCalendarManagerCiCo.calArray[pCalendarId]; loCalendarObj.clearObject(); //loCalendarObj.initializeObject(); loCalendarObj.renderCalDisplay(); } function fnGetDisplayDateCiCo(pDateToFormat){ var lsFormatDate = null; if(pDateToFormat){ var loDate = new Date(pDateToFormat); //var lsYear = loDate.getFullYear().toString().substring(2,4); var lsYear = loDate.getFullYear(); var lsMonth = moLanguageObjCiCo.calendarShortMonthArray[loDate.getMonth()] lsFormatDate = loDate.getDate() + ' ' + lsMonth + ' ' + lsYear; } return lsFormatDate; } function fnContinueCiCo(pCalendarId){ var loCalendarObj = moCalendarManagerCiCo.calArray[pCalendarId]; loCalendarObj.renderErrors(true); if(!loCalendarObj.hasError){ // send back info call passed in function, pass the checkin and checkout date objs loCalendarObj.returnFunction(loCalendarObj.ciDate, loCalendarObj.coDate, true); fnCloseCalendarCiCo(loCalendarObj.calendarId); } } function fnFormatForExportCiCo(pDateToFormat){ var loFormatDate = new Date(pDateToFormat); if(!isNaN(loFormatDate)){ var lsDateString = loFormatDate.getFullYear() + '-' + padZero(loFormatDate.getMonth() +1) + '-' + padZero(loFormatDate.getDate()); return lsDateString; } } function padZero(pNumber) { return (pNumber<0 || pNumber>9 ? "" : "0") + pNumber; }