<!--
var bomb = 0;
if( (navigator.appName=='Netscape') && (parseInt(navigator.appVersion) == 2) ){
	bomb = 1;
}

function calcTotal(start,end){
	if(bomb == 1) return false;
	var total = 0;
	for(i=start;i<=end;i++){
		var tmp = window.document.forms[2].elements[i].value;
		tmp = parseFloat(tmp);
		if(! isNaN(tmp) ){
			total += Math.round(tmp * 100);
		}
	}
	total = total / 100;
	return total;
}

function calculateBudget() {
	if(bomb == 1) return;
	if (document.forms) {
		var totalOut = calcTotal(0,11);
		var totalIn = calcTotal(12,12);
		window.document.forms[2].elements[14].value=totalIn;
		window.document.forms[2].elements[13].value=totalOut;
		window.document.forms[2].elements[15].value=totalIn-totalOut;	
	}
}

function numbersonly() {
if (event.keyCode < 48 || event.keyCode > 57) return false;
}

function numbersandpointonly(){
// Allow point/dot character for decimal placing
if (event.keyCode == 46) {
	return true; }
if (event.keyCode < 48 || event.keyCode > 57)  return false;
}
//-->
<!--
//Function to calculate the loan repayments etc.
	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 calculate(){
		var calcs = 12; //this is the number of calculations ie number of months in a year
		var loan = 0;
		var rate = 0;
		var intloan = "0"; //after parseInt on loan
		var intrate = "0"; //after parseInt on interest rate
		var term = "0"; //value of the term of mortgage
		var intterm = "0"; //term after parseint
		var monthlyterm; // term multiplied by 12
		var rate100 = "0"; //value of rate once divided by 100
		var monthlyrepayments = "0"; //monthlyrepayments value
		var mortgagetype = 1; //Mortgage Type from list box
		
		loan = document.mortgageform.loanvalue.value;
		rate = document.mortgageform.interest.value + '.'+ document.mortgageform.interest2.value;
		
		mortgagetype = document.mortgageform.mortgagetype.selectedIndex; 
		
		if (!parseInteger(loan) > 0){
			alert("Please enter an amount to borrow   ");
			document.mortgageform.loanvalue.focus();
			return false;
		}

		if (!parseInteger(rate) > 0|isNaN(rate)){
			alert("Please enter an interest rate   ");
			document.mortgageform.interest.focus();
			return false;
		}

		intloan = parseInteger(loan);
		
		if (!intloan > 0){
			alert("Please enter an amount for the mortgage   ");
			document.mortgageform.loanvalue.focus();
			return false;
		}
		
		if (!intrate > 0){
			alert("Please enter an interest rate   ");
			document.mortgageform.interest.focus();
			return false;
		}
		
		term = document.mortgageform.mortgage[document.mortgageform.mortgage.selectedIndex].value;

		//term = (term + 1) // aligns selected index with value
		intterm = parseInt(term);
		
		rate100 = (intrate / 100)
		
		monthlyrepayments = ((intloan * rate) / (1200))
		
		monthlyrepayments = (monthlyrepayments * 100);
		monthlyrepayments = Math.round(monthlyrepayments);
		monthlyrepayments = (monthlyrepayments / 100);
		monthlyrepayments = padZero(monthlyrepayments);	
		
		// Interest Only vs Repayment Payment types
		if (mortgagetype == 0) { // Interest Only Mortgage Payment Type
			document.mortgageform.CRGanswer.value = monthlyrepayments;
			return false; }
			
		//document.mortgageform.IOGanswer.value = monthlyrepayments;
		if (mortgagetype == 1) { // Repayment Mortgage Payment Type
			var topline = (intloan * rate * 12);
			var mid = Math.pow((1+(rate/1200)), (-term * 12));
			mid = (100 * 12 * (1 - mid));
			var answer = ((topline / mid) / 12);
			answer = (answer * 100);
			answer = Math.round(answer);
			answer = (answer / 100);
			answer = padZero(answer);
			document.mortgageform.CRGanswer.value = answer; }
		
	return false;			
	}

//Function for borrowing money	
	function range1(){
		//rem isNan
		document.calculationform.range1res.value = ""

		var income1 = 0;
		var income2 = "";
		var newincome1 = 0 //income1 after parseint
		var newincome2 = 0 //income2 after parseint
		var bonus1 = "";
		var bonus2 = "";
		var newbonus1 = 0 //bonus1 after parseint
		var newbonus2 = 0 //bonus2 after parseint
		var inc9 = 0
		var rgeres1 = 0 //range results
		var rgeres2 = 0 //second lot of results
		var intres1 = 0
		var intres2 = 0
				
		income1 = document.calculationform.income1.value;
		income2 = document.calculationform.income2.value;
		bonus1 = document.calculationform.commission1.value;
		bonus2 = document.calculationform.commission2.value;
		
		if (bonus1.length == 0){
			bonus1 = "0"
		}
		
		if (bonus2.length == 0){
			bonus2 = "0"
		}
		
		if (income2.length == 0){
			income2 = "0"
		}
		
		newincome1 = parseInteger(income1);
		newincome2 = parseInteger(income2);
		newbonus1 = parseInteger(bonus1);
		newbonus2 = parseInteger(bonus2);
		
		if (!newincome1 > 0){
			alert("Please enter an Income   ");
			document.calculationform.income1.focus();
			return false;
			}

		if (income2.length > 1 && !newincome2 > 0) {
			alert("Please enter an Income   ");
			document.calculationform.income2.focus();
			return false;
		}else{	// (income1 == greatest; income2 == smallest)
			if(income2.length > 1 && newincome2 > 0 && newincome2 > newincome1){
				newincome1 = parseInt(income2);
				newincome2 = parseInt(income1);
			}
		}

		if (bonus1.length > 1 && !newbonus1 > 0) {
			alert("Please enter a Bonus   ");
			document.calculationform.commission1.focus();
			return false;
			}
		
		if (bonus2.length > 1 && !newbonus2 > 0) {
			alert("Please enter a Bonus   ");
			document.calculationform.commission2.focus();
			return false;
			}
		
		if (newbonus1 >= 1){
			newbonus1 = (newbonus1 * 0.5)
			}else{
			newbonus1 == 0
			}
		
		if (newbonus2 >= 1){
			newbonus2 = (newbonus2 * 0.5)
			}else{
			newbonus2 == 0
			}

		newincome1 = (newincome1 + newbonus1)
		rgeres1 = newincome1 //this is used for the second calculation
		newincome2 = (newincome2 + newbonus2)
		rgeres2 = newincome2 //again used for the second set of results
		
		var res1 = (newincome1 + newincome2);
		var res2
		res1 = (res1 * 3);
		res2 = (newincome1 * 4);
		
		intres1 = ((rgeres1 * 5) + rgeres2)
		intres2 = ((rgeres1 + rgeres2) * 4)
				
		if (res1 == res2){
			document.calculationform.range1res.value = padZero(res1)
		}else if(res1 > res2){ 
			document.calculationform.range1res.value = padZero(res1)
		}else{
			document.calculationform.range1res.value = padZero(res2)
		}
		
		if (intres1 == intres2){
			document.calculationform.range2res.value = padZero(intres1)
		}else if(intres1 > intres2){
			document.calculationform.range2res.value = padZero(intres1)
		}else{
			document.calculationform.range2res.value = padZero(intres2)
		}
		
		return false;
	}
	
	function padZero(n){
		var a;
		n = n.toString();
		if (n.indexOf(".")!=-1) {
			a=n.split(".");
			n=(a[1].length==1)?n+"0":n;
		}
		return n;
	}
	
	// Helper Function to call Calculate Mortgage Function
	// Called from onchange event of MortgageType List Box
	function doCalculate() {calculate();}
	
	// Helper Function to call the range function Function
	// Called from Click here link
	function dorange() {range1();}
		
//-->	