-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
184 lines (153 loc) · 7.08 KB
/
script.js
File metadata and controls
184 lines (153 loc) · 7.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
// JavaScript for DHS WTP Calculator
document.addEventListener('DOMContentLoaded', function() {
// Initialize the calculator
const calculateBtn = document.getElementById('calculate-btn');
const resultsContainer = document.getElementById('results-container');
// Add event listener to calculate button
if (calculateBtn) {
calculateBtn.addEventListener('click', calculateOptions);
}
// Initialize accordion functionality
initAccordion();
// Smooth scrolling for anchor links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function(e) {
e.preventDefault();
const targetId = this.getAttribute('href');
const targetElement = document.querySelector(targetId);
if (targetElement) {
window.scrollTo({
top: targetElement.offsetTop - 80,
behavior: 'smooth'
});
}
});
});
});
// Function to calculate WTP options based on user inputs
function calculateOptions() {
// Get user inputs
const annualSalary = parseFloat(document.getElementById('annual-salary').value) || 0;
const yearsService = parseFloat(document.getElementById('years-service').value) || 0;
const monthsService = parseFloat(document.getElementById('months-service').value) || 0;
const annualLeave = parseFloat(document.getElementById('annual-leave').value) || 0;
const sickLeave = parseFloat(document.getElementById('sick-leave').value) || 0;
const leaveCategory = parseInt(document.getElementById('leave-category').value) || 8;
// Calculate total service in years
const totalService = yearsService + (monthsService / 12);
// Calculate monthly salary
const monthlySalary = annualSalary / 12;
// Calculate hourly rate (assuming 2080 work hours per year)
const hourlyRate = annualSalary / 2080;
// Calculate DRP value (approximately 5 months of salary)
const drpMonths = 5;
const drpSalaryValue = monthlySalary * drpMonths;
// Calculate leave accrual during DRP period
// Bi-weekly pay periods in 5 months = approximately 10
const leaveAccrualHours = leaveCategory * 10;
// Calculate annual leave payout
const annualLeavePayout = annualLeave * hourlyRate;
// Calculate VERA eligibility
const veraEligible = (totalService >= 20);
const yearsNeededForVera = veraEligible ? 0 : (20 - totalService).toFixed(2);
// Calculate VSIP value (capped at $25,000)
const vsipValue = 25000;
// Calculate severance pay
let severancePay = 0;
if (totalService <= 10) {
// One week's salary per year for first 10 years
severancePay = (annualSalary / 52) * totalService;
} else {
// One week's salary per year for first 10 years + two weeks' salary per year over 10
const firstTenYears = (annualSalary / 52) * 10;
const overTenYears = (annualSalary / 26) * (totalService - 10);
severancePay = firstTenYears + overTenYears;
}
// Cap severance at one year's salary
severancePay = Math.min(severancePay, annualSalary);
// Calculate combination value
const comboValue = drpSalaryValue + vsipValue;
// Update the results in the DOM
updateResults({
annualSalary,
monthlySalary,
drpMonths,
drpSalaryValue,
leaveAccrualHours,
annualLeavePayout,
veraEligible,
yearsNeededForVera,
vsipValue,
severancePay,
comboValue
});
// Show results section
document.getElementById('results-container').classList.remove('hidden');
// Scroll to results
document.getElementById('results').scrollIntoView({
behavior: 'smooth',
block: 'start'
});
}
// Function to update results in the DOM
function updateResults(data) {
// Format currency values
const formatCurrency = (value) => {
return new Intl.NumberFormat('en-US', {
style: 'currency',
currency: 'USD',
maximumFractionDigits: 0
}).format(value);
};
// Update DRP values
document.getElementById('drp-months').textContent = data.drpMonths + '+';
document.getElementById('drp-salary').textContent = formatCurrency(data.drpSalaryValue);
document.getElementById('drp-value').textContent = formatCurrency(data.drpSalaryValue);
document.getElementById('drp-leave-accrual').textContent = data.leaveAccrualHours;
document.getElementById('drp-leave-payment').textContent = formatCurrency(data.annualLeavePayout);
// Update VERA values
if (data.veraEligible) {
document.getElementById('vera-eligibility').textContent = 'Eligible';
document.getElementById('vera-eligibility').className = 'eligibility eligible';
document.getElementById('vera-value').textContent = 'Varies based on annuity calculation';
document.getElementById('vera-years-needed').parentElement.style.display = 'none';
} else {
document.getElementById('vera-eligibility').textContent = 'Not Eligible';
document.getElementById('vera-eligibility').className = 'eligibility not-eligible';
document.getElementById('vera-value').textContent = 'N/A';
document.getElementById('vera-years-needed').textContent = data.yearsNeededForVera;
document.getElementById('vera-years-needed').parentElement.style.display = 'block';
}
// Update VSIP values
document.getElementById('vsip-payment').textContent = formatCurrency(data.vsipValue);
document.getElementById('vsip-value').textContent = formatCurrency(data.vsipValue);
document.getElementById('vsip-severance').textContent = formatCurrency(data.severancePay);
document.getElementById('vsip-leave-payment').textContent = formatCurrency(data.annualLeavePayout);
// Update Combination values
document.getElementById('combo-drp').textContent = formatCurrency(data.drpSalaryValue);
document.getElementById('combo-vsip').textContent = formatCurrency(data.vsipValue);
document.getElementById('combo-value').textContent = formatCurrency(data.comboValue) + '+';
document.getElementById('combo-leave-payment').textContent = formatCurrency(data.annualLeavePayout);
// Update recommendation text
document.getElementById('recommendation-text').textContent =
`With your annual salary of ${formatCurrency(data.annualSalary)}, the DRP option provides approximately ${formatCurrency(data.drpSalaryValue)} in continued salary alone, which is ${data.drpSalaryValue > data.vsipValue ? 'significantly more than' : 'comparable to'} the maximum VSIP payment (${formatCurrency(data.vsipValue)}). ${data.drpSalaryValue > data.vsipValue * 2 ? 'The financial advantage of the DRP option is very pronounced at your salary level.' : ''}`;
}
// Function to initialize accordion functionality
function initAccordion() {
const accordionItems = document.querySelectorAll('.accordion-item');
accordionItems.forEach(item => {
const header = item.querySelector('.accordion-header');
if (header) {
header.addEventListener('click', () => {
// Toggle active class on clicked item
item.classList.toggle('active');
// Close other accordion items
accordionItems.forEach(otherItem => {
if (otherItem !== item && otherItem.classList.contains('active')) {
otherItem.classList.remove('active');
}
});
});
}
});
}