var SOURCE_URL = "/cms/global/json/july08woffers/july08woffersdata.json";
var SOURCE_TYPE = "json";
var DOCUMENT_ELEMENT_ID = "tableDiv"
var ONEWAY_PRICE_POSTPIN_DISCOUNT = 0;
var RETURN_PRICE_POSTPIN_DISCOUNT = 20;
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."],
["Price", "1", "Click to change sort order."],
["Travel dates <span class=\"normalText\"><br />Click <img src=\"/cms/global/assets/images/promotion/uk/jan08woffers/twisty-closed.gif\" width=\"9\" height=\"9\" alt=\"Plus sign.\" /> to show more dates</span>", "2", ""],
["Stops", "1", ""],
["Upgrades <span class=\"normalText\"><span class=\"noWrap\">one-way</span><br/>from</span>", "1", ""],
["Hotels <span class=\"normalText\">pppn from</span>", "1", ""],
["Car rental  <span class=\"normalText\">per&nbsp;day<br/>from</span>", "1", ""]];
var LOCATIONS = [["ABZ", "Aberdeen", "ABZ", "Aberdeen", "EUR"],
["BRS", "Bristol", "", "", "EUR"],
["ORK", "Cork", "", "", "EUR"],
["CITY", "City destinations", "", "", "CITY"],
["DUB", "Dublin", "", "", "EUR"],
["EMA", "East Midlands", "", "", "EUR"],
["EDI", "Edinburgh", "", "", "EUR"],
["EXPLORE", "destinations to Explore", "", "", "EXPLORE"],
["GLA", "Glasgow", "", "", "EUR"],
["GOLF", "Golf destinations", "", "", "GOLF"],
["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", "Central Asia", "", "Central Asia", "SASIA"],
["FEA", "Far East", "", "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"],
["POPULAR", "our bestsellers", "", "our bestsellers", "POPULAR"],
["PRICEBAND1", "destinations priced up to &pound;50", "", "destinations priced up to &pound;50", "PRICEBAND1"],
["PRICEBAND2", "destinations priced between &pound;51 and  &pound;150", "", "destinations priced between &pound;51 and  &pound;150", "PRICEBAND2"],
["PRICEBAND3", "destinations priced between &pound;151 and  &pound;300", "", "destinations priced between &pound;151 and  &pound;300", "PRICEBAND3"],
["PRICEBAND4", "destinations priced between &pound;301 and  &pound;450", "", "destinations priced between &pound;301 and  &pound;450", "PRICEBAND4"],
["PRICEBAND5", "destinations priced from &pound;451", "", "destinations priced from &pound;451", "PRICEBAND5"],
["SHOPPING", "Shopping destinations", "", "", "SHOPPING"],
["SKI", "Ski destinations", "", "", "SKI"],
["SNN", "Shannon", "", "", "EUR"],
["SUN", "Sun destinations", "", "", "SUN"],
["EUR", "Europe", "", "Europe", "EUR"],
["UKI", "UK and Ireland", "", "UK and Ireland", "UKI"],
["A_W", "All locations", "A_W", "All locations", "EUR"]
];
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 = ["CITY",
"SUN",
"SKI",
"EXPLORE",
"GOLF",
"SHOPPING"];
var VALID_PRICEBANDS = ["PRICEBAND1",
"PRICEBAND2",
"PRICEBAND3",
"PRICEBAND4",
"PRICEBAND5"];
var gWoffersData = new WoffersData(SOURCE_URL, SOURCE_TYPE);
var gWofferTable = null;
var gPageType = "";
var gFromCode = "";
var gToCode = "";
$(pageSetup);
function pageSetup() {
try {
gWofferTable = new WofferTable(DOCUMENT_ELEMENT_ID, gWoffersData, gFromCode, gToCode);
if(!isPostPin()) {
$("#loginForm").hide();
$("#loginSummary #loginSummaryButton").click(function() {openLogin();});
$("#loginForm #cancelLogin").click(function() {closeLogin();});
flashSwitch('/cms/global/flash/july08_sale/july08_sale_uksplash.swf', 760, 100, '8', '', 'altContent2', 'wMode:opaque', false);
}
$("#departureSelection").keyup(function() {gWofferTable.processFromChange(this);});
$("#departureSelection").change(function() {gWofferTable.processFromChange(this);});
$("#mar08Woffers .ngtable input[name='navigationType']").click(function() {processPageChangeEvent(this);});
$(".regionNavigation a").click(function() {gWofferTable.processRegionChangeEvent(this);});
$(".typeNavigation a").click(function() {gWofferTable.processTypeChangeEvent(this);});
$("#mar08Woffers .ngtable input[name='priceNavigation']").click(function() {gWofferTable.processPriceChangeEvent(this);});
$("#mar08Woffers .ngtable input[name='saleNonSale']").click(function() {gWofferTable.processIncludeExcludeEvent(this);});
}
catch(e) {
}
}
function openLogin() {
var tempDirLogin = "/main/lcoffers?campaign=" + gPageType + "&from=" + gWofferTable.fromCode + "&to=" + gWofferTable.toCode + "&override=true";
$("#directionalLogin")[0].setAttribute("value", tempDirLogin);
$("#loginSummary").slideUp(500,function(){$("#loginForm").slideDown(500);});
}
function closeLogin() {
$("#loginForm").slideUp(500, function(){$("#loginSummary").slideDown(500, function(){});});
}
function setPageParameters() {
var sourceType = getQueryValue("source").toUpperCase();
var cookieOverride = getQueryValue("override").toUpperCase();
if((gPageType == "") || (sourceType == "ED") || (sourceType == "FT") || (cookieOverride == "TRUE") ) {
gPageType = getQueryValue("campaign").toUpperCase();
}
if((gPageType != "REGIONS") && (gPageType != "TYPES") && (gPageType != "POPULAR") && (gPageType != "PRICES"))
{
gPageType = "REGIONS";
}
gFromCode = getQueryValue("from").toUpperCase();
var foundLocation = false;
if(gFromCode) {
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();
switch(gPageType) {
case "REGIONS": {
var foundRegion = false;
if(gToCode) {
for(var regionIndex = 0; regionIndex < VALID_REGIONS.length; ++regionIndex) {
if(VALID_REGIONS[regionIndex] == gToCode) {
foundRegion = true;
break;
}
}
}
if(!foundRegion) {
gToCode = "NAM";
}
break;
}
case "TYPES": {
var foundType = false;
if(gToCode) {
for(var typeIndex = 0; typeIndex < VALID_REGIONS.length; ++typeIndex) {
if(VALID_TYPES[typeIndex] == gToCode) {
foundType = true;
break;
}
}
}
if(!foundType) {
gToCode = "CITY";
}
break;
}
case "PRICES": {
var foundPriceBand = false;
if(gToCode) {
for(var priceIndex = 0; priceIndex < VALID_PRICEBANDS.length; ++priceIndex) {
if(VALID_PRICEBANDS[priceIndex] == gToCode) {
foundPriceBand = true;
break;
}
}
}
if(!foundPriceBand) {
gToCode = "PRICEBAND3";
}
break;
}
case "POPULAR": {
gToCode = "POPULAR";
break;
}
default: {
gPageType = "REGIONS";
gFromCode = "LON";
gToCode = "NAM";
}
}
trackingInfo["JANSALE1"] = gPageType;
trackingInfo["LKDeparturePoint"] = gFromCode;
trackingInfo["JANSALE2"] = gToCode;
trackingInfo["pageidextra"] = gPageType + "-" + gToCode;
trackingInfo["JANSALETEST"] = "updated-inscript";
}
function setPageType(pageType) {
var matchedDepartureLocations = $("select.departureSelection  option[value='" + gFromCode + "']");
if(matchedDepartureLocations) {
matchedDepartureLocations[0].selected = true;
}
$("#pageTypeSelectionDiv input[value='" + pageType.toUpperCase() + "']").attr({"checked":"checked"});
switch(pageType.toUpperCase()) {
case "TYPES" : {
$(".regionNavigation:visible").hide();
$(".priceNavigation:visible").hide();
$(".typeNavigation").show();
gPageType = "TYPES";
var imageNavItems = $(".typeNavigation li a");
imageNavItems.removeClass("selected");
$(".typeNavigation li." + gToCode.toLowerCase() + " a").addClass("selected");
break;
}
case "POPULAR" : {
$(".regionNavigation:visible").hide();
$(".typeNavigation:visible").hide();
$(".priceNavigation:visible").hide();
gPageType = "POPULAR";
break;
}
case "PRICES" : {
$(".regionNavigation:visible").hide();
$(".typeNavigation:visible").hide();
$(".priceNavigation").show();
gPageType = "PRICES";
$("#priceSelectionDiv input[value='" + gToCode.toUpperCase() + "']").attr({"checked":"checked"});
break;
}
default: {
$(".typeNavigation:visible").hide();
$(".priceNavigation:visible").hide();
$(".regionNavigation").show();
gPageType = "REGIONS";
var regionNavItems = $(".regionNavigation li a");
regionNavItems.removeClass("selected");
$(".regionNavigation li." + gToCode.toLowerCase() + " a").addClass("selected");
if (gToCode != "LAC")
{
$(".LAClink:visible").hide();
}
break;
}
}
}
function processPageChangeEvent(eventSource) {
var pageType = eventSource.getAttribute("value");
switch(pageType) {
case "REGIONS": {
gToCode = $(".regionNavigation li a.selected")[0].getAttribute("regionCode");
break;
}
case "TYPES": {
gToCode = $(".typeNavigation li a.selected")[0].getAttribute("regionCode");
break;
}
case "POPULAR": {
gToCode = "POPULAR";
break;
}
case "PRICES": {
gToCode = $("#priceSelectionDiv input[checked]")[0].value.toUpperCase();
break;
}
default: {
gToCode = "NAM";
}
}
setPageType(pageType);
gWofferTable.toCode = gToCode;
gWofferTable.buildOutput();
gWofferTable.trackChanges();
}
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.getWoffersForRegion = function(region) {
var matchingWoffers = new Array();
for(var index = 0; index < this.woffers.length; ++index) {
if(this.woffers[index].regionCode == region) {
matchingWoffers.push(this.woffers[index]);
}
}
return(matchingWoffers);
}
WoffersData.prototype.getWoffersForLocations = function(fromCode, toCode, includeNonSale) {
var matchingWoffers = new Array();
var currentWoffer = null;
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)))) {
if(includeNonSale == true) {
matchingWoffers.push(currentWoffer);
}
else if(currentWoffer.hasSaleFare()) {
matchingWoffers.push(currentWoffer);
}
}
}
return(matchingWoffers);
}
WoffersData.prototype.getWoffersThatMatchDepartureAndPrice = function(departureCode, fromPrice, toPrice, includeNonSale) {
var matchingWoffers = new Array();
var currentWoffer = null;
var prices = null;
var currentPrice = null;
var priceIndex = 0;
var addonPriceIndex = 0;
var addonPrices = null;
var foundPrice = false;
for(var index = 0; index < this.woffers.length; ++index) {
currentWoffer = this.woffers[index];
if((departureCode != "A_W") && (!currentWoffer.matchesDepartureCode(departureCode))) {
continue;
}
foundPrice = false;
prices = currentWoffer.prices.prices;
for(priceIndex = 0; priceIndex < prices.length; ++priceIndex) {
currentPrice = prices[priceIndex];
if(currentWoffer.originAirport == departureCode) {
if((currentPrice.price >= fromPrice) && (currentPrice.price <= toPrice)) {
foundPrice = true;
}
}
else {
addonPrices = currentPrice.addonPrices;
for(addonPriceIndex = 0; addonPriceIndex < addonPrices.length; ++addonPriceIndex) {
currentPrice = addonPrices[addonPriceIndex];
if((currentPrice.location == departureCode) && (currentPrice.price >= fromPrice) && (currentPrice.price <= toPrice)) {
foundPrice = true;
break;
}
}
}
if(foundPrice) {
if(includeNonSale == true) {
matchingWoffers.push(currentWoffer);
break;
}
else if(currentWoffer.hasSaleFare()) {
matchingWoffers.push(currentWoffer);
break;
}
}
}
}
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) {
this.originAirport = "";
this.destinationAirport = "";
this.destinationName = "";
this.regionCode = "";
this.priceType = "";
this.footnote = "";
this.prices = 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);
}
var tempOptionTitle = "";
var tempOptionValue = "";
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));
}
if(wofferData.optional1) {
tempOptionTitle = "optional1";
tempOptionValue = wofferData.optional1;
this.wofferOptions.push(new WofferOption(tempOptionTitle, tempOptionValue));
}
if(wofferData.optional2) {
tempOptionTitle = "optional2";
tempOptionValue = wofferData.optional2;
this.wofferOptions.push(new WofferOption(tempOptionTitle, tempOptionValue));
}
if(wofferData.optional3) {
tempOptionTitle = "optional3";
tempOptionValue = wofferData.optional3;
this.wofferOptions.push(new WofferOption(tempOptionTitle, tempOptionValue));
}
if(wofferData.optional4) {
tempOptionTitle = "optional4";
tempOptionValue = wofferData.optional4;
this.wofferOptions.push(new WofferOption(tempOptionTitle, tempOptionValue));
}
}
Woffer.prototype.getLowestPrice = function() {
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(lowestPrice);
}
Woffer.prototype.matchesDepartureCode = function(fromCode) {
var matched = false;
var currentPrice = null;
if((this.originAirport == fromCode) || (fromCode == "LON" && ((this.originAirport == "LHR") || (this.originAirport == "LGW") || (this.originAirport == "LCY")))) {
matched = true;
}
else {
for(var priceIndex = 0; priceIndex < this.prices.prices.length; ++priceIndex) {
currentPrice = this.prices.prices[priceIndex];
if(currentPrice.hasAddonLocation(fromCode)) {
matched = true;
break;
}
}
}
return(matched);
}
Woffer.prototype.matchesDestinationCode = function(toCode) {
var matched = false;
if(this.regionCode == toCode) {
matched = true;
}
else {
var holidayTypes = this.getOption("optional3")
if(holidayTypes && (holidayTypes.value.toUpperCase().search(toCode.toUpperCase()) != -1)) {
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.valueFare == false) {
matched = true;
break;
}
}
return(matched);
}
Woffer.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);
}
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) {
this.price = null;
var tempPrice = 0;
this.valueFare = false;
this.outboundFromDate = "";
this.outboundToDate = "";
this.addonPrices = 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.out_from) {
this.outboundFromDate = priceData.out_from;
}
if(priceData.out_to) {
this.outboundToDate = priceData.out_to;
}
var tempDepartureCode = "";
if(priceData.abz_add_on) {
tempDepartureCode = "ABZ";
tempPrice = priceData.abz_add_on.replace(/\,/g, '');
this.addonPrices.push(new AddonPrice(tempDepartureCode, Math.round(tempPrice)));
}
if(priceData.man_add_on) {
tempDepartureCode = "MAN";
tempPrice = priceData.man_add_on.replace(/\,/g, '');
this.addonPrices.push(new AddonPrice(tempDepartureCode, Math.round(tempPrice)));
}
if(priceData.edi_add_on) {
tempDepartureCode = "EDI";
tempPrice = priceData.edi_add_on.replace(/\,/g, '');
this.addonPrices.push(new AddonPrice(tempDepartureCode, Math.round(tempPrice)));
}
if(priceData.ncl_add_on) {
tempDepartureCode = "NCL";
tempPrice = priceData.ncl_add_on.replace(/\,/g, '');
this.addonPrices.push(new AddonPrice(tempDepartureCode, Math.round(tempPrice)));
}
if(priceData.gla_add_on) {
tempDepartureCode = "GLA";
tempPrice = priceData.gla_add_on.replace(/\,/g, '');
this.addonPrices.push(new AddonPrice(tempDepartureCode, Math.round(tempPrice)));
}
if(priceData.jer_add_on) {
tempDepartureCode = "JER";
tempPrice = priceData.jer_add_on.replace(/\,/g, '');
this.addonPrices.push(new AddonPrice(tempDepartureCode, Math.round(tempPrice)));
}
if(priceData.bfs_add_on) {
tempDepartureCode = "BFS";
tempPrice = priceData.bfs_add_on.replace(/\,/g, '');
this.addonPrices.push(new AddonPrice(tempDepartureCode, Math.round(tempPrice)));
}
}
Price.prototype.hasAddonLocation = function(locationCode) {
var matched = false;
var currentAddon = null;
for(var index = 0; index < this.addonPrices.length; ++index) {
currentAddon = this.addonPrices[index];
if(currentAddon.location == locationCode) {
matched = true;
break;
}
}
return(matched);
}
Price.prototype.getAddonPrice = function(locationCode) {
var returnPrice = null;
var currentAddon = null;
for(var index = 0; index < this.addonPrices.length; ++index) {
currentAddon = this.addonPrices[index];
if(currentAddon.location == locationCode) {
returnPrice = currentAddon;
break;
}
}
return(returnPrice);
}
function AddonPrice(location, price) {
this.location = location;
this.price = price;
}
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.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");
if (clickedRegionCode == "lac")
{
CaribLinkItem.show();
}
else {
CaribLinkItem.hide();
}
this.buildOutput();
this.trackChanges();
}
WofferTable.prototype.processTypeChangeEvent = function(element) {
var clickedRegionCode = element.getAttribute("regionCode");
this.toCode = clickedRegionCode;
var imageNavItems = $(".typeNavigation li a");
imageNavItems.removeClass("selected");
clickedRegionCode = clickedRegionCode.toLowerCase();
$(".typeNavigation li." + clickedRegionCode + " a").addClass("selected");
this.buildOutput();
this.trackChanges();
}
WofferTable.prototype.processPriceChangeEvent = function(element) {
var clickedPriceBand = element.getAttribute("value");
this.toCode = clickedPriceBand.toUpperCase();
this.buildOutput();
this.trackChanges();
}
WofferTable.prototype.processIncludeExcludeEvent = function(element) {
var clickedOption = element.getAttribute("value");
if(clickedOption.toUpperCase().search("SALEANDNONSALE") != -1) {
this.includeNonSale = true;
}
else {
this.includeNonSale = false;
}
this.buildOutput();
}
WofferTable.prototype.trackChanges = function()
{
trackingInfo["JANSALE1"] = gPageType;
trackingInfo["LKDeparturePoint"] = this.fromCode;
trackingInfo["JANSALE2"] = this.toCode;
trackingInfo["pageidextra"] = gPageType + "-" + this.toCode;
document.getElementById("t-tracking-fragment").innerHTML = vsDoTracking();
}
WofferTable.prototype.buildOutput = function() {
$("#wait").fadeIn("slow", function() {gWofferTable.buildOutput2();});
}
WofferTable.prototype.buildOutput2 = function() {
var priceHTML = "";
var datesHTML = "";
var prices = null;
var currentPrice = null;
var priceType = "";
var tempPrice = 0;
var tempHTML = "";
var rowID;
var nonFlightTokens;
var tempUpgradeData;
var	usedPriceCount = 0;
this.footnotes.length = 0;
tempHTML = "<div id=\"availableBasket\"><p>Available to add to your shopping basket <a class=\"howTo\" href=\"javascript:popUpScrolling('/main/SHOWMEHOW-POP',340,400);\">Show me how</a></p></div>";
tempHTML += "<table id=\"table1\" class=\"tablesorter peekFix\" cellspacing=\"0\" border=\"1\" summary=\"World offers fares\" style=\"width: 100%;\">\n";
tempHTML += "<thead>\n";
tempHTML += "<tr valign=\"top\" >\n";
for(var index = 0; index < TABLE_HEADERS.length; ++index) {
tempHTML +="<th id=\"tableHeaderCell" + index + "\" colspan=\"" + TABLE_HEADERS[index][1] + "\" title=\"" + TABLE_HEADERS[index][2] + "\">" + TABLE_HEADERS[index][0] + "</th>\n";
}
tempHTML += "</tr>\n";
tempHTML += "</thead>";
tempHTML += "<tbody id=\"table2body\">";
var matchingWoffers = null;
var currentWoffer = null;
var tempOption = null;
if(this.toCode.search("PRICEBAND") == 0) {
var fromPrice = 0;
var toPrice = 0;
for(var bandIndex = 0; bandIndex < PRICE_BANDS.length; ++bandIndex) {
if(PRICE_BANDS[bandIndex][0] == this.toCode) {
fromPrice = PRICE_BANDS[bandIndex][1];
toPrice = PRICE_BANDS[bandIndex][2];
}
}
matchingWoffers = gWoffersData.getWoffersThatMatchDepartureAndPrice(this.fromCode, fromPrice, toPrice, this.includeNonSale);
}
else {
matchingWoffers = gWoffersData.getWoffersForLocations(this.fromCode, this.toCode, this.includeNonSale);
}
if((matchingWoffers.length <= 0) && (toPrice == "50") && ((this.toCode != "EUR") && (this.toCode != "UKI"))) {
tempHTML += "<tr><td class=\"noMatchResult\" colspan=\"9\">Sorry, no July sale prices up to &pound;50 are available from this airport. Please select 'These and other prices' at Step&nbsp;2 to see our other prices from this airport";
tempHTML += ".</td></tr>\n";
}
else if((matchingWoffers.length <= 0) && (this.includeNonSale == false) && ((this.toCode == "EUR") || (this.toCode == "UKI"))) {
tempHTML += "<tr><td class=\"noMatchResult\" colspan=\"9\">Sorry, no sale prices to this region are available from this airport. Please select 'Sale and non-sale prices' at Step&nbsp;2 to see our other prices to this region";
tempHTML += ".</td></tr>\n";
}
else if(matchingWoffers.length <= 0) {
tempHTML += "<tr><td class=\"noMatchResult\" colspan=\"9\">Sorry, no prices available from ";
tempHTML += getAirportName(this.fromCode) + " to " + getAirportName(this.toCode);
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);
});
}
for(var index = 0; index < matchingWoffers.length; ++index) {
currentWoffer = matchingWoffers[index];
rowID = "wofferRow" + index;
tempHTML += "<tr id=\"" +rowID + "\">\n";
tempHTML +="<td class=\"destinationCell\">";
tempHTML += currentWoffer.destinationName;
if(currentWoffer.getOption("optional4")) {
tempHTML += "<img class=\"keyImage\" src=\"/cms/global/assets/images/promotion/uk/sep07woffers/late_deals_icon.gif\" alt=\"L\" title=\"Destinations with late availability for travel in April and May.\" width=\"12\" height=\"12\" />";
}
tempHTML += "</td>\n";
currentPrice = currentWoffer.getLowestPrice();
if(isAddon(currentWoffer.originAirport, this.fromCode)) {
tempPrice = parseInt(currentPrice.getAddonPrice(this.fromCode).price);
}
else {
tempPrice = parseInt(currentPrice.price);
}
if(currentPrice.valueFare == false) {
tempPrice = getAdjustedPrice(tempPrice, currentWoffer.priceType);
}
if(currentWoffer.destinationAirport == "LED" || currentWoffer.destinationAirport == "DME") {
if(isPostPin()) {
tempPrice = parseInt(tempPrice) + parseInt(RETURN_PRICE_POSTPIN_DISCOUNT)
}
}
priceHTML = "<div class=\"leadPrice\">&pound;" + tempPrice;
if(currentWoffer.priceType == RETURN_PRICE_TYPE) {
priceType = " rtn"
}
else {
priceType = " ow";
}
priceHTML += priceType;
if(currentPrice.valueFare) {
priceHTML += "<sup>1</sup><br />";
this.addFootnote("<sup>1</sup> Indicates a price not included in the July sale.  Limited Availability. Availability may be limited at peak times such as bank holidays and school holidays.<br />");
}
priceHTML += "</div>";
datesHTML = "<div class=\"leadDates\">";
datesHTML += currentPrice.outboundFromDate + " - " + currentPrice.outboundToDate;
datesHTML += "</div>";
priceHTML += "<div class=\"allPrices\" style=\"display: block;\">";
datesHTML += "<div class=\"allDates\" style=\"display: block;\">";
prices = currentWoffer.prices.prices;
usedPriceCount = 0;
for(var pricesIndex = 0; pricesIndex < prices.length; ++pricesIndex) {
currentPrice = prices[pricesIndex];
if(currentPrice.valueFare && (this.includeNonSale == false)) {
}
else {
++usedPriceCount;
if(isAddon(currentWoffer.originAirport, this.fromCode)) {
tempPrice = parseInt(currentPrice.getAddonPrice(this.fromCode).price);
}
else {
tempPrice = parseInt(currentPrice.price);
}
if(currentPrice.valueFare == false) {
tempPrice = getAdjustedPrice(tempPrice, currentWoffer.priceType);
}
priceHTML += "&pound;" + tempPrice + priceType;
if(currentPrice.valueFare) {
priceHTML += "<sup>1</sup><br />";
this.addFootnote("<sup>1</sup> Indicates a price not included in the July sale.  Limited Availability. Availability may be limited at peak times such as bank holidays and school holidays.<br />");
}
else {priceHTML += "<br/>";
}
datesHTML += currentPrice.outboundFromDate + " - " + currentPrice.outboundToDate + "<br />";
}
}
priceHTML += "</div>";
datesHTML += "</div>";
tempHTML += "<td class=\"priceCell\">" + priceHTML + "</td>\n";
tempHTML += "<td class=\"dateCell\">";
if(usedPriceCount > 1) {
tempHTML += "<a class=\"twistyLink\" onclick=\"this.blur();\" href=\"javascript:WofferTable.openTwisty('" +	rowID +	"');\">";
tempHTML += "<img src=\"/cms/global/assets/images/promotion/uk/jan08woffers/twisty-closed.gif\" width=\"9\" height=\"9\" alt=\"Plus sign.\" title=\"Click to show more prices and dates.\" /></a>";
}
tempHTML += datesHTML + "</td>\n";
tempHTML += "<td class=\"actionCell\">";
if(isPostPin()) {
tempHTML += "<a href=\"/main/FX/cugAlias-ba807?source=CUG_ba807&amp;eId=111042&amp;to=";
}
else {
tempHTML += "<a href=\"/main/FX?to=";
}
tempHTML += currentWoffer.destinationAirport + "&amp;from="
if(this.fromCode == "LON") {
tempHTML += currentWoffer.originAirport;
}
else {
tempHTML += this.fromCode
}
if(this.includeNonSale) {
tempHTML += "&amp;nonsalefares=true";
}
else {
tempHTML += "&amp;nonsalefares=false";
}
tempHTML += "\">";
tempHTML += "Plan or book";
tempHTML += "</a></div></td>\n";
tempHTML += "<td class=\"stopsCell\">";
if(isAddon(currentWoffer.originAirport, this.fromCode)) {
tempHTML += "<p title=\"Via " + getAirportName(currentWoffer.originAirport) + "\">1</p>";
}
else {
tempHTML += "<p title=\"Direct flight\">0</p>";
}
tempHTML += "</td>\n";
tempOption = currentWoffer.getOption("optional1");
if((!tempOption) || (tempOption.value.toUpperCase().search("NOT AVAILABLE") != -1)) {
tempHTML += "<td class=\"upgradeCell dissabled\">";
tempHTML += "<p title=\"Sorry no upgrade available for this destination\">N/A</p>";
}
else {
tempUpgradeData = tempOption.value.split(",")
tempHTML += "<td class=\"upgradeCell\">";
tempHTML += "&pound;" + tempUpgradeData[0];
}
tempHTML += "</td>\n";
tempOption = currentWoffer.getOption("nonFlightPrice");
if((!tempOption) || (tempOption.value.toUpperCase().search(/NOT AVAILABLE/) != -1)) {
tempHTML += "<td class=\"hotelCell dissabled\">";
tempHTML += "N/A";
}
else {
tempHTML += "<td class=\"hotelCell\">";
tempHTML += "&pound;" + getAdjustedHotelPrice(tempOption.value);
tempHTML += "&nbsp;";
}
tempOption = currentWoffer.getOption("nonFlight");
if(tempOption) {
if(tempOption.value.toUpperCase().search(/NOT AVAILABLE/) != -1) {
tempHTML += "N/A";
}
else {
switch(jQuery.trim(tempOption.value)) {
case "2": {
tempHTML += "<img src=\"/cms/global/assets/images/promotion/uk/july08_sale/2.gif\" width=\"36\" height=\"8\" alt=\"Two stars.\" /></a>";
break;
}
case "2.5": {
tempHTML += "<img src=\"/cms/global/assets/images/promotion/uk/july08_sale/2_plus.gif\" width=\"36\" height=\"8\" alt=\"Two plus stars.\" /></a>";
break;
}
case "3": {
tempHTML += "<img src=\"/cms/global/assets/images/promotion/uk/july08_sale/3.gif\" width=\"36\" height=\"8\" alt=\"Three stars.\" /></a>";
break;
}
case "3.5": {
tempHTML += "<img src=\"/cms/global/assets/images/promotion/uk/july08_sale/3_plus.gif\" width=\"36\" height=\"8\" alt=\"Three plus stars.\" /></a>";
break;
}
case "4": {
tempHTML += "<img src=\"/cms/global/assets/images/promotion/uk/july08_sale/4.gif\" width=\"36\" height=\"8\" alt=\"Four stars.\" /></a>";
break;
}
case "4.5": {
tempHTML += "<img src=\"/cms/global/assets/images/promotion/uk/july08_sale/4_plus.gif\" width=\"36\" height=\"8\" alt=\"Four plus stars.\" /></a>";
break;
}
case "5": {
tempHTML += "<img src=\"/cms/global/assets/images/promotion/uk/july08_sale/5.gif\" width=\"36\" height=\"8\" alt=\"Five stars.\" /></a>";
break;
}
}
}
}
tempHTML += "</td>\n";
tempOption = currentWoffer.getOption("optional2");
if((!tempOption) || (tempOption.value.toUpperCase().search("NOT AVAILABLE") != -1)) {
tempHTML += "<td class=\"carCell dissabled\">";
tempHTML += "N/A";
}
else {
tempHTML += "<td class=\"carCell\">";
tempHTML += "&pound;" + getAdjustedHotelPrice(tempOption.value);
}
tempHTML += "</tr>\n";
if(currentWoffer.footnote) {
this.addFootnote(currentWoffer.footnote);
}
}
tempHTML += "</tbody>";
tempHTML += "</tbody>\n</table>";
var jTableDiv = $("#" + this.elementId);
jTableDiv.hide();
jTableDiv.html(tempHTML);
WofferTable.closeAllTwistys();
jTableDiv.show();
if (matchingWoffers.length > 0) {
$(document).ready(function() {
$.tablesorter.defaults.widgets = ['zebra'];
$("table").tablesorter({
sortList: [[gLastColSorted,gLastColSortOrder]],
headers: {1: {sorter:'prices'}, 2: {sorter: false}, 3: {sorter: false}, 4: {sorter: false}, 5: {sorter: false}, 6: {sorter: false} }
});
});
}
document.getElementById("tableSelectionHeading").innerHTML = "Flights from " + getAirportName(this.fromCode) + " to " + getAirportName(this.toCode);
var tempFootnoteHTML = "<p>";
for(var footnoteIndex = 0; footnoteIndex < this.footnotes.length; ++footnoteIndex) {
tempFootnoteHTML += this.footnotes[footnoteIndex] + "";
}
tempFootnoteHTML += "</p>";
$('#footnotes').empty().append(tempFootnoteHTML);
$("#wait:visible").fadeOut();
}
WofferTable.prototype.addFootnote = function(footnote) {
var foundFootnote = false;
for(var footnoteIndex = 0; footnoteIndex < this.footnotes.length; ++footnoteIndex) {
if(this.footnotes[footnoteIndex] == footnote) {
foundFootnote = true;
break;
}
}
if(!foundFootnote) {
this.footnotes.push(footnote);
}
}
WofferTable.closeAllTwistys = function() {
var rows = $("#" + DOCUMENT_ELEMENT_ID + " #table2body tr");
for(var rowCount = 0; rowCount < rows.length; ++rowCount) {
WofferTable.closeTwisty(rows[rowCount].id);
}
}
WofferTable.openTwisty = function(wofferRow) {
$("#" + wofferRow + " .leadPrice")[0].style.display="none";
$("#" + wofferRow + " .leadDates")[0].style.display="none";
$("#" + wofferRow + " .allPrices")[0].style.display="block";
$("#" + wofferRow + " .allDates")[0].style.display="block";
var tempTarget = "javascript:WofferTable.closeTwisty('" + wofferRow + "');";
$("#" + wofferRow + " .twistyLink").attr({"href":tempTarget});
$("#" + wofferRow + " .twistyLink").html("<img src=\"/cms/global/assets/images/promotion/uk/jan08woffers/twisty-open.gif\" width=\"9\" height=\"9\" alt=\"Plus sign.\" title=\"Click to show only best price.\" />");
}
WofferTable.closeTwisty = function(wofferRow) {
if($("#" + wofferRow + " .allPrices").length > 0) {
$("#" + wofferRow + " .allPrices")[0].style.display="none";
}
if($("#" + wofferRow + " .allDates").length > 0) {
$("#" + wofferRow + " .allDates")[0].style.display="none";
}
if($("#" + wofferRow + " .leadPrice").length > 0) {
$("#" + wofferRow + " .leadPrice")[0].style.display="block";
}
if($("#" + wofferRow + " .leadDates").length > 0) {
$("#" + wofferRow + " .leadDates")[0].style.display="block";
}
var tempTarget = "javascript:WofferTable.openTwisty('" + wofferRow + "');";
$("#" + wofferRow + " .twistyLink").attr({"href":tempTarget});
$("#" + wofferRow + " .twistyLink").html("<img src=\"/cms/global/assets/images/promotion/uk/jan08woffers/twisty-closed.gif\" width=\"9\" height=\"9\" alt=\"Plus sign.\" title=\"Click to show more prices and dates.\" />");
}
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);
}
function isPostPin() {
var isPostpin = false;
if(document.nav_form.logintype.value != 'public') {
isPostpin = true;
}
return(isPostpin);
}
function getAdjustedPrice(originalPrice, priceType) {
var tempPrice = originalPrice;
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;
}
}
}
return(tempPrice);;
}
function getAdjustedHotelPrice(price) {
var tempPrice = parseFloat(price);
if(isPostPin()) {
var discount = HOTEL_PRICE_POSTPIN_DISCOUNT;
if(discount) {
discount = tempPrice * (parseFloat(discount) / 100);
tempPrice -= discount;
}
}
return Math.ceil(tempPrice);
}
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);
if(cEnd==-1)
{
cEnd = document.cookie.length;
}
return unescape(document.cookie.substring(cStart,cEnd));
}
}
return "";
}
function setCookie(cName,cValue)
{
var expireDate = new Date();
expireDate.setFullYear(expireDate.getFullYear() + 1);
document.cookie = cName + "=" + escape(cValue) + "; expires=" + expireDate;
}
function isAddon(wofferDeparture, requiredDeparture)
{
var isAddon = true;
if((wofferDeparture == requiredDeparture) || ((requiredDeparture == "LON") && ((wofferDeparture == "LHR") || (wofferDeparture == "LGW") || (wofferDeparture == "LCY")))) {
isAddon = false;
}
return(isAddon);
}