	// function to calculate the total cost field
	function Total() {

		var subtot = 0;
		subtot += 0.25 * (document.order.wv_q.value);
		subtot += 0.25 * (document.order.pv_q.value);
		subtot += 0.25 * (document.order.tv_q.value);
		subtot += 0.25 * (document.order.ei_q.value);
		subtot += 0.25 * (document.order.vsp_q.value);
		subtot += 0.25 * (document.order.wwje_q.value);
		subtot += 2 * (document.order.holder_q.value);
		subtot += 10 * (document.order.animallib_q.value);
		subtot += 15 * (document.order.plantbased_q.value);
		subtot += 15 * (document.order.becomingvegan_q.value);
		subtot += 10 * (document.order.maxnutvhs_q.value);
		subtot += 16 * (document.order.maxnutdvd_q.value);
		subtot += 11 * (document.order.convenientveg_q.value);
		subtot += 11 * (document.order.vittles_q.value);
		subtot += 5 * (document.order.meetyourmeat_q.value);
		subtot += 20 * (document.order.cowatmytable_q.value);
		subtot += 1 * (document.order.posters_q.value);
		subtot += 11 * (document.order.pictures_q.value);
		document.order.subtotal.value = round_decimals(subtot,2);

		//salestax

		var tax = 0;
		if (document.order.pa_resident.checked) {
			var tax = subtot * 0.07;
			document.order.salestax.value = round_decimals(tax,2);
		} else;

		//shipping and handling

		var totalitemcount = 0;
		totalitemcount += 1 * (document.order.animallib_q.value);
		totalitemcount += 1 * (document.order.plantbased_q.value);
		totalitemcount += 1 * (document.order.becomingvegan_q.value);
		totalitemcount += 1 * (document.order.convenientveg_q.value);
		totalitemcount += 1 * (document.order.vittles_q.value);
		totalitemcount += 1 * (document.order.meetyourmeat_q.value);
		totalitemcount += 1 * (document.order.cowatmytable_q.value);
		totalitemcount += 1 * (document.order.pictures_q.value);
		totalitemcount += 1 * (document.order.maxnutvhs_q.value);
		totalitemcount += 1 * (document.order.maxnutdvd_q.value);

		var shippingcost = 0;
		if (totalitemcount >0) {
			var shippingcost = 3 + (1.5 * totalitemcount);
		}

		document.order.shipping.value = round_decimals(shippingcost,2);

		//donation
		var donation = 0;
		donation += 1 * (document.order.donation.value);

		//total
		document.order.total.value = round_decimals(Math.round(subtot + tax + shippingcost + donation),2);

	}

	function UpdateCost(itemname, unitcost) {
	   costname = itemname + "_t";
	   qtyname = itemname + "_q";
	   var q = document.order[qtyname].value;
	   document.order[costname].value = round_decimals((q * unitcost),2);
	   Total();
	}

	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
	}
