$(document).ready(function() {

    $(document).on({
        submit: function(e) {
            e.preventDefault();
            e.stopPropagation();
            var eventForm = $('#contactform');
            if (!$(eventForm).find('.form-group.has-error').length) {
                $.ajax({
                    url: "/tpl/inc/send_contact.php",
                    type: 'post',
                    data: $(eventForm).serialize(),
                    dataType: 'script',
                    success: function(responseText) {

                    },
                    error: function(request) {
                        console.log(request.responseText);
                    }
                });
            }

        }
    }, '#contactform');

    $(document).on({
        submit: function(e) {
            e.preventDefault();
            e.stopPropagation();
            var eventForm = $('#inquiryform');
            if (!$(eventForm).find('.form-group.has-error').length) {
                $.ajax({
                    url: "/tpl/send_inquiry.php",
                    type: 'post',
                    data: $(eventForm).serialize(),
                    dataType: 'script',
                    success: function(responseText) {
                        //$('.inquiry_table').html(responseText);
                    },
                    error: function(request) {
                        console.log(request.responseText);
                    }
                });
            }

        }
    }, '#inquiryform');


    $(document).on({
        submit: function(e) {
            e.preventDefault();
            e.stopPropagation();
            var eventForm = $('#classform');
            if (!$(eventForm).find('.form-group.has-error').length) {
                $.ajax({
                    url: "/tpl/send_apply.php",
                    type: 'post',
                    data: $(eventForm).serialize(),
                    dataType: 'script',
                    success: function(responseText) {
                        //$('.inquiry_table').html(responseText);
                    },
                    error: function(request) {
                        console.log(request.responseText);
                    }
                });
            }

        }
    }, '#classform');

    if ($("#birthdayPicker").length) {
        $("#birthdayPicker").birthdayPicker({
            "maxAge": 90,
            "minAge": 18
        });

        setTimeout(function() {
            $("#birthdayPicker").find('select').each(function(idx, elem) {
                console.log($(elem).html());
                $(elem).children('option').eq(0).val('');
                $(elem).val('');
                $(elem).prop('required', true);
            });

        }, 100);

    }
});