let education_level_and_training_points=0;
let work_experience_last_points=0;
let work_experience_prior_points=0;
let first_language_ability_points=0;
let second_language_ability_points=0;
let age_points=0;

let high_skilled_employment_points=0;
let close_family_relative_points=0;
let experience_in_saskatchewan_points=0;
let past_student_experience_points=0;

$(document).ready(function(){

  $('.education_level_and_training').click(function(){
    education_level_and_training_points = ($(this).prop("checked")) ? parseInt($(this).val()) : 0;
    labourMarketPoints();
  });

  $('.work_experience_last').click(function(){
    work_experience_last_points = ($(this).prop("checked")) ? parseInt($(this).val()) : 0;  
    labourMarketPoints();
   });

$('.work_experience_prior').click(function(){
    work_experience_prior_points = ($(this).prop("checked")) ? parseInt($(this).val()) : 0; 
    labourMarketPoints();
  });
   
$('.first_language_ability').click(function(){
    first_language_ability_points = ($(this).prop("checked")) ? parseInt($(this).val()) : 0;
    labourMarketPoints();
 });
 
$('.second_language_ability').click(function(){
    second_language_ability_points = ($(this).prop("checked")) ? parseInt($(this).val()) : 0;
    labourMarketPoints();
 }); 

 $('.age').click(function(){
    age_points = ($(this).prop("checked")) ? parseInt($(this).val()) : 0;
    labourMarketPoints();
 });

// ###########################################################################

$('.high_skilled_employment').click(function(){
  high_skilled_employment_points = ($(this).prop("checked")) ? parseInt($(this).val()) : 0;
  connectionToSaskatchewan();
});

$('.close_family_relative').click(function(){
  close_family_relative_points = ($(this).prop("checked")) ? parseInt($(this).val()) : 0;
  connectionToSaskatchewan();
});

$('.experience_in_saskatchewan').click(function(){
  experience_in_saskatchewan_points = ($(this).prop("checked")) ? parseInt($(this).val()) : 0;
  connectionToSaskatchewan();
});

$('.past_student_experience').click(function(){
  past_student_experience_points = ($(this).prop("checked")) ? parseInt($(this).val()) : 0;
  connectionToSaskatchewan();
});

});

labourMarketPoints = ()=>{ 
  let final_points=0;
  final_points = education_level_and_training_points+work_experience_last_points+work_experience_prior_points+first_language_ability_points+second_language_ability_points+age_points;  
  $('.labour_market_points').val(final_points);
  showPoints3();
}

connectionToSaskatchewan = ()=>{
  let final_points=0;
  final_points = high_skilled_employment_points+close_family_relative_points+experience_in_saskatchewan_points+past_student_experience_points;  
  final_points = (final_points>30) ? 30 : final_points;
  $('.connection_to_saskatchewan').val(final_points);
  showPoints3();
}

showPoints3 = ()=>{
  let labour_market_points = ($('.labour_market_points').val()=="") ? 0 : parseInt($('.labour_market_points').val());
  let connection_to_saskatchewan = ($('.connection_to_saskatchewan').val()=="") ? 0 : parseInt($('.connection_to_saskatchewan').val());
  $('.final_points').val(labour_market_points+connection_to_saskatchewan);
}