// epperston.js

	//calculateEpperstonValue()
	//This function calculates and updates all totals
	function calculateEpperstonValue(){
		
		//declare variables
		var adulttotal,childtotal,tote2total,tote5total,tote10total,totalvalue;
		var champagnetotal,royalglasstotal,roseglasstotal,royalbottletotal,rosebottletotal;
		var	vintagetotal,cuveelouisetotal,popbottletotal,pinkbottletotal,royalmagnumtotal;


		//declare variables and assign values
		var adultPrice 	= document.getElementById("AdultPrice").value; 
		var adultQty	= document.getElementById("AdultQty").value;
		var childPrice 	= document.getElementById("ChildPrice").value;
		var childQty 	= document.getElementById("ChildQty").value;

		var tote2Qty  	= document.getElementById("ToteVoucher2").value;
		var tote5Qty  	= document.getElementById("ToteVoucher5").value;
		var tote10Qty  	= document.getElementById("ToteVoucher10").value;


		var	royalglassPrice  = document.getElementById("BrutRoyalGlassPrice").value;
		var	royalglassQty 	 = document.getElementById("BrutRoyalGlass").value;

		var	roseglassPrice   = document.getElementById("BrutRoseGlassPrice").value;
		var	roseglassQty  	 = document.getElementById("BrutRoseGlass").value;
		
		var	royalbottlePrice = document.getElementById("BrutRoyalBottlePrice").value;
		var	royalbottleQty	 = document.getElementById("BrutRoyalBottle").value;
		
		var	rosebottlePrice  = document.getElementById("BrutRoseBottlePrice").value;
		var	rosebottleQty  	 = document.getElementById("BrutRoseBottle").value;
		
		var	vintagePrice	 = document.getElementById("VintageBottlePrice").value;
		var	vintageQty	  	 = document.getElementById("VintageBottle").value;
		
		var	cuveelouisePrice = document.getElementById("CuveeLouiseBottlePrice").value;
		var	cuveelouiseQty 	 = document.getElementById("CuveeLouiseBottle").value;
		
		var	popbottlePrice   = document.getElementById("POPBottlePrice").value;
		var	popbottleQty  	 = document.getElementById("POPBottle").value;
		
		var	pinkbottlePrice	 = document.getElementById("PinkPOPBottlePrice").value;
		var	pinkbottleQty	 = document.getElementById("PinkPOPBottle").value;
		
		var	royalmagnumPrice = document.getElementById("BrutRoyalMagnumPrice").value;
		var	royalmagnumQty 	 = document.getElementById("BrutRoyalMagnum").value;



		//calculate totals
		adulttotal = adultPrice * adultQty;
		childtotal = childPrice * childQty;
		
		tote2total 	= 2 * tote2Qty;
		tote5total 	= 5 * tote5Qty;
		tote10total	= 10 * tote10Qty;
		
		royalglasstotal	 = royalglassPrice * royalglassQty;
		roseglasstotal	 = roseglassPrice * roseglassQty;
		royalbottletotal = royalbottlePrice * royalbottleQty;
		rosebottletotal	 = rosebottlePrice * rosebottleQty;
		vintagetotal	 = vintagePrice * vintageQty;
		cuveelouisetotal = cuveelouisePrice * cuveelouiseQty;
		popbottletotal 	 = popbottlePrice * popbottleQty;
		pinkbottletotal	 = pinkbottlePrice * pinkbottleQty;
		royalmagnumtotal = royalmagnumPrice * royalmagnumQty;

		//champagne total
		champagnetotal = royalglasstotal + roseglasstotal + royalbottletotal + rosebottletotal + vintagetotal;
		champagnetotal = champagnetotal + cuveelouisetotal + popbottletotal + pinkbottletotal + royalmagnumtotal;
		
		//total value
		totalvalue = adulttotal + childtotal + tote2total + tote5total + tote10total + champagnetotal;

		
		
		//update the html
		document.getElementById("AdultValue").innerHTML = "&pound;" + adulttotal.toFixed(2);	
		document.getElementById("ChildValue").innerHTML = "&pound;" + childtotal.toFixed(2);	
	
		document.getElementById("ToteVoucher2Value").innerHTML = "&pound;" + tote2total.toFixed(2);	
		document.getElementById("ToteVoucher5Value").innerHTML = "&pound;" + tote5total.toFixed(2);	
		document.getElementById("ToteVoucher10Value").innerHTML = "&pound;" + tote10total.toFixed(2);	

		document.getElementById("BrutRoyalGlassValue").innerHTML = "&pound;" + royalglasstotal.toFixed(2);
		document.getElementById("BrutRoseGlassValue").innerHTML = "&pound;" + roseglasstotal.toFixed(2);
		document.getElementById("BrutRoyalBottleValue").innerHTML = "&pound;" + royalbottletotal.toFixed(2);
		document.getElementById("BrutRoseBottleValue").innerHTML = "&pound;" + rosebottletotal.toFixed(2);
		document.getElementById("VintageBottleValue").innerHTML = "&pound;" + vintagetotal.toFixed(2);
		document.getElementById("CuveeLouiseBottleValue").innerHTML	= "&pound;" + cuveelouisetotal.toFixed(2);
		document.getElementById("POPBottleValue").innerHTML = "&pound;" + popbottletotal.toFixed(2);
		document.getElementById("PinkPOPBottleValue").innerHTML = "&pound;" + pinkbottletotal.toFixed(2);
		document.getElementById("BrutRoyalMagnumValue").innerHTML = "&pound;" + royalmagnumtotal.toFixed(2);

		document.getElementById("TotalValue").innerHTML = "&pound;" + totalvalue.toFixed(2);	

	}
	



	//validateTimeSelection()
	//This function checks that a time slot has been selected
	function validateTimeSelection(){

		//get the number of slots available
		timeSlotCount = document.getElementById("TimeSlotCount").value;
		timeSlotFound = false;
		
		for(i=0;i<timeSlotCount;i++){
			if(document.getElementById("TimeSlot-" + i).checked){
				timeSlotFound = true;	
			}
		}

		if(timeSlotFound == false){
			alert("Sorry, you must select a time slot to continue.");
			return false;
		} 
		else {
			return true;	
		}

	}
	
	


	//*************************
	//validateTicketSelection();
	//function to check the number of tickets selected...
	function validatePackageSelection(){

		//initialise the error vars
		errorList 	  = "";
		errorCount 	  = 0;
		errorMessage  = "";

		//get the values
		adultQty = Number(selectValues("AdultQty","value"));
		childQty = Number(selectValues("ChildQty","value"));
	
		totalQty = adultQty + childQty; 
	
		checknum = checkNumberSelected(totalQty);
		
		//is there at least 1 adult ticket?
		if(adultQty == 0){
			errorList 	+= "Sorry, you must select at least 1 adult ticket to continue."; 
			errorCount 	+= 1;
			errorMessage = errorList;
			alert(errorMessage);
			return false;
		} 
		else if(checknum != true){
			alert(checknum);
			return false;
		}
		else {
			return true;	
		}
	
	}	

	//checkNumberSelected(total,maximum,available);
	//function to check the number of tickets selected...
	function checkNumberSelected(totalQty){

		maximum = Number(document.getElementById("MaxNumber").value);
		available = Number(document.getElementById("NumberAvailable").value);

		//more than maximum number places
		if(available > maximum && totalQty > maximum){
			return "Sorry you can only book a maximum of " + maximum + " places.";
		}
		else if(maximum > available && totalQty > available){
			return "Sorry you can only book a maximum of " + available + " places.";
		}
		else {
			return true;
		}
	}
	//*************************
	
	
	
	//*************************
	//validateBistroSelection();
	//function to check the number of tickets selected...
	function validateBistroSelection(){

		//initialise the error vars
		errorList 	  = "";
		errorCount 	  = 0;
		errorMessage  = "";

		//get the values
		adultQty = Number(selectValues("AdultQty","value"));
		childQty = Number(selectValues("ChildQty","value"));
		available = Number(document.getElementById("NumberAvailable").value);
	
		totalQty = adultQty + childQty; 
	
		//is there at least 1 adult ticket?
		if(adultQty == 0){
			errorList 	+= "Sorry, you must select at least 1 adult ticket to continue."; 
			errorCount 	+= 1;
			errorMessage = errorList;
			alert(errorMessage);
			return false;
		} 
		else if(totalQty > available){
			alert("Sorry, there are only " + available + " bistro tickets available.");
			return false;
		}
		else {
			return true;	
		}
	
	}	



	