function checkNumber(input, min, max, msg)
{
    msg = msg + " field has invalid data: " + input.value;
    var str = input.value;
    for (var i = 0; i < str.length; i++) {
        var ch = str.substring(i, i + 1)
        if ((ch < "0" || "9" < ch) && ch != '.') {
            alert(msg);
            return false;
        }
    }
    var num = parseFloat(str)
    if (num < min || max < num) {
        alert(msg + " not in range [" + min + ".." + max + "]");
        return false;
    }
    input.value = str;
    return true;
}
function computeField(input)
{
    if (input.value != null && input.value.length != 0)
        input.value = "" + eval(input.value);
    computeForm(input.form);
}
function computeForm(form)
{
    if ((form.mortgage.value == null || form.mortgage.value.length == 0) ||
        (form.taxes.value == null || form.taxes.value.length == 0) ||
        (form.insurance.value == null || form.insurance.value.length == 0) ||
        (form.monthly.value == null || form.monthly.value.length == 0) ||
	(form.other.value == null || form.other.value.length == 0)) {
        return;
    }
    if (!checkNumber(form.mortgage, 1, 1000000, "mort payments")) {
        form.income.value = "Invalid";
        return;
    }
 var mortgage = 0
 var taxes = 0
 var insurance = 0
 var monthly = 0
 var other = 0
 mortgage = (eval(form.mortgage.value) * 12)
 taxes = eval(form.taxes.value)
 insurance = eval(form.insurance.value)
 monthly = (eval(form.monthly.value) * 12)
 other = (eval(form.other.value) * 12)
 form.income.value = eval(mortgage + taxes + insurance + monthly + other)
 form.income.value = eval(form.income.value / .36)
 form.income.value = Math.round(eval(form.income.value) * 100)
 form.income.value = (form.income.value * .01)

}
function clearForm(form)
{
    form.mortgage.value = "";
    form.taxes.value = "";
    form.insurance.value = "";
    form.monthly.value = "";
    form.other.value = "";

}