var DatePicker=new Class({initialize:function(A){this.dayChars=1;this.dayNames=["Lundi","Mardi","Mercredi","Jeudi","Vendredi","Samedi","Dimanche"];this.daysInMonth=[31,28,31,30,31,30,31,31,30,31,30,31];this.format="dd/mm/yyyy";this.monthNames=["Janvier","Février","Mars","Avril","Mai","Juin","Juillet","Août","Septembre","Octobre","Novembre","Décembre"];this.startDay=1;this.yearOrder="asc";this.yearRange=10;this.yearStart=(new Date().getFullYear());if(A.value!=A.get("alt")&&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();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.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(Browser.Engine.trident4){$$("select").addClass("dp_hide")}F.container=new Element("div",{"class":"dp_container"}).inject(F,"before");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"}).inject(F.container,"inside");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.inject(calSelCell,"inside");yearSel.inject(calSelCell,"inside");calSelCell.inject(calSelRow,"inside");calSelRow.inject(calTableThead,"inside");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.inject(calDayNameRow,"inside")}calDayNameRow.inject(calTableTbody,"inside");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).inject(calDayRow,"inside")}else{calDayCell=new Element("td",{"class":"dp_empty"}).appendText(".").inject(calDayRow,"inside")}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.inject(calTableTbody,"inside")}calTableThead.inject(calTable,"inside");calTableTbody.inject(calTable,"inside");calTable.inject(F.calendar,"inside");$$("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]);F.setStyle("color","");$("planning").set("checked","checked");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")}});window.addEvent("domready",function(){$$("input.date_picker").each(function(A){new DatePicker(A)})})
