var DatePicker=new Class({initialize:function(b){this.dayChars=1;this.dayNames=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];this.daysInMonth=[31,28,31,30,31,30,31,31,30,31,30,31];this.format="dd.mm.yyyy";this.monthNames=["January","February","March","April","May","June","July","August","September","October","November","December"];this.startDay=1;this.yearOrder="desc";this.yearRange=100;this.yearStart=(new Date().getFullYear())-5;if(b.value!=""){var a=b.value.split(".");b.then=new Date(a[2].toInt(),a[1].toInt()-1,a[0].toInt());b.today=b.then}else{b.then=b.today=new Date()}b.oldYear=b.year=b.then.getFullYear();b.oldMonth=b.month=b.then.getMonth();b.oldDay=b.then.getDate();b.nowYear=b.oldYear;b.nowMonth=b.oldMonth;b.nowDay=b.oldDay;if(b.alt){options=Json.evaluate(b.alt)}else{options=[]}b.options={monthNames:(options.monthNames&&options.monthNames.length==12?options.monthNames:this.monthNames)||this.monthNames,daysInMonth:(options.daysInMonth&&options.daysInMonth.length==12?options.daysInMonth:this.daysInMonth)||this.daysInMonth,dayNames:(options.dayNames&&options.dayNames.length==7?options.dayNames:this.dayNames)||this.dayNames,startDay:options.startDay||this.startDay,dayChars:options.dayChars||this.dayChars,format:options.format||this.format,yearStart:options.yearStart||this.yearStart,yearRange:options.yearRange||this.yearRange,yearOrder:options.yearOrder||this.yearOrder};b.setProperties({id:b.getProperty("name"),readonly:true});b.container=false;b.calendar=false;b.interval=null;b.active=false;b.onclick=b.onfocus=this.create.pass(b,this)},create:function(f){if(f.calendar){return false}if(window.ie6){$$("select").addClass("dp_hide")}f.container=new Element("div",{"class":"dp_container"}).injectBefore(f);f.container.onmouseover=f.onmouseover=function(){$clear(f.interval)};f.container.onmouseout=f.onmouseout=function(){f.interval=setInterval(function(){if(!f.active){this.remove(f)}}.bind(this),500)}.bind(this);f.calendar=new Element("div",{"class":"dp_cal"}).injectInside(f.container);var c=new Date(f.year,f.month,f.oldDay);if(f.month&&f.year){c.setFullYear(f.year,f.month,1)}else{f.month=c.getMonth();f.year=c.getFullYear();c.setDate(1)}f.year%4==0?f.options.daysInMonth[1]=29:f.options.daysInMonth[1]=28;var b=(1-(7+c.getDay()-f.options.startDay)%7);monthSel=new Element("select",{id:f.id+"_monthSelect"});for(var a=0;a<f.options.monthNames.length;a++){monthSel.options[a]=new Option(f.options.monthNames[a],a);if(f.month==a){monthSel.options[a].selected=true}}yearSel=new Element("select",{id:f.id+"_yearSelect"});d=0;f.options.yearStart?f.options.yearStart:f.options.yearStart=c.getFullYear();if(f.options.yearOrder=="desc"){for(var e=f.options.yearStart;e>(f.options.yearStart-f.options.yearRange-1);e--){yearSel.options[d]=new Option(e,e);if(f.year==e){yearSel.options[d].selected=true}d++}}else{for(var e=f.options.yearStart;e<(f.options.yearStart+f.options.yearRange+1);e++){yearSel.options[d]=new Option(e,e);if(f.year==e){yearSel.options[d].selected=true}d++}}calTable=new Element("table");calTableThead=new Element("thead");calSelRow=new Element("tr");calSelCell=new Element("th",{colspan:"7"});monthSel.injectInside(calSelCell);yearSel.injectInside(calSelCell);calSelCell.injectInside(calSelRow);calSelRow.injectInside(calTableThead);calTableTbody=new Element("tbody");calDayNameRow=new Element("tr");for(var d=0;d<f.options.dayNames.length;d++){calDayNameCell=new Element("th");calDayNameCell.appendText(f.options.dayNames[(f.options.startDay+d)%7].substr(0,f.options.dayChars));calDayNameCell.injectInside(calDayNameRow)}calDayNameRow.injectInside(calTableTbody);while(b<=f.options.daysInMonth[f.month]){calDayRow=new Element("tr");for(d=0;d<7;d++){if((b<=f.options.daysInMonth[f.month])&&(b>0)){calDayCell=new Element("td",{"class":f.id+"_calDay",axis:f.year+"|"+(parseInt(f.month)+1)+"|"+b}).appendText(b).injectInside(calDayRow)}else{calDayCell=new Element("td",{"class":"dp_empty"});calDayCell.appendText("_");calDayCell.injectInside(calDayRow)}if((b==f.oldDay)&&(f.month==f.oldMonth)&&(f.year==f.oldYear)){calDayCell.addClass("dp_selected")}if((b==f.nowDay)&&(f.month==f.nowMonth)&&(f.year==f.nowYear)){calDayCell.addClass("dp_today")}b++}calDayRow.injectInside(calTableTbody)}calTableThead.injectInside(calTable);calTableTbody.injectInside(calTable);calTable.injectInside(f.calendar);$$("td."+f.id+"_calDay").each(function(g){g.onmouseover=function(){g.addClass("dp_roll")}.bind(this)}.bind(this));$$("td."+f.id+"_calDay").each(function(g){g.onmouseout=function(){g.removeClass("dp_roll")}.bind(this)}.bind(this));$$("td."+f.id+"_calDay").each(function(g){g.onclick=function(){ds=g.axis.split("|");f.value=this.formatValue(f,ds[0],ds[1],ds[2]);this.remove(f)}.bind(this)}.bind(this));monthSel.onfocus=function(){f.active=true};monthSel.onchange=function(){f.month=monthSel.value;f.year=yearSel.value;this.remove(f);this.create(f)}.bind(this);yearSel.onfocus=function(){f.active=true};yearSel.onchange=function(){f.month=monthSel.value;f.year=yearSel.value;this.remove(f);this.create(f)}.bind(this)},formatValue:function(e,c,d,b){var a="";if(b<10){b="0"+b}if(d<10){d="0"+d}a=e.options.format.replace(/dd/i,b).replace(/mm/i,d).replace(/yyyy/i,c);e.month=e.oldMonth=""+(d-1)+"";e.year=e.oldYear=c;e.oldDay=b;return a},remove:function(a){$clear(a.interval);a.active=false;if(window.opera){a.container.empty()}else{if(a.container){a.container.destroy()}}a.calendar=false;a.container=false;$$("select.dp_hide").removeClass("dp_hide")}});