let owner_experience_points=0;
let manager_experience_points=0;
let current_assets_points=0;
let net_worth_points=0;
let personal_investment_points=0;
let jobs_points=0;
let english_language_points=0;
let education_level3_points=0;
let age3_points=0;
let canada_work_experience_points=0;
let business_exploratory_points=0;
let industry_sector_points=0;
let significant_benefits_points=0;
let location_of_business_points=0;
let business_experience_points=0;
let work_experience2_points=0;
let commercial_viability_points=0;
let ownership_points=0;


$(document).ready(function(){

  $('.owner_experience').click(function(){
    owner_experience_points = ($(this).prop("checked")) ? parseInt($(this).val()) : 0;
    showPoints();
  });

  $('.manager_experience').click(function(){
    manager_experience_points = ($(this).prop("checked")) ? parseInt($(this).val()) : 0;  
    showPoints();
   });

$('.current_assets').click(function(){
    current_assets_points = ($(this).prop("checked")) ? parseInt($(this).val()) : 0; 
    showPoints();
  });
   
$('.net_worth').click(function(){
    net_worth_points = ($(this).prop("checked")) ? parseInt($(this).val()) : 0;
    showPoints();
 });

 $('.personal_investment').click(function(){
    personal_investment_points = ($(this).prop("checked")) ? parseInt($(this).val()) : 0;
    showPoints();
 });

$('.jobs').click(function(){
    jobs_points = ($(this).prop("checked")) ? parseInt($(this).val()) : 0;
    showPoints();
   });

$('.english_language').click(function(){
    let lang_point = 0;
    english_language_points = ($(this).prop("checked")) ? parseInt($(this).val()) : 0;
    showPoints();
    lang_point = ($(this).data("language")=="el3") ? 2: 0;
    $('.language_ability').val(lang_point);
   });

$('.education_level3').change(function(){
    education_level3_points = parseInt($(this).val());
    showPoints();
   });

$('.age3').click(function(){
    age3_points = ($(this).prop("checked")) ? parseInt($(this).val()) : 0;
    showPoints();
   });

   $('.canada_work_experience').click(function(){
    canada_work_experience_points = ($(this).prop("checked")) ? parseInt($(this).val()) : 0;
    showPoints();
   });
   
   $('.business_exploratory').click(function(){
    business_exploratory_points = ($(this).prop("checked")) ? parseInt($(this).val()) : 0;
    showPoints();
   });

   $('.industry_sector').click(function(){
    industry_sector_points = parseInt($(this).val());
    showPoints();
   });

   $('.significant_benefits').click(function(){
    significant_benefits_points = 0;
    var input = document.getElementsByName("significant_benefits[]");  
    for(var i=0;i<input.length;i++) {
    if(input[i].checked){ 
        significant_benefits_points += parseInt(input[i].value);
    }}
    significant_benefits_points = (significant_benefits_points > 10) ? 10 : significant_benefits_points;
    showPoints();
   }); 

   $('.location_of_business').click(function(){
    location_of_business_points = parseInt($(this).val());
    showPoints();
   });

   $('.business_experience').click(function(){
    business_experience_points = parseInt($(this).val());
    showPoints();
   });

   $('.work_experience2').click(function(){
    work_experience2_points = parseInt($(this).val());
    showPoints();
   });

   $('.commercial_viability').click(function(){
    commercial_viability_points = ($(this).prop("checked")) ? parseInt($(this).val()) : 0;
    showPoints();
   });

   $('.ownership').click(function(){
    ownership_points = ($(this).prop("checked")) ? parseInt($(this).val()) : 0;
    showPoints();
   });
 

});

showPoints = ()=>{
 let final_points=0;
 let experience = (owner_experience_points+manager_experience_points) > 24 ? 24 : (owner_experience_points+manager_experience_points);
 let business_concept = (industry_sector_points+significant_benefits_points) > 16 ? 16 : (industry_sector_points+significant_benefits_points);
 let business_work_experience = (business_experience_points+work_experience2_points) > 24 ? 24 : (business_experience_points+work_experience2_points);

 final_points = experience+current_assets_points+net_worth_points+personal_investment_points+jobs_points+english_language_points+education_level3_points+age3_points+canada_work_experience_points+business_exploratory_points+business_concept+location_of_business_points+business_work_experience+commercial_viability_points+ownership_points;   
 $('.final_points').val(final_points);
}