/* Lufthansa KOSA RD - booking JavaScripts
* Gui interaction for flightmanager and booking
* 'Observer.js' needed !
*/
var constants = {};
constants.flightmanager = {};
constants.booking = {};
// Controller for useractions
var controller = {
		flightmanager : {
			init: function (){
				controller.Notify({command:"init"});
			},
			tripModeChanged: function(){
				controller.Notify({command:"tripmodechanged"});
			},
			drivenModeChanged: function(id){
				controller.Notify({command:"drivenmodechanged"});
			},
			flightClassChanged: function(){
				controller.Notify({command:"flightclasschanged"});
			},
			setFirstClassPossible: function(){
				controller.Notify({command:"setfirstclasspossible",value:true});
			},
			setFirstClassNotPossible: function(){
				controller.Notify({command:"setfirstclasspossible",value:false});
			},
			displayFirstClassErrorMsg: function(){
				controller.Notify({command:"displayfirstclasserrrormsg"});
			},
			hideFirstClassErrorMsg: function(){
				controller.Notify({command:"hidefirstclasserrrormsg"});
			},
			setFareDrivenPossible: function(){
				controller.Notify({command:"setfaredrivenpossible",value:true});
			},
			setFareDrivenNotPossible: function(){
				controller.Notify({command:"setfaredrivenpossible",value:false});
			}
			
		},
		booking: {
			init: function (){
				controller.Notify({command:"init"});
				controller.Notify({command:"afterguiupdate"});
			},
			tripModeChanged: function(){
				controller.Notify({command:"tripmodechanged"});
			},
			flexChanged: function(id){
				if(bookingModel.checkAndSetCurrentDrivenId(id)){
					controller.Notify({command:"flexchanged"});
					controller.Notify({command:"afterguiupdate"});
				}
			},
			scheduleChanged: function(id){
				if(bookingModel.checkAndSetCurrentDrivenId(id)){
					controller.Notify({command:"schedulechanged"});
					controller.Notify({command:"afterguiupdate"});
					controller.Notify({command:"hidefirstclasserrrormsg"});
				}
			},
			flightClassChanged: function(){
				controller.Notify({command:"flightclasschanged"});
			},
			setFirstClassPossible: function(){
				controller.Notify({command:"setfirstclasspossible",value:true});
			},
			setFirstClassNotPossible: function(){
				controller.Notify({command:"setfirstclasspossible",value:false});
			},
			displayFirstClassErrorMsg: function(){
				controller.Notify({command:"displayfirstclasserrrormsg"});
			},
			hideFirstClassErrorMsg: function(){
				controller.Notify({command:"hidefirstclasserrrormsg"});
			},
			setFareDrivenPossible: function(){
				controller.Notify({command:"setfaredrivenpossible",value:true});
			},
			setFareDrivenNotPossible: function(){
				controller.Notify({command:"setfaredrivenpossible",value:false});
			}
			
		}	
}
try {
	inherits(new Subject(), controller);
}
catch (e){
	//
}
// +++ Start Flightmanager +++
// Model with all necessary formelements for gui logic in flightmanager
var flightManagerModel = {
	objRoundTripRadio: null,
	objOneWayRadio: null,
	objFlightClass: null,
	arrFirstClassValues: new Array(),
	arrFlightClassList: new Array(),
	objScheduleDrivenRadio: null,
	strScheduleDrivenRadioId: "",
	objFlexDrivenRadio: null,
	strFlexDrivenRadioId: "",
	strFirstClassValue: "",
	oneWayWithFlex: true,
	oneWayWithSchedule: true,
	firstClassPossible: true,
	fareDrivenPossible: true,
	defaultFlightClassValue: true,
	
	init: function (){
		this.objRoundTripRadio = dojo.byId(constants.flightmanager.RADIO_ID_ROUNDTRIP);
		this.objOneWayRadio = dojo.byId(constants.flightmanager.RADIO_ID_ONEWAY);
		this.objFlightClass = dojo.byId(constants.flightmanager.FLIGHTCLASS_ID_SELECT);
		if(this.strScheduleDrivenRadioId!="") this.objScheduleDrivenRadio = dojo.byId(this.strScheduleDrivenRadioId);
		if(this.strFlexDrivenRadioId!="") this.objFlexDrivenRadio = dojo.byId(this.strFlexDrivenRadioId);
		this._saveFlightClassList();
	},
	Update: function (obj){
			var command = obj.command?obj.command:"";
			if(command=="init")this.init();
	},
	// set oneway element behavior (config by backend)
	setOneWayWithFlex: function(booleanValue){
		this.oneWayWithFlex = booleanValue;	
	},
	setOneWayWithSchedule: function(booleanValue){
		this.oneWayWithSchedule = booleanValue;	
	},
	// ask for oneway element behavior (called from view)
	isOneWayWithFlex: function (){
		return this.oneWayWithFlex;
	},
	isOneWayWithSchedule: function (){
		return this.oneWayWithSchedule;
	},
	// ask for the state of the radioelments
	isRoundTripChecked: function (){
		return this.objRoundTripRadio.checked;
	},
	isOneWayChecked: function (){
		return this.objOneWayRadio.checked;
	},
	isFlexDrivenChecked: function () {
		if(this.objFlexDrivenRadio) return this.objFlexDrivenRadio.checked;
		else return false;
	},
	isScheduleDrivenChecked: function () {
		if(this.objScheduleDrivenRadio) return this.objScheduleDrivenRadio.checked;
		else return false;
	},
	// sets the roundtrip radio, if needed (eg. oneway is hidden)
	setRoundTripChecked: function (){
		this.objRoundTripRadio.checked = true;
	},
	// model must know which is the value of a firstclass option in flightclass list
	addFirstClassValue: function (strValue){
		this.arrFirstClassValues[this.arrFirstClassValues.length] = strValue;
	},
	// model must know which is the value of the default list item
	addDefaultFlightClassValue: function (strValue){
		this.defaultFlightClassValue = strValue;
	},
	// if firstclass in the flightclass list is selected it will return true.
	isFirstClassValueSelected: function (){
		for(var k=0; k<this.objFlightClass.length;k++){
			if(this.objFlightClass.value==this.arrFirstClassValues[k])return true;
		}
		return false;
	},
	// set the ids for the form elements (before init)
	setFlexDrivenRadioId: function (strValue){
		this.strFlexDrivenRadioId = strValue;		
	},
	setScheduleDrivenRadioId: function (strValue){
		this.strScheduleDrivenRadioId = strValue;		
	},
	//
	setScheduleDriven: function (){
		this.objScheduleDrivenRadio.checked = true;
		controller.flightmanager.drivenModeChanged(this.strScheduleDrivenRadioId);
	},
	getFlightClassListArrayWithoutFirstClass: function(){
		var retArray = new Array();
		for(var i=0; i<this.arrFlightClassList.length; i++) {
			var foundFlag = false;
			for(var j=0; j<this.arrFirstClassValues.length;j++){
				if(this.arrFlightClassList[i][0]==this.arrFirstClassValues[j])foundFlag=true;
			}
			if(!foundFlag)retArray[retArray.length] =  new Array(this.arrFlightClassList[i][0],this.arrFlightClassList[i][1],this.arrFlightClassList[i][2]);
		}
		return retArray;
	},
	getFlightClassListArray: function(){
		return this.arrFlightClassList;	
	},
	_saveFlightClassList: function(){
		// save flight class list for internal use.
		var tempLength = this.objFlightClass.length;
		for(var i=0; i<tempLength; i++) {
			this.arrFlightClassList[i] = new Array(this.objFlightClass.options[i].value,this.objFlightClass.options[i].text,this.objFlightClass.options[i].selected);
		}
	}
};
// Views for flightmanager. Views listen to messages from the controller
// Views getting state information about the gui from the model and react state dependend
// Flightmanager namespace for views
var flightmanager = {};

// View for the inputfields for the return date
// Elements will be hide if the user clicks "one way"
flightmanager.returnDateView = {
	Update: function (obj){
		var command = obj.command?obj.command:"";
		if((command=="tripmodechanged")||(command=="init")){
			if(flightManagerModel.isRoundTripChecked()){
				dojo.query("."+constants.flightmanager.RETURN_FLIGHT_DATE_X_CLASS,constants.flightmanager.X_CLASS_SEARCH_ROOT).style("visibility","visible");
			}
			if(flightManagerModel.isOneWayChecked()){
				dojo.query("."+constants.flightmanager.RETURN_FLIGHT_DATE_X_CLASS,constants.flightmanager.X_CLASS_SEARCH_ROOT).style("visibility","hidden");
			}
		}
	}
};
// View for the radiofield for the flex driven selection
// Elements will be hide if the user will fly first class.
flightmanager.fareDrivenView = {
	Update: function (obj){
		var command = obj.command?obj.command:"";
		if((command=="flightclasschanged")||(command=="init")||(command=="setfaredrivenpossible")){
			if(command=="setfaredrivenpossible"){
				flightManagerModel.fareDrivenPossible = obj.value?obj.value:false;				
			}
			if((flightManagerModel.isFirstClassValueSelected())&&(!flightManagerModel.fareDrivenPossible)){
				dojo.query("."+constants.flightmanager.FARE_DRIVEN_X_CLASS,constants.flightmanager.X_CLASS_SEARCH_ROOT).style("visibility","hidden");
				flightManagerModel.setScheduleDriven();
			}else{
				dojo.query("."+constants.flightmanager.FARE_DRIVEN_X_CLASS,constants.flightmanager.X_CLASS_SEARCH_ROOT).style("visibility","visible");
			}
		}
	}
};
// View for the radiofield for the oneway driven radio
// Oneway driven elements will be hide if it is necessary (depends on packend config).
flightmanager.oneWayView = {
	Update: function (obj){
		var command = obj.command?obj.command:"";
		if((command=="drivenmodechanged")||(command=="init")){
			if(flightManagerModel.isFlexDrivenChecked()){
				if(flightManagerModel.isOneWayWithFlex()){
					dojo.query("."+constants.flightmanager.ONEWAY_X_CLASS,constants.flightmanager.X_CLASS_SEARCH_ROOT).style("visibility","visible");
				}else{
					dojo.query("."+constants.flightmanager.ONEWAY_X_CLASS,constants.flightmanager.X_CLASS_SEARCH_ROOT).style("visibility","hidden");
					flightManagerModel.setRoundTripChecked();
					controller.flightmanager.tripModeChanged();
				}
			}else if(flightManagerModel.isScheduleDrivenChecked()){
				if(flightManagerModel.isOneWayWithSchedule()){
					dojo.query("."+constants.flightmanager.ONEWAY_X_CLASS,constants.flightmanager.X_CLASS_SEARCH_ROOT).style("visibility","visible");
				}else{
					dojo.query("."+constants.flightmanager.ONEWAY_X_CLASS,constants.flightmanager.X_CLASS_SEARCH_ROOT).style("visibility","hidden");
					flightManagerModel.setRoundTripChecked();
					controller.flightmanager.tripModeChanged();
				}
			}	
		}
	}
};
flightmanager.flightClassView = {

	Update: function (obj){
		var command = obj.command?obj.command:"";
		var tmpRet = false;
		if(command=="setfirstclasspossible"){
			
			controller.booking.hideFirstClassErrorMsg();
			flightManagerModel.firstClassPossible = obj.value?obj.value:"";
			
			if(flightManagerModel.isFlexDrivenChecked()){
				
				var tmpValue = flightManagerModel.isFirstClassValueSelected();
				if(!flightManagerModel.firstClassPossible){
					tmpRet = this._setFlightClasses(flightManagerModel.getFlightClassListArrayWithoutFirstClass());
					if(tmpValue){
						controller.booking.displayFirstClassErrorMsg();
					}
				}
				else if(flightManagerModel.firstClassPossible){
					tmpRet = this._setFlightClasses(flightManagerModel.getFlightClassListArray());
				}
			}else if(flightManagerModel.isScheduleDrivenChecked()){
				tmpRet = this._setFlightClasses(flightManagerModel.getFlightClassListArray());
			}
			if(tmpRet)controller.flightmanager.flightClassChanged();
		}
		if(command=="drivenmodechanged"){
			if(flightManagerModel.isFlexDrivenChecked()){
				var tmpValue = flightManagerModel.isFirstClassValueSelected();
				if(!flightManagerModel.firstClassPossible){
					tmpRet = this._setFlightClasses(flightManagerModel.getFlightClassListArrayWithoutFirstClass());
					if(tmpValue){
						controller.booking.displayFirstClassErrorMsg();
					}
				}
				else if(flightManagerModel.firstClassPossible){
					tmpRet = this._setFlightClasses(flightManagerModel.getFlightClassListArray());
				}
			}else if(flightManagerModel.isScheduleDrivenChecked()){
				tmpRet = this._setFlightClasses(flightManagerModel.getFlightClassListArray());
			}
			if(tmpRet)controller.flightmanager.flightClassChanged();
		}
	},
	
	_eraseAllFlighClasses: function(){
		var tempLength = flightManagerModel.objFlightClass.options.length;
		for(var i=0; i<tempLength; i++) {
			flightManagerModel.objFlightClass.remove(0);
		}
	},

	_setFlightClasses: function(arrFlightClass){
		if(flightManagerModel.objFlightClass.options.length != arrFlightClass.length){

			var selectedValue = flightManagerModel.objFlightClass.options[flightManagerModel.objFlightClass.selectedIndex].value;
			this._eraseAllFlighClasses();
			for(var i=0; i<arrFlightClass.length;i++){
				var ol = flightManagerModel.objFlightClass.options.length;
				flightManagerModel.objFlightClass.options[ol] = new Option(arrFlightClass[i][1], arrFlightClass[i][0], false, false);
			}
			var ol = flightManagerModel.objFlightClass.options.length;
			var foundIndex = null;
			for(var j=0; j<ol;j++){
				if(flightManagerModel.objFlightClass.options[j].value == flightManagerModel.defaultFlightClassValue){
					if(foundIndex==null)foundIndex = j;
				}else if(flightManagerModel.objFlightClass.options[j].value == selectedValue){
					foundIndex = j;
				}
			}
			if(foundIndex!=null)flightManagerModel.objFlightClass.options[foundIndex].selected = true;
			return true;
		}
		return false;
	}
};
// View for first class exeption - error msg will be shown, if first class is selected
// but not possible with orgin / destination combination
flightmanager.firstClassErrorMsgView = {
	Update: function (obj){
		var command = obj.command?obj.command:"";
		if(command=="displayfirstclasserrrormsg"){
			dojo.query("."+constants.flightmanager.FIRSTCLASS_EXCEP_MSG_X_CLASS).style("display","block");
		}
		if(command=="hidefirstclasserrrormsg"){
			dojo.query("."+constants.flightmanager.FIRSTCLASS_EXCEP_MSG_X_CLASS).style("display","none");
		}
	}
};

// +++ End Flightmanager +++
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// +++ Start Bookingscreen +++
// Model with all necessary formelements for gui logic the booking screen.
var bookingModel = {
		objRoundTripRadio: null,
		objOneWayRadio: null,
		objFlex3Radio: null,
		objFlex0Radio: null,
		objScheduleRadio: null,
		objFlightClass: null,
		strFlex3RadioId: "",
		strFlex0RadioId: "",
		strScheduleRadioId: "",
		arrFirstClassValues: new Array(),
		strCurrentDrivenId: "",
		booleanLastDrivenModeSchedule: true,
		oneWayWithFlex0: true,
		oneWayWithFlex3: true,
		oneWayWithSchedule: true,
		firstClassPossible: true,
		fareDrivenPossible: true,
		
		init: function (){
			this.objRoundTripRadio = dojo.byId(constants.booking.RADIO_ID_ROUNDTRIP);
			this.objOneWayRadio = dojo.byId(constants.booking.RADIO_ID_ONEWAY);
			this.objFlightClass = dojo.byId(constants.booking.SELECT_ID_FLIGHT_CLASS);
			if(this.strFlex3RadioId!="") this.objFlex3Radio = dojo.byId(this.strFlex3RadioId);
			if(this.strFlex0RadioId!="") this.objFlex0Radio = dojo.byId(this.strFlex0RadioId);
			if(this.strScheduleRadioId!="") this.objScheduleRadio = dojo.byId(this.strScheduleRadioId);
		},
		Update: function (obj){
			var command = obj.command?obj.command:"";
			if(command=="init")this.init();
			if(command=="afterguiupdate"){
				if(this.isScheduleDrivenChecked())this.setLastDrivenModeSchedule();
				else this.setLastDrivenModeFlex();
			}
		},
		// ask for the state of the radioelments
		isRoundTripChecked: function (){
			return this.objRoundTripRadio.checked;
		},
		isOneWayChecked: function (){
			return this.objOneWayRadio.checked;
		},
		isFlex3DrivenChecked: function () {
			if(this.objFlex3Radio) return this.objFlex3Radio.checked;
			else return false;
		},
		isFlex0DrivenChecked: function () {
			if(this.objFlex0Radio) return this.objFlex0Radio.checked;
			else return false;
		},
		isScheduleDrivenChecked: function () {
			if(this.objScheduleRadio) return this.objScheduleRadio.checked;
			else return false;
		},
		// sets the drivenmode radios
		setRoundTripChecked: function (){
			this.objRoundTripRadio.checked = true;
		},
		setOneWayChecked: function (){
			this.objOneWayRadio.checked = true;
		},
		// set oneway element behavior (config by backend)
		setOneWayWithFlex0: function(booleanValue){
			this.oneWayWithFlex0 = booleanValue;	
		},
		setOneWayWithFlex3: function(booleanValue){
			this.oneWayWithFlex3 = booleanValue;	
		},
		setOneWayWithSchedule: function(booleanValue){
			this.oneWayWithSchedule = booleanValue;	
		},
		// ask for oneway element behavior (called from view)
		isOneWayWithFlex0: function (){
			return this.oneWayWithFlex0;
		},
		isOneWayWithFlex3: function (){
			return this.oneWayWithFlex3;
		},
		isOneWayWithSchedule: function (){
			return this.oneWayWithSchedule;
		},
		// flags to avoid unneccessary reload of flightclass list if only a change from flex3 to flex0 is made
		setLastDrivenModeFlex: function (){
			if((this.isFlex0DrivenChecked())||(this.isFlex3DrivenChecked())){
				this.booleanLastDrivenModeSchedule = false;
			}
		},
		setLastDrivenModeSchedule: function (){
			if(this.isScheduleDrivenChecked())this.booleanLastDrivenModeSchedule = true;
		},
		isLastDrivenModeSchedule: function () {
			return this.booleanLastDrivenModeSchedule;
		},
		// if firstclass in the flightclass list is selected it will return true.
		isFirstClassValueSelected: function(){
			for(var k=0; k<this.objFlightClass.length;k++){
				if(this.objFlightClass.value==this.arrFirstClassValues[k])return true;
			}
			return false;
		},
		// model must know which is the value of a firstclass option in flightclass list
		addFirstClassValue: function (strValue){
			this.arrFirstClassValues[this.arrFirstClassValues.length] = strValue;
		},
		// needed to avoid problems with a second click on the current selected radio
		checkAndSetCurrentDrivenId: function(strId){
			if(this.strCurrentDrivenId!=strId){
				this.strCurrentDrivenId=strId;
				return true;
			}
			return false;
		},
		// set the ids for the form elements (before init)
		setFlex3DrivenRadioId: function (strValue){
			this.strFlex3RadioId = strValue;
		},
		setFlex0DrivenRadioId: function (strValue){
			this.strFlex0RadioId = strValue;
		},
		setScheduleDrivenRadioId: function (strValue){
			this.strScheduleRadioId = strValue;
		},
		//
		setNextDrivenRadio: function(){
			if(this.objFlex0Radio!=null){
				this.objFlex0Radio.checked = true;
				controller.booking.flexChanged(this.objFlex0Radio.id);
			}else{
				this.objScheduleRadio.checked = true;
				controller.booking.scheduleChanged(this.objScheduleRadio.id);
			}
		}
};
// Views for booking. Views listen to messages from the controller
// Views getting state information about the gui from the model and react state dependend
// Booking namespace for views
var booking = {};

// View for the outboud time (label and field)
// Visibility of this view depends on: schedule driven vs. flex driven
booking.outboundFlightTimeView = {
	Update: function (obj){
		var command = obj.command?obj.command:"";
		if((command=="flexchanged")||(command=="schedulechanged")||(command=="init")){
			if(bookingModel.isScheduleDrivenChecked()){
				dojo.query("."+constants.booking.OUTBOUND_FLIGHT_TIME_X_CLASS,constants.booking.X_CLASS_SEARCH_ROOT).style("visibility","visible");
			}else{
				dojo.query("."+constants.booking.OUTBOUND_FLIGHT_TIME_X_CLASS,constants.booking.X_CLASS_SEARCH_ROOT).style("visibility","hidden");
			}
		}
	}
};
// View for the return time (label and field)
// Visibility of this view depends on: oneway flight vs. return flight
booking.returnFlightDateView = {
	Update: function (obj){
		var command = obj.command?obj.command:"";
		if((command=="tripmodechanged")||(command=="init")){
			if(bookingModel.isRoundTripChecked()){
				dojo.query("."+constants.booking.RETURN_FLIGHT_DATE_X_CLASS,constants.booking.X_CLASS_SEARCH_ROOT).style("visibility","visible");
			}else{
				dojo.query("."+constants.booking.RETURN_FLIGHT_DATE_X_CLASS,constants.booking.X_CLASS_SEARCH_ROOT).style("visibility","hidden");
			}	
		}
	}
};
// View for the return time (label and field)
// Visibility of this view depends on: oneway fly vs. return fly and schedule driven vs. flex driven
booking.returnFlightTimeView = {
	Update: function (obj){
		var command = obj.command?obj.command:"";
		if((command=="flexchanged")||(command=="schedulechanged")||(command=="init")||(command=="tripmodechanged")){
			if((bookingModel.isScheduleDrivenChecked())&&(bookingModel.isRoundTripChecked())){
				dojo.query("."+constants.booking.RETURN_FLIGHT_TIME_X_CLASS,constants.booking.X_CLASS_SEARCH_ROOT).style("visibility","visible");
			}else{
				dojo.query("."+constants.booking.RETURN_FLIGHT_TIME_X_CLASS,constants.booking.X_CLASS_SEARCH_ROOT).style("visibility","hidden");
			}
		}
	}
};
// Interaction object (not really a view) for automatic filling the flightclass selectlist, depending on the driven selection
// State of this view depends on: schedule driven vs. flex driven
booking.flightClassView = {
	objFlightClassSel: null,
	arrScheduleDrivenFlightClasses: new Array(),
	arrFlexDrivenFlightClasses:  new Array(),
	flexDrivenDefaultFlightClassValue: null,
	
	init: function (){
		this.objFlightClassSel = dojo.byId(constants.booking.SELECT_ID_FLIGHT_CLASS);
	},
	Update: function (obj){
		var command = obj.command?obj.command:"";
		if(command=="init"){
			this.init();
			if(bookingModel.isScheduleDrivenChecked()){
				this._fillScheduleDrivenFlightClasses();
				controller.booking.flightClassChanged();
			}else if(bookingModel.isFlex0DrivenChecked()){
				this._fillFlexDrivenFlightClasses();
				controller.booking.flightClassChanged();
			}else if(bookingModel.isFlex3DrivenChecked()){
				this._fillFlexDrivenFlightClasses();
				controller.booking.flightClassChanged();
			}
		}
		if(command=="schedulechanged"){
			if(bookingModel.isScheduleDrivenChecked()){
				this._fillScheduleDrivenFlightClasses();
				controller.booking.flightClassChanged();
			}
		}
		if(command=="flexchanged"){
			if(bookingModel.isLastDrivenModeSchedule()){
				var tmpValue = bookingModel.isFirstClassValueSelected();
				if(bookingModel.isFlex0DrivenChecked()){
					this._fillFlexDrivenFlightClasses();
					controller.booking.flightClassChanged();
				}else if(bookingModel.isFlex3DrivenChecked()){
					this._fillFlexDrivenFlightClasses();
					controller.booking.flightClassChanged();
				}
				if((tmpValue)&&(!bookingModel.firstClassPossible)){
					controller.booking.displayFirstClassErrorMsg();
				}
			}
		}
		if(command=="setfirstclasspossible"){
			controller.booking.hideFirstClassErrorMsg();
			bookingModel.firstClassPossible = obj.value?obj.value:"";
			if(bookingModel.isFlex0DrivenChecked()||bookingModel.isFlex3DrivenChecked()){
				var tmpValue = bookingModel.isFirstClassValueSelected();
				this._fillFlexDrivenFlightClassesOnFirstClassException();
				controller.booking.flightClassChanged();
				if((tmpValue)&&(!bookingModel.firstClassPossible)){
					controller.booking.displayFirstClassErrorMsg();
				}
			}
		}
	},
	_fillScheduleDrivenFlightClasses: function (){
		if(this._isNewFlightClassList(this.arrScheduleDrivenFlightClasses)){
			this._eraseAllFlighClasses();
			for(var i=0; i<this.arrScheduleDrivenFlightClasses.length;i++){
				this.objFlightClassSel.options[this.objFlightClassSel.options.length] = new Option(this.arrScheduleDrivenFlightClasses[i].text, this.arrScheduleDrivenFlightClasses[i].value, false, false);
				if(this.arrScheduleDrivenFlightClasses[i].selected){
					this.objFlightClassSel.options[this.objFlightClassSel.options.length-1].selected = true;
				}
			}
		}
	},
	_fillFlexDrivenFlightClasses: function(){
		if(this._isNewFlightClassList(this.arrFlexDrivenFlightClasses)){
			// start to find out if first is selected
			var theFirstClassValue = null;
			for(var j=0; j<this.arrFlexDrivenFlightClasses.length; j++){
				for(var k=0; k<bookingModel.arrFirstClassValues.length; k++){
					if(this.arrFlexDrivenFlightClasses[j].value==bookingModel.arrFirstClassValues[k]){
						theFirstClassValue = this.arrFlexDrivenFlightClasses[j].value;
						break;
					}
				}
			}
			// end to find...
			this._eraseAllFlighClasses();

			for(var i=0; i<this.arrFlexDrivenFlightClasses.length;i++){
				if(bookingModel.firstClassPossible){
					this.objFlightClassSel.options[this.objFlightClassSel.options.length] = new Option(this.arrFlexDrivenFlightClasses[i].text, this.arrFlexDrivenFlightClasses[i].value, false, false);
				}else if(this.arrFlexDrivenFlightClasses[i].value != theFirstClassValue){
					this.objFlightClassSel.options[this.objFlightClassSel.options.length] = new Option(this.arrFlexDrivenFlightClasses[i].text, this.arrFlexDrivenFlightClasses[i].value, false, false);
				}
			}		
			// easier as in '_fillFlexDrivenFlightClassesOnFirstClassException' because the list is only reloaded if necessary because of the if at the beginning of the methode
			var ol = this.objFlightClassSel.options.length;
			for(var j=0; j<ol;j++){
				if(this.objFlightClassSel.options[j].value == this.flexDrivenDefaultFlightClassValue){
					this.objFlightClassSel.options[j].selected = true;
				}
			}
			
		}
	},
	_fillFlexDrivenFlightClassesOnFirstClassException: function(){
		var theFirstClassValue = null;
		var isFirstClassSelected = false;
		var selectedFlag = false;
		var selectedValue = null;
		for(var j=0; j<this.arrFlexDrivenFlightClasses.length; j++){
			for(var k=0; k<bookingModel.arrFirstClassValues.length; k++){
				if(this.arrFlexDrivenFlightClasses[j].value==bookingModel.arrFirstClassValues[k]){
					theFirstClassValue = this.arrFlexDrivenFlightClasses[j].value;
					break;
				}
			}
		}
		selectedValue = this.objFlightClassSel.options[this.objFlightClassSel.selectedIndex].value;
		
		this._eraseAllFlighClasses();
		
		for(var i=0; i<this.arrFlexDrivenFlightClasses.length;i++){
			if(bookingModel.firstClassPossible){
				this.objFlightClassSel.options[this.objFlightClassSel.options.length] = new Option(this.arrFlexDrivenFlightClasses[i].text, this.arrFlexDrivenFlightClasses[i].value, false, false);
			}else if(this.arrFlexDrivenFlightClasses[i].value != theFirstClassValue){
				this.objFlightClassSel.options[this.objFlightClassSel.options.length] = new Option(this.arrFlexDrivenFlightClasses[i].text, this.arrFlexDrivenFlightClasses[i].value, false, false);
			}
		}

		var ol = this.objFlightClassSel.options.length;
		var foundIndex = null;
		for(var j=0; j<ol;j++){
			if(this.objFlightClassSel.options[j].value == this.flexDrivenDefaultFlightClassValue){
				if(foundIndex==null)foundIndex = j;
			}else if(this.objFlightClassSel.options[j].value == selectedValue){
				foundIndex = j;
			}
		}
		if(foundIndex!=null)this.objFlightClassSel.options[foundIndex].selected = true;

	},
	_eraseAllFlighClasses: function(){
		var tempLength = this.objFlightClassSel.length;
		for(var i=0; i<tempLength; i++) {
			this.objFlightClassSel.remove(0);
		}
	},
	_isNewFlightClassList: function(arrFlightClassList){
		var boolReturn = false;
		// check if on init.
		if(!bookingModel.firstClassPossible){
			boolReturn = true;
		}else if(this.objFlightClassSel.length>1){
			for(var i=0; i<this.objFlightClassSel.length; i++) {
				var foundFlag = false;
				for(var j=0; j<arrFlightClassList.length; j++) {
					if(this.objFlightClassSel[i].value == arrFlightClassList[j].value)foundFlag = true;
				}
				if(!foundFlag){
					boolReturn = true;
					break;
				}
			}
		}else boolReturn = true;
		return boolReturn;
	},
	setScheduleDrivenFlightClass: function (objValue){
		this.arrScheduleDrivenFlightClasses[this.arrScheduleDrivenFlightClasses.length] = objValue;
	},
	setFlexDrivenFlightClass: function (objValue){
		this.arrFlexDrivenFlightClasses[this.arrFlexDrivenFlightClasses.length] = objValue;
	},
	setFlexDrivenDefaultFlightClassValue: function(strValue){
		this.flexDrivenDefaultFlightClassValue = strValue;
	}
};
// View for the fare driven option (label and radiofield)
// Visibility of this view depends on: first class selection vs. no first class selection
booking.fareDrivenView = {
	Update: function (obj){
		var command = obj.command?obj.command:"";
		if((command=="flightclasschanged")||(command=="init")||(command=="setfaredrivenpossible")){
			if(command=="setfaredrivenpossible"){
				bookingModel.fareDrivenPossible = obj.value?obj.value:false;				
			}
			
			if(bookingModel.isFirstClassValueSelected()&&(!bookingModel.fareDrivenPossible)){
				dojo.query("."+constants.booking.FARE_DRIVEN_X_CLASS,constants.booking.X_CLASS_SEARCH_ROOT).style("visibility","hidden");
				if(bookingModel.isFlex3DrivenChecked())bookingModel.setNextDrivenRadio();
			}else{
				dojo.query("."+constants.booking.FARE_DRIVEN_X_CLASS,constants.booking.X_CLASS_SEARCH_ROOT).style("visibility","visible");
			}
		}
	}
};
// View for the oneway radio and depends on the oneway/flex0/flex3 radios
// Elements will be hide if it is necessary (depends on backend config).
booking.oneWayView = {
	Update: function (obj){
		var command = obj.command?obj.command:"";
		if((command=="flexchanged")||(command=="schedulechanged")||(command=="init")){
			if(bookingModel.isFlex0DrivenChecked()){
				if(bookingModel.isOneWayWithFlex0()){
					dojo.query("."+constants.booking.ONEWAY_X_CLASS,constants.booking.X_CLASS_SEARCH_ROOT).style("visibility","visible");
				}else{
					dojo.query("."+constants.booking.ONEWAY_X_CLASS,constants.booking.X_CLASS_SEARCH_ROOT).style("visibility","hidden");
					bookingModel.setRoundTripChecked();
					controller.booking.tripModeChanged();
				}
			}else if(bookingModel.isFlex3DrivenChecked()){
				if(bookingModel.isOneWayWithFlex3()){
					dojo.query("."+constants.booking.ONEWAY_X_CLASS,constants.booking.X_CLASS_SEARCH_ROOT).style("visibility","visible");
				}else{
					dojo.query("."+constants.booking.ONEWAY_X_CLASS,constants.booking.X_CLASS_SEARCH_ROOT).style("visibility","hidden");
					bookingModel.setRoundTripChecked();
					controller.booking.tripModeChanged();
				}
			}else if(bookingModel.isScheduleDrivenChecked()){
				if(bookingModel.isOneWayWithSchedule()){
					dojo.query("."+constants.booking.ONEWAY_X_CLASS,constants.booking.X_CLASS_SEARCH_ROOT).style("visibility","visible");
				}else{
					dojo.query("."+constants.booking.ONEWAY_X_CLASS,constants.booking.X_CLASS_SEARCH_ROOT).style("visibility","hidden");
					bookingModel.setRoundTripChecked();
					controller.booking.tripModeChanged();
				}
			}	
		}
	}
};
// View for first class exeption - error msg will be shown, if first class is selected
// but not possible with orgin / destination combination
booking.firstClassErrorMsgView = {
	Update: function (obj){
		var command = obj.command?obj.command:"";
		if(command=="displayfirstclasserrrormsg"){
			dojo.query("."+constants.booking.FIRSTCLASS_EXCEP_MSG_X_CLASS).style("display","block");
		}
		if(command=="hidefirstclasserrrormsg"){
			dojo.query("."+constants.booking.FIRSTCLASS_EXCEP_MSG_X_CLASS).style("display","none");
		}
	}
};

// +++ End Bookingscreen +++

///////////////////////////////////////////////////////////////////////////
function selectPromotion(pHiddenFieldId,pPromoLinkListId,pOriginSelectionId,pDestinationSelectionId,pPromotionId, pOriginCode, pDestinationCode){
		document.getElementById(pHiddenFieldId).value=pPromotionId;
		// select promo
		linkArr = document.getElementById(pPromoLinkListId).getElementsByTagName('LI');
		
		for (var i = 0; i <linkArr.length ; i++){	
			if (cssClassChanger('verify',linkArr[i],'selected')){
				cssClassChanger('remove',linkArr[i],'selected');
			}
			
		}
		cssClassChanger('add',document.getElementById('promoLink'+pPromotionId),'selected');
		// select origin
		
		lLength = document.getElementById(pOriginSelectionId).length;
		
		// select origin
		for (var i = 0; i <lLength ; i++){
			lOptions = document.getElementById(pOriginSelectionId).options[i];
			if (lOptions.value == pOriginCode){
				lOptions.selected='selected';
			}else{
				lOptions.selected="";
			}
		}
		// select destination
		lLength = document.getElementById(pDestinationSelectionId).length;
		for (var i = 0; i <lLength ; i++){
			lOptions = document.getElementById(pDestinationSelectionId).options[i];
			if (lOptions.value == pDestinationCode){
				lOptions.selected='selected';
			}else{
				lOptions.selected="";
			}
		}
}
/// added for awardbooking
/// this method is used to copy the origin/destination of the outbound flight entered by the user
/// to the corresponding destination/origin fields of the inbound flight
function duplicateField(obj,strId)
{
	if(dojo.byId(strId).value==""){dojo.byId(strId).value=obj.value};
	
}
/// Some little gui interaction for we fly home special booking
/// like in flightmanager and booking, but js-code here is shorter.	
dojo.declare("lh.app.wfhSpecialBookingHandler", null, {
		radioRtId:"",
		radioOwId:"",
		xCssClass:".x-wfh-rt",

		constructor: function(p) {
			dojo.mixin(this, p);
			dojo.connect(dojo.byId(this.radioRtId),"onclick",this, "returnRadioClicked");
			dojo.connect(dojo.byId(this.radioOwId),"onclick",this, "returnOneWayClicked");
			if(dojo.byId(this.radioOwId).checked) this.returnOneWayClicked();
		},
		returnRadioClicked: function(){
			result = dojo.query(this.xCssClass);
			for(var i=0; i<result.length; i++){
				dojo.style(result[i],"visibility","visible");	
			}
		},
		returnOneWayClicked: function(){
			result = dojo.query(this.xCssClass);
			for(var i=0; i<result.length; i++){
				dojo.style(result[i],"visibility","hidden");	
			}
		}
	});
/// For Closed User Groups
dojo.declare("lh.app.cugHandler", null, {
	checkBoxId: "",
	xCssClass: ".cug-x",
	
	constructor: function(p) {
		dojo.mixin(this, p);
		dojo.connect(dojo.byId(this.checkBoxId),"onclick",this, "handleClicked");
		this.handleClicked();
	},
	
	handleClicked: function(){
		result = dojo.query(this.xCssClass);
		if(dojo.byId(this.checkBoxId).checked){
			for(var i=0; i<result.length; i++){
				dojo.style(result[i],"display","block");	
			}
		}else{
			for(var i=0; i<result.length; i++){
				dojo.style(result[i],"display","none");	
			}
		}
	}
});
// Some origin and destination combination do not allow firstclass
// Therefor the gui will change after an ajax request to the backend.
dojo.declare("lh.app.firstClassExceptionHandler",null, {
	
	getUrl:"",
	type: "firstclass",
	pos: "DE",
	originInpEleId:"",
	destinationInpEleId:"",
	originCodeInpEleId:"",
	destinationCodeInpEleId:"",
	originState: {text:"",code:""},
	destinationState: {text:"",code:""},
	
	constructor: function(p) {
		dojo.mixin(this, p);
		
		this.originEle = dojo.byId(this.originInpEleId);
		this.destinationEle = dojo.byId(this.destinationInpEleId);
		this.originCodeEle = dojo.byId(this.originCodeInpEleId);
		this.destinationCodeEle = dojo.byId(this.destinationCodeInpEleId);
		
		dojo.connect(this.originEle,"onfocus",this, "getOriginState");
		dojo.connect(this.destinationEle,"onfocus",this, "getDestinationState");
		
		dojo.connect(this.originEle,"onblur",this, "checkOriginChanged");
		dojo.connect(this.destinationEle,"onblur",this, "checkDestinationChanged");
		this.checkInit();		
	},
	
	getOriginState: function(){
		// input element gets focus, therefore the old value is stored to recognize a change, because in IE onchange-event does not work with disabled autocomplete
		this.originState.text = this.originEle.value;
		this.originState.code = this.originCodeEle.value;
	},

	getDestinationState: function(){
		// input element gets focus, therefore the old value is stored to recognize a change, because in IE onchange-event does not work with disabled autocomplete
		this.destinationState.text = this.destinationEle.value;
		this.destinationState.code = this.destinationCodeEle.value;
	},
	
	checkOriginChanged: function(){
		//console.debug("checkOriginChanged");
		var originParameter = "";
		var destinationParameter = "";
		if((this.originState.code!=this.originCodeEle.value)||(this.originState.text!=this.originEle.value)){
			// code changed or text changed
			// code will be send to backend if code is not empty, else text will be send to backend.
			if(this.originCodeEle.value!="")originParameter=this.originCodeEle.value;
			else if(this.originEle.value!="")originParameter=this.originEle.value;
			
			if(this.destinationCodeEle.value!="")destinationParameter=this.destinationCodeEle.value;
			else if(this.destinationEle.value!="")destinationParameter=this.destinationEle.value;
			// only request backend if both values are set.
			if((originParameter!="")&&(destinationParameter!=""))this.checkFirstClassException(originParameter,destinationParameter);
		}
	},
	
	checkDestinationChanged: function(){
		//console.debug("checkDestinationChanged");
		var originParameter = "";
		var destinationParameter = "";
		if((this.destinationState.code!=this.destinationCodeEle.value)||(this.destinationState.text!=this.destinationEle.value)){
			// code changed or text changed
			// code will be send to backend if code is not empty, else text will be send to backend.
			if(this.originCodeEle.value!="")originParameter=this.originCodeEle.value;
			else if(this.originEle.value!="")originParameter=this.originEle.value;
			
			if(this.destinationCodeEle.value!="")destinationParameter=this.destinationCodeEle.value;
			else if(this.destinationEle.value!="")destinationParameter=this.destinationEle.value;
			// only request backend if both values are set.
			if((originParameter!="")&&(destinationParameter!=""))this.checkFirstClassException(originParameter,destinationParameter);
		}
	},
	
	checkInit: function(){
		var originParameter = "";
		var destinationParameter = "";
		if(this.originCodeEle.value!="")originParameter=this.originCodeEle.value;
		else if(this.originEle.value!="")originParameter=this.originEle.value;
		
		if(this.destinationCodeEle.value!="")destinationParameter=this.destinationCodeEle.value;
		else if(this.destinationEle.value!="")destinationParameter=this.destinationEle.value;
		if((originParameter!="")&&(destinationParameter!=""))this.checkFirstClassException(originParameter,destinationParameter);	
	},
	
	checkFirstClassException: function(originValue,destinationValue){
		dojo.xhrGet({url:this.getUrl,
            		handleAs: "json",
            		content:{type:this.type,pos:this.pos,origin:originValue,destination:destinationValue},
                    load: this.handleResponse,
                    error: function(response, ioArgs){
                          console.error("HTTP status code: ",ioArgs.xhr.status);
                          return response;
                    }                   
		});

	},
	
	handleResponse:function(response,ioParams){
		if(response.result==true){
			controller.booking.setFirstClassPossible();
		}else if(response.result==false){
			controller.booking.setFirstClassNotPossible();
		}
	}
});

dojo.declare("lh.app.firstClassExceptionHandlerFLM",lh.app.firstClassExceptionHandler, {

	handleResponse:function(response,ioParams){
		if(response.result==true){
			controller.flightmanager.setFirstClassPossible();
		}else if(response.result==false){
			controller.flightmanager.setFirstClassNotPossible();
		}
	}
	
});

dojo.declare("lh.app.noFirstClassCOCHandler", null,{

	getUrl:"",
	pos: "DE",
	originInpEleId:"",
	originCodeInpEleId:"",
	originState: {text:"",code:""},

	constructor: function(p) {
		dojo.mixin(this, p);
		this.originEle = dojo.byId(this.originInpEleId);
		this.originCodeEle = dojo.byId(this.originCodeInpEleId);
		
		dojo.connect(this.originEle,"onfocus",this, "getOriginState");
		dojo.connect(this.originEle,"onblur",this, "checkOriginChanged");
		
	},
	
	getOriginState: function(){
		// input element gets focus, therefore the old value is stored to recognize a change, because in IE onchange-event does not work with disabled autocomplete
		this.originState.text = this.originEle.value;
		this.originState.code = this.originCodeEle.value;
		
	},
	
	checkOriginChanged: function(){
		var originParameter = "";
		var destinationParameter = "";
		if((this.originState.code!=this.originCodeEle.value)||(this.originState.text!=this.originEle.value)){
			// code changed or text changed
			// code will be send to backend if code is not empty, else text will be send to backend.
			if(this.originCodeEle.value!="")originParameter=this.originCodeEle.value;
			else if(this.originEle.value!="")originParameter=this.originEle.value;
			// only request backend if values is set.
			if(originParameter!="")this.checkFirstClassCOC(originParameter);
		}
	},
	
	checkFirstClassCOC: function(originValue){
		dojo.xhrGet({url:this.getUrl,
            		handleAs: "json",
            		content:{pos:this.pos,origin:originValue},
                    load: this.handleResponse,
                    error: function(response, ioArgs){
                          console.error("HTTP status code: ",ioArgs.xhr.status);
                          return response;
                    }                   
		});
	},
	
	handleResponse:function(response,ioParams){
		if(response.result==true){
			controller.booking.setFareDrivenPossible();
		}else if(response.result==false){
			controller.booking.setFareDrivenNotPossible();
		}
	}
	
});

dojo.declare("lh.app.noFirstClassCOCHandlerFLM", lh.app.noFirstClassCOCHandler,{
	
	handleResponse:function(response,ioParams){
		if(response.result==true){
			controller.flightmanager.setFareDrivenPossible();
		}else if(response.result==false){
			controller.flightmanager.setFareDrivenNotPossible();
		}
	}
});
