function siteCalc(form) { form.opayout.value = form.payratio.value / (form.avgbonus.value/100 + 1); form.opayout.value = ( ( Math.floor(100 * form.opayout.value) ) / 100 ); form.rdratio.value = (form.opayout.value / 100) * (form.depbonus.value *1 + 100); form.rdratio.value = ( ( Math.floor(100 * form.rdratio.value) ) / 100 ); form.opayout.value = form.opayout.value + "%"; form.rdratio.value = form.rdratio.value + "%"; } function LoanEstimate(form) { var opayout = ( form.price.value - form.down.value ); var rate = form.rate.value; var years = form.years.value; //monthly var payout = calculatePayments( loanamount, rate , years, 12 ); var total = (payout *12 * years); var totalInterest = ReformOutput( (total - loanamount) ); form.monthlypay.value = ReformOutput(payout); form.mtotalpaid.value = ReformOutput(total); form.monthlytotal.value = totalInterest; //weekly payout = calculatePayments( loanamount, rate , years, 52 ); total = (payout * 52 * years); totalInterest = ReformOutput( (total - loanamount) ); form.weeklypay.value = ReformOutput(payout); form.wtotalpaid.value = ReformOutput(total); form.weeklytotal.value = totalInterest; //biweekly payout = calculatePayments( loanamount, rate , years, 26 ); total = (payout * 26 * years); totalInterest = ReformOutput( (total - loanamount) ); form.biweeklypay.value = ReformOutput(payout); form.btotalpaid.value = ReformOutput(total); form.biweeklytotal.value = totalInterest; } function ReformOutput( outputString ) { outputString = ( ( Math.floor((100 * outputString)) ) / 100 ); var oldStr = new String(outputString); var newStr = new String(); var decimalPlaces; var i = 1; var iCounter = 0; if ( -1 != oldStr.indexOf(".") ) { // Check for digits behind the decimal point decimalPlaces = oldStr.length - oldStr.indexOf("."); if ( decimalPlaces == 1 ) { newStr = ".00"; } else if ( decimalPlaces == 2 ) { newStr = oldStr.substring( oldStr.indexOf("."), oldStr.length) + "0"; } else { newStr = oldStr.substring( oldStr.indexOf("."), oldStr.length); } oldStr = oldStr.substring(0, oldStr.indexOf(".")); } else { newStr = ".00" } while ( i <= oldStr.length ) { // Get Character var cLetter = oldStr.charAt(oldStr.length-i); newStr = cLetter + newStr; iCounter++; if ( ( iCounter == 3 ) && (( oldStr.length - i ) > 0 ) ) { iCounter = 0; newStr = " " + newStr; } i++; } return ( newStr ); } // removes spaces and , commas function removeWhite( number ) { // Create String Value var original = new String(number); var reformated = new String(); var i = 0; var n = 0; var charpointer; while ( i <= original.length ) { c = original.charAt(original.length-i); if ( (c != ",") && (c != " ") ) { if ( n ) { reformated = c + reformated; } else { reformated = c; n=1; } } i++; } return ( reformated ); } function verifyFields(form) { form.price.value = removeWhite(form.price.value); form.down.value = removeWhite(form.down.value); if ( form.price.value == "" || form.price.value <= 0 ) { alert("Type in an amount larger than 0 in the price field."); form.price.focus(); return 0; } if ( ValidData(form.price.value) == 0 ) { alert("The calculator does not understand your input in the price field, please only enter numbers (ex. 255 000)"); form.price.focus(); return 0; } if ( form.down.value == "" || form.down.value < 0 ) { alert("Type in an amount larger than 0 in the downpayment field."); form.price.focus(); return 0; } if ( ValidData(form.down.value) == 0 ) { alert("The calculator does not understand your input in the downpayment field, please only enter numbers (ex. 15 000)"); form.price.focus(); return 0; } if ( form.rate.value == "" || form.rate.value < 0 ) { alert("Type in an amount larger than 0 in the interest rate field."); form.rate.focus(); return 0; } if ( ValidData(form.rate.value) == 0 ) { alert("The calculator does not understand your input in the interest rate field, please only enter numbers (ex. 7.5)"); form.rate.focus(); return 0; } if ( form.years.value == "" || form.years.value <= 0) { alert("Type in an amount larger than 0 in the years field."); form.years.focus(); return 0; } if ( ValidData(form.years.value) == 0 ) { alert("Use only numbers (0-9); don't use letters or any special characters (ex. 30)."); f.Years.focus(); return 0; } return 1; }