let speaking_points2=0;
let writing_points2=0;
let reading_points2=0;
let listening_points2=0;
let second_official_language_points2=0;
let education_level_points2=0;
let experience_noc_points=0;
let age_points2=0;
let arranged_employment_points2=0;
let adaptability_points2=0;

$(document).ready(function(){

  $('.speaking2').click(function(){
    speaking_points2 = ($(this).prop("checked")) ? parseInt($(this).val()) : 0;  
    if($(this).prop("checked") && speaking_points2==0){
     $('.speaking_err').show();
    }else{
     $('.speaking_err').hide();   
    }
    showPoints4();
   });

$('.writing2').click(function(){
    writing_points2 = ($(this).prop("checked")) ? parseInt($(this).val()) : 0; 
    if($(this).prop("checked") && writing_points2==0){
        $('.writing_err').show();
        }else{
        $('.writing_err').hide();   
        }
        showPoints4();
  });
   
$('.reading2').click(function(){
    reading_points2 = ($(this).prop("checked")) ? parseInt($(this).val()) : 0;
    if($(this).prop("checked") && reading_points2==0){
        $('.reading_err').show();
        }else{
        $('.reading_err').hide();   
        }
        showPoints4();
 });

 $('.listening2').click(function(){
    listening_points2 = ($(this).prop("checked")) ? parseInt($(this).val()) : 0;
    if($(this).prop("checked") && listening_points2==0){
        $('.listening_err').show();
        }else{
        $('.listening_err').hide();   
        }
        showPoints4();
 });

$('.second_official_language2').click(function(){
    second_official_language_points2 = ($(this).prop("checked")) ? parseInt($(this).val()) : 0;
    showPoints4();
   });

$('.education_level2').change(function(){ 
    education_level_points2 = parseInt($(this).val());
    showPoints4();
   });
 
$('.experience_noc').change(function(){
    experience_noc_points = parseInt($(this).val());
    showPoints4();
   });  

$('.age_while').change(function(){ 
    age_points2 = parseInt($(this).val());
    showPoints4();
   });

$('.arranged_employment2').click(function(){
    arranged_employment_points2 = ($(this).prop("checked")) ? parseInt($(this).val()) : 0;
    showPoints4();
   });
 
$('.adaptability2').click(function(){
    adaptability_points2 = 0;
    var input = document.getElementsByName("adaptability2[]");  
    for(var i=0;i<input.length;i++) {
    if(input[i].checked){ 
        adaptability_points2 += parseInt(input[i].value);
    }}
    adaptability_points2 = (adaptability_points2 > 10) ? 10 : adaptability_points2;
    showPoints4();
   }); 
});

showPoints4 = ()=>{
 let final_points=0;
 final_points = speaking_points2+writing_points2+reading_points2+listening_points2+second_official_language_points2+education_level_points2+experience_noc_points+age_points2+arranged_employment_points2+adaptability_points2;   
 $('.final_points').val(final_points);
}