// JavaScript Document

function calcForm(form) {
    nights_price = 11.00				//caravan, motorhome +2
    nights_priceTent = 12.00			//car, tent +2
    nights_priceTentSmall = 10.00			//small tent +2
	peak_supplement_price = 2.00	
	adults_price = 2.00
	children_price = 1.00
	car_price = 1.00
	dog_price = 0.50
	tent_price = 4.00
	awning_price = 1.00
	gazebo_price = 3.00
	elec_price = 3.00
	visitor_price = 1.00
	tent_surcharge = 3.00
	total_price = 0.0
    
	nights = form.nights.value
	nightsTents = form.nightsTents.value
	nightsTentsSmall = form.nightsTentsSmall.value


	if ( parseInt(nights) > 0 ){
		form.nightsTents.value = 0
		total_price = 0
   		total_price += nights * nights_price
	
			if (form.PEAK_SUPPLEMENT.checked){
				total_price += nights * peak_supplement_price
			}
			if (form.ADD_CAR.checked){
				total_price += nights * car_price
			}
			if (form.EXTENDED_AWNING.checked) {
				total_price += nights * awning_price 
			}
			if (form.ADD_GAZEBO.checked){
				total_price += nights * gazebo_price
			}
			if (form.ADD_SUR.checked){
				total_price += nights * tent_surcharge 
			}
			if (form.ELEC.checked){
				total_price += nights * elec_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

			var visitors_ind = form.ADD_DAY_VISITORS.selectedIndex
			var visitors = parseInt(form.ADD_DAY_VISITORS.options[visitors_ind].value)
				total_price += nights * visitors * visitor_price

			var dog_ind = form.ADD_DOG.selectedIndex
			var dogs = parseInt(form.ADD_DOG.options[dog_ind].value)
				total_price += nights * dogs * dog_price	
	
	}else if( parseInt(nightsTents) > 0 ){
		form.nights.value = 0
		form.nightsTentsSmall.value = 0		
		total_price = 0	
		total_price += nightsTents * nights_priceTent
	
		if (form.PEAK_SUPPLEMENT.checked){
			total_price += nightsTents * peak_supplement_price
		}
		if (form.ADD_CAR.checked){
			total_price += nightsTents * car_price
		}
		if (form.EXTENDED_AWNING.checked){
			total_price += nightsTents * awning_price
		}
		if (form.ADD_GAZEBO.checked){
			total_price += nightsTents * gazebo_price
		}
		if (form.ADD_SUR.checked){
			total_price += nightsTents * tent_surcharge
		}
		if (form.ELEC.checked){
			total_price += nightsTents * elec_price
		}
			var adults_ind = form.ADD_ADULTS.selectedIndex
			var adults = parseInt(form.ADD_ADULTS.options[adults_ind].value)
				total_price += nightsTents * adults * adults_price
						
			var children_ind = form.ADD_CHILDREN.selectedIndex
			var children = parseInt(form.ADD_CHILDREN.options[children_ind].value)
				total_price += nightsTents * children * children_price

			var visitors_ind = form.ADD_DAY_VISITORS.selectedIndex
			var visitors = parseInt(form.ADD_DAY_VISITORS.options[visitors_ind].value)
				total_price += nightsTents * visitors * visitor_price

			var dog_ind = form.ADD_DOG.selectedIndex
			var dogs = parseInt(form.ADD_DOG.options[dog_ind].value)
				total_price += nightsTents * dogs * dog_price	
	
	}else if( parseInt(nightsTentsSmall) > 0 ){
		form.nights.value = 0
		form.nightsTents.value = 0
		total_price = 0	
		total_price += nightsTentsSmall * nights_priceTentSmall
	
		if (form.PEAK_SUPPLEMENT.checked){
			total_price += nightsTentsSmall * peak_supplement_price
		}
		if (form.ADD_CAR.checked){
			total_price += nightsTentsSmall * car_price
		}
		if (form.EXTENDED_AWNING.checked){
			total_price += nightsTentsSmall * awning_price
		}
		if (form.ADD_GAZEBO.checked){
			total_price += nightsTentsSmall * gazebo_price
		}
		if (form.ADD_SUR.checked){
			total_price += nightsTentsSmall * tent_surcharge
		}
		if (form.ELEC.checked){
			total_price += nightsTentsSmall * elec_price
		}
			var adults_ind = form.ADD_ADULTS.selectedIndex
			var adults = parseInt(form.ADD_ADULTS.options[adults_ind].value)
				total_price += nightsTentsSmall * adults * adults_price
						
			var children_ind = form.ADD_CHILDREN.selectedIndex
			var children = parseInt(form.ADD_CHILDREN.options[children_ind].value)
				total_price += nightsTentsSmall * children * children_price

			var visitors_ind = form.ADD_DAY_VISITORS.selectedIndex
			var visitors = parseInt(form.ADD_DAY_VISITORS.options[visitors_ind].value)
				total_price += nightsTentsSmall * visitors * visitor_price

			var dog_ind = form.ADD_DOG.selectedIndex
			var dogs = parseInt(form.ADD_DOG.options[dog_ind].value)
				total_price += nightsTentsSmall * dogs * dog_price	
	} else {
		total_price = 0.00
	}
		
		pounds = Math.floor(total_price)
		pence = Math.floor(100*(total_price - pounds) + 0.0001)
	
		if(pence == 0){
			form.total.value = pounds + "." + pence + "0"
		}else{
			form.total.value = pounds + "." + pence
		}		


}

//show-hide elements
function showCaravan(){
	var caravan = document.getElementById('caravan');
	var tent = document.getElementById('tent').style;
	var tentSmall = document.getElementById('tentSmall').style;
	
		caravan.style.display='block';
		total_price = 0.00
		document.form.total.value = 0.00
	
	tent.display='none';
	tentSmall.display='none';	
	document.form.nightsTents.value = 0
	document.form.nightsTentsSmall.value = 0
}
function showTents(){
	var caravan = document.getElementById('caravan').style;
	var tent = document.getElementById('tent');
	var tentSmall = document.getElementById('tentSmall').style;

		tent.style.display='block';
		total_price = 0.00
		document.form.total.value = 0.00
	
	caravan.display='none';
	tentSmall.display='none';
	document.form.nights.value = 0
	document.form.nightsTentsSmall.value = 0
}
function showTentsSmall(){
	var caravan = document.getElementById('caravan').style;
	var tent = document.getElementById('tent').style;
	var tentSmall = document.getElementById('tentSmall');

		tentSmall.style.display='block';
		total_price = 0.00
		document.form.total.value = 0.00
	
	caravan.display='none';
	tent.display='none';	
	document.form.nights.value = 0
	document.form.nightsTents.value = 0	
}

