/*
* gets the selected value of a <select> item...
* WARNING - the select must have value attributes for each option
* otherwise breaks on IE / PC
*/
function getSelectedValue(theSelect)
{
	return(theSelect.options[theSelect.selectedIndex].value);
}

// Update display
function updateDisplay()
{
    /**
     * @global vars
     *  - adult_price
     *  - child_price
     *  - family_price
     */
	if(!orderForm) var orderForm = document.getElementById("orderForm");
	var total_cost = 0, adults = 0, children = 0, families = 0;

	// Update displayed summary
	document.getElementById('disp_num_guests').innerHTML = getSelectedValue(orderForm.number_adults);
    if (child_price) {
        document.getElementById('disp_num_guests').innerHTML = parseInt(document.getElementById('disp_num_guests').innerHTML) + parseInt(getSelectedValue(orderForm.number_children));
    }
	document.getElementById('disp_date').innerHTML = getSelectedValue(orderForm.tour_day)+"/"+getSelectedValue(orderForm.tour_month)+"/"+getSelectedValue(orderForm.tour_year);
    adults = getSelectedValue(orderForm.number_adults);
    if (child_price) {
        children = getSelectedValue(orderForm.number_children);
    }   
    if (family_price) {
	    while ((adults > 1) && (children > 1)) {
		families++;
		adults -= 2;
		children -= 2;
	    }
    }
    total_price = (adults * adult_price) + (children * child_price) + (families * family_price);
	document.getElementById('disp_total_cost').innerHTML = total_price;
	orderForm["Total_NZD"].value = dollarFormat(total_price);
	orderForm["Total_String"].value = '$' + total_price;

	// Update end dates for stay in Wellington if less than start dates
	if (orderForm.departure_day.selectedIndex < orderForm.arrival_day.selectedIndex) {
		orderForm.departure_day.selectedIndex = orderForm.arrival_day.selectedIndex;
	}
	if (orderForm.departure_month.selectedIndex < orderForm.arrival_month.selectedIndex) {
		orderForm.departure_month.selectedIndex = orderForm.arrival_month.selectedIndex;
	}
	if (orderForm.departure_year.selectedIndex < orderForm.arrival_year.selectedIndex) {
		orderForm.departure_year.selectedIndex = orderForm.arrival_year.selectedIndex;
	}

	// If phone selected display preference options
//	if(document.orderForm.contact_method[3].checked) {
//		document.getElementById('prefer_phone_time_fields').style.visibility = 'visible';
//	} else {
//		document.getElementById('prefer_phone_time_fields').style.visibility = 'hidden';
//	}
}


