function SubmitForm()
{
document.calculator.action = "";
document.calculator.submit()
}

function printPartOfPage(elementId)
{
 var printContent = document.getElementById(elementId);
 var windowUrl = 'about:blank';
 var uniqueName = new Date();
 var windowName = 'Print' + uniqueName.getTime();
 var printWindow = window.open(windowUrl, windowName, 'left=50000,top=50000,width=0,height=0');
	
	var grossdiv = document.getElementById('grossdiv').innerHTML;
	var interestdiv = document.getElementById('interestdiv').innerHTML;
	var yearsdiv = document.getElementById('yearsdiv').innerHTML;
	
	
	document.getElementById('grossdiv').innerHTML = document.getElementById('gross').value;
	document.getElementById('interestdiv').innerHTML = document.getElementById('interest').value;
	document.getElementById('yearsdiv').innerHTML = document.getElementById('years').value;

 printWindow.document.write(printContent.innerHTML);
 printWindow.document.close();
 printWindow.focus();
 printWindow.print();
 printWindow.close();
 
 	document.getElementById('grossdiv').innerHTML = grossdiv;
	document.getElementById('interestdiv').innerHTML = interestdiv;
	document.getElementById('yearsdiv').innerHTML = yearsdiv;
	
	document.getElementById('print_button').style.display = "none";
	document.getElementById('months').innerHTML = "0";
	document.getElementById('payment').innerHTML = "0";
	document.getElementById('value').innerHTML = "0";
}

//Calculator
var rExp = /[^\d.]*/gi;
var CURRENT_INTEREST_RATE = 12.5;

function GetElement(id){
	if(document.getElementById) return document.getElementById(id);
	if(document.all) return document.all[id];
	return null;
}

function CleanFloat(val){
	val = ("" + val).replace(rExp, "");	
	pt1 = val.indexOf('.');
	if(pt1 > -1 && pt1 < val.length - 1){
		pt2 = val .indexOf('.',pt1+1);
		if(pt2 > -1){
			val = val.substring(0,pt2-1);
		}
	}
	if(val.length == 0) return 0;
	return parseFloat(val);
} 

function CleanInt(val){
	val = ("" + val).replace(rExp, "");	
	pt1 = val.indexOf('.');
	if(pt1 > -1){
		val = val.substring(0,pt1-1);
	}
	if(val.length == 0) return 0;
	return parseInt(val);
}

function FormatNumber(val,prefix){
	var txt,dec;
	var neg = false;
	if(prefix == 'undefined') prefix = '';
	val = CleanFloat(val);
	val = Math.floor(val * 100) / 100;
	txt = "" + val;
	if(!(isNaN(txt)) && txt.toLowerCase().indexOf('infinity') == -1){
		dec = (txt.indexOf(".") > -1?txt.substring(txt.indexOf('.'),txt.length):'.00');
		if(dec.length == 2) dec += "0";
		txt = (txt.indexOf(".") > -1?txt.substring(0,txt.indexOf('.')):txt);
		if(txt.length > 3){
			im = Math.floor(txt.length/3);
			for(i=1;i<=im;i++){
				if(txt.length - (3*i) - (i-1) > 0) txt = txt.substring(0,txt.length - (3*i) - (i-1)) + "," + txt.substring(txt.length - (3*i) - (i-1),txt.length);
			}
		}
		txt = prefix + txt + dec;
	}
	return txt;
}

function CalculateRepayments(income,intrate,term)
{
	var rate, ifactor, months;
	var results = new Array();
	
	income= CleanFloat(income);
	intrate = CleanFloat(intrate);
	term = CleanInt(term);
	
	rate = income * 0.3;	
	months = term * 12;
	intrate = intrate/1200;
	ifactor= 0;
	for(i=1;i<=months;i++)
	{
		ifactor = ifactor + Math.pow((1+intrate),(-1*i));
	
	}			
	results['months'] = months;
	results['payment'] = rate;
	results['value'] = rate*ifactor;
	return results;	
}

function frmcalc(frm)
{
	var income, term, intrate;
	var results;
	
	//showhideresults('hidden');
	// Collect and check the gross monthly income value
	income = CleanFloat(frm.gmi.value);			
	if (!income){
		alert("Please enter a valid number for the Gross Monthly Income field.");
		frm.gmi.focus();
		return false;
	}
	// Collect the interest rate value
	intrate = CleanFloat(frm.ir.value);
	if (!intrate) {
		alert("Please select the interest rate for this loan.");
		frm.ir.focus();
		return false;
	}			
	// Collect and check the terms value
	term = CleanInt(frm.ytr.value);	
	if (!term) {
		alert("Please select the number of years to repay this loan.");
		frm.ytr.focus();
		return false;
	}
	document.getElementById('print_button').style.display = "";
	// Fetch and display the results
	results = CalculateRepayments(income,intrate,term);
	var months = GetElement('months');
	var payment = GetElement('payment');
	var value = GetElement('value');
	if(months) months.innerHTML = results['months'];
	if(payment) payment.innerHTML = FormatNumber(results['payment'],'R');
	if(value) value.innerHTML = FormatNumber(results['value'],'R');	
	return false;
}

function doText(t, e) {
document.getElementById('mapinfo').style.display = "";
document.getElementById('mapinfo').innerHTML = t;

}

function doClear() {
	document.getElementById('mapinfo').style.display = "none"; 
} 
