
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>');
}

// [ET] This functions are for the ajax stuff on transfer on AO and FO pages 
// To send the transfer form and errorchecking
var req = createXMLHttpRequest();  

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 sendRequest(frm, file) {  
	var rnd982g = Math.random();  
	var str = "";  
	if(str = getForm(frm)) {  
		req.open('GET', file+'?'+str+'&rnd982g='+rnd982g); 
		req.onreadystatechange = handleResponse; 
		req.send(null); 
		} 
	return false; 
} 


function handleResponse() { 
	if(req.readyState == 4){ 
		var response = req.responseText; 
		document.getElementById("results").innerHTML = response; 
		document.getElementById("htx").innerHTML = window.location.reload();
	} 
} 
  
 function getForm(fobj) { 
	  var str = ""; 
	  var ft = ""; 
	  var fv = ""; 
	  var fn = ""; 
	  var els = ""; 
	  for(var i = 0;i < fobj.elements.length;i++) { 
	  	els = fobj.elements[i]; 
		ft = els.title; 
		fv = els.value; 
		fn = els.name; 
		switch(els.type) { 
		case "text": 
		case "hidden": 
		case "password": 
		case "textarea": 
		// Field validation
   		if(encodeURI(ft) == "requiredText1" && encodeURI(fv).length < 1) { 
			alert('Please fill in the Inbound Flight Number field.');  
			els.focus();  
			return false;   
			}
		if(encodeURI(ft) == "requiredText2" && encodeURI(fv).length < 1) { 
			alert('Please fill in the Outbound Flight Number field.');  
			els.focus();  
			return false;   
			} 
		if(encodeURI(ft) == "requiredHour1" && ((encodeURI(fv).length < 1) || (encodeURI(fv) > 24))) { 
			alert('Please fill in / correct the Arrival Time - hour field.');  
			els.focus();  
			return false;   
			} 
		if(encodeURI(ft) == "requiredHour2" && ((encodeURI(fv).length < 1) || (encodeURI(fv) > 24))) { 
			alert('Please fill in / correct the Leaving Time - hour field.');  
			els.focus();  
			return false;   
			}
		if(encodeURI(ft) == "requiredMin1" && ((encodeURI(fv).length < 1) || (encodeURI(fv) > 60))) { 
			alert('Please fill in / correct the Leaving Time - minute field.');  
			els.focus();  
			return false;   
			}
		if(encodeURI(ft) == "requiredMin2" && ((encodeURI(fv).length < 1) || (encodeURI(fv) > 60))) { 
			alert('Please fill in / correct the Leaving Time - minute field.');  
			els.focus();  
			return false;   
			}
			str += fn + "=" + encodeURI(fv) + "&";  
			break;   
   
			case "checkbox":  
			case "radio":  
				if(els.checked) str += fn + "=" + encodeURI(fv) + "&";  
			break;      
   
			case "select-one":  
			str += fn + "=" +  
			els.options[els.selectedIndex].value + "&";  
			break;  
			} 
		}
		str = str.substr(0,(str.length - 1));  
  return str;  
}

function IsNumeric(sText)
{
	var ValidChars = "0123456789";
	var IsNumber=true;
	var Char;

	for (i = 0; i < sText.length && IsNumber == true; i++) 
	{ 
		Char = sText.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) 
		{
			IsNumber = false;
		}
	}
	return IsNumber; 
}

// UNIDENTIFIED COPY & PASTES REMOVED - SEE COMMON.JS.SNIP
	
function fetch_transfers(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;	
			
			for (var i = document.getElementById('htx_ao_transfers_table').rows.length - 1; i >= 0; i--)
			{
				document.getElementById('htx_ao_transfers_table').tBodies[0].deleteRow(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(
							'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.');
			}
		}
	}
	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'
	
	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(tblId, img_url, desc_line1, desc_line2, desc_line3, product_id, price, is_per_person)
{
	var tblBody = document.getElementById(tblId).tBodies[0];
	var newRow = tblBody.insertRow(-1);
	var newCell; // Used for each of the cells to add to the row
	
	// Picture
	transferPic = document.createElement('img');
	transferPic.src = img_url;
	transferPic.style.width = '50px';
	transferPic.style.height = '50px';
	newCell = newRow.insertCell(0);
	newCell.className = 'transfer_selection_image';
	newCell.appendChild(transferPic);
	
	// Route & Description
	newCell = newRow.insertCell(-1);
	newCell.className = 'transfer_selection_route';
	newCell.appendChild(document.createTextNode(desc_line1));
	newCell.appendChild(document.createElement('br'));
	newCell.appendChild(document.createTextNode(desc_line2));
	newCell.appendChild(document.createElement('br'));
	newCell.appendChild(document.createTextNode(desc_line3));
	
	// 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';
	}
}

function tweak_print_output() {
	alert('tweak_print_output activated');
	
	var all = document.all ? document.all : document.getElementsByTagName('*');
	var elements = new Array();
	alert("all.length[" + all.length + "]");
	
	for (var e = 0; e < all.length; e++)
	{
		if (all[e].className == 'platinumspecials')
		{
			if (elements.length == 5) 
			{
				all[e].style.border = "1px solid red";
				all[e].innerHTML = all[e].innerHTML + "</div><div class=\"specials_page\"";
			}
			elements[elements.length] = all[e];			
		}
	}
	
	alert('found ' + elements.length + ' platinum specials tables.');
}
