/* FILE ARCHIVED ON 9:11:00 Jan 17, 2009 AND RETRIEVED FROM THE AN OPENWAYBACK INSTANCE ON 12:09:57 May 1, 2024. JAVASCRIPT APPENDED BY OPENWAYBACK, COPYRIGHT INTERNET ARCHIVE. ALL OTHER CONTENT MAY ALSO BE PROTECTED BY COPYRIGHT (17 U.S.C. SECTION 108(a)(3)). */ /** * JavaScript functions for CFC e-Giving system allocation form * * @category CFCe * @package e-Giving * @author Dave Stevenson * @copyright 2008 Dave Stevenson, Global Impact * @license https://webarchive.library.unt.edu/eot2008/20090117091100/http://opensource.org/licenses/gpl-license.php GNU Public License * @version SVN: $Id$ * @link https://webarchive.library.unt.edu/eot2008/20090117091100/http://trac.globalimpact.net/wiki/systems/eGiving * @see https://webarchive.library.unt.edu/eot2008/20090117091100/http://www.cfcnca.org/common.js */ /** * CFCO: update salary grade and step selectora * * @returns null */ function salaryUpdate () { if (!eid('SalaryType1')) return; if (eid('SalaryType1').checked) { var grades = mgrades; eid('stepspan').style.display = 'inline'; } else if (eid('SalaryType2').checked) { var grades = cgrades; eid('stepspan').style.display = 'none'; } else var grades = Array(); var i = j = 0; eid('SalaryGradeSelect').options.length = 0; eid('SalaryGradeSelect').options[i++] = new Option('---', ''); for (var g in grades) { eid('SalaryGradeSelect').options[i] = new Option(grades[g], g); eid('SalaryGrade').value == g ? eid('SalaryGradeSelect').options[i++].selected = true : i++; } eid('SalaryStepSelect').options.length = 0; eid('SalaryStepSelect').options[j++] = new Option('---', ''); for (var s in steps) { eid('SalaryStepSelect').options[j] = new Option(steps[s], s); eid('SalaryStep').value == s ? eid('SalaryStepSelect').options[j++].selected = true : j++; } } /** * CFCO: calculate salary */ function calculateSalary () { if (!eid('SalaryType1')) return; eid('SalaryType1').checked ? 0 : eid('SalaryStep').value = '0'; var key = eid('SalaryGrade').value + eid('SalaryStep').value; eid('Salary').value = salaries[key] > 0 ? salaries[key] : 0; } /** * toggle payroll deduction options visiblity */ function payrollVisibility () { // check if this is the pledge review page or payroll deduction is not an option if (eid('review') || !eid('PayrollTR')) return; // if payroll option is checked, show related elements if (systemAbbr != 'CCG' && eid('PledgeType1') && eid('PledgeType1').checked) return MSIE ? eid('PayrollTR').style.display = 'block' : eid('PayrollTR').style.visibility = 'visible'; // payroll option is not checked, so make sure related elements are hidden MSIE ? eid('PayrollTR').style.display = 'none' : eid('PayrollTR').style.visibility = 'collapse'; // and clear payroll office number, if present eid('PayrollOffice') ? eid('PayrollOffice').value = '' : false; // and clear SSN eid('SSN').value = ''; } /** * toggle charity descriptions visibility * * @param object e = link object being clicked */ function toggleDescriptions (e) { // are we hiding or showing the descriptions? var show = e.innerHTML == 'Show descriptions' ? true : false; // update text of link object e.innerHTML = show ? 'Hide descriptions' : 'Show descriptions'; // copy list of charity codes to array var c = eid('Charities').value.split(','); // loop through charity codes, and update CSS class for each description span for (var i = 0; i < c.length; i++) eid('Description' + c[i]).className = show ? 'small' : 'nodisplay'; } /** * update occurances (for recurring gifts, the number of occurances in a year) * * @returns boolean */ function updateOccurances () { // occurances for payroll or recurring credit card gift var o; // if this is the review form, we don't have to do any of the following if (eid('PledgeType1') || eid('PledgeType4')) { // if payroll deduction, set occurances to number of pay periods if (eid('PledgeType1') && eid('PledgeType1').checked && eid('PayPeriods').value != '') o = parseFloat(eid('PayPeriods').value); else if (eid('PledgeType1') && eid('PledgeType1').value == 'ePledge' && eid('PayPeriods').value != '') o = parseFloat(eid('PayPeriods').value); // if recurring credit card, set occurances to 12 (months in a year) else if (eid('PledgeType4') && eid('PledgeType4').checked) o = 12; else o = 1; // set occurances for field value eid('Occurances').value = o; } else o = eid('Occurances').value; // copy list of charity codes to array var c = eid('Charities').value.split(','); // loop through charity codes, and update multiplier displayed on each gift basket row for (var i = 0; i < c.length; i++) eid('Occurances' + c[i]).innerHTML = o; eid('OccurancesTotal').innerHTML = o; return calculate(); } /** * validate new gift amount, and recalculate form if valid * * @param object e = form field element we're validating * @param string t = type of field ('p' = percentage, 't' = total) * * @returns boolean */ function newgift (e, t) { // if our pledge type is payroll or recurring credit card, we may need to indicate this later var per = ''; if (eid('PledgeType1') && eid('PledgeType1').checked) per = ' per pay period'; if (eid('PledgeType4') && eid('PledgeType4').checked) per = ' per month'; // value not a number? reset to zero if (!validateNumber(e)) v = 0; // parse the value as a float for performing calculations var v = parseFloat(e.value) // recurring gift may not be less than $1 if (v != 0 && (v < 1 || (t == 't' && v / parseFloat(eid('Occurances').value) < 1))) { // if it is, reset to zero and display alert v = 0; alert('Minimum gift cannot be less than $1.00' + per + '! The amount has been reset to zero.'); } // reformat value e.value = t == 'p' ? Math.floor(v) : v.toFixed(2); // set all calculated values on form return calculate(e, t); } /** * set all calculated values on form * * @param object e = form field element we're validating * @param string t = type of field ('p'=percentage, 't'=total) * * @returns boolean */ function calculate (e, t) { // copy list of charity codes to array var c = eid('Charities').value.split(','); // initialize total fields var partTotal = 0; var grandTotal = 0; var pctTotal = 0; // parse occurances of recurring gifts as float to perform calculations var o = parseFloat(eid('Occurances').value); // set occurances to 1 if it's not currently set o = o > 0 ? o : 1; // if we've changed the percentage amount for a charity if (t == 'p') { // extract the charity code code = e.name.replace('Pct', ''); // if this is the undesignated percentage amount, disallow update if (code == '99999') return die("When making percentage adjustments, remainders are applied to the Undesignated amount in order to keep the total percentage equal to 100% at all times.\n\nBecause of this, making adjustments to the undesignated percentage amount is disallowed."); // parse partial amount, perentage amount, partial total and current undeisgnated partial amount as float to perform calculations part = parseFloat(eval("eid('Part" + code + "').value")); pct = parseFloat(e.value) / 100; pt = parseFloat(eval("eid('PartTotal').value")); upart = parseFloat(eid('Part99999').value); // calculate the new partial amount for this charity npart = pt * pct; // calculate the difference between the new partial amount and old partial amount partdiff = part - npart; // apply the difference to the current undesignated partial amount upart += partdiff; // if undesignated partial amount would go less than zero, disallow update if (upart < 0) return die("Invalid percentage entered! Total exceeds 100%.\n\nWhen making percentage adjustments, remainders are applied to the Undesignated amount in order to keep the total percentage equal to 100% at all times.\n\nTo increase the percentage amount for this charity, try temporarily increasing your Undesignated dollar amount."); // calculate the new undeisgnated total utotal = upart * o; // set the new undesignated partial amount, reformatting to 2 decimals eid('Part99999').value = upart.toFixed(2); // set the new undesignated total amount, reformatting to 2 decimals eid('Total99999').value = utotal.toFixed(2); // set the new partial amount for this charity, reformatting to 2 decimals eval("eid('Part" + code + "').value = npart.toFixed(2)"); } // loop through the rows on our form for (var i = 0; i < c.length; i++) { // if we've changed the total amount for this charity, we need to update the partial amounts and percentage amounts if (t == 't') { // parse this total amount as float to perform calculations total = parseFloat(eval("eid('Total" + c[i] + "').value")); // if the field is blank, set the amount to zero if (isNaN(total)) total = 0; // calculate the partial amount for this charity part = total / o; // if there's a remainder, we need to recalculate the total for this charity if (total % o > 0) total = part.toFixed(2) * o; // add the partial amount to the partial grand total partTotal += part; // set the partial amount for this charity, reformatting to 2 decimals eval("eid('Part" + c[i] + "').value = part.toFixed(2)"); // set the total amount for this charity, reformatting to 2 decimals eval("eid('Total" + c[i] + "').value = total.toFixed(2)"); // add the total amount for this charity to the grand total grandTotal += total; } // if we've changed the partial or percentage amount, just update the totals right now else { // parse this part as float to perform calculations part = parseFloat(eval("eid('Part" + c[i] + "').value")); // if the field is blank, set the amount to zero if (isNaN(part)) part = 0; // otherwise calculate the total for this charity total = part * o; // add the amount to the partial grand total partTotal += part; // set the partial amount for this charity, reformatting to 2 decimals eval("eid('Part" + c[i] + "').value = part.toFixed(2)"); // set the total amount for this charity, reformatting to 2 decimals eval("eid('Total" + c[i] + "').value = total.toFixed(2)"); // add the total amount for this charity to the grand total grandTotal += total; } } // loop through the rows on our form again to calculate percentages for (var i = 0; i < c.length; i++) { // parse this total amount as float to perform calculations total = parseFloat(eval("eid('Total" + c[i] + "').value")); // if the field is blank, break out of this iteration if (isNaN(total)) total = 0; // calculcate the percentage of the grand total for this charity pct = total / grandTotal * 100; // add the amount to the percentage total pctTotal += pct; // if the percentage is not a number, set it to zero if (isNaN(pct)) pct = 0; // set the percentage for this charity, reformatting to integer eval("eid('Pct" + c[i] + "').value = Math.floor(pct)"); } // set the partial total and grand total, reformatting to 2 decimals eid('PartTotal').value = partTotal.toFixed(2); eid('GrandTotal').value = grandTotal.toFixed(2); // CFCO: calculate award earned, if any return calcAward(); } /** * CFCO: Calculate award earned, if any * * @returns boolean */ function calcAward () { // only do this for CFCO if (CFC == '0995') { // shortcut to award radio buttons var a = document.GiftForm.AwardButton; // parse the grand total amount as float to perform calculations var t = parseFloat(eid('GrandTotal').value); // initialize a variable to say "no award has been earned" var i = -1; // unset award values and highlight styles so no award appears selected a[0].checked = a[1].checked = a[2].checked = a[3].checked = false; eid('A0').className = eid('A1').className = eid('A2').className = eid('A3').className = 'off'; // calculate award t >= 2500 ? i = 3 : 0; t >= 1000 && t < 2500 ? i = 2 : 0; t >= 500 && t < 1000 ? i = 1 : 0; t >= 150 && t < 500 ? i = 0 : 0; // if an award has been earned, select and highlight the award on form if (i >= 0) { eid('A' + i).className = 'on'; return a[i].checked = true; } } return false; } /** * CFCNCA: Check award when award icon clicked * * @returns boolean */ function checkAward (d) { d === true ? eid('Award2').checked = true : eid('Award1').checked = true; return highlightAward(); } /** * CFCNCA: Highlight selected award * * @returns boolean */ function highlightAward () { // only do this for CFCNCA if (CFC == '0990') { // unset award highlight styles so no award appears selected eid('A1').className = eid('A2').className = ''; // highlight the appropriate award, if one is checked if (eid('Award1').checked) eid('A1').className = 'red'; if (eid('Award2').checked) eid('A2').className = 'red'; return true; } return false; } /** * CFCNCA: Display payroll partner alert * * If returning user decides to load their previous pledge and it was a payroll partner pledge, * we need to display relevant information * * @returns boolean */ function payrollPartnerAlert () { }