// This script gets the best rates on products from arrays
// in 2irates.js

// Best GIC Rate (bestGIC)

annBest = best_GIC_Annually[1];
semBest = best_GIC_SemiAnnual[1];
quaBest = best_GIC_Quarterly[1];
monBest = best_GIC_Monthly[1];
var yearGICann = 0; var yearGICsem = 0; var yearGICqua = 0; var yearGICmon = 0;
yearGIC = 1;

for (count = 2; count < 6; count++) {
	if (annBest < best_GIC_Annually[count]) { annBest = best_GIC_Annually[count]; yearGICann = count; }
	if (semBest < best_GIC_SemiAnnual[count]) { semBest = best_GIC_SemiAnnual[count]; yearGICsem = count; }
	if (quaBest < best_GIC_Quarterly[count]) { quaBest = best_GIC_Quarterly[count]; yearGICqua = count; }
	if (monBest < best_GIC_Monthly[count]) { monBest = best_GIC_Monthly[count]; yearGICmon = count; }
}

freqGIC = 'Annually';
yearGIC = yearGICann;
bestGIC = annBest;
if (semBest > bestGIC) { bestGIC = semBest; freqGIC = 'Semi-Annual'; yearGIC = yearGICsem; }
if (quaBest > bestGIC) { bestGIC = quaBest; freqGIC = 'Quarterly'; yearGIC = yearGICqua; }
if (monBest > bestGIC) { bestGIC = monBest; freqGIC = 'Monthly'; yearGIC = yearGICmon; }

// Best Max Rate

yearMaxRate = 1;
bestMax = best_GIC_MaxRate[1];
for (count = 2; count < 6; count ++) {
	if (bestMax < best_GIC_MaxRate[count]) { bestMax = best_GIC_MaxRate[count]; yearMaxRate = count; }}
	

// Best term deposit (bestTerm)

var bestTerm = best_Term[1]; 
var numYrs = 1;
var yearTerm = '30-59 Days';
for(count = 2; count < 7; count++) {
	if (bestTerm < best_Term[count]) { bestTerm = best_Term[count]; numYrs = count; }
}
	 if (numYrs == 2) { yearTerm = '60-89 Days'; }
else if (numYrs == 3) { yearTerm = '90-119 Days'; }
else if (numYrs == 4) { yearTerm = '120-179 Days'; }
else if (numYrs == 5) { yearTerm = '180-269 Days'; }
else if (numYrs == 6) { yearTerm = '270-364 Days'; }

// Best RRSP (bestRRSP)

bestRRSP = best_RSP[1]; yearRRSP = 1;
for(count = 2; count < 6; count++) {
	if (bestRRSP < best_RSP[count]) { bestRRSP = best_RSP[count]; yearRRSP = count; }
}

// Best RRIF (bestRRIF)

bestRRIF = best_RIF[1]; yearRRIF = 1;
for(count = 2; count < 8; count++) {
	if (bestRRIF < best_RIF[count]) { bestRRIF = best_RIF[count]; yearRRIF = count; }
}
if (yearRRIF == 6) { yearRRIF = 10; } 
else if (yearRRIF == 7) { yearRRIF = 20; }