function getDecimalFromEl(id) {
  var el = document.getElementById(id);
  if (el == null) return 0;
  //return parseFloat(el.value);
  return el.value; //We deal with it from the other end
}

function getXMLHttp()
{
  var xmlHttp

  try
  {
    //Firefox, Opera 8.0+, Safari
    xmlHttp = new XMLHttpRequest();
  }
  catch(e)
  {
    //Internet Explorer
    try
    {
      xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(e)
    {
      try
      {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch(e)
      {
        alert("Your browser does not support AJAX!")
        return false;
      }
    }
  }
  return xmlHttp;
}

function handleCalculatorResponse(response)
{
  //Find our element
  var results = document.getElementById('divResults');

  //Populate the results
  if (results != null)
    results.innerHTML = response;
}

function runCalculation() {
  //Get the variables
  var length = getDecimalFromEl('txtLength');
  var no = getDecimalFromEl('txtCount');
  var size = getDecimalFromEl('txtSize');

  //Now post an AJAX request, and use the results to populate our element
  var xmlHttp = getXMLHttp();

  //Handle the response
  xmlHttp.onreadystatechange = function()
  {
    if(xmlHttp.readyState == 4)
      handleCalculatorResponse(xmlHttp.responseText);
  }

  //Send the request
  xmlHttp.open("GET", "/themes/pacificsteeltheme/calc/psg_calculator.php?length="+length+"&no="+no+"&size="+size, true);
  xmlHttp.send(null);
}
