<!--

function checkNumberEntry(input, min, max, msg) {

        var str = input.value;

	if (str == null || input.length == 0) {
		msg = msg + " is blank.  You must fill in this field to calculate.";
		alert(msg);
		return false;
	}

        for (var i = 0; i < str.length; i++) {
            var curr_ch = str.substring(i, i + 1)
            if ((curr_ch < "0" || curr_ch > "9") && curr_ch != '.') {
	        msg = msg + " should only contain digits.  You entered: " + input.value;
                alert(msg);
                return false;
            }
        }
        var num = input.value;
        if (num < min && (min != "none")) {
	    msg = msg + " that's too low: " + input.value + ".  You should only enter values greater than " + min + ".";
            alert("You have entered a " + msg);
            return false;
        }

        if  (num > max && (max != "none")) {
	    msg = msg + " that's high: " + input.value + ".  You should only enter values less than " + max + ".";
            alert("You have entered a " + msg);
            return false;
        }
        input.value = str;
        return true;
}
function myRound(val) {

	val = val * 100;
	val = Math.round(val);
        return val / 100;
}

function computeField(input) {

        if (input.value != null && input.value.length != 0)
            input.value = "" + eval(input.value);
        compute(input.form);
}

function filterNum(str) {
re = /^\$|,/g;
// remove "$" and ","
return str.replace(re, "");
}

function compute(form) {
	document.getElementById('debtResults').style.visibility='';
	document.location="#results";
        var Debt = form.Debt.value;
	var Interest = form.Interest.value;
	var Payment = form.Payment.value

        if (!checkNumberEntry(form.Debt, 1, "none", "Debt")) {
            form.Time.value = "Invalid";
            return;
        }
        if (!checkNumberEntry(form.Payment, 1, "none", "Monthly Payment")) {
            form.Time.value = "Invalid";
            return;
        }

        if (!checkNumberEntry(form.Interest, 1, 99, "% Interest Rate")) {
            form.Time.value = "Invalid";
            return;
        }

        Interest = (Interest / 100.0) / 12.0;

	TimeToPay = (Math.log(0 * Interest - (-Payment)) - Math.log((-Debt) * Interest - (-Payment)))/ Math.log(1 + Interest);

	form.Time.value = Math.round(TimeToPay);
	var TotPaid = myRound(TimeToPay * Payment);
	form.TotPd.value = myRound(TotPaid);
	form.TotInt.value = myRound(TotPaid - Debt);
	
	if (form.Time.value == "NaN") {form.Time.value="Infinity"};
	if (form.TotPd.value == "NaN") {form.TotPd.value="Infinity"};
	if (form.TotInt.value == "NaN") {form.TotInt.value="Infinity"};
	
	if (navigator.appName == "Microsoft Internet Explorer"){
	
		if (form.Time.value == "Infinity") {
			document.all.message.innerHTML  = "Based upon the results of your debt calculation, you will not be able to repay your debts. We strongly recommend that you speak with one of our attorneys to evaluate your legal options.  We offer a <a href='free_evaluation_start.html'>free legal evaluation</a> with an attorney at your convenience."
		} else { 
			document.all.message.innerHTML = "Based upon the results of your debt calculation, we strongly recommend that you speak with one of our attorneys at no cost to you."
		}
	} else {
		if (form.Time.value == "Infinity") {
			document.getElementById("message").innerHTML  = "Based upon the results of your debt calculation, you will not be able to repay your debts.  We strongly recommend that you speak with one of our attorneys to evaluate your legal options.  We offer a <a href='free_evaluation_start.html'>free legal evaluation</a> with an attorney at your convenience."
		} else { 
			document.getElementById("message").innerHTML = "Based upon the results of your debt calculation, we strongly recommend that you speak with one of our attorneys at no cost to you."
		}
	}
}

function clearForm(form) {
        form.Time.value = form.TotPd.value = "";
}
//-->
