
<!--
//Change the following variables if costs change
LegalCostIncVat = 470.00;
StepB_5 = 128;
LandChargesSearch = 8;
BankTransferFee = 35.25;
StepB_2 = 8;


function CalculateTotal() { //function to calculate form values
	//Remove any commas in the field values
	PurchaseCost = document.form1.StepA_1.value;
	PurchaseParts = PurchaseCost.split(",");
	PurchaseCost = PurchaseParts.join("");
	PurchaseCost = parseFloat(PurchaseCost);
		
	StepB_7 = 0;
	if(document.form1.StepA_2.selectedIndex == 2){
		StepB_7 = 40;
		document.form1.StepB_10.value = "N/A";
	} else if(document.form1.StepA_2.selectedIndex == 1) {
		StepB_7 = 80;
		document.form1.StepB_10.value = "See Note *";
	}
	
	//define stamp duty fee
	if (PurchaseCost <= 60000) {
		StepB_4 = 0;
	} else if (PurchaseCost <= 250000) {
		StepB_4 = PurchaseCost / 100;
	} else if (PurchaseCost <= 500000) {
		StepB_4 = (PurchaseCost / 100) * 3;
	} else {
		StepB_4 = (PurchaseCost / 100) * 4;
	}
	
	//Define land registry fee
	if (PurchaseCost <= 50000) {
		LandRegistry = 40;
	} else if (PurchaseCost <= 80000) {
		LandRegistry = 60;
	} else if (PurchaseCost <= 100000) {
		LandRegistry = 100;
	} else if (PurchaseCost <= 200000) {
		LandRegistry = 150;
	} else if (PurchaseCost <= 500000) {
		LandRegistry = 250;
	} else if (PurchaseCost <= 1000000) {
		LandRegistry = 450;
	} else {
		LandRegistry = 750;
	}
	
	//Update form Purchase field values
	if (PurchaseCost > 0 || PurchaseCost == "NaN") {
		document.form1.StepA_1.value = formatCurrency(PurchaseCost);
		document.form1.StepB_1.value = formatCurrency(LegalCostIncVat);
		document.form1.StepB_2.value = formatCurrency(StepB_2);
		document.form1.StepB_3.value = formatCurrency(LandRegistry);
		document.form1.StepB_4.value = formatCurrency(StepB_4);
		document.form1.StepB_5.value = formatCurrency(StepB_5);
		document.form1.StepB_6.value = formatCurrency(LandChargesSearch);
		document.form1.StepB_7.value = formatCurrency(StepB_7);
		document.form1.StepB_8.value = formatCurrency(BankTransferFee);
		TotalCostonPurchase = LegalCostIncVat+StepB_2+LandRegistry+StepB_4+StepB_5+LandChargesSearch+StepB_7+BankTransferFee;
		document.form1.StepB_9.value = formatCurrency(TotalCostonPurchase);
	} else {
		document.form1.StepA_1.value = 0;
		document.form1.StepB_1.value = 0;
		document.form1.StepB_2.value = 0;
		document.form1.StepB_3.value = 0;
		document.form1.StepB_4.value = 0;
		document.form1.StepB_5.value = 0;
		document.form1.StepB_6.value = 0;
		document.form1.StepB_7.value = 0;
		document.form1.StepB_8.value = 0;
		TotalCostonPurchase = 0;
		document.form1.StepB_9.value = 0;
	}
}

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 Validate() {
	if(parseFloat(document.form1.StepA_1.value) == 0 || document.form1.StepA_1.value == "") {
		alert("Please enter the purchase price!");
		return false;
	}
	if(document.form1.StepA_2.selectedIndex == 0){
		alert("Please select whether the property is leasehold or not!");
		return false;
	}
	if(document.form1.StepA_3.selectedIndex == 0){
		alert("Please select whether you are obtaining a mortgage or not!");
		return false;
	}
	if(document.form1.StepC_1.value.length < 1) {
		alert("Please enter your name!");
		return false;
	}
	if(document.form1.StepC_2.value.length < 1) {
		alert("Please enter your address!");
		return false;
	}
	if(document.form1.StepC_3.value.length < 1) {
		alert("Please enter your telephone number!");
		return false;
	}
	if(document.form1.StepC_4.value.length < 1) {
		alert("Please enter your email address!");
		return false;
	}
}

printed=false;
function setFormAction(formAction){
	if(formAction=="print"){
		oldAction=form1.action;
		oldTarget=form1.target;
		form1.action="rtb_print.html";
		form1.target="_blank";
		printed=true;
	}else if(formAction=="submit" && printed){
		form1.action=oldAction;
		form1.target=oldTarget;
		printed=true;
	}
}

