
function totalise(form) {
	// bank holiday weekend dates (including the day before the weekend)
	// March to October only
	// version of Jan 16 2012 with single type of eletric hook-up
	holidays = new Array()
	holidays[0] = new Date("April 5, 2012")									// thursday
    next_holiday = new Date("April 6, 2012");	holidays.push(next_holiday)	// Good Friday
    next_holiday = new Date("April 7, 2012");   holidays.push(next_holiday)	// saturday
    next_holiday = new Date("April 8, 2012");   holidays.push(next_holiday)	// sunday
    next_holiday = new Date("April 9, 2012");   holidays.push(next_holiday)	// Easter Monday
    next_holiday = new Date("May 4, 2012");   	holidays.push(next_holiday) // friday
    next_holiday = new Date("May 5, 2012");   	holidays.push(next_holiday) // saturday
    next_holiday = new Date("May 6, 2012");   	holidays.push(next_holiday) // sunday
    next_holiday = new Date("May 7, 2012");   	holidays.push(next_holiday) // Mayday Monday
    next_holiday = new Date("June 1, 2012");   	holidays.push(next_holiday) // friday
    next_holiday = new Date("June 2, 2012");   	holidays.push(next_holiday) // saturday
    next_holiday = new Date("June 3, 2012");   	holidays.push(next_holiday) // sunday
    next_holiday = new Date("June 4, 2012");   	holidays.push(next_holiday) // Spring Monday
    next_holiday = new Date("June 5, 2012");   	holidays.push(next_holiday) // Jubilee Tuesday
    next_holiday = new Date("August 24, 2012");	holidays.push(next_holiday) // friday
	next_holiday = new Date("August 25, 2012");	holidays.push(next_holiday) // saturday
	next_holiday = new Date("August 26, 2012");	holidays.push(next_holiday) // sunday
	next_holiday = new Date("August 27, 2012");	holidays.push(next_holiday) // Late Summer Monday
	
    next_holiday = new Date("March 28, 2013");	holidays.push(next_holiday)	// thursday
    next_holiday = new Date("March 29, 2013");	holidays.push(next_holiday)	// Good Friday
    next_holiday = new Date("March 30, 2013");  holidays.push(next_holiday)	// saturday
    next_holiday = new Date("March 31, 2013");  holidays.push(next_holiday)	// sunday
    next_holiday = new Date("April 1, 2013");   holidays.push(next_holiday)	// Easter Monday
    next_holiday = new Date("May 3, 2013");   	holidays.push(next_holiday) // friday
    next_holiday = new Date("May 4, 2013");   	holidays.push(next_holiday) // saturday
    next_holiday = new Date("May 5, 2013");   	holidays.push(next_holiday) // sunday
    next_holiday = new Date("May 6, 2013");   	holidays.push(next_holiday) // Mayday Monday
    next_holiday = new Date("May 24, 2013");   	holidays.push(next_holiday) // friday
    next_holiday = new Date("May 25, 2013");   	holidays.push(next_holiday) // saturday
    next_holiday = new Date("May 26, 2013");   	holidays.push(next_holiday) // sunday
    next_holiday = new Date("May 27, 2013");   	holidays.push(next_holiday) // Spring Monday
    next_holiday = new Date("August 23, 2013");	holidays.push(next_holiday) // friday
	next_holiday = new Date("August 24, 2013");	holidays.push(next_holiday) // saturday
	next_holiday = new Date("August 25, 2013");	holidays.push(next_holiday) // sunday
	next_holiday = new Date("August 26, 2013");	holidays.push(next_holiday) // Late Summer Monday
	
	number_holidays = holidays.length
	
	//window.alert("Number holidays " + number_holidays)
	//window.alert("Tenth holiday " + holidays[9])

	nights_price_allweather = 22.95
	nights_price_grass_elec = 22.50
	nights_price_grass_noelec = 18.50
	pensioner_price_elec = 17.50     // need to change code below when changing charges
	pensioner_price_noelec = 14.25
	
	peak_supplement_price = 2.0
	adults_price = 6.50
	children_price = 2.50
	car_price = 2.00
	tent_price = 4.00
	gazebo_price = 4.00
	
	total_price = 0.0
	nights = parseInt(form.NIGHTS.value)
	
	// get arrival date and validate
	error = false
	error_nodate = false
	arrival_day = parseInt(form.ARRIVAL_DAY.value)
	if (arrival_day == 0) error_nodate = true
	arrival_year = parseInt(form.ARRIVAL_YEAR.value)
	if (arrival_year == 0) error_nodate = true

	arrival_month = 0
	if (form.ARRIVAL_MONTH.value == "Mar") {arrival_month =  2}
	if (form.ARRIVAL_MONTH.value == "Apr") {arrival_month =  3; if (arrival_day > 30) error = true}
	if (form.ARRIVAL_MONTH.value == "May") {arrival_month =  4}
	if (form.ARRIVAL_MONTH.value == "Jun") {arrival_month =  5; if (arrival_day > 30) error = true}
	if (form.ARRIVAL_MONTH.value == "Jul") {arrival_month =  6}
	if (form.ARRIVAL_MONTH.value == "Aug") {arrival_month =  7}
	if (form.ARRIVAL_MONTH.value == "Sep") {arrival_month =  8; if (arrival_day > 30) error = true}
	if (form.ARRIVAL_MONTH.value == "Oct") {arrival_month =  9}
	if (arrival_month == 0) error_nodate = true
	
	if (error_nodate) {window.alert("Arrival date not specified"); return}
	if (error) {window.alert("Invalid Date "+ arrival_day + " " + form.ARRIVAL_MONTH.value); return}
	
	arrival = new Date(arrival_year,arrival_month,arrival_day)

	//window.alert(arrival)
    
	// test for peak nights
	
	testday = new Date()
	testday = arrival
	//window.alert (testday)
	
	msperday = 60*60*24*1000
	peak_nights = 0;
	for (night=1; night<=nights; night++) {
		 //window.alert("Test day" + testday)
		// test months
		testday_is_peak = false
		if (testday.getMonth() == 6) testday_is_peak = true    // July
		if (testday.getMonth() == 7) testday_is_peak = true    // August
		// test BH weekends
		for (holiday=0; holiday<number_holidays; holiday++) {
//			window.alert ("Comparing " + testday + " with " + holidays[holiday])
//			window.alert ("testday time " + testday.getTime() + " holiday time " + holidays[holiday].getTime())
			testtime = testday.getTime()
			holidaytime = holidays[holiday].getTime()
			if (testtime == holidaytime) {
				testday_is_peak = true
//				window.alert("Holiday night" + testday)
			}
		}
		if (testday_is_peak) peak_nights++
		testday.setTime(testday.getTime() + msperday)  // advance testday by one day for next iteration
	}
	departure = new Date()
	departure = testday									// because last increment has set testday to departure date
	//window.alert("Peak nights " + peak_nights)
	//window.alert("Departure date " + departure)
	
	// pitches = form.PITCHES.value  Not using this yet.
	// pitches = 1
	// pitchnights = nights*pitches
   
    if (nights > 0) {
		if (form.PENSIONER.checked) {
			document.getElementById('PRICE_GRASS_NOELEC').innerHTML = '14.25' //using eval does not give last zero
			document.getElementById('PRICE_GRASS_ELEC').innerHTML = '17.50' 
			document.getElementById('PRICE_ALLWEATHER').innerHTML = '17.50'
			document.getElementById('PITCH_TYPE_TEXT').innerHTML = "PITCH TYPE - Over 65's concession prices"
			if (form.PITCH_TYPE[0].checked) {                 // no electricity
				total_price += nights*pensioner_price_noelec
			}
			else {
				total_price += nights*pensioner_price_elec
			}
		} 
		else {
			document.getElementById('PRICE_GRASS_NOELEC').innerHTML = '18.50'
			document.getElementById('PRICE_GRASS_ELEC').innerHTML = '22.50'
			document.getElementById('PRICE_ALLWEATHER').innerHTML = '22.95'
			document.getElementById('PITCH_TYPE_TEXT').innerHTML = 'PITCH TYPE - Standard prices'
			if (form.PITCH_TYPE[2].checked) total_price += nights*nights_price_allweather
			if (form.PITCH_TYPE[1].checked) total_price += nights*nights_price_grass_elec
			if (form.PITCH_TYPE[0].checked) total_price += nights*nights_price_grass_noelec
		}
		
		
		form.PEAK_NIGHTS.value = ""
		if (peak_nights > 0) {
			total_price += peak_nights*peak_supplement_price
			form.PEAK_NIGHTS.value = peak_nights
			if (form.PENSIONER.checked) {
				window.alert("The Over 65's concession is not available at peak times.")
				form.PENSIONER.checked = false
				// now subtract pensioner prices from total and add in standard prices
				if (form.PITCH_TYPE[0].checked) {                 // no electricity
					total_price -= nights*pensioner_price_noelec
				}
				else {
					total_price -= nights*pensioner_price_elec
				}
				if (form.PITCH_TYPE[2].checked) total_price += nights*nights_price_allweather
				if (form.PITCH_TYPE[1].checked) total_price += nights*nights_price_grass_elec
				if (form.PITCH_TYPE[0].checked) total_price += nights*nights_price_grass_noelec
				document.getElementById('PRICE_GRASS_NOELEC').innerHTML = '18.50'
				document.getElementById('PRICE_GRASS_ELEC').innerHTML = '22.50'
				document.getElementById('PRICE_ALLWEATHER').innerHTML = '22.95'
				document.getElementById('PITCH_TYPE_TEXT').innerHTML = 'PITCH TYPE - Standard prices'
			}
		}
		if (form.ADD_CAR.checked) total_price += nights*car_price
		if (form.ADD_TENT.checked) total_price += nights*tent_price
		if (form.GAZEBO.checked) total_price += nights*gazebo_price
  
		var adults_ind = form.ADD_ADULTS.selectedIndex
		var adults = parseInt(form.ADD_ADULTS.options[adults_ind].value)
		total_price += nights*adults*adults_price
	  
		var children_ind = form.ADD_CHILDREN.selectedIndex
		var children = parseInt(form.ADD_CHILDREN.options[children_ind].value)
		total_price += nights*children*children_price
	} 
	else {
		total_price = 0
	}
	
	pounds = Math.floor(total_price)
	pence = Math.floor(100*(total_price-pounds)+ 0.0001)
	form.TOTAL.value = pounds + "." + pence
}

