Picker.Date.Range=new Class({Extends:Picker.Date,options:{getStartEndDate:function(a){return a.get("value").split("-").map(function(a){var b=Date.parse(a);return Date.isValid(b)?b:null}).clean()},setStartEndDate:function(a,b){a.set("value",b.map(function(a){return a.format(this.options.format)},this).join(" - "))},footer:!0,columns:3},getInputDate:function(a){var b;if(!a)return;b=a.retrieve("datepicker:value");b&&b.length&&(b=b.map(Date.parse));if(!b||!b.length||b.some(function(a){return!Date.isValid(a)})){b=this.options.getStartEndDate.call(this,a);if(!b.length||!b.every(function(a){return Date.isValid(a)}))b=[this.date]}b.length==1?this.date=this.startDate=this.endDate=b[0]:b.length==2&&(this.date=this.startDate=b[0],this.endDate=b[1])},constructPicker:function(){var a,b,c,d,e;this.parent();a=this.footer,b=this;if(!a)return;c={click:function(){this.focus()},blur:function(){var a=Date.parse(this.get("value"));a.isValid&&(b[(this==d?"start":"end")+"Date"]=a),b.updateRangeSelection()},keydown:function(a){a.key=="enter"&&b.selectRange()}},d=this.startInput=(new Element("input",{events:c})).inject(a);(new Element("span",{text:" - "})).inject(a);e=this.endInput=(new Element("input",{events:c})).inject(a);this.applyButton=(new Element("button.apply",{text:Locale.get("DatePicker.apply_range"),events:{click:b.selectRange.pass([],b)}})).inject(a),this.cancelButton=(new Element("button.cancel",{text:Locale.get("DatePicker.cancel"),events:{click:b.close.pass(!1,b)}})).inject(a)},renderDays:function(){this.parent.apply(this,arguments),this.updateRangeSelection()},select:function(a){this.startDate&&(this.endDate==this.startDate||a>this.endDate)&&a>=this.startDate?this.endDate=a:(this.startDate=a,this.endDate=a),this.updateRangeSelection()},selectRange:function(){var a,b;this.date=this.startDate;a=[this.startDate,this.endDate],b=this.input;return this.options.setStartEndDate.call(this,b,a),b.store("datepicker:value",a.map(function(a){return a.strftime()})).fireEvent("change"),this.fireEvent("select",a,b),this.close(),this},updateRangeSelection:function(){var c,d,e,a=this.startDate,b=this.endDate||a;if(this.dateElements)for(c=this.dateElements.length;c--;){d=this.dateElements[c];d.time>=a&&d.time<=b?d.element.addClass("selected"):d.element.removeClass("selected")}e=a.format(this.options.format);return formattedEnd=b.format(this.options.format),this.startInput.set("value",e),this.endInput.set("value",formattedEnd),this}})