function floor(number)
{
  return Math.floor(number*Math.pow(10,0))/Math.pow(10,0);
}

function ChangeCurrency(frm)
{
var currency_type = document.form2.currency[document.form2.currency.selectedIndex].value;
var currency_rate=document.form2.currency_rate.value;
	
	if(currency_type!="euro")
	{
	document.form2.price.value = document.form2.property_price.value;
	}
	else
	{
	document.form2.price.value = floor((document.form2.property_price.value * currency_rate));
	}
updatemortgage();
dosum(frm);
}

function dosum(frm)
{

	document.form2.amount.value = document.form2.price.value - document.form2.deposit.value;
	
	var currency_type = document.form2.currency[document.form2.currency.selectedIndex].value;
	var currency_rate=document.form2.currency_rate.value;
	var amount=document.form2.amount.value;

	var term=document.form2.term.value;
	var rate=document.form2.rate.value;
	var method=document.form2.method.value;

	var months = term*12;
	var interestrate= rate/100;
	var parta=interestrate/12;
	var partb=parta+1;
	var partc=Math.pow(partb,months);
	//alert(partc);
	if(method=='Repayment')
	{
	var R = interestrate;
	var A = amount;
	var T = term;
	
	var P = ((A*R)/12) * (1/(1-(Math.pow(1/(1+R),T))));
		document.form2.result.value=floor(P);
	}
	else
	{
		var repaymenta=(amount * parta);
		var repayment = repaymenta;
		document.form2.result.value=floor(repaymenta);
	}
	
	//if(document.form2.currency[document.form2.currency.selectedIndex].value=="euro")
	//{
	//document.form2.result.value=floor((document.form2.result.value / currency_rate));
	//}
	
}

function updatemortgage(){
var currency_type = document.form2.currency[document.form2.currency.selectedIndex].value;
	var currency_rate=document.form2.currency_rate.value;

	var price=document.form2.price.value;
	document.form2.deposit.value = price * 0.30;
	document.form2.amount.value = floor(document.form2.price.value - document.form2.deposit.value);
}