﻿$(document).ready(function() {
    // Focus the first input element on the page.
    $(':input:visible:enabled:first').focus();

    // Add class to buttons
    $('div.buttons :button, div.buttons :submit, div.buttons a, input[type=button], input[type=submit]').addClass('ui-corner-all ui-state-default');

    // Add hover feedback to all buttons
    $('div.buttons :button, div.buttons :submit, div.buttons a, input[type=button], input[type=submit]').hover(function() {
        $(this).addClass('ui-state-hover');
    }, function() {
        $(this).removeClass('ui-state-hover');
    });

    $('.datepicker').datepicker({
        dateFormat: 'dd/mm/yy',
        changeMonth: true,
        changeYear: true

    });
    
    $('.datepickerDob').datepicker({
        dateFormat: 'dd/mm/yy',
        changeMonth: true,
        changeYear: true,
        yearRange: '-100:-10',
        defaultDate: '-30y'

    });


    //find all checkbox lists
    $(".dynamic-checkbox")
            .find(".checkBox:not(.none-above)")
            .each(function() {
                $(this).bind("click", function() {

                    //uncheck none of the above
                    if ($(this).is(':checked')) {
                        $(this)
                            .parents(".dynamic-checkbox")
                            .find(".none-above")
                            .attr('checked', false);
                    }
                });
            });

    $(".dynamic-checkbox")
            .find(".none-above")
            .click(
                function() {

                    //uncheck all checkboxes if checked
                    if ($(this).is(':checked')) {
                        $(this)
                        .parents(".dynamic-checkbox")
                        .find(".checkBox:not(.none-above)")
                        .attr('checked', false);
                    }
                });
});
