calendar=new Object();tr=new Object();tr.nextMonth="Mes siguiente";tr.prevMonth="Mes anterior";tr.closeCalendar="Cerrar calendario";tr.icons="/gifs";var months=['gennaio','febbraio','marzo','aprile','maggio','giugno','luglio','agosto','settembre','ottobre','novembre','dicembre',];var days=['l','m','x','g','v','s','d'];var days3=['lun','mar','mie','jue','vie','sab','dom'];var DOM={isParentOf:function(parentElm,contextElm){while(contextElm &&(contextElm !=parentElm))contextElm=contextElm.parentNode;return(contextElm==parentElm);},getParentOrSelf:function(contextElm,nodeName ){nodeName=nodeName.toLowerCase();while(contextElm.nodeName.toLowerCase() !=nodeName && contextElm.parentNode)contextElm=contextElm.parentNode;return contextElm;},addClass:function(elm,className ){elm.className+=' '+className;},removeClass:function(elm,className){var classMatch=new RegExp('\\b'+className+'\\b','g');if(classMatch.test(elm.className))elm.className=elm.className.replace(classMatch,' ');}};function getDimensions(elm ){var box={x:0,y:0,w:0,h:0};if(document.getBoxObjectFor){var boxRef=document.getBoxObjectFor(elm);box.x=boxRef.x;box.y=boxRef.y;box.w=boxRef.width;box.h=boxRef.height;}else if(elm.getBoundingClientRect){var rxIE50=/MSIE 5\.0/g;var boxRef=elm.getBoundingClientRect();box.x=boxRef.left;box.y=boxRef.top;box.w=(boxRef.right - boxRef.left);box.h=(boxRef.bottom - boxRef.top);if(document.compatMode && document.compatMode !='BackCompat'){box.x+=document.documentElement.scrollLeft - 2;box.y+=document.documentElement.scrollTop - 2;}else if(!gClientIsIE5){box.x+=document.body.scrollLeft - 2;box.y+=document.body.scrollTop - 2;}}else{box.w=elm.offsetWidth;box.h=elm.offsetHeight;while(elm){box.x+=elm.offsetLeft;box.y+=elm.offsetTop;if(elm.offsetParent) elm=elm.offsetParent;elsebreak;}}var cc;if(cc=document.getElementById('bodyconstraint'))box.x -=cc.offsetLeft;return box;}function showCalendar(me,calId,dt){getDimensions(me);if(document.getElementById){var c=document.getElementById(calId);var i=getChildImage(me);var f=DOM.getParentOrSelf(me,'form');calendar.cal=c;calendar.caldt=dt;calendar.calf=f;var m=f['Mes_llegada'].value;d=f['Dia_llegada'].value;y=f['Ano_llegada'].value;buildCal(y,m,d);var box=getDimensions(i);var left=box.x,top=(box.y+i.offsetHeight);c.style.left='475px';c.style.top='240px';c.style.display="block";}}function closeCal(){calendar.cal.style.display='none';}function buildCal(y,m,d){var daysInMonth=[31,0,31,30,31,30,31,31,30,31,30,31];td=new Date();if(!y) y=td.getFullYear();if(!m) m=td.getMonth()+1;if(!d) d=td.getDate;var dt=calendar.caldt;var mDate=new Date(y,m-1,1);var firstMonthDay=mDate.getDay();daysInMonth[1]=(((mDate.getFullYear()%100!=0)&&(mDate.getFullYear()%4==0))||(mDate.getFullYear()%400==0))?29:28;var t='<div id="calendariox"><table class="caltable" cellspacing="0"><tr>';t+='<td class="calheader" colspan="7" class="monthYear" bgcolor="#739ed5">';if(y==td.getFullYear() && m==td.getMonth()+1){t+='<img class="calNoPrevMonth" src="'+tr.icons+'/transparent.png" width="20" height="20" alt="'+tr.prevMonth+'">';}else{t+='<a class="calPrevMonth" href="" onclick="prevMonth('+y+','+m+');return false;" title="'+tr.prevMonth+'"><img src="/gifs/arrows_l.gif" width="20" height="20" alt="'+tr.prevMonth+'"></a>';}t+='&nbsp;<select name="ym" onchange="goYearMonth(this.options[this.selectedIndex].value)">';var mn=td.getMonth()+1;var yr=td.getFullYear();var last_month=0;for(n=0;n<=11;n++){t+='<option value="'+yr+'-'+mn+'"';if(mn==m && yr==y){t+=' selected="selected"';last_month=1;}else{last_month=0;}t+='>'+months[mn-1]+' '+yr+'</option>';mn++;if(mn>12){mn=1;yr++}}t+='</select>&nbsp;';if(last_month==1){t+='<img class="calNoNextMonth" src="'+tr.icons+'/transparent.png" width="20" height="20" alt="'+tr.nextMonth+'">';}else{t+='<a class="calNextMonth" href="" onclick="nextMonth('+y+','+m+');return false;" title="'+tr.nextMonth+'"><img src="/gifs/arrows_r.gif" width="20" height="20" alt="'+tr.nextMonth+'"></a>';}t+='</td></tr>';t+='<tr class="dayNames">';for(dn=0;dn<7;dn++){var cl='';if((dn%7==5)||(dn%7==6)) cl+=' weekend';t+='<td class="'+cl+'">'+days[dn]+'</td>';}t+='</tr><tr class="days">';for(i=1;i<=42;i++){var x=i -(firstMonthDay+6)%7;if(x>daysInMonth[m-1]||x<1) x='&nbsp;';var cl='';var href=0;if((i%7==0)||(i%7==6)) cl+=' weekend';if(x>0){var xDay=new Date(y,m-1,x);if((xDay.getFullYear()==y) &&(xDay.getMonth()+1==m)&&(xDay.getDate()==d)){cl+=' selected';href=1}if((xDay.getFullYear()==td.getFullYear())&&(xDay.getMonth()==td.getMonth())&&(xDay.getDate()==td.getDate())){cl+=' today';href=1;}else{if(xDay>td){cl+=' future';href=1;}else{if(xDay<td){cl+=' past'}}}};t+='<td class="'+cl+'">';if(href){t+='<a href="#" onclick="pickDate('+y+','+m+','+x+',\''+dt+'\');return false;">'+x+'</a>';}else{t+=x;}t+='</td>';if(((i)%7==0)&&(i<36)){t+='</tr><tr class="days">';}}t+='</tr></table></div>';document.getElementById("calendar").innerHTML=t;}function prevMonth(y,m){if(new Date(y,m-1,1)<td) return;if(m>1){m--}else{m=12;y--};buildCal(y,m);}function nextMonth(y,m){if(m<12){m++;}else{m=1;y++;}buildCal(y,m);}function goYearMonth(ym){var ymlist=ym.split("-");buildCal(ymlist[0],ymlist[1]);}function pickDate(y,m,d,dt){var f=calendar.calf;var dt=calendar.caldt;f['Mes_llegada'].value=m;f['Dia_llegada'].value=d;f['Ano_llegada'].value=y;closeCal();}function initDaySelect(){var forms=document.getElementsByTagName('form');for(var i=0;i<forms.length;i++)if(forms[i]['Dia_llegada'])updateDaySelect(forms[i]);}function buildDaysForMonth(year,month ){var monthDate=new Date(year,month-1);var orgMonth=monthDate.getMonth();var dayArray=[],weekDay;while(monthDate.getMonth()==orgMonth){weekDay=(monthDate.getDay()==0)?6:(monthDate.getDay()-1);dayArray.push(days3[weekDay]);monthDate.setDate(monthDate.getDate()+1);}return dayArray;}function getChildImage(contextElm ){contextElm=contextElm.firstChild;while(contextElm.nodeName.toLowerCase() !='img' && contextElm.nextSibling)contextElm=contextElm.nextSibling;return contextElm;}function getParentOrSelf(contextElm,nodeName ){nodeName=nodeName.toLowerCase();while(contextElm.nodeName.toLowerCase() !=nodeName && contextElm.parentNode)contextElm=contextElm.parentNode;return contextElm;}
