
DatePicker=function(element){this._element=element;this._abbreviatedMonthNames=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];this._longMonthNames=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];this._shortestDayNames=["Mon","Tue","Wed","Thu","Fri","Sat","Sun"];this._cssClass="ajax__calendar";this._buttonID=null;this.d=new Date();this._minDate=typeof minDate=="undefined"?ParseEuroShortDate(this.d.getDate()+"/"+(this.d.getMonth()+1)+"/"+this.d.getFullYear()):ParseEuroShortDate(minDate);this.d1=this.addMonths(new Date(),19);this._maxDate=typeof maxDate=="undefined"?ParseEuroShortDate(this.d1.getDate()+"/"+(this.d1.getMonth()+1)+"/"+this.d1.getFullYear()):ParseEuroShortDate(maxDate);this._selectedDate=null;this._visibleDate=null;this._todaysDate=null;this._firstDayOfWeek=1;this._popupDiv=null;this._prevArrow=null;this._prevArrowImage=null;this._nextArrow=null;this._nextArrowImage=null;this._title=null;this._today=null;this._daysRow=null;this._monthsRow=null;this._yearsRow=null;this._daysBody=null;this._monthsBody=null;this._yearsBody=null;this._button=null;this._mode="days";this._selectedDateChanging=false;this._isIEen=false;this._isAnimating=false;this._width=170;this._height=139;this._modes={"days":null,"months":null,"years":null};this._modeOrder={"days":0,"months":1,"years":2};this._blur=new DeferredOperation(Browser.isSf?1000:1,this,this._onblur);this._focus=new DeferredOperation(Browser.isSf?1000:1,this,this._onfocus);this._button$delegates={click:createDelegate(this,this._button_onclick)};this._element$delegates={focus:createDelegate(this,this._element_onfocus),focusout:createDelegate(this,this._element_onblur),blur:createDelegate(this,this._element_onblur),change:createDelegate(this,this._element_onchange)};this._popup$delegates={activate:createDelegate(this,this._popup_onfocus),focus:createDelegate(this,this._popup_onfocus),dragstart:createDelegate(this,this._popup_ondragstart),select:createDelegate(this,this._popup_onselect)};this._cell$delegates={mouseover:createDelegate(this,this._cell_onmouseover),mouseout:createDelegate(this,this._cell_onmouseout),mousedown:createDelegate(this,this._cell_onclick)};addDelegates(this._element,this._element$delegates);if(this._button)addDelegates(this._button,this._button$delegates);var value=this.get_selectedDate();if(value)this.set_selectedDate(value);};DatePicker.prototype={get_selectedDate:function(){if(this._selectedDate===null){var value=this._element.value;if(value)this._selectedDate=ParseEuroShortDate(value);}return this._selectedDate;},set_selectedDate:function(value){var elt=this._element;if(this._selectedDate!=value){this._selectedDate=value;this._selectedDateChanging=true;var text="";if(value)text=dateFormat2(value);if(text!=elt.value){elt.value=text;this._fireChanged();}this._selectedDateChanging=false;this._performLayout();}},get_todaysDate:function(){if(this._todaysDate!==null)return this._todaysDate;return new Date().getDateOnly();},dispose:function(){this._modes=null;this._modeOrder=null;if(this._container){this._container.parentNode.removeChild(this._container);this._container=null;}if(this._popupDiv){removeDelegates(this._popupDiv,this._popup$delegates);this._popupDiv=null;}if(this._prevArrow){removeDelegates(this._prevArrow,this._cell$delegates);this._prevArrow=null;}if(this._prevArrowImage){removeDelegates(this._prevArrowImage,this._cell$delegates);this._prevArrowImage=null;}if(this._nextArrow){removeDelegates(this._nextArrow,this._cell$delegates);this._nextArrow=null;}if(this._nextArrowImage){removeDelegates(this._nextArrowImage,this._cell$delegates);this._nextArrowImage=null;}if(this._title){removeDelegates(this._title,this._cell$delegates);this._title=null;}if(this._today){removeDelegates(this._today,this._cell$delegates);this._today=null;}var i,j,row;if(this._daysRow){for(i=0;i<this._daysBody.rows.length;i++){row=this._daysBody.rows[i];for(j=0;j<row.cells.length;j++)removeDelegates(row.cells[j].firstChild,this._cell$delegates);}this._daysRow=null;}if(this._monthsRow){for(i=0;i<this._monthsBody.rows.length;i++){row=this._monthsBody.rows[i];for(j=0;j<row.cells.length;j++)removeDelegates(row.cells[j].firstChild,this._cell$delegates);}this._monthsRow=null;}if(this._yearsRow){for(i=0;i<this._yearsBody.rows.length;i++){row=this._yearsBody.rows[i];for(j=0;j<row.cells.length;j++)removeDelegates(row.cells[j].firstChild,this._cell$delegates);}this._yearsRow=null;}if(this._button){removeDelegates(this._button,this._button$delegates);this._button=null;}var elt=this._element;removeDelegates(elt,this._element$delegates);},getViewportScrollX:function(){if(document.documentElement&&document.documentElement.scrollLeft){return document.documentElement.scrollLeft;}if(document.body&&document.body.scrollLeft){return document.body.scrollLeft;}if(window.pageXOffset){return window.pageXOffset;}if(window.scrollX){return window.scrollX;}return 0;},addMonths:function(date,months){date.setMonth(date.getMonth()+months);return date;},getViewportScrollY:function(){if(document.documentElement&&document.documentElement.scrollTop)return document.documentElement.scrollTop;if(document.body&&document.body.scrollTop)return document.body.scrollTop;if(window.pageYOffset)return window.pageYOffset;if(window.scrollY)return window.scrollY;return 0;},show:function(){if(!this._container){this._buildCalendar();this._buildHeader();this._buildBody();this._buildFooter();}if(!this._isIEen){this._isIEen=true;this._switchMonth(null);var rect=this._element.getClientRects()[0];$(this._popupDiv).pos(rect.left+this.getViewportScrollX(),rect.top+this._element.offsetHeight+this.getViewportScrollY()).show();}},hide:function(){if(this._isIEen){$(this._popupDiv).hide();this._switchMode("days",true);this._isIEen=false;}},_buildCalendar:function(){this._container=$("<div/>").appendTo(document.body).addClass(this._cssClass).get(0);this._popupDiv=$("<div/>").appendTo(this._container).addClass("ajax__calendar_container").hide().attr("tabindex","0").get(0);this._popupDiv.datePicker=this;addDelegates(this._popupDiv,this._popup$delegates);},_buildHeader:function(){this._header=$("<div/>").appendTo(this._popupDiv).addClass("ajax__calendar_header").get(0);var prevArrowWrapper=$("<div/>").appendTo(this._header).get(0);this._prevArrow=$("<div/>").appendTo(prevArrowWrapper).addClass("ajax__calendar_prev").get(0);this._prevArrow.mode="prev";addDelegates(this._prevArrow,this._cell$delegates);var nextArrowWrapper=$("<div/>").appendTo(this._header).get(0);this._nextArrow=$("<div/>").appendTo(nextArrowWrapper).addClass("ajax__calendar_next").get(0);this._nextArrow.mode="next";addDelegates(this._nextArrow,this._cell$delegates);var titleWrapper=$("<div/>").appendTo(this._header).get(0);this._title=createElement(titleWrapper,"div","ajax__calendar_title");this._title.mode="title";addDelegates(this._title,this._cell$delegates);},_buildBody:function(){this._body=createElement(this._popupDiv,"div","ajax__calendar_body");this._buildDays();this._buildMonths();this._buildYears();},_buildFooter:function(){var todayWrapper=createElement(this._popupDiv,"div");this._today=createElement(todayWrapper,"div","ajax__calendar_footer ajax__calendar_today");this._today.mode="today";addDelegates(this._today,this._cell$delegates);},_buildDays:function(){this._days=createElement(this._body,"div","ajax__calendar_days");this._modes["days"]=this._days;this._daysTable=createElement(this._days,"table");this._daysTable.cellPadding=0;this._daysTable.cellSpacing=0;this._daysTable.border=0;this._daysTable.style.margin="auto";this._daysTableHeader=createElement(this._daysTable,"thead");this._daysTableHeaderRow=createElement(this._daysTableHeader,"tr");this._daysBody=createElement(this._daysTable,"tbody");var i,dayCell;for(i=0;i<7;i++){dayCell=createElement(this._daysTableHeaderRow,"td");createElement(dayCell,"div","ajax__calendar_dayname");}for(i=0;i<6;i++){var daysRow=createElement(this._daysBody,"tr");for(var j=0;j<7;j++){dayCell=createElement(daysRow,"td");var dayDiv=createElement(dayCell,"div","ajax__calendar_day");dayDiv.mode="day";dayDiv.innerHTML="&nbsp;";addDelegates(dayDiv,this._cell$delegates);}}},_buildMonths:function(){this._months=createElement(this._body,"div","ajax__calendar_months");this._months.style.display="none";this._modes["months"]=this._months;this._monthsTable=createElement(this._months,"table");this._monthsTable.cellPadding=0;this._monthsTable.cellSpacing=0;this._monthsTable.border=0;this._monthsTable.style.margin="auto";this._monthsBody=createElement(this._monthsTable,"tbody");for(var i=0;i<3;i++){var monthsRow=createElement(this._monthsBody,"tr");for(var j=0;j<4;j++){var monthCell=createElement(monthsRow,"td");var monthDiv=createElement(monthCell,"div","ajax__calendar_month");monthDiv.mode="month";monthDiv.month=(i*4)+j;monthDiv.innerHTML="<br />"+this._abbreviatedMonthNames[(i*4)+j];addDelegates(monthDiv,this._cell$delegates);}}},_buildYears:function(){this._years=createElement(this._body,"div","ajax__calendar_years");this._years.style.display="none";this._modes["years"]=this._years;this._yearsTable=createElement(this._years,"table");this._yearsTable.cellPadding=0;this._yearsTable.cellSpacing=0;this._yearsTable.border=0;this._yearsTable.style.margin="auto";this._yearsBody=createElement(this._yearsTable,"tbody");for(var i=0;i<1;i++){var yearsRow=createElement(this._yearsBody,"tr");for(var j=0;j<3;j++){var yearCell=createElement(yearsRow,"td");var yearDiv=createElement(yearCell,"div","ajax__calendar_year");yearDiv.mode="year";yearDiv.year=((i*3)+j)-1;addDelegates(yearDiv,this._cell$delegates);}}},_performLayout:function(){var elt=this._element;var selectedDate=this.get_selectedDate();var visibleDate=this._getEffectiveVisibleDate();var todaysDate=this.get_todaysDate();if((selectedDate>this._maxDate||selectedDate<this._minDate)&&selectedDate){this._element.value="";alert("Arrival date is incorrect");this._selectedDate=this._minDate;return;}var i,j,row,cell,dayCell;switch(this._mode){case"days":var firstDayOfWeek=this._firstDayOfWeek;var daysToBacktrack=visibleDate.getDay()-firstDayOfWeek;if(daysToBacktrack<=0){daysToBacktrack+=7;}var startDate=new Date(visibleDate.getFullYear(),visibleDate.getMonth(),visibleDate.getDate()-daysToBacktrack);var currentDate=startDate;for(i=0;i<7;i++){dayCell=this._daysTableHeaderRow.cells[i].firstChild;if(dayCell.firstChild)dayCell.removeChild(dayCell.firstChild);dayCell.appendChild(document.createTextNode(this._shortestDayNames[(i+firstDayOfWeek+6)%7]));}for(var week=0;week<6;week++){var weekRow=this._daysBody.rows[week];for(var dayOfWeek=0;dayOfWeek<7;dayOfWeek++){dayCell=weekRow.cells[dayOfWeek].firstChild;if(dayCell.firstChild)dayCell.removeChild(dayCell.firstChild);dayCell.appendChild(document.createTextNode(currentDate.getDate()));dayCell.title=currentDate.getDay()-1>=0?this._shortestDayNames[currentDate.getDay()-1]:this._shortestDayNames[6];dayCell.date=currentDate;if(currentDate<this._minDate||currentDate>this._maxDate){removeCssClasses(dayCell.parentNode,["ajax__calendar_other","ajax__calendar_active"]);addCssClass(dayCell.parentNode,["ajax__calendar_unable"]);;}else{removeCssClasses(dayCell.parentNode,["ajax__calendar_unable","ajax__calendar_active","ajax__calendar_other"]);addCssClass(dayCell.parentNode,this._getCssClass(dayCell.date,'d'));}if(typeof isBooked!="undefined"){if(isBooked(currentDate.getFullYear(),currentDate.getMonth()+1,currentDate.getDate()))addCssClass(dayCell.parentNode,'bookedDate');else
removeCssClass(dayCell.parentNode,'bookedDate');}currentDate=new Date(currentDate.getFullYear(),currentDate.getMonth(),currentDate.getDate()+1);}}this._prevArrow.date=new Date(visibleDate.getFullYear(),visibleDate.getMonth()-1,1);this._nextArrow.date=new Date(visibleDate.getFullYear(),visibleDate.getMonth()+1,1);if(this._title.firstChild)this._title.removeChild(this._title.firstChild);this._title.appendChild(document.createTextNode(this._longMonthNames[visibleDate.getMonth()]+", "+visibleDate.getFullYear()));this._title.date=visibleDate;break;case"months":for(i=0;i<this._monthsBody.rows.length;i++){row=this._monthsBody.rows[i];for(j=0;j<row.cells.length;j++){cell=row.cells[j].firstChild;cell.date=new Date(visibleDate.getFullYear(),cell.month,1);if((cell.date.getYear()==this._minDate.getYear()&&cell.date.getMonth()<this._minDate.getMonth())||(cell.date.getYear()==this._maxDate.getYear()&&cell.date.getMonth()>this._maxDate.getMonth())){removeCssClasses(cell.parentNode,["ajax__calendar_active","ajax__calendar_other"]);addCssClass(cell.parentNode,["ajax__calendar_unable"]);;}else{removeCssClasses(cell.parentNode,["ajax__calendar_unable","ajax__calendar_active"]);typeof this._getCssClass(cell.date,'M')[0]=="undefined"?addCssClass(cell.parentNode,["ajax__calendar_other"]):addCssClass(cell.parentNode,this._getCssClass(cell.date,'M'));addCssClass(cell,["ajax__calendar_month"]);}}}if(this._title.firstChild)this._title.removeChild(this._title.firstChild);this._title.appendChild(document.createTextNode(visibleDate.getFullYear()));this._title.date=visibleDate;this._prevArrow.date=new Date(visibleDate.getFullYear()-1,0,1);this._nextArrow.date=new Date(visibleDate.getFullYear()+1,0,1);break;case"years":var minYear=(Math.floor(visibleDate.getFullYear()/10)*10);for(i=0;i<this._yearsBody.rows.length;i++){row=this._yearsBody.rows[i];for(j=0;j<row.cells.length;j++){cell=row.cells[j].firstChild;if(cell.firstChild)cell.removeChild(cell.lastChild);else
cell.appendChild(document.createElement("br"));cell.date=new Date(minYear+cell.year+1,0,1);cell.appendChild(document.createTextNode(minYear+cell.year+1));if(cell.date.getFullYear()<this._minDate.getFullYear()||cell.date.getFullYear()>this._maxDate.getFullYear())cell.style.display="none";removeCssClasses(cell.parentNode,["ajax__calendar_other","ajax__calendar_active"]);addCssClass(cell.parentNode,this._getCssClass(cell.date,'y'));}}if(this._title.firstChild)this._title.removeChild(this._title.firstChild);this._title.appendChild(document.createTextNode(minYear.toString()+"-"+(this._maxDate.getFullYear()).toString()));this._title.date=visibleDate;this._prevArrow.date=new Date(minYear-10,0,1);this._nextArrow.date=new Date(minYear+10,0,1);break;}if(this._today.firstChild)this._today.removeChild(this._today.firstChild);this._today.appendChild(document.createTextNode("Today: "+this._longMonthNames[todaysDate.getMonth()]+" "+todaysDate.getDate()+", "+todaysDate.getFullYear()));this._today.date=todaysDate;},_fireChanged:function(){var elt=this._element;if(document.createEventObject)elt.fireEvent("onchange");else if(document.createEvent){var e=document.createEvent("HTMLEvents");e.initEvent("change",true,true);elt.dispatchEvent(e);}},_switchMonth:function(date){this._visibleDate=date;this._performLayout();},_switchMode:function(mode){if(this._mode!=mode){var moveDown=this._modeOrder[this._mode]<this._modeOrder[mode];var oldElement=this._modes[this._mode];var newElement=this._modes[mode];this._mode=mode;$(oldElement).hide();this._performLayout();$(newElement).show();$(newElement).pos(0,0);}},_isSelected:function(date,part){var value=this.get_selectedDate();if(!value){return false;}switch(part){case'd':if(date.getDate()!=value.getDate()){return false;}case'M':if(date.getMonth()!=value.getMonth()){return false;}case'y':if(date.getFullYear()!=value.getFullYear()){return false;}break;}return true;},_isOther:function(date,part){var value=this._getEffectiveVisibleDate();switch(part){case'd':return(date.getFullYear()!=value.getFullYear()||date.getMonth()!=value.getMonth());case'M':return false;case'y':var minYear=(Math.floor(value.getFullYear()/10)*10);return date.getFullYear()<minYear||(minYear+10)<=date.getFullYear();}return false;},_getCssClass:function(date,part){return this._isSelected(date,part)?"ajax__calendar_active":(this._isOther(date,part)?"ajax__calendar_other":"");},_getEffectiveVisibleDate:function(){var value=this._visibleDate;if(value===null)value=this.get_selectedDate();if(value===null)value=this.get_todaysDate();return new Date(value.getFullYear(),value.getMonth(),1);},_onblur:function(){this._focus.cancel();this.hide();},_onfocus:function(){this._blur.cancel();this._element.focus();},_element_onfocus:function(e){if(!this._button){this._focus.cancel();this._blur.cancel();this.show();}},_element_onblur:function(e){if((e.type=='blur'&&!Browser.isIE)||(e.type=='focusout'&&Browser.isIE)){if(!this._button){this._focus.cancel();this._blur.post();}}},_element_onchange:function(e){if(!this._selectedDateChanging){var elt=this._element;this._selectedDate=ParseEuroShortDate(elt.value);this._switchMonth(this._selectedDate);}},_popup_onfocus:function(e){if((e.type=='focus'&&!Browser.isIE)||(e.type=='activate'&&Browser.isIE)||Browser.isSf||Browser.isOp){if(!this._button){this._blur.cancel();this._focus.post();}}},_popup_ondragstart:function(e){e.stopPropagation();e.preventDefault();},_popup_onselect:function(e){e.stopPropagation();e.preventDefault();},_cell_onmouseover:function(e){if(Browser.isSf){for(var i=0;i<this._daysBody.rows.length;i++){var row=this._daysBody.rows[i];for(var j=0;j<row.cells.length;j++)removeCssClass(row.cells[j].firstChild.parentNode,"ajax__calendar_hover");}}var target=e.target?e.target:e.srcElement;if(!hasCssClass(target.parentNode,'bookedDate'))addCssClass(target.parentNode,"ajax__calendar_hover");if(e.stopPropagation)e.stopPropagation();return false;},_cell_onmouseout:function(e){var target=e.target?e.target:e.srcElement;removeCssClass(target.parentNode,"ajax__calendar_hover");if(e.stopPropagation)e.stopPropagation();return false;},_cell_onclick:function(e){if(Browser.isSf||Browser.isOp)this._popup_onfocus(e);var target=e.target?e.target:e.srcElement;var visibleDate=this._getEffectiveVisibleDate();var isTargetDateInTheDateRange=target.date>=this._minDate&&target.date<=this._maxDate;var isTargetMonthValid=(target.date.getMonth()>=this._minDate.getMonth()&&target.date.getYear()==this._minDate.getYear()||target.date.getYear()>this._minDate.getYear());var isTargetYearValid=target.date.getYear()<=this._maxDate.getYear()&&target.date.getYear()>=this._minDate.getYear();var visibleDate=this._getEffectiveVisibleDate();removeCssClass(target.parentNode,"ajax__calendar_hover");switch(target.mode){case"prev":case"next":if(isTargetMonthValid&&isTargetYearValid&&target.date<=this._maxDate){this._switchMonth(target.date);break;}else
return;case"title":switch(this._mode){case"days":this._switchMode("months");break;case"months":this._switchMode("years");break;}break;case"month":if(isTargetMonthValid&&target.date<=this._maxDate){if(target.month!=visibleDate.getMonth())this._visibleDate=target.date;this._switchMode("days");break;}else
return;case"year":if(isTargetYearValid){if(target.date.getFullYear()!=visibleDate.getFullYear())this._visibleDate=target.date;this._switchMode("months");break;}else
return;case"day":if(isTargetDateInTheDateRange){if(hasCssClass(target.parentNode,'bookedDate'))break;this.set_selectedDate(target.date);this._switchMonth(target.date);$(this._element).trigger("changed");this.hide();}else
return;break;case"today":this.set_selectedDate(target.date);this._switchMonth(target.date);this.hide();break;}if(e.stopPropagation)e.stopPropagation();if(e.preventDefault)e.preventDefault();return false;},_button_onclick:function(e){e.preventDefault();e.stopPropagation();if(!this._isIEen)this.show();else
this.hide();}};$(function(){$(".dateEntry").each(function(){new DatePicker(this);});});function hidePickers(){$(".ajax__calendar_container").each(function(){this.datePicker.hide();});}