
// Define some constants
var days_in_year = 231;		// - Working year based on a standard 231 days
var days_in_month = 20;
var days_in_week = 5;

// define global varables
var values_calculated = false;

var driving_cost_yearly;
var driving_cost_monthly;
var driving_cost_weekly;

var transport_cost_cash_yearly;
var transport_cost_cash_monthly;
var transport_cost_cash_weekly;

var transport_cost_SR15pc_yearly;
var transport_cost_SR15pc_monthly;
var transport_cost_SR15pc_weekly;

var transport_cost_SR25pc_yearly;
var transport_cost_SR25pc_monthly;
var transport_cost_SR25pc_weekly;

var distance_travelled_1_way;

var emissions_driving_yearly;
var emissions_driving_monthly;
var emissions_driving_weekly;

var emissions_bus_yearly;
var emissions_bus_monthly;
var emissions_bus_weekly;

var emissions_train_yearly;
var emissions_train_monthly;
var emissions_train_weekly;

function recalculate()
{
	// NOTES:
	// 	- Working year based on a standard 231 days.
	//	- Public transport costs based on a SmartRider 25% discount for appropriate zone travel. Costs current as at 23/07/07.
	//	- Annual distance/costs based on a return trip 231 days a year.
	//	- Costs rounded to the nearest dollar.
	//	- Fuel consumption and car car_size costs based on figures by RAVCV
	//	For a full list of calculation details, see the calculator_cost.html page


	//
	// Get all the form results fields and clear them out
	//
	var field_driving_cost_weekly = document.getElementById('cost_driving_weekly');
	var field_driving_cost_monthly = document.getElementById('cost_driving_monthly');
	var field_driving_cost_yearly = document.getElementById('cost_driving_yearly');

	field_driving_cost_weekly.innerHTML = "&nbsp;";
	field_driving_cost_monthly.innerHTML = "&nbsp;";
	field_driving_cost_yearly.innerHTML = "&nbsp;";

	var field_cash_tickets_weekly = document.getElementById('cost_cash_tickets_weekly');
	var field_cash_tickets_monthly = document.getElementById('cost_cash_tickets_monthly');
	var field_cash_tickets_yearly = document.getElementById('cost_cash_tickets_yearly');

	field_cash_tickets_weekly.innerHTML = "&nbsp;";
	field_cash_tickets_monthly.innerHTML = "&nbsp;";
	field_cash_tickets_yearly.innerHTML = "&nbsp;";

	var field_cost_smartrider_weekly = document.getElementById('cost_smartrider_weekly');
	var field_cost_smartrider_monthly = document.getElementById('cost_smartrider_monthly');
	var field_cost_smartrider_yearly = document.getElementById('cost_smartrider_yearly');

	field_cost_smartrider_weekly.innerHTML = "&nbsp;";
	field_cost_smartrider_monthly.innerHTML = "&nbsp;";
	field_cost_smartrider_yearly.innerHTML = "&nbsp;";

	var field_cost_smartrider_auto_weekly = document.getElementById('cost_smartrider_auto_weekly');
	var field_cost_smartrider_auto_monthly = document.getElementById('cost_smartrider_auto_monthly');
	var field_cost_smartrider_auto_yearly = document.getElementById('cost_smartrider_auto_yearly');

	field_cost_smartrider_auto_weekly.innerHTML = "&nbsp;";
	field_cost_smartrider_auto_monthly.innerHTML = "&nbsp;";
	field_cost_smartrider_auto_yearly.innerHTML = "&nbsp;";

	// output fields
	var field_savings_weekly = document.getElementById('savings_weekly');
	var field_savings_monthly = document.getElementById('savings_monthly');
	var field_savings_yearly = document.getElementById('savings_yearly');
	var field_compare_text = document.getElementById('compare_text');
	document.getElementById('CarE_savings_weekly').innerHTML = "&nbsp;";
	document.getElementById('CarE_savings_monthly').innerHTML = "&nbsp;";
	document.getElementById('CarE_savings_yearly').innerHTML = "&nbsp;";
	document.getElementById('BusE_savings_weekly').innerHTML = "&nbsp;";
	document.getElementById('BusE_savings_monthly').innerHTML = "&nbsp;";
	document.getElementById('BusE_savings_yearly').innerHTML = "&nbsp;";
	document.getElementById('TrainE_savings_weekly').innerHTML = "&nbsp;";
	document.getElementById('TrainE_savings_monthly').innerHTML = "&nbsp;";
	document.getElementById('TrainE_savings_yearly').innerHTML = "&nbsp;";

	field_savings_weekly.innerHTML = "&nbsp;";
	field_savings_monthly.innerHTML = "&nbsp;";
	field_savings_yearly.innerHTML = "&nbsp;";
	field_compare_text.innerHTML = "&nbsp;";

	//
	// Get the values out of the form
	//
	var form_details = document.getElementById('form_savings_calculator');

	// Retrieve the zone entered
	var zone = parseInt(form_details.zone.value);

	// Get the distance travelled
	var distance_travelled = parseInt(form_details.distance.value);
	
	if( isNaN(distance_travelled) )
	{
		alert("Please enter the number of kilometres distance to work");
		form_details.distance_travelled.value = '0';
		return false;
	}
	
	// Retrieve the car size
	var car_size = parseInt(form_details.car_size.value);

	// Retrieve the parking cost
	var parking_cost = parseFloat(form_details.parking_cost.value);
	if( isNaN(parking_cost) )
	{
		alert("Please enter the daily cost for parking");
		form_details.parking_cost.value = '0.00';
		return false;
	}
	
	// Retrieve the petrol price
	var petrol_price = parseFloat(form_details.petrol_price.value);
	if( isNaN(petrol_price) )
	{
		alert("Please enter the current petrol price in cents");
		return false;
	}

	// Retrieve concession holder status
	var concession_holder = form_details.concession.checked;

	//
	// Calculate the driving cost according to selected car size, distance travelled, parking cost and the petrol price
	//
	driving_cost_yearly = calculate_driving_cost('year', car_size, distance_travelled, parking_cost, petrol_price);
	//alert(driving_cost_yearly);
	driving_cost_monthly = calculate_driving_cost('month', car_size, distance_travelled, parking_cost, petrol_price);
	driving_cost_weekly = calculate_driving_cost('week', car_size, distance_travelled, parking_cost, petrol_price);


	//
	// Calculate the public transport costs according to the number of zones selected and the ticket type
	//
	transport_cost_cash_yearly = calculate_annual_cash_transport_cost('year', zone, concession_holder);
	transport_cost_cash_monthly = calculate_annual_cash_transport_cost('month', zone, concession_holder);
	transport_cost_cash_weekly = calculate_annual_cash_transport_cost('week', zone, concession_holder);

	transport_cost_SR15pc_yearly = calculate_annual_SR15pc_transport_cost('year', zone, concession_holder);
	transport_cost_SR15pc_monthly = calculate_annual_SR15pc_transport_cost('month', zone, concession_holder);
	transport_cost_SR15pc_weekly = calculate_annual_SR15pc_transport_cost('week', zone, concession_holder);

	transport_cost_SR25pc_yearly = calculate_annual_SR25pc_transport_cost('year', zone, concession_holder);
	transport_cost_SR25pc_monthly = calculate_annual_SR25pc_transport_cost('month', zone, concession_holder);
	transport_cost_SR25pc_weekly = calculate_annual_SR25pc_transport_cost('week', zone, concession_holder);


	//
	// Fill the results fields
	//
	// - Driving Costs -
	field_driving_cost_weekly.innerHTML = addCommas(String(Math.round((driving_cost_weekly)*100)/100));
	field_driving_cost_monthly.innerHTML = addCommas(String(Math.round((driving_cost_monthly)*100)/100));
	field_driving_cost_yearly.innerHTML = addCommas(String(Math.round((driving_cost_yearly)*100)/100));

	// - Public Transport Costs -
	field_cash_tickets_weekly.innerHTML = String(Math.round((transport_cost_cash_weekly)*100)/100);
	field_cash_tickets_monthly.innerHTML = String(Math.round((transport_cost_cash_monthly)*100)/100);
	field_cash_tickets_yearly.innerHTML = String(Math.round((transport_cost_cash_yearly)*100)/100);

	field_cost_smartrider_weekly.innerHTML = String(Math.round((transport_cost_SR15pc_weekly)*100)/100);
	field_cost_smartrider_monthly.innerHTML = String(Math.round((transport_cost_SR15pc_monthly)*100)/100);
	field_cost_smartrider_yearly.innerHTML = String(Math.round((transport_cost_SR15pc_yearly)*100)/100);

	field_cost_smartrider_auto_weekly.innerHTML = String(Math.round((transport_cost_SR25pc_weekly)*100)/100);
	field_cost_smartrider_auto_monthly.innerHTML = String(Math.round((transport_cost_SR25pc_monthly)*100)/100);
	field_cost_smartrider_auto_yearly.innerHTML = String(Math.round((transport_cost_SR25pc_yearly)*100)/100);

    //
    // Calculate Emissions for each mode
    switch( parseInt(car_size) )
	{
		case 1:		// light
                    emissions_driving_yearly = (155.60 * distance_travelled) * 2 * 231 / 1000;
                    emissions_driving_monthly = (155.60 * distance_travelled) * 2 * 20 / 1000;
                    emissions_driving_weekly = (155.60 * distance_travelled) * 2 * 5 / 1000;
					break;

		case 2:		// small
                    emissions_driving_yearly = (187.75 * distance_travelled) * 2 * 231 / 1000;
                    emissions_driving_monthly = (187.75 * distance_travelled) * 2 * 20 / 1000;
                    emissions_driving_weekly = (187.75 * distance_travelled) * 2 * 5 / 1000;
					break;

		case 3:		// medium
                    emissions_driving_yearly = (222.67 * distance_travelled) * 2 * 231 / 1000;
                    emissions_driving_monthly = (222.67 * distance_travelled) * 2 * 20 / 1000;
                    emissions_driving_weekly = (222.67 * distance_travelled) * 2 * 5 / 1000;
					break;

		default:	// large
                    emissions_driving_yearly = (251 * distance_travelled) * 2 * 231 / 1000;
                    emissions_driving_monthly = (251 * distance_travelled) * 2 * 20 / 1000;
                    emissions_driving_weekly = (251 * distance_travelled) * 2 * 5 / 1000;
					break;
	}    
        
    emissions_bus_yearly = (42 * distance_travelled) * 2 * 231 * 1.3 / 1000;
    emissions_bus_monthly = (42 * distance_travelled) * 2 * 20 * 1.3 / 1000;
    emissions_bus_weekly = (42 * distance_travelled) * 2 * 5 * 1.3 / 1000;

    emissions_train_yearly = (52 * distance_travelled) * 2 * 231 / 1000;
    emissions_train_monthly = (52 * distance_travelled) * 2 * 20 / 1000;
    emissions_train_weekly = (52 * distance_travelled) * 2 * 5 / 1000;

	// set the valid flag
	values_calculated = true;

	// enable the compare button if 2 compare checkboxs are checked
	check_checkbox_count();

}


/**
 * Based on the figures inputted together with set running and fuel consumption costs within the function itself, this
 * function returns the driving cost for a return trip for the car of the given size for the specified period of time (week, month or year).
 *
 * @param integer car_size				- 1=light, 2=small, 3=medium, 4=large
 * @param integer distance_travelled	- Distance travelled in kilometres
 * @param float parking_cost			- Parking cost based on City of Perth and Wilson day parking costs
 * @param float petrol_price			- Petrol price in cents per litre
 * @return float
 */
function calculate_driving_cost(time, car_size, distance_travelled, parking_cost, petrol_price)
{
	var driving_cost = 0;

	// First get the running cost and fuel consumption costs for the selected car size
	//   	- Running Cost: The car running cost per kilometre comprises tyres, service and repairs. They exclude depreciation, interest costs, registration and insurance.
	//		- Fuel Consumption: litres per 100 kilometres (THIS IS Litres PER KM not per 100KM)
	var running = 0;
	var consumption = 0;
	switch( parseInt(car_size) )
	{
		case 1:		// light
					// 06/07 running = 0.052;
					// 06/07 consumption = 0.067;
					running = 0.0496;
					consumption = 0.066;
					break;

		case 2:		// small
					// 06/07 running = 0.061;
					// 06/07 consumption = 0.077;
					running = 0.0627;
					consumption = 0.08;
					break;

		case 3:		// medium
					// 06/07 running = 0.061;
					// 06/07 consumption = 0.10;
					running = 0.0641;
					consumption = 0.0937;
					break;

		default:	// large
					// 06/07 running = 0.048;
					// 06/07 consumption = 0.11;
					running = 0.0478;
					consumption = 0.1058;
					break;
	}

	// Using the calculated running and fuel consumption costs, together with the parking cost, petrol price and distance travelled values, calculate the driving cost for the specified time period
	switch( String(time) )
	{
		case 'week':
			driving_cost = (days_in_week * parking_cost) + (days_in_week * distance_travelled * running * 2) + (days_in_week * distance_travelled * consumption * petrol_price/100 * 2);
			break;
		case 'month':
			driving_cost = (days_in_month * parking_cost) + (days_in_month * distance_travelled * running * 2) + (days_in_month * distance_travelled * consumption * petrol_price/100 * 2);
			break;
		case 'year':
			driving_cost = (days_in_year * parking_cost) + (days_in_year * distance_travelled * running * 2) + (days_in_year * distance_travelled * consumption * petrol_price/100 * 2);
			break;
	}

	// Return the calculated annual driving cost
	return driving_cost;
}

/**
 * Check if there are 2 compare checkboxs 'checked' and enable the compare button, else disable it
 */
function check_checkbox_count()
{
	var count = 0;

	//
	// Get the values out of the form
	//
	var form_details = document.getElementById('form_savings_compare');
	if ( form_details.driving_compare.checked ) count++;
	if ( form_details.cash_compare.checked ) count++;
	if ( form_details.smartrider_compare.checked ) count++;
	if ( form_details.smartriderauto_compare.checked ) count++;

	// enable/disable the compare button
	if ( (count == 2) && (values_calculated == true) )
	{
		div_hide('compare_disable');
		div_show('compare_enable');
		return true;
	}
	else
	{
		div_hide('compare_enable');
		div_show('compare_disable');
		return false;
	}
}

/**
 * Check if there are 2 compare checkboxs 'checked' and enable the compare button, else disable it
 */
function recompare()
{
	var flag_a = false;
	var name_a = "";
	var weekly_a = 0;
	var monthly_a = 0;
	var yearly_a = 0;

	var name_b = "";
	var weekly_b = 0;
	var monthly_b = 0;
	var yearly_b = 0;

	// recalc everything to be sure
	recalculate();

	// Get the values for set a and set b
	var form_details = document.getElementById('form_savings_compare');

	// Driving costs?
	if (form_details.driving_compare.checked)
	{
		flag_a 		= true;
		name_a		= "Driving";
		weekly_a	= driving_cost_weekly;
		monthly_a	= driving_cost_monthly;
		yearly_a	= driving_cost_yearly;
	}

	// Cash Tickets?
	if (form_details.cash_compare.checked)
	{
		if (flag_a == false)
		{
			flag_a 		= true;
			name_a		= "Cash ticket";
			weekly_a	= transport_cost_cash_weekly;
			monthly_a	= transport_cost_cash_monthly;
			yearly_a	= transport_cost_cash_yearly;
		}
		else
		{
			name_b		= "Cash ticket";
			weekly_b	= transport_cost_cash_weekly;
			monthly_b	= transport_cost_cash_monthly;
			yearly_b	= transport_cost_cash_yearly;
		}
	}

	// Cash Tickets?
	if (form_details.smartrider_compare.checked)
	{
		if (flag_a == false)
		{
			flag_a 		= true;
			name_a		= "SmartRider";
			weekly_a	= transport_cost_SR15pc_weekly;
			monthly_a	= transport_cost_SR15pc_monthly;
			yearly_a	= transport_cost_SR15pc_yearly;
		}
		else
		{
			name_b		= "SmartRider";
			weekly_b	= transport_cost_SR15pc_weekly;
			monthly_b	= transport_cost_SR15pc_monthly;
			yearly_b	= transport_cost_SR15pc_yearly;
		}
	}

	// Cash Tickets?
	if (form_details.smartriderauto_compare.checked)
	{
		name_b		= "SmartRider with Autoload";
		weekly_b	= transport_cost_SR25pc_weekly;
		monthly_b	= transport_cost_SR25pc_monthly;
		yearly_b	= transport_cost_SR25pc_yearly;
	}

	var field_savings_weekly = document.getElementById('savings_weekly');
	var field_savings_monthly = document.getElementById('savings_monthly');
	var field_savings_yearly = document.getElementById('savings_yearly');
	var field_compare_text = document.getElementById('compare_text');

	// which of the 2 sets is cheaper
	if (weekly_a < weekly_b)
	{
		// set A is cheaper
		field_compare_text.innerHTML = name_a + " is cheaper. Checkout your savings below;"
		field_savings_weekly.innerHTML = addCommas(String(Math.round((weekly_b - weekly_a)*100)/100));
		field_savings_monthly.innerHTML = addCommas(String(Math.round((monthly_b - monthly_a)*100)/100));
		field_savings_yearly.innerHTML = addCommas(String(Math.round((yearly_b - yearly_a)*100)/100));
	}
	else
	{
		// set B is cheaper
		field_compare_text.innerHTML = name_b + " is cheaper. Checkout your savings below;"
		field_savings_weekly.innerHTML = addCommas(String(Math.round((weekly_a - weekly_b)*100)/100));
		field_savings_monthly.innerHTML = addCommas(String(Math.round((monthly_a - monthly_b)*100)/100));
		field_savings_yearly.innerHTML = addCommas(String(Math.round((yearly_a - yearly_b)*100)/100));
	}

    // Add in the CO2 emissions savings
	var field_CarE_savings_yearly = document.getElementById('CarE_savings_yearly');
	var field_BusE_savings_yearly = document.getElementById('BusE_savings_yearly');
	var field_TrainE_savings_yearly = document.getElementById('TrainE_savings_yearly');
	var field_CarE_savings_weekly = document.getElementById('CarE_savings_weekly');
	var field_BusE_savings_weekly = document.getElementById('BusE_savings_weekly');
	var field_TrainE_savings_weekly = document.getElementById('TrainE_savings_weekly');
	var field_CarE_savings_monthly = document.getElementById('CarE_savings_monthly');
	var field_BusE_savings_monthly = document.getElementById('BusE_savings_monthly');
	var field_TrainE_savings_monthly = document.getElementById('TrainE_savings_monthly');
		
	field_CarE_savings_yearly.innerHTML = addCommas(String(Math.round((emissions_driving_yearly)*100)/100));
	field_BusE_savings_yearly.innerHTML = addCommas(String(Math.round((emissions_bus_yearly)*100)/100));
	field_TrainE_savings_yearly.innerHTML = addCommas(String(Math.round((emissions_train_yearly)*100)/100));
	field_CarE_savings_weekly.innerHTML = addCommas(String(Math.round((emissions_driving_weekly)*100)/100));
	field_BusE_savings_weekly.innerHTML = addCommas(String(Math.round((emissions_bus_weekly)*100)/100));
	field_TrainE_savings_weekly.innerHTML = addCommas(String(Math.round((emissions_train_weekly)*100)/100));
    field_CarE_savings_monthly.innerHTML = addCommas(String(Math.round((emissions_driving_monthly)*100)/100));
    field_BusE_savings_monthly.innerHTML = addCommas(String(Math.round((emissions_bus_monthly)*100)/100));
    field_TrainE_savings_monthly.innerHTML = addCommas(String(Math.round((emissions_train_monthly)*100)/100));
}

function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}




/**
 * Based on the given number of zones selected, this function returns the annual Standard Cash
 * cost for a return trip using public transport.
 *
 * The prices given are based on the values at: http://www.transperth.wa.gov.au/Default.aspx?tabid=44
 *
 * @param integer zone
 * @return float
 */
function calculate_annual_cash_transport_cost(time, zone, concession)
{
	// Based on the zone entered, get the specified cost
	var transport_cost = 0;

	if ( concession )
	{
		// concession
		switch( parseInt(zone) )
		{
			case 1:			fare_price = 0.60;		// 2 sections
							break;
			case 2:			fare_price = 0.90;		// 1 zone
							break;
			case 3:			fare_price = 1.40;
							break;
			case 4:			fare_price = 1.80;
							break;
			case 5:			fare_price = 2.10;
							break;
			case 6:			fare_price = 2.40;
							break;
			case 7:			fare_price = 2.70;
							break;
			case 8:			fare_price = 3.10;
							break;
			case 9:		    fare_price = 3.50;
							break;
			case 10:		fare_price = 3.90;
							break;
		}
	}
	else
	{
		// full fare
		switch( parseInt(zone) )
		{
			case 1:			fare_price = 1.60;		// 2 sections
							break;
			case 2:			fare_price = 2.30;		// 1 zone
							break;
			case 3:			fare_price = 3.50;
							break;
			case 4:			fare_price = 4.30;
							break;
			case 5:			fare_price = 5.10;
							break;
			case 6:			fare_price = 6.20;
							break;
			case 7:			fare_price = 7.10;
							break;
			case 8:			fare_price = 8.20;
							break;
			case 9:			fare_price = 8.90;
							break;
			case 10:		fare_price = 9.60;
							break;
		}
	}

	switch( String(time) )
	{
		case 'week':	transport_cost = (fare_price * days_in_week) * 2;		// 2 trips a day
						break;
		case 'month':	transport_cost = (fare_price * days_in_month) * 2;
						break;
		case 'year':	transport_cost = (fare_price * days_in_year) * 2;
						break;
	}

	// Return the calculated cost
	return transport_cost;
}


/**
 * Based on the given number of zones selected, this function returns the annual Standard SmartRider
 * cost (with 15% discount) for a return trip using public transport.
 *
 * The prices given are based on the values at: http://www.transperth.wa.gov.au/Default.aspx?tabid=44
 *
 * @param integer zone
 * @return float
 */
function calculate_annual_SR15pc_transport_cost(time, zone, concession)
{
	// Based on the zone entered, get the specified cost
	var transport_cost = 0;
	if ( concession )
	{
		// concession
		switch( parseInt(zone) )
		{
			case 1:			fare_price = 0.51;		// 2 sections
							break;
			case 2:			fare_price = 0.77;		// 1 zone
							break;
			case 3:			fare_price = 1.19;
							break;
			case 4:			fare_price = 1.53;
							break;
			case 5:			fare_price = 1.79;
							break;
			case 6:			fare_price = 2.04;
							break;
			case 7:			fare_price = 2.30;
							break;
			case 8:			fare_price = 2.64;
							break;
			case 9:			fare_price = 2.98;
							break;
			case 10:		fare_price = 3.32;
							break;
		}
	}
	else
	{
		// full fare
		switch( parseInt(zone) )
		{
			case 1:			fare_price = 1.36;		// 2 sections
							break;
			case 2:			fare_price = 1.96;
							break;
			case 3:			fare_price = 2.98;
							break;
			case 4:			fare_price = 3.66;
							break;
			case 5:			fare_price = 4.34;
							break;
			case 6:			fare_price = 5.27;
							break;
			case 7:			fare_price = 6.04;
							break;
			case 8:			fare_price = 6.97;
							break;
			case 9:			fare_price = 7.57;
							break;
			case 10:		fare_price = 8.16;
							break;
		}
	}

	switch( String(time) )
	{
		case 'week':	transport_cost = (fare_price * days_in_week) * 2;		// 2 trips a day
						break;
		case 'month':	transport_cost = (fare_price * days_in_month) * 2;
						break;
		case 'year':	transport_cost = (fare_price * days_in_year) * 2;
						break;
	}

	// Return the calculated cost
	return transport_cost;
}


/**
 * Based on the given number of zones selected, this function returns the annual Standard SmartRider
 * cost (with 25% discount) for a return trip using public transport.
 *
 * The prices given are based on the values at: http://www.transperth.wa.gov.au/Default.aspx?tabid=44
 *
 * @param integer zone
 * @return float
 */
function calculate_annual_SR25pc_transport_cost(time, zone, concession)
{
	// Based on the zone entered, get the specified cost
	var transport_cost = 0;

	if ( concession )
	{
		// concession
		switch( parseInt(zone) )
		{
			case 1:			fare_price = 0.45;		// 2 sections
							break;
			case 2:			fare_price = 0.68;		// 1 zone
							break;
			case 3:			fare_price = 1.05;
							break;
			case 4:			fare_price = 1.35;
							break;
			case 5:			fare_price = 1.58;
							break;
			case 6:			fare_price = 1.80;
							break;
			case 7:			fare_price = 2.03;
							break;
			case 8:			fare_price = 2.33;
							break;
			case 9:			fare_price = 2.63;
							break;
			case 10:		fare_price = 2.93;
							break;
		}
	}
	else
	{
		// full fare
		switch( parseInt(zone) )
		{
			case 1:			fare_price = 1.20;		// 2 sections
							break;
			case 2:			fare_price = 1.73;		// 1 zone
							break;
			case 3:			fare_price = 2.63;
							break;
			case 4:			fare_price = 3.23;
							break;
			case 5:			fare_price = 3.83;
							break;
			case 6:			fare_price = 4.65;
							break;
			case 7:			fare_price = 5.33;
							break;
			case 8:			fare_price = 6.15;
							break;
			case 9:			fare_price = 6.68;
							break;
			case 10:		fare_price = 6.20;
							break;
		}
	}

	switch( String(time) )
	{
		case 'week':	transport_cost = (fare_price * days_in_week) * 2;		// 2 trips a day
						break;
		case 'month':	transport_cost = (fare_price * days_in_month) * 2;
						break;
		case 'year':	transport_cost = (fare_price * days_in_year) * 2;
						break;
	}

	// Return the calculated cost
	return transport_cost;
}


/**
 * Hide the specifed <div>
 *
 * @param string div name
 */
function div_hide( fieldname )
{
	document.getElementById(fieldname).style.display = "none";
}


/**
 * Show the specifed <div>
 *
 * @param string div name
 */
function div_show( fieldname )
{
	document.getElementById(fieldname).style.display = "block";
}