		/* FUNCTIONS FOR THE ASYNC FLIGHT LIVE PRICE */
		var pound_sign = '\u00A3';
		//var num_accomm_link_ids = new Array();
		var accomm_links = new Array();
		var async_flight_ready = true;
		
		function check_async_ready()
		{
			if (async_flight_ready)
			{
				return true;
			}
			else
			{
				alert('Please wait while the prices are loading.');
				return false;
			}
		}
		
		function get_flight_async(basket_state_id, search_id, quote_id, supplier_code, number_of_pax, flight_departure_date) // quote_id, NumberOfPax)
		{
			async_flight_ready = false;
			
			var xmlhttp = new createXMLHttpRequest;
			xmlhttp.onreadystatechange=function() 
			{
				if (xmlhttp.readyState == 4  && xmlhttp.status == 200) 
				{ 
					var content = xmlhttp.responseXML;
					var root = content.documentElement;
					var flight_price_pence;
					var basket_state_id;
					
					if(!root || root.nodeName == 'Errors' || !root.hasChildNodes())
					{
						alert('Sorry, we were unable to contact the airline to confirm that flight.\nPress OK to go back to the Flight Results page.');
						redirectToFlightResults();
						return;
					}
					
					if(root.hasChildNodes()) 
					{
						nds=root.childNodes;
						var len = nds.length;
						var total = 0;
						for (var i = 0; i < len; i++)
						{	
							
							if(nds[i].nodeName == 'PriceTemplate')
							{
								document.getElementById('basket_price_column').innerHTML = nds[i].firstChild.data;
							}
							else if(nds[i].nodeName == 'TotalFlightPricePence')
							{
								flight_price_pence = nds[i].firstChild.data;
							}
							else if(nds[i].nodeName == 'BasketStateId')
							{
								basket_state_id = nds[i].firstChild.data;
							}
							else if (nds[i].nodeName == 'Errors')
							{
								alert('Unfortunately, the flight you selected is no longer available.\nPress OK to go back to the Flight Results page.');
//								setTimeout("redirectToFlightResults()",5000);
								redirectToFlightResults();
								return;
							}
						}
						
						async_flight_ready = true;
						updateTotalHoliday(flight_price_pence, number_of_pax, basket_state_id);
					}
				}
			}
			//var hash = getUrlVars();
			//var itinerary_id = hash['itinerary_id'];
			//var url = '/fetch_opts.php?noint=1&mode=async_flight&quote_id=' + quote_id;
			var url = '/fetch_opts.php?noint=1&mode=update_basket&search_id=' + search_id
				+ '&departure=' + flight_departure_date
				+ '&basket_state_id=new'
				+ '&modify_basket[FLIGHT][_action]=replace'
				+ '&modify_basket[FLIGHT][_supplier]=MTC'
				+ '&modify_basket[FLIGHT][_type]=flight'
				+ '&modify_basket[FLIGHT][quote_id]=' + quote_id
				+ '&modify_basket[FLIGHT][supplier_code]=' + supplier_code;
			xmlhttp.open('GET', url, true);
			xmlhttp.send(null)
			return;
		}
		
		function getUrlVars()
		{
			var vars = [], hash;
			var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
		
			for(var i = 0; i < hashes.length; i++)
			{
				hash = hashes[i].split('=');
				vars.push(hash[0]);
				vars[hash[0]] = hash[1];
			}
			return vars;
		}
		
		function redirectToFlightResults(url)
		{
			window.location.href = flight_results_url;
			//return;
//			if(!url)
//			{
//				var urlPart = getUrlVars();
//				var packagetype = urlPart['packagetype'];
//				var departure = urlPart['departure']; 
//				var arrival = urlPart['arrival'];
//				var duration = urlPart['duration'];
//				var airporttocode = urlPart['airporttocode'];
//				var airportfromcode = urlPart['airportfromcode'];
//				var noint = urlPart['noint'];
//				
//				window.location.href = '/packagetype='+packagetype+'&departure='+departure+'&arrival='+arrival+'&duration='+duration+'&airporttocode='+airporttocode+'&airportfromcode='+airportfromcode+'&depvariance='+3
//			}
//			else
//			{
//				window.location.href = url;	
//			}
		}
		
		// Updates the Total Holiday (looping through the accommodation units and adding the total to the accom price) 
		function updateTotalHoliday(flight_price_pence, NumberOfPax, basket_state_id)
		{
			var accomm_price_pence;
			var holiday_price_pounds;
			for (var hotel_num = 1; document.getElementById('accomm_per_person_price_'+hotel_num+'_1'); hotel_num++)
			{
				for (hotel_room_type_num = 1; document.getElementById('accomm_per_person_price_'+hotel_num+'_'+hotel_room_type_num); hotel_room_type_num++)
				{
					accomm_per_person_price_pence = document.getElementById('accomm_per_person_price_'+hotel_num+'_'+hotel_room_type_num).value * 1;
					holiday_price_pounds = ( (parseInt(accomm_per_person_price_pence) + (parseInt(flight_price_pence) / NumberOfPax)) / 100).toFixed(2);
					document.getElementById('total_cost_text_live_price_'+hotel_num+'_'+hotel_room_type_num).innerText = pound_sign + holiday_price_pounds; // IE
					document.getElementById('total_cost_text_live_price_'+hotel_num+'_'+hotel_room_type_num).textContent = pound_sign + holiday_price_pounds; // Everyone else
					document.getElementById('accomm_link_'+hotel_num+'_'+hotel_room_type_num).action = accomm_links[hotel_num+'_'+hotel_room_type_num] + '&basket_state_id='+basket_state_id; // Everyone else
				}
			}
		}