// Define birth dates
function birthdate() {
   this.Victoria = new Date("October 17, 1993 20:08:00"); 
   this.Catherine = new Date("May 9, 1996 13:37:00");
   this.Rebecca = new Date("April 29, 2000 02:32:00");
}

// Return the age of the given kid in days
function k_days(name) {

	bdate = new birthdate();
	now = new Date();

	msPerDay = 24 * 60 * 60 * 1000 ; // Number of milliseconds per day

	days = (now.getTime() - bdate[name].getTime()) / msPerDay;
	days = Math.round(days);
	
	return days;
}
	
// Return a more recognisable age, given age in days
function k_age(days) {

	daysPerWeek = 7;
	daysPerMonth = 30;
	daysPerYear = 365;

	// Convert age in days to weeks, months, or years
	if (days <= 90) {
		unit = " weeks";
		age = days / daysPerWeek;
	} else {
		if (days < 600) {
			unit = " months";
			age = days / daysPerMonth;
		} else {
			unit = " years";
			age = days / daysPerYear;
		}
	}

	// Calculate fraction of year/month/week
	prefix = "";
	fract = "";
	base = Math.round(age - 0.5);
	rem = Math.round((age - base) * 100);
	if ((40 < rem) && (rem < 70)) {
		fract = "&#189";
	} else {
		if ((70 <= rem) && (rem < 94)) {
			fract = "&#190";
		} else {
			if (94 <= rem) {
				prefix = "almost ";
				base++;
			}
		}
	}

	return (prefix + base + fract + unit);
}

