// JavaScript Document

function floor(number)
{
  return Math.floor(number*Math.pow(10,2))/Math.pow(10,2);
}

function dosum()
{
  var mi = document.temps.IR.value / 1200;
  var base = 1;
  var mbase = 1 + mi;
  for (i=0; i<document.temps.YR.value * 12; i++)
  {
    base = base * mbase
  }
  document.temps.PI.value = floor(document.temps.LA.value * mi / ( 1 - (1/base)))
  document.temps.MT.value = floor(document.temps.AT.value / 12)
  document.temps.MI.value = floor(document.temps.AI.value / 12)
  var dasum = document.temps.LA.value * mi / ( 1 - (1/base)) +
        document.temps.AT.value / 12 + 
        document.temps.AI.value / 12;
  document.temps.MP.value = floor(dasum);
}

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);
}

// calculates title insurance
function computeForm(form)
{
    if (!checkNumber(form.amount, 0, 250000000, "amount of insurance") )
     {
     form.basic.value= "Error";
     return;
     }

     // calculation goes here - new rates effective May 1, 1998
     var amt = form.amount.value;

{ 
  var the_add = 0 

/*   
   if(form.status[0].checked) 
   { 
   //improved land
      //var the_add = 320
	  var the_add = 0
   } 
   else if(form.status[1].checked) 
   { 
   	// vacant lot
      var the_add = 0
	 // var the_add = 245
   }
   else if(form.status[2].checked) 
   { 
   // refinance
      var the_add = 0
	//  var the_add = 320 
   }
*/
}

     // if amount <= 17,391 - basic = 100
     if (amt <= 17391)
     {
     form.basic.value = (the_add + 100.00);
     }

     // if amount <= 100,000 - basic = 100 + 5.75 /1000 over 17,391
     else if (amt <= 100000)
     {
     amt1=thousands(amt, 0);
     form.basic.value = (the_add + (amt1* 5.75));
     }

     // if amount <= 1,000,000 - basic = 575.00 + 5.00 /1000 over 100,000
     else if (amt <= 1000000)
     {
     amt1=thousands(amt, 100000);
     form.basic.value = (the_add + 575.00 + (amt1* 5.00));
     }

     // if amount <= 5,000,000 - basic = 5,075.00 + 2.50 /1000 over 1,000,000
     else if (amt <= 5000000)
     {
     amt1=thousands(amt, 1000000);
     form.basic.value = (the_add + 5075.00 + (amt1* 2.50));
     }

     // if amount <= 10,000,000 - basic = 15,075 + 2.25 /1000 over 5,000,000
     else if (amt <= 10000000)
     {
     amt1=thousands(amt, 5000000);
     form.basic.value = (the_add + 15075 + (amt1* 2.25));
     }

     // over 10 million is a special area with everything at $2 per thousand
     // if amount <= 10,000,000 - basic = 7,453.75 + 2.00 /1000 over 2,000,000
     // if amount <= 10,000,000 - reissue = 6,708.375 + 2.00 /1000 over 2,000,000
     else if (amt <= 200000000)
     {
     amt1=thousands(amt, 10000000);
     form.basic.value = (the_add + 26325 + (amt1* 2.00));
     }

}

function thousands(amt, base) {    
     var amt1 = ((amt - base) / 1000)
     var amt2 = parseInt(((amt - base) / 1000))
     if (amt1 > amt2) {
     amt1 = amt2 + 1
     }
     return (amt1);
}


function clearForm(form)
{
    form.amount.value = "";
    form.basic.value = "";

}
