function PopUpCal(){this._nextId=0;this._inst=[];this._curInst=null;this._disabledInputs=[];this._popUpShowing=false;this._inDialog=false;this.regional=[];this.regional[""]={clearText:"Clear",closeText:"Close",prevText:"&lt;Prev",nextText:"Next&gt;",currentText:"Today",dayNames:["S","M","T","W","T","F","S"],monthNames:["JANUARY","FEBRUARY","MARCH","APRIL","MAY","JUNE","JULY","AUGUST","SEPTEMBER","OCTOBER","NOVEMBER","DECEMBER"],dateFormat:"DMY/"};this._defaults={autoPopUp:"focus",appendText:"",buttonText:"...",buttonImage:"",buttonImageOnly:false,closeAtTop:true,hideIfNoPrevNext:false,changeMonth:true,changeYear:true,yearRange:"-10:+10",firstDay:0,changeFirstDay:true,showOtherMonths:false,minDate:null,maxDate:null,speed:"medium",customDate:null,fieldSettings:null,onSelect:null};$.extend(this._defaults,this.regional[""]);this._calendarDiv=$('<div id="calendar_div"></div>');$(document.body).append(this._calendarDiv)}$.extend(PopUpCal.prototype,{_register:function(A){var B=this._nextId++;this._inst[B]=A;return B},_getInst:function(A){return this._inst[A]||A},setDefaults:function(A){$.extend(this._defaults,A||{})},_doKeyDown:function(B){var A=popUpCal._getInst(this._calId);if(popUpCal._popUpShowing){switch(B.keyCode){case 9:popUpCal.hideCalendar(A,"");break;case 13:popUpCal._selectDate(A);break;case 27:popUpCal.hideCalendar(A,A._get("speed"));break;case 33:popUpCal._adjustDate(A,-1,(B.ctrlKey?"Y":"M"));break;case 34:popUpCal._adjustDate(A,+1,(B.ctrlKey?"Y":"M"));break;case 35:if(B.ctrlKey){popUpCal._clearDate(A)}break;case 36:if(B.ctrlKey){popUpCal._gotoToday(A)}break;case 37:if(B.ctrlKey){popUpCal._adjustDate(A,-1,"D")}break;case 38:if(B.ctrlKey){popUpCal._adjustDate(A,-7,"D")}break;case 39:if(B.ctrlKey){popUpCal._adjustDate(A,+1,"D")}break;case 40:if(B.ctrlKey){popUpCal._adjustDate(A,+7,"D")}break}}else{if(B.keyCode==36&&B.ctrlKey){popUpCal.showFor(this)}}},_doKeyPress:function(C){var B=popUpCal._getInst(this._calId);var A=String.fromCharCode(C.charCode==undefined?C.keyCode:C.charCode);return(A<" "||A==B._get("dateFormat").charAt(3)||(A>="0"&&A<="9"))},_connectCalendar:function(E,D){var F=$(E);var C=D._get("appendText");if(C){F.after('<span class="calendar_append">'+C+"</span>")}var H=D._get("autoPopUp");if(H=="focus"||H=="both"){F.focus(this.showFor)}if(H=="button"||H=="both"){var G=D._get("buttonText");var I=D._get("buttonImage");var B=D._get("buttonImageOnly");var A=$(B?'<img class="calendar_trigger" src="'+I+'" alt="'+G+'" title="'+G+'"/>':'<button type="button" class="calendar_trigger">'+(I!=""?'<img src="'+I+'" alt="'+G+'" title="'+G+'"/>':G)+"</button>");F.wrap('<span class="calendar_wrap"></span>').after(A);A.click(this.showFor)}F.keydown(this._doKeyDown).keypress(this._doKeyPress);F[0]._calId=D._id},_inlineCalendar:function(C,B){$(C).append(B._calendarDiv);C._calId=B._id;var A=new Date();B._selectedDay=1;B._selectedMonth=A.getMonth();B._selectedYear=A.getFullYear();popUpCal._adjustDate(B)},dialogCalendar:function(D,A,B,E){var C=this._dialogInst;if(!C){C=this._dialogInst=new PopUpCalInstance({},false);this._dialogInput=$('<input type="text" size="1" style="position: absolute; top: -100px;"/>');this._dialogInput.keydown(this._doKeyDown);$("body").append(this._dialogInput);this._dialogInput[0]._calId=C._id}$.extend(C._settings,B||{});this._dialogInput.val(D);if(self.innerHeight){windowWidth=self.innerWidth;windowHeight=self.innerHeight}else{if(document.documentElement&&document.documentElement.clientHeight){windowWidth=document.documentElement.clientWidth;windowHeight=document.documentElement.clientHeight}else{if(document.body){windowWidth=document.body.clientWidth;windowHeight=document.body.clientHeight}}}this._pos=E||[(windowWidth/2)-100,(windowHeight/2)-100];this._dialogInput.css("left",this._pos[0]+"px").css("top",this._pos[1]+"px");C._settings.onSelect=A;this._inDialog=true;this._calendarDiv.addClass("calendar_dialog");this.showFor(this._dialogInput[0]);if($.blockUI){$.blockUI(this._calendarDiv)}},enableFor:function(A){A=(A.jquery?A:$(A));A.each(function(){this.disabled=false;$("../button.calendar_trigger",this).each(function(){this.disabled=false});$("../img.calendar_trigger",this).css({opacity:"1.0",cursor:""});var B=this;popUpCal._disabledInputs=$.map(popUpCal._disabledInputs,function(C){return(C==B?null:C)})})},disableFor:function(A){A=(A.jquery?A:$(A));A.each(function(){this.disabled=true;$("../button.calendar_trigger",this).each(function(){this.disabled=true});$("../img.calendar_trigger",this).css({opacity:"0.5",cursor:"default"});var B=this;popUpCal._disabledInputs=$.map(popUpCal._disabledInputs,function(C){return(C==B?null:C)});popUpCal._disabledInputs[popUpCal._disabledInputs.length]=this})},reconfigureFor:function(C,A){var B=this._getInst(C._calId);if(B){$.extend(B._settings,A||{});this._updateCalendar(B)}},setDateFor:function(C,A){var B=this._getInst(C._calId);if(B){B._setDate(A)}},getDateFor:function(B){var A=this._getInst(B._calId);return(A?A._getDate():null)},showFor:function(E){var A=(E.nodeName&&E.nodeName.toLowerCase()=="input"?E:this);if(A.nodeName.toLowerCase()!="input"){A=$("input",A.parentNode)[0]}if(popUpCal._lastInput==A){return }for(var B=0;B<popUpCal._disabledInputs.length;B++){if(popUpCal._disabledInputs[B]==A){return }}var D=popUpCal._getInst(A._calId);popUpCal.hideCalendar(D,"");popUpCal._lastInput=A;D._setDateFromField(A);if(popUpCal._inDialog){A.value=""}if(!popUpCal._pos){popUpCal._pos=popUpCal._findPos(A);popUpCal._pos[1]+=A.offsetHeight}D._calendarDiv.css("position",(popUpCal._inDialog&&$.blockUI?"static":"absolute")).css("left",popUpCal._pos[0]+"px").css("top",popUpCal._pos[1]+"px");popUpCal._pos=null;var C=D._get("fieldSettings");$.extend(D._settings,(C?C(A):{}));popUpCal._showCalendar(D)},_showCalendar:function(C){var B=this._getInst(C);popUpCal._updateCalendar(B);if(!B._inline){var A=B._get("speed");B._calendarDiv.show(A,function(){popUpCal._popUpShowing=true;popUpCal._afterShow(B)});if(A==""){popUpCal._popUpShowing=true;popUpCal._afterShow(B)}if(B._input[0].type!="hidden"){B._input[0].focus()}this._curInst=B}},_updateCalendar:function(A){A._calendarDiv.empty().append(A._generateCalendar());if(A._input&&A._input!="hidden"){A._input[0].focus()}},_afterShow:function(A){if($.browser.msie){$("#calendar_cover").css({width:A._calendarDiv[0].offsetWidth+4,height:A._calendarDiv[0].offsetHeight+4})}},hideCalendar:function(C,B){var A=this._getInst(C);if(popUpCal._popUpShowing){B=(B!=null?B:A._get("speed"));A._calendarDiv.hide(B,function(){popUpCal._tidyDialog(A)});if(B==""){popUpCal._tidyDialog(A)}popUpCal._popUpShowing=false;popUpCal._lastInput=null;A._settings.prompt=null;if(popUpCal._inDialog){popUpCal._dialogInput.css("position","absolute").css("left","0px").css("top","-100px");if($.blockUI){$.unblockUI();$("body").append(this._calendarDiv)}}popUpCal._inDialog=false}popUpCal._curInst=null},_tidyDialog:function(A){A._calendarDiv.removeClass("calendar_dialog");$(".calendar_prompt",A._calendarDiv).remove()},_checkExternalClick:function(A){if(!popUpCal._curInst){return }var B=$(A.target);if((B.parents("#calendar_div").length==0)&&(B.attr("class")!="calendar_trigger")&&popUpCal._popUpShowing&&!(popUpCal._inDialog&&$.blockUI)){popUpCal.hideCalendar(popUpCal._curInst,"")}},_adjustDate:function(D,C,B){var A=this._getInst(D);A._adjustDate(C,B);this._updateCalendar(A)},_gotoToday:function(C){var A=new Date();var B=this._getInst(C);B._selectedDay=A.getDate();B._selectedMonth=A.getMonth();B._selectedYear=A.getFullYear();this._adjustDate(B)},_selectMonthYear:function(D,A,C){var B=this._getInst(D);B._selectingMonthYear=false;B[C=="M"?"_selectedMonth":"_selectedYear"]=A.options[A.selectedIndex].value-0;this._adjustDate(B)},_clickMonthYear:function(B){var A=this._getInst(B);if(A._input&&A._selectingMonthYear&&!$.browser.msie){A._input[0].focus()}A._selectingMonthYear=!A._selectingMonthYear},_changeFirstDay:function(F,A){var D=this._getInst(F);var E=D._get("dayNames");var C=A.firstChild.nodeValue;for(var B=0;B<7;B++){if(E[B]==C){D._settings.firstDay=B;break}}this._updateCalendar(D)},_selectDay:function(C,B){var A=this._getInst(C);A._selectedDay=$("a",B).html();this._selectDate(C)},_clearDate:function(A){this._selectDate(A,"")},_selectDate:function(D,A){var C=this._getInst(D);A=(A!=null?A:C._formatDate());if(C._input){C._input.val(A)}var B=C._get("onSelect");if(B){B(A)}else{C._input.trigger("change")}if(C._inline){this._updateCalendar(C)}else{this.hideCalendar(C,C._get("speed"))}},noWeekends:function(B){var A=B.getDay();return[(A>0&&A<6),""]},_findPos:function(A){if(A.type=="hidden"){A=A.nextSibling}var C=curtop=0;if(A.offsetParent){C=A.offsetLeft;curtop=A.offsetTop;while(A=A.offsetParent){var B=C;C+=A.offsetLeft;if(C<0){C=B}curtop+=A.offsetTop}}return[C,curtop]}});function PopUpCalInstance(B,C){this._id=popUpCal._register(this);this._selectedDay=0;this._selectedMonth=0;this._selectedYear=0;this._input=null;this._inline=C;this._calendarDiv=(!C?popUpCal._calendarDiv:$('<div id="calendar_div_'+this._id+'" class="calendar_inline"></div>'));if(C){var A=new Date();this._currentDay=A.getDate();this._currentMonth=A.getMonth();this._currentYear=A.getFullYear()}this._settings=$.extend({},B||{})}$.extend(PopUpCalInstance.prototype,{_get:function(A){return(this._settings[A]!=null?this._settings[A]:popUpCal._defaults[A])},_setDateFromField:function(C){this._input=$(C);var A=this._get("dateFormat");var B=this._input.val().split(A.charAt(3));if(B.length==3){this._currentDay=parseInt(B[A.indexOf("D")],10);this._currentMonth=parseInt(B[A.indexOf("M")],10)-1;this._currentYear=parseInt(B[A.indexOf("Y")],10)}else{var D=new Date();this._currentDay=D.getDate();this._currentMonth=D.getMonth();this._currentYear=D.getFullYear()}this._selectedDay=this._currentDay;this._selectedMonth=this._currentMonth;this._selectedYear=this._currentYear;this._adjustDate()},_setDate:function(A){this._selectedDay=this._currentDay=A.getDate();this._selectedMonth=this._currentMonth=A.getMonth();this._selectedYear=this._currentYear=A.getFullYear();this._adjustDate()},_getDate:function(){return new Date(this._currentYear,this._currentMonth,this._currentDay)},_generateCalendar:function(){var Q=new Date();Q=new Date(Q.getFullYear(),Q.getMonth(),Q.getDate());var H='<div id="testata">\n<div class="freccialeft"><a onclick="popUpCal._adjustDate('+this._id+", -1, 'M');\">"+this._get("prevText")+'</a></div>\n<div class="mesecal"><p>'+this._get("monthNames")[this._selectedMonth]+"&#160;"+this._selectedYear+'</p></div>\n<div class="frecciaright"><a onclick="popUpCal._adjustDate('+this._id+", +1, 'M');\">"+this._get("nextText")+'</a></div>\n<div class="clear"/></div>';var F=this._get("minDate");var J=this._get("maxDate");H+='\n<div class="month">\n<ul>';var I=this._get("firstDay");var R=this._get("dayNames");for(var L=0;L<7;L++){H+='\n<li class="th">'+R[(L+I)%7]+"</li>"}var B=this._getDaysInMonth(this._selectedYear,this._selectedMonth);this._selectedDay=Math.min(this._selectedDay,B);var S=(this._getFirstDayOfMonth(this._selectedYear,this._selectedMonth)-I+7)%7;var G=new Date(this._currentYear,this._currentMonth,this._currentDay);var A=new Date(this._selectedYear,this._selectedMonth,this._selectedDay);var D=new Date(this._selectedYear,this._selectedMonth,1-S);var C=Math.ceil((S+B)/7);var N=this._get("customDate");var O=this._get("showOtherMonths");for(var E=0;E<C;E++){for(var L=0;L<7;L++){var K=(N?N(D):[true,""]);var P=(D.getMonth()!=this._selectedMonth);var M=P||!K[0]||(F&&D<F)||(J&&D>J);H+='<li class="day'+((L+I+6)%7>=5?" we":"")+(P?" free":"")+(D.getTime()==A.getTime()?" today":"")+(M?" ro":"")+(!P||O?" "+K[1]:"")+(D.getTime()==G.getTime()?" today":(D.getTime()==Q.getTime()?" today":""))+'"'+(M?"":' onmouseover="$(this).addClass(\'day_over\');" onmouseout="$(this).removeClass(\'day_over\');" onclick="popUpCal._selectDay('+this._id+', this);"')+">"+(P?(O?D.getDate():"&nbsp;"):(M?D.getDate():"<a>"+D.getDate()+"</a>"))+"</li>";D.setDate(D.getDate()+1)}}H+='</ul><div class="clear"/>\n</div>\n<div style="clear: both;"></div>'+(!$.browser.msie?"":'<!--[if lte IE 6.5]><iframe src="javascript:false;" class="calendar_cover"></iframe><![endif]-->');return H},_adjustDate:function(E,D){var A=new Date(this._selectedYear+(D=="Y"?E:0),this._selectedMonth+(D=="M"?E:0),this._selectedDay+(D=="D"?E:0));var B=this._get("minDate");var C=this._get("maxDate");A=(B&&A<B?B:A);A=(C&&A>C?C:A);this._selectedDay=A.getDate();this._selectedMonth=A.getMonth();this._selectedYear=A.getFullYear()},_getDaysInMonth:function(A,B){return 32-new Date(A,B,32).getDate()},_getFirstDayOfMonth:function(A,B){return new Date(A,B,1).getDay()},_canAdjustMonth:function(B){var A=new Date(this._selectedYear,this._selectedMonth+B,1);if(B<0){A.setDate(this._getDaysInMonth(A.getFullYear(),A.getMonth()))}return this._isInRange(A)},_isInRange:function(A){var B=this._get("minDate");var C=this._get("maxDate");return((!B||A>=B)&&(!C||A<=C))},_formatDate:function(){var B=this._currentDay=this._selectedDay;var F=this._currentMonth=this._selectedMonth;var D=this._currentYear=this._selectedYear;F++;var A=this._get("dateFormat");var E="";for(var C=0;C<3;C++){E+=A.charAt(3)+(A.charAt(C)=="D"?(B<10?"0":"")+B:(A.charAt(C)=="M"?(F<10?"0":"")+F:(A.charAt(C)=="Y"?D:"?")))}return E.substring(A.charAt(3)?1:0)}});$.fn.calendar=function(settings){return this.each(function(){var inlineSettings=null;for(attrName in popUpCal._defaults){var attrValue=this.getAttribute("cal:"+attrName);if(attrValue){inlineSettings=inlineSettings||{};try{inlineSettings[attrName]=eval(attrValue)}catch(err){inlineSettings[attrName]=attrValue}}}var nodeName=this.nodeName.toLowerCase();if(nodeName=="input"){var instSettings=(inlineSettings?$.extend($.extend({},settings||{}),inlineSettings||{}):settings);var inst=(inst&&!inlineSettings?inst:new PopUpCalInstance(instSettings,false));popUpCal._connectCalendar(this,inst)}else{if(nodeName=="div"||nodeName=="span"){var instSettings=$.extend($.extend({},settings||{}),inlineSettings||{});var inst=new PopUpCalInstance(instSettings,true);popUpCal._inlineCalendar(this,inst)}}})};$(document).ready(function(){popUpCal=new PopUpCal()})