let hourly_wage=0;
let hours_week=0;
let skill_level_points=0;
let post_secondary_points=0;
let occupation_identified_points=0;
let currently_working_in_bc_points=0;
let wage_points=0;
let area_of_employment_points=0;
let work_experience_points=0;
let experience_in_canada_points=0;
let education_level_points=0;
let secondary_education_points=0;
let eligible_professional_desig_points=0;
let industry_training_points=0;
let language_points=0;
let scored_clb_higher_points=0;
let graduated_from_public_points=0;
let fulltime_equivalent_outside_points=0;

$(document).ready(function(){

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

// HIGHEST LEVEL OF EDUCATION POINTS
  $('.high_level_education').click(function(){
    $('#post_secondary').hide();  
    post_secondary_points=0;
    $('.post_secondary').prop("checked",false);
    if($(this).prop("checked") && $(this).val()=="yes"){
     $('#post_secondary').show();
    }else{
     $('#post_secondary').hide();
     post_secondary_points=0;
     $('.post_secondary').prop("checked",false);
     $('.post_secondary').data('waschecked', false);
    }   
   showSirsPoints();
  });

// POST SECONDARY EDUCATION 
  $('.post_secondary').click(function(){
    post_secondary_points = ($(this).prop("checked")) ? parseInt($(this).val()) : 0;  
    showSirsPoints();
   });
   
// FRENCH PROFIENCY POINTS
  $('.french_proficiency').click(function(){
    $('#scored_clb_higher').hide();  
    scored_clb_higher_points=0;
    $('.scored_clb_higher').prop("checked",false);
    if($(this).prop("checked") && $(this).val()=="yes"){
     $('#scored_clb_higher').show();
    }else{
     $('#scored_clb_higher').hide();
     scored_clb_higher_points=0;
     $('.scored_clb_higher').prop("checked",false);
     $('.scored_clb_higher').data('waschecked', false);
    }   
   showSirsPoints();
  });

// SCORED CLB HIGHER 
  $('.scored_clb_higher').click(function(){
    scored_clb_higher_points = ($(this).prop("checked")) ? parseInt($(this).val()) : 0;  
    showSirsPoints();
   });  
   
// Did you graduated from Public B.C Post Secondary Institution located outside Area 1 within last 3 years?*  
$('.graduated_from_public').click(function(){
    graduated_from_public_points = ($(this).prop("checked")) ? parseInt($(this).val()) : 0;
    showSirsPoints();
   });
   
// Have you worked 1 year fulltime or equivalent outside of Area 1 within 5 years?*
$('.fulltime_equivalent_outside').click(function(){
    fulltime_equivalent_outside_points = ($(this).prop("checked")) ? parseInt($(this).val()) : 0;
    showSirsPoints();
   });   

// Is your Occupation identified in the Top 100 occupations in the BC Labour Market Outlook 2014-2024 ?  
$('.occupation_identified').click(function(){
    occupation_identified_points = ($(this).prop("checked")) ? parseInt($(this).val()) : 0; 
    showSirsPoints();
  });
   
// Are you Currently working in B.C. for the employer in occupation identified in the BC PNP registration?  
$('.currently_working_in_bc').click(function(){
    currently_working_in_bc_points = ($(this).prop("checked")) ? parseInt($(this).val()) : 0;
    showSirsPoints();
   });
   
$('.hourly_wage').change(function(){
    hourly_wage = parseInt($(this).val());
    if(hourly_wage>=10 && hourly_wage<=100){
        $('#currency_code').show();
        $('#wage_err').hide();
    }else{
        hourly_wage = 0;
        $('#wage_err').show();
        $(this).focus();
    }
    calculate();
}); 
$('.hours_week').change(function(){
    hours_week = parseInt($(this).val());
    if(hours_week<=80){
        $('#week_err').hide();
    }else{
        hours_week = 0;
        $('#week_err').show();
        $(this).focus();
    }
    calculate();
}); 

 // Regional District of Employment points are:  
$('.area_of_employment').click(function(){
    area_of_employment_points = ($(this).prop("checked")) ? parseInt($(this).val()) : 0;
    showSirsPoints();
   });

$('.work_experience').click(function(){
    work_experience_points = ($(this).prop("checked")) ? parseInt($(this).val()) : 0;
    showSirsPoints();
   });

$('.experience_in_canada').click(function(){
    experience_in_canada_points = ($(this).prop("checked")) ? parseInt($(this).val()) : 0;
    showSirsPoints();
   });

$('.education_level').click(function(){
    education_level_points = ($(this).prop("checked")) ? parseInt($(this).val()) : 0;
    showSirsPoints();
   });
 
$('.secondary_education').click(function(){
    secondary_education_points = ($(this).prop("checked")) ? parseInt($(this).val()) : 0;
    showSirsPoints();
   }); 
   
   $('.eligible_professional_desig').click(function(){
    eligible_professional_desig_points = ($(this).prop("checked")) ? parseInt($(this).val()) : 0;
    showSirsPoints();
   }); 
   
   $('.industry_training').click(function(){
    industry_training_points = ($(this).prop("checked")) ? parseInt($(this).val()) : 0;
    showSirsPoints();
   }); 

   $('.language').click(function(){
    language_points = ($(this).prop("checked")) ? parseInt($(this).val()) : 0;
    showSirsPoints();
   });    
   

});

calculate = ()=>{
  let score = 0;
  score = hourly_wage;
  if(score>=70.00){
   wage_points = 55;
  }else if(score >= 69.00 && score <= 69.99){
   wage_points = 54;
  }else if(score >= 68.00 && score <= 68.99){
    wage_points = 53;
   }else if(score >= 67.00 && score <= 67.99){
    wage_points = 52;
   }else if(score >= 66.00 && score <= 66.99){
    wage_points = 51;
   }else if(score >= 65.00 && score <= 65.99){
    wage_points = 50;
   }else if(score >= 64.00 && score <= 64.99){
    wage_points = 49;
   }else if(score >= 63.00 && score <= 63.99){
    wage_points = 48;
   }else if(score >= 62.00 && score <= 62.99){
    wage_points = 47;
   }else if(score >= 61.00 && score <= 61.99){
    wage_points = 46;
   }else if(score >= 60.00 && score <= 60.99){
    wage_points = 45;
   }else if(score >= 59.00 && score <= 59.99){
    wage_points = 44;
   }else if(score >= 58.00 && score <= 58.99){
   wage_points = 43;
  }else if(score >= 57.00 && score <= 57.99){
   wage_points = 42;
  }else if(score >= 56.00 && score <= 56.99){
   wage_points = 41;
  }else if(score >= 55.00 && score <= 55.99){
   wage_points = 40;
  }else if(score >= 54.00 && score <= 54.99){
   wage_points = 39;
  }else if(score >= 53.00 && score <= 53.99){
   wage_points = 38;
  }else if(score >= 52.00 && score <= 52.99){
   wage_points = 37;
  }else if(score >= 51.00 && score <= 51.99){
   wage_points = 36;
  }else if(score >= 50.00 && score <= 50.99){
   wage_points = 35;
  }else if(score >= 49.00 && score <= 49.99){
    wage_points = 34;
   }else if(score >= 48.00 && score <= 48.99){
    wage_points = 33;
   }else if(score >= 47.00 && score <= 47.99){
   wage_points = 32;
  }else if(score >= 46.00 && score <= 46.99){
   wage_points = 31;
  }else if(score >= 45.00 && score <= 45.99){
   wage_points = 30;
  }else if(score >= 44.00 && score <= 44.99){
   wage_points = 29;
  }else if(score >= 43.00 && score <= 43.99){
   wage_points = 28;
  }else if(score >= 42.00 && score <= 42.99){
   wage_points = 27;
  }else if(score >= 41.00 && score <= 41.99){
   wage_points = 26;
  }else if(score >= 40.00 && score <= 40.99){
   wage_points = 25;
  }else if(score >= 39.00 && score <= 39.99){
   wage_points = 24;
  }else if(score >= 38.00 && score <= 38.99){
    wage_points = 23;
   }else if(score >= 37.00 && score <= 37.99){
    wage_points = 22;
   }else if(score >= 36.00 && score <= 36.99){
    wage_points = 21;
   }else if(score >= 35.00 && score <= 35.99){
   wage_points = 20;
  }else if(score >= 34.00 && score <= 34.99){
   wage_points = 19;
  }else if(score >= 33.00 && score <= 33.99){
   wage_points = 18;
  }else if(score >= 32.00 && score <= 32.99){
   wage_points = 17;
  }else if(score >= 31.00 && score <= 31.99){
   wage_points = 16;
  }else if(score >= 30.00 && score <= 30.99){
   wage_points = 15;
  }else if(score >= 29.00 && score <= 29.99){
   wage_points = 14;
  }else if(score >= 28.00 && score <= 28.99){
   wage_points = 13;
  }else if(score >= 27.00 && score <= 27.99){
   wage_points = 12;
  }else if(score >= 26.00 && score <= 26.99){
   wage_points = 11;
  }else if(score >= 25.00 && score <= 25.99){
   wage_points = 10;
  }else if(score >= 24.00 && score <= 24.99){
   wage_points = 9;
  }else if(score >= 23.00 && score <= 23.99){
   wage_points = 8;
  }else if(score >= 22.00 && score <= 22.99){
   wage_points = 7;
  }else if(score >= 21.00 && score <= 21.99){
   wage_points = 6;
  }else if(score >= 20.00 && score <= 20.99){
   wage_points = 5;
  }else if(score >= 19.00 && score <= 19.99){
   wage_points = 4;
  }else if(score >= 18.00 && score <= 18.99){
   wage_points = 3;
  }else if(score >= 17.00 && score <= 17.99){
   wage_points = 2;
  }else if(score >= 16.00 && score <= 16.99){
   wage_points = 1;
  }else if(score < 16){
    wage_points = 0;
   }
   showSirsPoints();
}

showSirsPoints = ()=>{
 let final_points=0;
 console.log(fulltime_equivalent_outside_points);
 final_points = skill_level_points+post_secondary_points+occupation_identified_points+currently_working_in_bc_points+wage_points+area_of_employment_points+work_experience_points+experience_in_canada_points+education_level_points+secondary_education_points+eligible_professional_desig_points+industry_training_points+language_points+scored_clb_higher_points+graduated_from_public_points+fulltime_equivalent_outside_points;  
  
 if(graduated_from_public_points == 10 && fulltime_equivalent_outside_points == 10){
  final_points = final_points - fulltime_equivalent_outside_points;     
 }
 $('.final_points').val(final_points);
}