/*

	HITIT CMS INTEGRATION
	FLIGHT SEARCH API

*/

/* FlightSearch Constructor */
(function($, global){
	
	if(!$){
		console.log("jQuery is required by HITIT Flight Search API!");
	}
	
	var FlightSearch = function(){

		/*default values*/
		
		this.tripType = "ONE_WAY";
		this.tripTypeArea = $("#tripTypeArea");
		
		this.depPort = $("select#depPort");
		this.depPortArea = $("#depPortArea");
		
		this.arrPort = $("select#arrPort");
		this.arrPortArea = $("#arrPortArea");
		
		this.multiDepPort = $("select#multiDepPort");
		this.multiDepPortArea = $("#multiDepPortArea");
		
		this.multiArrPort = $("select#multiArrPort");
		this.multiArrPortArea = $("#multiArrPortArea");
		
		this.departureDate = $("input#departureDate");
		this.departureDateArea = $("#departureDateArea");
		
		this.returnDate = $("input#returnDate");
		this.returnDateArea = $("#returnDateArea");
		
		this.openDepartureDate = $("input#openDepartureDate");
		this.openDepartureDateArea = $("#openDepartureDateArea");
		
		this.openReturnDate = $("input#openReturnDate");
		this.openReturnDateArea = $("#openReturnDateArea");
		
		this.adult = $("select#adult");
		this.adultArea = $("#adultArea");
		
		this.child = $("select#child");
		this.childArea = $("#childArea");
		
		this.infant = $("select#infant");
		this.infantArea = $("#infantArea");
		
		this.student = $("select#student");
		this.studentArea = $("#studentArea");
		
		this.soldier = $("select#soldier");
		this.soldierArea = $("#soldierArea");
		
		this.discountsArea = $("#discountsArea");
		this.stcr = $("input#isStcrPnr");

		this.cabinClass =  $("#cabinClass");
		this.cabinClassArea =  $("#cabinClassArea");		
		
		this.currency = $("#currency");
		this.currencyArea =  $("#currencyArea");	
		
		this.actionURL = "RezvEntry.xhtml";
		
		this.depPortList = [{"selectItems":[{"disabled":false,"label":"Abuja (ABV)","value":"ABV","escape":true,"noSelectionOption":false},{"disabled":false,"label":"Benin (BNI)","value":"BNI","escape":true,"noSelectionOption":false},{"disabled":false,"label":"Jos (JOS)","value":"JOS","escape":true,"noSelectionOption":false},{"disabled":false,"label":"Lagos (LOS)","value":"LOS","escape":true,"noSelectionOption":false},{"disabled":false,"label":"Maiduguri (MIU)","value":"MIU","escape":true,"noSelectionOption":false},{"disabled":false,"label":"Port Harcourt (PHC)","value":"PHC","escape":true,"noSelectionOption":false},{"disabled":false,"label":"Sokoto (SKO)","value":"SKO","escape":true,"noSelectionOption":false},{"disabled":false,"label":"Warri (QRW)","value":"QRW","escape":true,"noSelectionOption":false},{"disabled":false,"label":"Yola (YOL)","value":"YOL","escape":true,"noSelectionOption":false}],"disabled":false,"label":"Nigeria","value":"NG","escape":false,"noSelectionOption":false}] || {};
		this.arrPortMatrix = {"LOS":[{"selectItems":[{"disabled":false,"label":"Abuja (ABV)","value":"ABV","escape":true,"noSelectionOption":false},{"disabled":false,"label":"Benin (BNI)","value":"BNI","escape":true,"noSelectionOption":false},{"disabled":false,"label":"Jos (JOS)","value":"JOS","escape":true,"noSelectionOption":false},{"disabled":false,"label":"Maiduguri (MIU)","value":"MIU","escape":true,"noSelectionOption":false},{"disabled":false,"label":"Port Harcourt (PHC)","value":"PHC","escape":true,"noSelectionOption":false},{"disabled":false,"label":"Sokoto (SKO)","value":"SKO","escape":true,"noSelectionOption":false},{"disabled":false,"label":"Warri (QRW)","value":"QRW","escape":true,"noSelectionOption":false},{"disabled":false,"label":"Yola (YOL)","value":"YOL","escape":true,"noSelectionOption":false}],"disabled":false,"label":"Nigeria","value":"NG","escape":false,"noSelectionOption":false}],"ABV":[{"selectItems":[{"disabled":false,"label":"Lagos (LOS)","value":"LOS","escape":true,"noSelectionOption":false},{"disabled":false,"label":"Maiduguri (MIU)","value":"MIU","escape":true,"noSelectionOption":false},{"disabled":false,"label":"Sokoto (SKO)","value":"SKO","escape":true,"noSelectionOption":false},{"disabled":false,"label":"Yola (YOL)","value":"YOL","escape":true,"noSelectionOption":false}],"disabled":false,"label":"Nigeria","value":"NG","escape":false,"noSelectionOption":false}],"SKO":[{"selectItems":[{"disabled":false,"label":"Abuja (ABV)","value":"ABV","escape":true,"noSelectionOption":false},{"disabled":false,"label":"Lagos (LOS)","value":"LOS","escape":true,"noSelectionOption":false}],"disabled":false,"label":"Nigeria","value":"NG","escape":false,"noSelectionOption":false}],"QRW":[{"selectItems":[{"disabled":false,"label":"Lagos (LOS)","value":"LOS","escape":true,"noSelectionOption":false}],"disabled":false,"label":"Nigeria","value":"NG","escape":false,"noSelectionOption":false}],"YOL":[{"selectItems":[{"disabled":false,"label":"Abuja (ABV)","value":"ABV","escape":true,"noSelectionOption":false},{"disabled":false,"label":"Lagos (LOS)","value":"LOS","escape":true,"noSelectionOption":false}],"disabled":false,"label":"Nigeria","value":"NG","escape":false,"noSelectionOption":false}],"MIU":[{"selectItems":[{"disabled":false,"label":"Abuja (ABV)","value":"ABV","escape":true,"noSelectionOption":false},{"disabled":false,"label":"Lagos (LOS)","value":"LOS","escape":true,"noSelectionOption":false}],"disabled":false,"label":"Nigeria","value":"NG","escape":false,"noSelectionOption":false}],"PHC":[{"selectItems":[{"disabled":false,"label":"Lagos (LOS)","value":"LOS","escape":true,"noSelectionOption":false}],"disabled":false,"label":"Nigeria","value":"NG","escape":false,"noSelectionOption":false}],"BNI":[{"selectItems":[{"disabled":false,"label":"Lagos (LOS)","value":"LOS","escape":true,"noSelectionOption":false}],"disabled":false,"label":"Nigeria","value":"NG","escape":false,"noSelectionOption":false}],"JOS":[{"selectItems":[{"disabled":false,"label":"Lagos (LOS)","value":"LOS","escape":true,"noSelectionOption":false}],"disabled":false,"label":"Nigeria","value":"NG","escape":false,"noSelectionOption":false}]} || {};
		
		this.maxPaxCount = 9 || 0;
		this.allowedPaxCount = 9 || 0;
		
		this.conditionalDiscountTypes = {} || [];
		
		this.conditinalDiscountMatrix = {"LOS#BNI":[],"BNI#LOS":[],"QRW#LOS":[],"ABV#LOS":[],"SKO#ABV":[],"JOS#LOS":[],"LOS#ABV":[],"LOS#YOL":[],"LOS#QRW":[],"ABV#SKO":[],"PHC#LOS":[],"ABV#YOL":[],"ABV#MIU":[],"LOS#MIU":[],"SKO#LOS":[],"LOS#SKO":[],"LOS#JOS":[],"YOL#ABV":[],"LOS#PHC":[],"MIU#LOS":[],"YOL#LOS":[],"MIU#ABV":[]} || {};
		
		this.dateFormat = "dd/MM/yyyy";
		
		this.language = "en" || $("html").attr("lang");

		this.digits = ["0","1","2","3","4","5","6","7","8","9"] || [];

		this.cabinClassListMap =  {} || {};
		this.currencyListMap =  {} || {};
		this.paxNationType = {} || {};
		this.rbd = $("input#rbd");
		
	};

	FlightSearch.prototype.init = function(){

		this.selectTripType(this.tripType);
		this.selectDepPort(this.depPort.val());
		this.selectArrPort(this.arrPort.val());
		
		if(this.multiDepPort.length > 0 && this.multiArrPort.length > 0){
			this.selectMultiDepPort(this.multiDepPort.val());
			this.selectMultiArrPort(this.multiArrPort.val());
		}
		
		this.selectDateFormat(this.dateFormat);
		
		this.fillDepPorts();
		this.fillPaxCombos();
		this.fillCabinClass();
		this.fillCurrency();

	};

	FlightSearch.prototype.selectDateFormat = function(dateFormat){

		this.dateFormat = dateFormat;
		
		this.departureDate.attr("format", dateFormat);
		
		this.returnDate.attr("format", dateFormat);

	};

	FlightSearch.prototype.fillDepPorts = function(){
		
		var depPortList = this.depPortList;
		
		var departurePortCombos = this.depPort.add(this.multiDepPort);

		departurePortCombos.each(function(){
		
			var placeholder = $(this).attr("placeholder");
		
			var selectMenu = $(this);
			
			selectMenu.html("<option value=''>"+placeholder+"</option>");
			
			$.each(depPortList, function(i, selectItem){
				var group = selectItem.selectItems;
				if(group){
					var optGroup = $("<optgroup/>").prop(selectItem).text(selectItem.label).attr('val', selectItem.value);
					$.each(group, function(i, selectItem){
						$("<option/>")
						.prop(selectItem)
						.text(selectItem.label)
						.appendTo(optGroup);
					});
					optGroup.appendTo(selectMenu);
				}else{
					 $("<option/>")
					 .prop(selectItem)
					 .text(selectItem.label)
					 .appendTo(selectMenu);
				}
			});
		
		});
	};

	FlightSearch.prototype.fillPaxCombos = function(){

		var digits = this.digits;
		
		var paxCombos = this.adult;
		paxCombos = paxCombos.add(this.child);
		paxCombos = paxCombos.add(this.infant);
		paxCombos = paxCombos.add(this.soldier);
		paxCombos = paxCombos.add(this.student);
		
		var maxPaxCount = this.maxPaxCount;
		
		paxCombos.each(function(){
		
			var selectMenu = $(this);
			
			selectMenu.html("");
			
			
			var placeholder = typeof ($(this).attr("placeholder") && $(this).attr("placeholder").length) != "undefined" ? $(this).attr("placeholder") : 0;

			selectMenu.append("<option value='0'>"+placeholder+"</option>");
		
			for(var i = 1; i <= maxPaxCount; i++){
			
				selectMenu.append("<option value='"+i+"'>"+digits[i]+"</option>");
			
			}
		
		});
	};

	FlightSearch.prototype.fillCabinClass = function(){
		
	    var flightSearch = this;
	    
	    flightSearch.isAvailable.cabinClass = !flightSearch.isNullOrEmpty(this.cabinClassListMap);
	    
	   
		if (flightSearch.isAvailable.cabinClass) {
			
			flightSearch.cabinClass.html("<option value=''>"+ flightSearch.cabinClass.attr("placeholder") +"</option>");
			
			$.each(flightSearch.cabinClassListMap, function(key, val) {
	            
	            $("<option/>")
	                .val(key)
	                .text(val)
	                .appendTo(flightSearch.cabinClass);			
				
			});
			
		}else{
			flightSearch.cabinClassArea.remove();
	    }
			
		
	};

	FlightSearch.prototype.fillCurrency = function(){
		
	    var flightSearch = this;
	    
	    flightSearch.isAvailable.currency = !flightSearch.isNullOrEmpty(this.currencyListMap);
	    
		if (flightSearch.isAvailable.currency) {
			
			flightSearch.currency.html("<option value=''>"+ flightSearch.currency.attr("placeholder") +"</option>");
			
			$.each(flightSearch.currencyListMap, function(key, val) {
	            
	            $("<option/>")
	                .val(key)
	                .text(val)
	                .appendTo(flightSearch.currency);			
				
			});
			
		}else{
			flightSearch.currencyArea.remove();
	    }
			
		
	};

	FlightSearch.prototype.selectDepPort = function(portCode){

			this.depPort.val(portCode);
			this.generateArrivalOptions(
				this.depPort,
				this.arrPort
			);
			this.residentNationAreaControl();
	};

	FlightSearch.prototype.selectArrPort = function(portCode){

			this.arrPort.val(portCode);
			this.toggleConditionalDiscountSelect(
				this.depPort,
				this.arrPort
			);
			this.residentNationAreaControl();
	};

	FlightSearch.prototype.selectMultiDepPort = function(portCode){

			this.multiDepPort.val(portCode);
			this.generateArrivalOptions(
				this.multiDepPort,
				this.multiArrPort
			);

	};

	FlightSearch.prototype.selectMultiArrPort = function(portCode){
		
			this.multiArrPort.val(portCode);
			this.toggleConditionalDiscountSelect(
				this.multiDepPort,
				this.multiArrPort
			);
		
	};

	FlightSearch.prototype.selectDepartureDate = function(date){
		
			this.departureDate.val(date);
			
			this.returnDate.attr("min", date);
			
		
	};

	FlightSearch.prototype.selectReturnDate = function(date){
		
			this.returnDate.val(date);
			
			this.departureDate.attr("max", date);
		
	};

	FlightSearch.prototype.selectTripType = function(tripType){

			this.tripType = tripType.length == 0 ? this.tripTypeArea.find(":checked").val() : tripType;
			
			this.tripTypeArea.find(":not([value='"+tripType+"'])").prop("checked",false);
			this.tripTypeArea.find("[value='"+tripType+"']").prop("checked",true);

			/*Hide all conditional areas*/
			
			this.departureDateArea.hide();
			this.returnDateArea.hide();
			this.multiDepPortArea.hide();
			this.multiArrPortArea.hide();
			this.openDepartureDateArea.hide();
			this.openReturnDateArea.hide();
			
			/*Clean isAvailable List*/
			this.isAvailable = {};

			switch(tripType){
			
				case "ONE_WAY":
					this.departureDateArea.show();
					this.isAvailable.departureDate = true;
					break;
				
				case "ROUND_TRIP":
					this.departureDateArea.show();
					this.returnDateArea.show();
					this.isAvailable.departureDate = true;
					this.isAvailable.returnDate = true;
					break;
					
				case "MULTI_DIRECTIONAL":
					this.departureDateArea.show();
					this.returnDateArea.show();
					this.isAvailable.departureDate = true;
					this.isAvailable.returnDate = true;
					
					this.multiDepPortArea.show();
					this.isAvailable.multiDepPort = true;
					
					this.multiArrPortArea.show();
					this.isAvailable.multiArrPort = true;
					
					break;
					
				case "INBOUND_OPEN":
					this.departureDateArea.show();
					this.openReturnDateArea.show();
					this.isAvailable.departureDate = true;
					this.isAvailable.openReturnDate = true;				
					break;	
					
				case "OUTBOUND_OPEN":
					this.openDepartureDateArea.show();
					this.returnDateArea.show();
					this.isAvailable.openDepartureDate = true;	
					this.isAvailable.returnDate = true;			
					break;				
			
			}

			this.toggleConditionalDiscountSelect(
				this.depPort,
				this.arrPort
			);
	};

	FlightSearch.prototype.search = function(){

		if(this.check()){

	    var that = this;
			
			if (this.stcr.length && this.adult.val() < 2 && this.stcr[0].checked) {
				alert("ERROR_STRETCHER_PNR_ADULT_COUNT");
				return false;
			}
			
			var formData = {};
			
			formData.tripType = this.tripType;
			formData.language = this.language;
			formData.dateFormat = this.dateFormat;
			formData.rbd = this.rbd.val();
					
			formData.depPort = this.depPort.val();
			formData.arrPort = this.arrPort.val();
			
			formData.adult = this.adult.val();
			formData.child = this.child.val();
			formData.infant = this.infant.val();
			
			formData.prefferedCabinClass = this.cabinClass.val();
			formData.currency = this.currency.val();
			if(this.stcr.length){
				formData.stcr=this.stcr[0].checked;
			}
			if (this.discountsArea.length && this.discountsArea[0].innerHTML != "") {
				for (i=0; i<this.discountsArea[0].childNodes.length; i++) {
					var id = this.discountsArea[0].childNodes[i].childNodes[1].id;
					formData[id] = document.getElementById(id).value;
				};
			};		
				
			$.each(this.isAvailable, function(key, val){
			
				if(val)
					formData[key] = that[key].val();
							
			});
			
			
			if("F" == "T" ){
				if( parseInt(this.soldier.val()) > 0 ){
					alert("?FLT_SEARCH_SLDR_ALERT_TEXT?");
				}
				if(parseInt(this.student.val()) > 0 || parseInt(formData["PD-ADLT-ST"]) > 0){
					alert("?FLT_SEARCH_STDT_ALERT_TEXT?");
				}
			}
			if ($("#residentNation").is(":checked")){
				formData.residentFare = "true";
			}
			this.postData(formData, this.actionURL);
		}

	};

	FlightSearch.prototype.check = function(){

		var errorMessages = "";
		
		if(this.tripType == "")
			errorMessages += "?Please select trip type.?" + '\n';
		
		/*---------------------Port Check---------------------*/
		
		if(this.isNullOrEmpty(this.depPort.val()))
			errorMessages += "?Please select departing port?" + '\n';
		
		if(this.isNullOrEmpty(this.arrPort.val()))
			errorMessages += "?Please select arrival port?" + '\n';
		
		if(this.isAvailable.multiDepPort && this.isNullOrEmpty(this.multiDepPort.val()))
			errorMessages += "?Please select departing port?" + '\n';
		
		if(this.isAvailable.multiArrPort && this.isNullOrEmpty(this.multiArrPort.val()))
			errorMessages += "?Please select arrival port?" + '\n';
			
		/*-----------------------------------------------------*/
		
		/*---------------------Pax Check-----------------------*/

		var totalAdultCount = 
	            parseInt(this.adult.val() || 0) +
	            parseInt(this.student.val() || 0) +
	            parseInt(this.soldier.val() || 0);
	    
		var totalChildCount = parseInt(this.child.val() || 0);
		var totalInfantCount = parseInt(this.infant.val() || 0);
		
		if (this.discountsArea.length) {
			for (i=0; i<this.discountsArea[0].childNodes.length; i++) {
				var adultExp = new RegExp("ADLT", "g");
				var childExp = new RegExp("CHLD", "g");
				
				if (adultExp.test(this.discountsArea[0].childNodes[i].id))
					totalAdultCount += parseInt(this.discountsArea[0].childNodes[i].childNodes[1].value || 0);
				else if (childExp.test(this.discountsArea[0].childNodes[i].id))
					totalChildCount += parseInt(this.discountsArea[0].childNodes[i].childNodes[1].value || 0);
			};
		};
		
		/*Infant Check*/
		if(totalInfantCount > totalAdultCount)
			errorMessages += "Infant Count Can Not Be Greater Than Adult Count" + '\n';
		
		/*Child Check*/
		if(totalAdultCount == 0 && totalChildCount > 0)
			errorMessages += "?Alert Without parents to make the trip, please call call center.?" + '\n';
			
		/*Minimum Pax Count Check*/
		if( (totalAdultCount + totalChildCount) == 0 )
			errorMessages += "At Least One Passenger Should Be Selected" + '\n';
			
		/*Maximum Pax Count Check*/
		if( (totalAdultCount + totalChildCount) > this.allowedPaxCount )
			errorMessages += "Passenger Count Exceeds Max Number" + '\n';
			
		/*-----------------------------------------------------*/
		
		/*---------------------Date Check----------------------*/
		
		if( this.isInvalidDate(this.departureDate.val()) || this.checkDateIsBeforeToday(this.departureDate.val()))
			errorMessages += "Please Select Departure Date" + '\n';
			
		if( this.isAvailable.returnDate && this.isInvalidDate(this.returnDate.val()) )
			errorMessages += "Please Select Arrival Date" + '\n';
			
		
		/*-----------------------------------------------------*/
		
		/*-------------Parametric Cabin Class Check------------*/
		
		if(this.isNullOrEmpty(this.cabinClassList) && (false || false) && this.isNullOrEmpty(this.cabinClass.val()))
			errorMessages += "?Please select cabin class.?" + '\n';
		
		/*-----------------------------------------------------*/
		
		if(false && this.isNullOrEmpty(this.currency.val()))
			errorMessages += "?Please select currency.?" + '\n';
		
		if(errorMessages.length > 0){
			alert(errorMessages);
			return false;
		}else{
			return true;
		}

	};

	/**
		Private functions
		
		Warning:
		It is not safe to call externally!
	**/

	FlightSearch.prototype.postData = function(formData, actionURL){

			//Create a virtual form
			var form = $("<form/>").prop({
					action : actionURL,
					method : 'post',
					target : '_self'
				});
				
			//Each value is processed in here as an property of that virtual form.
			$.each(formData, function (i, e) {
				//Create a virtual input
				var input = $("<input/>");
				input.prop({
					type : "hidden",
					name : i
				}).val(e);
				//Append that input to our form
				form.append(input);
			});
			
			form
			.appendTo('body').submit().remove();
		

	};

	FlightSearch.prototype.generateArrivalOptions = function(departurePort, arrivalPort){
		
		var placeholder = arrivalPort.attr("placeholder");
		
		arrivalPort.html("<option value=''>"+placeholder+"</option>");
		
		var destinationList = this.arrPortMatrix[departurePort.val()]
		
		if(destinationList){
			$.each(destinationList, function(i, selectItem){
				var group = selectItem.selectItems;
				if(group){
					var optGroup = $("<optgroup/>").prop(selectItem).text(selectItem.label).attr('val', selectItem.value);
					$.each(group, function(i, selectItem){
						$("<option/>")
						.prop(selectItem)
						.text(selectItem.label)
						.appendTo(optGroup);
					});
					optGroup.appendTo(arrivalPort);
				}else{
					$("<option/>")
					.prop(selectItem)
					.text(selectItem.label)
					.appendTo(arrivalPort);
				}
			});
		}
		

	};

	FlightSearch.prototype.toggleConditionalDiscountSelectFunction = function(departurePort, arrivalPort){
		
		/*Set both to zero*/	
		this.student.val(0);
		this.soldier.val(0);
		
		this.isAvailable.student = false;				
		this.isAvailable.soldier = false;
		
		var that = this;
		
		var studentArea = this.studentArea.hide();
		
		var soldierArea = this.soldierArea.hide();
		
		function generateDiscountArea(code){
				if (document.getElementById(code) == null) {
					var elID = code;
					var elemDiv = document.createElement("div");
					elemDiv.id = elID + "Area";
					var label = document.createElement("label");
					label.innerHTML = that.conditionalDiscountTypes[elID];
					var select = document.createElement("select");
					select.id = elID;
					
					var discounts = document.getElementById("discountsArea");
					discounts.innerHTML = "";
					discounts.appendChild(elemDiv);
					document.getElementById(elID + "Area").appendChild(label)
					document.getElementById(elID + "Area").appendChild(select);
					
					var selectMenu = document.getElementById(elID);
				
					
					
					var option = document.createElement("option");
					option.value = 0;
					option.innerHTML = that.conditionalDiscountTypes[elID];
					selectMenu.appendChild(option);
					
					var digits = new FlightSearch;
					for(var i = 1; i <= digits.digits.length - 1; i++){
						var option = document.createElement("option");
						option.value = digits.digits[i];
						option.innerHTML = digits.digits[i];
						selectMenu.appendChild(option);
					
					};
					
					discounts.style.display = "block";
				};
		}

		var eligiblePassengerTypeList = this.conditinalDiscountMatrix[departurePort.val() + '#' + arrivalPort.val()];
		
		var tripExp = new RegExp("ROUND", "g");	
		if (tripExp.test(this.tripType) && eligiblePassengerTypeList) {
			eligiblePassengerTypeList = eligiblePassengerTypeList.concat(this.conditinalDiscountMatrix[arrivalPort.val() + '#' + departurePort.val()]);
		}
			
		if(eligiblePassengerTypeList){
			$.each(eligiblePassengerTypeList, function(index, code){
				switch(code){
					case "STDT":
						that.isAvailable.student = true;
						studentArea.show();
						break;
					case "SLDR":
						that.isAvailable.soldier = true;
						soldierArea.show();
						break;
					default:
						generateDiscountArea(code);
						break;
				
				};
		
		});
		}
		
	};

	FlightSearch.prototype.toggleConditionalDiscountSelect = function(departurePort, arrivalPort){
		
		if (this.discountsArea.length) {
			this.discountsArea[0].innerHTML = "";
		};
		
		this.toggleConditionalDiscountSelectFunction(departurePort, arrivalPort);

	};

	FlightSearch.prototype.isNullOrEmpty = function(value){

		return (value == null || value == ""); //  || !(Object.keys(value).length)

	};

	FlightSearch.prototype.isInvalidDate = function(dateString){

		return (dateString == null || dateString == "");

	};

	FlightSearch.prototype.checkDateIsBeforeToday = function(dateString){

		return false;
	};

	FlightSearch.prototype.residentNationAreaControl = function (){
		if (this.paxNationType.depCountry && this.paxNationType.arrCountry) {
			var depSelected = $('select#depPort option:selected');
			var arrSelected = $('select#arrPort option:selected');

			if (depSelected && arrSelected) {
				var depCountry = depSelected.closest('optgroup').val();
				var arrCountry = arrSelected.closest('optgroup').val();

				if (depCountry && arrCountry && this.paxNationType.depCountry === depCountry && this.paxNationType.arrCountry === arrCountry) {
					$('#residentNationArea').show();
				} else {
					$('#residentNationArea').hide();
				}
			} else {
				$('#residentNationArea').hide();
			}
		} else {
			$('#residentNationArea').hide();
		}
	}
	
	global.FlightSearch = FlightSearch; //Put FlightSearch API prototype into global object
	
}(jQuery, window)); //Assign jQuery as $, window as global in this scope. To be extended for other frameworks
