$(document).ready(function() {

    function changeAge() {
        var parentMail = $(".fs-parent_email");
        var minor = isYoung();
        parentMail.css("display", (minor ? "block" : "none"));
    }

    function isYoung() {
        var objDate = new Date();
        var curyear = objDate.getFullYear();
        var curmonth = objDate.getMonth()+1;
        var curdate = objDate.getDate();

        var regForm = $("#form_id_2");
        var byear   = $("#birthyear").val();
        var bmonth  = $("#birthmonth").val();
        var bday    = $("#birthday").val();

        showparent = false;

        if(byear != "" && bmonth != "" && bday != "") {
            if ((curyear - byear) < 18) {
                showparent = true;
            } else {
                if ((curyear-byear) == 18 ) {
                    if (curmonth < bmonth ) {
                      showparent = true;
                    } else {
                      if (curmonth == bmonth ) {
                        if (curdate < bday ) {
                          showparent = true;
                        }
                      }
                    }
                }
            }
        }
        return showparent;
    }


    $(".join-date").change(function() {
        changeAge();
    });

    changeAge();

});
