// http://alphaadv.net/njtitle/njratecalc09.js
<!-- New Jersey Title Insurance Rate Calculator -->
<!-- Thank you for finding this page interesting enough to view the source code. -->
<!-- Please respect my copyrights.  Thankx -->
<!-- Page written November 8, 1998, Last update February 20, 2009 -->

<!-- Changing the lines above or below is an invitation to Adventures in Legal Land -->

<!-- Activate Cloaking Device -->

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 calcNJrates(form)
{
     form.stdsearch.value = 100.00
     form.stdsearch.value=roundit(form.stdsearch.value)
     form.refinancesearch.value = 100.00
     form.refinancesearch.value=roundit(form.refinancesearch.value)
     form.constructionsearch.value = 100.00
     form.constructionsearch.value=roundit(form.constructionsearch.value)

// tiamt = greater of saleprice or mortgageamount
     var tiamt = 0
     var sale = form.saleprice.value / 1
     var mtg = form.mtgamount.value / 1
     var previousmtg = form.previousmtgamount.value / 1
     if (sale >= mtg) {
     tiamt = form.saleprice.value
     }
     else {
     tiamt = form.mtgamount.value
     }

// caclulate standard
     form.standard.value=standard(tiamt)


// calculate refinance
// - A - full refinance, if the old mortgage amount is greater than the mortgage amount, else
// - B - refinance & standard, if the previous mortgage amount is less than the mortgage amount
     if (previousmtg >= mtg) {
     // A - full refinance
          form.refinance.value = refi(mtg)
     }

     // B - refinance up to the old mtg, then standard to new mtg
     else if (previousmtg < mtg) {
          // 1  refinance(previousmtg)
               var reficalc=0
               reficalc = refi(previousmtg)
							 form.refinance.value = reficalc
               form.refinance.value = roundit(form.refinance.value);
							 reficalc = form.refinance.value
               // alert (reficalc)

          // 2 - standard(previousmtgamount)
               reficalc = reficalc - standard(previousmtg)
							 // alert (reficalc)
							 
          // 3 + standard(mtg)
               form.refinance.value = reficalc + standard(mtg)
							 // alert (reficalc)
     }

		 
// calculate construction
     form.construction.value=construction(tiamt)


// test minimums for all 3 rates
// standard
     if (form.standard.value > 200) {
          form.standard.value=roundit(form.standard.value);
          }
     else {
          form.standard.value = "200.00"
          form.standard.value=roundit(form.standard.value)
     }
// refinance
     if (form.refinance.value > 200) {
     form.refinance.value=roundit(form.refinance.value);
          }
     else {
          form.refinance.value = "200.00"
          form.refinance.value=roundit(form.refinance.value)
     }
// construction
     if (form.construction.value > 200) {
     form.construction.value=roundit(form.construction.value);
          }
     else {
          form.construction.value = "200.00"
          form.construction.value=roundit(form.construction.value)
     }

// end of overall calculation

     // form.standard.value=roundit(form.standard.value);
     // form.construction.value=roundit(form.construction.value);
     // form.refinance.value=roundit(form.refinance.value);

     return;
}

function standard(amt)
{
     // if amount <= 100,000 - standard = 5.00/1000
     if (amt <= 100000) {
          amt1=thousands(amt, 0);
          standardrate = (amt1 * 5.00);
     }

     // if amount <= 500,000 - standard = 500 + 3.95 /1000 over 100,000
     else if (amt <= 500000) {
          amt1=thousands(amt, 100000);
          standardrate = (500 + (amt1 * 3.95));
     }

     // if amount <= 2,000,000 - standard = 2,080 + 2.65 /1000 over 500,000
     else if (amt <= 2000000) {
          amt1=thousands(amt, 500000);
          standardrate = (2080 + (amt1 * 2.65));
     }

     // if amount > 2,000,000 - standard = 6,055 + 2.00 /1000 over 2,000,000
     else if (amt > 2000000) {
          amt1=thousands(amt, 2000000);
          standardrate = (6055 + (amt1 * 2.00));
     }

     // round - I need to remember rounding info
     return(standardrate);
}

function refi(amt)
{
     // if amount <= 100,000 - reissue = 2.50/1000
     if (amt <= 100000) {
          amt1=thousands(amt, 0);
          refirate = (amt1 * 2.50);
     }

     // if amount <= 500,000 - reissue = 250 + 2.25 /1000 over 100,000
     else if (amt <= 500000) {
          amt1=thousands(amt, 100000);
          refirate = (250 + (amt1 * 2.25));
     }

     // if amount <= 2,000,000 - reissue = 1,150 + 2.00 /1000 over 500,000
     else if (amt <= 2000000) {
          amt1=thousands(amt, 500000);
          refirate = (1150 + (amt1 * 2.00));
     }

     // if amount > 2,000,000 - reissue = 4,150 + 1.50 /1000 over 2,000,000
     else if (amt > 2000000) {
          amt1=thousands(amt, 2000000);
          refirate = (4150 + (amt1 * 1.50));
     }

     // round - I need to remember rounding info
     return(refirate);
}

function construction(amt)
{
     // if amount <= 100,000 - standard = 1.00/1000
     if (amt <= 100000) {
          amt1=thousands(amt, 0);
          standardrate = (0 + (amt1 * 1.00));
     }

     // if amount <= 500,000 - standard = 195 + 1.00 /1000 over 100,000
     else if (amt <= 500000) {
          amt1=thousands(amt, 100000);
          standardrate = (100 + (amt1 * 1.00));
     }

     // if amount <= 2,000,000 - standard = 595 + 1.00 /1000 over 500,000
     else if (amt <= 2000000) {
          amt1=thousands(amt, 500000);
          standardrate = (500 + (amt1 * 1.00));
     }

     // if amount > 2,000,000 - standard = 2, 095 + 1.00 /1000 over 2,000,000
     else if (amt > 2000000) {
          amt1=thousands(amt, 2000000);
          standardrate = (2000 + (amt1 * 1.00));
     }

     // round - I need to remember rounding info
     return(standardrate);
}

function thousands(amt, base) {    
     var amt1 = ((amt - base) / 1000)
     var amt2 = parseInt(((amt - base) / 1000))
     if (amt1 > amt2) {
     amt1 = amt2 + 1
     }
     return (amt1);
}

function roundit(what){  
     var places = 2
     var iplaces = 6
     var pad = ' '
     var xx = what.indexOf('.')    
     var l = what.length 
     var zstr = '0000000000000000000000'     
     var theInt = ''     
     var theFrac = ''
     var theNo = '' 
     rfac = '' 
     rfacx = 0 
     whatx = 0 
     var xt = parseInt(places) + 1 
     var rstr = '' + zstr.substring(1,xt)    
     var rfac = '.' + rstr + '5'   
     var rfacx = parseFloat(rfac)  
     if (xx == -1 ) {         
          // even dollar amount - no decimals          
          theFrac = zstr      
          theInt = what  
     }
     else if (xx == 0) {      
          theInt = '0'        
          whatx = 0 + parseFloat(what) + parseFloat(rfacx)       
          what = whatx + zstr      
          theFrac = '' + what.substring(1, what.length)               
     }    
     else {         
          theInt = what.substring(0,xx)      
          whatx = parseFloat(what) + rfacx        
          what = '' + whatx + zstr      
          theFrac = '' + what.substring(xx+1,xx + 1 + parseInt(places))    
          var astr = 'places = ' + places    
     } 

     // theInt is the integer, theFrac is the decimals
     first = theFrac.substring(0,1)
     round = theFrac.substring(2,1)
     if (theFrac < 50){
     theFrac = '00'
     }
     else {
     theFrac = '00'
     theInt  = parseInt(theInt) + 1
     theInt = '' + theInt
     }

     //alert('theInt= ' + theInt + '\ntheFrac= ' + theFrac + '\nwhat= ' + what + '\nwhatx= ' + whatx) 
     theFrac = theFrac.substring(0,parseInt(places)) 
     var dif = iplaces - theInt.length 
     var ii = 0 
     var padstr = '' 
     for (ii = 0 ; ii < dif ; ii++) {                  
          padstr += pad  
     }    
     theNo = padstr + theInt + '.' + theFrac 
     return theNo;
}

function clearForm(form)
{
     form.saleprice.value = "";
     form.mtgamount.value = "";
     form.previousmtgamount.value = "";

     form.standard.value = "";
     form.refinance.value = "";
     form.construction.value = "";

     form.standardsearch.value = "";
     form.refinancesearch.value = "";
     form.constructionsearch.value = "";
}

<!-- Deactivate Cloaking Device -->
