// JavaScript Document
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 round  (rnum) {
   
	 
	var rlength = 2; // The number of decimal places to round to
	if (rnum > 8191 && rnum < 10485) {
		rnum = rnum-5000;
		var newnumber = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength);
		newnumber = newnumber+5000;
	} else {
		var newnumber = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength);
	}

	return newnumber.toFixed(2);
	
}
		
		function calculate() {
			
	
		 
		  prix = document.getElementById("price").value;
		  
		  offer = prix * .09;
		  survey = prix * .02;
		  fees = prix * .02;
		  vat = fees * .15;
		  fees = fees + vat;
		  mortgage = prix * .028;
		  
		  ourprix = prix - 0
		  eighty = ourprix * .8;
		  
		 
		  
		  total = offer + survey + fees + mortgage + 1000;
		  ptyou = prix - total;
		  
		  document.getElementById("span1").innerHTML = "<strong>- " + formatCurrency(offer) + "</strong>";
		  document.getElementById("span2").innerHTML = "<strong>- " + formatCurrency(survey) + "</strong>";
		  document.getElementById("span3").innerHTML = "<strong>- " + formatCurrency(fees) + "</strong>";
		  document.getElementById("span4").innerHTML = "<strong>- " + formatCurrency(mortgage) + "</strong>";
		  document.getElementById("span5").innerHTML = "<strong>- " + formatCurrency(total) + "</strong>";
		  document.getElementById("span6").innerHTML = "<strong>" + formatCurrency(ptyou) + "</strong>";
		   document.getElementById("span7").innerHTML = "<strong>" + formatCurrency(eighty) + "</strong>";
		  
		  document.getElementById("maintext").innerHTML = "View the cost comparison below";
		
		}