﻿var DatePicker=new Class({initialize:function(a){this.dayChars=2;this.dayNames=["Sonntag","Montag","Dienstag","Mittwoch","Donnerstag","Freitag","Samstag"];this.daysInMonth=[31,28,31,30,31,30,31,31,30,31,30,31];this.format="dd.mm.yyyy";this.monthNames=["Januar","Februar","März","April","Mai","Juni","July","August","September","Oktober","November","Dezember"];this.startDay=1;this.yearOrder="asc";this.yearRange=4;this.yearStart=(new Date().getFullYear());if(a.value!=""){a.then=new Date(a.value);a.today=new Date()}else{a.then=a.today=new Date()}a.oldYear=a.year=a.then.getFullYear();a.oldMonth=a.month=a.then.getMonth();a.oldDay=a.then.getDate();a.nowYear=a.today.getFullYear();a.nowMonth=a.today.getMonth();a.nowDay=a.today.getDate();if(a.alt){options=Json.evaluate(a.alt)}else{options=[]}a.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};a.setProperties({id:a.getProperty("name")});a.container=false;a.calendar=false;a.interval=null;a.active=false;a.onclick=a.onfocus=this.create.pass(a,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();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"}).appendText(" ").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.remove()}}a.calendar=false;a.container=false;$$("select.dp_hide").removeClass("dp_hide")}});
