// global

var accommodaton=0;

// hides the fields when the CPD Approval form loads
function hideDivs() {
	document.getElementById("d11").style.display = 'none';
	document.getElementById("d12").style.display = 'none';
	document.getElementById("d13").style.display = 'none';
	document.getElementById("d14").style.display = 'none';
	document.getElementById("d15").style.display = 'none';
	document.getElementById("d16").style.display = 'none';
	document.getElementById("d17").style.display = 'none';
	document.getElementById("d100").style.display = 'none';
	document.getElementById("d110").style.display = 'none';
}

//  displays / hides the fields based on
//  selection of the TypeSelect radio buttons
function checkARtype(val) {

	// Get the radio buttons and act on the value
	v = radio_active(document.BookingForm.AccommodationRequired);
	if (v==1) {
		// show the fields formation
		document.getElementById("d12").style.display = 'none';
		document.getElementById("d100").style.display = 'none';
		document.getElementById("d110").style.display = 'none';
		document.getElementById("d11").style.display = 'block';
		document.getElementById("d13").style.display = 'block';
		document.getElementById("d15").style.display = 'block';
	}
	else if(v==0) {
		// hide the fields
		document.getElementById("d11").style.display = 'none';
		document.getElementById("d12").style.display = 'block';
		document.getElementById("d13").style.display = 'block';
		document.getElementById("d100").style.display = 'block';
		document.getElementById("d110").style.display = 'block';

	}

	// we blank various fields whenever the user decides
	// to change their accommodation/no accommodation choice.

	// blank the cost field
	document.BookingForm.TotalCost.value = "0.00";

	// blank the Price field
	for(counter=0; counter < document.BookingForm.Price.length; counter++) {
		document.BookingForm.Price[counter].checked = false;
	}
	
	// blank the days fields
	for(counter=0; counter < document.BookingForm.Days.length; counter++) {
		document.BookingForm.Days[counter].checked = false;
	}


	// cost display
	document.getElementById("d17").innerHTML='';

	// end 
	// document.getElementById('d11').focus();
}

function Mealblock(val) {

	// Get the radio buttons and act on the value
	v = radio_active(document.BookingForm.EveningMeal);

	if (v==0) {
		// show the fields formation
		document.getElementById("d110").style.display = 'none';
	}
	else if(v==1) {
		// hide the fields
		document.getElementById("d110").style.display = 'block';

	}

	// blank the meal days fields
	for(counter=0; counter < document.BookingForm.Meals.length; counter++) {
		document.BookingForm.Meals[counter].checked = false;
	}

	showCost();
}

function showCost(val) {
	var v=0;
	var cost=0;
	var d1=0,d2=0,d3=0;
	var m1=0,m2=0,m3=0;

	// fixed prices for non-accommodation
	// change here
	var Sat=80;
	var Sun=80;
	var Mon=50;
	var Meal=20;

	// check which days the person will be walking on
	for(counter=0; counter < document.BookingForm.Days.length; counter++) {
		if(document.BookingForm.Days[counter].checked) {
			v += document.BookingForm.Days[counter].value;
			if(counter == 0){ d1=1};
			if(counter == 1){ d2=1};
			if(counter == 2){ d3=1};
		}
	}

	for(counter=0; counter < document.BookingForm.Meals.length; counter++) {
		if(document.BookingForm.Meals[counter].checked) {
			v += document.BookingForm.Days[counter].value;
			if(counter == 0){ m1=1};
			if(counter == 1){ m2=1};
			if(counter == 2){ m3=1};
		}
	}
	// get the price and work the cost
	v = radio_active(document.BookingForm.AccommodationRequired);

	if(v == 1) {  // accommodation required
		var Price = radio_active(document.BookingForm.Price);
		if(Price == 1) { Price = 150 };
		if(Price == 2) { Price = 140 };
		if(Price == 3) { Price = 125 };
		if(Price == 4) { Price = 125 };
		cost = d1 * Price + d2 * Price + d3 * Price;
	}
	else if( v == 0) {  // price is set for the no accommodation people

		cost = d1 * Sat + d2 * Sun + d3 * Mon + m1 * Meal + m2 * Meal + m3 * Meal;
	}
	if( cost < 0 ) {cost = "0.00"}
	else { 
		document.getElementById("d17").innerHTML = "<h1>Total to pay: $" + cost + ".00" + "</h1><blockquote></blockquote>";
	document.getElementById("d17").style.display='block';
	}


	document.BookingForm.TotalCost.value=cost;
	document.getElementById("d14").style.display='none';
	document.getElementById('14').focus();
}

// returns the value of the radio button group 
 function radio_active(radio_group) {
     // Run through the group
     for (counter = 0; counter < radio_group.length; counter++) {
         // When we find the activated button, return the index
         if (radio_group[counter].checked) {
             return radio_group[counter].value;
         }
     }
     // If no button is activated, return -1
     return -1
}




