// JavaScript Document var offer ='';var round ='';var tax ='';var currentService; window.onload = function totalcost() { if(document.getElementById('subtotalprice')) { currentService = document.getElementById('subtotalprice').value; updateprice(); } } function updateprice() { var saving = document.getElementById('subtotalprice').value * offer; document.getElementById('saving').value = penceDoubleZero(Math.round(saving*100)/100); var aftertax = (document.getElementById('subtotalprice').value - saving) * tax; document.getElementById('vat').value = penceDoubleZero(Math.round(aftertax*100)/100); var totalwithoutMOT = document.getElementById('subtotalprice').value-saving+aftertax; document.getElementById('total').value = penceDoubleZero(totalwithoutMOT+Number(document.getElementById('additionaloptions').value)); if(document.getElementById('saving').value < 1) { document.getElementById('savingammount').style.display = "none"; } else { } } function changeservice (valuesent) { var price = currentService; var sub = document.getElementById('subtotalprice').value; var oldremoved = sub - price; var newprice = oldremoved + valuesent; document.getElementById('subtotalprice').value = newprice; currentService = valuesent; updateprice(); } function updateservice (valuesent, checked) { if(checked) { document.getElementById('additionaloptions').value = penceDoubleZero(Number(document.getElementById('additionaloptions').value)+ Number(valuesent)); } else { document.getElementById('additionaloptions').value = penceDoubleZero(Number(document.getElementById('additionaloptions').value) - Number(valuesent)); } updateprice(); } function penceDoubleZero(ammount) { var price_array= String(ammount).split("."); var pence = price_array[1]; if(price_array[1]) { if(pence.length < 2) { return String(price_array[0])+"."+String(pence)+String("0"); } else { num = Math.round(ammount*100)/100; num = num.toFixed(2); return num; } } else { return ammount; } }