Object.extend(Date.prototype,{tomorrow:function(){var date=new Date();if(date.getDate()=="31"){date=new Date(1/1)}date.setMonth(this.getMonth());date.setYear(this.getFullYear());date.setDate(this.getDate()+1);return date},format:function(dateTimeFormatString){var dateTimeFormat=new Template(dateTimeFormatString?dateTimeFormatString:"#{date}/#{month}/#{year}");var yearPart=padDatePart(this.getFullYear()%100);var datePart=padDatePart(this.getDate());var monthPart=padDatePart(this.getMonth()+1);return dateTimeFormat.evaluate({date:datePart,month:monthPart,year:yearPart})}});var DateSelector=Class.create({_returnDate:function(){return this.options.returnDateTextField},_outwardDate:function(){return this.options.outwardDateTextField},_returnHour:function(){return this.options.returnHourDropDown},_returnMinute:function(){return this.options.returnMinuteDropDown},initialize:function(options){this.options=options;Object.extend(this._outwardDate(),{today:function(){this.setValue(new Date().format())},tomorrow:function(){this.setValue(new Date().tomorrow().format())},nextDay:function(){var dateShown=this._dateShown();return dateShown?dateShown.tomorrow():null},selectedDate:function(){return this._dateShown()},_dateShown:function(){return this._unformattedDate(this.getValue())},_unformattedDate:function(currentDate){var array=currentDate.split("/");if(padDatePart(array[0])!="31"){var date=new Date()}else{var date=new Date(1/1)}date.setDate(padDatePart(array[0]));date.setMonth(padDatePart(array[1])-1);date.setYear(padDatePart(array[2]));if(!this._isValidDate(date)){return null}return date},_isValidDate:function(date){return date.toString()!="Invalid Date"&&date.toString()!="NaN"}});Object.extend(this._returnDate(),{sameDay:function(){var outwardDate=this.outwardDate().selectedDate();this.removeClassName("textFieldBlur");this.setValue(outwardDate?outwardDate.format():this.getValue())},nextDay:function(){var nextDay=this.outwardDate().nextDay();this.removeClassName("textFieldBlur");this.setValue(nextDay?nextDay.format():this.getValue())},outwardDate:function(){return $("outwardDate")}});Object.extend(this._returnHour(),{setDefault:function(){if(this.getValue()!=""){return}this.setValue("9")}});Object.extend(this._returnMinute(),{setDefault:function(){if(this.getValue()!=""){return}this.setValue("0")}})}});document.observe("dom:loaded",function(){if($("returnDate")){$("returnDate").setValue=$("returnDate").setValue.wrap(function(proceed,value){$("ReturnHour").setDefault();$("ReturnMinute").setDefault();return proceed(value)})}$("AdultsTravelling")&&$("AdultsTravelling").blur()});
