function CurrencyFormatted(amount) { var i = parseFloat(amount); if(isNaN(i)) { i = 0.00; } var minus = ''; if(i < 0) { minus = '-'; } i = Math.abs(i); i = parseInt((i + .005) * 100); i = i / 100; s = new String(i); if(s.indexOf('.') < 0) { s += '.00'; } if(s.indexOf('.') == (s.length - 2)) { s += '0'; } s = minus + s; return s; } function sayHello() { alert("Hello"); } function validate(id) { var inputTotal = document.getElementById('tot_' + id); var inputRepay = document.getElementById('rep_' + id); inputRepay.style.backgroundColor = '#ffdddd'; inputTotal.style.backgroundColor = '#ffdddd'; // blank-out non-numeric illegal entries if((inputTotal.value*1)>0) { inputTotal.style.backgroundColor = '#ffffff'; } else {inputTotal.value="";} if((inputRepay.value*1)>0) { inputRepay.style.backgroundColor = '#ffffff'; } else {inputRepay.value="";} if ((inputTotal.value+inputRepay.value)==0) { inputTotal.value=''; inputRepay.value=''; inputTotal.style.backgroundColor = '#ffffff'; inputRepay.style.backgroundColor = '#ffffff'; } DoCalc(); } function round(num) { return Math.round(num * 100) / 100; } function DoCalc() { var SubPrimeRate = 0.079; var PrimeRate = 0.079; var TotalOwed = 0; var TotalRepayment = 0; for (i=1;i 0)?("£" + NewTotalRepayment):(""); document.getElementById("couldBePaying").innerHTML = (TotalRepayment > 0)?("Your monthly repayments could be:"):(""); document.getElementById("savingYou").innerHTML = (TotalRepayment - NewTotalRepayment > 0)?("A monthly saving of"):("Increase the repayment period for lower monthly payments"); document.getElementById("savingYouAmount").innerHTML = (TotalRepayment - NewTotalRepayment > 0)?("£" + CurrencyFormatted(TotalRepayment - NewTotalRepayment)):(""); //alert(document.getElementById('couldBePaying').innerHTML); return false; } function getCurrentNumber() { return parseInt(document.forms["consolidator"].otherCount.value); } function incrementCurrent() { current = parseInt(document.forms["consolidator"].otherCount.value); document.forms["consolidator"].otherCount.value = current + 1; } function addRow() { var rowIndex = getCurrentNumber() + 1; var theTable = document.getElementById('AmountsTable'); var newRow = document.createElement('TR'); var newCell = document.createElement('TD'); newCell.setAttribute("className", "consoleBodyText"); newCell.setAttribute("class", "consoleBodyText"); //NS var newCell2 = document.createElement('TD'); newCell2.setAttribute("className", "consoleBodyText"); newCell2.setAttribute("class", "consoleBodyText"); //NS newCell2.innerHTML = "£ "; var newCell3 = document.createElement('TD'); newCell3.setAttribute("className", "consoleBodyText"); newCell3.setAttribute("class", "consoleBodyText"); //NS newCell3.innerHTML = "£ "; // add new table row to table newRow.appendChild(newCell); newRow.appendChild(newCell2); newRow.appendChild(newCell3); theTable.tBodies[0].appendChild(newRow); incrementCurrent(); } function checkDebtConsoleZero(console){ if(console.CalcTotalOwed.value == 0) { alert("Your total outstanding debt is zero!"); return false; } else if (console.CalcTotalRepayments.value == 0) { alert("Your total monthly repayment is zero!"); return false; } else { //validate entered amounts var inputTotal; var inputRepay; var inputsCount = getCurrentNumber(); var loop; //loop through amounts for(loop = 1 ; loop <= inputsCount ; loop ++) { inputTotal = document.getElementById('tot_' + loop); inputRepay = document.getElementById('rep_' + loop); //check colours of tabs if(inputTotal.value > 0) { if(inputRepay.value == "") { alert("You must provide a monthly repayment for each outstanding debt!"); inputRepay.focus(); return false; } } if(inputRepay.value > 0) { if(inputTotal.value == "") { alert("You must provide a monthly repayment for each outstanding debt!"); inputTotal.focus(); return false; } } } consolidator.submit(); } }