
var VALID_AUTOSTARTID = ["CW",
"CE"];
var SOURCE_URL = "/cms/global/json/july_woffers_2009/woffersdata-ie.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 upgradeCol = 'true';
var bookCol = 'false';
var TABLE_HEADERS = [["Destination", "1", "Click to change sort order."],
["Price from", "1", "Click to change sort order."],
["&nbsp;","1",""],
["Travel dates <span class=\"normalText\"><br />Click <img src=\"/cms/global/assets/images/promotion/uk/oct08plo/clubHoliday/twisty-closed.gif\" width=\"9\" height=\"9\" alt=\"Plus sign.\" /> to see more</span>", "1", "Click to change sort order."]];
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", "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"],
["SNN", "Shannon", "", "", "EUR"],
["EUR", "Europe", "", "Europe", "EUR"],
["UKI", "UK and Ireland", "", "UK and Ireland", "UKI"],
["A_W", "All locations", "A_W", "All locations", "EUR"]
];
var VALID_DEPARTURES = ["ORK",
"DUB"];
var VALID_REGIONS = ["NAM",
"SASIA",
"EUR",
"FEA",
"LAC",
"ME",
"NAF",
"AFR",
"UKI"];
var gWoffersData = new WoffersData(SOURCE_URL, SOURCE_TYPE);
var gWofferTable = null;
var gFromCode = "";
var gToCode = "";
var	gLastClassSelected = "";
$(pageSetup);
function pageSetup() {
try {
detectFlash('8');
var matchedDepartureLocations = $("select.departureSelection  option[value='" + gFromCode + "']");
if(matchedDepartureLocations) {
matchedDepartureLocations[0].selected = true;
}
$(".regionNavigation").show();
var regionNavItems = $(".regionNavigation li a");
regionNavItems.removeClass("selected");
$(".regionNavigation li." + gToCode.toLowerCase() + " a").addClass("selected");
gWofferTable = new WofferTable(DOCUMENT_ELEMENT_ID, gWoffersData, gFromCode, gToCode);
gWoffersData.build();
$("#departureSelection").keyup(function() {gWofferTable.processFromChange(this);});
$("#departureSelection").change(function() {gWofferTable.processFromChange(this);});
$(".regionNavigation a").click(function() {gWofferTable.processRegionChangeEvent(this);});
$("#oct08plo input[name='saleNonSale']").click(function() {gWofferTable.processIncludeExcludeEvent(this);});
$("#CW").batbox( { width:800, height:660, allowScrolling:true } );
if(flashOkay == true){
$("#CE").batbox( { width:600, height:560, allowScrolling:true } );
}
else
{
$("#CE").attr("href","javascript://");
$("#CE").batbox( { width:600, height:560, inlineId:"content2", allowScrolling:true } );
}
$("#loginPodDiv").hide();
$("select#cabin option:eq(2)").attr("selected","selected");
checkAutostart();
}
catch(e) {
}
}
function checkAutostart(){
var autoStartID = getQueryValue("autoStartID").toUpperCase();
for(var autostartIndex = 0; autostartIndex < VALID_AUTOSTARTID.length; ++autostartIndex)
{
if(VALID_AUTOSTARTID[autostartIndex] == autoStartID)
{
$('#'+autoStartID).trigger('click');
break;
}
}
};
function setPageParameters() {
var sourceType = getQueryValue("source").toUpperCase();
var cookieOverride = getQueryValue("override").toUpperCase();
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 = "ORK";
}
gToCode = getQueryValue("to").toUpperCase();
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";
}
trackingInfo["JANSALE1"] = "REGIONS";
trackingInfo["LKDeparturePoint"] = gFromCode;
trackingInfo["JANSALE2"] = gToCode;
trackingInfo["pageidextra"] = "REGIONS" + "-" + gToCode;
trackingInfo["JANSALETEST"] = "updated-inscript";
}
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");
imageNavItems.removeClass("selected");
clickedRegionCode = clickedRegionCode.toLowerCase();
$(".regionNavigation li." + clickedRegionCode + " a").addClass("selected");
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"] = "REGIONS";
trackingInfo["LKDeparturePoint"] = this.fromCode;
trackingInfo["JANSALE2"] = this.toCode;
trackingInfo["pageidextra"] = "REGIONS" + "-" + 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() {
try{
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 += "<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";
TABLE_HEADERS[0][0] = "Destination";
for(var index = 0; index < TABLE_HEADERS.length; ++index) {
if ((index == 0)&&((upgradeCol=='false')||(bookCol=='false')||(this.toCode=='EUR'))){
tempHTML +="<th width=\"175\" id=\"tableHeaderCell" + index + "\"  colspan=\"" + TABLE_HEADERS[index][1] + "\" title=\"" + TABLE_HEADERS[index][2] + "\">" + TABLE_HEADERS[index][0] + "</th>\n";
} else if(index == 0){
tempHTML +="<th id=\"tableHeaderCell" + index + "\"  colspan=\"" + TABLE_HEADERS[index][1] + "\" title=\"" + TABLE_HEADERS[index][2] + "\">" + TABLE_HEADERS[index][0] + "</th>\n";
} else if(index == 1){
tempHTML +="<th width=\"110\" id=\"tableHeaderCell" + index + "\"  colspan=\"" + TABLE_HEADERS[index][1] + "\" title=\"" + TABLE_HEADERS[index][2] + "\">" + TABLE_HEADERS[index][0] + "</th>\n";
} else if((index==4)&&(upgradeCol=='true')&&(this.toCode != 'EUR')){
tempHTML +="<th id=\"tableHeaderCell" + index + "\"  colspan=\"" + TABLE_HEADERS[index][1] + "\" title=\"" + TABLE_HEADERS[index][2] + "\">" + TABLE_HEADERS[index][0] + "</th>\n";
} else if ((index==5)&&(bookCol=='true')){
tempHTML +="<th id=\"tableHeaderCell" + index + "\"  colspan=\"" + TABLE_HEADERS[index][1] + "\" title=\"" + TABLE_HEADERS[index][2] + "\">" + TABLE_HEADERS[index][0] + "</th>\n";
} else if((index == 2)||(index == 3)){
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) {
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 += "<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 += "\" title=\"Plan or book.\">";
tempHTML += currentWoffer.destinationName + "</a>";
tempOption = currentWoffer.getOption("optional4");
if(tempOption) {
tempHTML += "<span class=\"londonAll\"><br/>"+tempOption.value;+"</span>"
} else if (gFromCode != "LHR" && gFromCode != "LGW" & gFromCode != "LCY") {
tempHTML += "<span class=\"londonAll\"><br/>from "+getAirportName(currentWoffer.originAirport);+"</span>"
}
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 && this.toCode != "EUR") {
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\"><a href=\"/main/FX?to=";
priceHTML += currentWoffer.destinationAirport + "&amp;from="
if(this.fromCode == "LON") {
priceHTML += currentWoffer.originAirport;
}
else {
priceHTML += this.fromCode
}
if(this.includeNonSale) {
priceHTML += "&amp;nonsalefares=true";
}
else {
priceHTML += "&amp;nonsalefares=false";
}
priceHTML += "\" title=\"Plan or book.\">";
priceHTML += "&euro;" + tempPrice;
if(currentWoffer.priceType == RETURN_PRICE_TYPE) {
priceType = " return"
}
else {
priceType = " one-way";
}
priceHTML += priceType;
if(currentPrice.valueFare) {
priceHTML += "<sup>1</sup><br />";
this.addFootnote("<sup>1</sup> Indicates a price not included in the sale. Limited Availability. Availability may be limited at peak times such as bank holidays and school holidays.<br />");
}
priceHTML += "</a></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;\">";
priceHTML += "<a href=\"/main/FX?to=";
priceHTML += currentWoffer.destinationAirport + "&amp;from="
if(this.fromCode == "LON") {
priceHTML += currentWoffer.originAirport;
}
else {
priceHTML += this.fromCode
}
if(this.includeNonSale) {
priceHTML += "&amp;nonsalefares=true";
}
else {
priceHTML += "&amp;nonsalefares=false";
}
priceHTML += "\" title=\"Plan or book.\">";
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 += "&euro;" + tempPrice + priceType;
if(currentPrice.valueFare) {
priceHTML += "<sup>1</sup><br />";
this.addFootnote("<sup>1</sup> Indicates a price not included in the 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 += "</a></div>";
datesHTML += "</div>";
tempHTML += "<td class=\"priceCell\">" + priceHTML + "</td>\n";
tempHTML += "<td class=\"dateTwistyCell\">";
if(usedPriceCount > 1) {
tempHTML += "<a class=\"twistyLink\" onclick=\"this.blur();\" href=\"javascript:WofferTable.openTwisty('" +        rowID +        "');\">";
tempHTML += "<img src=\"/cms/global/assets/images/promotion/uk/oct08plo/clubHoliday/twisty-closed.gif\" width=\"9\" height=\"9\" alt=\"Plus sign.\" title=\"Click to show more prices and dates.\" /></a>";
}
tempHTML += "</td>\n";
tempHTML += "<td class=\"dateCell\">";
tempHTML += datesHTML + "</td>\n";
if(bookCol=='true'){
tempHTML += "<td class=\"actionCell\">";
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";
}
if(currentWoffer.footnote) {
this.addFootnote(currentWoffer.footnote);
}
}
tempHTML += "</tbody>";
tempHTML += "</tbody>\n</table>";
$("#tableDiv").html(tempHTML);
WofferTable.closeAllTwistys();
if (matchingWoffers.length > 0) {
$(document).ready(function() {
$.tablesorter.defaults.widgets = ['zebra'];
$("table").tablesorter({
sortList: [[gLastColSorted,gLastColSortOrder]],
headers: {0: {sorter:'linkedDestinations'}, 1: {sorter:'linkedPrices'}, 2: {sorter: false}, 3: {sorter:'travelDates'}, 4: {sorter: false}, 5: {sorter: false}, 6: {sorter: false} }
});
});
}
var tempFootnoteHTML = "<p>";
for(var footnoteIndex = 0; footnoteIndex < this.footnotes.length; ++footnoteIndex) {
tempFootnoteHTML += this.footnotes[footnoteIndex] + "";
}
tempFootnoteHTML += "</p>";
$('#footnotes').empty().append(tempFootnoteHTML);
}
catch(e) {
alert(e.toString());
}
}
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/oct08plo/clubHoliday/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/oct08plo/clubHoliday/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;
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);
}

