function checkValues(form) 
{
  // check for proper input ranges and return false if
  // the input is not acceptable.

  if (parseFloat(form.width.value) <= 0.00)
  {
    window.alert("Width must be greater than zero.");
    return false;
  }

  // return true if it is all OK.
  return true;
}

function decimal(num,places)
{
  var mult = Math.pow(10,places);
  return Math.round(num * mult) / mult;
}

function calculate() 
{
  // make sure input is correct
  theForm = document.calculation;
  if (checkValues(theForm))
  {
    // calc welt melt size
    consta = 0.00;
    if (document.calculation.units[0].checked)
    {
      consta = 4.85;
    }
    else
    {
      consta = 0.191;
    }

    if (!theForm.addmelt.checked)
	{
	  consta = 0;
	}


    // get the input from the form
    var W_W = parseFloat(theForm.width.value);
    var SashSet = parseFloat(theForm.sashset.value);
	var quantity = parseFloat(document.customerinfo.quan.value);
	if (isNaN(quantity))
	{
	  quantity = 1;
	  document.customerinfo.quan.value = 1;
	} 

    with (Math) 
    {
      // do all the calculations here.
      var radius = ((W_W / 2) * 2 * 0.414) + consta;
      var SashSize = (((W_W / 2) - SashSet) * 2 * 0.414) + consta;

      // put the results into the form fields for viewing
      theForm.length.value = decimal(radius,3);
      theForm.angle.value = 67.5;
      theForm.number.value = quantity * 8;
      theForm.sashSize.value = decimal(SashSize,3);

    }
    // ends with math
  }

  // return false so that the button does not do it's default action.
  return false;
}

