
function surfto(form)
{
	var myindex = form.select1.selectedIndex;
	if (form.select1.options[myindex].value != "0")
	{
		location=form.select1.options[myindex].value;
	}
}

// LEFTNAV

function toggleLeftNav(varName, elementName, toggle, img, imgVarName, imageToggle)
{
	if (document.getElementById)
	{
		var el = document.getElementById(elementName);
		if ( ! el )
		{
			return false;
		}
		el.style.display = ((toggle) ? 'none' : 'block');
		eval(varName + ' = ' + ((toggle) ? 0 : 1));
		toggleLeftNavImage(document.getElementById(img), imgVarName, imageToggle);
		return false;
	}
	return true;
}

function toggleLeftNavImage(objImage, varName, imageToggle) {
	if (objImage.src) {
		objImage.src = '/images/leftnav/' + ((imageToggle) ? 'open.gif' : 'close.gif');
		eval(varName + ' = ' + ((imageToggle) ? 0 : 1));
	};
};


//various print methods for various browsers

var da = (document.all) ? 1 : 0;
var pr = (window.print) ? 1 : 0;
var mac = (navigator.userAgent.indexOf("Mac") != -1); 

function printPage() {
  if (pr) // NS4, IE5
    window.print()
  else if (da && !mac) // IE4 (Windows)
    vbPrintPage()
  else // other browsers
    alert("Sorry, your browser doesn't support this feature.\nPlease choose \"Print\" from your browser menu.");
  return false;
}

if (da && !pr && !mac) with (document) {
  writeln('<OBJECT ID="WB" WIDTH="0" HEIGHT="0" CLASSID="clsid:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>');
  writeln('<' + 'SCRIPT LANGUAGE="VBScript">');
  writeln('Sub window_onunload');
  writeln('  On Error Resume Next');
  writeln('  Set WB = nothing');
  writeln('End Sub');
  writeln('Sub vbPrintPage');
  writeln('  OLECMDID_PRINT = 6');
  writeln('  OLECMDEXECOPT_DONTPROMPTUSER = 2');
  writeln('  OLECMDEXECOPT_PROMPTUSER = 1');
  writeln('  On Error Resume Next');
  writeln('  WB.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER');
  writeln('End Sub');
  writeln('<' + '/SCRIPT>');
}

function createXMLHttpRequest() {  
	var xmlhttprequest = false;
	
	if (window.XMLHttpRequest)
	{
		xmlhttprequest = new XMLHttpRequest();
	}
	else if (window.ActiveXObject)
	{
		try 
		{
			xmlhttprequest = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch (e)
		{
			try
			{
				xmlhttprequest = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
			}
		}
	}
	else
	{
		return false;	
	}
	return xmlhttprequest;  
}

function fetch_accomm_info(more_info_text, trailstream_id, description_id)
{
	var img_node = document.getElementById("Images_" + description_id);
	var len;
	var images;
	
	images = img_node.childNodes;
	len = images.length;
	
	if(len == 0)
	{
		fetch_accomm_request(more_info_text, trailstream_id, description_id);
	}
	else
	{
		document.getElementById("Long_" + description_id).style.display = 'block';
		document.getElementById("Images_" + description_id).style.display = 'block';
		document.getElementById("Single_img_" + description_id).style.display = 'none';
		document.getElementById("Short_" + description_id).style.display = 'none';
	}
}

function fetch_accomm_request(more_info_text, trailstream_id, description_id)
{
	var xmlhttprequest = createXMLHttpRequest();
	
	xmlhttprequest.onreadystatechange = function()
	{
		if(xmlhttprequest.readyState == 4 && xmlhttprequest.status == 200)
		{
			var doc = xmlhttprequest.responseXML;
			var root = doc.documentElement;
			var nds;
			var imgs;
			
			if(root.hasChildNodes()) 
			{
				nds=root.childNodes;
				var len = nds.length;
				for (var i = 0; i < len; i++)
				{
					if(nds[i].nodeName == 'Accomm')
					{
						document.getElementById("Long_" + description_id).innerHTML = nds[i].getAttribute("Description") + "&nbsp;&nbsp;<br /><a class=\"toggle_link_minus\" href=\"Javascript:void(0);\" onclick=\"return hide_accomm_info('" + description_id + "');\">hide property info</a>&nbsp;";
						document.getElementById("Long_" + description_id).style.display = 'block';
						document.getElementById("Images_" + description_id).style.display = 'block';
						document.getElementById("Single_img_" + description_id).style.display = 'none';
						document.getElementById("Short_" + description_id).style.display = 'none';
						
						imgs = nds[i].childNodes;
						var num_imgs = imgs.length;
						for (var j = 0; j < num_imgs; j++)
						{
							if(imgs[j].nodeName == 'Image')
							{
								var img = document.createElement("img");
								//img.setAttribute('width', '130px');
								//img.setAttribute('height', '95px');
								img.className = "img_accomm";
								img.setAttribute('className', "img_accomm"); 
								img.setAttribute('src', imgs[j].getAttribute("url"));
								
								
								document.getElementById("Images_" + description_id).appendChild(img);
							}
						}
						
					}
				}
			}
		}
	}
	
	url = '/fetch_opts.php?mode=trailstream_detail&trailstream_id=' + trailstream_id + '&noint=1';
	
	xmlhttprequest.open('GET', url, true)
	xmlhttprequest.send(null)
}

function hide_accomm_info(description_id)
{
	document.getElementById("Long_" + description_id).style.display = 'none';
	document.getElementById("Short_" + description_id).style.display = 'block';
	document.getElementById("Images_" + description_id).style.display = 'none';
	document.getElementById("Single_img_" + description_id).style.display = 'block';
}

function fetch_cars(selected_product_type, hotel_name, resort_name, airport_code, arrival_date, arrival_time, return_date, return_time, num_pax)
{
	var xmlhttprequest = createXMLHttpRequest();
	
	xmlhttprequest.onreadystatechange = function()
	{
		
		if(xmlhttprequest.readyState == 4 && xmlhttprequest.status == 200)
		{
			var doc = xmlhttprequest.responseXML;
			var root = doc.documentElement;
			var nds;
			var selected_product_id;	
			var cheapest_product_id;	
			var cheapest_product_type;	
			var cars;
			
			var car_table = document.getElementById('ao_car_table');
			if(car_table.hasChildNodes())
			{
				cars = car_table.childNodes;
				var car_len = cars.length;
				
				for (var i = 0; i < car_len; i++)
				{
					if(cars[i] && cars[i].className == "car_item")
					{
						
						document.getElementById('ao_car_table').removeChild(cars[i])
					}
				}
			}
			
			if(root.hasChildNodes()) 
			{
				nds=root.childNodes;
				var len = nds.length;
				var vehicle_found = false;
				
				for (var i = 0; i < len; i++)
				{
					if(nds[i].nodeName == 'Vehicle')
					{
						vehicle_found = true;
						add_car_row(
							'ao_car_table',
							nds[i].getAttribute("Identity"),
							nds[i].getAttribute("Description"),
							nds[i].getAttribute("PickUpTime"),
							nds[i].getAttribute("DropOffTime"),
							nds[i].getAttribute("PickUpPointDescription"),
							nds[i].getAttribute("BasicCost"),
							nds[i].getAttribute("Image"),
							(i+1)
						);
						
					}
				}
			}
			document.getElementById('ao_car_table').style.opacity = 1;
			document.getElementById('ao_car_table').style.filter = 'alpha(opacity=100)';
			document.getElementById('car_updating_products_message').style.display = 'none';
			document.getElementById('car_prices_updated_message').style.display = 'inline';
			
			format_car_display();
			
			if(!vehicle_found)
			{
				alert('Sorry, we could not find any car hire options for '+airport_code+'.');
			}
//			if (selected_product_id && document.getElementById('htx_chosen_product-'+selected_product_id))
//			{
//				document.getElementById('car_chosen_product-'+selected_product_id).checked = 'checked';
//			}
//			else if (cheapest_product_id)
//			{
//				document.getElementById('car_chosen_product-'+cheapest_product_id).checked = 'checked';
//				alert('Sorry, we couldn\'t find a '+selected_product_type+' on this route at these times.\nWe have selected a '+cheapest_product_type+' for you instead.');
//			}
//			else
//			{
//				alert('Sorry, we do not have any transfers available from '+airport_code+' to '+hotel_name+' at the time specified.');
//			}
		}
	}
	url = '/fetch_opts.php?mode=extra&supplier_code=CAR&airport_code='+airport_code+'&resort_name='+resort_name+'&hotel_name='+hotel_name+'&arrival_date='+arrival_date+'&arrival_time='+arrival_time+'&return_date='+return_date+'&return_time='+return_time+'&num_pax='+num_pax+'&noint=1';
	
	document.getElementById('ao_car_table').style.opacity = 0.2;
	document.getElementById('ao_car_table').style.filter = 'alpha(opacity=20)';
	document.getElementById('car_updating_products_message').style.display = 'block';
	document.getElementById('car_prices_updated_message').style.display = 'none';
	xmlhttprequest.open('GET', url, true)
	xmlhttprequest.send(null)
}


function add_car_row(tblId, product_id, description, pick_up_time, drop_off_time, pick_up_point, price, img_url, index)
{
	var tblBody = document.getElementById(tblId);
	
	var new_div = document.createElement("div");
	var div_img = document.createElement("div");
	var div_desc = document.createElement("div");
	
	var div_description = document.createElement("div");
	var div_pick_up_time = document.createElement("div");
	var div_drop_off_time = document.createElement("div");
	var div_pick_up_point = document.createElement("div");
	
	var div_price = document.createElement("div");
	var div_price_inner = document.createElement("div");
	
	var txt_description = document.createTextNode(description);
	var txt_pick_up_time = document.createTextNode("Pick-up time: " + pick_up_time);
	var txt_drop_off_time = document.createTextNode("Drop-off time: " + drop_off_time);
	var txt_pick_up_point = document.createTextNode("Pick-up point: " + pick_up_point);
	
	div_price_inner.setAttribute("style", "font-weight:bold;");
	div_description.setAttribute("style", "font-weight:bold;");
	div_description.appendChild(txt_description);
	div_pick_up_time.appendChild(txt_pick_up_time);
	div_drop_off_time.appendChild(txt_drop_off_time);
	div_pick_up_point.appendChild(txt_pick_up_point);
	
	new_div.setAttribute('class', 'car_item');
	new_div.setAttribute('id', 'car_item' + index);
	
	div_desc.setAttribute('class', 'car_desc');
	div_img.setAttribute('class', 'car_image');
	
	div_price.setAttribute('class', 'car_price');
	div_price_inner.setAttribute('class', 'car_price_inner');

	
	var div_check = document.createElement("div");
	var div_check_in = document.createElement("div");
	
	var input_check = document.createElement("input");
	
	input_check.setAttribute('onchange', 'update_car_view(this.form, this.name, this.value, this.checked);');
	input_check.setAttribute('onclick', 'update_car_view(this.form, this.name, this.value, this.checked);');
	input_check.setAttribute('type', 'checkbox');
	input_check.setAttribute('name', 'car_chosen_product');
	alert(product_id);
	input_check.setAttribute('value', product_id);
	input_check.setAttribute('id', 'car_chosen_product-' + product_id);
	
	div_check_in.setAttribute('class', 'car_checkbox_inner');
	
	var img = document.createElement("img");
	img.setAttribute('width', '50px');
	img.setAttribute('height', '50px');
	img.setAttribute('src', img_url);
	
	var text_price = document.createTextNode('£' + price);
	div_price_inner.appendChild(text_price);
	div_check.setAttribute('class', 'car_selection_checkbox');
	
	div_desc.setAttribute('class', 'car_desc');
	
	div_price.appendChild(div_price_inner);

	div_desc.appendChild(div_description);
	div_desc.appendChild(div_pick_up_time);
	div_desc.appendChild(div_drop_off_time);
	div_desc.appendChild(div_pick_up_point);
	
	div_img.appendChild(img);
	
	new_div.appendChild(div_img);
	new_div.appendChild(div_desc);
	
	new_div.appendChild(div_price);
	
	div_check_in.appendChild(input_check);	
	div_check.appendChild(div_check_in);
	new_div.appendChild(div_check);
	
	tblBody.appendChild(new_div);
}

function fetch_transfers_huy(selected_product_type, hotel_name, resort_name, airport_code, arrival_date, arrival_time, return_date, return_time, num_pax)
{
	var xmlhttprequest = createXMLHttpRequest();
	
	xmlhttprequest.onreadystatechange = function()
	{
		
		if(xmlhttprequest.readyState == 4 && xmlhttprequest.status == 200)
		{
			var doc = xmlhttprequest.responseXML;
			var root = doc.documentElement;
			var nds;
			var selected_product_id;	
			var cheapest_product_id;	
			var cheapest_product_type;	
			
			// transfer item
			//document.getElementById('htx_ao_transfers_table').removeChild(document.getElementById('transfer_item1'));
			//document.getElementById('htx_ao_transfers_table').removeChild(document.getElementById('transfer_item2'));
			
			var car_table = document.getElementById('htx_ao_transfers_table');
			
			if(car_table.hasChildNodes())
			{
				cars = car_table.childNodes;
				var car_len = cars.length;
				
				for (var i = 0; i < car_len; i++)
				{
					if(cars[i] && cars[i].className == "transfer_item")
					{
						document.getElementById('htx_ao_transfers_table').removeChild(cars[i])
					}
				}
			}
			
			if(root.hasChildNodes()) 
			{
				nds=root.childNodes;
				var len = nds.length;
				for (var i = 0; i < len; i++)
				{
					if(nds[i].nodeName == 'Transfer')
					{
						htx_product_types[nds[i].getAttribute("ProductId")] = nds[i].getAttribute("ProductType");
						if (!cheapest_product_id)
						{
							cheapest_product_id = nds[i].getAttribute("ProductId");
							cheapest_product_type = nds[i].getAttribute("ProductType");
						}
						if (!selected_product_id && selected_product_type == nds[i].getAttribute("ProductType"))
						{
							selected_product_id = nds[i].getAttribute("ProductId");
						}

						desc_line2 = '';
						if (nds[i].getAttribute("MinPax"))
						{
							desc_line2 += nds[i].getAttribute("MinPax") + '-' + nds[i].getAttribute("MaxPax") + ' Passenger ';
						}
						desc_line2 += nds[i].getAttribute("ProductType");
						
						add_transfer_row_huy(
							'htx_ao_transfers_table',
							nds[i].getAttribute("Image"),
							'From '+nds[i].getAttribute("AirportName")+' ('+nds[i].getAttribute("AirportCode")+') to '+nds[i].getAttribute("HotelName"),
							desc_line2,
							'Duration: ' + nds[i].getAttribute("TransferMinutes") + ' minutes',
							nds[i].getAttribute("ProductId"),
							nds[i].getAttribute("ReturnPricePounds"),
							nds[i].getAttribute("IsPerPerson")
						);
					}
				}
			}
			document.getElementById('htx_ao_transfers_table').style.opacity = 1;
			document.getElementById('htx_ao_transfers_table').style.filter = 'alpha(opacity=100)';
			document.getElementById('htx_updating_products_message').style.display = 'none';
			document.getElementById('htx_prices_updated_message').style.display = 'inline';
			if (selected_product_id && document.getElementById('htx_chosen_product-'+selected_product_id))
			{
				document.getElementById('htx_chosen_product-'+selected_product_id).checked = 'checked';
			}
			else if (cheapest_product_id)
			{
				document.getElementById('htx_chosen_product-'+cheapest_product_id).checked = 'checked';
				alert('Sorry, we couldn\'t find a '+selected_product_type+' on this route at these times.\nWe have selected a '+cheapest_product_type+' for you instead.');
			}
			else
			{
				alert('Sorry, we do not have any transfers available from '+airport_code+' to '+hotel_name+' at the time specified.');
			}
		}
		
		format_transfer_display_huy();
	}
//	url = '/fetch_transfer.php?airport_code='+airport_code+'&resort_name='+resort_name+'&hotel_name='+hotel_name+'&arrival_date='+arrival_date+'&arrival_time='+arrival_time+'&return_date='+return_date+'&return_time='+return_time+'&num_pax='+num_pax+'&noint=1'
	url = '/fetch_opts.php?mode=extra&supplier_code=HTX&airport_code='+airport_code+'&resort_name='+resort_name+'&hotel_name='+hotel_name+'&arrival_date='+arrival_date+'&arrival_time='+arrival_time+'&return_date='+return_date+'&return_time='+return_time+'&num_pax='+num_pax+'&noint=1';	
	document.getElementById('htx_ao_transfers_table').style.opacity = 0.2;
	document.getElementById('htx_ao_transfers_table').style.filter = 'alpha(opacity=20)';
	document.getElementById('htx_updating_products_message').style.display = 'block';
	document.getElementById('htx_prices_updated_message').style.display = 'none';
	xmlhttprequest.open('GET', url, true)
	xmlhttprequest.send(null)
	
}

function add_transfer_row_huy(tblId, img_url, desc_line1, desc_line2, desc_line3, product_id, price, is_per_person)
{
	var tblBody = document.getElementById(tblId);
	var newCell; // Used for each of the cells to add to the row
	
	var new_div = document.createElement("div");
	var div_price = document.createElement("div");
	var div_desc1 = document.createElement("div");
	var div_desc2 = document.createElement("div");
	var div_desc3 = document.createElement("div");
	var div_desc = document.createElement("div");
	var div_img = document.createElement("div");
	var div_check = document.createElement("div");
	var div_check_in = document.createElement("div");
	var strong_bold = document.createElement("strong");
	
	var input_check = document.createElement("input");
	
	input_check.setAttribute('onchange', 'update_transfers_view(this.form, this.name, this.value, this.checked);');
	input_check.setAttribute('onclick', 'update_transfers_view(this.form, this.name, this.value, this.checked);');
	input_check.setAttribute('type', 'checkbox');
	input_check.setAttribute('name', 'htx_chosen_product');
	input_check.setAttribute('value', product_id + '-return');
	input_check.setAttribute('id', 'htx_chosen_product-' + product_id);
	
	div_check_in.setAttribute('class', 'transfer_checkbox_inner');
	
	var img = document.createElement("img");
	img.setAttribute('width', '50px');
	img.setAttribute('height', '50px');
	img.setAttribute('src', img_url);
	
	var person_text = "";
	
	if(is_per_person == "True")
	{
		person_text = "per person";	
	}
	
	var text_price1 = document.createTextNode('£' + price);
	var text_price2 = document.createTextNode(' (return) ' + person_text);
	var desc1 = document.createTextNode(desc_line1);
	var desc2 = document.createTextNode(desc_line2);
	var desc3 = document.createTextNode(desc_line3);
	
	div_check.setAttribute('class', 'transfer_selection_checkbox');
	div_img.setAttribute('class', 'transfer_image');
	new_div.setAttribute('class', 'transfer_item');
	new_div.setAttribute('id', 'transfer_item1');
	
	div_desc.setAttribute('class', 'transfer_text');
	
	div_price.setAttribute('class', 'transfer_price');
	
//	text_price1.style.font-weight = "bold";
	
	
	strong_bold.appendChild(text_price1);
	div_price.appendChild(strong_bold);
	div_price.appendChild(text_price2);

	div_check_in.appendChild(input_check);

	div_desc2.setAttribute("style", "font-weight:bold;");
	div_img.appendChild(img);
	div_desc1.appendChild(desc1);
	div_desc2.appendChild(desc2);
	div_desc3.appendChild(desc3);

	div_desc.appendChild(div_desc2);
	div_desc.appendChild(div_desc1);
	div_desc.appendChild(div_desc3);
	
	new_div.appendChild(div_img);
	new_div.appendChild(div_desc);
	new_div.appendChild(div_price);
	
	div_check.appendChild(div_check_in);
	new_div.appendChild(div_check);
	
	tblBody.appendChild(new_div);
	
	
	// Checkbox
//	newCell = newRow.insertCell(-1);
//	newCell.className = 'transfer_selection_checkbox';
//	if (navigator.appName == 'Microsoft Internet Explorer')
//	{
		// IE doesn't set the name attribute when following standards.
//		transferCheckbox = document.createElement('<input type="checkbox" name="htx_chosen_product" id="htx_chosen_product-'+product_id
//			+'" value="'+product_id+'-return" onchange="update_transfers_view(this.form, this.name, this.value, this.checked)" onclick="update_transfers_view(this.form, this.name, this.value, this.checked)">');
//	}
//	else
//	{
//		transferCheckbox = document.createElement('input');
//		transferCheckbox.type = 'checkbox';
//		transferCheckbox.name = 'htx_chosen_product';
//		transferCheckbox.id = 'htx_chosen_product-'+product_id;
//		transferCheckbox.value = product_id+'-return';
//		transferCheckbox.onchange = function() { update_transfers_view(this.form, this.name, this.value, this.checked); }
//	}
//	newCell.appendChild(transferCheckbox);
//		
//	// Price
//	newCell = newRow.insertCell(-1);
//	newCell.className = 'transfer_selection_price';
//	newCell.innerHTML = '<strong>£'+price+'</strong> (return)';
//	if (is_per_person == 'True')
//	{
//		newCell.innerHTML += '<br />Per Person';
//	}
}
