1function sundaysInMonth( m, y ) {
2 var days = new Date( y,m,0 ).getDate();
3 var sundays = [ 8 - (new Date( m +'/01/'+ y ).getDay()) ];
4 for ( var i = sundays[0] + 7; i < days; i += 7 ) {
5 sundays.push( i );
6 }
7 return sundays;
8}
9
10alert( sundaysInMonth( 10,2012 ) ); //=> [ 7,14,21,28 ]
11alert( sundaysInMonth( 10,2012 ).length ); //=> 4