function down_payment(which){    var mortgage = document.CalculatorForm;    var percentvalue, down, loanamm;    /* preprocess salesprice */    loanamm = mortgage.salesprice.value;    while ((pos=loanamm.indexOf(",")) >= 0)    {    sub_1 = loanamm.substring(0, pos);    sub_2 = loanamm.substring(pos+1, loanamm.length);    loanamm = sub_1 + sub_2;    }    /* preprocess downamount */    down = mortgage.downamount.value;    while ((pos=down.indexOf(",")) >= 0)    {    sub_1 = down.substring(0, pos);    sub_2 = down.substring(pos+1, down.length);    down = sub_1 + sub_2;    }    if (which == "downamount")    {    percentvalue = Math.floor((parseFloat(down)/parseFloat(loanamm)*100.0)*100) / 100;    mortgage.percent.value = percentvalue;    }    if (which == "percent")    {    down = parseInt(parseFloat(loanamm) * parseFloat(mortgage.percent.value) / 100.0);    mortgage.downamount.value = down;    }    /* put comma in dollar values */    mortgage.salesprice.value = calc_commas(mortgage.salesprice.value);    mortgage.downamount.value = calc_commas(mortgage.downamount.value);}function compu_calc(){    var mortgage = document.CalculatorForm;    var annualRate, monthRate, months, principle, payment, tax, checkprc;    var loanamm, down, ctax, cloan, pos, sub_1, sub_2;            /* validate certain values */        if (parseInt(mortgage.salesprice.value) <= 0)    {    if (parseInt(mortgage.salesprice.defaultValue) > 0)    {        mortgage.salesprice.value = mortgage.salesprice.defaultValue;    }    else    {        mortgage.salesprice.value = "219000";    }    }    if (parseInt(mortgage.downamount.value) < 0)    {    if (parseInt(mortgage.downamount.defaultValue) >= 0)    {        mortgage.downamount.value = mortgage.downamount.defaultValue;        mortgage.percent.value = mortgage.percent.defaultValue;    }    else    {        mortgage.downamount.value = parseInt(parseFloat(mortgage.salesprice.value) * 20.0 / 100.0);        mortgage.percent.value = "10.0";    }    }    if (parseInt(mortgage.percent.value) < 0)    {    if (parseInt(mortgage.percent.defaultValue) >= 0)    {        mortgage.downamount.value = mortgage.downamount.defaultValue;        mortgage.percent.value = mortgage.percent.defaultValue;    }    else    {        mortgage.downamount.value = parseInt(parseFloat(mortgage.salesprice.value) * 20.0 / 100.0);        mortgage.percent.value = "20.0";    }    }    checkprc = parseFloat(mortgage.percent.value)           if (parseFloat(mortgage.anintrate.value) < 0.0)    {    if (parseFloat(mortgage.anintrate.defaultValue) > 0.0)    {        mortgage.anintrate.value = mortgage.anintrate.defaultValue;    }    else    {        mortgage.anintrate.value = "7.0";    }    }    if (parseInt(mortgage.numberofyears.value) <= 0)    {    if (parseInt(mortgage.numberofyears.defaultValue) > 0)    {        mortgage.numberofyears.value = mortgage.numberofyears.defaultValue;    }    else    {        mortgage.numberofyears.value = "30";    }    }    /* preprocess salesprice */    loanamm = mortgage.salesprice.value;    while ((pos=loanamm.indexOf(",")) >= 0)    {    sub_1 = loanamm.substring(0, pos);    sub_2 = loanamm.substring(pos+1, loanamm.length);    loanamm = sub_1 + sub_2;    }    /* preprocess downamount */    down = mortgage.downamount.value;    while ((pos=down.indexOf(",")) >= 0)    {    sub_1 = down.substring(0, pos);    sub_2 = down.substring(pos+1, down.length);    down = sub_1 + sub_2;    }    /* the real computation */    annualRate = parseFloat(mortgage.anintrate.value) / 100;    monthRate = annualRate / 12.0;    months = parseInt(mortgage.numberofyears.value) * 12;    principle = parseInt(loanamm) - parseInt(down);    payment = Math.floor(((principle*monthRate)/(1-Math.pow((1+monthRate),(-1*months)))*100)/100)+(0);	 tax = Math.round((loanamm*0.0125) / 12);        if (checkprc < 20)    	 {            insurance = Math.round((principle*0.0035) / 12);    }    else    {      insurance = "None"    }    asking = (219000);	    /* put value up */    mortgage.loanamm.value = principle;    mortgage.monthly.value = payment;        mortgage.loaninsurance.value = insurance;    mortgage.propertytax.value = tax;        /* put comma in dollar values */    mortgage.salesprice.value = calc_commas(mortgage.salesprice.value);    mortgage.downamount.value = calc_commas(mortgage.downamount.value);    mortgage.loanamm.value = calc_commas(mortgage.loanamm.value);    mortgage.monthly.value = calc_commas(mortgage.monthly.value);    mortgage.propertytax.value = calc_commas(mortgage.propertytax.value);     if (checkprc <20) {        mortgage.loaninsurance.value = calc_commas(mortgage.loaninsurance.value); }}function calc_commas(target){    var newtarget, decimal, pos, sub_1, sub_2, i;    newtarget = "";    /* get rid of existing commas */    while ((pos=target.indexOf(",")) >= 0)    {    sub_1 = target.substring(0, pos);    sub_2 = target.substring(pos+1, target.length);    target = sub_1 + sub_2;    }    /* extract decimals for safe keeping */    decimal = "";    if ((pos=target.indexOf(".")) >= 0)    {    decimal = target.substring(pos, target.length);    target = target.substring(0, pos);    }    /* here comes the real work */    for (i = target.length-1; i >= 0; i--)    {    if (((target.length-i-1) % 3) == 0)    {        if ((target.length-i-1) > 0)        {        newtarget = "," + newtarget;        }    }    newtarget = target.substring(i,i+1) + newtarget;    }    /* add on any decimals */    newtarget = newtarget + decimal;    return newtarget;}