// JavaScript routines for date differencesdayMsec=24*3600*1000;     // 1 day in milliseconds// Convert an integer to a string with commas// ---------------------------------------function niceString(x){var s=x.toString();var n=s.length;if (n<=3) return s;var t="";for (var i=0;i<n;i++) { t+=s.substring(i,i+1); if ((n-i-1)%3==0 && i!=n-1) t+=","; };return t;}// The length in days of a given month of a given year// ---------------------------------------------// Here we use the JavaScript convention of month numbers starting at 0function monthLength(month,year){var firstOfMonth=new Date(year,month,1);var firstOfNext;if (month==11) firstOfNext=new Date(year+1,0,1);else firstOfNext=new Date(year,month+1,1);return Math.floor((firstOfNext-firstOfMonth)/dayMsec);}// Number of days since a date in the past// -----------------------------------function intDaysSince(year,month,day, year2,month2,day2){var originalDate=new Date(year,month-1,day);    // JavaScript starts months at 0var secondDate=year2<0 ? new Date() : new Date(year2,month2-1,day2);var differenceMillisecs=secondDate-originalDate;return Math.floor(differenceMillisecs/dayMsec);}// A text representation of the number of days since a date in the past// -------------------------------------------------------------function daysSince(year,month,day,year2,month2,day2){return niceString(intDaysSince(year,month,day,year2,month2,day2))+"&nbsp;days";}// A text representation of the number of years, days and months since a date in the past// ------------------------------------------------------------------------------function yearsMonthsDaysSince(y,m,d, y2,m2,d2){var diff=new Array(0,0,0);m=m-1;    // JavaScript starts months at 0// Get y1, m1, d1 as year, month day of current datevar secondDate=y2<0 ? new Date() : new Date(y2,m2-1,d2);var y1=secondDate.getYear();if (y1<1900) y1+=1900;var m1=secondDate.getMonth();var d1=Math.floor(secondDate.getDate());// The difference in daysif (d1>=d) diff[2]=d1-d;else { // Need to borrow days from the month if (m1==0) {y1--; m1=11;} else m1--; diff[2]=d1+monthLength(m1,y1)-d; };// The difference in monthsif (m1>=m) diff[1]=m1-m;else { // Need to borrow months from the years diff[1]=m1+12-m; y1--; };// The difference in yearsdiff[0]=y1-y;// String text versions of the difference together, nicely punctuatedvar s="";if (diff[0]!=0) s=diff[0].toString()+(diff[0]==1?"&nbsp;year":"&nbsp;years");if (diff[1]!=0) { if (s!="")  {  if (diff[2]==0) s+=" and "; else s+=", ";  };  s+=diff[1].toString()+(diff[1]==1?"&nbsp;month":"&nbsp;months"); };if (diff[2]!=0) { if (s!="") s+=" and "; s+=diff[2].toString()+(diff[2]==1?"&nbsp;day":"&nbsp;days"); };return s;}// A table of images representing the number of days since a date in the past// --------------------------------------------------------------------------function daysSinceTable(year,month,day, year2,month2,day2, imageDirURL,ncols){var d=intDaysSince(year,month,day,year2,month2,day2);var nrows=Math.ceil(d/(5*ncols));var i=0;var str='<table class="days" align="left" border="0" cellpadding="0" cellspacing="0"><tr><td colspan="';str+=ncols.toString()+'" align="center"><b>'+daysSince(year,month,day,year2,month2,day2)+'</b></td></tr>';for (var irow=0;irow<nrows;irow++) { str+='<tr>'; for (var icol=0;icol<ncols;icol++)  {  str+='<td class="days">';  if (d>0)   {   if (d<5) k=d; else k=5;   var year=1+Math.floor(i/365);   src=imageDirURL+"y"+year.toString()+k.toString()+".gif";   str+='<image src="'+src+'" width="36" height="36" />';   d-=k;   i+=k;   }  else   {   str+='&nbsp;';   };  str+='</td>';  }; str+='</tr>'; };str+='</table>';return str;}