function floor(number)
{
  return Math.floor(number*Math.pow(10,2))/Math.pow(10,2);
}

function dosum()
{
  var mi = $("#calcpg input[name='IR']:first").val() / 1200;
  var base = 1;
  var mbase = 1 + mi;
  for (i=0; i<$("#calcpg input[name='YR']:first").val() * 12; i++)
  {
    base = base * mbase
  }
  $("#calcpg input[name='PI']:first").val(floor($("#calcpg input[name='LA']:first").val() * mi / ( 1 - (1/base))));
  $("#calcpg input[name='MT']:first").val(floor($("#calcpg input[name='AT']:first").val() / 12));
  $("#calcpg input[name='MI']:first").val(floor($("#calcpg input[name='AT']:first").val() / 12));
  var dasum = $("#calcpg input[name='LA']:first").val() * mi / ( 1 - (1/base)) +
        $("#calcpg input[name='AT']:first").val() / 12 + 
        $("#calcpg input[name='AI']:first").val() / 12;
  $("#calcpg input[name='MP']:first").val(floor(dasum));
}


$(document).ready(function(){
  //give forms a secondary border
  $("input, textarea").wrap("<div class='formfieldwrapper'></div>");
  $("input, textarea").focus(function(){
    $(this).css('color','#000000');
    $(this).css('backgroundColor','#ffffff');
    $(this).css('backgroundPosition','0px -50px');
  });
  $("input, textarea").blur(function(){
    $(this).css('color','#4d4d4d');
    $(this).css('backgroundColor','#d5e7fb');
    $(this).css('backgroundPosition','0px 0px');
  });
  
  //links with rel=external now open in a new window
  $("a[@rel='external']").attr("target","_blank");
});
