function calculate_stamp_duty(frm)
{
	
	var v = frm.property_value.value;
	var sd = '';
	
	
	
	// hide the error msg
	var sd_error = id('calculator_error');
	if (v == "" || !Math.round(v) )
	{
	
		sd_error.innerHTML= 'Please enter a property value';
		sd_error.style.display = 'block';
		frm.stamp_duty_vic.value = '';
		return false;
	}
	else
	{
		sd_error.innerHTML= '';		
		sd_error.style.display = 'none';
	}

	

	// calculate stamp duty
	frm.stamp_duty_vic.value = 0;
	
	if(v <= 20000)
	{
		var sd = eval(((v)/100)*1.4);
	}
	else if ((v > 20000) && (v < 115000))
	{
		var sd = eval((((v - 20000)/100)*2.4) + 280);
	}
	else if ((v >= 115000) && (v < 870000)) {
		var sd = eval((((v - 115000)/100)*6) + 2560);
	}
	else {
		var sd = eval(((v)/100)*5.5);
	}
   
    frm.stamp_duty_vic.value = sd;
	frm.stamp_duty_vic.value = '$ ' + addc(cents(sd));

}


function calculate_loan_repayment(frm)
{
	
	var la = frm.loan_amount.value;
	var lt = frm.loan_term.value;
	var lr = frm.loan_rate.value;
	
	
	
	// hide the error msg
	var l_error = id('calculator_error');
	if (la == "" || !Math.round(la) ||
		lt == "" || !Math.round(lt) ||
		lr == "" || !Math.round(lr) 
	)
	{
		l_error.innerHTML= 'Please enter the Loan Amount, Loan Term and Interest Rate';
		l_error.style.display = 'block';
		frm.loan_repayment.value = '';
		return false;
	}
	else
	{
		l_error.innerHTML= '';		
		l_error.style.display = 'none';
		
		var mi=lr/1200;
		var base=1;
		var mbase=1+mi;
		var dec="";
		
		for(i=0;i<lt*12;i++)
		{
			base=base*mbase;
		}
		
		var mp = Math.floor(la*mi/(1-(1/base)));
		
		
		if((mp*100)%10==0)
		{
			dec = "0";
		}
	
		if((mp*10)%10==0){
			dec = ".00";
		}
		
		
		frm.loan_repayment.value = "$ " + mp + dec;
	}

	
	

}





function addc(i)
{
	if (i.length >= 10 && i.length <= 12)
	{
		i = (i.substring(0,i.length-9) + "," + i.substring(i.length-9,i.length-6) + "," + i.substring(i.length-6,i.length));
	}
	else if (i.length >= 7 && i.length <= 9) {
		i = (i.substring(0,i.length-6) + "," + (i.substring(i.length-6,i.length)));
	}
	return i;
}

function cents(i)
{
	var d = Math.floor(i);
	var tot = Math.round(i*100).toString();
	return (tot.substring(0,tot.length-2) + "." + tot.substring(tot.length-2,tot.length))
}

