function Dummy(){return}

function adjust_form () {

    if (document.forms[0].total_field != null)
    {
	    var total_field = parseInt (document.forms[0].total_field.value);
	    max_width = 0;
	    max_field_width  = 0;
	    max_height = 0;

	    for (i=1; i<=total_field; i++) {
		    field = document.getElementById ("span"+i);
		    if (field.offsetWidth > max_field_width)
			    max_field_width = field.offsetWidth;
	    }
	}
/*	

	if (max_field_width > 0) {
	for (i=1; i<=total_field; i++) {
		label = document.getElementById ("label"+i);

		field = document.getElementById ("span"+i);
		field.style.width = max_field_width;

		if (label.offsetHeight < field.offsetHeight)
			label.style.height = field.offsetHeight;
		else
			field.style.height = label.offsetHeight;
	}
	}
*/
}

function adjust_menu ()
{
	Dummy();

	var max_height = 0;

	for (i=0; i<total_menu; i++) {
		top_menu = document.getElementById ("menu"+i);
		top_menu_link = document.getElementById ("menu_link"+i);

		top_menu.style.width = top_menu_link.offsetWidth;

		if (top_menu_link.offsetHeight > max_height)
			max_height = top_menu_link.offsetHeight;
	}

	for (i=0; i<total_menu; i++) {
		top_menu_link = document.getElementById ("menu_link"+i);
		top_menu_link.style.height = max_height;
	}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

// External code 
// http://alphaadv.net/patitle/ratecalc.js
// Pennsylvania Title Insurance Rate Calculator -->
// Thank you for finding this page interesting enough to view the source code. -->
// Please respect my copyrights.  Thankx -->
// Page written October 17, 1997, Last update May 1, 2006 -->

// Changing the lines below is an invitation to Adventures in Legal Land -->

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.amount.value == null || form.amount.value.length == 0) 
{
        return;
}

    if (!checkNumber(form.amount, 0, 30000000, "amount of insurance") )
     {
     form.basic.value= "Talk";
     form.reissue.value= "to";
     form.construction.value= "your";
     form.refinance02.value= "title";
     form.refinance24.value= "company";
     return;
     }

     // calculation goes here - new rates effective January 1, 2002
     var amt = form.amount.value;

     // if amount <= 30,000 - basic = 420
     if (amt <= 30000)
     {
     form.basic.value = "420.00";
     }

     // if amount <= 45,000 - basic = 420 + 7.25 /1000 over 30,000
     else if (amt <= 45000)
     {
     amt1=thousands(amt, 30000);
     form.basic.value = (420 + (amt1* 7.25));
     }

     // if amount <= 100,000 - basic = 528.75 + 6.00 /1000 over 45,000
     else if (amt <= 100000)
     {
     amt1=thousands(amt, 45000);
     form.basic.value = (528.75 + (amt1* 6.00));
     }

     // if amount <= 500,000 - basic = 858.75 + 5.00 /1000 over 100,000
     else if (amt <= 500000)
     {
     amt1=thousands(amt, 100000);
     form.basic.value = (858.75 + (amt1* 5.00));
     }

     // if amount <= 1,000,000 - basic = 2,858.75 + 3.75 /1000 over 500,000
     else if (amt <= 1000000)
     {
     amt1=thousands(amt, 500000);
     form.basic.value = (2858.75 + (amt1* 3.75));
     }

     // if amount <= 2,000,000 - basic = 4,733.75 + 2.75 /1000 over 1,000,000
     else if (amt <= 2000000)
     {
     amt1=thousands(amt, 1000000);
     form.basic.value = (4733.75 + (amt1* 2.75));
     }

     // over 2 million is a special area with everything at $2 per thousand
     // if amount <= 7,000,000 - basic = 7,483.75 + 2.00 /1000 over 2,000,000
     // if amount <= 7,000,000 - reissue = 6,735.375 + 2.00 /1000 over 2,000,000
     else if (amt <= 7000000)
     {
     amt1=thousands(amt, 2000000);
     form.basic.value = (7483.75 + (amt1* 2.00));

     // now calculate reissue, construction and refinance - special for this range
     form.reissue.value = (6735.375 + (amt1* 2.00) );
     form.construction.value = (form.reissue.value * .9);
     form.refinance02.value = (form.reissue.value * .7);
     form.refinance24.value = (form.reissue.value * .8);

     // round
     form.basic.value=roundit(form.basic.value);
     form.reissue.value=roundit(form.reissue.value);
     form.construction.value=roundit(form.construction.value);
     form.refinance02.value=roundit(form.refinance02.value);
		 form.refinance24.value=roundit(form.refinance24.value);
     return;                                 // end of 2 - 7 million section
     }

     // over 7 million is a special area with everything at $1.50 per thousand?
     // if amount <= 30,000,000 - basic = 17,483.75 + 2.00 /1000 over 2,000,000
     // if amount <= 30,000,000 - reissue = 16,735.375 + 2.00 /1000 over 2,000,000
     else if (amt <= 30000000)
     {
     amt1=thousands(amt, 7000000);
     form.basic.value = (17483.75 + (amt1* 1.50));

     // now calculate reissue, construction and refinance - special for this range
     form.reissue.value = (16735.375 + (amt1* 1.50) );
     form.construction.value = (form.reissue.value * .9);
		 form.refinance02.value = (form.reissue.value * .7);
     form.refinance24.value = (form.reissue.value * .8);

     // round
     form.basic.value=roundit(form.basic.value);
     form.reissue.value=roundit(form.reissue.value);
     form.construction.value=roundit(form.construction.value);
     form.refinance02.value=roundit(form.refinance02.value);
		 form.refinance24.value=roundit(form.refinance24.value);
     return;                                 // end of 7 - 30 million section
     }

     // now calculate reissue, construction and refinance
     form.reissue.value = (form.basic.value * .9);
     form.construction.value = (form.reissue.value * .9);
     form.refinance02.value = (form.reissue.value * .7);
     form.refinance24.value = (form.reissue.value * .8);

     // round
     form.basic.value=roundit(form.basic.value);
     form.reissue.value=roundit(form.reissue.value);
     form.construction.value=roundit(form.construction.value);
     form.refinance02.value=roundit(form.refinance02.value);
		 form.refinance24.value=roundit(form.refinance24.value);

     return;
}

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 usca17etseq = "True";
     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
     // round up to 0, 3, 5 or 8
     first = theFrac.substring(0,1)
     round = theFrac.substring(2,1)
     //special cases for 09 and 99 due to string consideration
     if (theFrac == 09){                          // 09 special
     theFrac = '10'
     }
     else if (theFrac == 99){                          // 99 special
     theFrac = '00'
     theInt  = parseInt(theInt) + 1
     theInt = '' + theInt
     }
     else if (round == 2 || round == 4 || round == 7 || round == 9 ) {          // add 1 cent  
          //alert('the first = ' + first + '\nround = ' + round)
          if (first == 0){
               theFrac = parseInt(theFrac) + 1
               theFrac = '0' + parseInt(theFrac)
               }
               else {
               //alert('round 1 cent w/o a 0')
               theFrac = parseInt(theFrac) + 1         
               }
          theFrac = '' + theFrac
          //alert('add 1 cent\nthe first = ' + first + '\nround = ' + round + '\ntheFrac = ' + theFrac)
     }
     else if (round == 1 || round == 6) {                        // add 2 cents
          if (first == 0){
               theFrac = parseInt(theFrac) + 2
               theFrac = '0' + parseInt(theFrac)
               }
               else {
               theFrac = parseInt(theFrac) + 2         
               }
          theFrac = '' + theFrac
          //alert('add 2 cents\nthe first = ' + first + '\nround = ' + round + '\ntheFrac = ' + theFrac)
     }    
     else {                                       // no rounding required
     } 
     //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.amount.value = "";
    form.basic.value = "";
    form.reissue.value = "";
    form.construction.value = "";
    form.refinance02.value = "";
    form.refinance24.value = "";
}

