// JavaScript Document

<!-- Begin
var max_units = 3000; // quantities in excess of max_units all have the same unit price
var currency = "$"; // currency sign used in 'formatMessage()'
// Edit this function to reflect your discount prices! 

function getPrice(units) {
// Note: It is important to work your way down from max to min amounts!
alert
if (units > max_units) return 3.58 * units;
if (units >= 2501) return 3.63 * units;
if (units >= 2001) return 3.83 * units;
if (units >= 1501) return 3.88 * units;
if (units >= 1001) return 4.08 * units;
if (units >= 751) return 4.23 * units;
if (units >= 501) return 4.43 * units;
else  return 2200;
}

function getCPrice(units) {
// Note: It is important to work your way down from max to min amounts!
alert
if (units >= 1501) return 6.65 * units;
if (units >= 1001) return 7.30 * units;
if (units >= 751) return 7.90 * units;
if (units >= 501) return 8.75 * units;
if (units >= 175) return 9.40 * units;
else  return 1650;
}

function getNumberOfUnits() {
var units = document.calculator.units.value; 
return (units == "") ? 0 : units;
}

function showResult(result) {
// adjust the following line if result must popup somewhere else
document.calculator.respons.value = result;	

}

function formatMessage(price) {
return currency + formatPrice(price); //units + " * " + currency + formatPrice(unit_price) + " = " + currency + formatPrice(units * unit_price);
}
// AltUnits (alternate units): add extra units to reach minimum for next discount price
//function getAltUnits(units) {
//var discount_price = getDiscountPrice(units);
//if (units < max_units) do { units++ } while (discount_price == getDiscountPrice(units));
//return units;
//}

function findPrice() {
var units = getNumberOfUnits();
var price = getPrice(units);
//var alt_units = getAltUnits(units);
//var alt_unit_price = getDiscountPrice(alt_units);
var result;
//if ((units * unit_price) < (alt_units * alt_unit_price))
result = formatMessage(price);
//else
//result = formatMessage(alt_units, alt_unit_price);
showResult(result);

var concreteprice, concreteresult;
concreteprice = getCPrice(units);
concreteresult = formatMessage(concreteprice);
document.calculator.concrete.value = concreteresult;


}

function formatPrice(value) {
var result= Math.floor(value) + ".";
var cents = 100 * (value-Math.floor(value)) + 0.5;
result += Math.floor(cents / 10);
result += Math.floor(cents % 10);
return result;
}

function filterNonNumeric(field) {
var result = new String();
var numbers = "0123456789";
var chars = field.value.split(""); // create array 
for (i = 0; i < chars.length; i++) {
if (numbers.indexOf(chars[i]) != -1) result += chars[i];
}
if (field.value != result) field.value = result;
}
//  End -->


