function checkAge() {


    /* the minumum age you want to allow in */
    var min_age = 21;

    /* change "age_form" to whatever your form has for a name="..." */
    var year = document.getElementById("dob_year").value;
    var month = document.getElementById("dob_month").value;
    var day = document.getElementById("dob_day").value;

    if ((isNaN(year)) || (isNaN(month)) || (isNaN(day)) || (day>31) || (month>12) || (year.length != 4)) {
        alert("Please enter valid numbers into the date fields then re-submit!");
        return false;
    } else {

        var year = parseInt(document.forms["age_form"]["dob_year"].value);
        var month = parseInt(document.forms["age_form"]["dob_month"].value) - 1;
        var day = parseInt(document.forms["age_form"]["dob_day"].value);

        var theirDate = new Date((year + min_age), month, day);
        var today = new Date;

        if ( (today.getTime() - theirDate.getTime()) < 0) {
            alert("You are too young to enter this site!");
            return false;
        }
        else {
            return true;
        }
    }
}
