var trfDeeds = 0;
var trfDuty = 0;
var trfFee = 0;
var trfPP = 0;
var trfVat = 0;
var bndSDuty = 0;
var bndDeeds = 0;
var bndFee = 0;
var bndPP = 0;
var bndVat = 0;
var price = 0;
var bond = 0;

function buyLegal() {
	trfDuty = price * 0.08;
}

function buyNatural() {
	if ( price > 1000001 ) trfDuty = (price - 1000000) * 0.08 + 25000;
	else if ( price > 500001 ) trfDuty = (price - 500000) * 0.05;
	else trfDuty = 0;
}

function calcSDuty() {
	bndSDuty = 0;
}

function calcFee() {
	if ( bond > 0 ) bndFee = 2500;
	if ( bond >= 100000.01 ) bndFee = bndFee + 100;
	if ( bond >= 125000.01 ) bndFee = bndFee + 100;
	if ( bond >= 150000.01 ) bndFee = bndFee + 200;
	if ( bond >= 175000.01 ) bndFee = bndFee + 100;
	if ( bond >= 200000.01 ) bndFee = bndFee + 300;
	if ( bond >= 250000.01 ) bndFee = bndFee + 400;
	if ( bond >= 300000.01 ) bndFee = bndFee + 400;
	if ( bond >= 350000.01 ) bndFee = bndFee + 500;
	if ( bond >= 400000.01 ) bndFee = bndFee + 400;
	if ( bond >= 450000.01 ) bndFee = bndFee + 400;
	if ( bond >= 500000.01 ) {
		if ( bond >= 5000000.01 ) {
			var increments = Math.round((bond - 5000000) / 100000);
			if ( ((increments * 100000) + 5000000) < bond ) increments++;
			bndFee = 25400 + (increments * 200);
		} else if ( bond >= 1000000.01) {
			var increments = Math.round((bond - 1000000) / 100000);
			if ( ((increments * 100000) + 1000000) < bond ) increments++;
			bndFee = 9400 + (increments * 400);
		} else {
			var increments = Math.round((bond - 500000) / 100000);
			if ( ((increments * 100000) + 500000) < bond ) increments++;
			bndFee = 5400 + (increments * 800);
		} // else
	} // if
	if ( price > 0 ) trfFee = 3200;
	if ( price >= 80000.01 ) trfFee = trfFee + 200;
	if ( price >= 90000.01 ) trfFee = trfFee + 250;
	if ( price >= 100000.01 ) trfFee = trfFee + 100;
	if ( price >= 125000.01 ) trfFee = trfFee + 150;
	if ( price >= 150000.01 ) trfFee = trfFee + 300;
	if ( price >= 175000.01 ) trfFee = trfFee + 200;
	if ( price >= 200000.01 ) trfFee = trfFee + 400;
	if ( price >= 250000.01 ) trfFee = trfFee + 700;
	if ( price >= 300000.01 ) trfFee = trfFee + 400;
	if ( price >= 350000.01 ) trfFee = trfFee + 500;
	if ( price >= 400000.01 ) trfFee = trfFee + 500;
	if ( price >= 450000.01 ) trfFee = trfFee + 600;
	if ( price >= 500000.01 ) {
		if ( price >= 5000000.01 ) {
			var increments = Math.round((price - 5000000) / 100000);
			if ( ((increments * 100000) + 5000000) < price ) increments++;
			trfFee = 32500 + (increments * 250);
		} else if ( price >= 1000000.01) {
			var increments = Math.round((price - 1000000) / 100000);
			if ( ((increments * 100000) + 1000000) < price ) increments++;
			trfFee = 12500 + (increments * 500);
		} else {
			var increments = Math.round((price - 500000) / 100000);
			if ( ((increments * 100000) + 500000) < price ) increments++;
			trfFee = 7500 + (increments * 1000);
		} // else
	} // if
}

function calcDeeds() {
	if ( bond > 0 ) bndDeeds = 260;
	if ( bond >= 150000.01 ) bndDeeds = bndDeeds + 40;
	if ( bond >= 300000.01 ) bndDeeds = bndDeeds + 100;
	if ( bond >= 500000.01 ) bndDeeds = bndDeeds + 100;
	if ( bond >= 1000000.01 ) bndDeeds = bndDeeds + 150;
	if ( bond >= 2000000.01 ) bndDeeds = bndDeeds + 350;
	if ( bond >= 5000000.01 ) bndDeeds = bndDeeds + 1000;
	if ( price > 0 ) trfDeeds = 70;
	if ( price >= 150000.01 ) trfDeeds = trfDeeds + 230;
	if ( price >= 300000.01 ) trfDeeds = trfDeeds + 100;
	if ( price >= 500000.01 ) trfDeeds = trfDeeds + 100;
	if ( price >= 1000000.01 ) trfDeeds = trfDeeds + 100;
	if ( price >= 2000000.01 ) trfDeeds = trfDeeds + 200;
	if ( price >= 3000000.01 ) trfDeeds = trfDeeds + 200;
	if ( price >= 5000000.01 ) trfDeeds = trfDeeds + 200;
}

function calcDuty() {
	price = document.getElementById('purPrice').value;
	if ( document.getElementById('Natural').checked ) buyNatural()
	else buyLegal();
	document.getElementById('TransDuty').value = trfDuty;
}

function calcBond() {
	bond = document.getElementById('bondPrice').value;
	calcFee();
	calcDeeds()
	if ( bond > 0 ) bndPP = 0;
	bndVat = (bndFee + bndPP) * 0.14;
	document.getElementById('BondsStampDuty').value = bndSDuty;
	document.getElementById('BondsDeeds').value = bndDeeds;
	document.getElementById('BondsFees').value = bndFee;
	document.getElementById('BondsPP').value = bndPP;
	document.getElementById('BondsVat').value = bndVat;
	document.getElementById('BondsTotal').value = bndSDuty + bndDeeds + bndFee + bndPP + bndVat;
}

function calcTransfer() {
	price = document.getElementById('purPrice').value;
	bond = document.getElementById('bondPrice').value;
	if ( document.getElementById('Natural').checked ) buyNatural();
	else buyLegal();
	calcFee();
	calcDeeds()
	if ( bond > 0 ) bndPP = 0;
	if ( price > 0 ) trfPP = 0;
	bndVat = (bndFee + bndPP) * 0.14;
	trfVat = (trfFee + trfPP) * 0.14;
	document.getElementById('TransDuty').value = trfDuty;
	document.getElementById('BondsStampDuty').value = bndSDuty;
	document.getElementById('TransDeeds').value = trfDeeds;
	document.getElementById('BondsDeeds').value = bndDeeds;
	document.getElementById('TransFees').value = trfFee;
	document.getElementById('BondsFees').value = bndFee;
	document.getElementById('TransPP').value = trfPP;
	document.getElementById('BondsPP').value = bndPP;
	document.getElementById('TransVat').value = trfVat;
	document.getElementById('BondsVat').value = bndVat;
	document.getElementById('TransTotal').value = trfDuty + trfDeeds + trfFee + trfPP + trfVat;
	document.getElementById('BondsTotal').value = bndSDuty + bndDeeds + bndFee + bndPP + bndVat;
}
