letdowOffset=1;// I am fixing this to indicate that the first day of the week is always Monday (weeks end on Sunday), for this application. This was a parameter in the original code.
//dowOffset = typeof(dowOffset) == 'number' ? dowOffset : 0; //default dowOffset to zero - This should check to ensure that dowOffset is between 0..6
letnewYear=newDate(this.getFullYear(),0,1);
letday=newYear.getDay()-dowOffset;//the day of week the year begins on
day=(day>=0?day:day+7);
// The number of days from the beginning of the year to this.day
// I have removed the mid-week starting cutoff detection because in this app we always want to start with week #1 (never have a week zero).
//if(day < 4) { //if the year starts before the middle of a week
weeknum=Math.floor((daynum+day-1)/7)+1;
// I have turned off the detection of whether the last days of the year belong to this year's last week or next year's first week. This gets too confusing and does not result in any additional usefulness.
//if(weeknum > 52) {
// nYear = new Date(this.getFullYear() + 1, 0, 1);
// nday = nYear.getDay() - dowOffset;
// nday = nday >= 0 ? nday : nday + 7;
// // if the next year starts before the middle of the week, it is week #1 of that year