function computeForm(form) {
	if (form.property.value == null || form.property.value.length == 0)
		form.property.value = 0;
	if (form.amount.value == null || form.amount.value.length == 0)
		form.amount.value = 0;
	form.nswStampDuty.value = 0;
	form.vicStampDuty.value = 0;
	form.qldStampDuty.value = 0;
	form.saStampDuty.value = 0;
	form.waStampDuty.value = 0;
	form.ntStampDuty.value = 0;
	form.actStampDuty.value = 0;
	form.tasStampDuty.value = 0;
	form.nswStampDuty2.value = 0;
	form.vicStampDuty2.value = 0;
	form.qldStampDuty2.value = 0;
	form.saStampDuty2.value = 0;
	form.waStampDuty2.value = 0;
	form.ntStampDuty2.value = 0;
	form.actStampDuty2.value = 0;
	form.tasStampDuty2.value = 0;
	if (form.amount.value > 16000) {
		form.nswStampDuty.value = Math.ceil((form.amount.value-16000)/1000)*4+5;
	} else if (form.amount.value > 0) {
		form.nswStampDuty.value = 5;
	}
	if (form.property.value <= 14000) {
		form.nswStampDuty2.value = Math.ceil(form.property.value/100)*1.25;
	} else if (form.property.value <= 30000) {
		form.nswStampDuty2.value = 175+Math.ceil((form.property.value-14000)/100)*1.5;
	} else if (form.property.value <= 80000) {
		form.nswStampDuty2.value = 415+Math.ceil((form.property.value-30000)/100)*1.75;
	} else if (form.property.value <= 300000) {
		form.nswStampDuty2.value = 1290+Math.ceil((form.property.value-80000)/100)*3.5;
	} else if (form.property.value <= 1000000) {
		form.nswStampDuty2.value = 8990+Math.ceil((form.property.value-300000)/100)*4.5;
	} else {
		form.nswStampDuty2.value = 40490+Math.ceil((form.property.value-1000000)/100)*5.5;
	}
	if (form.amount.value > 10000) {
		form.vicStampDuty.value = Math.ceil((form.amount.value-10000)/200)*0.8+4;
	} else if (form.amount.value > 0) {
		form.vicStampDuty.value = 4;
	}
	if (form.property.value <= 20000) {
		form.vicStampDuty2.value = form.property.value*0.014;
	} else if (form.property.value <= 115000) {
		form.vicStampDuty2.value = 280+(form.property.value-20000)*0.024;
	} else if (form.property.value <= 870000) {
		form.vicStampDuty2.value = 2560+(form.property.value-115000)*0.06;
	} else {
		form.vicStampDuty2.value = form.property.value*5.5;
	}
	form.qldStampDuty.value = Math.ceil(form.amount.value/100)*0.4;
	if (form.property.value <= 250000) {
		form.qldStampDuty2.value = Math.ceil(form.property.value/100);
	} else if (form.property.value <= 500000) {
		form.qldStampDuty2.value = 2500+Math.ceil((form.property.value-250000)/100)*3.5;
	} else {
		form.qldStampDuty2.value = 11250+Math.ceil((form.property.value-500000)/100)*3.75;
	}
	if (form.amount.value <= 400) {
		form.saStampDuty.value = 0;
	} else if (form.amount.value <= 4000) {
		form.saStampDuty.value = 10;
	} else if (form.amount.value <= 10000) {
		form.saStampDuty.value = 10+Math.ceil((form.amount.value-4000)/100)*0.25;
	} else {
		form.saStampDuty.value = 25+Math.ceil((form.amount.value-10000)/100)*0.35;
	}
	if (form.property.value <= 12000) {
		form.saStampDuty2.value = Math.ceil(form.property.value/100);
	} else if (form.property.value <= 30000) {
		form.saStampDuty2.value = 120+Math.ceil((form.property.value-12000)/100)*2;
	} else if (form.property.value <= 50000) {
		form.saStampDuty2.value = 480+Math.ceil((form.property.value-30000)/100)*3;
	} else if (form.property.value <= 100000) {
		form.saStampDuty2.value = 1080+Math.ceil((form.property.value-50000)/100)*3.5;
	} else if (form.property.value <= 500000) {
		form.saStampDuty2.value = 2830+Math.ceil((form.property.value-100000)/100)*4;
	} else if (form.property.value <= 1000000) {
		form.saStampDuty2.value = 18830+Math.ceil((form.property.value-500000)/100)*4.5;
	} else {
		form.saStampDuty2.value = 41330+Math.ceil((form.property.value-1000000)/100)*5;
	}
	var tempProperty = form.property.value;
	form.waStampDuty.value = form.amount.value*0.0025;
	if (form.property.value > 0 && form.property.value <= 80000) {
		tempProperty = (tempProperty / 100);
		for (var i=0, k=1; tempProperty > i && tempProperty > k; i++, k++);
		form.waStampDuty2.value = eval(form.waStampDuty2.value) + (k * 1.95);
	}
	if (form.property.value > 80000 && form.property.value <= 100000) {
		tempProperty = (tempProperty - 80000) / 100;
		for (var i=0, k=1; tempProperty > i && tempProperty > k; i++, k++);
		form.waStampDuty2.value = eval(form.waStampDuty2.value) + (k * 2.85) + 1560;
	}
	if (form.property.value > 100000 && form.property.value <= 250000) {
		tempProperty = (tempProperty - 100000) / 100;
		for (var i=0, k=1; tempProperty > i && tempProperty > k; i++, k++);
		form.waStampDuty2.value = eval(form.waStampDuty2.value) + (k * 3.7) + 2130;
	}
	if (form.property.value > 250000 && form.property.value <= 500000) {
		tempProperty = (tempProperty - 250000) / 100;
		for (var i=0, k=1; tempProperty > i && tempProperty > k; i++, k++);
		form.waStampDuty2.value = eval(form.waStampDuty2.value) + (k * 4.55) + 7680;
	}
	if (form.property.value > 500000) {
		tempProperty = (tempProperty - 500000) / 100;
		for (var i=0, k=1; tempProperty > i && tempProperty > k; i++, k++);
		form.waStampDuty2.value = eval(form.waStampDuty2.value) + (k * 4.85) + 19055;
	}
	form.ntStampDuty.value = 0;
	tempProperty = form.property.value;
	tempProperty /= 1000;
	var tempP = tempProperty;
	tempProperty *= tempProperty;
	if (form.property.value <= 500000) {
		form.ntStampDuty2.value = (tempProperty*0.065)+(21*tempP);
	} else {
		form.ntStampDuty2.value = (form.property.value*0.054);
	}
	form.actStampDuty.value = 0;
	if (form.property.value == 0) {
		form.actStampDuty2.value = 0;
	} else if (form.property.value <= 1600) {
		form.actStampDuty2.value = 20;
	} else if (form.property.value <= 14000) {
		form.actStampDuty2.value = Math.ceil(form.property.value/100)*1.25;
	} else if (form.property.value <= 30000) {
		form.actStampDuty2.value = 175+Math.ceil((form.property.value-14000)/100)*1.5;
	} else if (form.property.value <= 60000) {
		form.actStampDuty2.value = 415+Math.ceil((form.property.value-30000)/100)*2;
	} else if (form.property.value <= 100000) {
		form.actStampDuty2.value = 1015+Math.ceil((form.property.value-60000)/100)*2.5;
	} else if (form.property.value <= 300000) {
		form.actStampDuty2.value = 2015+Math.ceil((form.property.value-100000)/100)*3.5;
	} else if (form.property.value <= 1000000) {
		form.actStampDuty2.value = 9015+Math.ceil((form.property.value-300000)/100)*4.5;
	} else {
		form.actStampDuty2.value = 40515+Math.ceil((form.property.value-1000000)/100)*5.5;
	}
	if (form.amount.value == 0) {
		form.tasStampDuty.value = 0;
	} else if (form.amount.value <= 8000) {
		form.tasStampDuty.value = 20;
	} else if (form.amount.value <= 10000) {
		form.tasStampDuty.value = form.amount.value*0.0025;
	} else {
		form.tasStampDuty.value = form.amount.value*0.0035-10;
	}
	if (form.property.value == 0) {
		form.tasStampDuty2.value = 0;
	} else if (form.property.value <= 1300) {
		form.tasStampDuty2.value = 20;
	} else if (form.property.value <= 10000) {
		form.tasStampDuty2.value = Math.ceil(form.property.value/100)*1.5;
	} else if (form.property.value <= 30000) {
		form.tasStampDuty2.value = Math.ceil(form.property.value/100)*2-50;
	} else if (form.property.value <= 75000) {
		form.tasStampDuty2.value = Math.ceil(form.property.value/100)*2.5-200;
	} else if (form.property.value <= 150000) {
		form.tasStampDuty2.value = Math.ceil(form.property.value/100)*3-575;
	} else if (form.property.value <= 225000) {
		form.tasStampDuty2.value = Math.ceil(form.property.value/100)*3.5-1325;
	} else {
		form.tasStampDuty2.value = Math.ceil(form.property.value/100)*4-2450;
	}
	form.nswTotalDuty.value = eval(form.nswStampDuty.value) + eval(form.nswStampDuty2.value);
	form.vicTotalDuty.value = eval(form.vicStampDuty.value) + eval(form.vicStampDuty2.value);
	form.qldTotalDuty.value = eval(form.qldStampDuty.value) + eval(form.qldStampDuty2.value);
	form.saTotalDuty.value = eval(form.saStampDuty.value) + eval(form.saStampDuty2.value);
	form.waTotalDuty.value = eval(form.waStampDuty.value) + eval(form.waStampDuty2.value);
	form.ntTotalDuty.value = eval(form.ntStampDuty.value) + eval(form.ntStampDuty2.value);
	form.actTotalDuty.value = eval(form.actStampDuty.value) + eval(form.actStampDuty2.value);
	form.tasTotalDuty.value = eval(form.tasStampDuty.value) + eval(form.tasStampDuty2.value);
	form.nswStampDuty.value = format(round(form.nswStampDuty.value));
	form.vicStampDuty.value = format(round(form.vicStampDuty.value));
	form.qldStampDuty.value = format(round(form.qldStampDuty.value));
	form.saStampDuty.value = format(round(form.saStampDuty.value));
	form.waStampDuty.value = format(round(form.waStampDuty.value));
	form.ntStampDuty.value = format(round(form.ntStampDuty.value));
	form.actStampDuty.value = format(round(form.actStampDuty.value));
	form.tasStampDuty.value = format(round(form.tasStampDuty.value));
	form.nswStampDuty2.value = format(round(form.nswStampDuty2.value));
	form.vicStampDuty2.value = format(round(form.vicStampDuty2.value));
	form.qldStampDuty2.value = format(round(form.qldStampDuty2.value));
	form.saStampDuty2.value = format(round(form.saStampDuty2.value));
	form.waStampDuty2.value = format(round(form.waStampDuty2.value));
	form.ntStampDuty2.value = format(round(form.ntStampDuty2.value));
	form.actStampDuty2.value = format(round(form.actStampDuty2.value));
	form.tasStampDuty2.value = format(round(form.tasStampDuty2.value));
	form.nswTotalDuty.value = format(round(form.nswTotalDuty.value));
	form.vicTotalDuty.value = format(round(form.vicTotalDuty.value));
	form.qldTotalDuty.value = format(round(form.qldTotalDuty.value));
	form.saTotalDuty.value = format(round(form.saTotalDuty.value));
	form.waTotalDuty.value = format(round(form.waTotalDuty.value));
	form.ntTotalDuty.value = format(round(form.ntTotalDuty.value));
	form.actTotalDuty.value = format(round(form.actTotalDuty.value));
	form.tasTotalDuty.value = format(round(form.tasTotalDuty.value));
}
function format(number) {
if (number.length > 9 && number.length <= 12) {
	number = (number.substring(0,number.length-9) + "," +
	number.substring(number.length-9,number.length-6) + "," +
	number.substring(number.length-6,number.length));
	return number;
}
if (number.length > 6 && number.length <= 9) {
	number = (number.substring(0,number.length-6) + "," +
	number.substring(number.length-6,number.length));
	return number;
}
return number;
}
function round(number) {
	var dollars = Math.floor(number);
	for (var decimalAt = 0; decimalAt < number.length; decimalAt++) {
		if (number.charAt(decimalAt)==".")
		break;
	}
	var cents = "" + Math.round(number * 100);
	cents = cents.substring(cents.length-2, cents.length);
	dollars += ((number.charAt(decimalAt+2)=="9")&&(cents=="00"))? 1 : 0;
	return (dollars + "." + cents)
}

function CheckLoan(loanform) {
	var LAmount = parseInt(loanform.LAmount.value);
	var Interest = parseFloat(loanform.Interest.value);
	var Years = parseInt(loanform.Years.value);
	var Deposit = parseInt(loanform.Deposit.value);
	if (isNaN(LAmount) || LAmount <= 0) {
		alert('You need to enter a numeric loan amount');
		return false;
	} else if (isNaN(Interest) || Interest <= 0) {
		alert('You need to enter a numeric interest rate');
		return false;
	} else if (isNaN(Years) || Years <= 0) {
		alert('You need to enter a numeric loan term, in years');
		return false;
	} else if (Years > 40) {
		alert('You need to enter a realistic loan term');
		loanform.Years.value='';
		loanform.Years.focus();
		return false;
	}
	if (isNaN(Deposit) || Deposit < 0) {
		loanform.Deposit.value = 0;
	}
	return true;
}

function doClear(results) {
	results.Payment.value='';
	results.Interest.value='';
	results.LoanSD.value='';
	results.PropSD.value='';
	results.Total.value='';
}

function CalculateLoan(loanform, results) {    var Deposit = parseInt(loanform.Deposit.value);
	var LAmount = parseInt(loanform.LAmount.value);
	var Rate = parseFloat(loanform.Interest.value);
	var Term = parseInt(loanform.Years.value);
	var Frequency = loanform.Frequency.options[loanform.Frequency.selectedIndex].value;
	var State = loanform.State.options[loanform.State.selectedIndex].value;
	var Payment,NumPays,Total;

	if (Frequency == 'Monthly') {
		Rate = Rate / 1200.0;
		NumPays = Term * 12;
	} else if (Frequency == 'Fortnightly') {
		Rate = Rate / 2600.0;
		NumPays = Term * 26;
	} else if (Frequency == 'Weekly') {
		Rate = Rate / 5200.0;
		NumPays = Term * 52;
	}
	Payment = LAmount * Rate / (1 - Math.pow((1 + Rate), -NumPays));
	Total = Payment * NumPays;

	results.Payment.value = format(RoundCents(Payment));
	document.SDForm.property.value = Deposit + LAmount;
	document.SDForm.amount.value = LAmount;
	computeForm(document.SDForm);
	results.LoanSD.value = eval('document.SDForm.'+State+'StampDuty.value');
	results.PropSD.value = eval('document.SDForm.'+State+'StampDuty2.value');
	results.Interest.value = format(RoundCents(Total - LAmount));
	results.Total.value = format(RoundCents(Total + parseFloat(results.LoanSD.value.replace('$', '')) + parseFloat(results.PropSD.value.replace('$', ''))));
}

function RoundCents(n) {
	var val = new String(Math.round(n * 100));
	var Dollars = val.substring(0, val.length-2);
	var Cents = val.substring(val.length-2);
	return (Dollars + '.' + Cents);
}

//stamp duty
function computeForm3(form) {
	//for vanuatu
	if (form.property.value == null || form.property.value.length == 0)
		form.property.value = 0;
	if (form.amount.value == null || form.amount.value.length == 0)
		form.amount.value = 0;
	form.vicStampDuty.value = 0;

	form.vicStampDuty.value = form.property.value*0.07;
	

	form.vicTotalDuty.value = eval(form.vicStampDuty.value);
	form.vicTotalDuty.value = format(round(form.vicTotalDuty.value));

}
function computeForm2(form){
computeForm5(form)
}

function computeForm4(form) {
computeForm5(form) ;
	
   if(form.property.value == null || form.property.value.length == 0)form.property.value = 0;
   if(form.amount.value == null || form.amount.value.length == 0)form.amount.value = 0;
   form.nswStampDuty.value = 0;
   form.vicStampDuty.value = 0;
   form.qldStampDuty.value = 0;
   form.actStampDuty.value = 0;
   form.saStampDuty.value = 0;
  form.waStampDuty.value = 0;
   form.ntStampDuty.value = 0;
  form.tasStampDuty.value = 0;
   form.nswStampDuty2.value = 0;
   form.vicStampDuty2.value = 0;
   form.qldStampDuty2.value = 0;
   form.actStampDuty2.value = 0;
   form.saStampDuty2.value = 0;
   form.waStampDuty2.value = 0;
   form.ntStampDuty2.value = 0;
 form.tasStampDuty2.value = 0;
   form.nswTransfer.value = 0;
   form.vicTransfer.value = 0;
   form.qldTransfer.value = 0;
   form.actTransfer.value = 0;
  form.saTransfer.value = 0;
   form.waTransfer.value = 0;
   form.ntTransfer.value = 0;
   form.tasTransfer.value = 0;
   var temp = 0;
   // VIC
   var tempAmount = parseInt(form.amount.value);
   if(form.amount.value > 0 && form.amount.value <= 25000) form.vicStampDuty2.value = tempAmount * 0.014;
   if(form.amount.value > 25000 && form.amount.value <= 130000) form.vicStampDuty2.value = 350 + ((tempAmount-25000) * 0.024);
   if(form.amount.value > 130000 && form.amount.value <= 440000) form.vicStampDuty2.value = 2870 + ((tempAmount-130000) * 0.05);
   if(form.amount.value > 440000 && form.amount.value <= 550000) form.vicStampDuty2.value = 18370 + ((tempAmount- 440000) * 0.06);
   if(form.amount.value > 550000 && form.amount.value <= 960000) form.vicStampDuty2.value = 28070 + ((tempAmount-550000) * 0.06);
   if(form.amount.value > 960000) form.vicStampDuty2.value = tempAmount * 0.055;
   //QLD
   tempAmount = parseInt(form.amount.value);
   if(tempAmount > 0 && tempAmount <= 5000) form.qldStampDuty2.value = 0;
   if(tempAmount > 5000 && tempAmount <= 105000){
	   tempAmount =tempAmount - 5000;
	   temp = Math.floor(tempAmount/100) * 1.5;
	   if (tempAmount%100 > 0){
			 temp += 1.5;
	   }
		form.qldStampDuty2.value = temp;
   }
   else if(tempAmount > 105000 && tempAmount <= 480000){
	   tempAmount = tempAmount - 105000;
	   temp = Math.floor(tempAmount/100) * 3.5;
	   if (tempAmount%100 > 0){
			 temp = temp + 3.5;
	   }
	    form.qldStampDuty2.value = temp + 1500;
   }
  else if(tempAmount > 480000 && tempAmount <= 980000){
	   tempAmount = tempAmount - 480000;
	   temp = Math.floor(tempAmount/100) * 4.5;
	   if (tempAmount%100 > 0){
			 temp += 4.5;
	   }
	   form.qldStampDuty2.value = temp +  14625;
   }
 else  if(tempAmount  > 980000){
	   tempAmount =tempAmount  - 980000;
	  temp = Math.floor(tempAmount/100) * 5.25;
	   if (tempAmount%100 > 0){
			temp += 5.25;
	   }
	   form.qldStampDuty2.value = temp +  37125;
   }
    //NSW
    tempAmount = parseInt(form.amount.value);
   if(tempAmount  > 0 && tempAmount  <= 14000){
	   temp = Math.floor(tempAmount/100) * 1.25;
	   if (tempAmount%100 > 0){
			 temp += 1.25;
	   }
	   form.nswStampDuty2.value = temp ;
   }
   else if(tempAmount > 14000 && tempAmount <= 30000){
	   tempAmount = tempAmount - 14000;
	   temp = Math.floor(tempAmount/100) * 1.5;
	   if (tempAmount%100 > 0){
			 temp += 1.5;
	   }
	    form.nswStampDuty2.value = temp + 175;
   }
  else if(tempAmount > 30000 && tempAmount <= 80000){
	   tempAmount =tempAmount  - 30000;
	   temp = Math.floor(tempAmount/100) * 1.75;
	   if (tempAmount%100 > 0){
			 temp += 1.75;
	   }
	    form.nswStampDuty2.value  = temp + 415;
   }
   else if(tempAmount > 80000 && tempAmount <= 300000){
	   tempAmount =tempAmount  - 80000;
	   temp = Math.floor(tempAmount/100) * 3.5;
	   if (tempAmount%100 > 0){
			 temp += 3.5;
	   }
	    form.nswStampDuty2.value = temp +  1290;
   }
    else if(tempAmount > 300000 && tempAmount <= 1000000){
	   tempAmount =tempAmount - 300000;
	   temp = Math.floor(tempAmount/100) * 4.5;
	   if (tempAmount%100 > 0){
			  temp += 4.5;
	   }
	    form.nswStampDuty2.value  = temp +  8990;
   }
 else  if(tempAmount > 1000000){
	   tempAmount =tempAmount  - 1000000;
	   temp = Math.floor(tempAmount/100) * 5.5;
	   if (tempAmount%100 > 0){
			temp += 5.5;
	   }
	    form.nswStampDuty2.value = temp +  40490;
   }
//ACT
    tempAmount = parseInt(form.amount.value);
   if(tempAmount  > 0 && tempAmount  <= 100000){
	   temp = Math.floor(tempAmount/100) * 2;
	   if (tempAmount%100 > 0){
			 temp += 2;
	   }
	   if(temp<20) temp=20;
	   form.actStampDuty2.value = temp ;
   }
   else if(tempAmount > 100000 && tempAmount <= 200000){
	   tempAmount = tempAmount - 100000;
	   temp = Math.floor(tempAmount/100) * 3.5;
	   if (tempAmount%100 > 0){
			 temp += 3.5;
	   }
	    form.actStampDuty2.value = temp + 2000;
   }
  else if(tempAmount > 200000 && tempAmount <=300000){
	   tempAmount =tempAmount  - 200000;
	   temp = Math.floor(tempAmount/100) * 4;
	   if (tempAmount%100 > 0){
			 temp += 4;
	   }
	    form.actStampDuty2.value  = temp + 5500;
   }
   else if(tempAmount > 300000 && tempAmount <= 500000){
	   tempAmount =tempAmount  - 300000;
	   temp = Math.floor(tempAmount/100) * 5.5;
	   if (tempAmount%100 > 0){
			 temp += 5.5;
	   }
	    form.actStampDuty2.value = temp +  9500;
   }
    else if(tempAmount > 500000 && tempAmount <= 1000000){
	   tempAmount =tempAmount - 500000;
	   temp = Math.floor(tempAmount/100) * 5.75;
	   if (tempAmount%100 > 0){
			  temp += 5.75;
	   }
	    form.actStampDuty2.value  = temp +  20500;
   }
 else  if(tempAmount > 1000000){
	   tempAmount =tempAmount  - 1000000;
	   temp = Math.floor(tempAmount/100) * 6.75;
	   if (tempAmount%100 > 0){
			temp += 6.75;
	   }
	    form.actStampDuty2.value = temp +  49250;
   }
 //SA
    tempAmount = parseInt(form.amount.value);
   if(tempAmount  > 0 && tempAmount  <= 12000){
	   temp = Math.floor(tempAmount/100) * 1;
	   if (tempAmount%100 > 0){
			 temp += 1;
	   }
	   form.saStampDuty2.value = temp ;
   }
   else if(tempAmount > 12000 && tempAmount <= 30000){
	   tempAmount = tempAmount - 12000;
	   temp = Math.floor(tempAmount/100) * 2;
	   if (tempAmount%100 > 0){
			 temp += 2;
	   }
	    form.saStampDuty2.value = temp + 120;
   }
  else if(tempAmount > 30000 && tempAmount <= 50000){
	   tempAmount =tempAmount  - 30000;
	   temp = Math.floor(tempAmount/100) * 3;
	   if (tempAmount%100 > 0){
			 temp += 3;
	   }
	    form.saStampDuty2.value  = temp + 480;
   }
   else if(tempAmount > 50000 && tempAmount <= 100000){
	   tempAmount =tempAmount  - 50000;
	   temp = Math.floor(tempAmount/100) * 3.5;
	   if (tempAmount%100 > 0){
			 temp += 3.5;
	   }
	    form.saStampDuty2.value = temp +  1080;
   }
    else if(tempAmount > 100000 && tempAmount <= 200000){
	   tempAmount =tempAmount - 100000;
	   temp = Math.floor(tempAmount/100) * 4;
	   if (tempAmount%100 > 0){
			  temp += 4;
	   }
	    form.saStampDuty2.value  = temp +  2830;
   }
    else if(tempAmount > 200000 && tempAmount <= 250000){
	   tempAmount =tempAmount - 200000;
	   temp = Math.floor(tempAmount/100) * 4.25;
	   if (tempAmount%100 > 0){
			  temp += 4.25;
	   }
	    form.saStampDuty2.value  = temp +  6830;
   }
    else if(tempAmount > 250000 && tempAmount <= 300000){
	   tempAmount =tempAmount - 250000;
	   temp = Math.floor(tempAmount/100) * 4.75;
	   if (tempAmount%100 > 0){
			  temp += 4.75;
	   }
	    form.saStampDuty2.value  = temp +  8955;
   }
    else if(tempAmount > 300000 && tempAmount <= 500000){
	   tempAmount =tempAmount - 300000;
	   temp = Math.floor(tempAmount/100) * 5;
	   if (tempAmount%100 > 0){
			  temp += 5;
	   }
	    form.saStampDuty2.value  = temp +  11330;
   }
 else  if(tempAmount > 500000){
	   tempAmount =tempAmount  - 500000;
	   temp = Math.floor(tempAmount/100) * 5.5;
	   if (tempAmount%100 > 0){
			temp += 5.5;
	   }
	    form.saStampDuty2.value = temp +  21330;
   }
 //WA
   tempAmount = parseInt(form.amount.value);
   if(tempAmount > 0 && tempAmount <= 120000){
	   temp = Math.floor(tempAmount/100) * 1.9;
	   if (tempAmount%100 > 0){
			 temp += 1.9;
	   }
		form.waStampDuty2.value = temp;
   }
   else if(tempAmount > 120000 && tempAmount <= 150000){
	   tempAmount = tempAmount - 120000;
	   temp = Math.floor(tempAmount/100) * 2.85;
	   if (tempAmount%100 > 0){
			 temp = temp + 2.85;
	   }
	    form.waStampDuty2.value = temp + 2280;
   }
  else if(tempAmount > 150000 && tempAmount <= 360000){
	   tempAmount = tempAmount - 150000;
	   temp = Math.floor(tempAmount/100) * 3.8;
	   if (tempAmount%100 > 0){
			 temp += 3.8;
	   }
	   form.waStampDuty2.value = temp +  3135;
   }
   else if(tempAmount > 360000 && tempAmount <= 725000){
	   tempAmount = tempAmount - 360000;
	   temp = Math.floor(tempAmount/100) * 4.75;
	   if (tempAmount%100 > 0){
			 temp += 4.75;
	   }
	   form.waStampDuty2.value = temp +  11115;
   }
 else  if(tempAmount  > 725000){
	   tempAmount =tempAmount  - 725000;
	  temp = Math.floor(tempAmount/100) * 5.15;
	   if (tempAmount%100 > 0){
			temp += 5.15;
	   }
	   form.waStampDuty2.value = temp +  28453;
   }
   //NT
 tempAmount = parseInt(form.amount.value);
   if(tempAmount > 0 && tempAmount <= 525000){
	   temp = tempAmount/1000;
		temp = (0.06571441 * (temp * temp)) + (15 * temp);
		form.ntStampDuty2.value = temp;
   }else{
		temp = tempAmount * 0.0495;
		form.ntStampDuty2.value = temp;
   }
//TAS
   tempAmount = parseInt(form.amount.value);
   if(tempAmount > 0 && tempAmount <= 1300) form.tasStampDuty2.value = 20;
   if(tempAmount > 1301 && tempAmount <= 10000){
	   temp = Math.floor(tempAmount/100) * 1.5;
	   if (tempAmount%100 > 0){
			 temp += 1.5;
	   }
		form.tasStampDuty2.value = temp;
   }
   else if(tempAmount > 10000 && tempAmount <= 30000){
	   tempAmount = tempAmount - 10000;
	   temp = Math.floor(tempAmount/100) * 2;
	   if (tempAmount%100 > 0){
			 temp = temp + 2;
	   }
	    form.tasStampDuty2.value = temp + 150;
   }
  else if(tempAmount > 30000 && tempAmount <= 75000){
	   tempAmount = tempAmount - 30000;
	   temp = Math.floor(tempAmount/100) * 2.5;
	   if (tempAmount%100 > 0){
			 temp += 2.5;
	   }
	   form.tasStampDuty2.value = temp +  550;
   }
   else if(tempAmount > 75000 && tempAmount <=150000){
	   tempAmount = tempAmount - 75000;
	   temp = Math.floor(tempAmount/100) * 3;
	   if (tempAmount%100 > 0){
			 temp += 3;
	   }
	   form.tasStampDuty2.value = temp + 1675;
   }
   else if(tempAmount > 150000 && tempAmount <= 225000){
	   tempAmount = tempAmount - 150000;
	   temp = Math.floor(tempAmount/100) * 3.5;
	   if (tempAmount%100 > 0){
			 temp += 3.5;
	   }
	   form.tasStampDuty2.value = temp +  3925;
   }
 else  if(tempAmount  > 225000){
	   tempAmount =tempAmount  - 225000;
	  temp = Math.floor(tempAmount/100) * 4;
	   if (tempAmount%100 > 0){
			temp += 4;
	   }
	   form.tasStampDuty2.value = temp +  6550;
   }

 form.nswStampDuty.value = format(round(form.nswStampDuty.value));
   form.vicStampDuty.value = format(round(form.vicStampDuty.value));
   form.qldStampDuty.value = format(round(form.qldStampDuty.value));
   form.actStampDuty.value = format(round(form.actStampDuty.value));
  form.saStampDuty.value = format(round(form.saStampDuty.value));
    form.waStampDuty.value = format(round(form.waStampDuty.value));
  form.ntStampDuty.value = format(round(form.ntStampDuty.value));
   form.tasStampDuty.value = format(round(form.tasStampDuty.value));
   form.nswStampDuty2.value = format(round(form.nswStampDuty2.value));
   form.vicStampDuty2.value = format(round(form.vicStampDuty2.value));
   form.qldStampDuty2.value = format(round(form.qldStampDuty2.value));
   form.actStampDuty2.value = format(round(form.actStampDuty2.value));
  form.saStampDuty2.value = format(round(form.saStampDuty2.value));
   form.waStampDuty2.value = format(round(form.waStampDuty2.value));
    form.ntStampDuty2.value = format(round(form.ntStampDuty2.value));
  form.tasStampDuty2.value = format(round(form.tasStampDuty2.value));
   form.nswTotalDuty.value =form.nswStampDuty2.value;
   form.vicTotalDuty.value = form.vicStampDuty2.value;
   form.qldTotalDuty.value = form.qldStampDuty2.value;
   form.actTotalDuty.value = form.actStampDuty2.value;
  form.saTotalDuty.value = form.saStampDuty2.value;
   form.waTotalDuty.value = form.waStampDuty2.value;
  form.ntTotalDuty.value = form.ntStampDuty2.value;
   form.tasTotalDuty.value = form.tasStampDuty2.value;
   form.nswTransfer.value = format(round(form.nswTransfer.value));
   form.vicTransfer.value = format(round(form.vicTransfer.value));
   form.qldTransfer.value = format(round(form.qldTransfer.value));
   form.actTransfer.value = format(round(form.actTransfer.value));
  form.saTransfer.value = format(round(form.saTransfer.value));
  form.waTransfer.value = format(round(form.waTransfer.value));
   form.ntTransfer.value = format(round(form.ntTransfer.value));
   form.tasTransfer.value = format(round(form.tasTransfer.value));
}

function computeForm5(form){
if(form.property.value==null||form.property.value.length==0)form.property.value=0;
if(form.amount.value==null||form.amount.value.length==0)form.amount.value=0;

 var __reg2 = $("#amount").toNumber().val();
    var __reg3 = $("#property").toNumber().val();
    var propType = false; //$('#living_property').is(':checked');
    var __reg1 = false; // $('#first_home_buyer').is(':checked');

    switch ($('#states').val()) {
        case "act-calc-amount":calculateACT(__reg2, __reg3, propType, __reg1);break;
        case "nsw-calc-amount":calculateNSW(__reg2, __reg3, propType, __reg1);break;
        case "nt-calc-amount":calculateNT(__reg2, __reg3, propType, __reg1);break;
        case "qld-calc-amount":calculateQLD(__reg2, __reg3, propType, __reg1);break;
        case "sa-calc-amount":calculateSA(__reg2, __reg3, propType, __reg1);break;
        case "tas-calc-amount":calculateTAS(__reg2, __reg3, propType, __reg1);break;
        case "vic-calc-amount":calculateVIC(__reg2, __reg3, propType, __reg1);break;
        case "wa-calc-amount":calculateWA(__reg2, __reg3, propType, __reg1);break;
    }
}

function StampDuty_recalculate()
{
    var __reg2 = calc.calcInit.getValue("amount");
    var __reg1 = calc.calcInit.getValue("property");
    if (__reg2 > __reg1 * 1.1) 
    {
        calc.calcInit.getObject("amount").setValue(__reg1 * 1.1);
    }
    notesResult.text = "";
}
function calculateACT(loan, amt, propType, firsthome)
{    
    var __reg1 = amt;
    var duty;
    var notes;
    var mortReg = 96;
    var __reg3 = 189;
    var __reg2 = 0;
    if (firsthome && propType && __reg1 < 422000)
    {
        if (__reg1 <= 349800) 
        {
            duty = 20;
        }
        else 
        {
            duty = (__reg1 - 349800) * 0.2245;
            if (duty < 20) 
            {
                duty = 20;
            }
        }
    }
    else 
    {
        if (__reg1 <= 100000) 
        {
            duty = Math.max(Math.ceil(__reg1 / 100) * 2, 20);
        }
        else 
        {
            if (__reg1 <= 200000) 
            {
                duty = Math.ceil((__reg1 - 100000) / 100) * 3.5 + 2000;
            }
            else 
            {
                if (__reg1 <= 300000) 
                {
                    duty = Math.ceil((__reg1 - 200000) / 100) * 4 + 5500;
                }
                else 
                {
                    if (__reg1 <= 500000) 
                    {
                        duty = Math.ceil((__reg1 - 300000) / 100) * 5.5 + 9500;
                    }
                    else 
                    {
                        if (__reg1 <= 1000000) 
                        {
                            duty = Math.ceil((__reg1 - 500000) / 100) * 5.75 + 20500;
                        }
                        else 
                        {
                            duty = Math.ceil((__reg1 - 1000000) / 100) * 6.75 + 49250;
                        }
                    }
                }
            }
        }
    }
    __reg2 = 0;
    notes = "- Eligibility for the home buyer concession is determined by income, the number of dependent children and property ownership in the last 2 years.\n- Home buyer concession is available for vacant blocks is determined by the value of the land.";
    display(duty, __reg2, mortReg, __reg3, notes);
}
function calculateNSW(loan, amt, propType, firsthome)
{
    var __reg1 = amt;
    var __reg3 = loan;
    var __reg2 = undefined;
    var loanduty;
    var mortReg;
    var trans;
    var notes;
    var loandutyPercentage = 1;
    mortReg = 95;
    trans = 190;
    if (firsthome && __reg1 < 600000 && propType) 
    {
        if (__reg1 <= 500000) 
        {
            __reg2 = 0;
        }
        else 
        {
            __reg2 = __reg1 * 0.2249 - 112450;
        }
    }
    else 
    {
        __reg1 = Math.ceil(__reg1 / 100) * 100;
        if (__reg1 <= 14000) 
        {
            __reg2 = __reg1 / 100 * 1.25;
        }
        else 
        {
            if (__reg1 <= 30000) 
            {
                __reg2 = (__reg1 - 14000) / 100 * 1.5 + 175;
            }
            else 
            {
                if (__reg1 <= 80000) 
                {
                    __reg2 = (__reg1 - 30000) / 100 * 1.75 + 415;
                }
                else 
                {
                    if (__reg1 <= 300000) 
                    {
                        __reg2 = (__reg1 - 80000) / 100 * 3.5 + 1290;
                    }
                    else 
                    {
                        if (__reg1 <= 1000000) 
                        {
                            __reg2 = (__reg1 - 300000) / 100 * 4.5 + 8990;
                        }
                        else 
                        {
                            if (__reg1 < 3000000) 
                            {
                                __reg2 = (__reg1 - 1000000) / 100 * 5.5 + 40490;
                            }
                            else 
                            {
                                __reg2 = (__reg1 - 3000000) / 100 * 7 + 150490;
                            }
                        }
                    }
                }
            }
        }
    }
    var modded = __reg3 % 1000;
    if (modded != 0) 
    {
        var mod = 1000 - modded;
        __reg3 = 0 - (0 - __reg3 - mod);
    }
    if (__reg3 <= 16000) 
    {
        loanduty = 5;
    }
    else 
    {
        loanduty = (__reg3 - 16000) / 1000 * 4 + 5;
    }
    if (propType) 
    {
        loandutyPercentage = 0;
    }
    loanduty = 0;
    notes = "First home buyers purchasing a vacant block of residential land may be exempt from paying stamp duty or eligible for a discount depending on the value of the land.A reduction in duty on the purchase of new homes by people who are not first home buyers may also be available. Please visit the Office of State Revenue website for more details about the Housing Construction Acceleration Plan initiative.";
    display(__reg2, loanduty, mortReg, trans, notes);
}
function calculateNT(loan, amt, propType, firsthome)
{
    var __reg2 = amt;
    var __reg1 = undefined;
    var loanduty;
    var mortReg;
    var trans;
    var __reg3 = undefined;
    mortReg = 105;
    trans = 105;
    loanduty = 0;
    __reg3 = "If property is your principal place of residence you may be eligible for a stamp duty rebate of up to $2,500. There may be stamp duty concessions available. Please contact the Territory Revenue Office for more details.";
    if (__reg2 <= 525000) 
    {
        __reg1 = 0.06571441 * Math.pow(__reg2 / 1000, 2) + 15 * (__reg2 / 1000);
    }
    else 
    {
        __reg1 = 0.0495 * __reg2;
    }
    if (firsthome && propType && __reg2 <= 750000) 
    {
        __reg1 = __reg1 - 15515.5;
    }
    if (__reg1 < 0) 
    {
        __reg1 = 0;
    }
    display(__reg1, loanduty, mortReg, trans, __reg3);
}
function calculateQLD(loan, amt, propType, firsthome)
{
    var __reg1 = amt;
    var __reg2 = undefined;
    var loanduty;
    var mortReg;
    var trans;
    var notes;
    notes = "A new first home owner transfer duty concession will be available for the purchase of vacant land, where a residence is to be constructed, and will be determined by the value of the land.";
    trans = 124.2;
    if (__reg1 > 180000) 
    {
        trans = trans + Math.ceil((__reg1 - 180000) / 10000) * 26.3;
    }
    mortReg = 124.2;
    loanduty = 0;
    if (propType) 
    {
        if (__reg1 <= 350000) 
        {
            __reg2 = Math.ceil(__reg1 / 100) * 1;
        }
        else 
        {
            if (__reg1 <= 540000) 
            {
                __reg2 = 3500 + Math.ceil((__reg1 - 350000) / 100) * 3.5;
            }
            else 
            {
                if (__reg1 <= 980000) 
                {
                    __reg2 = 10150 + Math.ceil((__reg1 - 540000) / 100) * 4.5;
                }
                else 
                {
                    __reg2 = 29950 + Math.ceil((__reg1 - 980000) / 100) * 5.25;
                }
            }
        }
        var __reg3 = 0;
        if (firsthome)
        {
            if (__reg1 < 504999.99) 
            {
                __reg3 = 8750;
            }
            else 
            {
                if (__reg1 < 509999.99) 
                {
                    __reg3 = 7875;
                }
                else 
                {
                    if (__reg1 < 514999.99) 
                    {
                        __reg3 = 7000;
                    }
                    else 
                    {
                        if (__reg1 < 519999.99) 
                        {
                            __reg3 = 6125;
                        }
                        else 
                        {
                            if (__reg1 < 524999.99) 
                            {
                                __reg3 = 5250;
                            }
                            else 
                            {
                                if (__reg1 < 529999.99) 
                                {
                                    __reg3 = 4375;
                                }
                                else 
                                {
                                    if (__reg1 < 534999.99) 
                                    {
                                        __reg3 = 3500;
                                    }
                                    else 
                                    {
                                        if (__reg1 < 539999.99) 
                                        {
                                            __reg3 = 2625;
                                        }
                                        else 
                                        {
                                            if (__reg1 < 544999.99) 
                                            {
                                                __reg3 = 1750;
                                            }
                                            else 
                                            {
                                                if (__reg1 < 549999.99) 
                                                {
                                                    __reg3 = 875;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            __reg2 = __reg2 - __reg3;
            if (__reg2 < 0) 
            {
                __reg2 = 0;
            }
        }
    }
    else 
    {
        if (__reg1 < 5000) 
        {
            __reg2 = 0;
        }
        else 
        {
            if (__reg1 <= 75000) 
            {
                __reg2 = Math.ceil((__reg1 - 5000) / 100) * 1.5;
            }
            else 
            {
                if (__reg1 <= 540000) 
                {
                    __reg2 = 1050 + Math.ceil((__reg1 - 75000) / 100) * 3.5;
                }
                else 
                {
                    if (__reg1 <= 980000) 
                    {
                        __reg2 = 17325 + Math.ceil((__reg1 - 540000) / 100) * 4.5;
                    }
                    else 
                    {
                        __reg2 = 37125 + Math.ceil((__reg1 - 980000) / 100) * 5.25;
                    }
                }
            }
        }
    }
    display(__reg2, loanduty, mortReg, trans, notes);
}
function calculateSA(loan, amt, propType, firsthome)
{
    var __reg1 = amt;
    var transfer;
    var __reg2 = undefined;
    var __reg3 = undefined;
    var mortReg;
    var loanduty;
    if (__reg1 <= 5000) 
    {
        trans = 117;
    }
    else 
    {
        if (__reg1 <= 20000) 
        {
            trans = 131;
        }
        else 
        {
            if (__reg1 <= 40000) 
            {
                trans = 146;
            }
            else 
            {
                trans = Math.ceil((__reg1 - 50000) / 10000) * 65 + 209;
            }
        }
    }
    mortReg = 117;
    __reg3 = "A First Home Buyers Grant of $4,000 is available for first home purchases with a market value of up to $400,000 and phases out for property with market values between $400,000 and $450,000 by $8 for every $100 in excess of $400,000.\n\n The FHBG is in addition to the $7,000 First Home Owner Grant.\n\n A First Home Owners Boost Scheme is available to contracts entered into on or after 14 October 2008, it provides an additional $7,000 to first home buyers purchasing an established home or $14,000 for a newly-constructed home on contracts signed before the end of June 2009.";
    __reg1 = Math.ceil(__reg1 / 100) * 100;
    if (__reg1 <= 12000) 
    {
        __reg2 = __reg1 / 100 * 1;
    }
    else 
    {
        if (__reg1 <= 30000) 
        {
            __reg2 = (__reg1 - 12000) / 100 * 2 + 120;
        }
        else 
        {
            if (__reg1 <= 50000) 
            {
                __reg2 = (__reg1 - 30000) / 100 * 3 + 480;
            }
            else 
            {
                if (__reg1 <= 100000) 
                {
                    __reg2 = (__reg1 - 50000) / 100 * 3.5 + 1080;
                }
                else 
                {
                    if (__reg1 <= 200000) 
                    {
                        __reg2 = (__reg1 - 100000) / 100 * 4 + 2830;
                    }
                    else 
                    {
                        if (__reg1 <= 250000) 
                        {
                            __reg2 = (__reg1 - 200000) / 100 * 4.25 + 6830;
                        }
                        else 
                        {
                            if (__reg1 <= 300000) 
                            {
                                __reg2 = (__reg1 - 250000) / 100 * 4.75 + 8955;
                            }
                            else 
                            {
                                if (__reg1 <= 500000) 
                                {
                                    __reg2 = (__reg1 - 300000) / 100 * 5 + 11330;
                                }
                                else 
                                {
                                    __reg2 = (__reg1 - 500000) / 100 * 5.5 + 21330;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    if (firsthome && propType) 
    {
        __reg1 = Math.ceil(__reg1 / 100) * 100;
        if (__reg1 <= 12000) 
        {
            __reg2 = __reg1 / 100 * 1;
        }
        else 
        {
            if (__reg1 <= 30000) 
            {
                __reg2 = (__reg1 - 12000) / 100 * 2 + 120;
            }
            else 
            {
                if (__reg1 <= 50000) 
                {
                    __reg2 = (__reg1 - 30000) / 100 * 3 + 480;
                }
                else 
                {
                    if (__reg1 <= 100000) 
                    {
                        __reg2 = (__reg1 - 50000) / 100 * 3.5 + 1080;
                    }
                    else 
                    {
                        if (__reg1 <= 200000) 
                        {
                            __reg2 = (__reg1 - 100000) / 100 * 4 + 2830;
                        }
                        else 
                        {
                            if (__reg1 <= 250000) 
                            {
                                __reg2 = (__reg1 - 200000) / 100 * 4.25 + 6830;
                            }
                            else 
                            {
                                if (__reg1 <= 300000) 
                                {
                                    __reg2 = (__reg1 - 250000) / 100 * 4.75 + 8955;
                                }
                                else 
                                {
                                    if (__reg1 <= 500000) 
                                    {
                                        __reg2 = (__reg1 - 300000) / 100 * 5 + 11330;
                                    }
                                    else 
                                    {
                                        __reg2 = (__reg1 - 500000) / 100 * 5.5 + 21330;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    loanduty = 0;
    display(__reg2, loanduty, mortReg, trans, __reg3);
}
function calculateTAS(loan, amt, propType, firsthome)
{
    var __reg1 = amt;
    duty;
    loanduty;
    mortReg;
    trans;
    notes;
    mortReg = 85.5;
    trans = 131;
    notes = "There may be concessions available for purchasing vacant land, depending on the value of the land.";
    if (__reg1 <= 1300) 
    {
        duty = 20;
    }
    else 
    {
        if (__reg1 <= 10000) 
        {
            duty = Math.ceil(__reg1 / 100) * 1.5;
        }
        else 
        {
            if (__reg1 <= 30000) 
            {
                duty = Math.ceil((__reg1 - 10000) / 100) * 2 + 150;
            }
            else 
            {
                if (__reg1 <= 75000) 
                {
                    duty = Math.ceil((__reg1 - 30000) / 100) * 2.5 + 550;
                }
                else 
                {
                    if (__reg1 <= 150000) 
                    {
                        duty = Math.ceil((__reg1 - 75000) / 100) * 3 + 1675;
                    }
                    else 
                    {
                        if (__reg1 <= 225000) 
                        {
                            duty = Math.ceil((__reg1 - 150000) / 100) * 3.5 + 3925;
                        }
                        else 
                        {
                            duty = Math.ceil((__reg1 - 225000) / 100) * 4 + 6550;
                        }
                    }
                }
            }
        }
    }
    notes = "";
    if (firsthome && propType) 
    {
        if (__reg1 < 140000) 
        {
            duty = 0;
        }
        else 
        {
            if (__reg1 < 350000) 
            {
                notes = "A rebate of up to $4,000 is available to First Home Owners purchasing property valued between $140,000 and $350,000. Other concessions may be available, contact the State Revenue Office for full details.";
            }
        }
    }
    if (NotesTas.length == 0) 
    {
        notes = "Other concessions may be available, contact the State Revenue Office for full details.";
    }
    loanduty = 0;
    display(duty, loanduty, mortReg, trans, notes);
}
function calculateVIC(loan, amt, propType, firsthome)
{
    var __reg1 = amt;
    var __reg3 = undefined;
    var modded;
    var __reg2 = undefined;
    var notes;
    var mortReg;
    var loanduty;
    __reg3 = Math.ceil(Math.floor(__reg1 / 1000) * 2.46 + 119.4);
    if (__reg3 > 1350) 
    {
        __reg3 = 1350;
    }
    __reg3 = Math.ceil(__reg3);
    mortReg = 98;
    loanduty = 0;
    if (propType) 
    {
        if (__reg1 <= 25000) 
        {
            __reg2 = __reg1 / 100 * 1.4;
        }
        else 
        {
            if (__reg1 > 25000 && __reg1 <= 130000) 
            {
                __reg2 = (__reg1 - 25000) / 100 * 2.4 + 350;
            }
            else 
            {
                if (__reg1 > 130000 && __reg1 <= 440000) 
                {
                    __reg2 = (__reg1 - 130000) / 100 * 5 + 2870;
                }
                else 
                {
                    if (__reg1 > 440000 && __reg1 <= 550000) 
                    {
                        __reg2 = (__reg1 - 440000) / 100 * 6 + 18370;
                    }
                    else 
                    {
                        if (__reg1 > 550000 && __reg1 <= 960000) 
                        {
                            __reg2 = (__reg1 - 550000) / 100 * 6 + 28070;
                        }
                        else 
                        {
                            __reg2 = __reg1 / 100 * 5.5;
                        }
                    }
                }
            }
        }
    }
    else 
    {
        if (__reg1 <= 25000) 
        {
            __reg2 = __reg1 / 100 * 1.4;
        }
        else 
        {
            if (__reg1 > 25000 && __reg1 <= 130000) 
            {
                __reg2 = (__reg1 - 25000) / 100 * 2.4 + 350;
            }
            else 
            {
                if (__reg1 > 130000 && __reg1 <= 960000) 
                {
                    __reg2 = (__reg1 - 130000) / 100 * 6 + 2870;
                }
                else 
                {
                    __reg2 = __reg1 / 100 * 5.5;
                }
            }
        }
    }
    notes = "- First home buyers now are eligible for both the First Home Bonus and the Principle Place of Residence (PPR) concession. \n- Further concessions are available for Home Buyers with Concession Cards and First Home Buyers with families. For full details of available concessions & eligibility requirements please contact the State Revenue Office.";
    display(__reg2, loanduty, mortReg, __reg3, notes);
}
function calculateWA(loanamount, amount, propType, firsthome)
{
    var __reg1 = amount;
    var __reg2 = undefined;
    if (__reg1 <= 85000) 
    {
        __reg2 = 110;
    }
    else 
    {
        if (__reg1 <= 120000) 
        {
            __reg2 = 120;
        }
        else 
        {
            if (__reg1 <= 200000) 
            {
                __reg2 = 140;
            }
            else 
            {
                if (__reg1 <= 300000) 
                {
                    __reg2 = 160;
                }
                else 
                {
                    if (__reg1 <= 400000) 
                    {
                        __reg2 = 180;
                    }
                    else 
                    {
                        if (__reg1 <= 500000) 
                        {
                            __reg2 = 200;
                        }
                        else 
                        {
                            if (__reg1 <= 600000) 
                            {
                                __reg2 = 220;
                            }
                            else 
                            {
                                if (__reg1 <= 700000) 
                                {
                                    __reg2 = 240;
                                }
                                else 
                                {
                                    if (__reg1 <= 800000) 
                                    {
                                        __reg2 = 260;
                                    }
                                    else 
                                    {
                                        if (__reg1 <= 900000) 
                                        {
                                            __reg2 = 280;
                                        }
                                        else 
                                        {
                                            if (__reg1 <= 1000000) 
                                            {
                                                __reg2 = 300;
                                            }
                                            else 
                                            {
                                                if (__reg1 <= 1100000) 
                                                {
                                                    __reg2 = 320;
                                                }
                                                else 
                                                {
                                                    if (__reg1 <= 1200000) 
                                                    {
                                                        __reg2 = 340;
                                                    }
                                                    else 
                                                    {
                                                        if (__reg1 <= 1300000) 
                                                        {
                                                            __reg2 = 360;
                                                        }
                                                        else 
                                                        {
                                                            if (__reg1 <= 1400000) 
                                                            {
                                                                __reg2 = 380;
                                                            }
                                                            else 
                                                            {
                                                                if (__reg1 <= 1500000) 
                                                                {
                                                                    __reg2 = 400;
                                                                }
                                                                else 
                                                                {
                                                                    if (__reg1 <= 1600000) 
                                                                    {
                                                                        __reg2 = 420;
                                                                    }
                                                                    else 
                                                                    {
                                                                        if (__reg1 <= 1700000) 
                                                                        {
                                                                            __reg2 = 440;
                                                                        }
                                                                        else 
                                                                        {
                                                                            if (__reg1 <= 1800000) 
                                                                            {
                                                                                __reg2 = 460;
                                                                            }
                                                                            else 
                                                                            {
                                                                                if (__reg1 <= 1900000) 
                                                                                {
                                                                                    __reg2 = 480;
                                                                                }
                                                                                else 
                                                                                {
                                                                                    if (__reg1 <= 2000000) 
                                                                                    {
                                                                                        __reg2 = 500;
                                                                                    }
                                                                                    else 
                                                                                    {
                                                                                        __reg2 = Math.ceil((__reg1 - 2000000) / 100000) * 20 + 500;
                                                                                    }
                                                                                }
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    var mortgage = 110;
    var notes = "There may be concessions or rebates available for first home buyers purchasing vacant land and building homes.";
    var __reg3 = undefined;
    if (firsthome && propType && __reg1 <= 600000) 
    {
        if (__reg1 <= 500000) 
        {
            __reg3 = 0;
        }
        else 
        {
            if (__reg1 <= 600000) 
            {
                __reg3 = Math.ceil((__reg1 - 500000) / 100) * 22.51;
            }
        }
    }
    else 
    {
        if (__reg1 <= 120000) 
        {
            __reg3 = Math.ceil(__reg1 / 100) * 1.9;
        }
        else 
        {
            if (__reg1 > 120000 && __reg1 <= 150000) 
            {
                __reg3 = Math.ceil((__reg1 - 120000) / 100) * 2.85 + 2280;
            }
            else 
            {
                if (__reg1 > 150000 && __reg1 <= 360000) 
                {
                    __reg3 = Math.ceil((__reg1 - 150000) / 100) * 3.8 + 3135;
                }
                else 
                {
                    if (__reg1 > 360000 && __reg1 <= 725000) 
                    {
                        __reg3 = Math.ceil((__reg1 - 360000) / 100) * 4.75 + 11115;
                    }
                    else 
                    {
                        __reg3 = Math.ceil((__reg1 - 725000) / 100) * 5.15 + 28453;
                    }
                }
            }
        }
    }
    var loanduty = 0;
    display(__reg3, loanduty, mortgage, __reg2, notes);
}


function display(duty, loanduty, mortReg, trans, notes)
{
   /*
   $('#saStampDuty').val(mortReg).formatCurrency();
    $('#nswStampDuty').val(mortReg).formatCurrency();
    $('#vicStampDuty').val(mortReg).formatCurrency();
    $('#qldStampDuty').val(mortReg).formatCurrency();
    $('#waStampDuty').val(mortReg).formatCurrency();
    $('#ntStampDuty').val(mortReg).formatCurrency();
    $('#actStampDuty').val(mortReg).formatCurrency();
    $('#tasStampDuty').val(mortReg).formatCurrency();
*/ 
    $('#saTransfer').val(trans).formatCurrency();
    $('#nswTransfer').val(trans).formatCurrency();
    $('#vicTransfer').val(trans).formatCurrency();
    $('#qldTransfer').val(trans).formatCurrency();
    $('#waTransfer').val(trans).formatCurrency();
    $('#ntTransfer').val(trans).formatCurrency();
    $('#actTransfer').val(trans).formatCurrency();
    $('#tasTransfer').val(trans).formatCurrency();

	$('#saStampDuty2').val(duty).formatCurrency();
    $('#nswStampDuty2').val(duty).formatCurrency();
    $('#vicStampDuty2').val(duty).formatCurrency();
    $('#qldStampDuty2').val(duty).formatCurrency();
    $('#waStampDuty2').val(duty).formatCurrency();
    $('#ntStampDuty2').val(duty).formatCurrency();
    $('#actStampDuty2').val(duty).formatCurrency();
    $('#tasStampDuty2').val(duty).formatCurrency();

$('#saStampDuty').val(loanduty).formatCurrency();
    $('#nswStampDuty').val(loanduty).formatCurrency();
    $('#vicStampDuty').val(loanduty).formatCurrency();
    $('#qldStampDuty').val(loanduty).formatCurrency();
    $('#waStampDuty').val(loanduty).formatCurrency();
    $('#ntStampDuty').val(loanduty).formatCurrency();
    $('#actStampDuty').val(loanduty).formatCurrency();
    $('#tasStampDuty').val(loanduty).formatCurrency();

    $('#saTotalDuty').val(duty + loanduty  + trans).formatCurrency();
    $('#nswTotalDuty').val(duty + loanduty  + trans).formatCurrency();
    $('#vicTotalDuty').val(duty + loanduty  + trans).formatCurrency();
    $('#qldTotalDuty').val(duty + loanduty + trans).formatCurrency();
    $('#waTotalDuty').val(duty + loanduty  + trans).formatCurrency();
    $('#ntTotalDuty').val(duty + loanduty  + trans).formatCurrency();
    $('#actTotalDuty').val(duty + loanduty  + trans).formatCurrency();
    $('#tasTotalDuty').val(duty + loanduty  + trans).formatCurrency();

    //$('#text_area').html(notes);
    //calc.repaint("text"); //??

    //$('#registration_fee');
    //$('#transfer_fee').formatCurrency();
    //$('#stamp_duty_property').formatCurrency();
    //$('#stamp_duty_loan').formatCurrency();
    //$('#total').formatCurrency();
    
    $('#property').formatCurrency({roundToDecimalPlace:-2});
    $('#amount').formatCurrency({roundToDecimalPlace:-2});
}
//  This file is part of the jQuery formatCurrency Plugin.
//
//    The jQuery formatCurrency Plugin is free software: you can redistribute it
//    and/or modify it under the terms of the GNU General Public License as published 
//    by the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.

//    The jQuery formatCurrency Plugin is distributed in the hope that it will
//    be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 
//    of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License along with 
//    the jQuery formatCurrency Plugin.  If not, see <http://www.gnu.org/licenses/>.

(function($) {

	$.formatCurrency = {};

	$.formatCurrency.regions = [];

	// default Region is en
	$.formatCurrency.regions[''] = {
		symbol: '', // '$'
		positiveFormat: '%s%n',
		negativeFormat: '(%s%n)',
		decimalSymbol: '.',
		digitGroupSymbol: ',',
		groupDigits: true
	};

	$.fn.formatCurrency = function(destination, settings) {

		if (arguments.length == 1 && typeof destination !== "string") {
			settings = destination;
			destination = false;
		}

		// initialize defaults
		var defaults = {
			name: "formatCurrency",
			colorize: false,
			region: '',
			global: true,
			roundToDecimalPlace: 2, // roundToDecimalPlace: -1; for no rounding; 0 to round to the dollar; 1 for one digit cents; 2 for two digit cents; 3 for three digit cents; ...
			eventOnDecimalsEntered: false
		};
		// initialize default region
		defaults = $.extend(defaults, $.formatCurrency.regions['']);
		// override defaults with settings passed in
		settings = $.extend(defaults, settings);

		// check for region setting
		if (settings.region.length > 0) {
			settings = $.extend(settings, getRegionOrCulture(settings.region));
		}
		settings.regex = generateRegex(settings);

		return this.each(function() {
			$this = $(this);

			// get number
			var num = '0';
			num = $this[$this.is('input, select, textarea') ? 'val' : 'html']();

			//identify '(123)' as a negative number
			if (num.search('\\(') >= 0) {
				num = '-' + num;
			}

			if (num === '') {
				return;
			}

			// if the number is valid use it, otherwise clean it
			if (isNaN(num)) {
				// clean number
				num = num.replace(settings.regex, '');
				
				if (num === '') {
					return;
				}
				
				if (settings.decimalSymbol != '.') {
					num = num.replace(settings.decimalSymbol, '.');  // reset to US decimal for arithmetic
				}
				if (isNaN(num)) {
					num = '0';
				}
			}
			
			// evalutate number input
			var numParts = String(num).split('.');
			var isPositive = (num == Math.abs(num));
			var hasDecimals = (numParts.length > 1);
			var decimals = (hasDecimals ? numParts[1].toString() : '0');
			var originalDecimals = decimals;
			
			// format number
			num = Math.abs(numParts[0]);
			if (settings.roundToDecimalPlace >= 0) {
				decimals = parseFloat('1.' + decimals); // prepend "0."; (IE does NOT round 0.50.toFixed(0) up, but (1+0.50).toFixed(0)-1
				decimals = decimals.toFixed(settings.roundToDecimalPlace); // round
				if (decimals.substring(0, 1) == '2') {
					num = Number(num) + 1;
				}
				decimals = decimals.substring(2); // remove "0."
			}
			num = String(num);

			if (settings.groupDigits) {
				for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++) {
					num = num.substring(0, num.length - (4 * i + 3)) + settings.digitGroupSymbol + num.substring(num.length - (4 * i + 3));
				}
			}

			if ((hasDecimals && settings.roundToDecimalPlace == -1) || settings.roundToDecimalPlace > 0) {
				num += settings.decimalSymbol + decimals;
			}

			// format symbol/negative
			var format = isPositive ? settings.positiveFormat : settings.negativeFormat;
			var money = format.replace(/%s/g, settings.symbol);
			money = money.replace(/%n/g, num);

			// setup destination
			var $destination = $([]);
			if (!destination) {
				$destination = $this;
			} else {
				$destination = $(destination);
			}
			// set destination
			$destination[$destination.is('input, select, textarea') ? 'val' : 'html'](money);

			if (hasDecimals && settings.eventOnDecimalsEntered) {
				$destination.trigger('decimalsEntered', originalDecimals);
			}

			// colorize
			if (settings.colorize) {
				$destination.css('color', isPositive ? 'black' : 'red');
			}
		});
	};

	// Remove all non numbers from text
	$.fn.toNumber = function(settings) {
		var defaults = $.extend({
			name: "toNumber",
			region: '',
			global: true
		}, $.formatCurrency.regions['']);

		settings = jQuery.extend(defaults, settings);
		if (settings.region.length > 0) {
			settings = $.extend(settings, getRegionOrCulture(settings.region));
		}
		settings.regex = generateRegex(settings);

		return this.each(function() {
			var method = $(this).is('input, select, textarea') ? 'val' : 'html';
			$(this)[method]($(this)[method]().replace('(', '(-').replace(settings.regex, ''));
		});
	};

	// returns the value from the first element as a number
	$.fn.asNumber = function(settings) {
		var defaults = $.extend({
			name: "asNumber",
			region: '',
			parse: true,
			parseType: 'Float',
			global: true
		}, $.formatCurrency.regions['']);
		settings = jQuery.extend(defaults, settings);
		if (settings.region.length > 0) {
			settings = $.extend(settings, getRegionOrCulture(settings.region));
		}
		settings.regex = generateRegex(settings);
		settings.parseType = validateParseType(settings.parseType);

		var method = $(this).is('input, select, textarea') ? 'val' : 'html';
		var num = $(this)[method]();
		num = num ? num : "";
		num = num.replace('(', '(-');
		num = num.replace(settings.regex, '');
		if (!settings.parse) {
			return num;
		}

		if (num.length == 0) {
			num = '0';
		}

		if (settings.decimalSymbol != '.') {
			num = num.replace(settings.decimalSymbol, '.');  // reset to US decimal for arthmetic
		}

		return window['parse' + settings.parseType](num);
	};

	function getRegionOrCulture(region) {
		var regionInfo = $.formatCurrency.regions[region];
		if (regionInfo) {
			return regionInfo;
		}
		else {
			if (/(\w+)-(\w+)/g.test(region)) {
				var culture = region.replace(/(\w+)-(\w+)/g, "$1");
				return $.formatCurrency.regions[culture];
			}
		}
		// fallback to extend(null) (i.e. nothing)
		return null;
	}

	function validateParseType(parseType) {
		switch (parseType.toLowerCase()) {
			case 'int':
				return 'Int';
			case 'float':
				return 'Float';
			default:
				throw 'invalid parseType';
		}
	}
	
	function generateRegex(settings) {
		if (settings.symbol === '') {
			return new RegExp("[^\\d" + settings.decimalSymbol + "-]", "g");
		}
		else {
			var symbol = settings.symbol.replace('$', '\\$').replace('.', '\\.');		
			return new RegExp(symbol + "|[^\\d" + settings.decimalSymbol + "-]", "g");
		}	
	}

})(jQuery);

$(document).ready( function(){
$('#property').change(
      function(){ 
        var i = $('#property').asNumber().toFixed(2);
      //alert(i);
        if (i > 5000000) i = 5000000;  if (i < 0) i = 0;
        $('#property').val(i);         
        $('#property').formatCurrency({roundToDecimalPlace: -2});
      }
		);
		$('#amount').change(
      function(){ 
        var i = $('#amount').asNumber().toFixed(2);
      //alert(i);
        if (i > 5000000) i = 5000000;  if (i < 0) i = 0;
        $('#amount').val(i);         
        $('#amount').formatCurrency({roundToDecimalPlace: -2});
      }
		);
		 $("#property").formatCurrency({roundToDecimalPlace: 0});
    $("#amount").formatCurrency({roundToDecimalPlace: 0});

    });


