function ck_age(born_date,today,min_age,msg)
{

	var age=years_diff(today,born_date);

	if (age<min_age)
	{
		alert(msg)
		return false;
	}
	else return true;
}

function years_diff(S1, S2) //returns the difference in years between dates S1 and S2 (YYYY-MM-DD)
{
    var D1 = ReadISO8601date(S1);
    if (D1 < 0)
    {
    	alert("Date 1 is bad");
    	return false;
    }
    var D2 = ReadISO8601date(S2);
    if (D2 < 0)
    {
        alert("Date 2 bad");
        return false;
    }
    return (D1[0] - D2[0]) - (D1[1] * 100 + D1[2] < D2[1] * 100 + D2[2]);
}

function ReadISO8601date(Q) //used in years_diff function
{
	var T // adaptable for other layouts
  if ((T = /^(\d+)([-\/])(\d\d)(\2)(\d\d)$/.exec(Q)) == null)
    { return -2 } // bad format
  for (var j=1; j<=5; j+=2) T[j] = +T[j] // some use needs numbers
  if (!ValidDate(T[1], T[3]-1, T[5])) { return -1 } // bad value
  return [ T[1], T[3], T[5] ]
}

function ValidDate(y, m, d)
{ // m = 0..11 ; y m d integers, y!=0
  with (new Date(y, m, d))
    return (getMonth()==m && getDate()==d) /* was y, m */
}