var SOURCE_URL = "/cms/global/json/jansale2010/woffersdata.json";
var SOURCE_TYPE = "json";
var DOCUMENT_ELEMENT_ID = "tableDiv"
var ONEWAY_PRICE_POSTPIN_DISCOUNT = 0;
var RETURN_PRICE_POSTPIN_DISCOUNT = 0;
var HOTEL_PRICE_POSTPIN_DISCOUNT = 0;
var ONEWAY_PRICE_TYPE = "ow";
var RETURN_PRICE_TYPE = "rt";
var TABLE_HEADERS = [["Destination", "1", "Click to change sort order.", "", "HYBRID"],
["Flight only from", "1", "", "", "HYBRID"],
["Holidays per person from<br/><div class='needHelp'>Need help with your booking? Call 0844&nbsp;493&nbsp;0760</div>","1","","", "HYBRID"],
["Destination", "1", "Click to change sort order.", "", "FLIGHTS"],
["Flight only from", "1", "", "", "FLIGHTS"],
["Travel dates <span><br />Click <img src=\"/cms/global/assets/images/promotion/uk/may_campaign_2009/twisty-closed.gif\" width=\"9\" height=\"9\" alt=\"Plus sign.\" /> to see more</span>","1","","", "FLIGHTS"],
["Plan or book your trip", "1", "", "", "FLIGHTS"]
];
var LOCATIONS = [["ABZ", "Aberdeen", "ABZ", "Aberdeen", "EUR"],
["BRS", "Bristol", "", "", "EUR"],
["ORK", "Cork", "", "", "EUR"],
["DUB", "Dublin", "", "", "EUR"],
["EMA", "East Midlands", "", "", "EUR"],
["EDI", "Edinburgh", "", "", "EUR"],
["GLA", "Glasgow", "", "", "EUR"],
["INV", "Inverness", "", "", "EUR"],
["IOM", "Isle of Man", "", "", "EUR"],
["JER", "Jersey", "", "", "EUR"],
["LON", "London (All)", "LON", "London", "EUR"],
["LCY", "London City", "LON", "London", "EUR"],
["LGW", "London Gatwick", "LON", "London", "EUR"],
["LHR", "London Heathrow", "LON", "London", "EUR"],
["MAN", "Manchester", "", "", "EUR"],
["NCL", "Newcastle", "", "", "EUR"],
["NAM", "North America", "", "North America", "NAM"],
["AFR", "Africa", "", "Africa", "AFR"],
["SASIA", "South Asia", "", "South Asia", "SASIA"],
["FEA", "Asia and Far East", "", "Asia and Far East", "FEA"],
["LAC", "Latin America and Caribbean", "", "Latin America and Caribbean", "LAC"],
["ME", "Middle East", "", "Middle East", "ME"],
["NAF", "North Africa", "", "North Africa", "NAF"],
["NQY", "Newquay", "", "Newquay", "NQY"],
["SNN", "Shannon", "", "", "EUR"],
["EUR", "Europe", "", "Europe", "EUR"],
["UKI", "UK and Ireland", "", "UK and Ireland", "UKI"]
];
var PRICE_BANDS = [["PRICEBAND1", "0", "50"],
["PRICEBAND2", "51", "150"],
["PRICEBAND3", "151", "300"],
["PRICEBAND4", "301", "450"],
["PRICEBAND5", "451", "9999999"]];
var VALID_DEPARTURES = ["ABZ",
"EDI",
"GLA",
"JER",
"LON",
"LCY",
"LHR",
"LGW",
"MAN",
"NCL"];
var VALID_REGIONS = ["NAM",
"SASIA",
"EUR",
"FEA",
"LAC",
"ME",
"NAF",
"AFR",
"UKI"];
var VALID_TYPES = ["BEACH",
"EUROPE",
"CITY"];
var VALID_PRICEBANDS = ["PRICEBAND1",
"PRICEBAND2",
"PRICEBAND3",
"PRICEBAND4",
"PRICEBAND5"];
var VALID_CABINS = ["M",
"W",
"J",
"F"
];

var VALID_ADDONS = { "ABZLHR": true,
"EDILHR": true,
"EDILGW": true,
"EDILCY": true,
"GLALHR": true,
"GLALGW": true,
"GLALCY": true,
"MANLHR": true,
"MANLGW": true,
"JERLGW": true,
"NCLLHR": true};
var ALERT_DESTINATIONS = ["XXX"];
var TECHNICAL_DIFFICULTIES = false;
var TECHNICAL_DIFFICULTIES_MESSAGE = "Sorry, we are experiencing technical difficulties at the moment, please try again later.";
var gWoffersData = new WoffersData(SOURCE_URL, SOURCE_TYPE);
var gWofferTable = null;
var gPageType = "";
var gNavType = "";
var gFromCode = "";
var gToCode = "";
var gLinkType = "";
var navObj = "";
var gPlanTripInitialised = false;
var gTravelClass = "";
var gTravelClassName = "";
var gFlightFound = false;
var gPackageFound = false;
$(pageSetup);
function setPageParameters() {

gPageType = "FLIGHTS";
gNavType = "REGIONS";
gFromCode = "LON";
gToCode = "NAM";
gLinkType = "LPBMPAGE";


gTravelClass = "M";


gPageType = getQueryValue("pagetype").toUpperCase();
gLinkType = getQueryValue("linktype").toUpperCase();
if(gPageType == "NOT FOUND") {
gPageType = getCookie("BA_SALE_PAGE_TYPE");
}
switch(gPageType) {
case "0": {
gPageType = "HYBRID";

break;
}

case "1": {
gPageType = "HYBRID";

break;
}

default: {
gPageType = "HYBRID";
}

}

if(gLinkType == "NOT FOUND") {
gLinkType = getCookie("BA_SALE_LINK_TYPE");
}
switch(gLinkType) {
case "0": {
gLinkType = "FXPAGE";

break;
}

case "1": {
gLinkType = "LPBMPAGE";

break;
}

default: {

gLinkType = "LPBMPAGE";
}

}




gFromCode = getQueryValue("from").toUpperCase();

var foundLocation = false;

if(gFromCode && (gFromCode != "NOT FOUND")) {
for(var locationIndex = 0; locationIndex < VALID_DEPARTURES.length; ++locationIndex) {
if(VALID_DEPARTURES[locationIndex] == gFromCode) {
foundLocation = true;

break;
}
}
}


if(!foundLocation) {
gFromCode = "LON";
}



gToCode = getQueryValue("to").toUpperCase();

var foundRegion = false;

if(gToCode && (gToCode != "NOT FOUND")) {
for(var regionIndex = 0; regionIndex < VALID_REGIONS.length; ++regionIndex) {
if(VALID_REGIONS[regionIndex] == gToCode) {
foundRegion = true;

break;
}
}
}

if(!foundRegion) {
gToCode = "NAM";
}



gTravelClass = getQueryValue("cabin").toUpperCase();

var foundCabin = false;

if(gTravelClass && (gTravelClass != "NOT FOUND")) {
for(var cabinIndex = 0; cabinIndex < VALID_CABINS.length; ++cabinIndex) {
if(VALID_CABINS[cabinIndex] == gTravelClass) {
foundCabin = true;
break;
}
}
}

if(!foundCabin) {
gTravelClass = "M";
}

}
function pageSetup() {
try {






if ($.browser.safari) { $("#t-centre>.clearBoth").height(0); }


setNavType("REGIONS");
setTravelClass();



$("#departureSelection").keyup(function() {gWofferTable.processFromChange(this);});
$("#departureSelection").change(function() {gWofferTable.processFromChange(this);});


$(".regionNavigation a").click(function() {gWofferTable.processRegionChangeEvent(this);});


$("#travelClassPod input[name='travelClassOption']").click(function() {gWofferTable.processTravelClassEvent(this);});



gWofferTable = new WofferTable(DOCUMENT_ELEMENT_ID, gWoffersData, gFromCode, gToCode);




gWoffersData.build();
}


catch(e) {



}

}
function setTravelClass()
{
$("#travelClassPod input[value='" + gTravelClass.toUpperCase() + "']").attr({"checked":"checked"});
}
function setNavType(navType)
{

var typeNavItems = $(".typeNavigation li a");
var regionNavItems = $(".regionNavigation li a");


var matchedDepartureLocations = $("select.departureSelection  option[value='" + gFromCode + "']");


if(matchedDepartureLocations) {
matchedDepartureLocations[0].selected = true;
}

$("#pageTypeSelectionDiv input[value='" + navType.toUpperCase() + "']").attr({"checked":"checked"});
navObj = $("#pageTypeSelectionDiv input[value='" + navType.toUpperCase() + "']");


switch(navType.toUpperCase()) {
case "TYPES" :{
$(".regionNavigation:visible").hide();
$(".typeNavigation").show();
$("#t-topic-content").removeClass('regions').addClass('types');
typeNavItems.removeClass("selected");
$(".typeNavigation li." + gToCode.toLowerCase() + " a").addClass("selected");
gNavType = "TYPES";
break;
}
case "REGIONS" : {
$(".typeNavigation:visible").hide();
$(".regionNavigation").show();
$("#t-topic-content").removeClass('types').addClass('regions');
regionNavItems.removeClass("selected");
$(".regionNavigation li." + gToCode.toLowerCase() + " a").addClass("selected");
gNavType = "REGIONS";

break;
}



default: {
$(".regionNavigation:visible").hide();

$(".typeNavigation").show();
gNavType = "TYPES";


$("#topBanner img").attr("src","/cms/global/assets/images/promotion/uk/may_campaign_2009/beaches_wide.gif");
$("#t-topic-content").addClass('types');
$("#tableHeadText").html("Flight offers");

imageNavItems.removeClass("selected");


$(".typeNavigation li." + gToCode.toLowerCase() + " a").addClass("selected");
break;
}

}
}
function initialisePlantrip() {


if(!gPlanTripInitialised) {

var packageType = getQueryValue("packagetype").toUpperCase();
switch(packageType) {
case "FH": {
$("#hotelPackage").click();

gPlanTripInitialised = true;

break;
}

case "FC": {
$("#carPackage").click();

gPlanTripInitialised = true;

break;
}

default: {

}

}

}

}
function WoffersData(sourceURL, sourceType) {
if(sourceType != "json") {
throw new Error("Invalid source type (" + sourceType + ") supplied to Woffers constructor.");
}


this.sourceURL = sourceURL;
this.sourceType = sourceType;
}
WoffersData.prototype.build = function()
{

var instance = this;
var ajaxXmlhttp = null;

this.woffers = new Array();


if(window.XMLHttpRequest && !(window.ActiveXObject)) {

try {
ajaxXmlhttp = new XMLHttpRequest();
}


catch(e) {
ajaxXmlhttp = null;
}
}


else if(window.ActiveXObject) {


try {
ajaxXmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}

catch(e) {
try {
ajaxXmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}

catch(e) {
ajaxXmlhttp = null;
}
}
}


if(ajaxXmlhttp) {

ajaxXmlhttp.onreadystatechange = function() {
if(ajaxXmlhttp.readyState == '4') {
var response = ajaxXmlhttp.responseText;


response = response.replace(/\r\n/g, '');


response = eval('(' + response + ')');


instance.parseJson(response);

}

};


ajaxXmlhttp.open("GET", this.sourceURL, true);


ajaxXmlhttp.send(null);
}

}
WoffersData.prototype.parseJson = function(json)
{


for(var index = 0; index < json.routes.length; ++index)
{
this.woffers.push(new Woffer(json.routes[index]));
}




gWofferTable.buildOutput();
}
WoffersData.prototype.getWoffersForLocations = function(fromCode, toCode, includeNonSale) {
var matchingWoffers = new Array();
var currentWoffer = null;
var currentTravelClass = '';



for(var index = 0; index < this.woffers.length; ++index) {

currentWoffer = this.woffers[index];

if(
((fromCode == "A_W") || (currentWoffer.matchesDepartureCode(fromCode))) &&
((toCode == "A_W") || (currentWoffer.matchesDestinationCode(toCode)))
)
{


currentTravelClass = currentWoffer.getBaseCabin();
if ((gTravelClass == 'M' || gTravelClass == 'W') && currentTravelClass.indexOf("M") < 0) {
continue;
}
if ((gTravelClass == 'J' || gTravelClass == 'F') && currentTravelClass.indexOf("J") < 0) {
continue;
}

if(includeNonSale == true) {

matchingWoffers.push(currentWoffer);
}



else if(currentWoffer.hasSaleFare()) {
matchingWoffers.push(currentWoffer);
}
}

}


return(matchingWoffers);

}
WoffersData.prototype.processError = function(ajaxResponse, text, exception)
{
throw new Error("Encountered a problem retreiving the JSON file." +
" Reported status is: " + text + ".\n\n" +
" Exception details are: " + exception.toString());
}
function Woffer(wofferData)
{
var tempOptionTitle = "";
var tempOptionValue = "";


this.originAirport = "";
this.destinationAirport = "";
this.destinationName = "";
this.regionCode = "";
this.priceType = "";
this.footnote = "";
this.prices = null;
this.addons = null;
this.wofferOptions = new Array();


if(wofferData.from)
{
this.originAirport = wofferData.from;
}


if(wofferData.to)
{
this.destinationAirport = wofferData.to;
}




if(wofferData.to_name)
{
this.destinationName = wofferData.to_name;
}
else if(wofferData.destinations)
{
this.destinationName = wofferData.destinations;
}


if(wofferData.region)
{
this.regionCode = wofferData.region;
}


if(wofferData.price_type)
{
this.priceType = wofferData.price_type;
}


if(wofferData.footnote)
{
this.footnote = wofferData.footnote;
}


if(wofferData.datesprices)
{
this.prices = new Prices(wofferData.datesprices);
}


if(wofferData.non_flight)
{
tempOptionTitle = "nonFlight";
tempOptionValue = wofferData.non_flight;
this.wofferOptions.push(new WofferOption(tempOptionTitle, tempOptionValue));
}


if(wofferData.non_flight_price)
{
tempOptionTitle = "nonFlightPrice";
tempOptionValue = wofferData.non_flight_price;
this.wofferOptions.push(new WofferOption(tempOptionTitle, tempOptionValue));
}
}
Woffer.prototype.getLowestPriceWithBaseCabin = function()
{
var lowestPrice = null;
var currentPrice = null;

for(var index = 0; index < this.prices.prices.length; ++index)
{
currentPrice = this.prices.prices[index];

if ((gTravelClass == 'M' || gTravelClass == 'W') && currentPrice.baseCabin != "M")
{
continue;
}
if ((gTravelClass == 'J' || gTravelClass == 'F') && currentPrice.baseCabin != "J")
{
continue;
}


if((lowestPrice == null) || (currentPrice.price < lowestPrice.price))
{
lowestPrice = currentPrice;
}
}
return(lowestPrice);
}
Woffer.prototype.matchesDepartureCode = function(fromCode) {
var matched = false;
var currentPrice = null;
var routeKey;




if((this.originAirport == fromCode) || (fromCode == "LON" && ((this.originAirport == "LHR") || (this.originAirport == "LGW") || (this.originAirport == "LCY")))) {

matched = true;
}


if(!matched)
{

for(var priceIndex = 0; priceIndex < this.prices.prices.length; ++priceIndex)
{
currentPrice = this.prices.prices[priceIndex];
if ("ALL" in currentPrice.addonPrices)
{
routeKey = fromCode.toUpperCase() + this.originAirport.toUpperCase();

if (routeKey in VALID_ADDONS)
{
matched = true;
break;
}
}
}
}

if(!matched)
{

for(var priceIndex = 0; priceIndex < this.prices.prices.length; ++priceIndex)
{
currentPrice = this.prices.prices[priceIndex];
if (fromCode.toUpperCase() in currentPrice.addonPrices)
{
matched = true;
break;
}
}
}

return(matched);

}
Woffer.prototype.matchesDestinationCode = function(toCode) {
var matched = false;


if(this.regionCode == toCode) {
matched = true;
}

return(matched);

}
Woffer.prototype.matchesPriceBand = function(fromPrice, toPrice) {
var matched = false;
var lowestPrice = null;
var currentPrice = null;

for(var index = 0; index < this.prices.prices.length; ++index) {
currentPrice = this.prices.prices[index];

if((lowestPrice == null) || (currentPrice.price < lowestPrice.price)) {
lowestPrice = currentPrice;
}
}

return(matched);

}
Woffer.prototype.hasSaleFare = function()
{
var matched = false;
var currentPrice = null;

for(var index = 0; index < this.prices.prices.length; ++index)
{
currentPrice = this.prices.prices[index];

if (currentPrice.upgradePrice == 0)
{
currentPrice.upgradePrice = null;
}

if ((gTravelClass == 'W' || gTravelClass == 'F') && currentPrice.upgradePrice == null)
{
continue;
}


if(currentPrice.valueFare == false)
{

matched = true;

break;
}
}

return(matched);
}
Woffer.prototype.getBaseCabin = function() {
var returnOption = "";
for(var index = 0; index < this.prices.prices.length; ++index)
{
returnOption = returnOption + this.prices.prices[index].baseCabin;
}

return(returnOption);
}
function Prices(priceData) {


this.prices = new Array();

var newPrice = null;


for(var index = 0; index < priceData.length; index++)
{
newPrice = new Price(priceData[index]);

if(newPrice.price && (newPrice.price != ""))
{
this.prices.push(new Price(priceData[index]));
}
}
}
function Price(priceData)
{
var tempPrice = 0;
var tempOptionTitle = "";
var tempOptionValue = 0;



this.price = null;
this.upgradePrice = null;
this.valueFare = false;
this.outboundFromDate = "";
this.outboundToDate = "";
this.addonPrices = new Array();
this.addonCabin = 0;
this.addonUpgrade = 0;
this.baseCabin = "";
this.wofferOptions = new Array();



if(priceData.fare_info && (priceData.fare_info.toUpperCase().search("VALUE") != -1)) {

this.valueFare = true;
}


if(priceData.price) {

tempPrice = priceData.price.replace(/\,/g, '');

this.price = Math.round(tempPrice);
}

if(priceData.upgrade_price) {

tempPrice = priceData.upgrade_price.replace(/\,/g, '');

this.upgradePrice = Math.round(tempPrice);
}


if(priceData.out_from) {
this.outboundFromDate = priceData.out_from;
}


if(priceData.out_to) {
this.outboundToDate = priceData.out_to;
}




if(priceData.optional1)
{
tempOptionTitle = "optional1";
tempOptionValue = priceData.optional1;
this.wofferOptions.push(new WofferOption(tempOptionTitle, tempOptionValue));
}


if(priceData.optional2)
{
tempOptionTitle = "optional2";
tempOptionValue = priceData.optional2;
this.wofferOptions.push(new WofferOption(tempOptionTitle, tempOptionValue));
}


if(priceData.optional3)
{
tempOptionTitle = "optional3";
tempOptionValue = priceData.optional3;
this.wofferOptions.push(new WofferOption(tempOptionTitle, tempOptionValue));
}


if(priceData.optional4)
{
tempOptionTitle = "optional4";
tempOptionValue = priceData.optional4;
this.wofferOptions.push(new WofferOption(tempOptionTitle, tempOptionValue));
}




if(priceData.addon_upgrade)
{

tempPrice = priceData.addon_upgrade.replace(/\,/g, '');
this.addonUpgrade = Math.round(tempPrice);
}

if(priceData.addon_cabin)
{

tempPrice = priceData.addon_cabin.replace(/\,/g, '');
this.addonCabin = Math.round(tempPrice);
this.addonPrices["ALL"] = new AddonPrice("ALL", Math.round(tempPrice), this.addonUpgrade);
}


if(priceData.base_cabin)
{
this.baseCabin = priceData.base_cabin;
}








var tempDepartureCode = "";


if(priceData.abz_add_on) {
tempDepartureCode = "ABZ";


tempPrice = priceData.abz_add_on.replace(/\,/g, '');


this.addonPrices[tempDepartureCode] = new AddonPrice(tempDepartureCode, Math.round(tempPrice),Math.round(tempPrice)-this.price);
}


if(priceData.man_add_on) {
tempDepartureCode = "MAN";


tempPrice = priceData.man_add_on.replace(/\,/g, '');


this.addonPrices[tempDepartureCode] = new AddonPrice(tempDepartureCode, Math.round(tempPrice),Math.round(tempPrice)-this.price);
}


if(priceData.edi_add_on) {
tempDepartureCode = "EDI";


tempPrice = priceData.edi_add_on.replace(/\,/g, '');


this.addonPrices[tempDepartureCode] = new AddonPrice(tempDepartureCode, Math.round(tempPrice),Math.round(tempPrice)-this.price);
}


if(priceData.ncl_add_on) {
tempDepartureCode = "NCL";


tempPrice = priceData.ncl_add_on.replace(/\,/g, '');


this.addonPrices[tempDepartureCode] = new AddonPrice(tempDepartureCode, Math.round(tempPrice),Math.round(tempPrice)-this.price);
}


if(priceData.gla_add_on) {
tempDepartureCode = "GLA";


tempPrice = priceData.gla_add_on.replace(/\,/g, '');


this.addonPrices[tempDepartureCode] = new AddonPrice(tempDepartureCode, Math.round(tempPrice),Math.round(tempPrice)-this.price);
}


if(priceData.jer_add_on) {
tempDepartureCode = "JER";


tempPrice = priceData.jer_add_on.replace(/\,/g, '');


this.addonPrices[tempDepartureCode] = new AddonPrice(tempDepartureCode, Math.round(tempPrice),Math.round(tempPrice)-this.price);
}


if(priceData.bfs_add_on) {
tempDepartureCode = "BFS";


tempPrice = priceData.bfs_add_on.replace(/\,/g, '');


this.addonPrices[tempDepartureCode] = new AddonPrice(tempDepartureCode, Math.round(tempPrice),Math.round(tempPrice)-this.price);
}

}
Price.prototype.getOption = function(optionKey) {
var returnOption = null;
var currentOption = null;

for(var index = 0; index < this.wofferOptions.length; ++index)
{
currentOption = this.wofferOptions[index];

if(currentOption.title == optionKey)
{
returnOption = currentOption;
break;
}
}

return(returnOption);
}
Price.prototype.hasAddonLocation = function(locationCode)
{
var matched = false;

try
{

if ("ALL" in this.addonPrices)
{
matched = true;
}
else if (locationCode in this.addonPrices)
{
matched = true;
}
}
catch(e){}

return(matched);
}
Price.prototype.getAddonPrice = function(locationCode)
{
var returnPrice = null;
var currentAddon = null;

try
{

if ("ALL" in this.addonPrices)
{
returnPrice = this.addonPrices["ALL"];
}
else if (locationCode in this.addonPrices)
{
returnPrice = this.addonPrices[locationCode];
}
}
catch(e){}
return(returnPrice);

}
function AddonPrice(location, price, addon)
{

this.location = location;
this.price = price;
this.addon = addon;

}
function WofferOption(title, value)
{

this.title = title;
this.value = value;

}
function WofferTable(elementId, wofferData, fromCode, toCode)
{
this.elementId = elementId;
this.wofferData = wofferData;
this.fromCode = fromCode;
this.toCode = toCode;
this.footnotes = new Array();
this.includeNonSale = false;
}
WofferTable.prototype.processTravelClassEvent = function(element) {
gTravelClass = element.getAttribute("value");

this.buildOutput();
}
WofferTable.prototype.processFromChange = function(element)
{
for(var index = 0; index < element.options.length; ++index) {

if(element.options[index].selected) {
this.fromCode = element.options[index].value;


gFromCode = this.fromCode;

break;
}
}

this.buildOutput();



}
WofferTable.prototype.processRegionChangeEvent = function(element)
{

var clickedRegionCode = element.getAttribute("regionCode");







this.toCode = clickedRegionCode;

var imageNavItems = $(".regionNavigation li a");


var CaribLinkItem = $(".LAClink");


imageNavItems.removeClass("selected");




clickedRegionCode = clickedRegionCode.toLowerCase();

$(".regionNavigation li." + clickedRegionCode + " a").addClass("selected");



this.buildOutput();


}
WofferTable.prototype.trackChanges = function()
{



trackingInfo["MARSALE1"] = gNavType;
trackingInfo["LKDeparturePoint"] = this.fromCode;
trackingInfo["MARSALE2"] = this.toCode;
trackingInfo["pageidextra"] = gNavType + "-" + this.toCode;


document.getElementById("t-tracking-fragment").innerHTML = vsDoTracking();
}
WofferTable.prototype.buildOutput = function()
{


$("#tablePodBottom").show();
$("#tableDiv").slideUp(500, function() {gWofferTable.buildOutput2();
$("#tableDiv").slideDown(500);
$("#tablePodBottom").hide();
$("#salepageBottom").show();});
}
WofferTable.prototype.buildOutput2 = function()
{
var valueFareFooter = false;
var priceHTML = "";
var datesHTML = "";
var upgradeHTML = "";
var prices = null;
var currentPrice = null;
var priceType = "";
var tempPrice = 0;
var tempHTML = "";
var rowID;
var nonFlightTokens;
var tempUpgradeData;
var	usedPriceCount = 0;

var lb_fromCode;
var lb_toCode;

this.footnotes.length = 0;




tempHTML += "<table id=\"table1\" class=\"tablesorter peekFix ngtable\" cellspacing=\"0\" border=\"0\" summary=\"World offers fares\" style=\"width: 100%;\"><a name=\"top\"></a>\n";
tempHTML += "<thead>\n";
tempHTML += "<tr valign=\"top\" >\n";
for(var index = 0; index < TABLE_HEADERS.length; ++index) {
if(TABLE_HEADERS[index][4] == gPageType) {
tempHTML += "<th id=\"tableHeaderCell" + index + "\" colspan=\"" + TABLE_HEADERS[index][1] + "\" title=\"" + TABLE_HEADERS[index][2] + "\">";
if (index == 2 && (this.toCode == "NAM"||this.toCode == "EUR")) {
tempHTML += "Holidays per person from<br/>" + TABLE_HEADERS[index][3] +	"</th>\n";
}
else {
tempHTML +=	TABLE_HEADERS[index][0] + TABLE_HEADERS[index][3] +	"</th>\n";
}
}
}
tempHTML += "</tr>\n";
tempHTML += "</thead>";



tempHTML += "<tbody id=\"table2body\">";

var matchingWoffers = null;
var currentWoffer = null;
var currentWofferPrice = null;
var tempOption = null;

var tempOption2 = null;
if ( TECHNICAL_DIFFICULTIES ) {
tempHTML += "<tr><td class=\"noMatchResult\" colspan=\"9\">" + TECHNICAL_DIFFICULTIES_MESSAGE + ".</td></tr>\n";
} else {

matchingWoffers = gWoffersData.getWoffersForLocations(this.fromCode, this.toCode, this.includeNonSale);
}





if ((this.toCode == "EUR") && (gTravelClass == "W" || gTravelClass == "F")) {
matchingWoffers.length = 0;
}

if(matchingWoffers.length <= 0)
{
tempHTML += "<tr><td class=\"noMatchResult\" colspan=\"9\">Sorry, no destinations available from ";
tempHTML += getAirportName(this.fromCode) + " match your search";
tempHTML += ".</td></tr>\n";
}

else
{
matchingWoffers.sort(function(first, second)
{
var result = 0;


if((first.originAirport == this.gWofferTable.fromCode) && (second.originAirport != this.gWofferTable.fromCode)) {

result = -1;
}


else if((first.originAirport != this.gWofferTable.fromCode) && (second.originAirport == this.gWofferTable.fromCode)) {

result = 1;
}



else if(first.destinationName < second.destinationName) {
result = -1;
}

else if(first.destinationName > second.destinationName) {
result = 1;
}

return(result);

});

}
var rowClass = "";
var countRowsToDisplay = 0;



for(var index = 0; index < matchingWoffers.length; ++index)
{
currentWoffer = matchingWoffers[index];
currentWofferPrice = null;
rowID = "wofferRow" + index;
rowClass="";
var tempTableRowHTML = "";
gFlightFound = false;
gPackageFound = false;
var urlTCO = null;


currentWofferPrice = currentWoffer.getLowestPriceWithBaseCabin();



if (this.toCode == "EUR")
{
tempOption = currentWofferPrice.getOption("optional4");
if(tempOption && tempOption.value == "new" && !currentWofferPrice.valueFare)
{
rowClass = "justadded";
}
}
tempOption2 = currentWofferPrice.getOption("optional3");
if(tempOption2 && tempOption2.value == "so" && !currentWofferPrice.valueFare)
{
rowClass = "specialoffer";
}
tempTableRowHTML += "<tr id=\"" +rowID + "\"" + (rowClass!=""?" class='" + rowClass + "'":"") + ">\n";




tempTableRowHTML +="<td class=\"destinationCell\">";
urlTCO = currentWofferPrice.getOption("optional4");
var destinationTag = currentWoffer.destinationName;
var destinationTagNoBrackets = destinationTag.split("(");
var destinationTagNoSpace = destinationTagNoBrackets[0];
destinationTagNoSpace = destinationTagNoSpace.replace(/\s+$/, '');
if (urlTCO != null) {
tempTableRowHTML += '<a href="' + urlTCO.value;																					
			tempTableRowHTML += "\" alt=\"" + destinationTagNoSpace + ".\" title=\"See our destination guide for " + destinationTagNoSpace + ".\">";
			// Add the departure name
			tempTableRowHTML += currentWoffer.destinationName + "</a>";
			tempTableRowHTML += '<div class="locationThumbnail">';
			tempTableRowHTML += '<a href="' + urlTCO.value;
tempTableRowHTML += "\" alt=\"" + destinationTagNoSpace + ".\"  title=\"See our destination guide for " + destinationTagNoSpace + ".\">";
tempTableRowHTML += getHTMLforThumbnail(currentWoffer.destinationAirport, destinationTagNoSpace) + "</a>";
tempTableRowHTML += "</div>";
} else {
tempTableRowHTML += currentWoffer.destinationName;
tempTableRowHTML += '<div class="locationThumbnail">';
tempTableRowHTML += "<img height='93' width='160' alt='" + destinationTagNoSpace.replace(/'/g, '&acute;') + ".' ";
			tempTableRowHTML += "src='/cms/global/assets/images/promotion/uk/novsale2009/thumbnails/thumbnail_" + currentWoffer.destinationAirport + ".jpg'/>";
//			tempTableRowHTML += getHTMLforThumbnail(currentWoffer.destinationAirport, destinationTagNoSpace);
			tempTableRowHTML += "</div>";
		}

		if ( currentWoffer.footnote ) {
			var footnotenumber = currentWoffer.footnote.match(/^[^\sA-Za-z]+/);
			if (footnotenumber && footnotenumber.length == 1) {
				tempTableRowHTML += "&nbsp;<sup>" + footnotenumber[0] + "</sup>";
			}
		}

		// London ALL issue
		if(gFromCode == "LON" ) {
			tempTableRowHTML += "<span class=\"londonAll\">from "+getAirportName(currentWoffer.originAirport)+"</span>";
		} else if ( gFromCode != "LON" && gFromCode != "LHR" && gFromCode != "LGW" && gFromCode != "LCY" && gFromCode != currentWoffer.originAirport ) {
			tempTableRowHTML += "<span class=\"londonAll\">via "+getAirportName(currentWoffer.originAirport)+"</span>";
		}

		tempTableRowHTML += "</td>\n";
	
		///////////////////////////////////////////////////////////////////////
		// Hybrid Flights cell
		///////////////////////////////////////////////////////////////////////
		if (gPageType == "HYBRID") {
			tempTableRowHTML += getHybridFlightCell(currentWoffer, currentWofferPrice, this.fromCode, this.includeNonSale);
		}
	
		///////////////////////////////////////////////////////////////////////
		// Flight + Hotel cell
		///////////////////////////////////////////////////////////////////////
		if (gPageType == "HYBRID") {
			tempTableRowHTML += getDealCell(currentWoffer.destinationAirport, currentWoffer.originAirport, this.fromCode);
		}

		///////////////////////////////////////////////////////////////////////
		// Flights cell
		///////////////////////////////////////////////////////////////////////
		if (gPageType == "FLIGHTS") {
			tempTableRowHTML += getFlightCell(currentWoffer, this.fromCode, this.includeNonSale);
		}

		///////////////////////////////////////////////////////////////////////
		// Flight + Car cell
		///////////////////////////////////////////////////////////////////////
		//tempHTML += getCarCell(currentWoffer.destinationAirport, currentWoffer.originAirport, this.fromCode);


			
		///////////////////////////////////////////////////////////////////////
		// Footnotes
		///////////////////////////////////////////////////////////////////////
		// If the current woffer has a footnote...
		if(currentWoffer.footnote) {
			// ...add it to the list
			this.addFootnote(currentWoffer.footnote);
		}
	
		// November sale 2009 
		if (gTravelClass == 'F' || gTravelClass == 'W') {
			if (gFlightFound == true || gPackageFound == true) {
				++countRowsToDisplay;
				tempHTML += tempTableRowHTML;
			} else {
				// do not add destination row to table
			}
		} else {
			++countRowsToDisplay;
			tempHTML += tempTableRowHTML;
		}
	
	
	} // End for all matching woffers


	/*if ((gTravelClass == 'F' || gTravelClass == 'W') && this.toCode == 'EUR') {
		tempHTML += "<tr><td class=\"noMatchResult\" colspan=\"3\">Sorry, no destinations available from ";
		tempHTML += getAirportName(this.fromCode) + " match your search";
		tempHTML += ".</td></tr>";
	} */

// JI commented out following as seems to add double message ("Sorry..." message already created before this)
	/*if (countRowsToDisplay == 0) {
		tempHTML += "<tr><td class=\"noMatchResult\" colspan=\"3\">Sorry, no destinations available from ";
		tempHTML += getAirportName(this.fromCode) + " match your search";
		tempHTML += ".</td></tr>";
	}*/
	
	// Close the HTML table tag
	tempHTML += "</tbody>\n</table>";		// DAR 30AUG

	///////////////////////////////////////////////////////////////////////////
	// Update the DOM with the new table
	///////////////////////////////////////////////////////////////////////////
	$("#tableDiv").html(tempHTML);

	// Initialise the table (close all 'detail' divs etc)
	$(".flightDetail").hide();
	$(".datesDetail").hide();
	$(".flightOutlineDup").hide();
	$(".dealDetail").hide();



	$(".flightCell .twiddly").toggle(
      function () {
        $(this).html("show less travel dates");
		$(this).parent().children('.flightDetail').show().children().show();   
	  },
      function () {
        $(this).html("show more travel dates");
		$(this).parent().children('.flightDetail').hide().children().hide();   
      }
    );


/*
	// register event handlers for clickable elements of the new table
	// If we click a summary twisty, close the summary and open the detail
	$(".flightCell .twiddly").click(function() {
		 // $(this).hide();
		 // $(this).parent().children('.flightOutline').hide();
		 $(this).parent().children('.flightDetail').show().children().show();
	});

	// If we click a detail twisty, close the detail and open the summary
	$(".flightCell .flightDetail .twiddly").click(function() {
		 $(this).parent().hide();
		 $(this).parent().parent().children(".twiddly").show();
		 //$(this).parent().parent().children(".flightOutline").show();
	});
*/

	// register event handlers for clickable elements of the new table
	// If we click a summary twisty, close the summary and open the detail
	$(".datesCell .twiddly").click(function() {
		 $(this).hide();
		 $(this).parent().children('.datesOutline').hide();
		 $(this).parent().children('.datesDetail').show().children().show();
	});

	// If we click a detail twisty, close the detail and open the summary
	$(".datesCell .datesDetail .twiddly").click(function() {
		 $(this).parent().hide();
		 $(this).parent().parent().children(".twiddly").show();
		 $(this).parent().parent().children(".datesOutline").show();
	});

	$(".deal .twiddly").click(function() {
		 $(this).parent().parent().children().toggle();
	});
	
	///////////////////////////////////////////////////////////////////////////
	// Initial table sort
	///////////////////////////////////////////////////////////////////////////
	if(matchingWoffers && matchingWoffers.length > 0) {
		
		//removed table-sorting due to safari/chrome/webkit bug
		
	}

	// for the sale fares only nav, display any justadded routes add the top of the table, and add two headers.
	// Remove the headers on resorting.
	if(!this.includeNonSale) {
		var trjustadded = $("tr.justadded");
		
		if(trjustadded.length) {
			var tbody = trjustadded[0].parentNode;
			// move all justadded rows to the top of the table
			$(tbody).prepend(trjustadded);
			// fix the odd/even zebra stripes
			$(tbody).find("tr:odd").removeClass("even").addClass("odd");
			$(tbody).find("tr:even").removeClass("odd").addClass("even");
			
			$("tr.justadded:first").before( "<tr class='sectionHeader'><th colspan='5'>New routes added</th></tr>" );
			$("tr.justadded:last").after( "<tr class='sectionHeader'><th colspan='5'>Also on sale</th></tr>" );
			
			// make sure to remove these new sectionHeader rows when the table sort order is changed
			$(".header").click(function(){ $(".sectionHeader").remove() });
		}
	}

	// similar procedure to the previous one, display any specialoffer routes add the top of the table, and add two headers.
	if(!this.includeNonSale) {
		var trjustadded = $("tr.specialoffer");
		
		if(trjustadded.length) {
			var tbody = trjustadded[0].parentNode;
			// move all justadded rows to the top of the table
			$(tbody).prepend(trjustadded);
			// fix the odd/even zebra stripes
			$(tbody).find("tr:odd").removeClass("even").addClass("odd");
			$(tbody).find("tr:even").removeClass("odd").addClass("even");
			
			$("tr.specialoffer:first").before( "<tr class='spoffHeader'><th>This week only</th><th>&nbsp;</th><th colspan='3'>GET 3 NIGHTS HOTEL FROM &pound;50<br />Book by midnight Wednesday</th></tr>" );
			$("tr.specialoffer:last").after( "<tr class='spoffHeader2'><th colspan='5'>Book by 22 September 2009</th></tr>" );
			
			// make sure to remove these new sectionHeader rows when the table sort order is changed
			$(".header").click(function(){ $(".spoffHeader").remove() });
			$(".header").click(function(){ $(".spoffHeader2").remove() });
		}
	}

	///////////////////////////////////////////////////////////////////////////
	// Update table heading with the 'from' and 'to' details
	///////////////////////////////////////////////////////////////////////////
//	document.getElementById("tableSelectionHeading").innerHTML = "Flights from " + getAirportName(this.fromCode) + " to " + getAirportName(this.toCode);
	
	
	///////////////////////////////////////////////////////////////////////////
	// Add any footnotes under the table
	///////////////////////////////////////////////////////////////////////////
	var tempFootnoteHTML = "<p>";
	
	// Add any/all footnotes to the temp HTML
	for(var footnoteIndex = 0; footnoteIndex < this.footnotes.length; ++footnoteIndex) {
		tempFootnoteHTML += this.footnotes[footnoteIndex] + "";	
	}

	tempFootnoteHTML += "</p>";
	
	// Update the DOM using the constructed HTML
	$('#footnotes').empty().append(tempFootnoteHTML);

	// Set plan trip frag to the correct 'package' selection
	// GK: NOTE - This is not ideal placed here.  It should be in 
	// doc.ready() but there are issues with ordering of events in the 
	// DP plantrip frag doc.ready().  This will have to do untill we get
	// more time
	initialisePlantrip();

} // End buildOutput method


//////////////////////////////////////////////////////////////////////////////
// 
//////////////////////////////////////////////////////////////////////////////
WofferTable.prototype.addFootnote = function(footnote) 
{
	var foundFootnote = false;
	
	// ...see if it has already been recorded
	for(var footnoteIndex = 0; footnoteIndex < this.footnotes.length; ++footnoteIndex) 
	{
		if(this.footnotes[footnoteIndex] == footnote) 
		{
			foundFootnote = true;	
			
			break;
		}
	}

	// If the footnote is not already in our list...
	if(!foundFootnote) 
	{
		// ...add it
		this.footnotes.push(footnote);	
	}
		
} // End addFootnote() method

//////////////////////////////////////////////////////////////////////////////
// 
//////////////////////////////////////////////////////////////////////////////
function getAirportName(airportCode) 
{
	var airportName = "";
	
	for(var locationIndex = 0; locationIndex < LOCATIONS.length; ++locationIndex) 
	{
		if(LOCATIONS[locationIndex][0] == airportCode) 
		{
			airportName = LOCATIONS[locationIndex][1];
			
			break;
		}
	}
	
	return(airportName);
}

//////////////////////////////////////////////////////////////////////////////
// Return true if we are postpin
//////////////////////////////////////////////////////////////////////////////
function isPostPin() 
{
	var isPostpin = false;
	
	if(document.nav_form.logintype.value != 'public') 
	{
		isPostpin = true;
	}
	
	return(isPostpin);
}

//////////////////////////////////////////////////////////////////////////////
// Return the supplied price with any adjustments based on the following
// criterion...
// 1) Only applies adjustment if we are postpin
// 2) can apply different adjustments depending on supplied priceType which
//    should either be ONEWAY_PRICE_TYPE or RETURN_PRICE_TYPE.
//////////////////////////////////////////////////////////////////////////////
function getAdjustedPrice(originalPrice, priceType) 
{
	// Initialise the price to the supplied one
	var tempPrice = originalPrice;
	
	// If we are postpin, then apply the relevant adjustment
	if(isPostPin()) 
	{
		switch(priceType) {
			case ONEWAY_PRICE_TYPE: {
				tempPrice = parseInt(tempPrice) - parseInt(ONEWAY_PRICE_POSTPIN_DISCOUNT);
				
				break;
			}
			
			case RETURN_PRICE_TYPE: {
				tempPrice = parseInt(tempPrice) - parseInt(RETURN_PRICE_POSTPIN_DISCOUNT);
				
				break;
			}
			
		} // End switch
			
	} // End if(isPostPin)

	return(tempPrice);;
}

//////////////////////////////////////////////////////////////////////////////
// Take a price and return the modified price based on any discount for
// postpin users.
//////////////////////////////////////////////////////////////////////////////
function getAdjustedHotelPrice(price) 
{
	var tempPrice = parseFloat(price);

	if(isPostPin()) 
	{
		var discount = HOTEL_PRICE_POSTPIN_DISCOUNT;
		
		if(discount) 
		{
			discount = tempPrice * (parseFloat(discount) / 100);
			tempPrice -= discount;
		}
	}
	
	// Round up to nearest whole number
	return Math.ceil(tempPrice);
}

//////////////////////////////////////////////////////////////////////////////
// Get cookie parameter
//////////////////////////////////////////////////////////////////////////////
function getCookie(cName)
{
	if (document.cookie.length > 0)
	{
		cStart=document.cookie.indexOf(cName + "=");
		
		if(cStart!=-1)
		{
			cStart = cStart + cName.length + 1;
			
			cEnd = document.cookie.indexOf(";" , cStart);
			
			// is this the last one?
			if(cEnd==-1)
			{
				cEnd = document.cookie.length;
			}
			
			return unescape(document.cookie.substring(cStart,cEnd));
		}
	}
	
	return "";
	
} // End getCookie()

//////////////////////////////////////////////////////////////////////////////
// Set cookie parameter
//////////////////////////////////////////////////////////////////////////////
function setCookie(cName,cValue)
{
	var expireDate = new Date();
	expireDate.setFullYear(expireDate.getFullYear() + 1);
	
	document.cookie = cName +  "=" + escape(cValue) + "; expires=" + expireDate;

	switch(cValue) {
		case 0: { 
			gLinkType = "FXPAGE";			
			break;
		}
		
		case 1: {
			gLinkType = "LPBMPAGE";		
			break;
		}
		
		default: { 
			gLinkType = "FXPAGE";			
		}
	}
}

//////////////////////////////////////////////////////////////////////////////
// 
//////////////////////////////////////////////////////////////////////////////
function isAddon(wofferDeparture, requiredDeparture)
{
	var routeKey;
	var isAddon = true;
	
	
	
		// if London based then should not be an add-on regardless
		if((wofferDeparture == requiredDeparture) || ((requiredDeparture == "LON") && ((wofferDeparture == "LHR") || (wofferDeparture == "LGW") || (wofferDeparture == "LCY")))) 
		{
			isAddon = false;
		}
		else
		{
			// now check to see if we fly from requiredDeparture point to the orginal
			// wofferDeparture airport otherwise it can't be an add-on
routeKey = requiredDeparture.toUpperCase() + wofferDeparture.toUpperCase();
if (routeKey in VALID_ADDONS)
{
isAddon = true;
}
else
{
isAddon = false;
}
}

return(isAddon);

}
function tb_plan_book()
{



var params = {};
vsSplitParameters($("#batbox_iframeContent")[0].src,params);
fromCode = (params.from ? params.from : "");
toCode = (params.to ? params.to : "");

self.parent.location = "/main/fx?fromPkg=" + fromCode + "&to=" + toCode;
}
function FXUrl(fromCode, currentWoffer)
{
var url = "/main/FX?to=";
url += currentWoffer.destinationAirport + "&amp;fromPkg=";
url += fromCode;
url += "&amp;cabin="+gTravelClass;
return url;
}
function FXUpgradeUrl(fromCode, currentWoffer)
{
var url = "/main/FX?to=";
url += currentWoffer.destinationAirport + "&amp;fromPkg=";
url += fromCode;
url += "&amp;cabin=W";
return url;
}
function LPBMUrl(fromCode, currentWoffer)
{
var url = "";

if ( ((fromCode == "LCY") || (fromCode == "LGW") || (fromCode == "LHR") || (fromCode == "LON")) && (currentWoffer.destinationAirport != "BWI") )
{
url = "http://www.britishairways.com/travel/low-price-finder/public/en_gb?eId=113021&origin=";
url += fromCode + "&destination=";
url += currentWoffer.destinationAirport + "&amp;cabin=" + gTravelClass;
}
else
{
url = "/main/FX?to=";
url += currentWoffer.destinationAirport + "&amp;fromPkg=";
url += fromCode;
url += "&amp;cabin="+gTravelClass;
}
return url;
}
function StringBuilder(str)
{
if ( $.browser.msie )
{
var internal = str?[str]:[];

this.append = function(str)
{
internal[internal.length]=str;
}

this.toString = function()
{
return internal.join("");
}
}
else
{
var internal = str || "";
this.append = function(str)
{
internal+=str;
}
this.toString = function()
{
return internal;
}
}

return this;
}
function getHybridFlightCell(currentWoffer, currentPrice, sOrigin, includeNonSale)
{
var flightHTML = "<td class='flightCell'>";
var flightOutline = "";
var flightOutlineDup = "";
var notNullPrice = true;
var leadPrice = "";
var leadOutboundFromDate = "";
var leadOutboundToDate = "";

var priceFirst = currentPrice.upgradePrice;

if (priceFirst == null && (gTravelClass == 'F' || gTravelClass == 'W'))
{
gFlightFound = false;
return ('<td></td>');
}
gFlightFound = true;

switch (gTravelClass) {
case 'M': {
gTravelClassName = "Economy";
break;
}
case 'W': {
gTravelClassName = "Premium Economy";
break;
}
case 'J': {
gTravelClassName = "Business/Club";
break;
}
case 'F': {
gTravelClassName = "First";
break;
}
}

leadPrice = currentPrice.price;
leadOutboundFromDate = currentPrice.outboundFromDate;
leadOutboundToDate = currentPrice.outboundToDate;

if(isAddon(currentWoffer.originAirport, sOrigin))
{

tempPrice = parseInt(currentPrice.getAddonPrice(sOrigin).price);
}
else
{

tempPrice = parseInt(currentPrice.price);
}

if (priceFirst != null && (gTravelClass == 'F' || gTravelClass == 'W'))
{

if(isAddon(currentWoffer.originAirport, sOrigin))
{

tempPrice = parseInt(currentPrice.getAddonPrice(sOrigin).addon);
}

else
{

tempPrice = parseInt(currentPrice.upgradePrice)
}
}
lb_toCode = currentWoffer.destinationAirport;

if(this.fromCode == "LON")
{
lb_fromCode = currentWoffer.originAirport;
}
else
{
lb_fromCode = sOrigin;
}


flightOutline = "<div class='flightOutline'>"


if(gLinkType == "FXPAGE")
{
flightOutline += '<div class="leadPrice"><a href="' + FXUrl(lb_fromCode, currentWoffer) + '" title="Plan or book.">';
}
else if ((gLinkType != "FXPAGE") && (currentWoffer.destinationAirport=="BWI"))
{
flightOutline += '<div class="leadPrice"><a href="' + LPBMUrl(lb_fromCode, currentWoffer) + '" title="Plan or book.">';
}
else
{
flightOutline += '<div class="leadPrice"><a href="' + LPBMUrl(lb_fromCode, currentWoffer) + '" title="See lowest price by month.">';
}

flightOutline += "&pound;" + tempPrice;
flightOutlineDup = "<div class='flightOutlineDup'>"


if(gLinkType == "FXPAGE")
{
flightOutlineDup += '<div class="leadPrice"><a href="' + FXUrl(lb_fromCode,currentWoffer) + '" title="Plan or book.">';
}
else if ((gLinkType != "FXPAGE") && (currentWoffer.destinationAirport=="BWI"))
{
flightOutlineDup += '<div class="leadPrice"><a href="' + LPBMUrl(lb_fromCode, currentWoffer) + '" title="Plan or book.">';
}
else
{
flightOutlineDup += '<div class="leadPrice"><a href="' + LPBMUrl(lb_fromCode, currentWoffer) + '" title="See lowest price by month.">';
}

flightOutlineDup += "&pound;" + tempPrice;
if(currentWoffer.priceType == RETURN_PRICE_TYPE)
{
priceType = "return flight"
}

else
{
priceType = "one-way flight";
}

flightOutline += "</a><span class='priceType'>"+priceType+"</span>";
flightOutlineDup += "</a><span class='priceType'>"+priceType+"</span>";
if(currentPrice.valueFare)
{
flightOutline += "<sup>1</sup>";
flightOutlineDup += "<sup>1</sup><br/>";
valueFareFooter = true;
}

flightOutline += "</div><span class=\"travelClass\"><a href=\"javascript:popUpScrolling('/main/pop_cabininfo',590,630)\" title=\"Class of travel.\">"+gTravelClassName+"</a></span>";
flightOutlineDup += "</div>";


flightOutline += "<div class=\"leadDates\">";
flightOutline += currentPrice.outboundFromDate + " - " + currentPrice.outboundToDate;
flightOutline += "</div>";
flightOutline += "</div>"
flightOutlineDup += "<div class=\"leadDates\">";
flightOutlineDup += currentPrice.outboundFromDate + " - " + currentPrice.outboundToDate;
flightOutlineDup += "</div>";
flightOutlineDup += "</div>"
flightDetail = "<div class='flightDetail'>"
flightDetail += "<div class='detail'>";
prices = currentWoffer.prices.prices;

usedPriceCount = 0;
for(var pricesIndex = 0; pricesIndex < prices.length; ++pricesIndex)
{

if(gLinkType == "FXPAGE")
{
flightDetail += '<div class="detailPrice"><a href="' + FXUrl(lb_fromCode,currentWoffer) + '" title="Plan or book.">';
}
else
{
flightDetail += '<div class="detailPrice"><a href="' + LPBMUrl(lb_fromCode,currentWoffer) + '" title="Plan or book.">';
}

currentPrice = prices[pricesIndex];

if(currentPrice.valueFare && (includeNonSale == false))
{

}
else
{

++usedPriceCount;

if (currentPrice.price == leadPrice && currentPrice.outboundFromDate == leadOutboundFromDate && currentPrice.outboundToDate == leadOutboundToDate)
{
continue;
}

if(isAddon(currentWoffer.originAirport, sOrigin))
{
if(currentPrice.getAddonPrice(sOrigin) == null)
{

--usedPriceCount;
notNullPrice = false;
}
else
{
tempPrice = parseInt(currentPrice.getAddonPrice(sOrigin).price);


if ((gTravelClass == 'F' || gTravelClass == 'W') && priceFirst != null)
{

tempPrice = parseInt(currentPrice.getAddonPrice(sOrigin).addon);
}
}
}


else
{
tempPrice = parseInt(currentPrice.price);


if ((gTravelClass == 'F' || gTravelClass == 'W') && priceFirst != null)
{

tempPrice = parseInt(currentPrice.upgradePrice);
}
}



if(currentPrice.valueFare == false)
{

tempPrice = getAdjustedPrice(tempPrice, currentWoffer.priceType);
}
if(notNullPrice)
{
flightDetail += "&pound;" + tempPrice;

if(currentPrice.valueFare)
{
flightDetail += "</a><sup>1</sup> ";
valueFareFooter = true;
}
else
{
flightDetail += "</a></div> ";
}

flightDetail += '<div class="detailDates">' + currentPrice.outboundFromDate + ' - ' + currentPrice.outboundToDate + '</div>';

flightDetail += '<div class="clearBoth peekFix"></div>';
}

}

}
flightDetail += "</div>"
flightDetail += "</div>"
if(usedPriceCount > 1)
{
flightHTML += flightOutline;
flightHTML += "<div class='twiddly'>";
flightHTML += "show more travel dates";
flightHTML += "</div>";
flightHTML += flightDetail;
}
else
{
flightHTML += flightOutline;
flightHTML += flightOutlineDup;
}



flightHTML += "</td>";
return flightHTML;
}
function getFlightCell(currentWoffer, sOrigin, includeNonSale)
{
var flightHTML = "<td class='flightCell'>";
var datesHTML = "<td class='datesCell'>";
var actionHTML = "<td class='actionCell'>";
var flightOutline = "";
var flightOutlineDup = "";
var datesOutline = "";
var datesOutlineDup = "";
var actionOutline = "";
var notNullPrice = true;
var url = "";


currentPrice = currentWoffer.getLowestPriceWithBaseCabin();


if(isAddon(currentWoffer.originAirport, sOrigin))
{
tempPrice = parseInt(currentPrice.getAddonPrice(sOrigin).price);
}

else
{
tempPrice = parseInt(currentPrice.price);
}



if(currentPrice.valueFare == false)
{

tempPrice = getAdjustedPrice(tempPrice, currentWoffer.priceType);
}

lb_toCode = currentWoffer.destinationAirport;
if(this.fromCode == "LON")
{
lb_fromCode = currentWoffer.originAirport;
}
else
{
lb_fromCode = sOrigin;
}



if(gLinkType == "FXPAGE")
{
url = FXUrl(lb_fromCode,currentWoffer);
}
else
{
url = LPBMUrl(lb_fromCode,currentWoffer);
}


flightOutline = "<div class='flightOutline'>"
flightOutline += '<div class="leadPrice"><a href="' + url + '" title="Plan or book.">';
flightOutline += "&pound;" + tempPrice;


flightOutlineDup = "<div class='flightOutlineDup'>"
flightOutlineDup += '<div class="leadPrice"><a href="' + url + '" title="Plan or book.">';
flightOutlineDup += "&pound;" + tempPrice;

actionOutline += '<a href="' + url + '" title="Plan or book.">Plan or book</a>';
actionHTML += actionOutline + '</td>';

if(currentWoffer.priceType == RETURN_PRICE_TYPE)
{
priceType = " return"
}
else
{
priceType = " one-way";
}

flightOutline += priceType;
flightOutlineDup += priceType;

if(currentPrice.valueFare)
{
flightOutline += "<sup>1</sup><br />";
flightOutlineDup += "<sup>1</sup><br />";
valueFareFooter = true;
}

flightOutline += "</a></div>";
flightOutlineDup += "</a></div>";


flightOutline += "</div>"
flightOutlineDup += "</div>"

datesOutline = "<div class='datesOutline'>"
datesOutline += "<div class=\"leadDates\">";
datesOutline += currentPrice.outboundFromDate + " - " + currentPrice.outboundToDate;
datesOutline += "</div>";
datesOutline += "</div>";
datesOutlineDup = "<div class='datesOutlineDup'>"
datesOutlineDup += "<div class=\"leadDates\">";
datesOutlineDup += currentPrice.outboundFromDate + " - " + currentPrice.outboundToDate;
datesOutlineDup += "</div>";
datesOutlineDup += "</div>";

flightDetail = "<div class='flightDetail'>"
flightDetail += "<div class='detail'>";
datesDetail = "<div class='datesDetail'>"
datesDetail += "<div class='twiddly'>";
datesDetail += "<img height='9' width='9' title='Click to show less details.' alt='Minus sign.' src='/cms/global/assets/images/promotion/uk/may_campaign_2009/twisty-open.gif'/>";
datesDetail += "</div>";
datesDetail += "<div class='detail'>";
prices = currentWoffer.prices.prices;

usedPriceCount = 0;
for(var pricesIndex = 0; pricesIndex < prices.length; ++pricesIndex)
{
flightDetail += '<div class="detailPrice"><a href="' + getDpUrl(currentWoffer.destinationAirport, currentWoffer.originAirport, lb_fromCode) + '" title="Plan or book.">';
currentPrice = prices[pricesIndex];

if(currentPrice.valueFare && (includeNonSale == false)) {

}

else {
++usedPriceCount;


if(isAddon(currentWoffer.originAirport, sOrigin)) {
if(currentPrice.getAddonPrice(sOrigin) == null) {

--usedPriceCount;
notNullPrice = false;
}

else {
tempPrice = parseInt(currentPrice.getAddonPrice(sOrigin).price);
}
}


else {
tempPrice = parseInt(currentPrice.price);
}



if(currentPrice.valueFare == false) {

tempPrice = getAdjustedPrice(tempPrice, currentWoffer.priceType);
}
if(notNullPrice) {
flightDetail += "&pound;" + tempPrice + priceType;

if(currentPrice.valueFare) {
flightDetail += "</a><sup>1</sup> ";
valueFareFooter = true;
}

else {
flightDetail += "</a></div> ";
}

datesDetail += '<div class="detailDates">' + currentPrice.outboundFromDate + ' - ' + currentPrice.outboundToDate + '</div>';
}

}

}
flightDetail += "</div>"
flightDetail += "</div>"
datesDetail += "</div>"
datesDetail += "</div>"
if(usedPriceCount > 1) {
flightHTML += flightOutline;
flightHTML += flightDetail;
datesHTML += "<div class='twiddly'>";
datesHTML += "<img height='9' width='9' title='Click to show more details.' alt='Plus sign.' src='/cms/global/assets/images/promotion/uk/may_campaign_2009/twisty-closed.gif'/>";
datesHTML += "</div>";
datesHTML += datesOutline;
datesHTML += datesDetail;
}
else
{
flightHTML += "<div class='twiddly'>";

flightHTML += "</div>";
flightHTML += flightOutline;
flightHTML += flightOutlineDup;

datesHTML += "<div class='twiddly'>";

datesHTML += "</div>";
datesHTML += datesOutline;
datesHTML += datesOutlineDup;
}
flightHTML += "</td>";
datesHTML += "</td>";

return flightHTML+datesHTML+actionHTML;
}

