
function checkForZero(field) {
        if (field.value == 0 || field.value.length == 0) {
            alert ("This field can't be 0!");
            field.focus(); }
        else
	    calculatePayment(field.form);
    }

function cmdCalc_Click(form) {
        if (form.price.value == 0 || form.price.value.length == 0) {
            alert ("The Price field can't be 0!");
            form.price.focus(); }
        else if (form.ir.value == 0 || form.ir.value.length == 0) {
            alert ("The Interest Rate field can't be 0!");
            form.ir.focus(); }
        else if (form.term.value == 0 || form.term.value.length == 0) {
            alert ("The Term field can't be 0!");
            form.term.focus(); }
        else
            calculatePayment(form);
    }

function curr(amount)
{
	var i = parseFloat(amount);
	if(isNaN(i)) { i = 0.00; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	s = new String(i);
	if(s.indexOf('.') < 0) { s += '.00'; } 	if(s.indexOf('.') == (s.length - 2)) { s += '0'; } 	s = minus + s; 	return s; } function numberFormat(nStr,prefix){ 	 	nStr += ''; 	x = nStr.split('.'); 	x1 = x[0]; 	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return prefix + x1 + x2;

}

function calculatePayment(form) {
        princ = form.price.value - form.dp.value;
        intRate = (form.ir.value/100) / 12;
        months = form.term.value * 12;
    document.getElementById('pmt').innerHTML = numberFormat(Math.floor((princ*intRate)/(1-Math.pow(1+intRate,(-1*months)))*100)/100,"$");
  	document.getElementById('principle').innerHTML = numberFormat(princ,"$");
	document.getElementById('payments').innerHTML = months;
	document.getElementById('total').innerHTML = numberFormat(months * (Math.floor((princ*intRate)/(1-Math.pow(1+intRate,(-1*months)))*100)/100).toFixed(2),"$");
    }
	
sfHover = function() {
	var sfEls = document.getElementById("suckerfishnav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);


