$(document).ready(function() { $gotoResults = ''; if ($gotoResults == '1') { alert("Go to results"); $('#step1').hide("fast"); $('#step2').hide("fast"); $('#step3').hide("fast"); $('#step4').hide("fast"); $('#GraphResults').show("fast"); $('#block-body-2').show("fast"); governmentCostCalculator(0); generateOppCostsGraph(1); generateCurrentYearGraph(1); generateSpendingPie(1); //generateNationalDebtGraph(); } else { //alert("Start process"); $('#step1').show("fast"); $('#step2').hide("fast"); $('#step3').hide("fast"); $('#step4').hide("fast"); $('#block-body-2').hide("fast"); } }); $('#navName').bind('click',function(e) { //trackLink($('#btnStep1'), 'Calculator', 'Home Pg : Calculator : Pos1'); inputFullName = document.getElementById('fullname').value; $('#navName').removeClass('name'); $('#navName').addClass('name-fixed'); $('#navEducation').removeClass('education-fixed'); $('#navEducation').addClass('education'); $('#navAge').removeClass('age-fixed'); $('#navAge').addClass('age'); $('#navSalary').removeClass('salary-fixed'); $('#navSalary').addClass('salary'); $('#navResults').removeClass('results-fixed'); $('#navResults').addClass('results'); $('#step1').show("fast"); $('#step2').hide("fast"); $('#step3').hide("fast"); $('#step4').hide("fast"); $('#block-body-2').hide("fast"); }); $('#navEducation').bind('click',function(e) { //trackLink($('#btnStep2'), 'Calculator', 'Home Pg : Calculator : Pos2'); clickStep2(); }); $('#btnStep2').bind('click',function(e) { //trackLink(this, 'Calculator', 'Home Pg : Calculator : Pos2 : Button'); clickStep2(); }); $('#fullname').bind('keypress',function(e) { var code = (e.keyCode ? e.keyCode : e.which); if(code == 13) { //trackLink(this, 'Calculator', 'Home Pg : Calculator : Pos2 : Button'); clickStep2(); } }); $('#education').bind('keypress',function(e) { var code = (e.keyCode ? e.keyCode : e.which); if(code == 13) { //trackLink(this, 'Calculator', 'Home Pg : Calculator : Pos3 : Button'); clickStep3(); } }); $('#age').bind('keypress',function(e) { var code = (e.keyCode ? e.keyCode : e.which); if(code == 13) { //trackLink(this, 'Calculator', 'Home Pg : Calculator : Pos4 : Button'); clickStep4(); } }); $('#salary').bind('keypress',function(e) { var code = (e.keyCode ? e.keyCode : e.which); if(code == 13) { //trackLink(this, 'Calculator', 'Home Pg : Calculator : Pos5 : Button'); clickResults(); } }); $('#navAge').bind('click',function(e) { //trackLink($('#btnStep3'), 'Calculator', 'Home Pg : Calculator : Pos3'); clickStep3(); }); $('#btnStep3').bind('click',function(e) { //trackLink(this, 'Calculator', 'Home Pg : Calculator : Pos3 : Button'); clickStep3(); }); $('#navSalary').bind('click',function(e) { //trackLink($('#btnStep4'), 'Calculator', 'Home Pg : Calculator : Pos4'); clickStep4(); }); $('#btnStep4').bind('click',function(e) { //trackLink(this, 'Calculator', 'Home Pg : Calculator : Pos4 : Button'); clickStep4(); }); function IsNumeric(sText) { if (sText == '') { IsNumber = false; } else { var ValidChars = "0123456789."; var IsNumber=true; var Char; for (i = 0; i < sText.length && IsNumber == true; i++) { Char = sText.charAt(i); if (ValidChars.indexOf(Char) == -1) { IsNumber = false; } } } return IsNumber; } function formatCurrency(num) { num = num.toString().replace(/\$|\,/g,''); if(isNaN(num)) num = "0"; sign = (num == (num = Math.abs(num))); num = Math.floor(num*100+0.50000000001); cents = num%100; num = Math.floor(num/100).toString(); if(cents<10) cents = "0" + cents; for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++) num = num.substring(0,num.length-(4*i+3))+','+ num.substring(num.length-(4*i+3)); return (((sign)?'':'-') + '$' + num + '.' + cents); } function replaceAll(text, strA, strB) { while ( text.indexOf(strA) != -1) { text = text.replace(strA,strB); } return text; } function clickResults() { //alert (123); inputEducation = document.getElementById('input_education').value; inputAge = document.getElementById('input_age').value; inputSalary = document.getElementById('input_salary').value; if (inputEducation == 5) { alert('Please select your education level.'); return; } if (inputAge == "") { alert('Please enter your age.'); return; } if (! IsNumeric(inputAge)) { alert('Age must be a number.'); return; } if (inputAge < 12 ) { alert('Please enter an age of at least 12.'); return; } if (inputAge > 120 ) { alert('Age must be 120 or lower.'); return; } if (inputSalary == "") { alert('Please enter your salary.'); return; } inputSalary = replaceAll(inputSalary, "$", ""); inputSalary = replaceAll(inputSalary, ",", ""); inputSalary = replaceAll(inputSalary, " ", ""); if (! IsNumeric(inputSalary)) { alert('Please do not use letters or other non-digit characters.'); return; } //var salaryFormatted = formatCurrency(inputSalary); inputGovtItem = 0; document.calcform.submit(); } function generateResultsFromClick(inputEducation, inputAge, inputSalary) { //alert('generating results from home page click'); //alert(inputEducation); //alert(inputAge); //alert(inputSalary); inputSalary = replaceAll(inputSalary, "$", ""); inputSalary = replaceAll(inputSalary, ",", ""); inputSalary = replaceAll(inputSalary, " ", ""); var salaryFormatted = formatCurrency(inputSalary); // set dropdown on results page document.getElementById('educationOnForm').value = inputEducation; //Set program dropdown to 0 document.forms['resultsForm'].programAreaOnForm.value = 0; //set the age field on the result form document.forms['resultsForm'].ageOnForm.value = inputAge; //set salary field document.forms['resultsForm'].salaryOnForm.value = salaryFormatted; //alert(4); inputGovtItem = 0; governmentCostCalculator(inputEducation, inputAge, inputSalary, inputGovtItem, 1); //alert(5); generateOppCostsGraph(1); //alert(6); generateCurrentYearGraph(1); //alert(7); generateSpendingPie(1); //alert(4); generateExpendituresGraph(1, 750); generateNationalDebtGraph(); //alert(5); } function clickResultsOnForm(buttonGovtItem) { //alert ("at start of click results on form"); //clicked from the fields on the results page. //alert('button clicked'); inputEducation = document.getElementById('educationOnForm').value; inputAge = document.getElementById('ageOnForm').value inputSalaryOriginal = document.getElementById('salaryOnForm').value; inputSalary = replaceAll(inputSalaryOriginal, "$", ""); inputSalary = replaceAll(inputSalary, ",", ""); inputSalary = replaceAll(inputSalary, " ", ""); inputGovtItem = document.getElementById('programAreaOnForm').value; //alert("inputGovtItem = " + inputGovtItem); //alert("buttonGovtItem = " + buttonGovtItem); var animate; if (buttonGovtItem > -1 ) { inputGovtItem = buttonGovtItem; //Set program dropdown document.forms['resultsForm'].programAreaOnForm.value = inputGovtItem; } if (inputGovtItem == '') { inputGovtItem = 0; } if (inputGovtItem == 0) { var animate = 1; } else { var animate = 0; } //alert("inputEducation = " + inputEducation); //alert("inputAge = " + inputAge); //alert("inputSalary = " + inputSalary); //alert("inputGovtItem = " + inputGovtItem); if (! IsNumeric(inputSalary)) { alert('Please do not use letters or other non-digit characters.'); return; } if (! IsNumeric(inputAge)) { alert('Age Must Be A Number.'); return; } if (inputAge < 12 ) { alert('Please enter an age of at least 12.'); return; } if (inputAge > 120 ) { alert('Age must be 120 or lower.'); return; } // Set the fields in the stepwise process //document.getElementById('education').value = inputEducation; //document.forms['salaryFormFirst'].salary.value = inputSalaryOriginal; //document.forms['ageFormFirst'].age.value = inputAge; //Set the salary field on the results form var salaryFormatted = formatCurrency(inputSalary); document.forms['resultsForm'].salaryOnForm.value = salaryFormatted; governmentCostCalculator(inputEducation, inputAge, inputSalary, inputGovtItem, 1); //governmentCostCalculator(1); generateOppCostsGraph(animate); generateCurrentYearGraph(animate); //generateSpendingPie(animate); //generateNationalDebtGraph(); //save(); //$('#navName').removeClass('name-fixed'); //$('#navName').addClass('name'); //$('#navEducation').removeClass('education-fixed'); //$('#navEducation').addClass('education'); //$('#navAge').removeClass('age-fixed'); //$('#navAge').addClass('age'); //$('#navSalary').removeClass('salary-fixed'); //$('#navSalary').addClass('salary'); $('#navResults').removeClass('results'); $('#navResults').addClass('results-fixed'); $('#step1').hide("fast"); $('#step2').hide("fast"); $('#step3').hide("fast"); $('#step4').hide("fast"); $('#GraphResults').show("fast"); $('#block-body-2').show("fast"); //alert ("at end of click function: " + reportId); } $('#navResults').bind('click',function(e) { clickResults(); }); $('#btnResults').bind('click',function(e) { clickResults(); }); $('#setSalaryField').bind('click',function(e) { alert('Setting Salary.'); document.forms['salform'].salaryOnForm.value = 78945; });