	//*************************
	//buyTicketsFor(icrm)
	//function to redirect the engine to stage 2 with the icrmid
	function buyTicketsFor(icrm){
		document.location = 'buy-tickets-online.asp?s=2&id=' + icrm;
	}
	//*************************
	
	//*************************	
	//calculateBooking()
	//function to calculate the cost of the booking, applying any discounts
	function calculateBooking(){
		
		
	
	}
	//*************************	
	
	//*************************	
	function checkDiscountCode(){

		$('DiscountCode').value = $('DisplayDiscountCode').value;
		if($('DiscountCode').value == ''){
			//code not entered
			alert('You must enter the Offer Code before clicking \'Update\'.');	
		}
		else {
			var discountCode = $('DiscountCode').value;
			discountCode = discountCode.toUpperCase()
			
			url = 'ajax/buy-tickets-online/check-discount-code.asp'
			
			new Ajax.Request(url,{
				method : 'post',
				parameters : $('frmBuyTicketsOnline').serialize(true),
				onSuccess:function(transport){
					//$('DisplayTickets').innerHTML = transport.responseText;
					$('TicketSelection').replace(transport.responseText);	
				},
				onFailure:function(transport){
					alert(transport.responseText);	
				}							 
							 
			});
			
		}
	}	
	//*************************		
	
	
	
	
	//*************************
	//calculateTicketSelection()
	//function to calculate the values for the ticket selection
	function calculateTicketSelection(){
	
		//declare variables
		totalValue = 0;
		groupDiscountA = 0;
		groupDiscountB = 0;
		groupDiscountC = 0;
		groupDiscountPrice = 0;
		groupDiscountQuantity = 0;
		groupDiscountLineValue = 0;
	
		//tickets
		for(i=1;i<11;i++){
			
			//make sure stri is 2 characters long
			stri = (i<10) ? '0' + i : i;
			
			//check there's an object for price and quantity
			if($('Ticket' + stri + 'Price') && $('Ticket' + stri + 'Quantity')){
				thisPrice = Number($F('Ticket' + stri + 'Price'));
				thisQuantity = Number($F('Ticket' + stri + 'Quantity'));
				thisLineValue = Number(thisPrice * thisQuantity).toFixed(2);
				
				//set the lineValue
				$('Ticket' + stri + 'LineValue').innerHTML = '&pound;' + thisLineValue;
								
				//add the line value to the total value
				totalValue+= Number(thisLineValue);
			}		
		
			//check for group discount (only available to Ticket01)
			if(i==1){
				if($('Ticket01Price') && $('Ticket01Quantity')){
				
					//get the quantity of tickets
					thisQuantity = $F('Ticket01Quantity');
					
					//create three values for the group discount levels
					groupDiscountLevelA = $('GroupDiscountLevelA').value;
					groupDiscountValueA = $('GroupDiscountValueA').value;
					groupDiscountLevelB = $('GroupDiscountLevelB').value;
					groupDiscountValueB = $('GroupDiscountValueB').value;
					groupDiscountLevelC = $('GroupDiscountLevelC').value;
					groupDiscountValueC = $('GroupDiscountValueC').value;
					
					//calculate groupDiscountA
					if(!isNaN(groupDiscountLevelA) && !isNaN(groupDiscountValueA)){
						if(Number(thisQuantity) >= Number(groupDiscountLevelA)){
							groupDiscountA = Number(groupDiscountValueA) * Number(thisQuantity);
						}
					}
					
					//calculate groupDiscountB
					if(!isNaN(groupDiscountLevelB) && !isNaN(groupDiscountValueB)){
						if(Number(thisQuantity) >= Number(groupDiscountLevelB)){
							groupDiscountB = Number(groupDiscountValueB) * Number(thisQuantity);
						}
					}				
									
					//calculate groupDiscountC
					if(!isNaN(groupDiscountLevelC) && !isNaN(groupDiscountValueC)){
						if(Number(thisQuantity) >= Number(groupDiscountLevelC)){
							groupDiscountC = Number(groupDiscountValueC) * Number(thisQuantity);
						}
					}
					
					//get the highest discount
					maxDiscount = Math.max(groupDiscountA,groupDiscountB,groupDiscountC);
					
					if(maxDiscount > 0){
						if(maxDiscount==groupDiscountA){
							groupDiscountPrice = Number(groupDiscountValueA);
							groupDiscountQuantity = thisQuantity;
							groupDiscountLineValue = groupDiscountA
						} else if(maxDiscount==groupDiscountB){
							groupDiscountPrice = Number(groupDiscountValueB);
							groupDiscountQuantity = thisQuantity;
							groupDiscountLineValue = groupDiscountB;
						} else if(maxDiscount==groupDiscountC){
							groupDiscountPrice = Number(groupDiscountValueC);
							groupDiscountQuantity = thisQuantity;
							groupDiscountLineValue = groupDiscountC;
						}
					}
					
					//set the value
					$('GroupDiscountPrice').innerHTML = '&pound;' + Number(groupDiscountPrice).toFixed(2);
					$('GroupDiscountQuantity').innerHTML = Number(groupDiscountQuantity);
					$('GroupDiscountLineValue').innerHTML = '-&pound;' + Number(groupDiscountLineValue).toFixed(2);
					
					//show/hide the row
					if(groupDiscountLineValue > 0){
						$('GroupDiscountRow').show();
					} else {
						$('GroupDiscountRow').hide();
					}
					
					//remove fromt the total value
					totalValue -= Number(groupDiscountLineValue);
				}	
			}
		}
		
		//picnic tables for 4 as package
		if($('Picnic04Price') && $('Picnic04Quantity')){
			thisPrice = Number($F('Picnic04Price'));
			thisQuantity = Number($F('Picnic04Quantity'));
			thisLineValue = Number(thisPrice * thisQuantity).toFixed(2);
			
			//set the lineValue
			$('Picnic04LineValue').innerHTML = '&pound;' + thisLineValue;
							
			//add the line value to the total value
			totalValue+= Number(thisLineValue);
		}

		
		//picnic tables for 6 as package
		if($('Picnic06Price') && $('Picnic06Quantity')){
			thisPrice = Number($F('Picnic06Price'));
			thisQuantity = Number($F('Picnic06Quantity'));
			thisLineValue = Number(thisPrice * thisQuantity).toFixed(2);
			
			//set the lineValue
			$('Picnic06LineValue').innerHTML = '&pound;' + thisLineValue;
							
			//add the line value to the total value
			totalValue+= Number(thisLineValue);
		}
		
		//trackside bar tables for 4 as package
		if($('TracksideBar04Price') && $('TracksideBar04Quantity')){
			thisPrice = Number($F('TracksideBar04Price'));
			thisQuantity = Number($F('TracksideBar04Quantity'));
			thisLineValue = Number(thisPrice * thisQuantity).toFixed(2);
			
			//set the lineValue
			$('TracksideBar04LineValue').innerHTML = '&pound;' + thisLineValue;
							
			//add the line value to the total value
			totalValue+= Number(thisLineValue);
		}

			
		//packages
		for(i=65;i<71;i++){
		
			//get the character from the character code (i)
			stri = String.fromCharCode(i);
			
			//check there's an object for price and quantity
			if($('Package' + stri + 'Price') && $('Package' + stri + 'Quantity')){
				thisPrice = Number($F('Package' + stri + 'Price'));
				thisQuantity = Number($F('Package' + stri + 'Quantity'));
				thisLineValue = Number(thisPrice * thisQuantity).toFixed(2);
				
				//set the lineValue
				$('Package' + stri + 'LineValue').innerHTML = '&pound;' + thisLineValue;
								
				//add the line value to the total value
				totalValue+= Number(thisLineValue);
			}				
		
		}
		
		
		//picnic tables for 4 as add on
		if($('PicnicAddOn04Price') && $('PicnicAddOn04Quantity')){
			thisPrice = Number($F('PicnicAddOn04Price'));
			thisQuantity = Number($F('PicnicAddOn04Quantity'));
			thisLineValue = Number(thisPrice * thisQuantity).toFixed(2);
			
			//set the lineValue
			$('PicnicAddOn04LineValue').innerHTML = '&pound;' + thisLineValue;
							
			//add the line value to the total value
			totalValue+= Number(thisLineValue);
		}

		
		//picnic tables for 6 as add on
		if($('PicnicAddOn06Price') && $('PicnicAddOn06Quantity')){
			thisPrice = Number($F('PicnicAddOn06Price'));
			thisQuantity = Number($F('PicnicAddOn06Quantity'));
			thisLineValue = Number(thisPrice * thisQuantity).toFixed(2);
			
			//set the lineValue
			$('PicnicAddOn06LineValue').innerHTML = '&pound;' + thisLineValue;
							
			//add the line value to the total value
			totalValue+= Number(thisLineValue);
		}

		
		
		//set the totalValue
		$('TicketSelectionTotalValue').innerHTML = '&pound;' + Number(totalValue).toFixed(2);
		
	
	}	
	//*************************
	
	
	//*************************
	//ticketsSelected()
	//function called when the continue button is pressed on the ticket selection screen
	function ticketsSelected(){
	
		//first, recalculate the tickets selected to make sure the price is correct
		calculateTicketSelection();
		
		//check at least one ticket is selected
		totalQuantity = 0;
		$$('#frmTicketSelection select').each(function(item){
			if(!item.hasClassName('addOn')){
				totalQuantity += Number(item.value);
			}
		});
		
		if(totalQuantity > 0){
			$('frmTicketSelection').submit();		
		} else {
			alert('Please select a ticket before clicking \'Continue\'.  ');
		}
	
	}
	//*************************
	
	
	//*************************
	//paymentDetailsEntered();
	//function to call when the continue button is clicked after
	//the customer details and payment details have been entered
	function paymentDetailsEntered(){
	
		//reset the error variables	
		errorCount 		= 0;
		errorList 		= '';
		errorMessage 	= '';
	
		//title
		if($F('Title') == ''){
			errorList += '\n- \'Title\' is a required field.  ';
			errorCount ++;
		}
		
		//forename
		if($F('Forename') == ''){
			errorList += '\n- \'Forename\' is a required field.  ';
			errorCount ++;
		}
		
		//surname
		if($F('Surname') == ''){
			errorList += '\n- \'Surname\' is a required field.  ';
			errorCount ++;
		}
		
		//address1
		if($F('Address1') == ''){
			errorList += '\n- The first line of your address is a required field.  ';
			errorCount ++;
		}
		
		//postcode
		if($F('Postcode') == ''){
			errorList += '\n- \'Postcode\' is a required field.  ';
			errorCount ++;
		}
		
		//telephone,mobile,fax
		if($F('Telephone') == '' && $F('Mobile') == '' && $F('Fax') == ''){
			errorList += '\n- You must enter at least one contact number in the fields provided.  ';
			errorCount ++;
		}
		
		//email
		if($F('Email') == ''){
			errorList += '\n- \'Email\' is a required field.  ';
			errorCount ++;
		} else {
			email = String($F('Email'));
			
			if(email.indexOf('@')==-1 || email.length < 5 || email.indexOf('.') == -1){
				errorList += '\n- You must enter a valid email address.  ';
				errorCount ++;
			}
			
			if($F('Email')!= $F('EmailCheck')){
				errorList += '\n- The email address in \'Email\' and \'Re-Type Your Email\' does not match.  ';
				errorCount++;
			}
			
			
		}
		
		if($('CardType')){
			//card type
			if($F('CardType') == ''){
				errorList += '\n- You must select the type of card you wish to pay with.  ';
				errorCount ++;		
			}
			
			//cardholder name
			if($F('CardholderName') == ''){
				errorList += '\n- You must enter the name as it appears on the card.  ';
				errorCount ++;		
			}
			
			//card number
			if($F('CardNumber') == ''){
				errorList += '\n- You must enter the card number.  ';
				errorCount ++;		
			}
			
			//card expiry
			if($F('ExpiryDateMonth') == '' || $F('ExpiryDateYear') == ''){
				errorList += '\n- You must select the expiry date of the card.  ';
				errorCount ++;		
			}
			
			//card cvc
			if($F('CVCNumber') == ''){
				errorList += '\n- You must enter the CVC Number that appears on the card.  ';
				errorCount ++;		
			}
		}
		
		if($('AcceptTANDC').checked==false){
			errorList += '\n- You must check the box to indicate that you\n  accept the Musselburgh Racecourse Terms and Conditions of Entry.  ';
			errorCount ++;		
		}
		
		if(errorCount==0){
			$('frmBuyTicketsOnline').submit();
		} else if(errorCount==1){
			errorMessage = 'The following error has occurred -  \n';
			errorMessage += errorList;
			errorMessage +='\n\nPlease correct this error before clicking \'Continue\'.  ';
			alert(errorMessage);		
		} else {
			errorMessage = 'The following errors have occurred -  \n';
			errorMessage += errorList;
			errorMessage +='\n\nPlease correct these errors before clicking \'Continue\'.  ';
			alert(errorMessage);
		}
	}
	//*************************

