$(document).ready(function() {
  $('.phone-input').mask('(999)999-9999');
  $('.date-input').mask('9999-99-99');


  $('#currently_enrolled input[@type="radio"]').change(function() {
    toggleDisabled('#currently_enrolled .dependent', $('#EducationCurrentlyEnrolled1').attr('checked'));
  });

  $('#worked_at_ymca input[@type="radio"]').change(function() {
    toggleDisabled('#worked_at_ymca .dependent', $('#MiscWorkedAtYmca1').attr('checked'));
  });
  $('#relatives_at_ymca input[@type="radio"]').change(function() {
    toggleDisabled('#relatives_at_ymca .dependent', $('#MiscRelativesAtYmca1').attr('checked'));
  });
  $('#convicted input[@type="radio"]').change(function() {
    toggleDisabled('#convicted .dependent', $('#MiscConvicted1').attr('checked'));
  });
  $('#arrested input[@type="radio"]').change(function() {
    toggleDisabled('#arrested .dependent', $('#MiscArrested1').attr('checked'));
  });

  $('#ada input[@type="radio"]').change(function() {
    toggleDisabled('#ada .dependent', $('#MiscAda1').attr('checked'));
  });


  $('#basic_first_aid input[@type="checkbox"]').change(function() {
    toggleDisabled('#basic_first_aid .dependent', $(this).attr('checked'));
  });
  $('#aed input[@type="checkbox"]').change(function() {
    toggleDisabled('#aed .dependent', $(this).attr('checked'));
  });
  $('#cpr_pro input[@type="checkbox"]').change(function() {
    toggleDisabled('#cpr_pro .dependent', $(this).attr('checked'));
  });
  $('#o2 input[@type="checkbox"]').change(function() {
    toggleDisabled('#o2 .dependent', $(this).attr('checked'));
  });
  $('#lifeguard input[@type="checkbox"]').change(function() {
    toggleDisabled('#lifeguard .dependent', $(this).attr('checked'));
  });
  $('#swim_instructor input[@type="checkbox"]').change(function() {
    toggleDisabled('#swim_instructor .dependent', $(this).attr('checked'));
  });

  $('#driver_license input[@type="radio"]').change(function() {
    toggleDisabled('#driver_license .dependent', $('#DrivingLicense1').attr('checked'));
  });

  popUpCal.setDefaults({
    dateFormat:  'YMD-',
    speed: 'fast',
    autoPopUp: 'button',
    buttonImage: '/img/cal.gif',
    defaultDate: null
  });
                              
  $('.date-input').calendar();


});

  
function toggleDisabled(target, flag) {
  if(flag == 1) {
    $(target).removeAttr('disabled');
  } else {
    $(target).attr('disabled', 'disabled');
  }
}
