var outSelected, inSelected

function addLoadEvent(func)
{
    var oldonload = window.onload;
    if (typeof window.onload != 'function')
	{ window.onload = func; }
	else
	{ window.onload = function() { oldonload(); func(); } }
}

 function selectHoveredFlight(flight_id, positionout, position, fare_id, fId, routePositionout, routePosition, provider)
{
 var bFound
 bFound = false
 var i
 i = 0
 oFormElements = document.getElementsByName("tblOutbound")
 
 do
 {
  if (i < oFormElements.length)
  {
   if(oFormElements.item(i).id == flight_id)
   {
    oFormElements.item(i).checked = true;
    bFound = true
   }
   i = i + 1
  }
  else
  {
   bFound = true
  }
 } while (bFound == false)
 bFound = false
 i = 0
 oFormElements = document.getElementsByName("tblInbound")
 do
 {
  if (i < oFormElements.length)
  {
   if(oFormElements.item(i).id == flight_id)
   {
    oFormElements.item(i).checked = true;
    bFound = true
   }
   i = i + 1
  }
  else
  {
   bFound = true
  }
 } while (bFound == false)
 
 oFormElement = document.getElementById('flight'+flight_id)
 oFormElement = document.getElementById('flightbutton'+flight_id)
 
 document.frmResults.txtIsPostBack.value="true";
 document.frmResults.FARE_PK.value=fId;
 document.frmResults.CSI_FAREID.value=fId;
 document.frmResults.fare_id.value=fare_id;
 document.frmResults.Provider_Flight.value=provider;
 if (document.getElementById('transfer_position')) document.getElementById('transfer_position').value=''; 
 
 if(inSelected != fId) {
  document.frmResults.route_in.value=position; 
  document.frmResults.CSI_ROUTEIDIN.value=position;
 }
 if(outSelected != fId) {
  document.frmResults.route_out.value=positionout; 
  document.frmResults.CSI_ROUTEIDOUT.value=positionout; 
 }
 document.frmResults.route_out_position.value=routePositionout;
 document.frmResults.route_in_position.value=routePosition;
}


 function selectHoveredFlightOneWay(flight_id, positionout, fare_id, fId, routePositionout, provider)
{
 var bFound
 bFound = false
 var i
 i = 0
 oFormElements = document.getElementsByName("tblOutbound")
 
 do
 {
  if (i < oFormElements.length)
  {
   if(oFormElements.item(i).id == flight_id)
   {
    oFormElements.item(i).checked = true;
    bFound = true
   }
   i = i + 1
  }
  else
  {
   bFound = true
  }
 } while (bFound == false)
 
 oFormElement = document.getElementById('flight'+flight_id)
 oFormElement = document.getElementById('flightbutton'+flight_id)
 
 document.frmResults.txtIsPostBack.value="true";
 document.frmResults.FARE_PK.value=fId;
 document.frmResults.CSI_FAREID.value=fId;
 document.frmResults.fare_id.value=fare_id;
 document.frmResults.Provider_Flight.value=provider;
 
 if(outSelected != fId) {
  document.frmResults.route_out.value=positionout; 
  document.frmResults.CSI_ROUTEIDOUT.value=positionout; 
 }
 document.frmResults.route_out_position.value=routePositionout;
}

function switchBYOSearchForms(fId)
{
	if(fId[fId.selectedIndex].value=='Flight_Car')
	{ div_switch('searchOptionsAccomm',false,true); }
	else
	{ div_switch('searchOptionsAccomm',true,true); }
	if(fId[fId.selectedIndex].value=='Hotel')
	{ div_switch('searchOptionsFlights',false,true);div_switch('searchOptionsFlightsExt',false,true); }
	else
	{ div_switch('searchOptionsFlights',true,true);div_switch('searchOptionsFlightsExt',true,true); }
}
function setFilterHotels(sHotelName)
{ document.frmResults.txtIsPostBack.value="true"; if (document.frmResults.FilterHotels) document.frmResults.FilterHotels.value=sHotelName; }
function setLevel(fieldName, fId)
{ document.frmResults.txtLevel.value=fId; }
function setParentID(fId)
{ document.frmResults.ParentID.value=fId; }
function setFareID(fId)
{ document.frmResults.CSI_FAREID.value=fId; }
function setSortFlights(fId,datatype,order,sId)
{ document.frmResults.txtIsPostBack.value="true"; document.frmResults.SortFlights.value=fId + ";" + datatype + ";" + order+ ";" + sId; }
function setSortHotels(fId,datatype,order,sId)
{ document.frmResults.txtIsPostBack.value="true"; document.frmResults.SortHotels.value=fId + ";" + datatype + ";" + order + ";" + sId; }
function setSortCars(fId)
{ document.frmResults.txtIsPostBack.value="true"; document.frmResults.SortCars.value=fId; }
function setSearchType(searchId)
{ document.frmResults.search_type.value=searchId; }
function setAccomm(fieldName, fId, pId, sId, parentId, sessionId, expSupplier, expRoomCode, BoardCode)
{
	if(BoardCode==null) BoardCode='';
	document.frmResults.accomm_id.value=fId;
	document.frmResults.Provider_Accomm.value=pId;
	document.frmResults.hrnQuoteKey.value=sId;
	document.frmResults.expRoomCode.value=expRoomCode;
	document.frmResults.ParentID.value=parentId;
	document.frmResults.exp_supplier.value=expSupplier;
	document.frmResults.BoardCode.value=BoardCode;
}
function setProvider(fieldName, fId)
{
	document.frmResults.Provider_Flight.value=fId;
	document.frmResults.txtIsPostBack.value="true";
}
function setHotelCacheKey(key) {
	el = document.frmResults.hotelCacheKey;
	if (el) { el.value = key; }
}
function setTransferID(tID) {
	el = document.frmResults.transfer_position;
	if (el) { el.value = tID; }
}

function setPrices(expediaPrice,roomNameType,paxQty)
{
	var roomName = splitString(roomNameType,0)
	var roomType = splitString(roomNameType,1)
	
	var roomDetail = roomName + ", " + roomType
	
	document.frmResults.expedia_Price.value=expediaPrice; writeInDiv(roomDetail,'currentRoomName');
	if(document.frmResults.delopt.length == undefined)
	{ 
	//writeInDiv(formatCurrency(expediaPrice),'total_cost'); 
	writeInDiv(formatCurrency(expediaPrice),'total_costTop');
	writeInDiv(formatCurrency(expediaPrice / paxQty),'perpax_costTop');
	}
	else
	{
		for (var i=0; i < document.frmResults.delopt.length; i++)
		{ 
			if(document.frmResults.delopt[i].checked) 
			{ 
			//writeInDiv(formatCurrency(parseFloat(document.frmResults.delopt[i].totalValue)+expediaPrice),'total_cost'); 
			writeInDiv(formatCurrency(parseFloat(document.frmResults.delopt[i].totalValue)+expediaPrice),'total_costTop'); 
			//writeInDiv(formatCurrency((parseFloat(document.frmResults.delopt[i].totalValue)+expediaPrice) / paxQty),'perpax_cost'); 
			writeInDiv(formatCurrency((parseFloat(document.frmResults.delopt[i].totalValue)+expediaPrice) / paxQty),'perpax_costTop');
			} 
		}
		 
	}
}

function getTotalPrice(type) {
	// For use with MultipleRoom types; calculates the price of selected rooms
	var totalPrice = 0;
	if (document.getElementById('RoomCount')) {
		
		var iRooms = parseInt(document.getElementById('RoomCount').value);
		switch (type) {
			case 'radio': // Room options are in check boxes
				for (var iRoom=0; iRoom<iRooms; iRoom ++) {
					var iOption=1;
					while (document.getElementById('RB_'+(iRoom+1)+'_'+iOption)) {
						if (document.getElementById('RB_'+(iRoom+1)+'_'+iOption).checked) {
							var sValue = document.getElementById('RB_'+(iRoom+1)+'_'+iOption).getAttribute('itemValue');
							totalPrice += parseFloat(sValue);
						}
						iOption ++;
					}
					var iOption=1;
					var iOptionLoop=1;
					var bFound=false;
					var iOption=1;
					while (document.getElementById('barceloRoomID'+(iRoom+1)+iOption)) {
						if (document.getElementById('barceloRoomID'+(iRoom+1)+iOption).checked) {
							var sValue = document.getElementById('barceloRoomID'+(iRoom+1)+iOption).value;
							var sValues = sValue.split('|');
							totalPrice += parseFloat(sValues[1]);
						}
						iOption ++;
					}
					var iOption=1;
					var iOptionLoop=1;
					var bFound=false;
					while ( bFound==false)
					{
						if (document.getElementById('youtravelRoomID'+(iRoom+1)+iOption))
						{
							if (document.getElementById('youtravelRoomID'+(iRoom+1)+iOption).checked) {
								
								var sValue = document.getElementById('youtravelRoomID'+(iRoom+1)+iOption).value;
								var sValues = sValue.split('|');
								totalPrice += parseFloat(sValues[1]);
								bFound = true;
							}
						}
						iOption ++;
						if ( iOption==10) {bFound=true;}
					}
					var iOption=1;
					var iOptionLoop=1;
					var bFound=false;
					while ( bFound==false)
					{
						if (document.getElementById('packageenginePackageID'+(iRoom+1)+iOption))
						{
							if (document.getElementById('packageenginePackageID'+(iRoom+1)+iOption).checked) {
								
								var sValue = document.getElementById('packageenginePackageID'+(iRoom+1)+iOption).value;
								var sValues = sValue.split('|');
								totalPrice += parseFloat(sValues[1]);
								bFound = true;
							}
						}
						iOption ++;
						if ( iOption==10) {bFound=true;}
					}
				}
				break;
		}		
	}
	return totalPrice;
}

function updatePricingTotals(iPaxQty){
	var dDepositPrice = '0';
	fId = document.frmResults;
	//Get base price
	dTotalPrice = parseFloat(fId.basePrice.value);
	//Check for options and extras and add to total price
	
	oFormElements = document.getElementsByTagName("input")
	for (i = 0; i < oFormElements.length; i++)
	{
		if(oFormElements.item(i).type=="checkbox" && oFormElements.item(i).name=="CarExtras")
		{
			if(oFormElements.item(i).checked && oFormElements.item(i).getAttribute("itemValue") != undefined)
			{ 
				dTotalPrice += parseFloat(oFormElements.item(i).getAttribute("itemValue")); 
			}
		}
		if(oFormElements.item(i).type=="radio" && (oFormElements.item(i).name=="delopt" || oFormElements.item(i).name.indexOf("_RoomID") > 0 || oFormElements.item(i).name.indexOf("PackageID") > 0))
		{
			if(oFormElements.item(i).checked && oFormElements.item(i).getAttribute("itemValue") != undefined && oFormElements.item(i).getAttribute("itemValue") != 'na')
			{ 
				dTotalPrice += parseFloat(oFormElements.item(i).getAttribute("itemValue"));
			}
			
			if(oFormElements.item(i).checked && oFormElements.item(i).getAttribute("depositValue") != undefined && oFormElements.item(i).getAttribute("depositValue") != 'na'){ 
				dDepositPrice = parseFloat(oFormElements.item(i).getAttribute("depositValue"));
			}
		}
	}
	objSelect = document.getElementsByTagName('select')
	for(x=0;x<objSelect.length;x++) 
	{
		if(objSelect[x].options[objSelect[x].selectedIndex].getAttribute('itemValue')!=null && objSelect[x].options[objSelect[x].selectedIndex].getAttribute('itemValue')!='NaN')
		{
			dTotalPrice += parseFloat(objSelect[x].options[objSelect[x].selectedIndex].getAttribute('itemValue'))
		}
	}
	//Update totals on page
	writeInDiv(formatCurrency(dTotalPrice),'total_costTop');
	writeInDiv(formatCurrency(dTotalPrice / iPaxQty),'perpax_costTop');
	if(document.getElementById('id_depositTop')) {
		writeInDiv(formatCurrency(dDepositPrice),'id_depositTop');
	}
}
function setPricesMR(roomPrice,roomNameType,paxQty,iRoom)
{
	//alert(roomPrice+'|'+roomNameType+'|'+paxQty+'|'+iRoom);
	//var roomName = splitString(roomNameType,0)
	//var roomType = splitString(roomNameType,1)
	
	//var roomDetail = roomName + ", " + roomType
	//document.frmResults.expedia_Price.value=roomPrice;
	
	if(roomNameType != '') {
		writeInDiv(roomNameType,'RoomName'+iRoom);
		
	}
		updatePricingTotals(paxQty);
	//}else{
		//writeInDiv(formatCurrency(parseFloat(roomPrice)),'total_costTop');
		//writeInDiv(formatCurrency(parseFloat(roomPrice) / iPaxQty),'perpax_costTop');
		//if(document.getElementById('id_depositTop')) {
			//writeInDiv(formatCurrency(getDepositPrice('radio')),'id_depositTop');
		//}
	//}
	
}

function changeBoardtype(sBoardtype) {
	var sTBody = document.getElementsByTagName('tr');
	var iRoom = 1
	for(x=0;x<sTBody.length;x++) {
		if(sTBody[x].id.indexOf('_RoomOption') >= 0) {
			if(sTBody[x].id.indexOf('_'+sBoardtype+'_') >= 0) {
				sTBody[x].style.display = 'block';
				
				if(Right(sTBody[x].id,1)==iRoom) {
					sTBody[x].getElementsByTagName('input')[0].checked = true;
					//alert(sTBody[x].getElementsByTagName('input')[0].desc);
					if(sTBody[x].getElementsByTagName('input')[0].checked) {
						document.getElementById('RoomName'+iRoom).innerHTML = sTBody[x].getElementsByTagName('input')[0].desc
						//sTBody[x].getElementsByTagName('span')[0].innerHTML = sTBody[x].getElementsByTagName('input')[0].desc	
					}
					//sTBody[x].getElementsByTagName('span')[0].innerHTML = 'Room ' + Right(sTBody[x].id,1)
					iRoom++;
				}
			}else{
				sTBody[x].style.display = 'none';
			}
		}
	}
	setPricesMR(getTotalPrice('radio')+parseFloat(document.getElementById('autoFlightCarPrice').value),'',parseFloat(document.getElementById('autoNumPax').value),1);
}

var bTotalRoomPricesSet = 0;
function changeBoardtypeMR(id) {
	var iFoundSelected = 0;
	if(document.getElementById('available_boardtypes')) {
		sSelect = document.getElementById('available_boardtypes')
		for(x=0;x<sSelect.length;x++) {
			for(i=1;i<4;i++) {
				for(y=0;y<32;y++) {
						if(document.getElementById(sSelect[x].value+'_'+i+'_'+y)) {
							if (sSelect[x].value != sSelect.options[sSelect.selectedIndex].value)
							{
								document.getElementById(sSelect[x].value+'_'+i+'_'+y).style.display='none';
							}
							else
							{
								document.getElementById(sSelect[x].value+'_'+i+'_'+y).style.display='block';
							}
						}
				}
			}
		}
	}
	for(i=1;i<4;i++) {
		iFoundSelected = 0;
		for(x=0;x<32;x++) {
			if(document.getElementById(id+'_'+i+'_'+x) && document.getElementById('RB_'+i+'_'+x)) {
				if(document.getElementById(id+'_'+i+'_'+x)) {
					document.getElementById(id+'_'+i+'_'+x).style.display='';
				}
				
				if(iFoundSelected==0 && document.getElementById('RB_'+i+'_'+x)) {
					if (document.getElementById('RB_'+i+'_'+x).getAttribute('roomStatus') == 'AV')
					{
						iFoundSelected = 1;
						document.getElementById('RB_'+i+'_'+x).checked = true;
						document.getElementById('RoomName'+i).innerHTML = document.getElementById('RB_'+i+'_'+x).getAttribute('roomDetails');
					}
				}
			}
		}
	}
	bTotalRoomPricesSet = 1;
	setPricesMR(getTotalPrice('radio'),'',parseFloat(document.getElementById('autoNumPax').value),1);
}

function splitString(stringvar,x){
Stringtemp = stringvar.split("|");
//if( Stringtemp.length!=0) { 
 return Stringtemp[x];
}

function setDeliveryPrices(delOptionPrice,paxQty,flightprice)
{
 if(document.frmResults.expedia_Price.value != '')
 { 
 	var fId = document.frmResults.expedia_Price; 
    var roomPrice = new String(fId.value)

	roomPrice = Math.round(roomPrice*100)/100
	 
	var TotalPrice = roomPrice
	
	//writeInDiv(formatCurrency(TotalPrice+delOptionPrice),'total_cost'); 
	writeInDiv(formatCurrency(TotalPrice+delOptionPrice),'total_costTop'); 
	//writeInDiv(formatCurrency((TotalPrice+delOptionPrice) / paxQty),'perpax_cost'); 
	writeInDiv(formatCurrency((TotalPrice+delOptionPrice) / paxQty),'perpax_costTop');
 }
 else
 {	
	flightprice=Math.round(flightprice*100)/100
	
	var TotalPrice = flightprice
	//writeInDiv(formatCurrency(TotalPrice+delOptionPrice),'total_cost'); 
	writeInDiv(formatCurrency(TotalPrice+delOptionPrice),'total_costTop'); 
	//writeInDiv(formatCurrency((TotalPrice+delOptionPrice) / paxQty),'perpax_cost'); 
	writeInDiv(formatCurrency((TotalPrice+delOptionPrice) / paxQty),'perpax_costTop');
 }
}
function setLMPrice(lmPrice)
{
	document.frmResults.flight_cost.value=lmPrice;
	writeInDiv(lmPrice,'total_cost');
	alert (document.frmResults.flight_cost.value)
}


// A.Seabridge to untick all other transfers on page before ticking new one - direct traveller

function removeTransfer(ckbox){
	fId = document.frmResults;
	var ckboxchecked = ckbox.checked
	//untick all checked transfers
	oFormElements = document.getElementsByTagName("input")
	for (i = 0; i < oFormElements.length; i++)
	{
		if(oFormElements.item(i).type=="checkbox" && oFormElements.item(i).name=="chkremovetransfer")
		{
			oFormElements.item(i).checked=false;
		}
	}
	//tick/untick selected checkbox based on user reponse to popup message
	if(ckboxchecked==true){
		
		/*@cc_on @*/
		/*@if (@_win32 && @_jscript_version>=5)
		
		function window.confirm(str)
		{
			execScript('n = msgbox("'+str+'","4132", "Remove transfer?")', "vbscript");
			return(n == 6);
		}
		
		@end @*/


		
		if(confirm('Are you sure you do not require this complimentary Direct Traveller transfer and you wish to remove it from the holiday?')){
			ckbox.checked=true;
		}
		else{
			ckbox.checked=false;
		}
	}
	else{
		ckbox.checked=false;
	}
}

function onClick(td, tablename, position, fare_id, fId, routePosition, provider)
{
	document.frmResults.txtIsPostBack.value="true";
	document.frmResults.FARE_PK.value=fId;
	document.frmResults.CSI_FAREID.value=fId;
	document.frmResults.fare_id.value=fare_id;
	document.frmResults.Provider_Flight.value=provider;
	if (tablename == "tblOutbound")
	{ 
		document.frmResults.route_out.value=position; document.frmResults.CSI_ROUTEIDOUT.value=position; document.frmResults.route_out_position.value=routePosition; 
		outSelected = fId;
	}
	else if (tablename == "tblInbound")
	{ 
		document.frmResults.route_in.value=position; document.frmResults.CSI_ROUTEIDIN.value=position; document.frmResults.route_in_position.value=routePosition; 
		inSelected = fId;
	}
}

function SetDevLayer(ShowDiv)
{ document.frmResults.ShowDiv.value=ShowDiv; }
function ChangePageTransfers(pagenumber)
{ document.frmResults.txtLevel.value='SEARCH'; document.frmResults.txtIsPostBack.value="true"; document.frmResults.pagenumbertransfers.value=pagenumber; document.frmResults.ShowDiv.value='transfers'; submitform('','Please wait while we retrieve another page of transfer results.'); }
function ChangePageFlights(pagenumber)
{ document.frmResults.txtLevel.value='SEARCH'; document.frmResults.txtIsPostBack.value="true"; document.frmResults.pagenumberflights.value=pagenumber; document.frmResults.ShowDiv.value='flights'; submitform('','Please wait while we retrieve another page of flight results.'); }
function ChangePageHotels(pagenumber)
{ document.frmResults.txtLevel.value='SEARCH'; document.frmResults.txtIsPostBack.value="true"; document.frmResults.pagenumberhotels.value=pagenumber; document.frmResults.ShowDiv.value='accomm'; submitform('','Please wait while we retrieve another page of results.'); }
function submitform(level,msg)
{
	div_switch('superDiv',false,true);
	
	div_switch('superLoad2',true,true);
	
	if(level=='booking') { div_switch('data',false,true); }
	
	writeInDiv(msg,'waitMessage'); 
	document.frmResults.submit();
}
function PassengerInput(NoOfPax)
{ var x = 1; while (x < NoOfPax) { document.write('Pax Test'); x = x+1; } }
function setCarOption(position)
{ document.frmResults.car_position.value=position; }
function setCarOptionEx(position,supplier)
{ document.frmResults.car_position.value=position;document.frmResults.car_provider.value=supplier; }
function fetchMoreHotels(cacheKey, cacheLocation)
{ document.frmResults.fetchMoreHotels.value='true'; document.frmResults.cacheKey.value=cacheKey; document.frmResults.cacheLocation.value=cacheLocation; document.frmResults.txtLevel.value='SEARCH'; document.frmResults.txtIsPostBack.value="false"; submitform('','Please wait while we retrieve more hotel results.'); }
function checkSelectedFlights()
{
	if (checkSelectedFlightsEx()) {
		submitform('','Please wait while we update your prices based on your new flight selection.'); }
}

function newcheckSelectedFlight(flight_pos, numberlegsout, numberlegsin)
{
 var foundOutbound
 var foundInbound
 
 foundOutbound = false;
 foundInbound = false;
 //alert(flight_pos+'|'+numberlegsout+'|'+numberlegsin);
 // PRE CHECK IF FLIGHT IS ALREADY PRE SELECTED
if(document.getElementById('tblInbound'+flight_pos+',1')) {
  //Return
  if(numberlegsin == 1 && numberlegsout == 1)
  {
   foundInbound = true;
   foundOutbound = true;
  }
  if(foundOutbound == true && foundInbound == true)
  {
   return true;
  }
}else{
  //Oneway
  if(numberlegsout == 1)
  {
   foundOutbound = true;
  }
  if(foundOutbound == true && foundInbound == true)
  {
   return true;
  } 
}
 // END CHECK IF FLIGHT IS ALREADY PRE SELECTED
 for(i=1;i<=numberlegsout;i++)
 {
  oFormElement = document.getElementById('tblOutbound'+flight_pos+','+i)
  if(oFormElement.checked == true)
  {
   foundOutbound = true;
  }
 }
 for(i=1;i<=numberlegsin;i++)
 {
  oFormElement = document.getElementById('tblInbound'+flight_pos+','+i)
  if(oFormElement.checked == true)
  {
   foundInbound = true;
  }
 }
if(document.getElementById('tblInbound'+flight_pos+',1')) {
 //Return flights
  if(foundOutbound == true && foundInbound == true)
  {
   return true;
   submitform('','Updating your prices based on your new flight selection.'); 
  }
  else
  {
   alert('Please select your flight options.');
   return false;
  }  
 }else{
  //Oneway flights
  if(foundOutbound == true)
  {
   return true;
   submitform('','Updating your prices based on your new flight selection.'); 
  }
  else
  {
   alert('Please select your flight options.');
   return false;
  }   
 }

}

function checkSelectedFlights()
{
 var bSelOutBound = false;
 var bSelInBound = false;
 var iOutBoundFlightID = '';
 var iInBoundFlightID = '';
 for (var i=0; i<document.frmResults.tblOutbound.length; i++)
 {
  if (document.frmResults.tblOutbound[i].checked)
  { bSelOutBound = true; iOutBoundFlightID = document.frmResults.tblOutbound[i].id; }
  else
  { bSelOutBound = false; }
  if (bSelOutBound == true) break;
 }
 //Check if oneway or return
 if(document.getElementById("tblInbound")) {
  for (var i=0; i<document.frmResults.tblInbound.length; i++)
  {
   if (document.frmResults.tblInbound[i].checked)
   { bSelInBound = true; iInBoundFlightID = document.frmResults.tblInbound[i].id; }
   else
   { bSelInBound = false; }
   if (bSelInBound == true) break;
  }
 }else{
  bSelInBound = true; 
 }
 if(bSelOutBound==true && bSelInBound==true)
 {
  if(iOutBoundFlightID==iInBoundFlightID || !document.getElementById("tblInbound"))
  { submitform('','Updating your prices based on your new flight selection.'); }
  else
  { alert('When selecting alternative flights, the outbound and inbound routes must be from the same flight!'); return false; }
 }
 else
 { alert('Sorry, you must select an outbound and an inbound flight!'); return false; }
}

function checkBYOForm(fId)
{
	if(fId.airportfrom.selectedIndex == 0)
	{ alert("Please select a departure airport!"); fId.airportfrom.focus(); return false; }
	else if(fId.airportto == undefined && fId.locationto == undefined && (fId.lookup.value.length <= 2 || fId.lookup.value == "- Enter a destination -"))
	{ alert("Please enter a destination (min. 3 characters)!"); fId.lookup.focus(); return false; }
	else if(fId.airportto != undefined && fId.airportto[fId.airportto.selectedIndex].value == "" && (fId.lookup.value.length <= 2 || fId.lookup.value == "- Enter a destination -"))
	{ alert("Please confirm your destination or enter a new search (min. 3 characters)!"); fId.airportto.focus(); return false; }
	else if(fId.locationto != undefined && fId.locationto[fId.locationto.selectedIndex].value == "" && (fId.lookup.value.length <= 2 || fId.lookup.value == "- Enter a destination -"))
	{ alert("Please confirm your destination or enter a new search (min. 3 characters)!"); fId.locationto.focus(); return false; }
	else if(checkValidDate(fId) == false)
	{ alert("Please select an alternative departure date!\nThe date you have selected is unavailable."); fId.startdate_d.focus(); return false; }
	else if(checkTimeTravel(fId) == false)
	{ alert("Please select an alternative return date!\nYour departure date is after your return date."); fId.enddate_d.focus(); return false; }
	else
	{ return true; }
}


function resultsTimeout()
{  
//self.location.href = "/buildyourown/?e=session_timeout&amp;"+location.search.substring(1,location.search.length);
}

var r = 0;
var c = 0;
var prevCell = '';
var maxRows = 1;
var maxCols = 5;
var playTime = 200;
var clearTime = 150; 

function clear(){
	document.getElementById(prevCell).className = 'dnormal';
	r = 0;
	c = 0;
	prevCell = '';
}

function highLightCell(){
	if (prevCell != ''){document.getElementById(prevCell).className = 'dnormal'}
	var idStr = 'd'+c;
	document.getElementById(idStr).className = 'dhighLight';
	prevCell = idStr;
	if (c < (maxCols+1)){c++}
	if (c == maxCols && r < (maxRows+1)){r++; c = 0}
	setTimeout('highLightCell()',playTime);
	if (r == maxRows){setTimeout('clear()',clearTime)}
}

function flightHotelSort(sId, sPageNum) {
	var iId = parseInt(sId);
	switch(iId){
		case 0:
			setSortHotels('default','','','0');
			break;
		case 1:
			setSortHotels('AccommInfo/AccommName','text','ascending','1');
			break;
		case 2:
			setSortHotels('AccommInfo/StarRating','number','descending','2');
			break;
		case 3:
			setSortHotels("translate(PricedRooms/PricedRoom/TotalCostPrice,',','')",'number','ascending','3');
			break;
	}
	ChangePageHotels(sPageNum);
}

function checkPaxForm(sBookLevel, sParentID)
{	
	
	if(checkAdditinalPax() == false)
	{ return false; }
	
	if(checkAdditinalsecondPax() == false)
	{ return false; }
	if(checkFormFieldSelectedIndex("title", "Please select a title for all passengers!") == false)
	{ return false; }
	else if(checkFormFieldValue("firstname", "- First Name -", "Please enter a first name for all passengers!",2) == false)
	{ return false; }
	else if(checkFormFieldValue("surname", "- Surname -", "Please enter a surname for all passengers!") == false)
	{ return false; }
	else if(checkFormFieldAges("Please check the following date of births!") == false)
	{ return false; }
	else if(checkAgeDOBMatch(document.getElementById('AgeCheckNoChilds').value, document.getElementById('AgeCheckNoAdults').value, document.getElementById('AgeCheckDepDate').value, document.getElementById('AgeCheckSearchType').value) == false)
	{ return false; }
	
	else
	{	
	
		// HOTEL ON REQUEST CHECKS
		var bPassRoomCheck;
		bPassRoomCheck = false;
		var oFormElements;
		oFormElements = document.getElementsByTagName("input")
		if (oFormElements.length == 0) { bPassRoomCheck = true; }
		var ihotelCount = 0
		for (i = 0; i < oFormElements.length; i++)
		{
			if(oFormElements.item(i).type=="radio" && oFormElements.item(i).name!="oneway" && oFormElements.item(i).name!="transport" && oFormElements.item(i).name!="delopt")
			{
				ihotelCount = ihotelCount + 1
				if(oFormElements.item(i).checked == true)
				{
					bPassRoomCheck = true;
				}
			}
			//else
			//{
				//bPassRoomCheck = true;
			//}
		}
		
		if (bPassRoomCheck == false && ihotelCount > 0)
		{
			alert('This hotel is not available, it may be on request. Please call for pricing.');
			return false;
		}
	
		if(document.getElementById('CarFlightNo')){
			  if (document.getElementById('CarFlightNo').value == "" || document.getElementById('CarFlightNo').value == "Flight No.") {
				alert("Please enter 'Walk In' if you are not flying in.");
				document.getElementById('CarFlightNo').value = "Walk In";
				document.getElementById('CarFlightNo').focus();
				return false;
			  }
		}
		
		if(document.getElementById('accept_tandc')){
			if(!document.getElementById('accept_tandc').checked) {
				alert("Please ensure that you have read and agree to the booking terms and conditions and the fare rules for this flight!");
				return false;
			}
		}
		
		if(document.getElementById('carhiretandc')){
			if(!document.getElementById('carhiretandc').checked) {
				alert("Please ensure that you have read and agree to the car hire booking terms and conditions!");
				return false;
			}
		}
		
		//new field for DT for hotel where customer wants to pick their car up from
		if(document.getElementById('CarPickupHotelID')){
			if(document.getElementById("CarPickupHotelID").options[document.getElementById("CarPickupHotelID").selectedIndex].value == "-"){
				alert("Please Select the Hotel Where you wish to pick up your car from!");
				return false;
			}
		}

		div_switch('data',false,true);
		if(document.getElementById('flights')){
			div_switch('flights',false,true);
		}
		div_switch('superLoad2',true,true);
		setLevel('txtLevel',sBookLevel);
		if(sParentID!='') { setParentID(sParentID); }
		//document.loadingImg.src='/images/searching_anim.gif';
		submitform('booking','DirectTraveller is processing your booking.');
		//document.loadingImg.src='/images/searching_anim.gif';
	}
}

function checkAdditinalPax()
{
	if (document.getElementById('AddExtraDriver')){
		if(document.getElementById('AddExtraDriver').selectedIndex == 1){
			if(checkFormFieldSelectedIndex("CarDriverAddTitle1", "Please select a title for additional driver!") == false)
			{ return false; }
			else if(checkFormFieldValue("CarDriverAddFName1", "- First Name -", "Please enter a first name for additional driver!",2) == false)
			{ return false; }
			else if(checkFormFieldValue("CarDriverAddSName1", "- Surname -", "Please enter a surname for additional driver!") == false)
			{ return false; }
			else if(checkFormAdditionalFieldAges("Please check the additional drivers date of birth!") == false)
			{ return false; }
		}
		else
		{ return true; }
	}
	else
	{ return true; }
}

function checkAdditinalsecondPax()
{
	if (document.getElementById('AddSecondExtraDriver')){
		if(document.getElementById('AddSecondExtraDriver').selectedIndex == 1){
			if(checkFormFieldSelectedIndex("CarDriverAddTitle2", "Please select a title for second additional driver!") == false)
			{ return false; }
			else if(checkFormFieldValue("CarDriverAddFName2", "- First Name -", "Please enter a first name for second additional driver!",2) == false)
			{ return false; }
			else if(checkFormFieldValue("CarDriverAddSName2", "- Surname -", "Please enter a surname for second additional driver!") == false)
			{ return false; }
			else if(checkFormSecondAdditionalFieldAges("Please check the second additional drivers date of birth!") == false)
			{ return false; }
		}
		else
		{ return true; }
	}
	else
	{ return true; }
}

function UpdateFEFlightOptions(iPaxQty)
{
	var dTotalPrice = 0
	var i
	oFormElements = document.getElementsByTagName("input")
	for (i = 0; i < oFormElements.length; i++)
	{
		if(oFormElements.item(i).type=="radio" && (oFormElements.item(i).name.indexOf("FE_") > -1))
		{
			if(oFormElements.item(i).checked && oFormElements.item(i).itemValue != undefined)
			{
				dTotalPrice += parseFloat(oFormElements.item(i).itemValue); 
			}
		}
	}
	writeInDiv(formatCurrency(dTotalPrice),'total_costTop');
	writeInDiv(formatCurrency(dTotalPrice / iPaxQty),'perpax_costTop');
}

function checkAgeDOBMatch(NumChildren, NumAdults, DepDate, SearchType){
	var Str = document.getElementById('AgeCheckSearchType').value

	if (Str.indexOf("Hotel") >= 0 && document.getElementById('AgeCheckNoChilds').value != "0")
	{
		var i, today, d, by, bm, bd, bday, age, dif, DOB
		var ErrTxt = "There has been a problem matching the date of birth of your children with the ages that you originally search for! -\n\n"
			for (i = 1; i <= NumChildren; i++)
			{
				//get depdate in correct format
				d =DepDate.split('/'); 
				by = Number(d[2]); bm = Number(d[1])-1; bd = Number(d[0]); 
				today = new Date(by,bm,bd) 
				
				//get childs DOB in correct format
				DOB = document.getElementById('dobd' + (i + Number(NumAdults))).value + "/" + document.getElementById('dobm' + (i + Number(NumAdults))).value + "/" + document.getElementById('doby' + (i + Number(NumAdults))).value
				d =DOB.split('/'); 
				by = Number(d[2]); bm = Number(d[1])-1; bd = Number(d[0]); 
				bday = new Date(by,bm,bd) 
				age=0; dif=bday; 
				
				while(dif<today)
				{ 
					dif = new Date(by+age,bm,parseInt(bd)-1); 
					age++; 
				} 
				age +=-2 ; 
				if (document.getElementById('AgeCheck' + i).value != age)
				{
				ErrTxt = ErrTxt + "Child " + i + ": " + DOB + " makes the child " + age + " years old, the child must be " + document.getElementById('AgeCheck' + i).value + " at time of departure.\n"
				//return false; break;
				}
			}
			if (ErrTxt == "There has been a problem matching the date of birth of your children with the ages that you originally search for! -\n\n")
				{return true;}
			else
				{alert(ErrTxt + "\nPlease enter the correct date of birth or search again with the age of the child at the date of departure."); return false;}
	}
} 

	
	function ucasePassortNumber(fID,value){
		if (value!='e.g. GBR 123456789'){
			fID.value = fID.value.toUpperCase()
		}
	}
	

function hideShowPassportInfo(numPax, provider) {
	if (provider == 'multicom'){
		for(x=1;x<=numPax;x++) {
			if (document.getElementById('FOIDVal_' + x).disabled == true){
				document.getElementById('FOIDVal_' + x).disabled = false;
				document.getElementById('FOIDVal_' + x).style.display='';
				document.getElementById('FOID_ByPass').value = false;
				if (x==numPax){
					document.getElementById('FOIDlabel3').innerHTML = 'Don\'t have all the passengers passport details right now?';
				}
			}else{
				document.getElementById('FOIDVal_' + x).disabled = true;
				document.getElementById('FOIDVal_' + x).style.display='none';
				document.getElementById('FOID_ByPass').value = true;
				if (x==numPax){
					document.getElementById('FOIDlabel3').innerHTML = 'Do you have all the passengers passport details?';
					alert('Please note that passport information will still be required to complete this booking.\n\nYou will be prompted to pay offline at the next stage and one of our team will call you back as soon as possible to confirm the necessary details.');
				}
				
			}
	
		}
		
	}else{ //AMADEUS
	
		for(x=1;x<=numPax;x++) {
			if (document.getElementById('infoPassportNum' + x).disabled == true){
				document.getElementById('FOID_ByPass').value = false;
				document.getElementById('infoPassportNum' + x).disabled = false;
				document.getElementById('infoPassportExpiryD' + x).disabled = false;
				document.getElementById('infoPassportExpiryM' + x).disabled = false;
				document.getElementById('infoPassportExpiryY' + x).disabled = false;
				document.getElementById('infoPassportNumTitle' + x).style.display='';
				document.getElementById('infoPassportExpiryTitle' + x).style.display='';
				document.getElementById('infoPassportNum' + x).style.display='';
				document.getElementById('infoPassportExpiryD' + x).style.display='';
				document.getElementById('infoPassportExpiryM' + x).style.display='';
				document.getElementById('infoPassportExpiryY' + x).style.display='';
				if (x==numPax){
					document.getElementById('FOIDlabel3').innerHTML = 'Don\'t have all the passengers passport details right now?';
				}
			}else{
				document.getElementById('FOID_ByPass').value = true;
				document.getElementById('infoPassportNum' + x).disabled = true;
				document.getElementById('infoPassportExpiryD' + x).disabled = true;
				document.getElementById('infoPassportExpiryM' + x).disabled = true;
				document.getElementById('infoPassportExpiryY' + x).disabled = true;
				document.getElementById('infoPassportNumTitle' + x).style.display='none';
				document.getElementById('infoPassportExpiryTitle' + x).style.display='none';
				document.getElementById('infoPassportNum' + x).style.display='none';
				document.getElementById('infoPassportExpiryD' + x).style.display='none';
				document.getElementById('infoPassportExpiryM' + x).style.display='none';
				document.getElementById('infoPassportExpiryY' + x).style.display='none';
				if (x==numPax){
					document.getElementById('FOIDlabel3').innerHTML = 'Do you have all the passengers passport details?';
					alert('Please note that passport information will still be required to complete this booking.\n\nYou will be prompted to pay offline at the next stage and one of our team will call you back as soon as possible to confirm the necessary details.');
				}
				
			}
	
		}
		
	}


}