function clear_field(field) {
		if (field.value==field.defaultValue) {
			field.value=''
		}
	}

function calc_num_fasteners(form) {

if (isNaN(form.width.value)) {
	alert("Enter a number (feet) in the deck width field.")
}
if (isNaN(form.length.value)) {
	alert("Enter a number (feet) in the deck length field.")
}
if (isNaN(form.joist_width_inches.value)) {
	alert("Enter a number (inches) for the center to center joist separation.")
}
if (isNaN(form.deckboard_width_inches.value)) {
	alert("Enter a number (inches) for the nominal width of the deckboard.")
}

var width = form.width.value;
var length = form.length.value;
var actual_deckboard_width = form.deckboard_width_inches.value - 0.5; 
var joist_width = form.joist_width_inches.value;
var num_boards = Math.ceil(width * 12 / actual_deckboard_width);
var num_joists = Math.ceil((length * 12 / joist_width) + 1);
var num_fasteners = num_joists * num_boards; 
form.num_fasteners.value = num_fasteners;
form.num_boards.value = num_boards;
form.num_joists.value = num_joists;
form.num_boxes.value = Math.ceil(num_fasteners/170);
}

function DeckClip_Form1_Validator(theForm)
{

  var checkOK = "0123456789-.,";
  var checkStr = theForm.length.value;
  var allValid = true;
  var validGroups = true;
  var decPoints = 0;
  var allNum = "";
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
    if (ch == ".")
    {
      allNum += ".";
      decPoints++;
    }
    else if (ch == "," && decPoints != 0)
    {
      validGroups = false;
      break;
    }
    else if (ch != ",")
      allNum += ch;
  }
  if (!allValid)
  {
    alert("Invalid. Enter only numeric characters in the \"length\" field.");
    theForm.length.focus();
    return (false);
  }

  if (decPoints > 1 || !validGroups)
  {
    alert("Invalid. Enter a number in the \"length\" field.");
    theForm.length.focus();
    return (false);
  }

  var checkOK = "0123456789-.,";
  var checkStr = theForm.width.value;
  var allValid = true;
  var validGroups = true;
  var decPoints = 0;
  var allNum = "";
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
    if (ch == ".")
    {
      allNum += ".";
      decPoints++;
    }
    else if (ch == "," && decPoints != 0)
    {
      validGroups = false;
      break;
    }
    else if (ch != ",")
      allNum += ch;
  }
  if (!allValid)
  {
    alert("Invalid. Enter only numeric characters in the \"width\" field.");
    theForm.width.focus();
    return (false);
  }

  if (decPoints > 1 || !validGroups)
  {
    alert("Invalid. Enter a number in the \"width\" field.");
    theForm.width.focus();
    return (false);
  }

  var checkOK = "0123456789-.,";
  var checkStr = theForm.joist_width_inches.value;
  var allValid = true;
  var validGroups = true;
  var decPoints = 0;
  var allNum = "";
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
    if (ch == ".")
    {
      allNum += ".";
      decPoints++;
    }
    else if (ch == "," && decPoints != 0)
    {
      validGroups = false;
      break;
    }
    else if (ch != ",")
      allNum += ch;
  }
  if (!allValid)
  {
    alert("Invalid. Enter only numeric characters in the \"joist_width_inches\" field.");
    theForm.joist_width_inches.focus();
    return (false);
  }

  if (decPoints > 1 || !validGroups)
  {
    alert("Please enter a valid number in the \"joist_width_inches\" field.");
    theForm.joist_width_inches.focus();
    return (false);
  }

  var checkOK = "0123456789-.,";
  var checkStr = theForm.deckboard_width_inches.value;
  var allValid = true;
  var validGroups = true;
  var decPoints = 0;
  var allNum = "";
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
    if (ch == ".")
    {
      allNum += ".";
      decPoints++;
    }
    else if (ch == "," && decPoints != 0)
    {
      validGroups = false;
      break;
    }
    else if (ch != ",")
      allNum += ch;
  }
  if (!allValid)
  {
    alert("Invalid. Enter only numeric characters in the \"deckboard_width_inches\" field.");
    theForm.deckboard_width_inches.focus();
    return (false);
  }

  if (decPoints > 1 || !validGroups)
  {
    alert("Please enter a valid number in the \"deckboard_width_inches\" field.");
    theForm.deckboard_width_inches.focus();
    return (false);
  }
  return (true);
}
