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(){

  //make external links open in a new window
  $("a").each(function(){
    href = $(this).attr('href');
    base = basedir.split('http://').join('').split('https://').join('');
    if( !href.match(base) && !href.match("javascript:") ){
      $(this).click(function(){
        window.open($(this).attr('href'));
        return false;
      });
    }
  });
  
  //min height of the content block
  if( $("#content").height() < 423 ){
    $("#content").height(423);
  }
  
  //button events
  $("button")
    .mouseover(function(){ $(this).addClass("hover"); })
    .mouseout(function(){ $(this).removeClass("hover"); });
  
});
