
function select_item(name, value) {
	this.name = name;
	this.value = value;
}

function get_selection(select_object) {
	contents = new select_item();
	for(var i=0;i<select_object.options.length;i++) {
		if(select_object.options[i].selected == true) {
			contents.name = select_object.options[i].text;
			contents.value = select_object.options[i].value;
		}
	}
	return contents;
}

function StripChars(strIn) {
	var newstr = "";
	var Chars = "0123456789.";
    for (var i = 0; i < strIn.length; i++) {
       if (Chars.indexOf(strIn.charAt(i)) == -1) {}
	   else {
	   	newstr = newstr + strIn.charAt(i);
	   }
    }
	return newstr;
}

function stampduty(formfield) {
	var amount = StripChars(formfield.amount.value);
	var loanamount = StripChars(formfield.loanamount.value);
	var state = get_selection(formfield.state);
	var type = "OO"
	for (i=0; i< formfield.elements.length; i++) {
		if (formfield.elements[i].name == 'Type') {
			for (s=0;s < 2; s++) {
				if (formfield.Type[s].checked == true) {
					type = formfield.Type[s].value;
				}
			}
		}
	}
	if ((amount == "") && (loanamount == "")) {
		window.alert("You have not entered any values!");
		return;
	}
	t_amount = amount;
	if ((amount % 100) != 0 ) {
			var mod = eval(100-(amount % 100));
			amount = -(-amount - mod);
	}
	
	if ((loanamount % 100) != 0 ) {
			var mod2 = eval(100-(loanamount % 100));
			loanamount = -(-loanamount- mod2);
	}
	
//********************** Victoria *************************
	if (state.value == "VIC") {

		if ((t_amount % 1000) != 0 ) {
			var mod = eval(1000-(t_amount % 1000));
			t_amount = -(-t_amount - mod);
		}
		if ((t_amount > 0) && (t_amount <= 500000)) {
			var transfer = (t_amount / 1000) * 2.46 + 94.6;
		}
		else {
			var transfer = 1325;
		}
		transfer = Math.ceil(transfer) ;
		mortgage = 75;
		var exnotes = "First Home Bonus\n"+
"- First home buyers are eligible for a $3,000 bonus if consideration of the property does not exceed $500,000 and if transaction takes place between 1st Jan 2006 and 30 Jun 2007.\n\n"+
"First Home Buyers with Families\n"+
"- Must have at least 1 dependant child (under 18 and under control of applicant).\n"+
"- Full stamp duty exemption for properties valued up to $150,000.\n"+
"- Stamp duty concessions on a reducing scale for properties between $150,000 to $200,000.\n"+
"- All applicants must have not previously owned a home.\n\n"+

"Home Buyers with Concession Cards\n"+
"- Full stamp duty exemption for properties valued up to $250,000\n"+
"- Stamp duty concessions on a reducing scale for properties between $250,000 to $350,000\n"+
"- Have a Pensioner Concession Card (Department of Social Security or Department of Veterans' Affairs), Veterans' Affairs Gold Card, Health Benefits Card, or Health Care Card.\n"+
"- Mortgage registration fee changed from $45 to $46.20.";

		if (amount <= 20000) {
			var duty = eval(((amount)/100)*1.4);
	
		}
		else if ((amount > 20000) && (amount <= 115000)) {
			var duty = eval((((amount - 20000)/100)*2.4) + 280);
		}
	
		else if ((amount > 115000) && (amount <= 870000)) {
			var duty = eval((((amount - 115000)/100)*6) + 2560);
		}
		
		else {
			var duty = eval(((amount)/100)*5.5) ;
		}
		if ((loanamount % 200) != 0 ) {
			var mod = eval(200-(loanamount % 200));
			loanamount = -(-loanamount- mod);
		}
/*
		No more loan duty as of 1/7/2004
		
		if (loanamount <= 10000) {
			var loanduty = 4;
		}
		else {
			var loanduty = eval((((loanamount - 10000)/200)*0.8) + 4);
		}
*/
		var loanduty = 0;
		
	}

//********************** New South Wales *************************
	else if (state.value == "NSW") {
		var mortgage = 79;
		var transfer = 79;
		var exnotes = "First Home Plus Scheme\n"+
"- Full stamp and mortgage duty exemption for homes valued up to $500,000 in NSW\n"+
"- Stamp and mortgage duty concessions on a reducing scale for homes between $500,000 and $600,000.\n"+
"- First home buyers purchasing vacant block of residential land will pay no stamp duty on land valued up to $300,000.\n"+
"- Discounts are available on stamp duty between $300,000 and $450,000.";

	
		if (amount <= 14000) {
			var duty = eval((amount/100)*1.25);
		}
	
		else if ((amount > 14000) && (amount <= 30000)) {
			var duty = eval((((amount - 14000)/100)*1.5) + 175);
		}
	
		else if ((amount > 30000) && (amount <= 80000)) {
			var duty = eval((((amount - 30000)/100)*1.75) + 415);
		}
	
		else if ((amount > 80000) && (amount <= 300000)) {
			var duty = eval((((amount - 80000)/100)*3.5) + 1290);
		}
	
		else if ((amount > 300000) && (amount <= 1000000)) {
			var duty = eval((((amount - 300000)/100)*4.5) + 8990);
		}
		
		else {
			var duty = eval((((amount - 1000000)/100)*5.5) + 40490);
		}
		if ((loanamount % 1000) != 0 ) {
			var mod = eval(1000-(loanamount % 1000));
			loanamount = -(-loanamount- mod);
		}
		if (loanamount <= 16000) {
			var loanduty = 5;
		}
		else {
			var loanduty = eval((((loanamount - 16000)/1000)*4) + 5);
		}
		
	}

//********************** ACT *************************
	else if (state.value == "ACT") {
		var mortgage = 87;
		var transfer = 170;
		var loanduty = 0;
		var exnotes = "Home Buyer Concession\n"+
"- Eligibility is determined by income and the number of dependent children.\n"+
"- First home buyer concession available for vacant blocks with property values up to $186,600.";	
	if(amount <=326000 && type == 'OO'){
		if(amount <= 285000){
		        duty = 20;
				}
		else if ( amount <= 326000){
			duty = Math.ceil((amount-285000)/100) * 26.66;
		}
	}else
	{


		
				if (amount <= 100000) {
					var duty = Math.max(Math.ceil(eval(amount/100))*2, 20);
				}
				else if (amount <= 200000) {
					var duty = Math.ceil(eval((amount-100000)/100))*3.5 + 2000;
				}
				else if (amount <= 300000) {
					var duty = Math.ceil(eval((amount-200000)/100))*4 + 5500;
				}
				else if (amount <= 500000) {
					var duty = Math.ceil(eval((amount-300000)/100))*5.5 + 9500;
				}
				else if (amount <= 1000000) {
					var duty = Math.ceil(eval((amount-500000)/100))*5.75 + 20500;
				}
				else {
					var duty = Math.ceil(eval((amount-1000000)/100))*6.75 + 49250;
				}
				
				
				/*if (loanamount <= 285000) {
					var loanduty = 20;
				}
				else if ((loanamount > 285000) && (loanamount <= 326000)) {
					var loanduty = eval(((loanamount - 285000)/100)* 26.66);
				}
				else {
					var loanduty = duty;
				}*/
				loanduty = 0.0
	 }
	}

//********************** Queensland *************************
	else if (state.value == "QLD") {
		if ((t_amount % 10000) != 0 ) {
			var mod = eval(10000-(t_amount % 10000));
			t_amount = -(-t_amount - mod);
		}
		var transfer = 111.30;
		if (t_amount > 180000) transfer += Math.ceil(eval((t_amount-180000)/10000))*23.70 + 111.30;

		var mortgage = 111.30;
		
		if (type == 'OO') {
			var exnotes = "First Home Buyers' Rebate\n- Full stamp and mortgage duty exemption for properties valued up to $250,000.\n- Stamp duty rebate applies on a reducing scale for properties valued between $250,000 and $500,000.";
		
			if(loanamount > 70000) loanduty = Math.ceil(eval((loanamount - 70000)/100)) * 0.40;
			else loanduty = 0;
/*						
			if (amount <= 250000) {
				var duty = eval((amount/100)*1);
			}
			else if ((amount > 250000) && (amount <= 500000)) {
				var duty = eval((((amount - 250000)/100)*3.5) + 2500);
			}
			else {
				var duty = eval((((amount - 500000)/100)*3.75) + 11250);
			}
*/

/*			if (amount <= 80000) var duty = 800;
			else if (amount <= 300000) var duty = amount*0.01;
			else if (amount <= 500000) var duty = 3000 + Math.ceil(eval((amount - 300000)/100)) * 3.5;
			else var duty = 11250 + Math.ceil(eval((amount - 500000)/100)) * 3.75;
							
*/
			if (amount <= 300000) var duty = Math.ceil(eval( amount /100)) * 1.0;
			else if (amount <= 500000) var duty = 3000 + Math.ceil(eval((amount - 300000)/100)) * 3.5;
			else var duty = 10000 + Math.ceil(eval((amount - 500000)/100)) * 3.75;
		}
		else {
			var exnotes = "";
			
			loanduty = Math.ceil(eval(loanamount/100)) * 0.40

			if (amount <= 20000) var duty = Math.ceil(eval(amount/100)) * 1.5;
			else if (amount <= 50000) var duty = 300 + Math.ceil(eval((amount - 20000)/100)) * 2.25;
			else if (amount <= 100000) var duty = 975 + Math.ceil(eval((amount - 50000)/100)) * 2.75;
			else if (amount <= 250000) var duty = 2350 + Math.ceil(eval((amount - 100000)/100)) * 3.25;
			else if (amount <= 500000) var duty = 7225 + Math.ceil(eval((amount - 250000)/100)) * 3.5;
			else var duty = 15975 + Math.ceil(eval((amount - 500000)/100)) * 3.75;
/*
			
			if (amount <= 20000) {
				var duty = Math.ceil(eval(amount/100))*1.5;
			}
			else if ((amount > 20000) && (amount <= 50000)) {
				var duty = Math.ceil(eval((((amount - 20000)/100)*2.25) + 300);
			}
			else if ((amount > 50000) && (amount <= 100000)) {
				var duty = eval((((amount - 50000)/100)*2.75) + 975);
			}
			else if ((amount > 100000) && (amount <= 250000)) {
				var duty = eval((((amount - 100000)/100)*3.25) +2350);
			}
			else if ((amount > 250000) && (amount <= 500000)) {
				var duty = eval((((amount - 250000)/100)*3.5) + 7225);
			}
			else {
				var duty = eval((((amount - 500000)/100)*3.75) + 15975);
			}
*/
		}
		
	}

//********************** South Australia *************************
	else if (state.value == "SAN") {
		if (amount <= 5000)
	        transfer = 104;
	    if (amount > 5000 && amount <= 20000)
	        transfer = 116;
	    if (amount > 20000 && amount <= 40000)
	        transfer = 130;
	    if (amount > 40000 && amount <= 50000)
	    { 
		transfer = 186;
	    }
	    if (amount > 50000)
	    { 
		transfer = Math.ceil((amount - 50000)/10000)*57.50 + 186;
	    }
		mortgage = 104;
		
		
		
		
	
	
		
		
		
		
		

		var exnotes = "First Home Owner's Concession\n"+
"Properties valued up to $80,500 will receive a full exemption from stamp duty.  Where the property is valued between $80,501 and $100,000, the concession will reduce from 100% to 50% (2.5% reduction per $1,000 of property value) and will remain at 50% where the property is valued between $100,001 and $150,000.  Thereafter the concession reduces by $24 for every $1,000 increase in property value above $150,000 and phases out completely for first home purchases above $250,000.\n\n"+

"From 1 July 2005, all mortgages taken out for the purposes of securing a loan that has been or is to be applied for home acquisition or improvement will be exempt from stamp duty.";
		
		// Round up to next $100
		amount = Math.ceil(amount/100.0)*100;
		
		if (amount <= 12000) {
			var duty = eval((amount/100.0)*1);
		}
	
		else if ((amount > 12000) && (amount <= 30000)) {
			var duty = eval((((amount - 12000)/100)*2) + 120);
		}
	
		else if ((amount > 30000) && (amount <= 50000)) {
			var duty = eval((((amount - 30000)/100)*3) + 480);
		}
	
		else if ((amount > 50000) && (amount <= 100000)) {
			var duty = eval((((amount - 50000)/100)*3.5) + 1080);
		}
	
		else if ((amount > 100000) && (amount <= 200000)) {
			var duty = eval((((amount - 100000)/100)*4) + 2830);
		}
		else if ((amount > 200000) && (amount <= 250000)) {
			var duty = eval((((amount - 200000)/100)*4.25) + 6830);
		}
		else if ((amount > 250000) && (amount <= 300000)) {
			var duty = eval((((amount - 250000)/100)*4.75) + 8955);
		}
		else if ((amount > 300000) && (amount <= 500000)) {
			var duty = eval((((amount - 300000)/100)*5) + 11330);
		}
		else {
			var duty = eval((((amount - 500000)/100)*5.5) + 21330);
		}
		
		loanamount = Math.ceil(loanamount/100)*100;
		
		if (loanamount <= 400) {
			var loanduty = 0;
		}
		else if ((loanamount > 400) && (loanamount <= 6000)) {
			
			if (type == "OO") {var loanduty = 0;}
		          else {var loanduty = 10;};
		}
		else {
			if (type == "OO") var loanduty = 0; //eval((((loanamount - 6000)/100)*0.35) + 10);
			else var loanduty = eval((((loanamount - 6000)/100)*0.45) + 10);
		}
	}

//********************** Tasmania *************************
	else if (state.value == "TAS") {
		var mortgage = 85.50;
		var transfer = 131;
		var exnotes = "First Home Owner's Rebate\n"+
"- Homes purchased after 20th May 2004 will receive up to $4,000 stamp duty relief for homes purchased for less than $350,000.\n"+
"- A concession of $2,400 is available for the purchase of vacant land providing the dutiable value does not exceed $175,000.\n"+
"- Property must be first home and intended as principal residence.";
		if (amount <= 1300) {
			var duty = 20;
		}
		else if ((amount > 1300) && (amount <= 10000)) {
			var duty = eval((amount/100)*1.5);
		}
	
		else if ((amount > 10000) && (amount <= 30000)) {
			var duty = eval((((amount - 10000)/100)*2) + 150);
		}
	
		else if ((amount > 30000) && (amount <= 75000)) {
			var duty = eval((((amount - 30000)/100)*2.5) + 550);
		}
	
		else if ((amount > 75000) && (amount <= 150000)) {
			var duty = eval((((amount - 75000)/100)*3) + 1675);
		}
	
		else if ((amount > 150000) && (amount <= 225000)) {
			var duty = eval((((amount - 150000)/100)*3.5) + 3925);
		}
		
		else {
			var duty = eval((((amount - 225000)/100)*4) + 6550);
		}
		
		if (loanamount <= 10000) {
			var loanduty = 20;
		}
		else if ( loanamount > 10000 ) {
			var loanduty = eval(((loanamount - 10000)*0.00175) + 20);
		}
		
	}

//********************** Western Australia *************************
	else if (state.value == "WAN") {
		var transfer;
	//Init.getObject("notesResult").setText("WA");
		if (amount <= 85000) {
			transfer = 82;
		}
		else if (amount <= 120000) {
			transfer = 92;
		}
		else if (amount <= 200000) {
			transfer = 112;
		}
		else if (amount <= 300000) {
			transfer = 132;
		}
		else if (amount <= 400000) {
			transfer = 152;
		}
		else if (amount <= 500000) {
			transfer = 172;
		}
		else if (amount <= 600000) {
			transfer = 192;
		}
		else if (amount <= 700000) {
			transfer = 212;
		}
		else if (amount <= 800000) {
			transfer = 232;
		}
		else if (amount <= 900000) {
			transfer = 252;
		}
		else if (amount <= 1000000) {
			transfer = 272;
		}
		else if (amount <= 1100000) {
			transfer = 292;
		}
		else if (amount <= 1200000) {
			transfer = 312;
		}
		else if (amount <= 1300000) {
			transfer = 332;
		}
		else if (amount <= 1400000) {
			transfer = 352;
		}
		else if (amount <= 1500000) {
			transfer = 372;
		}
		else if (amount <= 1600000) {
			transfer = 392;
		}
		else if (amount <= 1700000) {
			transfer = 412;
		}
		else if (amount <= 1800000) {
			transfer = 432;
		}
		else if (amount <= 1900000) {
			transfer = 452;
		}
		else if (amount <= 2000000) {
			transfer = 472;
		}
		else {
			transfer = Math.ceil((amount - 2000000)/100000)*20 + 472;
		}
		
		var mortgage = 82;
		
		var exnotes = "First Home Owner's Concession\n"+
"- Property must be first home and intended as principal residence.\n"+
"- First home buyers will get a full exemption from conveyance duty on homes up to $250,000. Then for every $100 or part thereof above $250,000, $13.20 duty is payable, up to $350,000.\n"+
"- First home purchasers buying vacant land and building a home will receive full rebate on land values to $150,000 and a partial rebate on land values to $200,000.";
		
		if (type == 'OO' && amount <= 200000) {
			if (amount <= 100000) {	
				var duty = Math.ceil(eval(amount/100))*1.5;
			}
			else {
				var duty = Math.ceil(eval((amount - 100000) / 100)) *4.7 + 1500;
			}
		}
		else {
			if (amount <= 80000) {	
				var duty = Math.ceil(eval(amount/100))*2.0;
			}
		
			else if ((amount > 80000) && (amount <= 100000)) {
				var duty = Math.ceil(eval((amount - 80000)/100))*3.0 + 1600;
			}
		
			else if ((amount > 100000) && (amount <= 250000)) {
				var duty = Math.ceil(eval((amount - 100000)/100))*4.0 + 2200;
			}
		
			else if ((amount > 250000) && (amount <= 500000)) {
				var duty = Math.ceil(eval((amount - 250000)/100))*5.0 + 8200;
			}
		
			else {
				var duty = Math.ceil(eval((amount - 500000)/100))*5.4 + 20700;
			}
		}

        var loanduty = 20;

		if (type =="OO") {
		    if (loanamount > 16000) loanduty += Math.ceil(eval((loanamount-16000)/100)) * 0.125;
		}
		else {
			if (loanamount > 10000) loanduty += Math.ceil(eval((loanamount-10000)/100)) * 0.2;
		}
	}

//********************** Northern Territory  *************************
	else if (state.value == "NT") {
		var mortgage = 90;
		var transfer = 90;
		var loanduty = 0;

		var exnotes = "First Home Owner's Concession\n"+
"- If property is your first home anywhere in Australia, then you may be eligible for a concession of up to $8,015.60 on the total stamp duty payable.  This represents the duty on the first $225,000 of the property value. \n"+
"- Property may be an existing home or land to build a new home.\n";

		
		// A rebate of up to $3,640.60 off the total stamp duty payable\n- Property must be first home and intended as principal residence"
	
		if (amount <=500000) {
			newamount = eval(amount / 1000);
			var duty = eval((0.065 * Math.pow(newamount,2)) + (21 * newamount));
		}
	
		else {
			var duty = eval(0.054 * amount);
		}
		if (type =="OO") {
			duty = duty - 2500;
			if (duty < 0) duty = 0;
		}
	}
	total = eval(duty + loanduty + mortgage + transfer);
	total = rounding(total);
	duty = rounding(duty);
	loanduty = rounding(loanduty);
	mortgage = rounding(mortgage);
	transfer = rounding(transfer);
	
	formfield.duty.value = duty;
	formfield.loanduty.value = loanduty;
	formfield.mortgage.value = mortgage;
	formfield.transfer.value = transfer;
	formfield.total.value = total;
	formfield.notes.value = exnotes;
}
function rounding(n) {
	pennies = n * 100;
	pennies = Math.round(pennies);
	strPennies = "" + pennies;
	len = strPennies.length;
	return strPennies.substring(0, len - 2) + "." + strPennies.substring((len - 2), len);
}

