Date.prototype.getDiff = function(date, interval){
  if (typeof date == "string"){
     date = new Date(date);
  }
  if (isNaN(date) || !(date instanceof Date)){
     return NaN; //invalid date passed
  }
  if (typeof interval == "undefined") interval = "ms"; //msec (default)
  var diff = this - date; //alert(this+' - '+date+" = "+diff)//diff in msec
  switch(interval.toLowerCase()){
    case "s": //sec
      diff = diff/1000; break;
    case "n": //min
      diff = diff/(1000*60); break;
    case "h": //hr
      diff = diff/(1000*60*60); break;
    case "d": //day
      diff = diff/(1000*60*60*24); break;
    case "m": //month
      diff = diff/(1000*60*60*24*30); break;
    case "y": //year
      diff = diff/(1000*60*60*24*365); break;
    default:
      ; //msec
  }
  return Math.floor(diff);
}

var arrBday = [
  ['Pam S.', '1/3/2068'],
  ['James Myers', '1/7/1978'],
  ['Kurt D.', '1/13/1972'],
  ['Ross M.', '1/15/1972'],
  ['Heza', '1/17/1978'],
  ['Tina', '1/17/1980'],
  ['Tiffany', '2/5/1980'],
  ['Ilse', '2/10/1945'],
  ['Morgan M.', '2/13/2004'],
  ['Dad', '2/17/1951'],
  ['Steve E.', '2/18/1972'],
  ['Beatrice Clement', '2/22/1980'],
  ['Ralph', '2/22/1945'],
  ['Marti T.', '2/22/1945'],
  ['Diana I.', '3/6/2005'],
  ['David S.', '3/13/1957'],
  ['Cliff O.', '3/19/1972'],
  ['Tim Hobbs', '3/27/1974'],
  ['Mark L.', '3/29/1972'],
  ['Uncle Richard', '4/3/1953'],
  ['Aunt MaryAnn', '4/12/1972'],
  ['Karin Liegl', '4/13/1976'],
  ['Alex', '4/14/1976'],
  ['Brenda Hill', '4/14/1976'],
  ['Leigh Rogers', '4/19/2005'], 
  ['Ping Ping', '4/28/1979'],
  ['Elaye Wong', '5/8/1971'],
  ['Larry Miller', '5/8/1977'],
  ['Joe Madrak', '5/17/1955'],
  ['Scott Laidlaw', '5/17/1955'],
  ['Eva Galambos', '5/21/1976'],
  ['Mom', '5/25/1955'],
  ['Tenley Newcomb', '5/26/1976'], 
  ['Granddaddy', '5/29/1927'],
  ['Daryl Flatt', '5/27/1971'],
  ['Paul Delucia', '6/3/1979'],
  ['Dave Hall', '6/3/1979'],
  ['Tanase Bude', '6/15/1971'],
  ['Martin Gentemann', '7/2/1984'], 
  ['Tavia Kopf', '7/9/1978'],
  ['Sam Reid', '7/10/1986'],
  ['Oma', '7/13/1919'],
  ['Haydee Idos', '7/16/1996'],
  ['Amanda M Schenk', '7/21/1982'],
  ['Mary French', '7/24/1971'],
  ['Quentin Johnston', '8/1/1971'],
  ['Angie Laidlaw', '8/2/1971'],
  ['Marko Kimpel', '8/11/1975'],
  ['Aunt Sae', '8/12/1919'],  
  ['Roland Gentemann', '9/7/1978'],
  ['Stacy Nigro', '9/9/1974'],
  ['Amy Sloan', '9/17/1977'],
  ['Jano Brain', '9/19/1978'],
  ['Jeannie Spencer', '9/25/1947'],
  ['Randy Cooper', '9/27/1971'],
  ['Devyn Howell ', '10/8/1980'],
  ['Eliana Aquino', '10/11/1980'],
  ['Chris Wright', '10/17/1955'],
  ['Carlos Herd', '10/23/1965'],
  ['Chris Metzger', '10/24/1971'],
  ['Hugh Dinkler', '10/24/1971'],
  ['Robert Soklaski', '10/29/1971'],
  ['Jim Guida', '11/2/1971'],
  ['Jan Tijmes', '11/2/1976'],
  ['Molly Gibbson Matheny', '11/6/1979'],
  ['Alizza Punzalan-Hall', '11/7/1976'],
  ['Grandmommy', '11/13/1923'],
  ['allisong', '11/28/1977'],
  ['Julee Schoenfeld', '12/05/1975'],
  ['Kathleen Kastner', '12/17/1971']
];


function getBdayList(numDays){
  var bday,temp,idx,diff;
  var today = new Date();
  var bdayList = new Array();
  for (var i=0;i<arrBday.length;i++){
    bday = new Date(arrBday[i][1]);
    if (isNaN(bday)) continue;
    temp = new Date(today.getFullYear(), bday.getMonth(), bday.getDate(), 23, 59, 59, 999);
    diff = temp.getDiff(today, "d");
    if (diff >= 0 && diff <= numDays){
       idx = bdayList.length;
       bdayList[idx] = new Object();
       bdayList[idx].name = arrBday[i][0];
       bdayList[idx].bday = arrBday[i][1];
       bdayList[idx].age = today.getDiff(bday, "y");
       if (diff > 0) bdayList[idx].age = bdayList[idx].age;
       bdayList[idx].today = (diff == 0) ? true : false;
       
    }
  }
  return bdayList;    
}

function displayBdayList(){
  var bdayList = getBdayList(14);
  var len = bdayList.length;
  var s1 = ""; //today's bday list
  var s2 = ""; //next 2 week's bday list
  if (len>0){
    for (var i=0; i<len; i++){
       if (bdayList[i].today){
          if (s1 != ""){
            s1 +=bdayList[i].name + ' (' + bdayList[i].age + ')' + '<br/><br />';
          }
          else{
             s1 = '<br /><b>Today: </b><br />' +  bdayList[i].name +  ' (' + bdayList[i].age + ')' + '<br />';
          }  
       }
        else{
         if (s2 != ""){
            s2 +=bdayList[i].name + ' - ' + '<font class="note">' + bdayList[i].bday + '</font>' + '<br />';
         }
         else{
            s2 = '<font class="small_details">Within next 14 days: </font><br />' + bdayList[i].name + ' - ' + '<font class="emp">' + bdayList[i].bday + '</font>' + '<br />';
         }          
       }
     }
  }
  else{
    s1 = "Nada, Nix, Zillch";
  }
  document.write(s1 + '<div>' + s2 + '</div>');
}
