var BezurkDateSelector=Class.create();BezurkDateSelector.prototype={daysOfWeek:['Sun','Mon','Tue','Wed','Thu','Fri','Sat'],months:['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'],monthsOut:16,showDayOfWeek:true,initialize:function(dayElement,monthYearElement,defaultDate,showDayOfWeek,small){this.dayElement=dayElement;this.monthYearElement=monthYearElement;this.date=defaultDate;this.showDayOfWeek=(showDayOfWeek==null)?true:showDayOfWeek;var today=new Date();var dayOptions=this.getDaySelectOptions(this.date.getMonth(),this.date.getFullYear(),this.date.getDate());dayOptions.each(function(opt){dayElement.appendChild(opt);});var monthYearOptions=this.getMonthYearSelectOptions(today,this.monthsOut,this.date.getMonth(),this.date.getFullYear(),small);monthYearOptions.each(function(opt){monthYearElement.appendChild(opt);});Event.observe(monthYearElement,'change',this.updateDay.bindAsEventListener(this),false);},getDayOfWeek:function(date){return this.daysOfWeek[date.getDay()];},getDaySelectOptions:function(month,year,selectedDay){var options=[];var endDay=31;for(var day=1;day<=endDay;day++){var date=new Date();date.setFullYear(year,month,day);if(date.getDate()!=day||date.getMonth()!=month||date.getFullYear()!=year){break;}
var option=document.createElement('option');var optionText='';if(this.showDayOfWeek){optionText=document.createTextNode(day+' '+this.getDayOfWeek(date));}else{optionText=document.createTextNode(day);}
option.appendChild(optionText);option.setAttribute('value',day);if(selectedDay&&selectedDay==day){option.setAttribute('selected','selected');}
options.push(option);}
return options;},getMonthYearSelectOptions:function(startDate,monthsOut,selectedMonth,selectedYear,small){var options=[];var startMonth=startDate.getMonth();var startYear=startDate.getFullYear();for(var i=0;i<monthsOut;i++){var month=(startMonth+i)%12;var year=startYear+((startMonth+i)/12|0);var canonicalMonth=this.months[month];var option=document.createElement('option');var optionText=(typeof(small)!='undefined'&&small)?document.createTextNode(canonicalMonth+' '+(''+year).substring(2,4)):document.createTextNode(canonicalMonth+' '+year)
option.appendChild(optionText);option.setAttribute('value',month+','+year);if(!((typeof(selectedMonth)=='undefined')||(typeof(selectedYear)=='undefined'))){if(selectedMonth==month&&selectedYear==year){option.setAttribute('selected','selected');}}
options.push(option);}
return options;},updateDay:function(){var month=this.monthYearElement.value.split(',')[0];var year=this.monthYearElement.value.split(',')[1];var previousDay=this.dayElement.value;this.dayElement.innerHTML='';var dayOptions=this.getDaySelectOptions(month,year);dayOptions.each(function(opt){this.dayElement.appendChild(opt);}.bindAsEventListener(this));this.dayElement.value=previousDay;}};