function CalculateTotal(frm) {
var order_total = 0
var item_quantity = 0
for (var i=0; i < frm.elements.length; ++i) {
form_field = frm.elements[i]
form_name = form_field.id
if (form_name.substring(0,4) == "PROD") {
item_price = parseFloat(form_name.substring(form_name.lastIndexOf("_") + 1))
item_quantity = parseInt(form_field.value)
if (item_quantity >= 0) {
order_total += item_quantity * item_price

}
}
}

frm.TOTAL.value = round_decimals(order_total, 2)


qty1=parseInt(document.frmCheckout.qty1.value)
qty2=parseInt(document.frmCheckout.qty2.value)
if (qty1 >=1 || qty2 >=1) {
document.getElementById("b1_2").src="images/cart.gif";
}
else {
document.getElementById("b1_2").src="images/blank.gif";
}


qty3=parseInt(document.frmCheckout.qty3.value)
qty4=parseInt(document.frmCheckout.qty4.value)
if (qty3 >=1 || qty4 >=1) {
document.getElementById("b3_4").src="images/cart.gif";
}
else {
document.getElementById("b3_4").src="images/blank.gif";
}


qty5=parseInt(document.frmCheckout.qty5.value)
qty6=parseInt(document.frmCheckout.qty6.value)
if (qty5 >=1 || qty6 >=1) {
document.getElementById("b5_6").src="images/cart.gif";
}
else {
document.getElementById("b5_6").src="images/blank.gif";
}


qty7=parseInt(document.frmCheckout.qty7.value)
qty8=parseInt(document.frmCheckout.qty8.value)
if (qty7 >=1 || qty8 >=1) {
document.getElementById("b7_8").src="images/cart.gif";
}
else {
document.getElementById("b7_8").src="images/blank.gif";
}


qty9=parseInt(document.frmCheckout.qty9.value)
qty10=parseInt(document.frmCheckout.qty10.value)
if (qty9 >=1 || qty10 >=1) {
document.getElementById("b9_10").src="images/cart.gif";
}
else {
document.getElementById("b9_10").src="images/blank.gif";
}

qty11=parseInt(document.frmCheckout.qty11.value)
qty12=parseInt(document.frmCheckout.qty12.value)
if (qty11 >=1 || qty12 >=1) {
document.getElementById("b11_12").src="images/cart.gif";
}
else {
document.getElementById("b11_12").src="images/blank.gif";
}

qty13=parseInt(document.frmCheckout.qty13.value)
qty14=parseInt(document.frmCheckout.qty14.value)
if (qty13 >=1 || qty14 >=1) {
document.getElementById("b13_14").src="images/cart.gif";
}
else {
document.getElementById("b13_14").src="images/blank.gif";
}

qty15=parseInt(document.frmCheckout.qty15.value)
qty16=parseInt(document.frmCheckout.qty16.value)
if (qty15 >=1 || qty16 >=1) {
document.getElementById("b15_16").src="images/cart.gif";
}
else {
document.getElementById("b15_16").src="images/blank.gif";
}


}


function round_decimals(original_number, decimals) {
var result1 = original_number * Math.pow(10, decimals)
var result2 = Math.round(result1)
var result3 = result2 / Math.pow(10, decimals)
return pad_with_zeros(result3, decimals)
}

function pad_with_zeros(rounded_value, decimal_places) {
var value_string = rounded_value.toString()
var decimal_location = value_string.indexOf(".")
if (decimal_location == -1) {
decimal_part_length = 0
value_string += decimal_places > 0 ? "." : ""
}
else {
decimal_part_length = value_string.length - decimal_location - 1
}

var pad_total = decimal_places - decimal_part_length
if (pad_total > 0) {
for (var counter = 1; counter <= pad_total; counter++) 
value_string += "0"
}
return value_string
}

function validate_required(field,alerttxt)
{
with (field)
  {
  if (value==null||value=="")
    {
    alert(alerttxt);return false;
    }
  else
    {
    return true;
    }
  }
}

function validate_form(thisform)
{
with (thisform)
  {
  if (validate_required(TOTAL,"Please select at least one drink!")==false)
  {return false;}
  }
}

