function calculate_net_free_area()
{ 
  this_length = safe_number(document.net_free_area_calculator.length.value)
  this_width  = safe_number(document.net_free_area_calculator.width.value)
  this_nfa    = safe_number(document.net_free_area_calculator.nfa.value)
  if (this_length * this_width * this_nfa > 0)
  { document.net_free_area_calculator.total.value = nice_number(((((this_length * this_width) / 300) * 144) / 2) / this_nfa); }
  else
  { document.net_free_area_calculator.total.value = ""; }
}

function safe_number(val) 
{
  var num = parseFloat(val); 

  if (isNaN(num)) { num = 0; }
  num = Math.round(num*100)/100

  return num;
}

function nice_number(val) 
{
  var num = safe_number(val); 
  num = "" + num;

  var dot = num.indexOf(".");

  if (dot < 1) { num = num + ".00"; }
  else if (dot == (num.length-2)) { num = num + "0"; }
  else if (dot < (num.length-3)) { num = num.substring(0,dot+3); }

  return num;
}

var o = '<form name="net_free_area_calculator" style="font-size:10px; font-family:Verdana, Arial, Helvetica, sans-serif; text-align:left; line-height:14px; color:000000; border:0px;">' +
        '<strong><font color="#FF0000" size="2">Step 1:</font></strong><br>Determine the length and width of the space you desire to ventilate.<br>Be sure to factor the amount of soffit overhang into your calculation.<br><br>Length (ft): ' +
        '<input type="text" name="length" onkeyup="calculate_net_free_area()" size="9">' +
        '&nbsp;&nbsp;&nbsp;' +
        'Width (ft): ' +
        '<input type="text" name="width" onkeyup="calculate_net_free_area()" size="9">' +
        '<br><br><br><strong><font color="#FF0000" size="2">Step 2:</font></strong><br>Choose a roof ventilation product. Determine the products square inches<br>of net free area and enter it in the below box.<br><br>' +
        'Net Free Area of Each Roof Vent: ' +
        '<input type="text" name="nfa" onkeyup="calculate_net_free_area()" size="9">' +
        '<br><br><br><strong><font color="#FF0000" size="2">Step 3:</font></strong><br>Based on your calculations, and product choice, you require the below<br>number of ventilation units for your project:<br><br><input type="button" value="Calculate" onclick="calculate_net_free_area()">&nbsp;' +
        'Number of Chosen Roof Vents Required = ' +
        '<input type="text" name="total" class="ghost" size="6">' +
        '</form>';

document.write(o);