//start calculations
function startCalc1() {
    interval = setInterval("calc1()",1);
}

function startCalc2() {
    interval = setInterval("calc2()",1);
}

//calculations
function calc1() {
  borrow = document.cost.borrow.value;
	period = document.cost.period.value;
	type = document.cost.type.selectedIndex;
	term = document.cost.period[document.cost.period.selectedIndex].value;
	rate = document.cost.int1.value + '.'+ document.cost.int2.value;
  
	monthlyrepayments = ((borrow * rate) / (1200));
	monthlyrepayments = (monthlyrepayments * 100);
	monthlyrepayments = Math.round(monthlyrepayments);
	monthlyrepayments = (monthlyrepayments / 100);
	
	if (type == 0) {
		document.cost.total1.value = monthlyrepayments;
		return false;
	}
		
	if (type == 1) {
		upper = (borrow*rate*12);
	  	 mid = Math.pow((1+(rate/1200)),(-period*12));
	  	 mid2 = (100*12*(1-mid));
	  	 answer = ((upper/mid2)/12);
	  	
	  	document.cost.total1.value = answer.toFixed(2);
    }

	return false;
}

function parseInteger(val)
{
	var i;
	do
	{
		i = val.indexOf(',');
		val = val.substring(0, i) + val.substring(i+1);
	} while (val.indexOf(',') != -1);
	return parseInt(val);
}

function calc2() {	
	income1 = document.borro.income1.value;
	income2 = document.borro.income2.value;
	bonus1 = document.borro.bonus1.value;
	bonus2 = document.borro.bonus2.value;
	
	if (bonus1.length == 0)
		bonus1 = "0";
	
	if (bonus2.length == 0)
		bonus2 = "0";
	
	if (income2.length == 0)
		income2 = "0";

	if (income2 == 0) {
		res1 = (income1*3.75)+(bonus1*3.75);
		res2 = (income1 * 5)+(bonus1 * 5);
		
		document.borro.total2.value = res1.toFixed(2);
		document.borro.total3.value = res2.toFixed(2);
	
	}else if(income2 > 0) {
		res1 = (income1*3.25)+(bonus1*3.25)+(income2*3.25)+(bonus2*3.25);
		res2 = (income1*4.25)+(bonus1*4.25)+(income2*4.25)+(bonus2*4.25);
		
		document.borro.total2.value = res1.toFixed(2);
		document.borro.total3.value = res2.toFixed(2);
	}
}		