// debug can be either none, alert, or textarea
// depending on the kind of debugging required

var debug = "none";

/* 	Important - Rename the following fields on the web page
	(This makes it so much easier to work out which field is which !!!!!)

 	#####################################################################

 	Rename "MortgageType" 		to		"PurchaseOrRefinance"
 	Rename "PurchaseReason"		to		"OwnerOccupiedOrInvestment"
 	Rename "property"			to		"PurchasePrice"
 	Rename "amount"				to		"AmountBorrowed"
 	Rename "StampDuty"			to		"StampDutyBorrow"
 	Rename "StampDuty2"			to		"StampDutyPurchase"
 	Rename "TotalDuty"			to		"StampDutyTotal"

 	#####################################################################
*/

function computeForm(form)
{
	if (form.PurchasePrice.value == null || form.PurchasePrice.value.length == 0)
		form.PurchasePrice.value = 0;

	if (form.AmountBorrowed.value == null || form.AmountBorrowed.value.length == 0)
		form.AmountBorrowed.value = 0;

	form.StampDutyBorrow.value = 0;
	form.StampDutyPurchase.value = 0;

	// form.Transfer.value = 0;
 	// form.Percent95.value = 0.95*tempProperty;

	var amountBorrowed = form.AmountBorrowed.value;
	var purchasePrice = form.PurchasePrice.value;
	var tempAmount = amountBorrowed;
	var tempProperty = purchasePrice;
	var state = form.yourState.options[form.yourState.selectedIndex].value;
	var thisFHB = form.FirstHomeBuyer.value;
	var thisOwnerOccupiedOrInvestment = form.OwnerOccupiedOrInvestment.value;
	var thisPurchaseOrRefinance = form.PurchaseOrRefinance.value;

	if(amountBorrowed > 0)
	{
		doError("amountBorrowed = " + amountBorrowed
			 + ", purchasePrice = " + purchasePrice
			 + ", State = " + state
			 + ", First Home Buyer = " + thisFHB
			 + ", thisOwnerOccupiedOrInvestment = " + thisOwnerOccupiedOrInvestment
			 + ", thisPurchaseOrRefinance = " + thisPurchaseOrRefinance);
	}

	// ########################## A C T ##########################
	// ########################## A C T ##########################
	// ########################## A C T ##########################

	if (state == "ACT")
	{
		tempAmount = form.AmountBorrowed.value;
		tempProperty = form.PurchasePrice.value;

		// Conveyancing ACT Start
		// ----------------------

		// Rates checked 11/09/2004 dlh
		// Rates checked 28/08/2005 dlh

		if (form.PurchaseOrRefinance.value == "Purchase")
		{
			if (form.PurchasePrice.value > 0 && form.PurchasePrice.value <= 100000)
			{
				tempProperty = (tempProperty / 100);
				for (var i=0, k=1; tempProperty >i && tempProperty > k ; i++, k++);
				form.StampDutyBorrow.value = eval(form.StampDutyBorrow.value) + (k * 2);
			}

			if (form.PurchasePrice.value > 100000 && form.PurchasePrice.value <= 200000)
			{
				tempProperty = (tempProperty -100000) / 100;
				for (var i=0, k=1; tempProperty >i && tempProperty > k ; i++, k++);
				form.StampDutyPurchase.value = eval(form.StampDutyPurchase.value) + (k * 3.5) + 2000;
			}

			if (form.PurchasePrice.value > 200000 && form.PurchasePrice.value <= 300000)
			{
				tempProperty = (tempProperty - 200000) / 100;
				for (var i=0, k=1; tempProperty >i && tempProperty > k ; i++, k++);
				form.StampDutyPurchase.value = eval(form.StampDutyPurchase.value) + (k * 4) + 5500;
			}

			if (form.PurchasePrice.value > 300000 && form.PurchasePrice.value <= 500000)
			{
				tempProperty = (tempProperty - 300000) / 100;
				for (var i=0, k=1; tempProperty >i && tempProperty > k ; i++, k++);
				form.StampDutyPurchase.value = eval(form.StampDutyPurchase.value) + (k * 5.5) + 9500;
			}

			if (form.PurchasePrice.value > 500000 && form.PurchasePrice.value <= 1000000)
			{
				tempProperty = (tempProperty - 500000) / 100;
				for (var i=0, k=1; tempProperty >i && tempProperty > k ; i++, k++);
				form.StampDutyPurchase.value = eval(form.StampDutyPurchase.value) + (k * 5.75) + 20500;
			}

			if (form.PurchasePrice.value > 1000000)
			{
				tempProperty = (tempProperty - 1000000) / 100;
				for (var i=0, k=1; tempProperty >i && tempProperty > k ; i++, k++);
				form.StampDutyPurchase.value = eval(form.StampDutyPurchase.value) + (k * 6.75) + 49250;
			}
		}

		// form.Transfer.value = 140;

		// Conveyancing ACT End
		//---------------------

		// Mortgage ACT Start
		// ------------------

		// Rates checked 11/09/2004 dlh
		// Rates checked 28/08/2005 dlh

		form.StampDutyBorrow.value = 0;

		// Mortgage ACT End
		// ----------------

	}


	// ########################## N S W ##########################
	// ########################## N S W ##########################
	// ########################## N S W ##########################

	if (state == "NSW")
	{

		// Conveyancing NSW Start
		// ----------------------

		// Rates checked 11/09/2004 dlh
		// Rates checked 28/08/2005 dlh

		if (form.PurchaseOrRefinance.value == "Purchase")
		{
			if (form.PurchasePrice.value > 0 && form.PurchasePrice.value <= 14000)
			{
				tempProperty = (tempProperty / 100);
				for (var i=0, k=1; tempProperty >i && tempProperty > k ; i++, k++);
				form.StampDutyPurchase.value = eval(form.StampDutyPurchase.value) + (k * 1.25);
			}

			if (form.PurchasePrice.value > 14000 && form.PurchasePrice.value <= 30000)
			{
				tempProperty = (tempProperty - 14000) / 100;
				for (var i=0, k=1; tempProperty >i && tempProperty > k ; i++, k++);
				form.StampDutyPurchase.value = eval(form.StampDutyPurchase.value) + (k * 1.5) + 175;
			}

			if (form.PurchasePrice.value > 30000 && form.PurchasePrice.value <= 80000)
			{
				tempProperty = (tempProperty - 30000) / 100;
				for (var i=0, k=1; tempProperty >i && tempProperty > k ; i++, k++);
				form.StampDutyPurchase.value = eval(form.StampDutyPurchase.value) + (k * 1.75) + 415;
			}

			if (form.PurchasePrice.value > 80000 && form.PurchasePrice.value <= 300000)
			{
				tempProperty = (tempProperty - 80000) / 100;
				for (var i=0, k=1; tempProperty >i && tempProperty > k ; i++, k++);
				form.StampDutyPurchase.value = eval(form.StampDutyPurchase.value) + (k * 3.5) + 1290;
			}

			if (form.PurchasePrice.value > 300000 && form.PurchasePrice.value <= 1000000)
			{
				tempProperty = (tempProperty - 300000) / 100;
				for (var i=0, k=1; tempProperty >i && tempProperty > k ; i++, k++);
				form.StampDutyPurchase.value = eval(form.StampDutyPurchase.value) + (k * 4.5) + 8990;
			}

			if (form.PurchasePrice.value > 1000000 && form.PurchasePrice.value <= 3000000)
			{
				tempProperty = (tempProperty - 1000000) / 100;
				for (var i=0, k=1; tempProperty >i && tempProperty > k ; i++, k++);
				form.StampDutyPurchase.value = eval(form.StampDutyPurchase.value) + (k * 5.5) + 40490;
			}

			if (form.PurchasePrice.value > 3000000)
			{
				tempProperty = (tempProperty - 3000000) / 100;
				for (var i=0, k=1; tempProperty >i && tempProperty > k ; i++, k++);
				form.StampDutyPurchase.value = eval(form.StampDutyPurchase.value) + (k * 7.0) + 150490;
			}

			// First Home Buyers Concession

			if (thisFHB == "Yes")
			{
				if (purchasePrice <= 500000)
				{
					form.StampDutyPurchase.value = 0;
				}
				else if (amountBorrowed <= 600000)
				{
					form.StampDutyPurchase.value = (purchasePrice * 0.2249) - 112450;
				}
			}
		}

		// Conveyancing NSW End
		// --------------------

		// Mortgage NSW Start
		// ------------------

		// Rates checked 11/09/2004 dlh
		// Rates checked 28/08/2005 dlh

		if (form.AmountBorrowed.value > 0 && form.AmountBorrowed.value <= 16000)
			form.StampDutyBorrow.value = 5;

		if (form.AmountBorrowed.value > 16000)
		{
			tempAmount = (tempAmount - 16000) / 1000;
			for (var i=0, k=1; tempAmount > i && tempAmount > k ; i++, k++);
			form.StampDutyBorrow.value = (k * 4) + 5;
		}

		// Owner Occupied Concession - 01/09/2004 dlh

		if (thisOwnerOccupiedOrInvestment == "Owner Occupied")
		{
			// 10/07/2006 dlh if (amountBorrowed <= 50000)

			if (amountBorrowed <= 500000)											// 10/07/2006 dlh
			{
				form.StampDutyBorrow.value = 0;
			}
			else if (amountBorrowed <= 535000)
			{
				form.StampDutyBorrow.value = form.StampDutyBorrow.value * 0.25;
			}
			else if (amountBorrowed <= 565000)
			{
				form.StampDutyBorrow.value = form.StampDutyBorrow.value * 0.5;
			}
			else if (amountBorrowed <= 600000)
			{
				form.StampDutyBorrow.value = form.StampDutyBorrow.value * 0.75;
			}

		}

		// Refinance Concession - New From 2004
		// Added 28/08/05 dlh

		if (thisPurchaseOrRefinance == "Refinance")
		{
			if (amountBorrowed <= 1000000)
			{
				form.StampDutyBorrow.value = 0;
			}
			else
			{
				//form.StampDutyBorrow.value = (amountBorrowed - 100000 + 999.99) / 1000 * 4;
				tempAmount = (amountBorrowed - 1000000) / 1000;
				for (var i=0, k=1; tempAmount >i && tempAmount > k ; i++, k++);
				form.StampDutyBorrow.value = eval(k * 4);

			}

		}

		// Mortgage NSW End
		// ----------------

	}


	// ########################## N T ##########################
	// ########################## N T ##########################
	// ########################## N T ##########################

	if (state == "NT")
	{

		// Conveyancing NT Start
		// ---------------------

		// Rates Checked 17/08/2004 dlh
		// Rates Checked 28/08/2005 dlh

		tempProperty /= 1000;

		if (form.PurchaseOrRefinance.value == "Purchase")
		{
			var tempP = tempProperty;
			tempProperty *= tempProperty;

			if (form.PurchasePrice.value <= 500000 )
			{
				form.StampDutyPurchase.value = eval(tempProperty * 0.065) + eval(21 * tempP);
			}

 			// 17/08/2004 dlh if (form.PurchasePrice.value > 500000)

 			else
 			{
 				form.StampDutyPurchase.value = (form.PurchasePrice.value * 0.054);
 			}
		}


		// First Home Buyer and Owner Occupier Rebates
		// Rates checked 18/07/2004 dlh
		// Rates checked 28/08/2005 dlh

		if (thisFHB == "Yes")
		{
			var FHBConcession = 8015.6		// 28/08/2005 dlh

			// 28/08/2005 dlh if (eval(form.StampDutyPurchase.value) < 3640.6)

			if (eval(form.StampDutyPurchase.value) < FHBConcession)
			{
				form.StampDutyPurchase.value = 0;
			}
			else
			{
				// 28/08/2005 dlh form.StampDutyPurchase.value -= 3640.6
				form.StampDutyPurchase.value -= FHBConcession;
			}
		}
		else
		{
			if (thisOwnerOccupiedOrInvestment == "Owner Occupied")
			{
				var OwnerOccConcession = 2500		// 28/08/2005 dlh

				// 28/08/2005 dlh if (eval(form.StampDutyPurchase.value) < 1500)

				if (eval(form.StampDutyPurchase.value) < OwnerOccConcession)
				{
					form.StampDutyPurchase.value = 0
				}
				else
				{
					// 28/08/2005 dlh form.StampDutyPurchase.value -= 1500

					form.StampDutyPurchase.value -= OwnerOccConcession	// 28/08/2005 dlh
				}
			}
		}	//	end if (thisFHB == "Yes")

		// Conveyancing NT End
		// -------------------

		// Mortgage NT Start
		// -----------------

		// Rates Checked 17/08/2004 dlh
		// Rates Checked 28/08/2005 dlh

		tempAmount = form.AmountBorrowed.value;
 		tempProperty = form.PurchasePrice.value;

 		form.StampDutyBorrow.value = 0;

		// Mortgage NT End
		// ---------------


	}


	// ########################## Q L D ##########################
	// ########################## Q L D ##########################
	// ########################## Q L D ##########################

	if (state == "QLD")
	{
		// Queensland

		tempAmount = form.AmountBorrowed.value;
		tempProperty = form.PurchasePrice.value;

		// Conveyancing QLD Start
		// ----------------------

		// Rates checked 28/08/2005 dlh

		if (form.PurchaseOrRefinance.value == "Purchase")
		{
			if (thisOwnerOccupiedOrInvestment == "Investment")
			{
				if (form.PurchasePrice.value > 0 && form.PurchasePrice.value <= 20000)
				{
					tempProperty = (tempProperty / 100);
					for (var i=0, k=1; tempProperty >i && tempProperty > k ; i++, k++);
					form.StampDutyPurchase.value = eval(form.StampDutyPurchase.value) + (k * 1.5);
				}

				if (form.PurchasePrice.value > 20000 && form.PurchasePrice.value <= 50000)
				{
					tempProperty = (tempProperty - 20000) / 100;
					for (var i=0, k=1; tempProperty >i && tempProperty > k ; i++, k++);
					form.StampDutyPurchase.value = eval(form.StampDutyPurchase.value) + (k * 2.25) + 300;
 				}

 				if (form.PurchasePrice.value > 50000 && form.PurchasePrice.value <= 100000)
				{
					tempProperty = (tempProperty - 50000) / 100;
					for (var i=0, k=1; tempProperty >i && tempProperty > k ; i++, k++);
					form.StampDutyPurchase.value = eval(form.StampDutyPurchase.value) + (k * 2.75) + 975;
				}

				if (form.PurchasePrice.value > 100000 && form.PurchasePrice.value <= 250000)
				{
					tempProperty = (tempProperty - 100000) / 100;
					for (var i=0, k=1; tempProperty >i && tempProperty > k ; i++, k++);
					form.StampDutyPurchase.value = eval(form.StampDutyPurchase.value) + (k * 3.25) + 2350;
				}

 				if (form.PurchasePrice.value > 250000 && form.PurchasePrice.value <= 500000)
				{
					tempProperty = (tempProperty - 250000) / 100;
					for (var i=0, k=1; tempProperty >i && tempProperty > k ; i++, k++);
					form.StampDutyPurchase.value = eval(form.StampDutyPurchase.value) + (k * 3.5) + 7225;
				}

				// 10/07/2006 dlh if (form.PurchasePrice.value > 500000)

				if (form.PurchasePrice.value > 500000 && form.PurchasePrice.value <= 700000)
				{
					tempProperty = (tempProperty - 500000) / 100;
					for (var i=0, k=1; tempProperty >i && tempProperty > k ; i++, k++);
					// 10/07/2006 dlh form.StampDutyPurchase.value = eval(form.StampDutyPurchase.value) + (k * 3.75) + 15975;
					form.StampDutyPurchase.value = eval(form.StampDutyPurchase.value) + (k * 4.0) + 15975;			// 10/07/2006 dlh
				}

				if (form.PurchasePrice.value > 700000)																// 10/07/2006 dlh
				{																									// 10/07/2006 dlh
					tempProperty = (tempProperty - 700000) / 100;													// 10/07/2006 dlh
					for (var i=0, k=1; tempProperty >i && tempProperty > k ; i++, k++);							// 10/07/2006 dlh
					form.StampDutyPurchase.value = eval(form.StampDutyPurchase.value) + (k * 4.5) + 23975;			// 10/07/2006 dlh
				}																									// 10/07/2006 dlh

			}

			if (thisOwnerOccupiedOrInvestment == "Owner Occupied")
			{
				// 10/07/2006 dlh if (form.PurchasePrice.value > 0 && form.PurchasePrice.value <= 300000)

				if (form.PurchasePrice.value > 0 && form.PurchasePrice.value <= 320000)								// 10/07/2006 dlh
				{
					tempProperty = (tempProperty / 100);
					for (var i=0, k=1; tempProperty >i && tempProperty > k ; i++, k++);
					form.StampDutyPurchase.value = eval(form.StampDutyPurchase.value) + (k * 1.0);
				}

				// 28/08/2005 dlh if (form.PurchasePrice.value > 250000 && form.PurchasePrice.value <= 500000)
				// 10/07/2006 dlh if (form.PurchasePrice.value > 300000 && form.PurchasePrice.value <= 500000)		// 28/08/2005 dlh

				if (form.PurchasePrice.value > 320000 && form.PurchasePrice.value <= 500000)						// 10/07/2006 dlh
				{
					// 28/08/2005 dlh tempProperty = (tempProperty - 250000) / 100;

					tempProperty = (tempProperty - 320000) / 100;													// 28/08/2005 dlh
					for (var i=0, k=1; tempProperty >i && tempProperty > k ; i++, k++);
					// 10/07/2006 dlh form.StampDutyPurchase.value = eval(form.StampDutyPurchase.value) + (k * 3.5) + 3000;
					form.StampDutyPurchase.value = eval(form.StampDutyPurchase.value) + (k * 3.5) + 3200;			// 10/07/2006 dlh
				}

 				// 10/07/2006 dlh if (form.PurchasePrice.value > 500000)

 				if (form.PurchasePrice.value > 500000 && form.PurchasePrice.value <= 700000)
				{
					tempProperty = (tempProperty - 500000) / 100;
					for (var i=0, k=1; tempProperty >i && tempProperty > k ; i++, k++);
					// 10/07/2006 dlh form.StampDutyPurchase.value = eval(form.StampDutyPurchase.value) + (k * 3.75) + 10000;
					form.StampDutyPurchase.value = eval(form.StampDutyPurchase.value) + (k * 4.0) + 9500;			// 10/07/2006 dlh
				}

 				if (form.PurchasePrice.value > 700000)																// 10/07/2006 dlh
				{																									// 10/07/2006 dlh
					tempProperty = (tempProperty - 700000) / 100;													// 10/07/2006 dlh
					for (var i=0, k=1; tempProperty >i && tempProperty > k ; i++, k++);							// 10/07/2006 dlh
					form.StampDutyPurchase.value = eval(form.StampDutyPurchase.value) + (k * 4.5) + 17500;			// 10/07/2006 dlh
				}																									// 10/07/2006 dlh

 				if (thisFHB == "Yes")
 				{

 					if (eval(form.PurchasePrice.value) <= 329999)
 					{
 						form.StampDutyPurchase.value = 0
 					}

 					if (eval(form.PurchasePrice.value) > 329999 && eval(form.PurchasePrice.value) <= 339999)
 					{
 						form.StampDutyPurchase.value -= 3000
 					}

 					if (eval(form.PurchasePrice.value) >= 340000 && eval(form.PurchasePrice.value) <= 349999)
 					{
 						form.StampDutyPurchase.value -= 2800
 					}

					if (eval(form.PurchasePrice.value) >= 350000 && eval(form.PurchasePrice.value) <= 359999)
 					{
 						form.StampDutyPurchase.value -= 2600
 					}

					if (eval(form.PurchasePrice.value) >= 360000 && eval(form.PurchasePrice.value) <= 369999)
 					{
 						form.StampDutyPurchase.value -= 2400
 					}

 					if (eval(form.PurchasePrice.value) >= 370000 && eval(form.PurchasePrice.value) <= 379999)
 					{
 						form.StampDutyPurchase.value -= 2200
 					}

 					if (eval(form.PurchasePrice.value) >= 380000 && eval(form.PurchasePrice.value) <= 389999)
 					{
 						form.StampDutyPurchase.value -= 2000
 					}

					if (eval(form.PurchasePrice.value) >= 390000 && eval(form.PurchasePrice.value) <= 399999)
 					{
 						form.StampDutyPurchase.value -= 1800
 					}

					if (eval(form.PurchasePrice.value) >= 400000 && eval(form.PurchasePrice.value) <= 409999)
 					{
 						form.StampDutyPurchase.value -= 1600
 					}

					if (eval(form.PurchasePrice.value) >= 410000 && eval(form.PurchasePrice.value) <= 419999)
 					{
 						form.StampDutyPurchase.value -= 1400
 					}

					if (eval(form.PurchasePrice.value) >= 420000 && eval(form.PurchasePrice.value) <= 429999)
 					{
 						form.StampDutyPurchase.value -= 1200
 					}

 					if (eval(form.PurchasePrice.value) >= 430000 && eval(form.PurchasePrice.value) <= 439999)
 					{
 						form.StampDutyPurchase.value -= 1000
 					}

					if (eval(form.PurchasePrice.value) >= 440000 && eval(form.PurchasePrice.value) <= 449999)
 					{
 						form.StampDutyPurchase.value -= 800
 					}

					if (eval(form.PurchasePrice.value) >= 450000 && eval(form.PurchasePrice.value) <= 459999)
 					{
 						form.StampDutyPurchase.value -= 600
 					}

					if (eval(form.PurchasePrice.value) >= 460000 && eval(form.PurchasePrice.value) <= 469999)
 					{
 						form.StampDutyPurchase.value -= 400
 					}

					if (eval(form.PurchasePrice.value) >= 470000 && eval(form.PurchasePrice.value) <= 479999)
 					{
 						form.StampDutyPurchase.value -= 300
 					}

					if (eval(form.PurchasePrice.value) >= 480000 && eval(form.PurchasePrice.value) <= 489999)
 					{
 						form.StampDutyPurchase.value -= 200
 					}

					if (eval(form.PurchasePrice.value) >= 490000 && eval(form.PurchasePrice.value) <= 499999)
 					{
 						form.StampDutyPurchase.value -= 100
					}

				}
			}
		}


// Darryl 28/01/2007 #######################################
//					if (eval(form.PurchasePrice.value) >= 420000 && eval(form.PurchasePrice.value) <= //429999)
// 					{
// 						form.StampDutyPurchase.value -= 800
// 					}
//
//					if (eval(form.PurchasePrice.value) >= 430000 && eval(form.PurchasePrice.value) <= //439999)
// 					{
// 						form.StampDutyPurchase.value -= 700
// 					}
//
//					if (eval(form.PurchasePrice.value) >= 440000 && eval(form.PurchasePrice.value) <= //449999)
// 					{
// 						form.StampDutyPurchase.value -= 600
// 					}
//
//					if (eval(form.PurchasePrice.value) >= 450000 && eval(form.PurchasePrice.value) <= //459999)
// 					{
// 						form.StampDutyPurchase.value -= 500
// 					}
//
//					if (eval(form.PurchasePrice.value) >= 460000 && eval(form.PurchasePrice.value) <= //469999)
// 					{
// 						form.StampDutyPurchase.value -= 400
// 					}
//					if (eval(form.PurchasePrice.value) >= 470000 && eval(form.PurchasePrice.value) <= //479999)
// 					{
// 						form.StampDutyPurchase.value -= 300
// 					}
//
//					if (eval(form.PurchasePrice.value) >= 480000 && eval(form.PurchasePrice.value) <= //489999)
// 					{
// 						form.StampDutyPurchase.value -= 200
// 					}
//
//					if (eval(form.PurchasePrice.value) >= 490000 && eval(form.PurchasePrice.value) <= //499999)
// 					{
// 						form.StampDutyPurchase.value -= 100
// 					}
//#####################################################


		// Conveyancing QLD End
		// --------------------


		// Mortgage QLD Start
		// ------------------

		// Rates checked 28/08/2005 dlh

		if (thisOwnerOccupiedOrInvestment == "Investment")
		{
			tempAmount *= 0.004;
		}

		if (thisOwnerOccupiedOrInvestment == "Owner Occupied")
		{
			if (thisPurchaseOrRefinance == "Refinance")
			{
				// 28/08/2005 dlh tempAmount = ((tempAmount-250000)*0.004);

				tempAmount = ((tempAmount-100000)*0.004);		// 28/08/2005 dlh

				if (tempAmount < 0)
				{
					tempAmount = 0;
				}
			}

			if (thisPurchaseOrRefinance == "Purchase")
			{
				if (thisFHB == "Yes")		// First Home Buyer
				{
					tempAmount = ((tempAmount-250000)*0.004);
					if (tempAmount < 0)
					{
						tempAmount = 0;
					}
				}
				// 28/08/2005 dlh if (thisFHB == "No")
				else
				{
					tempAmount = ((tempAmount-70000)*0.004);
					if (tempAmount < 0)
					{
						tempAmount = 0;
					}
				}
			}
		}

		form.StampDutyBorrow.value = tempAmount;

		// Mortgage QLD End
		// ----------------

	}


	// ########################## S A ##########################
	// ########################## S A ##########################
	// ########################## S A ##########################

	if (state == "SA")
	{

		tempAmount = form.AmountBorrowed.value;
 		tempProperty = form.PurchasePrice.value;

		// Conveyancing SA Start
		// ---------------------

		// Rates Checked 11/09/2004 dlh
		// Rates Checked 28/08/2005 dlh

		if (form.PurchaseOrRefinance.value == "Purchase")
		{
			if (form.PurchasePrice.value > 0 && form.PurchasePrice.value <= 12000)
			{
				tempProperty = (tempProperty / 100);
				for (var i=0, k=1; tempProperty >i && tempProperty > k ; i++, k++);
				form.StampDutyPurchase.value = eval(form.StampDutyPurchase.value) + (k * 1);
			}

			if (form.PurchasePrice.value > 12000 && form.PurchasePrice.value <=30000)
			{
				tempProperty = (tempProperty - 12000) / 100;
				for (var i=0, k=1; tempProperty >i && tempProperty > k ; i++, k++);
				form.StampDutyPurchase.value = eval(form.StampDutyPurchase.value) + (k * 2) + 120;
			}

			if (form.PurchasePrice.value > 30000 && form.PurchasePrice.value <= 50000)
			{
				tempProperty = (tempProperty - 30000) / 100;
				for (var i=0, k=1; tempProperty >i && tempProperty > k ; i++, k++);
				form.StampDutyPurchase.value = eval(form.StampDutyPurchase.value) + (k * 3) + 480;
			}

			if (form.PurchasePrice.value > 50000 && form.PurchasePrice.value <= 100000)
			{
				tempProperty = (tempProperty - 50000) / 100;
				for (var i=0, k=1; tempProperty >i && tempProperty > k ; i++, k++);
				form.StampDutyPurchase.value = eval(form.StampDutyPurchase.value) + (k * 3.5) + 1080;
			}

			if (form.PurchasePrice.value > 100000 && form.PurchasePrice.value <= 200000)
			{
				tempProperty = (tempProperty - 100000) / 100;
				for (var i=0, k=1; tempProperty >i && tempProperty > k ; i++, k++);
				form.StampDutyPurchase.value = eval(form.StampDutyPurchase.value) + (k * 4) + 2830;
			}

			if (form.PurchasePrice.value > 200000 && form.PurchasePrice.value <= 250000)
			{
				tempProperty = (tempProperty - 200000) / 100;
				for (var i=0, k=1; tempProperty >i && tempProperty > k ; i++, k++);
				form.StampDutyPurchase.value = eval(form.StampDutyPurchase.value) + (k * 4.25) + 6830;
			}

			if (form.PurchasePrice.value > 250000 && form.PurchasePrice.value  <= 300000)
			{
				tempProperty = (tempProperty - 250000) / 100;
				for (var i=0, k=1; tempProperty >i && tempProperty > k ; i++, k++);
				form.StampDutyPurchase.value = eval(form.StampDutyPurchase.value) + (k * 4.75) + 8955;
			}

			if (form.PurchasePrice.value > 300000 && form.PurchasePrice.value <= 500000)
			{
				tempProperty = (tempProperty - 300000) / 100;
				for (var i=0, k=1; tempProperty >i && tempProperty > k ; i++, k++);
				form.StampDutyPurchase.value = eval(form.StampDutyPurchase.value) + (k * 5) + 11330;
			}

			if (form.PurchasePrice.value > 500000)
			{
				tempProperty = (tempProperty - 500000) / 100;
				for (var i=0, k=1; tempProperty >i && tempProperty > k ; i++, k++);
				form.StampDutyPurchase.value = eval(form.StampDutyPurchase.value) + (k * 5.5) + 21330;
			}


			// First Home Buyer Concession

			if (thisFHB == "Yes" && thisOwnerOccupiedOrInvestment == "Owner Occupied")
			{
				tempProperty = eval(form.PurchasePrice.value);

				// Up to $80,000 = Full rebate

				if (eval(form.PurchasePrice.value) > 0 && eval(form.PurchasePrice.value) <= 80000)
				{
					form.StampDutyPurchase.value = 0;
				}

				// From $80,000.01 to $100,000, reduced by 2.5% for each $1,000 from $80,000 to $100,000

 				if (eval(form.PurchasePrice.value) > 80000 && eval(form.PurchasePrice.value) <= 100000)
				{
					Surplus = form.PurchasePrice.value - 80000;
					if (eval(Surplus % 1000 > 500))
						Surplus = Surplus + 1000;
					Surplus = (Surplus / 1000) * 1000;
					Percentage = Surplus * 0.000025;
					Payable = form.StampDutyPurchase.value * Percentage;
					Concession = form.StampDutyPurchase.value - Payable;
					form.StampDutyPurchase.value = form.StampDutyPurchase.value - Concession;
				}

				// From $100,000.01 to $150,000, reduced by 50%

				if (eval(form.PurchasePrice.value) > 100000 && eval(form.PurchasePrice.value) <= 150000)
				{
					//for (var i=0, k=1; tempProperty >i && tempProperty > k ; i++, k++);

					form.StampDutyPurchase.value = form.StampDutyPurchase.value / 2;
 				}

				// 28/08/2005 dlh - this last section added to conform to vb code

				// From $150,000.01 to $250,000, reduced by concession on $150,000 ($2,415)
				// and then by $24 for each $1,000 over $150,000

				if (eval(form.PurchasePrice.value) > 150000 && eval(form.PurchasePrice.value) <= 250000)
				{

					// 50% of Concession on $150,000 ($2,415) + $24 per $1,000 over $150,000

					Concession = 2415 + ((form.PurchasePrice.value - 150000) / 1000) * 24;
					form.StampDutyPurchase.value = form.StampDutyPurchase.value - Concession;
 				}

			}

		}

		//tempProperty = form.PurchasePrice.value;

		//if (form.PurchasePrice.value > 50000)
		//{
 		//	tempProperty = (tempProperty - 50000) / 10000;

			// for (var i=0, k=1; tempProperty >i && tempProperty > k ; i++, k++);
			// form.Transfer.value = (k * 45) + 142;
 		//}

		// Conveyancing SA End
		// -------------------

		// Mortgage SA Start
		// -----------------

		// Rates Checked 11/09/2004 dlh
		// Rates Checked 28/08/2005 dlh

		if (form.FirstHomeBuyer.value == "Yes") {
			form.StampDutyBorrow.value = 0;
		}
		else {
			if (form.OwnerOccupiedOrInvestment.value == "Owner Occupied") {
				form.StampDutyBorrow.value = 0;
			}
			else {

				if (form.AmountBorrowed.value <= 400) {
  					form.StampDutyBorrow.value = 0;
  				}

				if (form.AmountBorrowed.value > 400 && form.AmountBorrowed.value <= 6000) {
					form.StampDutyBorrow.value = 10;
				}

				if (form.AmountBorrowed.value > 6000) {
					tempAmount = (tempAmount - 6000) / 100;
					for (var i=0, k=1; tempAmount >i && tempAmount > k ; i++, k++);
					form.StampDutyBorrow.value = (k * 0.45) + 10;
				}
			}
		}

		// Mortgage SA End
		// ---------------

	}


	// ########################## T A S ##########################
	// ########################## T A S ##########################
	// ########################## T A S ##########################

	if (state == "TAS")
	{

		// Conveyancing TAS Start
		// ----------------------

		// Validated 04/11/2002
		// Rates Checked 28/08/2005 dlh

		if (form.PurchaseOrRefinance.value == "Purchase")
		{
			if (form.PurchasePrice.value > 0 && form.PurchasePrice.value <= 1300)
				form.StampDutyPurchase.value = eval(form.StampDutyPurchase.value) + 20;

			if (form.PurchasePrice.value > 1300 && form.PurchasePrice.value <= 10000)
			{
				tempProperty = (tempProperty - 1300) / 100;
				for (var i=0, k=1; tempProperty >i && tempProperty > k ; i++, k++);
				form.StampDutyPurchase.value = eval(form.StampDutyPurchase.value) + (k * 1.5);
			}

			if (form.PurchasePrice.value > 10000 && form.PurchasePrice.value <= 30000)
			{
				tempProperty = (tempProperty - 10000) / 100;
				for (var i=0, k=1; tempProperty >i && tempProperty > k ; i++, k++);
				form.StampDutyPurchase.value = eval(form.StampDutyPurchase.value) + (k * 2) + 150;
			}

			if (form.PurchasePrice.value > 30000 && form.PurchasePrice.value <= 75000)
			{
				tempProperty = (tempProperty - 30000) / 100;
				for (var i=0, k=1; tempProperty >i && tempProperty > k ; i++, k++);
				form.StampDutyPurchase.value = eval(form.StampDutyPurchase.value) + (k * 2.5) + 550;
			}

			if (form.PurchasePrice.value > 75000 && form.PurchasePrice.value <= 150000)
			{
				tempProperty = (tempProperty - 75000) / 100;
				for (var i=0, k=1; tempProperty >i && tempProperty > k ; i++, k++);
				form.StampDutyPurchase.value = eval(form.StampDutyPurchase.value) + (k * 3) + 1675;
			}

			if (form.PurchasePrice.value > 150000 && form.PurchasePrice.value <= 225000)
			{
				tempProperty = (tempProperty - 150000) / 100;
				for (var i=0, k=1; tempProperty >i && tempProperty > k ; i++, k++);
				form.StampDutyPurchase.value = eval(form.StampDutyPurchase.value) + (k * 3.5) + 3925;
			}

			if (form.PurchasePrice.value > 225000)
			{
				tempProperty = (tempProperty - 225000) / 100;
				for (var i=0, k=1; tempProperty >i && tempProperty > k ; i++, k++);
				form.StampDutyPurchase.value = eval(form.StampDutyPurchase.value) + (k * 4) + 6550;
			}
		}

		// First Home Buyer Concession - 11/09/2004 - dlh

		if (form.FirstHomeBuyer.value == "Yes")
		{
			// 28/08/2005 dlh if (form.StampDutyPurchase.value < 4000)
			// 28/08/2005 dlh 	form.StampDutyPurchase.value = 0;
			// 28/08/2005 dlh else
			// 28/08/2005 dlh 	form.StampDutyPurchase.value = form.StampDutyPurchase.value - 4000;

			form.StampDutyPurchase.value = (form.StampDutyPurchase.value < 4000) ? 0 : form.StampDutyPurchase.value - 4000; // 28/08/2005 dlh

		}

		// Conveyancing TAS End
		// --------------------

		// Mortgage TAS Start
		// ------------------

		// Validated 04/11/2002
		// Rates Checked 28/08/2005 dlh

		tempAmount = form.AmountBorrowed.value;
		tempProperty = form.PurchasePrice.value;

		if (form.AmountBorrowed.value > 0 && form.AmountBorrowed.value <= 8000)
			form.StampDutyBorrow.value = 20;

		if (form.AmountBorrowed.value > 8000 && form.AmountBorrowed.value <= 10000)
		{
			tempAmount = (tempAmount - 8000) / 100;
			for (var i=0, k=1; tempAmount >i && tempAmount > k ; i++, k++);
			form.StampDutyBorrow.value = (k * 0.25) + 20.00000000000001;
		}

		if (form.AmountBorrowed.value > 10000)
		{
			tempAmount = (tempAmount - 10000) / 100;
			for (var i=0, k=1; tempAmount >i && tempAmount > k ; i++, k++);
			// 10/07/2006 dlh dlh form.StampDutyBorrow.value = (k * 0.35) + 25.00000000000001;
			form.StampDutyBorrow.value = (k * 0.175) + 25.00000000000001;							// 10/07/2006 dlh
		}

		// Mortgage TAS End
		// ----------------

	}


	// ########################## V I C ##########################
	// ########################## V I C ##########################
	// ########################## V I C ##########################

	if (state == "VIC")
	{


		tempAmount = form.AmountBorrowed.value;
		tempProperty = form.PurchasePrice.value;

		// Conveyancing VIC Start
		// ----------------------

		// Rates Checked 11/09/2004 dlh
		// Rates Checked 28/08/2005 dlh



	if (form.PurchaseOrRefinance.value == "Purchase")
		{
		if (thisOwnerOccupiedOrInvestment == "Investment") // Darryl 28/01/2007 to allow for Owner Occupied below
			{

				if (form.PurchasePrice.value > 0 && form.PurchasePrice.value <= 20000)
				{
					form.StampDutyPurchase.value = eval(tempProperty) * 0.014;
				}

				if (form.PurchasePrice.value > 20000 && form.PurchasePrice.value <= 115000)
				{
					tempProperty = (tempProperty - 20000);
					form.StampDutyPurchase.value = eval(tempProperty) * 0.024 + 280;
				}

				if (form.PurchasePrice.value > 115000 && form.PurchasePrice.value <= 870000)
				{
					tempProperty = (tempProperty - 115000);
					form.StampDutyPurchase.value = eval(tempProperty) * 0.06 + 2560;
				}

				if (form.PurchasePrice.value > 870000)
				{
					form.StampDutyPurchase.value = eval(tempProperty) * 0.055;
				}
			}

// Darryl 27/01/2007 ############# Owner occupied concession

		if (thisOwnerOccupiedOrInvestment == "Owner Occupied")
			{

				if (form.PurchasePrice.value > 0 && form.PurchasePrice.value <= 20000)
				{
					form.StampDutyPurchase.value = eval(tempProperty) * 0.014;
				}

				if (form.PurchasePrice.value > 20000 && form.PurchasePrice.value <= 115000)
				{
					tempProperty = (tempProperty - 20000);
					form.StampDutyPurchase.value = eval(tempProperty) * 0.024 + 280;
				}

				if (form.PurchasePrice.value > 115000 && form.PurchasePrice.value <= 400000)
				{
					tempProperty = (tempProperty - 115000);
					form.StampDutyPurchase.value = eval(tempProperty) * 0.05 + 2560;
				}

				if (form.PurchasePrice.value > 400000 && form.PurchasePrice.value <= 500000)
				{
					tempProperty = (tempProperty - 400000);
					form.StampDutyPurchase.value = eval(tempProperty) * 0.06 + 16810;
				}

				if (form.PurchasePrice.value > 500000 && form.PurchasePrice.value <= 870000)
				{
					tempProperty = (tempProperty - 500000);
					form.StampDutyPurchase.value = eval(tempProperty) * 0.06 + 25660;
				}

				if (form.PurchasePrice.value > 870000)
				{
					form.StampDutyPurchase.value = eval(tempProperty) * 0.055;
				}
			}
		}

// #########################################



		// Conveyancing VIC End
		// --------------------


		// Mortgage VIC Start
		// ------------------

		// Rates Checked 11/09/2004 dlh
		// Rates Checked 28/08/2005 dlh

		form.StampDutyBorrow.value = 0;

		// Mortgage VIC End
		// ----------------


	}


	// ########################## W A ##########################
	// ########################## W A ##########################
	// ########################## W A ##########################

	if (state == "WA")
	{
		tempAmount = form.AmountBorrowed.value;
		tempProperty = form.PurchasePrice.value;

		// Conveyancing WA Start
		// ---------------------

		// Rates Checked 28/08/2005 dlh

		//Investment

		if (form.PurchaseOrRefinance.value == "Purchase" && form.PurchasePrice.value > 0)
		{
			if (form.PurchasePrice.value > 0 && form.PurchasePrice.value <= 80000)
			{
				tempProperty = (tempProperty / 100);
				for (var i=0, k=1; tempProperty >i && tempProperty > k ; i++, k++);
				// 28/08/2005 dlh form.StampDutyPurchase.value = eval(form.StampDutyPurchase.value) + (k * 2.2);
				form.StampDutyPurchase.value = eval(form.StampDutyPurchase.value) + (k * 2);			// 28/08/2005 dlh
			}

			if (form.PurchasePrice.value > 80000 && form.PurchasePrice.value <= 100000)
			{
				tempProperty = (tempProperty - 80000) / 100;
				for (var i=0, k=1; tempProperty >i && tempProperty > k ; i++, k++);
				// 28/08/2005 dlh form.StampDutyPurchase.value = eval(form.StampDutyPurchase.value) + (k * 3.3) + 1760;
				form.StampDutyPurchase.value = eval(form.StampDutyPurchase.value) + (k * 3) + 1600;		// 28/08/2005 dlh
			}

			if (form.PurchasePrice.value > 100000 && form.PurchasePrice.value <= 250000)
			{
				tempProperty = (tempProperty - 100000) / 100;
				for (var i=0, k=1; tempProperty >i && tempProperty > k ; i++, k++);
				// 28/08/2005 dlh form.StampDutyPurchase.value = eval(form.StampDutyPurchase.value) + (k * 4.5) + 2420;
				form.StampDutyPurchase.value = eval(form.StampDutyPurchase.value) + (k * 4) + 2200;		// 28/08/2005 dlh
			}

			if (form.PurchasePrice.value > 250000 && form.PurchasePrice.value <= 500000)
			{
				tempProperty = (tempProperty - 250000) / 100;
				for (var i=0, k=1; tempProperty >i && tempProperty > k ; i++, k++);
				// 28/08/2005 dlh form.StampDutyPurchase.value = eval(form.StampDutyPurchase.value) + (k * 5.60) + 9170;
				form.StampDutyPurchase.value = eval(form.StampDutyPurchase.value) + (k * 5) + 8200;		// 28/08/2005 dlh
			}

			if (form.PurchasePrice.value > 500000)
			{
				tempProperty = (tempProperty - 500000) / 100;
				for (var i=0, k=1; tempProperty >i && tempProperty > k ; i++, k++);
				// 28/08/2005 dlh form.StampDutyPurchase.value = eval(form.StampDutyPurchase.value) + (k * 6) + 23170;
				form.StampDutyPurchase.value = eval(form.StampDutyPurchase.value) + (k * 5.4) + 20700;	// 28/08/2005 dlh
			}

			// Owner Occupied

			if (thisOwnerOccupiedOrInvestment == "Owner Occupied")
			{
				if (form.PurchasePrice.value <= 100000)
					form.StampDutyPurchase.value = form.PurchasePrice.value / 100 * 1.5;
				else
				{
					if (form.PurchasePrice.value <= 200000)
						// 28/08/2005 dlh form.StampDutyPurchase.value = 1500 + ((form.PurchasePrice.value - 100000) / 100 * 5.42);
						form.StampDutyPurchase.value = 1500 + ((form.PurchasePrice.value - 100000) / 100 * 4.7);	// 28/08/2005 dlh
				}
			}

			// First Home Buyer

			if (thisFHB == "Yes")
			{
				// 28/08/2005 dlh if (eval(form.PurchasePrice.value) > 0 && eval(form.PurchasePrice.value) <= 220000)

				if (eval(form.PurchasePrice.value) > 0 && eval(form.PurchasePrice.value) <= 250000)			// 28/08/2005 dlh
				{
					form.StampDutyPurchase.value = 0;
				}
				else
				{
					if (form.PurchasePrice.value <= 350000)
					{
						// 10/07/2006 dlh tempProperty = (form.PurchasePrice.value - 220000) / 100;			// 28/08/2005 dlh
						tempProperty = (form.PurchasePrice.value - 250000) / 100;							// 10/07/2006 dlh
						for (var i=0, k=1; tempProperty > i && tempProperty > k ; i++, k++);
						// 28/08/2005 dlh form.StampDutyPurchase.value = eval(form.StampDutyPurchase.value) - 500;
						// 10/07/2006 dlh form.StampDutyPurchase.value = eval(form.StampDutyPurchase.value) + (k * 13.2);		// 28/08/2005 dlh
						form.StampDutyPurchase.value = (k * 13.2);		// 10/07/2006 dlh
					}
				}
			}
		}

		// Conveyancing WA End
		// -------------------

		// Mortgage WA Start
		// -----------------

		// Rates Checked 28/08/2005 dlh

		// Investment

		if (form.AmountBorrowed.value > 0) {													// 28/08/2005 dlh

			// Owner Occupied

			if (thisOwnerOccupiedOrInvestment == "Owner Occupied")
			{
				// 09/07/2006 dlh if (eval(form.AmountBorrowed.value) <= 8000)
				if (eval(form.AmountBorrowed.value) <= 16000)									// 09/07/2006 dlh
				{
					form.StampDutyBorrow.value = 20;
				}

				// 28/08/2005 dlh if (eval(form.AmountBorrowed.value) > 8000)

				else																			// 28/08/2005 dlh
				{
					// 10/07/2006 dlh form.StampDutyBorrow.value = tempAmount * 0.0025;
					form.StampDutyBorrow.value = tempAmount * 0.00125;							// 10/07/2006 dlh
				}
			}

			// Investment Property

			if (thisOwnerOccupiedOrInvestment == "Investment")
			{
				// 28/08/2005 dlh if (eval(form.AmountBorrowed.value) <= 5000)
				// 09/07/2006 dlh if (eval(form.AmountBorrowed.value) <= 8000)					// 28/08/2005 dlh

				if (eval(form.AmountBorrowed.value) <= 10000)									// 09/07/2006 dlh
				{
					form.StampDutyBorrow.value = 20;
				}

				// 28/08/2005 dlh if (eval(form.AmountBorrowed.value) > 5000)

				else																			// 28/08/2005 dlh
				{
					// 09/07/2006 dlh form.StampDutyBorrow.value = tempAmount * 0.004;
					form.StampDutyBorrow.value = tempAmount * 0.002;							// 09/07/2006 dlh
				}
			}

		}	// if (form.AmountBorrowed.value > 0)

		// Mortgage WA End
		// ---------------


	}


	form.StampDutyTotal.value = eval(form.StampDutyBorrow.value) + eval(form.StampDutyPurchase.value)
	form.StampDutyBorrow.value = format(round(form.StampDutyBorrow.value));
	form.StampDutyPurchase.value = format(round(form.StampDutyPurchase.value));
	form.StampDutyTotal.value = format(round(form.StampDutyTotal.value));

}	//	End of function computeForm(form)


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;

}	//	End of function format(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)

}	// End of function round(number)

// doError is the error handling routine
// depending on the type of debug message
// it presents either no debug message, an alert
// or puts the message in a textarea
//

// Courtesy of http://webmonkey.wired.com/webmonkey/98/29/index4a_page2.html?tw=programming

function doError(the_message)
{
   if (debug == "alert")
   {
	alert(the_message);
   } else if (debug == "textarea") {
	window.document.the_form.the_text.value += the_message + "<br>\n";
   }

}	//	End of function doError(the_message)

