function checkForm() {
var str = "The following errors were found:\n\n";
var errorMsg = str;
	
	
	if (document.apply_form.name.value == 0) {
		errorMsg = errorMsg + " :: Please enter your name.\n";
	}
	if (document.apply_form.address.value == 0) {
		errorMsg = errorMsg + " :: Please enter your address.\n";
	}
	if ((/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.apply_form.email.value)) == 0) {
		errorMsg = errorMsg + " :: Please enter a valid email address.\n";
	}
	if (document.apply_form.city.value == 0) {
		errorMsg = errorMsg + " :: Please enter your city.\n";
	}
	if (document.apply_form.zip.value == 0) {
		errorMsg = errorMsg + " :: Please enter your zip code.\n";
	}
	if (document.apply_form.mortgages.value == 0) {
		errorMsg = errorMsg + " :: Please indicate the number of properties or mortgages.\n";
	}
	if (document.apply_form.ratio.value =='') {
		errorMsg = errorMsg + " :: Please calculate your debt to income ratio below.\n";
	}

	if (errorMsg != str) {
		alert (errorMsg);
		return false;
	}
}


function cent(amount) {
	 return (amount == Math.floor(amount)) ? amount + '.00' : (  (amount*10 == Math.floor(amount*10)) ? amount + '0' : amount);
}

function total(what,incomenumber,debtnumber) {
	var incomeTotal = 0;
	var debtTotal = 0;
	for (var i=1;i<incomenumber;i++) {
		if (what.elements['income' + i].value == '')
			what.elements['income' + i].value == '0.00'; // fix for Opera.
		incomeTotal += (what.elements['income' + i].value - 0);
	}
	for (var i=1;i<debtnumber;i++) {
		if (what.elements['debt' + i].value == '')
			what.elements['debt' + i].value == '0.00'; // fix for Opera.
		debtTotal += (what.elements['debt' + i].value - 0);
	}
	what.incomeTotal.value = cent(Math.round(incomeTotal*Math.pow(10,2))/Math.pow(10,2));
	what.debtTotal.value = cent(Math.round(debtTotal*Math.pow(10,2))/Math.pow(10,2));
	what.ratio.value = cent(Math.round(what.debtTotal.value/what.incomeTotal.value*Math.pow(10,2))/Math.pow(10,2));
	document.location.href='/apply.cfm#submit';
	return false;
}

function toggle_visibility(id) {
	var e = document.getElementById(id);
	if(e.style.display == 'block')
		e.style.display = 'none';
	else
		e.style.display = 'block';
}