function SimpleMVCController() { }; var cachedViews = new Array(); var ViewsEnum = {START_VIEW: "startView", FLIGHTS_FORM: "FlightsForm", CONNECTING_FLIGHTS_FORM: "ConnectingFlightsForm", CONNECTING_FLIGHTS_RESULT: "ConnectingFlightsResult", FLIGHTS_NO_RESULT: "FlightsNoResults", FLIGHTS_ONE_RESULT: "FlightsOneResult", FLIGHTS_MULTIPLE_RESULTS: "FlightsMultipleResults"}; var data = {}; var currentMonth; var wt_controller = new SimpleMVCController(); data.searchByFlight = true; data.flightType = "arrival"; data.loading = false; var wtCities; var todaysDate; var latestDate; //The id of the div where everything will be repainted wt_controller.resultsContainer = "whichTerminalMainContainer"; /** * Attaches an autocompleter component with a field showing matching cities after * 3 characters are entered. */ wt_controller.fillCities = function(cityList, el) { wtCities = cityList; var tokens = wtCities; /*$("#ap-city, #ap-city-01, #ap-city-02, #wt_flyingLocation").autocompleteArray( wtCities, { delay:10, minChars:1, matchSubset:1, onItemSelect:selectItem, onFindValue:findValue, autoFill:true, maxItemsToShow:10 })*/ if ($ && $("#wt_flyingLocation")) { var a = $("#wt_flyingLocation").autocomplete({ minChars:2, delimiter: /[^\s]+\s+([^\s])/, // regex or character zIndex: 9999, deferRequestBy: 0, //miliseconds noCache: false, //default is false, set to true to disable caching // callback function: // local autosugest options: lookup: wtCities }); } /** removed code for autocompleter.js **/ }; wt_controller.GotCities = function(cities) { alert(cities); }; /** * Retrieves a list of cities to be used by autocompleter components */ /** removed code for autocompleter.js **/ /** * Injects the result html into the resultsContainer div */ wt_controller.showResults = function(result) { document.getElementById(wt_controller.resultsContainer).innerHTML = result; wt_controller.attachTips(); }; /** * Go back to the page */ wt_controller.showStartPage = function(result) { wt_controller.processAndDisplay(result, ViewsEnum.START_VIEW); //document.getElementById(wt_controller.resultsContainer).innerHTML = result; if(!cachedViews[ViewsEnum.START_VIEW]) { cachedViews[ViewsEnum.START_VIEW] = result; } }; /** * Hides the hideDiv component and displays the displayDiv component * This is for use in the form where the user can either choose to * enter a flight number or a destination. */ wt_controller.swapDivs = function(displayDiv, hideDiv) { document.getElementById(displayDiv).style.display = ""; document.getElementById(hideDiv).style.display = "none"; }; /** * Searches for arrival flights based on the date and either * the flight number or the airport arriving from. */ wt_controller.searchFlights = function() { if (!data.loading) { wt_controller.displayLoadingImage(true); if(wt_controller.validateFlightForm()) { data.errors = []; var flightDate = new Date(); var dateStr = document.forms["wt_flightForm"].elements["hiddenDateField"].value; var splitDateStr = dateStr.split("/"); var monthYearStr = splitDateStr[1].split(","); flightDate.setDate(splitDateStr[0]); flightDate.setMonth(monthYearStr[0]-1); flightDate.setFullYear(monthYearStr[1]); var flightCode = ""; var flightDest = ""; if(data.searchByFlight) { flightCode = document.forms["wt_flightForm"].elements["wt_flightNumber"].value; data.flightCode = flightCode; } else { flightDest = document.forms["wt_flightForm"].elements["wt_flyingLocation"].value; data.flightDest = flightDest; } if(data.flightType == "arrival") { AjaxTerminalFinderHelper.searchFlights(wtAirportCode, "A", flightDate, flightCode, flightDest, wt_controller.showFlightSearchResult); } if(data.flightType == "departure") { AjaxTerminalFinderHelper.searchFlights(wtAirportCode, "D", flightDate, flightCode, flightDest, wt_controller.showFlightSearchResult); } if(data.flightType == "connectingInbound") { AjaxTerminalFinderHelper.searchFlights(wtAirportCode, "A", flightDate, flightCode, flightDest, wt_controller.showFlightSearchResult); } if(data.flightType == "connectingOutbound") { AjaxTerminalFinderHelper.searchFlights(wtAirportCode, "D", flightDate, flightCode, flightDest, wt_controller.showFlightSearchResult); } } else { if(data.flightType == "connectingInbound" || data.flightType == "connectingOutbound") { wt_controller.getView(ViewsEnum.CONNECTING_FLIGHTS_FORM,wt_controller.showFlightsForm); } else { wt_controller.getView(ViewsEnum.FLIGHTS_FORM,wt_controller.showFlightsForm); } wt_controller.displayLoadingImage(false); } } }; wt_controller.showFlightNoResults = function(result) { wt_controller.processAndDisplay(result, ViewsEnum.FLIGHTS_NO_RESULT); }; /** * Validates that the given date is between today and six months. */ wt_controller.validateFlightForm = function() { var errors = new Array(); var dateStr = document.forms["wt_flightForm"].elements["hiddenDateField"].value; var splitStr = dateStr.split("/"); var day = splitStr[0]; var monthYearStr = splitStr[1].split(","); var month = monthYearStr[0]; var year = monthYearStr[1]; if(!wt_controller.checkBeforeToday(year, month, day)) { errors.push("Date is in the past"); } var date = new Date(); date.setFullYear(year); date.setMonth((month*1)-1); date.setDate(day); // entry date must be less than maximum date (13 months ahead) if( date.print("%Y%m") > wt_controller.getMaxMonthDate().print("%Y%m") ) { errors.push("Flight information held up to "+wt_controller.getMaxMonthDate().print("%m/%Y")+". Please select a date within the range."); } //need to also see if the destination is chosen, is it valid. if(!data.searchByFlight) { var arrivalFrom = document.forms["wt_flightForm"].elements["wt_flyingLocation"].value; if(arrivalFrom.length >0) { var found = false; for(var i=0;i-1) { found = true; break; } } if(!found) { if(data.flightType=="arrival" || data.flightType=="connectingInbound") { errors.push("Departure airport not found. Please double check."); } if(data.flightType=="departure" || data.flightType=="connectingOutbound") { errors.push("Destination not found. Please double check."); } //errors.push("Search airport not found. Please double check."); } } else { errors.push("Please specify an airport."); } } else { var flightCode = document.forms["wt_flightForm"].elements["wt_flightNumber"].value; if(flightCode == document.forms["wt_flightForm"].elements["wt_flightNumber"].title) { errors.push("Please enter a flight number."); } } if(errors.length>0) { data.errors = errors; return false; } else return true; }; /** * Display the first arriving/departure flights form and set up associated components * like the calendar and the autocompleter. This also caches the javascript * template for the arriving/departure flights form for future use. */ wt_controller.showFlightsForm = function(template) { var result2 = template.process(data); document.getElementById(wt_controller.resultsContainer).innerHTML = result2; wt_controller.displayLoadingImage(false); if(!(data.flightType == "connectingOutbound")) { //set date to today's date. wt_controller.setDateNow("wt_flightForm", new Date()); } else { //set date to selected inbound flight var selectedDate = data.selectedInboundFlight.scheduledStart; wt_controller.setDateNow("wt_flightForm", selectedDate); } new TextBoxHint("wt_flightNumber", "e.g. BA1234" ); new TextBoxHint("wt_flyingLocation", "Enter city or airport" ); /** removed code for autocompleter.js **/ if(data.flightType == "connectingInbound" || data.flightType == "connectingOutbound") { if(!cachedViews[ViewsEnum.CONNECTING_FLIGHTS_FORM]) { cachedViews[ViewsEnum.CONNECTING_FLIGHTS_FORM] = template; } } else { if(!cachedViews[ViewsEnum.FLIGHTS_FORM]) { cachedViews[ViewsEnum.FLIGHTS_FORM] = template; } } wt_controller.attachTips(); setDateWiget(); setAutoCompleter(); }; wt_controller.updateFlightDateHiddenField = function(formName) { var day = document.forms[formName].elements["termDay"].value; var monthYear = document.forms[formName].elements["termMonth"].value; var dp = $('.datepicker'); monthYear = monthYear.replace(',', ','); if (dp != null && dp[0] != null) { dp[0].value = day + '/' + monthYear.replace(',', '/'); } document.forms[formName].elements["flightDateHiddenField"].value = day + '/' + monthYear; }; wt_controller.updateMonthDays = function() { var monthSelect = document.getElementById("termMonth"); var monthString = monthSelect.options[monthSelect.selectedIndex].value; var monthStringSplit = monthString.split(","); var month = monthStringSplit[0]*1; var yearStr = monthStringSplit[1]; var year = yearStr*1; var maxDays = wt_controller.daysInMonth(month, year); var daySelect = document.getElementById("termDay"); var selectedDay = daySelect.selectedIndex; //removeAllOptions(daySelect); daySelect.length = 0; for(var i=1; i<=maxDays; i++) { wt_controller.addOption(daySelect,i,i); } daySelect.selectedIndex = selectedDay; }; /** * Validator for the Calendar component that disables certain dates * Here, no dates before and after 6 months ares selectable */ wt_controller.dateStatusHandler = function(date, y, m, d) { // entry date cannot be before today if(wt_controller.checkBeforeToday(y,m+1,d) == false) { return true; } // entry date must be less than maximum date (13 months ahead) //if( date.print("%Y%m") > wt_controller.getMaxMonthDate().print("%Y%m") ) { // return true; //} if(date.getTime() > latestDate.getTime()) { return true; } return false; }; /** * Checks whether the given date is before today * */ wt_controller.checkBeforeToday = function(yearStr, monthStr, dayStr) { monthStr = monthStr - 1; var theDate = new Date(); theDate.__msh_oldSetFullYear( yearStr, monthStr, dayStr); if ( theDate.print("%Y%m%d") < new Date().print("%Y%m%d") ) { return false; } else { return true; } }; /** * Sets the appropriate form date elements to today's date. */ wt_controller.setDateNow = function(formName, date) { //var now = new Date(); document.forms[formName].elements['hiddenDateField'].value = date.print("%e/%m,%Y"); document.forms[formName].elements['termMonth'].value = date.print("%m,%Y"); //document.forms['carparkquote'].elements['dd'].selectedIndex=now.getDate() - 2; document.forms[formName].elements['termDay'].value = date.getDate(); }; /** * Calculates the latest date possible that can be chosen using the calendar component */ wt_controller.getMaxMonthDate = function() { var maxMonth = data.flightMonths[data.flightMonths.length-1].value; var maxMonthMySplit = maxMonth.split(","); var monthStr = maxMonthMySplit[0]; var yearStr = maxMonthMySplit[1]; var maxMonthDate = new Date(); maxMonthDate.__msh_oldSetFullYear( yearStr, monthStr-1, 1); return maxMonthDate; }; /** * Gets a given javascript view template from the server and calls the given callback function. * Takes care to cache the view if it has been loaded from the server already. * */ wt_controller.getView = function(viewName, callBackFunc) { //check local cache first if(cachedViews[viewName]) { callBackFunc(cachedViews[viewName]); } else { //get from server AjaxTerminalFinderHelper.getViewTemplate(viewName, callBackFunc); } }; /** * Navigate from the start view to the arrival flights form * */ wt_controller.goToArrivalFlights = function() { data.flightType = "arrival"; wt_controller.clearMatchingData(); wt_controller.displayLoadingImage(true); wt_controller.getView(ViewsEnum.FLIGHTS_FORM,wt_controller.showFlightsForm); }; wt_controller.goToDepartureFlights = function() { data.flightType = "departure"; wt_controller.clearMatchingData(); wt_controller.displayLoadingImage(true); wt_controller.getView(ViewsEnum.FLIGHTS_FORM,wt_controller.showFlightsForm); }; wt_controller.goToConnectingInboundFlights = function() { data.flightType = "connectingInbound"; wt_controller.clearMatchingData(); wt_controller.displayLoadingImage(true); wt_controller.getView(ViewsEnum.CONNECTING_FLIGHTS_FORM,wt_controller.showFlightsForm); }; wt_controller.goToConnectingOutboundFlights = function() { data.flightType = "connectingOutbound"; wt_controller.clearMatchingData(); wt_controller.displayLoadingImage(true); wt_controller.getView(ViewsEnum.CONNECTING_FLIGHTS_FORM,wt_controller.showFlightsForm); }; wt_controller.goToStart = function() { data.errors = []; data.searchByFlight = true; wt_controller.clearMatchingData(); wt_controller.getView(ViewsEnum.START_VIEW, wt_controller.showStartPage); document.getElementById("whichTerminalMainContainer").style.display = ""; }; wt_controller.clearMatchingData = function() { data.matchingFlights = null; data.matchingFlight = null; } /** * Adds a given number of months to a date and returns it. * */ wt_controller.addMonthsToDate = function(startDate, numMonths){ var addYears = Math.floor(numMonths/12); var addMonths = numMonths - (addYears * 12); var newMonth = startDate.getMonth() + addMonths; if (startDate.getMonth() + addMonths > 11) { ++addYears; newMonth = startDate.getMonth() + addMonths - 12; } var newDate = new Date(startDate.getFullYear()+addYears,newMonth,startDate.getDate(),startDate.getHours(),startDate.getMinutes(),startDate.getSeconds()); // adjust to correct month while (newDate.getMonth() != newMonth) { newDate = wt_controller.addDaysToDate(newDate, -1); } return newDate; }; /** * Adds a given number of days to a date and returns it */ wt_controller.addDaysToDate = function(myDate,days) { return new Date(myDate.getTime() + (days*24*60*60*1000)); }; /** * Calculates the number of days in a month */ wt_controller.daysInMonth = function(iMonth, iYear) { return 32 - new Date(iYear, iMonth-1, 32).getDate(); }; /** * Event to notify form date elements that a date has been changed by the calendar * */ wt_controller.dateChanged = function(formName, dateValue) { var dates = dateValue.split("/"); // dates[0] = 31 // dates[1] = 08,07 (August 2007) document.forms[eval("\""+formName+"\"")].elements["termDay"].selectedIndex = dates[0]-1; document.forms[eval("\""+formName+"\"")].elements["termMonth"].value = dates[1]; wt_controller.updateMonthDays(); }; /** * component for implementing a hint in a textbox. The hint disappears when the focus is set to the textbox * and reappears when focus is removed. */ function TextBoxHint(inputBox, textHint) { if(!document.getElementById) return false; // If browser does not understand, get out now! if(!document.getElementById(inputBox)) return false; // If text box is not found get out! var inputBoxId = document.getElementById(inputBox); // Assign the hbw_postcode to postCodeBox inputBoxId.value = textHint; if (inputBoxId.addEventListener) { inputBoxId.addEventListener("focus", function() { if(inputBoxId.value == textHint) inputBoxId.value = ''; }, false); inputBoxId.addEventListener("blur", function() { if(inputBoxId.value == '') inputBoxId.value = textHint; }, false); } else if (inputBoxId.attachEvent) { inputBoxId.attachEvent("onfocus", function() { if(inputBoxId.value == textHint) inputBoxId.value = ''; }); inputBoxId.attachEvent("onblur", function() { if(inputBoxId.value == '') inputBoxId.value = textHint; }); } else { document.getElementById(inputBox).addEvent("focus", function() // When the user clicks in the box { if(inputBoxId.value == textHint) // If the value is the default value inputBoxId.value = ''; // Clear the box }); document.getElementById(inputBox).addEvent("blur", function() { if(inputBoxId.value == '') // If the box is empty inputBoxId.value = textHint; // Fill the box with instruction }); } }; /* * Initialize the date and month data to be used by the calendars * */ wt_controller.init = function() { dwr.engine.setHttpMethod("GET"); dwr.engine.setAsync(false); //Commented out this regex as we don't kno why it was used. Replaces with alpha-numeric matching regex so we don't have to modify all .inc files //data.regex = /[^a-z]{2,}\s+?([A-Z]{2,})+?|[A-Z]+/; data.regex = /.*/; data.errors = []; todaysDate = new Date(); var daysInMonth = wt_controller.daysInMonth(todaysDate.getMonth()+1,todaysDate.getFullYear()); var flightDays = new Array(daysInMonth); var tempDate = new Date(); for(var i=1;i<=daysInMonth;i++) { tempDate.setDate(i); flightDays[i] = { value: tempDate.print("%e"), display: tempDate.print("%d")}; } var flightMonths = new Array(6); flightMonths[0] = {value: todaysDate.print("%m,%Y"), display: todaysDate.print("%b %Y")}; latestDate = wt_controller.addDaysToDate(todaysDate, 180); var numberOfMonths = 0; if(latestDate.getMonth() 0) { data.matchingFlights = results; wt_controller.getView(ViewsEnum.FLIGHTS_MULTIPLE_RESULTS,wt_controller.showFlightMultipleResults); } }; wt_controller.showFlightDetails = function(flightCode) { wt_controller.displayLoadingImage(true); for(f in data.matchingFlights) { if(data.matchingFlights[f].flightCode == flightCode) { data.matchingFlight = data.matchingFlights[f]; break; } } wt_controller.getView(ViewsEnum.FLIGHTS_ONE_RESULT,wt_controller.showFlightOneResult); wt_controller.attachTips(); }; Array.prototype.findProperty = function(property, value) { var result = null; var i = 0; for(i=0;i

Which terminal?

\"Which

Check which terminal you need at Heathrow Airport.

"; if (document.getElementById(wt_controller.resultsContainer)) { document.getElementById(wt_controller.resultsContainer).innerHTML = resultHTML; } } } wt_controller.displayLoadingImage(false); wt_controller.attachTips(); }; wt_controller.displayLoadingImage = function(show) { if(show) { document.getElementById("wt_loadingImage").style.display = ""; } else { document.getElementById("wt_loadingImage").style.display = "none"; } data.loading = show; }; wt_controller.addOption = function(selectbox,text,value ) { var optn = document.createElement("OPTION"); optn.text = text; optn.value = value; selectbox.options.add(optn); } /** * Calls the init method upon load of the browser. */ //window.addEvent("load", wt_controller.init); if (window.addEventListener) { window.addEventListener("load", wt_controller.init, false); } else if (window.attachEvent) { window.attachEvent("onload", wt_controller.init); } else { window.onload = wt_controller.init; } /** * START: Script for Calender widget. */ function setDateWiget() { var dp = $('.datepicker'), setNewDate = function() { var $this = $(this), date = $this.val().split('/'), $selects = $this.parent().parent().find('select').slice(0,3); $selects.eq(0).val(parseInt(date[0],10)); $selects.eq(1).children().eq(parseInt(date[1],10) - 1).attr('selected', true); $selects.eq(2).val(parseInt(date[2],10)); }; dp.datepicker({ dateFormat : 'dd/mm/yy', minDate : new Date(), maxDate : '+1y', showOn : 'button', buttonImage : '/baa-airport-parking-portlet/images/icon-date-picker.gif', buttonImageOnly : true, buttonText : 'Pick a date', onClose : function() { setNewDate.call(this); }, onSelect: showDate }); dp.datepicker('setDate', new Date()); dp.each(function() { var $this = $(this), date = $this.val().split('/'), $selects = $this.parent().parent().find('select').slice(0,3); setNewDate.call(this); $selects.change(function() { var monthIndex = $selects.eq(1).children('option:selected').index() + 1, newDate; date[0] = $selects.eq(0).val(); date[1] = monthIndex < 10 ? '0' + monthIndex : monthIndex; date[2] = $selects.eq(2).val(); newDate = date.join('/'); $this.val(newDate); }); }); } function showDate(){ var dp = $('.datepicker') var arrDate = $(this).val().split('/'); if (arrDate != null) { var selectObj = getElementsByTag($(this).parent().parent().find('select').prevObject[0].parentNode, 'select'); if (selectObj != null) { if (arrDate[0] != null && arrDate[0].length >=2 && arrDate[0].substring(0,1) == "0") { arrDate[0] = arrDate[0].substring(1,2); } selectOption(selectObj[0], arrDate[0]); selectOption(selectObj[1], arrDate[1] + "," + arrDate[2]); } } } function selectOption(selectObj, val){ if (selectObj != null && val != null) { for (var i = 0; i < selectObj.length; i++) { if (selectObj.options[i].value == val) { selectObj.options[i].selected = "1"; } } } } function getElementsByTag(domNode, tagName) { if (domNode == null) domNode = document; if (tagName == null) tagName = '*'; var el = new Array(); var tags = domNode.getElementsByTagName(tagName); for(i=0,j=0; i