
var bg={curDate:null,birthDate:null,showAge:function(data){bdate=document.getElementById("age").getAttribute("bday").split(" ");this.birthDate=new Date(parseInt(bdate[0],10),(parseInt(bdate[1],10)-1),parseInt(bdate[2],10));this.curDate=new Date(Date.parse(data.datetime));this.printAge();},getTimeStamp:function(dateObj){return(dateObj.getTime()/1000);},calculateAge:function(){y1=this.birthDate.getFullYear();m1=this.birthDate.getMonth();d1=this.birthDate.getDate();y2=this.curDate.getFullYear();m2=this.curDate.getMonth();d2=this.curDate.getDate();t0=y1*12+m1-1;t=y2*12+m2-1;dm=t-t0;if(d2>=d1){return[Math.floor(dm/12),(dm%12),d2-d1];}
dm=dm-1;t=t-1;return[Math.floor(dm/12),(dm%12),(this.getTimeStamp(new Date(y2,m2,d2))-
this.getTimeStamp(new Date(Math.floor(t/12),(t%12)+1,d1)))/(60*60*24)];},pluralizeStr:function(data,str,p){if(data<=0){return"";}else if(data==1){return(data+" "+str);}else{return(data+" "+str+p);}},formatAge:function(age){years=this.pluralizeStr(age[0],"year","s");months=this.pluralizeStr(age[1],"month","s");days=this.pluralizeStr(age[2],"day","s");if(age[0]&&age[1]&&age[2]){sep1=", ";sep2="";sep3=" and ";}else if(age[0]&&(age[1]||age[2])){sep1=" and ";sep2="";sep3="";}else if(!age[0]&&(age[1]&&age[2])){sep1="";sep2=" and ";sep3="";}else{sep1="";sep2="";sep3="";}
return(years+sep1+months+sep2+sep3+days);},printAge:function(){age=this.calculateAge();formattedAge=this.formatAge(age);document.getElementById("age").innerHTML=formattedAge;}};
