//	********************************************************************************************************
//		CSearchFormHandler.js
//	********************************************************************************************************
//
//		CREATED FROM:	Robert Stiehler (idaSys)
//		CREATED AT:	11.09.2008
//		
//		UPDATES:
//
//	--------------------------------------------------------------------------------------------------------


//class CSearchFormHandler
//{
//public:
	function CSearchFormHandler()
	{
	//public:
		this.initializeSearchForm = declared_initializeSearchForm;
		this.setForumlarPreSection = declared_setForumlarPreSection;
		this.setTopDestinations = declared_setTopDestinations;
		this.initAirportsLL = declared_initAirportsLL;
		this.changeAirport = declared_changeAirport;
		this.setSeason = declared_setSeason;
		this.setSc = declared_setSc;
		this.SearchSubmit = declared_SearchSubmit;
		this.dateDependenciesOnChange = declared_dateDependenciesOnChange;
		this.loadFormValues = declared_loadFormValues;
		this.selectDepartureDate = declared_selectDepartureDate;
		this.selectArrivalDate = declared_selectArrivalDate;
		this.clearSearchFormForNewContent = declared_clearSearchFormForNewContent;
		this.objCalendarHandler = new CCalendarHandler();
		
		this.setDefaultDaysToDeparture = declared_setDefaultDaysToDeparture;
		this.setPreSelectedDuration = declared_setPreSelectedDuration;

		this.initWettendassHandler = declared_initWettendassHandler;

		//protected:
		this.createDateMonths = declared_createDateMonths;
		this.createDateDays = declared_createDateDays;
		this.getNumberOfDaysInMonth = declared_getNumberOfDaysInMonth;
		this.createAdultPax = declared_createAdultPax;
		this.createChildPax = declared_createChildPax;
		this.objSearchChildFormHandler = new CSearchChildFormHandler();
		this.objSearchChildFormBuilder = new CSearchChildFormBuilder();
		this.objCalendarBuilder = new CCalendarBuilder();
		
	//private:
		this.inArray = declared_inArray;
		this.adaptDays = declared_adaptDays;
		this.saveFormValues = declared_saveFormValues;
		this.SetInput = declared_SetInput;
		this.SFH_isInternetExplorer = declared_SFH_isInternetExplorer;
		
		this.log = xajax_logStringToFile;
		
	//protected attributes:
		this.preSelectedDuration = 3;
		
	//private attributes:
		this.AirportDepArrayTMP = new Array();
		this.AirportArrArrayTMP = new Array();
		
		this.TopDestinationAirportArray = new Array();
		
		this.defaultDaysToDeparture = 7;
		this.MonthArray = new Array(translationsTextSearchForm["Jan"], translationsTextSearchForm["Feb"], translationsTextSearchForm["Mar"], translationsTextSearchForm["Apr"], translationsTextSearchForm["Mai"], translationsTextSearchForm["Jun"], translationsTextSearchForm["Jul"], translationsTextSearchForm["Aug"], translationsTextSearchForm["Sep"], translationsTextSearchForm["Okt"], translationsTextSearchForm["Nov"], translationsTextSearchForm["Dez"]);
		this.UpToNumberOfMonth = 13;
		this.UpToMonth = new Array(10, 9); //Month#Year_after_2000
		
		this.MaximumPax = 4;
		this.MaximumChildPax = this.MaximumPax - 2;
		
		this.posibleDepartureCountrys = new Array("Deutschland", "Schweiz", "Österreich", "Niederlande", "Spanien", "Frankreich", "Italien", "Dänemark", "Finnland", "Norwegen", "Schweden", "Grossbritannien", "Island", "Israel",
											"Alemania", "Suiza", "Austria", "Países Bajos", "España", "Francia", "Italia", "Dinamarca", "Finlandia", "Noruega", "Suecia", "Gran Bretaña", "Islandia", "Israel",
											"Germany", "Switzerland", "Austria", "Netherlands", "Spain", "France", "Italy", "Denmark", "Finland", "Norway", "Sweden", "Great Britain", "Iceland", "Israel",
											"Germania", "Svizzera", "Austria", "Paesi Bassi", "Spagna", "Francia", "Italia", "Danimarca", "Finlandia", "Norvegia", "Svezia", "Gran Bretagna", "Islanda", "Israele");
		
		this.abstractSearchForm = null;
		
		//saved search attributes
		this.save_DestTLC = "";
		this.save_ArrTLC = "";
		
		this.save_OutbDay = "";
		this.save_OutbMonth = "";

		this.save_RetDay = "";
		this.save_RetMonth = "";

		this.save_numAdults = "";
		this.save_numChildren = "";
	}

//public:
	function declared_initializeSearchForm(OutTLC, ArrTLC)
	{
		try
		{
			//just for testing
			this.createAdultPax();
			this.createChildPax();
			
			//initialize outbound & arrival airport
			if(OutTLC != null && ArrTLC != null)
				this.initAirportsLL('', 'w', OutTLC, ArrTLC);
			else
				this.initAirportsLL('', 'w', 'DUS', 'VIE');
			
			//initialize search form date inputs
			var actDate = new Date();
			var tmpYear = actDate.getYear();
			
			if(!this.SFH_isInternetExplorer())
			{
				tmpYear = parseInt(tmpYear, 10) - 100;
				if(tmpYear > 1900) //opera bug
					tmpYear -= 1900;
			}
			else
				tmpYear = parseInt(tmpYear, 10) - 2000;
			this.createDateMonths("omy", actDate.getMonth(), tmpYear);
			this.createDateMonths("rmy", actDate.getMonth(), tmpYear);
			this.createDateDays("od", actDate.getMonth(), tmpYear);
			this.createDateDays("rd", actDate.getMonth(), tmpYear);
			
			actDate = new Date(actDate.getFullYear(), actDate.getMonth(), actDate.getDate() + this.defaultDaysToDeparture);
			tmpYear = actDate.getYear();
			
			if(!this.SFH_isInternetExplorer())
				tmpYear = parseInt(tmpYear, 10) - 100;
			else
				tmpYear = parseInt(tmpYear, 10) - 2000;
			tmpMonth = actDate.getMonth();
			tmpMonth = tmpMonth + 1; //correct month (js starts counting month with 0 (= januar))
			this.selectDepartureDate(actDate.getDate(), tmpMonth, tmpYear);
			
			actDate = new Date(actDate.getFullYear(), actDate.getMonth(), actDate.getDate() + this.preSelectedDuration);
						
			tmpYear = actDate.getYear();
			if(!this.SFH_isInternetExplorer())
				tmpYear = parseInt(tmpYear, 10) - 100;
			else
				tmpYear = parseInt(tmpYear, 10) - 2000;
			tmpMonth = actDate.getMonth();
			tmpMonth = tmpMonth + 1;					
			this.selectArrivalDate(actDate.getDate(), tmpMonth, tmpYear);
		}
		catch(e) {this.log("CSearchFormHandler::initializeSearchForm\n" + e.message, "logging/JSExceptionLog.txt");}
	}

//public:
	function declared_setDefaultDaysToDeparture(days)
	{
		try
		{
			this.defaultDaysToDeparture = days;
		}
		catch(e) {this.log("CSearchFormHandler::setDefaultDaysToDeparture\n" + e.message, "logging/JSExceptionLog.txt");}
	}

//public:
	function declared_setForumlarPreSection(outDay, outMonth, outYear, arrDay, arrMonth, arrYear, numAdults, numChildren)
	{
		try
		{
			for(var i = 0; i < document.getElementById("numAdults").length; i++)
			{
				if(document.getElementById("numAdults")[i].value == numAdults)
					document.getElementById("numAdults")[i].selected = "selected";
			}
			
			for(var i = 0; i < document.getElementById("numChilds").length; i++)
			{
				if(document.getElementById("numChilds")[i].value == numChildren)
					document.getElementById("numChilds")[i].selected = "selected";
			}
			
			this.selectDepartureDate(parseInt(outDay, 10), parseInt(outMonth, 10), parseInt(outYear, 10));
			this.selectArrivalDate(parseInt(arrDay, 10), parseInt(arrMonth, 10), parseInt(arrYear, 10));
		}
		catch(e) {this.log("CSearchFormHandler::setForumlarPreSection\n" + e.message, "logging/JSExceptionLog.txt");}
	}

//public:
	function declared_setPreSelectedDuration(duration)
	{
		try
		{
			this.preSelectedDuration = duration;
		}
		catch(e) {this.log("CSearchFormHandler::initializeSearchForm\n" + e.message, "logging/JSExceptionLog.txt");}
	}

//public:
	function declared_setTopDestinations(TLC, Airport)
	{
		try
		{
			this.TopDestinationAirportArray.push(new Array(TLC, Airport));
		}
		catch(e) {this.log("CSearchFormHandler::setTopDestinations\n" + e.message, "logging/JSExceptionLog.txt");}
	}

//public:
	function declared_initWettendassHandler()
	{
		try
		{
			// Leeren der Select-Boxen
			for (var i=document.getElementById("omy").length;i>=0;i--)
				document.getElementById("omy").options[i] = null;
			for (var i=document.getElementById("rmy").length;i>=0;i--)
				document.getElementById("rmy").options[i] = null;
			for (var i=document.getElementById("od").length;i>=0;i--)
				document.getElementById("od").options[i] = null;
			for (var i=document.getElementById("rd").length;i>=0;i--)
				document.getElementById("rd").options[i] = null;
			
/*

			for (var i=document.getElementById("numChilds").length;i>=0;i--)
				document.getElementById("numChilds").options[i] = null;	

			//kinder-selcetbox-anpassem
			Childoption = document.createElement("option");				
			Childoption.innerHTML = "0 Kind";
			Childoption.value = "0";
			document.getElementById("numChilds").appendChild(Childoption);
				
			Childoption = document.createElement("option");				
			Childoption.innerHTML = "1 Kind";
			Childoption.value = "1";
			document.getElementById("numChilds").appendChild(Childoption);		
*/				
				
				
			var MonthOption;

			// Juni als Abflug- und Zielmonat setzen 
			MonthOption = document.createElement("option");				
			MonthOption.innerHTML = "Mai 10";
			MonthOption.value = "0510";
			document.getElementById("omy").appendChild(MonthOption);

			MonthOption = document.createElement("option");				
			MonthOption.innerHTML = "Mai 10";
			MonthOption.value = "0510";
			document.getElementById("rmy").appendChild(MonthOption);
			
			var DayOption;

			// Hinflug-Tage setzen
			var DayOption = document.createElement("option");
			DayOption.value = "15";
			DayOption.innerHTML = 15;
			document.getElementById("od").appendChild(DayOption);

			var DayOption = document.createElement("option");
			DayOption.value = "16";
			DayOption.innerHTML = 16;
			document.getElementById("od").appendChild(DayOption);

			var DayOption = document.createElement("option");
			DayOption.value = "17";
			DayOption.innerHTML = 17;
			document.getElementById("od").appendChild(DayOption);

			var DayOption = document.createElement("option");
			DayOption.value = "18";
			DayOption.innerHTML = 18;
			document.getElementById("od").appendChild(DayOption);

			var DayOption = document.createElement("option");
			DayOption.value = "19";
			DayOption.innerHTML = 19;
			document.getElementById("od").appendChild(DayOption);

			var DayOption = document.createElement("option");
			DayOption.value = "20";
			DayOption.innerHTML = 20;
			document.getElementById("od").appendChild(DayOption);

			var DayOption = document.createElement("option");
			DayOption.value = "21";
			DayOption.innerHTML = 21;
			document.getElementById("od").appendChild(DayOption);

			var DayOption = document.createElement("option");
			DayOption.value = "22";
			DayOption.innerHTML = 22;
			document.getElementById("od").appendChild(DayOption);

			var DayOption = document.createElement("option");
			DayOption.value = "23";
			DayOption.innerHTML = 23;
			document.getElementById("od").appendChild(DayOption);

			// Rückflug-Tage setzen *****
			var DayOption = document.createElement("option");
			DayOption.value = "24";
			DayOption.innerHTML = 24;
			document.getElementById("rd").appendChild(DayOption);

			var DayOption = document.createElement("option");
			DayOption.value = "25";
			DayOption.innerHTML = 25;
			document.getElementById("rd").appendChild(DayOption);

			var DayOption = document.createElement("option");
			DayOption.value = "26";
			DayOption.innerHTML = 26;
			document.getElementById("rd").appendChild(DayOption);

			var DayOption = document.createElement("option");
			DayOption.value = "27";
			DayOption.innerHTML = 27;
			document.getElementById("rd").appendChild(DayOption);

			var DayOption = document.createElement("option");
			DayOption.value = "28";
			DayOption.innerHTML = 28;
			document.getElementById("rd").appendChild(DayOption);
		
			var DayOption = document.createElement("option");
			DayOption.value = "29";
			DayOption.innerHTML = 29;
			document.getElementById("rd").appendChild(DayOption);

			var DayOption = document.createElement("option");
			DayOption.value = "30";
			DayOption.innerHTML = 30;
			document.getElementById("rd").appendChild(DayOption);

			var DayOption = document.createElement("option");
			DayOption.value = "31";
			DayOption.innerHTML = 31;
			document.getElementById("rd").appendChild(DayOption);

			//12 - 17 vorselectieren
			document.getElementById('od').options[7].selected = true;
			document.getElementById('rd').options[2].selected = true;
				
		}
		catch(e) {this.log("CSearchFormHandler::initWettendass\n" + e.message, "logging/JSExceptionLog.txt");}
	}

//protected:
	function declared_selectDepartureDate(Day, Month, Year)
	{
		try
		{
			if(Year < 10)
				Year = "0" + Year;
			
			if(Month < 10)
				Month = "0" + Month;
			
			for(var i = 0; i < document.getElementById("omy").length; i++)
			{				
				if(parseInt(document.getElementById("omy").options[i].value, 10) == parseInt(Month + "" + Year, 10))
					document.getElementById("omy").selectedIndex = i;
			}
			
			this.dateDependenciesOnChange();
			
			for(var i = 0; i < document.getElementById("od").length; i++)
			{
				if(parseInt(document.getElementById("od").options[i].value, 10) == parseInt(Day, 10))
					document.getElementById("od").selectedIndex = i;
			}
		}
		catch(e) {this.log("CSearchFormHandler::selectDepartureDate\n" + e.message, "logging/JSExceptionLog.txt");}
	}

//protected
	function declared_selectArrivalDate(Day, Month, Year)
	{
		try
		{
			if(Year < 10)
				Year = "0" + Year;
			
			if(Month < 10)
				Month = "0" + Month;
			
			for(var i = 0; i < document.getElementById("rmy").length; i++)
			{
				if(parseInt(document.getElementById("rmy").options[i].value, 10) == parseInt(Month + "" + Year, 10))
				{
					document.getElementById("rmy").selectedIndex = i;
				}
			}
			
			this.dateDependenciesOnChange();
			
			for(var i = 0; i < document.getElementById("rd").length; i++)
			{
				if(parseInt(document.getElementById("rd").options[i].value, 10) == parseInt(Day, 10))
					document.getElementById("rd").selectedIndex = i;
			}
		}
		catch(e) {this.log("CSearchFormHandler::selectArrivalDate\n" + e.message, "logging/JSExceptionLog.txt");}
	}

//protected:
	function declared_createDateMonths(selectBox, actuallMonth, actuallYear)
	{
		try
		{			
			for(var i = actuallMonth; i < actuallMonth + this.UpToNumberOfMonth; i++)
			{
				var YearIterator;
				var MonthIterator;
				var tmpMonth = "";
				
				YearIterator = actuallYear;
				MonthIterator = i;
				
				while(MonthIterator > 11)
				{
					MonthIterator -= 12;
					YearIterator++;
				}
				
				YearIterator = ("0" + YearIterator).slice(-2);
				
				var MonthOption = document.createElement("option");				
				MonthOption.innerHTML = this.MonthArray[MonthIterator] + ' ' +  YearIterator;
				MonthOption.value = ("0" + (MonthIterator + 1)).slice(-2)+ '' + YearIterator;
				
				document.getElementById(selectBox).appendChild(MonthOption);
			}
		}
		catch(e) {this.log("CSearchFormHandler::createDateMonths\n" + e.message, "logging/JSExceptionLog.txt");}
	}
	
//protected:
	function declared_createDateDays(selectBox, Month, Year)
	{
		try
		{
			for(var i = 1; i <= this.getNumberOfDaysInMonth(Month, Year); i++)
			{
				var DayOption = document.createElement("option");
				
				if(i < 10)
					DayOption.value = "0" + i;
				else
					DayOption.value = i;
				
				DayOption.innerHTML = i;
				
				document.getElementById(selectBox).appendChild(DayOption);
			}
		}
		catch(e) {this.log("CSearchFormHandler::createDateDays\n" + e.message, "logging/JSExceptionLog.txt");}
	}
	
//protected:
	function declared_getNumberOfDaysInMonth(Month, Year)
	{
		try
		{
			var Days = 31;
			
			if(Month == 4 || Month == 6 || Month == 9 || Month == 11)
				--Days;
			
			if(Month == 2)
			{
				if(Year < 2000)
					Year += 2000;
				
				Days = Days - 3;
				if(Year % 4 == 0)
					Days++;
				
				if(Year % 100 == 0)
					Days--;
				
				if(Year % 400 == 0)
					Days++;
			}
			
			return Days;
		}
		catch(e) {this.log("CSearchFormHandler::getNumberOfDaysInMonth\n" + e.message, "logging/JSExceptionLog.txt");}
	}

//protected:
	function declared_createAdultPax()
	{
		try
		{
			for(var i = 1; i <= this.MaximumPax; i++)
			{
				var AdultOption = document.createElement("option");
				AdultOption.value = i;
				
				if(i > 1)
					AdultOption.innerHTML = i + " " + translationsTextSearchForm["Erwachsene"];
				else
					AdultOption.innerHTML = i + " " + translationsTextSearchForm["Erwachsener"];
				
				document.getElementById("numAdults").appendChild(AdultOption);
			}
			
			document.getElementById("numAdults").selectedIndex = 1;
		}
		catch(e) {this.log("CSearchFormHandler::createAdultPax\n" + e.message, "logging/JSExceptionLog.txt");}
	}
	
//protected:
	function declared_createChildPax()
	{
		try
		{
			for(var i = 0; i <= this.MaximumChildPax; i++)
			{
				var AdultOption = document.createElement("option");
				AdultOption.value = i;
				
				if(i > 1 || i == 0)
					AdultOption.innerHTML = i + " " + translationsTextSearchForm["Kinder"];
				else
					AdultOption.innerHTML = i + " " + translationsTextSearchForm["Kind"];
				
				document.getElementById("numChilds").appendChild(AdultOption);
			}
		}
		catch(e) {this.log("CSearchFormHandler::createChildPax\n" + e.message, "logging/JSExceptionLog.txt");}
	}
	
//public:
	function declared_initAirportsLL(bookingmode, season, srcTLC, dstTLC)
	{
		try
		{
			var outSelect = document.getElementById("da");
			var option;
			var currentCountry;
			var group = null;
			var temp = null;
			
			while(outSelect.childNodes.length > 0)
				outSelect.removeChild(outSelect.lastChild);
			
			daSeasons = new Object();
			
			for(var key in ft) // departures
			{
				if(!isNaN(key) && key in ca) // countrys
				{
					// just posible departure airports
					if(this.inArray(ca[key], this.posibleDepartureCountrys))
					{
						group = true;
						group = document.createElement("optgroup");
						group.setAttribute("label", ca[key]);
						outSelect.appendChild(group);
					}
					else
						group = null;
				}
				else if(group && key in ca && (group.label!="Frankreich" || key=="ORY" || key=="CDG"))
				{
					option = document.createElement("option");
					option.setAttribute("value", key);
					option.innerHTML = ca[key];
					
					if(key == srcTLC)
						option.setAttribute("selected", true);
					
					group.appendChild(option);
					daSeasons[key] = "b";
				}
			}
			
			outSelect.seasons = "b";
			
			// create destinations for departure
			this.changeAirport(bookingmode, "return", season, dstTLC);
		}
		catch(e) {this.log("CSearchFormHandler::initAirportsLL\n" + e.message, "logging/JSExceptionLog.txt");}
	}
	
//public:
	function declared_changeAirport(bookingmode, direction, season, tlcToSelect)
	{
		try
		{
			var fillSelect = (direction == "outbound") ? document.getElementById("da") : document.getElementById("aa");
			var refSelect = (direction == "outbound") ? document.getElementById("aa") : document.getElementById("da");
			var dataArray = (direction == "outbound") ? ff : ft;
			var destinations = dataArray[refSelect.value].split(" ");
			var group = null;
			var key = "";
			var nodeSeason = "";
			var gray = false;
			var oldvalue = fillSelect.value;
			var oldseason = fillSelect.season;
			var fillSeason = new Object();
			var refSeason = (direction == "outbound") ? aaSeasons : daSeasons;
			
			var topGroup = null;
			var topE;
	
			if(tlcToSelect != undefined)
				oldvalue = tlcToSelect;
	
			refSelect.season = refSeason[refSelect.value];
			
			while(fillSelect.childNodes.length > 0)
				fillSelect.removeChild(fillSelect.lastChild);
			
			// Top Binoli-Ziele in Ziel-Flughafen-Liste eintragen
			if(direction == "return")
			{
				topGroup = document.createElement("optgroup");
				topGroup.setAttribute("label", translationsTextSearchForm["TopBINOLIZiele"]);
				fillSelect.appendChild(topGroup);
							
				for(var i = 0; i < this.TopDestinationAirportArray.length; i++)
				{
					ziele = ft[refSelect.value];
					if (ziele.indexOf(this.TopDestinationAirportArray[i][0], 0) > -1)
					{
						topE = document.createElement("option");
						topE.setAttribute("value", this.TopDestinationAirportArray[i][0]);
						topE.appendChild(document.createTextNode(this.TopDestinationAirportArray[i][1]));
						topGroup.appendChild(topE);
					}
				}
				
				topE = document.createElement("option");
				topE.setAttribute("value", "");
				topE.appendChild(document.createTextNode(""));
				topE.disabled = true;
				fillSelect.appendChild(topE);
			}
			
			// Ziele in Ziel-Flughafen-Liste eintragen
			for(var i = 0; i < destinations.length; i++)
			{
				key = destinations[i].substr(0, 3);
				nodeSeason = destinations[i].substr(3);
				gray = (nodeSeason != "b" && nodeSeason != season);
	
				if(!isNaN(key) && key in ca) // Land
				{
					if(ca[key] == "Deutschland" || ca[key] == "Schweiz" || ca[key] == "Österreich" || ca[key] == "Niederlande" || ca[key] == "Spanien" || ca[key] == "Italien" || ca[key] == "Dänemark" || ca[key] == "Finnland" || ca[key] == "Frankreich" || ca[key] == "Grossbritannien" || ca[key] == "Island" || ca[key] == "Israel" || ca[key] == "Norwegen" || ca[key] == "Schweden"
								|| ca[key] == "Alemania" || ca[key] == "Suiza" || ca[key] == "Austria" || ca[key] == "Países Bajos" || ca[key] == "España" || ca[key] == "Italia" || ca[key] == "Dinamarca" || ca[key] == "Finlandia" || ca[key] == "Francia" || ca[key] == "Gran Bretaña" || ca[key] == "Islandia" || ca[key] == "Israel" || ca[key] == "Noruega" || ca[key] == "Suecia"
								|| ca[key] == "Germania" || ca[key] == "Svizzera" || ca[key] == "Austria" || ca[key] == "Paesi Bassi" || ca[key] == "Spagna" || ca[key] == "Italia" || ca[key] == "Danimarca" || ca[key] == "Finlandia" || ca[key] == "Francia" || ca[key] == "Gran Bretagna" || ca[key] == "Islanda" || ca[key] == "Israele" || ca[key] == "Norvegia" || ca[key] == "Svezia"
								|| ca[key] == "Germany" || ca[key] == "Switzerland" || ca[key] == "Austria" || ca[key] == "Netherlands" || ca[key] == "Spain" || ca[key] == "Italy" || ca[key] == "Denmark" || ca[key] == "Finland" || ca[key] == "France" || ca[key] == "Great Britain" || ca[key] == "Iceland" || ca[key] == "Israel" || ca[key] == "Norway" || ca[key] == "Sweden"
								|| direction == "return")
					{
						if(group && group.childNodes.length > 0)
							fillSelect.appendChild(group); // Alte Gruppe einfügen, wenn nicht leer
		
						group = document.createElement("optgroup");
						group.setAttribute("label", ca[key]);
					}
					else
					{
						if(group && group.childNodes.length > 0)
							fillSelect.appendChild(group); // Alte Gruppe einfügen, wenn nicht leer
						
						group = null;
					}
				}
				else if(group && key in ca && (direction == "outbound" || bookingmode == "MW" || this.inArray(key, bookableDests))) // Airport
				{
		  			e = document.createElement("option");
		  			e.setAttribute("value", key);
					optiontext = document.createTextNode(ca[key]);
					e.appendChild(optiontext);
	
		  			if(key == tlcToSelect || key == oldvalue)
		  				e.setAttribute("selected", true);
		  			
		  			group.appendChild(e);
		  			fillSeason[key] = nodeSeason;
				}
			}
	
			if(group && group.childNodes.length > 0)
				fillSelect.appendChild(group); // Letzte Gruppe einfügen, wenn nicht leer
			
			fillSelect.season = fillSeason[fillSelect.value];
			
			if(direction == "outbound")
				daSeasons = fillSeason;
			else
				aaSeasons = fillSeason;
		}
		catch(e) {this.log("CSearchFormHandler::changeAirport\n" + e.message, "logging/JSExceptionLog.txt");}
	}
	
//public:
	function declared_setSeason()
	{
		try
		{
			var od = parseInt(document.formSearch.od.value, 10);
			var rd = parseInt(document.formSearch.rd.value, 10);
			var om = parseInt(document.formSearch.omy.value.substring(0, 2), 10);
			var rm = parseInt(document.formSearch.rmy.value.substring(0, 2), 10);
			var oy = parseInt(document.formSearch.omy.value.substring(2, 4), 10);
			var ry = parseInt(document.formSearch.rmy.value.substring(2, 4), 10);
		
			var out = oy * 10000 + om * 100 + od;
			var ret = ry * 10000 + rm * 100 + rd;
		
			if(out <= 71031)
				outboundSeason = "s";
			else
				outboundSeason = "w";
		
			if (ret <= 71031)
				returnSeason = "s";
			else
				returnSeason = "w";
		}
		catch(e) {this.log("CSearchFormHandler::setSeason\n" + e.message, "logging/JSExceptionLog.txt");}
	}
	
//public:
	function declared_setSc()
	{
		try
		{
			var isfcc = fcc.match(document.getElementById("da").value) || fcc.match(document.getElementById("aa").value);
			document.getElementById("sc").options[1].text = "Business";			
		}
		catch(e) {this.log("CSearchFormHandler::setSc\n" + e.message, "logging/JSExceptionLog.txt");}
	}
	
//public:
	function declared_clearSearchFormForNewContent()
	{
		try
		{
			this.saveFormValues();
			
			var holder = document.getElementById("searchFormContent");
			
			while(holder.hasChildNodes())
				holder.removeChild(holder.lastChild);
		}
		catch(e) {this.log("CSearchFormHandler::clearSearchFormForNewContent\n" + e.message, "logging/JSExceptionLog.txt");}
	}
	
//public:
	function declared_SearchSubmit(ChildBirthDayString, alternativeSubmit, alternativeSubmitRules)
	{
		try
		{	
			var countChilds = 0;
			var objNumChilds = document.getElementsByName("numChilds");

			for(var i= 0; i < objNumChilds.length; i++)
			{
				//Selectbox holen
				if(objNumChilds[i].nodeName.toLowerCase() == "select")
				{
					countChilds = objNumChilds[i].value;
					break; 
				}	
			}
			
			if(countChilds > 0)
			{
				for(var i= 0; i < objNumChilds.length; i++)
				{
					objNumChilds[i].value = countChilds;
				}
				
				var childBirthDayValue = "";	
				var objBirthDay = document.getElementsByName("childBirthDay");
				
				for(var i= 0; i < objBirthDay.length; i++)
				{
					if(objBirthDay[i].value != "" || childBirthDayValue.length < objBirthDay[i].value.length)
						childBirthDayValue = objBirthDay[i].value;
				}
				
				if(childBirthDayValue != "")
				{
					if((childBirthDayValue.split('#').length - 1) != countChilds)
						childBirthDayValue= "";

					for(var i= 0; i < objBirthDay.length; i++)
					{
						objBirthDay[i].value = childBirthDayValue;	
					}
					
				}
			
				if(countChilds > 0 && !ChildBirthDayString && childBirthDayValue == "")
	
				{
					var Children = document.getElementById("numChilds").value;
													
					this.abstractSearchForm = document.getElementById("searchFormContent").cloneNode(true);
					this.objSearchChildFormHandler.setAbstractSearchForm(this.abstractSearchForm);
					this.objSearchChildFormHandler.setNumberOfChildren(Children);
					
					this.clearSearchFormForNewContent();
					
					this.objSearchChildFormBuilder.createSearchChildForm("searchFormContent", Children);
					return;
				}
			}
			
			if(ChildBirthDayString)
			{
				this.loadFormValues();
				document.getElementById("childBirthDay").value = ChildBirthDayString;
			}
			
			//disable ajax call for flash stage
			//kill flash stage
			//(just usefull on step_stat_1_home.php)
			if(this.SFH_isInternetExplorer())
			{
				try{
					xajax_loadTeasers = function(){};
					//kill all html node in full depth
					for(var i = 0; i < document.getElementById("SWFTeaser").childNodes.length; i++)
						document.getElementById("SWFTeaser").removeChild(document.getElementById("SWFTeaser").childNodes[i]);					
					for(var i = 0; i < document.getElementById("SWFTeaser").childNodes.length; i++)
						document.getElementById("SWFTeaser").removeChild(document.getElementById("SWFTeaser").childNodes[i]);
					//show placeholder again
					document.getElementById("placeholderOnStartup").style.display = "block";
				}
				catch(e) {}
			}
			
			document.formSearch.outboundDepartureDate.value = document.formSearch.od.value + document.formSearch.omy.value;
			document.formSearch.returnDepartureDate.value = document.formSearch.rd.value + document.formSearch.rmy.value;
			
			switch(alternativeSubmitRules)
			{
				case "airberlinBTN":
				document.getElementById("da").name = "VON";
				document.getElementById("aa").name = "NACH";
				document.getElementById("outboundDepartureDate").name = "HINDATUM";
				document.getElementById("returnDepartureDate").name = "RUECKDATUM";
				
				document.formSearch.action = "http://www.airberlin.com/site/abvakanz_c.php?LANG=deu";
				break;
				
				//etracker
				default:			
					var oldAction = document.formSearch.action;
					
					//die dynamische Erweiterung
					var actionParams = "et_cid=4&et_lid=10&et_sub=";
					actionParams += document.getElementById("da").value;
					actionParams += document.getElementById("aa").value;					
					actionParams +=(document.getElementById("outboundDepartureDate").value).substr(2,4);
					
					//einfache Version
					//var actionParams = "et_cid=4&et_lid=10&et_sub=SM";
					
					if(oldAction.indexOf("?") > 0)
						document.formSearch.action = (oldAction + "&" + actionParams);
					else
						document.formSearch.action = (oldAction + "?" + actionParams);
	
				break;
				
			}
			
			document.formSearch.submit();
		}
		catch(e) {this.log("CSearchFormHandler::SearchSubmit\n" + e.message, "logging/JSExceptionLog.txt");}
	}
	
//public:
	function declared_dateDependenciesOnChange()
	{
		try
		{
			var om = document.formSearch.omy.value.substring(0, 2);
			var oy = document.formSearch.omy.value.substring(2, 4);
			var rm = document.formSearch.rmy.value.substring(0, 2);
			var ry = document.formSearch.rmy.value.substring(2, 4);
			
			if((oy > ry) || ((oy >= ry) && (om > rm)) || ((oy >= ry) && (om >= rm) && (document.formSearch.od.value > document.formSearch.rd.value)))
		    {
		    	if (document.formSearch.od.value > document.formSearch.rd.value)
		    		document.formSearch.rd.value = document.formSearch.od.value;
				
		    	document.formSearch.rmy.value = document.formSearch.omy.value;
		    }
			
			var s = document.formSearch.od;
			this.adaptDays(s, om, oy);
			
			s = document.formSearch.rd;
			this.adaptDays(s, document.formSearch.rmy.value.substring(0, 2), document.formSearch.rmy.value.substring(2, 4));
		}
		catch(e) {this.log("CSearchFormHandler::dateDependenciesOnChange\n" + e.message, "logging/JSExceptionLog.txt");}
	}

//public:
	function declared_loadFormValues()
	{
		try
		{
			this.SetInput("da", this.save_DestTLC);
			this.SetInput("aa", this.save_ArrTLC);
			
			this.SetInput("od", this.save_OutbDay);
			this.SetInput("omy", this.save_OutbMonth);
			
			this.SetInput("rd", this.save_RetDay);
			this.SetInput("rmy", this.save_RetMonth);
			
			this.SetInput("numAdults", this.save_numAdults);
			this.SetInput("numChilds", this.save_numChildren);
		}
		catch(e) {this.log("CSearchFormHandler::loadFormValues\n" + e.message, "logging/JSExceptionLog.txt");}
	}
	
	//private:
	function declared_adaptDays(formElement, month, year)
	{
		try
		{
			if(formElement)
			{
				var newDays = this.getNumberOfDaysInMonth(month, year);				
				var curDays = formElement.getElementsByTagName("option").length;
								
				if(newDays > curDays)
				{
					for(i = (curDays + 1); i <= newDays; i++)
					{
						o = document.createElement("option");
						day = "0" + i;
						o.value = day.substr(day.length - 2, 2);
						o.innerHTML = i;					
						formElement.appendChild(o);
					}
				}
				else if(newDays < curDays)
				{
					for(i = curDays; i > newDays; i--)
					{				
						var p2 = formElement.getElementsByTagName('option')[(i - 1)];
						p2.parentNode.removeChild(p2);
					}
				}
			}
		}
		catch(e) {this.log("CSearchFormHandler::adaptDays\n" + e.message, "logging/JSExceptionLog.txt");}
	}
	
//private:
	function declared_inArray(needle, haystack)
	{
		try
		{
			for(var i = 0; i < haystack.length; i++)
				if (haystack[i] == needle)
					return true;
			
			return false;
		}
		catch(e) {this.log("CSearchFormHandler::inArray\n" + e.message, "logging/JSExceptionLog.txt");}
	}
	
//private:
	function declared_saveFormValues()
	{
		try
		{
			this.save_DestTLC = document.getElementById("da").value;
			this.save_ArrTLC = document.getElementById("aa").value;
			
			this.save_OutbDay = document.getElementById("od").value;
			this.save_OutbMonth = document.getElementById("omy").value;
			
			this.save_RetDay = document.getElementById("rd").value;
			this.save_RetMonth = document.getElementById("rmy").value;
			
			this.save_numAdults = document.getElementById("numAdults").value;
			this.save_numChildren = document.getElementById("numChilds").value;
		}
		catch(e) {this.log("CSearchFormHandler::saveFormValues\n" + e.message, "logging/JSExceptionLog.txt");}
	}
	
//private:
	function declared_SetInput(ID, value)
	{
		try
		{
			for(var i = 0; i < document.getElementById(ID).options.length; i++)
			{
				if(document.getElementById(ID).options[i].value == value)
					document.getElementById(ID).selectedIndex = i;
			}
		}
		catch(e) {this.log("CSearchFormHandler::SetInput\n" + e.message, "logging/JSExceptionLog.txt");}
	}
	
//private:
	function declared_SFH_isInternetExplorer()
	{
		var browser = navigator.userAgent.toLowerCase();
		var explorer = ((browser.indexOf("msie") != -1) && (browser.indexOf("opera") == -1));
		
		if(explorer)
			return true;
		else
			return false;
	}
//};