		/* FUNCTIONS FOR THE ASYNC FLIGHT LIVE PRICE */
		var pound_sign = '\u00A3';
			
		function get_flight_async(quote_id, NumberOfPax)
		{
			var xmlhttp = new createXMLHttpRequest;
			xmlhttp.onreadystatechange=function() 
			{
				if (xmlhttp.readyState == 4  && xmlhttp.status == 200) 
				{ 
					var content = xmlhttp.responseXML;
					var root = content.documentElement;
					
					if(!root || root.nodeName == 'Errors' || !root.hasChildNodes())
					{
						alert('Unfortunately, the flight you selected is no longer available.\nPress OK to go back to the Flight Results page.');
						setTimeout("redirectToFlightResults('" + root.getAttribute("ReturnURL") + "')",1000);
						return;
					}
					
					for (var i = document.getElementById('price_breakdown_live_price').rows.length - 1; i >= 0; i--)
					{
						document.getElementById('price_breakdown_live_price').tBodies[0].deleteRow(i);
					}
						
					if(root.hasChildNodes()) 
					{
						nds=root.childNodes;
						var len = nds.length;
						var total = 0;
						for (var i = 0; i < len; i++)
						{	
							if(nds[i].nodeName == 'Details')
							{
								addRowPriceBreakDown('price_breakdown_live_price', nds[i].getAttribute("PriceDescription"), nds[i].getAttribute("UnitCostPence"), nds[i].getAttribute("Quantity"));
							}
							else if(nds[i].nodeName == 'Operator')
							{
								if (document.getElementById('flight_operator'))
								{
									if (nds[i].getAttribute("Logo"))
									{
										document.getElementById('flight_operator').innerHTML = '<img src="' + nds[i].getAttribute("Logo") + '" alt="' + nds[i].getAttribute("Name") + '" />';
									}
									else
									{
										document.getElementById('flight_operator').innerHTML = nds[i].getAttribute("Name");
									}
								}				
							}
							else if(nds[i].nodeName == 'DepartureDateString')
							{
								document.getElementById('traveldetails').tBodies[0].rows[1].cells[1].innerHTML 
									= '<strong>'+ nds[i].getAttribute("Date") + '</strong> ' + nds[i].getAttribute("Time");
							}
							else if (nds[i].nodeName == 'ReturnDateString')
							{
								document.getElementById('traveldetails').tBodies[0].rows[2].cells[1].innerHTML 
									= '<strong>'+ nds[i].getAttribute("Date") + '</strong> ' + nds[i].getAttribute("Time");
							}
							else if (nds[i].nodeName == 'TotalCostPounds')
							{
								total = nds[i].getAttribute("Value") * 1; // Ensure it is an integer
							}
						}
						
						addRowTotal('price_breakdown_live_price', 'Total:', total);
						updateTotalHoliday(total, NumberOfPax);
					}
				}
			}
			var hash = getUrlVars();
			var itinerary_id = hash['itinerary_id'];
			var url = '/fetch_opts.php?noint=1&mode=async_flight&quote_id=' + quote_id;
			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)
		{
			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;	
			}
		}
		
		// Adds rows to pricebreakdown table
		function addRowPriceBreakDown(tblId, name, price, quantity)
		{
			if (price == 0) // Ignore 0 prices
			{
				return true;
			}
			
			var tblBody = document.getElementById(tblId).tBodies[0];
			var newRow = tblBody.insertRow(-1);
			var newCell;
			
			newCell = newRow.insertCell(0);
			newCell.className = 'price_breakdown_label';
			newCell.appendChild(document.createTextNode(name));
				
			newCell = newRow.insertCell(-1);
			newCell.className = 'price_breakdown_price';
			newCell.appendChild(document.createTextNode(pound_sign + (price / 100).toFixed(2) ));
				
			newCell = newRow.insertCell(-1);
			newCell.className = 'price_breakdown_quantity';
			newCell.appendChild(document.createTextNode('(x' + quantity + ')'));
		}
		
		// Adds the total row to the pricebreakdown table
		function addRowTotal(tblId, name, total)
		{
			var tblBody = document.getElementById(tblId).tBodies[0];
			var newRow = tblBody.insertRow(-1);
			var newCell;
			
			cell = newRow.insertCell(-1);
			cell.className = 'price_breakdown_total';
			cell.innerHTML = '<strong>' + name + '</strong>';
				
			cell = newRow.insertCell(-1);
			cell.className = 'price_breakdown_total';
			cell.innerHTML = '<strong>' + pound_sign + total.toFixed(2) + '</strong>';
			cell.style.textAlign = 'right';
			
			cell = newRow.insertCell(-1);
			cell.className = 'price_breakdown_total';
			cell.innerHTML = '&nbsp;';
		}
		
		// Updates the Total Holiday (looping through the accommodation units and adding the total to the accom price) 
		// To calculate the correct hotel price, we have to pass through numberOfAdults, numberOfChildren
		function updateTotalHoliday(flight_price, NumberOfPax)
		{
			var accommPrice;
			var holidayPrice;
				
			// Not the best...Set up a hidden field with the value price_breakdown_loading, when the page loaded overwrite the value to price_breakdown
			// When someone clicks the select accomm button, checks the value of the field. 
			document.getElementById('price_breakdown_checking').value = 'price_breakdown';
			
			for (var hotel_num = 0; document.getElementById('accomm_total_cost_'+hotel_num+'_0'); hotel_num++)
			{
				for (hotel_room_type_num = 0; document.getElementById('accomm_total_cost_'+hotel_num+'_'+hotel_room_type_num); hotel_room_type_num++)
				{
					accommPrice = document.getElementById('accomm_total_cost_'+hotel_num+'_'+hotel_room_type_num).value * 1;
					holidayPrice = ((accommPrice + flight_price) / NumberOfPax).toFixed(2);
		 			document.getElementById('total_cost_text_live_price_'+hotel_num+'_'+hotel_room_type_num).innerText = pound_sign + holidayPrice; // IE
					document.getElementById('total_cost_text_live_price_'+hotel_num+'_'+hotel_room_type_num).textContent = pound_sign + holidayPrice; // Everyone else
				}
			}
		}