
var lengthBox, quantityBox, priceBox;

function getBoxes(id) {
   lengthBox = document.getElementById("length" + id); 
   quantityBox = document.getElementById("squant" + id); 
   priceBox = document.getElementById("price" + id); 
}

function calculatePrice2(id, pricePerMetre) {
   getBoxes(id);
   var metrePrice = parseFloat(pricePerMetre);
   var newQuantity = (lengthBox.value/1000) * quantityBox.value;
   var newPrice = (Math.round(newQuantity * pricePerMetre * 100) / 100).toString();
   if (newPrice.length == 1) newPrice += ".00";
   else if (newPrice.length == 3 && newPrice.indexOf(".") != -1) newPrice += "0";
   priceBox.innerHTML = newPrice;
}

function sortQuantity2(id, minLength, maxLength) {
   getBoxes(id);
   if (lengthBox.value > maxLength) {
      window.alert("You have exceeded the maximum possible length for this product.\nThe value must be between " + minLength + "mm and " + maxLength + "mm.");
      return false;
   }
   if (lengthBox.value < minLength) {
      window.alert("The specified length is less than the minimum possible length for this product.\nThe value must be between " + minLength + "mm and " + maxLength + "mm.");
      return false;
   }
   
   var newquant = priceBox.innerHTML * 100;
   document.getElementById("aquant" + id).value = newquant;
   document.getElementById("oprompt" + id).value = quantityBox.value + " X " + lengthBox.value + "mm.";
   return true;
}  