		function plotConferencingMenu(strName, intTabIndex) {
			var i;
			document.write ("<select name='" + strName + "' tabindex='" + intTabIndex + "' onchange='updateConferencing(this);'>")
			document.write ("<option value=''>Select type</option>")
			for (i=0; i<arrConferencingType.length; i++) {
				document.write("<option value='" + arrConferencingType[i][1] + "'>" + arrConferencingType[i][0] + "</option>")
			}
			document.write ("</select>")
		}

		function plotWebConferencingMenu(strName, intTabIndex) {
			var i;
			document.write ("<select name='" + strName + "' tabindex='" + intTabIndex + "' onchange='updateWebConferencing(this);'>")
			document.write ("<option value=''>Select type</option>")
			for (i=0; i<arrWebConferencingType.length; i++) {
				document.write("<option value='" + arrWebConferencingType[i][1] + "'>" + arrWebConferencingType[i][0] + "</option>")
			}
			document.write ("</select>")
		}

		function updateConferencing(objElement) {

			with (document.calculator) {
				conferencing_unit.value = objElement.options[objElement.selectedIndex].value;
				//formatDollar(conferencing_unit);
			//	conferencing_unit.focus();
				calculateFTotal();
			}
		}

		function updateWebConferencing(objElement) {
			with (document.calculator) {
				webconferencing_unit.value = objElement.options[objElement.selectedIndex].value;
				//formatDollar(webconferencing_unit);
			//	conferencing_unit.focus();
				calculateFTotal();
			}
		}

		function calculateFTotal() {
			calculateTotals();
			calculateConferencing();
			with (document.calculator) {
				conferencing_total.value = conferencing_total.value;
				grandtotal.value =   trip_total.value - conferencing_total.value;
				formatDollar(grandtotal);
			}
		}

		function calculateConferencing() {
			with (document.calculator) {
				if (isNumber(conferencing_unit.value) && isNumber(conferencing_quantity.value) && isNumber(conferencing_duration.value)) {
					conferencing_total.value = (0 - conferencing_unit.value) * conferencing_quantity.value * conferencing_duration.value * -1;
				}
				if ((typeof(webconferencing_unit) != "undefined") && isNumber(webconferencing_unit.value) && isNumber(conferencing_quantity.value) && isNumber(conferencing_duration.value)) {
					conferencing_total.value = parseFloat(conferencing_total.value) + parseFloat((0 - webconferencing_unit.value) * conferencing_quantity.value * conferencing_duration.value * -1);
				}

				formatDollar(conferencing_total);
			}
		}

		function calculateTravel() {
			with (document.calculator) {
				if (isNumber(travel_unit.value) && isNumber(travel_quantity.value)) {
					travel_subtotal.value = travel_unit.value * travel_quantity.value;
				}
				formatDollar(travel_subtotal);
			}
		}

		function calculateLodging() {
			with (document.calculator) {
				if (isNumber(lodging_unit.value) && isNumber(lodging_quantity.value) && isNumber(lodging_duration.value)) {
					lodging_subtotal.value = lodging_unit.value * lodging_quantity.value * lodging_duration.value;
				}
				formatDollar(lodging_subtotal);
			}
		}

		//function calculateRental() {
		//	with (document.calculator) {
		//		if (isNumber(rental_unit.value) && isNumber(rental_quantity.value) && isNumber(rental_duration.value)) {
		//			rental_subtotal.value = rental_unit.value * rental_quantity.value * rental_duration.value;
		//		}
		//		formatDollar(rental_subtotal);
		//	}
		//}

		function calculateMeal1() {
			with (document.calculator) {
				if (isNumber(meal1_unit.value) && isNumber(meal1_quantity.value)) {
					meal1_subtotal.value = meal1_unit.value * meal1_quantity.value;
				}
				formatDollar(meal1_subtotal);
			}
		}
		function calculateMeal2() {
			with (document.calculator) {
				if (isNumber(meal2_unit.value) && isNumber(meal2_quantity.value)) {
					meal2_subtotal.value = meal2_unit.value * meal2_quantity.value;
				}
				formatDollar(meal2_subtotal);
			}
		}
	function calculateMeal3() {
			with (document.calculator) {
				if (isNumber(meal3_unit.value) && isNumber(meal3_quantity.value)) {
					meal3_subtotal.value = meal3_unit.value * meal3_quantity.value;
				}
				formatDollar(meal3_subtotal);
			}
		}
	function calculateMealSubTotal() {
			with (document.calculator) {
				meal_subtotal.value = (meal1_subtotal.value - 0) + (meal2_subtotal.value-0) + (meal3_subtotal.value-0);

				formatDollar(meal_subtotal);
			}
		}
		function calculateTotals() {
			calculateTravel();
			calculateLodging();
			//calculateRental();
			//calculateMeal1();
			//calculateMeal2();
			//calculateMeal3();
			//calculateMealSubTotal() ;
			with (document.calculator) {
				//trip_total.value = (travel_subtotal.value - 0) + (lodging_subtotal.value - 0) + (rental_subtotal.value - 0) + (meal_subtotal.value - 0);
				//trip_total.value = (travel_subtotal.value - 0) + (lodging_subtotal.value - 0) + (meal_subtotal.value - 0);
				trip_total.value = (travel_subtotal.value - 0) + (lodging_subtotal.value - 0) ;
				formatDollar(trip_total);

			}
		}

		function formatDollar(objElement) {
			var strAmount = objElement.value;
			var intDollar, intCents;
			if (isNumber(strAmount)) {
				// valid number
				if (strAmount.length == 0) {
					// empty
					intDollar = "0"
					intCents = "00"
				} else if (strAmount.indexOf(".") == 0) {
					// no dollar
					intDollar = "0";
					intCents = roundCents(strAmount.substring(1, strAmount.length));
				} else if (strAmount.indexOf(".") < 0) {
					// no cents
					intDollar = strAmount;
					intCents = "00";
				} else {
					// dollars and cents
					intDollar = strAmount.substring(0, strAmount.indexOf("."))
					intCents = roundCents(strAmount.substring(strAmount.indexOf(".") + 1, strAmount.length));
				}
				// modify the value
				objElement.value = intDollar + "." + intCents;
			} else {
				alert("Please enter a valid number.");
				objElement.select();
			}
		}

		function formatNumber(objElement) {
			var strAmount = objElement.value;
			if (isNumber(strAmount)) {
				if (isNumber == "") {
					strAmount = 0;
				} else {
					strAmount = Math.round(strAmount);
				}
				objElement.value = strAmount;
			} else {
				alert("Please enter a valid number.");
				objElement.select();
			}
		}

		function roundCents(strCents) {
			var strReturn;
			if (strCents.length > 2) {
				// cents is more than 2 decimals
				strReturn = strCents.substring(0, 2)
				if (strCents.charAt(2) >= 5) {
					// round up
					strReturn = String(++strReturn);
				}
				if (strReturn.length == 1) {
				// this means strReturn was "0" plus some other digit, and we lost leading zero when treating strReturn as number for ++ operation, so add leading zero back in
				strReturn = "0" + strReturn;
				}
			} else if (strCents.length == 2) {
				// cents is 2 digits
				strReturn = strCents
			} else if (strCents.length == 1) {
				// cents is 1 digit only
				strReturn = strCents + "0";
			} else {
				// cents is 0 digits
				strReturn = "00";
			}
			return strReturn;
		}

		function isNumber(strNumber) {
			// valid chars for number
			var strValid = "0123456789.-";

			for (i=0; i<strNumber.length; i++) {
				// go through each char in string
				if (strValid.indexOf(strNumber.charAt(i)) < 0) {
					return false;
				}
			}
			return true;
		}

		function CalculateCO2Saving()
		{
		   totalSavings = 0;

		   with (document.calculator)
		   {
		      if (isNumber(petrol_car_miles.value))
		      {
		         totalSavings = totalSavings + petrol_car_miles.value * 0.29;
		      }
		      if (isNumber(diesel_car_miles.value))
		      {
		         totalSavings = totalSavings + diesel_car_miles.value * 0.27;
		      }
		      if (isNumber(rail_travel_miles.value))
		      {
		         totalSavings = totalSavings + rail_travel_miles.value * 0.064;
		      }
		      if (isNumber(air_longhaul_travel_miles.value))
		      {
		         totalSavings = totalSavings + air_longhaul_travel_miles.value * 0.176;
		      }
		      if (isNumber(air_shorthaul_travel_miles.value))
		      {
		         totalSavings = totalSavings + air_shorthaul_travel_miles.value * 0.24;
		      }

		      CO2_grandtotal.value = Math.round(totalSavings * 100)/100;
				formatDollar(CO2_grandtotal);
		   }
		}

