<!-- Javascript que calcula la edad de una persona en meses y dias o en anos, meses y dias -->
function getAge(birth)
{

var now = new Date();


aSecond = 1000;
aMinute = aSecond * 60;
aHour = aMinute * 60;
aDay = aHour * 24;
aWeek = aDay * 7;
aMonth = aDay * 30;


var age = now.getTime() - birth.getTime();

if (age < 0) {
return "not born yet"
}


years = (new Date(now.getTime() - aMonth* (birth.getMonth()) )).getYear()
- (new Date(birth.getTime() - aMonth* (birth.getMonth()) )).getYear();


offsetNow = (new Date(now.getTime() - aDay* (birth.getDate() -1) ));
offsetBirth = (new Date(birth.getTime() - aDay* (birth.getDate() -1) ));
if(years > 1){
months = years*12 + ( offsetNow.getMonth() - offsetBirth.getMonth()) ;
}else{
months = (now.getYear() - birth.getYear())*12 + ( offsetNow.getMonth() - offsetBirth.getMonth()) ;
}
agestr="";

if (months < 24){
weeks = Math.floor(age / aWeek);
age -= weeks * aWeek;
days = Math.floor(age / aDay);

if(weeks > 0){
if(weeks == 1){
agestr = agestr + weeks + " semana ";
}else if(weeks < 9){
agestr = agestr + weeks + " semanas ";
}else{
agestr = agestr + months ;

if(now.getDate() - birth.getDate() > 10){
agestr = agestr + " ½ ";
}
agestr = agestr + " meses ";

}
}

if(days > 0){

if(weeks < 9){
if(weeks > 0){
agestr = agestr + " y ";
}
if(days == 1){
agestr = agestr + days + " d&iacute;a ";
}else{
agestr = agestr + days + " d&iacute;as ";
}
}
}
}else{
agestr = agestr + years;
if (months%12 > 5 && years<14){
agestr = agestr + " ½ ";
}
agestr = agestr + " años ";
}

return agestr;
}


