

Date.prototype.getWeek = function()
{   
  //var firstSunday = new Date(this.getFullYear(),0,3);
  // get the first day of this year
  var firstSunday = new Date(this.getFullYear(),0,1);

  // loop to see if the first day of the year is Sunday, if not then get next day and check
  for(i=2;i<=7;i++)
  {
    if(firstSunday.getDay()==0)
    {
      // found the first Sunday of the year
      // 1) get today's date-firstSunday's date which gives us milliseconds
      // 2) divide milliseconds by 86400000 to get day's difference
      // 3) divide by 7 to get difference of weeks
      // 4) add one week because week zero is the first week and we want it to read week 1
      return Math.ceil((((this - firstSunday) / 86400000)-1) / 7)+1;

    }
    else
    {
      firstSunday = new Date(this.getFullYear(),0,i);
    }
  }
}

 var today = new Date();
 var weekno = today.getWeek()
