// JavaScript Document
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;
			var transfer = (t_amount / 1000) * 2.46 + 116;
		}
		else {
			//var transfer = 1325;
			var transfer = 1346;
		}
		//transfer = Math.ceil(transfer) ;
		//mortgage = 75;
		mortgage = 95.1;
		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 (type != "INV")
        {
            if (amount <= 25000)
            {
                duty = amount / 100 * 1.40;
            }
            else if (amount > 25000 && amount <= 130000)
            {
                duty = (amount - 25000) / 100 * 2.40 + 350;
            }
            else if (amount > 130000 && amount <= 440000)
            {
                duty = (amount - 130000) / 100 * 5 + 2870;
            }
            else if (amount > 440000 && amount <= 550000)
            {
                duty = (amount - 440000) / 100 * 6 + 18370;
            }
            else if (amount > 550000 && amount <= 960000)
            {
                duty = (amount - 550000) / 100 * 6 + 28070;
            }
            else
            {
                duty = amount / 100 * 5.50;
            } // end else if
        }
        else if (amount <= 25000)
        {
            duty = amount / 100 * 1.40;
        }
        else if (amount > 25000 && amount <= 130000)
        {
            duty = (amount - 25000) / 100 * 2.40 + 350;
        }
        else if (amount > 130000 && amount <= 550000)
        {
            duty = (amount - 130000) / 100 * 6 + 2870;
        }
        else if (amount > 550000 && amount <= 960000)
        {
            duty = (amount - 550000) / 100 * 6 + 28070;
        }
        else
        {
            duty = amount / 100 * 5.50;
        } // end else if
        if (loanamount % 200 != 0)
        {
            loanamount_VIC = 200 - loanamount % 200;
            loanamount = -(-loanamount - loanamount_VIC);
        } // end if
		/*
		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 = 92;
		var transfer = 92;
		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);
		}
		var loanduty = 0;
	}

//********************** ACT *************************
	else if (state.value == "ACT") {
		var mortgage = 93;
		var transfer = 183;
		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 = 120.5000;
		var transfer = 124.2000;
		if (t_amount > 180000) transfer += Math.ceil(eval((t_amount-180000)/10000))*25.6;

		//var mortgage = 120.5000;
		var mortgage = 124.2000;
		
		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.";
		
			loanduty = 0;
			if (amount <= 350000)
            {
                duty = amount * 1.000000 / 100;
            }
            else if (amount > 350000 && amount <= 540000)
            {
                duty = 3500 + Math.ceil((amount - 350000) / 100) * 3.50;
            }
            else if (amount > 540000 && amount <= 980000)
            {
                duty = 10150 + Math.ceil((amount - 540000) / 100) * 4.50;
            }
            else
            {
                duty = 29950 + Math.ceil((amount - 980000) / 100) * 5.25;
            } // end else if
			/*
			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
			loanduty = 0
			
			if (amount <= 5000)	duty = 0;
			else if (amount <= 75000) var duty = Math.ceil(eval(amount/100)) * 1.5;
			else if (amount <= 540000) var duty = 1050 + Math.ceil(eval((amount - 75000)/100)) * 3.50;
			else if (amount <= 980000) var duty = 17325 + Math.ceil(eval((amount - 540000)/100)) * 4.50;
			//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 = 37125 + Math.ceil(eval((amount - 980000)/100)) * 5.25;
			/*
			else 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 = 112;
	    if (amount > 5000 && amount <= 20000)
	        transfer = 125;
	    if (amount > 20000 && amount <= 40000)
	        transfer = 140;
	    if (amount > 40000 && amount <= 50000)
	    { 
		transfer = 201;
	    }
	    if (amount > 50000)
	    { 
		transfer = Math.ceil((amount - 50000)/10000)*62 + 201;
	    }
		mortgage = 112;

		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.15) + 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);
		}
		
		var loanduty = 0;
		/*
		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 = 88;
		}
		else if (amount > 85000 && amount <= 120000)
        {
            transfer = 98;
        }
        else if (amount > 120000 && amount <= 200000)
        {
            transfer = 118;
        }
        else
        {
            transfer = Math.ceil((amount - 200000) / 100000) * 20 + 118;
        } // end else if
		/*
		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 = 88;
		
		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')
        {
            if (amount <= 120000)
            {
                duty = Math.ceil(amount / 100) * 1.90;
            }
            else if (amount > 120000 && amount <= 150000)
            {
                duty = Math.ceil((amount - 12000) / 100) * 2.85 + 2280;
            }
            else if (amount > 150000 && amount <= 360000)
            {
                duty = Math.ceil((amount - 150000) / 100) * 3.80 + 3135;
            }
            else if (amount > 360000 && amount <= 725000)
            {
                duty = Math.ceil((amount - 360000) / 100) * 4.75 + 11115;
            }
            else
            {
                duty = Math.ceil((amount - 725000) / 100) * 5.15 + 28453;
            } // end else if
        }
        else if (amount <= 80000)
        {
            duty = Math.ceil(amount / 100) * 1.90;
        }
        else if (amount > 80000 && amount <= 100000)
        {
            duty = Math.ceil((amount - 80000) / 100) * 2.85 + 1520;
        }
        else if (amount > 100000 && amount <= 250000)
        {
            duty = Math.ceil((amount - 100000) / 100) * 3.80 + 2090;
        }
        else if (amount > 250000 && amount <= 500000)
        {
            duty = Math.ceil((amount - 250000) / 100) * 4.75 + 7790;
        }
        else
        {
            duty = Math.ceil((amount - 500000) / 100) * 5.15 + 19665;
        } // end else if
        loanduty = 0;
		/*
		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 <=525000) {
			newamount = eval(amount / 1000);
			var duty = eval((0.06571441 * Math.pow(newamount,2)) + (15 * newamount));
		}
	
		else {
			var duty = eval(0.0495 * 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;
	if (n != 0)
		return strPennies.substring(0, len - 2) + "." + strPennies.substring((len - 2), len);
	else 
		return "0";
}

//<![CDATA[

var dw=405; /* div width plus total border width. */
var dh=-200; /* (div height plus total border width) divided by -2. In this case (368+6)/-2 .*/
//var lt=(screen.width-dw)/2;
var lt=150;

var speed=10;

function one() 
{	
	var obj=document.getElementById("dialogue").style;
	obj.position="absolute";
	
	if( navigator.appName=="Netscape") 
	{
		ns=window.scrollY;
		obj.top=75+"%"
		obj.marginTop=dh+ns+"px";
		obj.left=lt+"px";
	}
	else 
	{
		ie=document.body.parentNode.scrollTop;
		obj.top=75+"%";
		obj.marginTop=dh+ie+"px";
		obj.left=lt+"px";
	}
	setTimeout("one()",speed);
}
function one_email() 
{	
	var obj=document.getElementById("dialogue_email").style;
	obj.position="absolute";
	
	if( navigator.appName=="Netscape") 
	{
		ns=window.scrollY;
		obj.top=60+"%"
		obj.marginTop=dh+ns+"px";
		obj.left=lt+"px";
	}
	else 
	{
		ie=document.body.parentNode.scrollTop;
		obj.top=60+"%";
		obj.marginTop=dh+ie+"px";
		obj.left=lt+"px";
	}
	setTimeout("one_email()",speed);
}
//onload=one;
//]]>
function showPopUp()
{
one();
document.getElementById("dialogue").style.display = "";
document.getElementById("overlay").style.display = "";
}
function showPopUp_email()
{
one_email();
document.getElementById("dialogue_email").style.display = "";
document.getElementById("overlay").style.display = "";
}
function hidePopUp()
{
document.getElementById("dialogue").style.display = "none";
document.getElementById("overlay").style.display = "none";
}
function hidePopUp_email()
{
document.getElementById("dialogue_email").style.display = "none";
document.getElementById("overlay").style.display = "none";
}
function validate()
{
	if (checkForm())
	{
		document.getElementById("emailStatus").innerHTML = "Sending...";
		document.sender_form.state.value = document.frm.state.value;
		document.sender_form.amount.value = document.frm.amount.value;
		document.sender_form.loanamount.value = document.frm.loanamount.value;
		document.sender_form.Type.value = document.frm.Type.value;
		document.sender_form.mortgage.value = document.frm.mortgage.value;
		document.sender_form.transfer.value = document.frm.transfer.value;
		document.sender_form.duty.value = document.frm.duty.value;
		document.sender_form.loanduty.value = document.frm.loanduty.value;
		document.sender_form.total.value = document.frm.total.value;
		document.sender_form.notes.value = document.frm.notes.value;
    	url="send_stampduty.php?"+getData();
		// document.write(url)
		loadXML(url,showStat)
	}
}
function showStat()
{
	var msg="";
	var proceed="";
	var nodes=xdoc.getElementsByTagName("proceed");
	if(nodes[0].childNodes[0])
		proceed=nodes[0].childNodes[0].nodeValue;
	nodes=xdoc.getElementsByTagName("msg");
	if(nodes[0].childNodes[0])
		msg=nodes[0].childNodes[0].nodeValue;
	if(proceed=="Y" && msg=="")
	{
		document.getElementById("emailStatus").innerHTML = msg;		
		hidePopUp_email();
	}
	else
	{
		document.getElementById("emailStatus").innerHTML = msg;
	}
}
function getData()
{
	var str='';
	for(var i=0;i<document.sender_form.elements.length;i++)
	{
	var itm=document.sender_form.elements[i];
	if(itm.name && itm.value)
		{   
		    if(itm.type=="radio" || itm.type=="checkbox" ) 
			{
			if(itm.checked)
			str+=itm.name+"="+itm.value+"&";
			}
		    else
			str+=itm.name+"="+itm.value+"&";
		}
	}
	
	return(str)
}
function loadXML(url,doFunc)
{
	if (window.XMLHttpRequest)
	{
		xmlhttp=new XMLHttpRequest()
	}
	// code for IE
	else if (window.ActiveXObject)
	{
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
	else
		alert('Your browser cannot handle this script');
	// xmlhttp.onreadystatechange=getAll;
	xmlhttp.onreadystatechange=function()
	{ 
		if (xmlhttp.readyState==4)
			if (xmlhttp.status==200)
			{  
				xdoc=xmlhttp.responseXML;
				doFunc();
			}
			else
				alert("Problem retrieving XML data:" + xmlhttp.statusText)
	}		
    xmlhttp.open("GET",url,true)
    xmlhttp.send(null)
}
function checkForm() {
	toEmail = document.getElementById("toEmail").value;
	if (toEmail == "") {
		//alert ("Please enter the valid email address");
		document.getElementById("emailStatus").innerHTML = "Please enter the valid email address";
		document.getElementById("toEmail").select();
		document.getElementById("toEmail").focus();
		return false;
	}	
	return true;
}
function stampduty_print(){
	
	for(var i=0;i<document.frm.elements.length;i++)
	{		
		var itm=document.frm.elements[i];
		/*
		if (document.getElementById("print_"+itm.name))
		{
			document.getElementById("print_"+itm.name).innerHTML = itm.value;
			if (itm.value == "INV")
				document.getElementById("print_"+itm.name).innerHTML
		}
		*/
		if(itm.type=="radio")
		{
			if(itm.checked)
			{
				if (itm.value == "OO")
					document.getElementById("print_"+itm.name).innerHTML = "to live in";
				else if (itm.value == "INV")
					document.getElementById("print_"+itm.name).innerHTML = "an investment";
				else
					document.getElementById("print_"+itm.name).innerHTML = itm.value;
			}
		}
		else if (itm.type != "button" && itm.type!= "reset")
		{
			document.getElementById("print_"+itm.name).innerHTML = itm.value;
		}
	}
	document.getElementById("FTAddress").innerHTML = FTAddress;
	document.getElementById("FTFax").innerHTML = FTFax;
	document.getElementById("FTPhone").innerHTML = FTPhone;
	document.getElementById("FTWeb").innerHTML = FTWeb;
	document.getElementById("FTMail").innerHTML = FTMail;
	window.print();
}
