﻿//requires reference to: jquery.date.js
var DOBValidationHelper = {

    //ensure there is more than 0 radio buttons checked.
    DoValidate: function(sender, args) {

        var dateParts = args.Value.split("/");
        var dob = new Date();
        dob.setFullYear(dateParts[2], parseInt(dateParts[1]) - 1, dateParts[0]);

        var now = new Date();

        var eighteenYrsAgo = new Date();
        eighteenYrsAgo.setFullYear(now.getFullYear(), now.getMonth(), now.getDate());
        eighteenYrsAgo.addYears(-18);

        //this calculates the number of days different between how old they must be compared to how old they are
        var diff = ((eighteenYrsAgo.getTime() - dob.getTime()) / (60 * 60 * 24 * 1000));

        //as longs as its in the negative, they are under 18
        args.IsValid = (diff < 0);

    }

}
