// JavaScript Document

	function changeSearchForm(form, pType) {
		switch(form) {
			case 1:
				document.getElementById('SearchTbl_1').style.display = 'block';
				document.getElementById('SearchTbl_2').style.display = 'none';
				document.getElementById('SearchTbl_3').style.display = 'none';
				break;
			case 2:
				document.getElementById('SearchTbl_1').style.display = 'none';
				document.getElementById('SearchTbl_2').style.display = 'block';
				document.getElementById('SearchTbl_2_1').selected = true;
				document.getElementById('SearchTbl_2_2').selected = false;
				document.getElementById('SearchTbl_3').style.display = 'none';
				break;
			case 3:
				document.getElementById('SearchTbl_1').style.display = 'none';
				document.getElementById('SearchTbl_2').style.display = 'none';
				document.getElementById('SearchTbl_3').style.display = 'block';
				break;
			case 4:
				document.getElementById('SearchTbl_1').style.display = 'none';
				document.getElementById('SearchTbl_2').style.display = 'block';
				document.getElementById('SearchTbl_2_2').selected = true;
				document.getElementById('SearchTbl_2_1').selected = false;
				document.getElementById('SearchTbl_3').style.display = 'none';
				break;
		}
		document.getElementById('WWTESearchForm').elements['PackageType'].value = pType;
	}
	

	/*CLICK & MIX*/
function setWWTESearchFormRoomVisibility() {
	
	document.getElementById('WWTESearchFormRoom2').style.display = 'none';
	document.getElementById('WWTESearchFormRoom3').style.display = 'none';
	document.getElementById('WWTESearchFormRoom4').style.display = 'none';
	
	switch(document.getElementById('WWTESearchForm').elements['NumRoom'].value) {
		
		case '4': document.getElementById('WWTESearchFormRoom4').style.display = 'block';
		case '3': document.getElementById('WWTESearchFormRoom3').style.display = 'block';
		case '2': document.getElementById('WWTESearchFormRoom2').style.display = 'block';
		
	}
	
	switch(document.getElementById('WWTESearchForm').elements['NumRoom'].value) {
		
		case '1':
			document.getElementById('WWTESearchForm').elements['NumChild2'].value = '0';
			setWWTESearchFormChildVisibility(2);
			
		case '2':
			document.getElementById('WWTESearchForm').elements['NumChild3'].value = '0';
			setWWTESearchFormChildVisibility(3);
			
		case '3':
			document.getElementById('WWTESearchForm').elements['NumChild4'].value = '0';
			setWWTESearchFormChildVisibility(4);
		
	}
	
}


function setWWTESearchFormChildVisibility(RoomNumber) {
	
	document.getElementById('WWTESearchFormRoom' + RoomNumber + 'Child').style.display = 'none';
	document.getElementById('WWTESearchFormRoom' + RoomNumber + 'Child1').style.display = 'none';
	document.getElementById('WWTESearchFormRoom' + RoomNumber + 'Child2').style.display = 'none';
	document.getElementById('WWTESearchFormRoom' + RoomNumber + 'Child3').style.display = 'none';
	
	switch(document.getElementById('WWTESearchForm').elements['NumChild' + RoomNumber].value) {
		
		case '3': document.getElementById('WWTESearchFormRoom' + RoomNumber + 'Child3').style.display = 'inline';
		case '2': document.getElementById('WWTESearchFormRoom' + RoomNumber + 'Child2').style.display = 'inline';
		case '1':
			document.getElementById('WWTESearchFormRoom' + RoomNumber + 'Child1').style.display = 'inline';
			document.getElementById('WWTESearchFormRoom' + RoomNumber + 'Child').style.display = 'block';
		
	}
	
	if(document.getElementById('WWTESearchForm').elements['NumChild1'].value != '0' || document.getElementById('WWTESearchForm').elements['NumChild2'].value != '0' || document.getElementById('WWTESearchForm').elements['NumChild3'].value != '0' || document.getElementById('WWTESearchForm').elements['NumChild4'].value != '0') {
		document.getElementById('WWTESearchFormChildAdvice').style.display = 'block';
	} else {
		document.getElementById('WWTESearchFormChildAdvice').style.display = 'none';
	}
	
}


function setWWTESearchFormAction() {
	
	var WWTESearchForm = document.getElementById('WWTESearchForm');
	
	WWTESearchForm.action+= '&PackageType=' + WWTESearchForm.elements['PackageType'].value;
	
	if(WWTESearchForm.elements['PackageType'].value != 3) {
		WWTESearchForm.action+= '&FrAirport=' + WWTESearchForm.elements['FrAirport'].value;
	}
	
	WWTESearchForm.action+= '&DestID=' + WWTESearchForm.elements['DestID'].value + '&FromDate=' + WWTESearchForm.elements['FromDay'].value + '.' + WWTESearchForm.elements['FromMonth'].value + '.' + WWTESearchForm.elements['FromYear'].value + '&FromTime=' + WWTESearchForm.elements['FromTime'].value + '&ToDate=' + WWTESearchForm.elements['ToDay'].value + '.' + WWTESearchForm.elements['ToMonth'].value + '.' + WWTESearchForm.elements['ToYear'].value + '&ToTime=' + WWTESearchForm.elements['ToTime'].value + '&NumRoom=' + WWTESearchForm.elements['NumRoom'].value;
	
	switch(WWTESearchForm.elements['NumRoom'].value) {
		
		case '4':
			WWTESearchForm.action+= '&NumAdult4=' + WWTESearchForm.elements['NumAdult4'].value + '&NumChild4=' + WWTESearchForm.elements['NumChild4'].value;
			
			switch(WWTESearchForm.elements['NumChild4'].value) {
				
				case '3': WWTESearchForm.action+= '&Rm4Child3Age=' + WWTESearchForm.elements['Rm4Child3Age'].value;
				case '2': WWTESearchForm.action+= '&Rm4Child2Age=' + WWTESearchForm.elements['Rm4Child2Age'].value;
				case '1': WWTESearchForm.action+= '&Rm4Child1Age=' + WWTESearchForm.elements['Rm4Child1Age'].value;
				
			}
			
		case '3':
			WWTESearchForm.action+= '&NumAdult3=' + WWTESearchForm.elements['NumAdult3'].value + '&NumChild3=' + WWTESearchForm.elements['NumChild3'].value;
			
			switch(WWTESearchForm.elements['NumChild3'].value) {
				
				case '3': WWTESearchForm.action+= '&Rm3Child3Age=' + WWTESearchForm.elements['Rm3Child3Age'].value;
				case '2': WWTESearchForm.action+= '&Rm3Child2Age=' + WWTESearchForm.elements['Rm3Child2Age'].value;
				case '1': WWTESearchForm.action+= '&Rm3Child1Age=' + WWTESearchForm.elements['Rm3Child1Age'].value;
				
			}
			
		case '2':
			WWTESearchForm.action+= '&NumAdult2=' + WWTESearchForm.elements['NumAdult2'].value + '&NumChild2=' + WWTESearchForm.elements['NumChild2'].value;
			
			switch(WWTESearchForm.elements['NumChild2'].value) {
				
				case '3': WWTESearchForm.action+= '&Rm2Child3Age=' + WWTESearchForm.elements['Rm2Child3Age'].value;
				case '2': WWTESearchForm.action+= '&Rm2Child2Age=' + WWTESearchForm.elements['Rm2Child2Age'].value;
				case '1': WWTESearchForm.action+= '&Rm2Child1Age=' + WWTESearchForm.elements['Rm2Child1Age'].value;
				
			}
			
		case '1':
			WWTESearchForm.action+= '&NumAdult1=' + WWTESearchForm.elements['NumAdult1'].value + '&NumChild1=' + WWTESearchForm.elements['NumChild1'].value;
			
			switch(WWTESearchForm.elements['NumChild1'].value) {
				
				case '3': WWTESearchForm.action+= '&Rm1Child3Age=' + WWTESearchForm.elements['Rm1Child3Age'].value;
				case '2': WWTESearchForm.action+= '&Rm1Child2Age=' + WWTESearchForm.elements['Rm1Child2Age'].value;
				case '1': WWTESearchForm.action+= '&Rm1Child1Age=' + WWTESearchForm.elements['Rm1Child1Age'].value;
				
			}
		
	}
	
	document.getElementById('WWTESearchForm').action = WWTESearchForm.action;
		
}


//Linienflüge
function ibe_set_city_dep (text) {
self.document.form_main['param[city_dep]'].value = text;
ACCfncHideDateSelector(0, false);
return;
}
function ibe_set_city_arr (text) {
self.document.form_main['param[city_arr]'].value = text;
ACCfncHideDateSelector(0, false);
return;
}
function ibe_set_dep_arl (code, decode) {
ACCfncHideDateSelector(0, false);
if(!dep_arl_arr[code])
	dep_arl_custom_arr[code] = decode;
dep_arl_manager(code);
return;
}
function dep_arl_manager(select_code) {
var dep_arl_list = self.document.form_main['param[dep_arl]'];
// empty list
var i = dep_arl_list.length;
while(i>=0) {
	dep_arl_list.options[i] = null;
	i--;
}
// 1st empty record
dep_arl_list.options[0] = new Option("(egal)", "", false, false);
dep_arl_list.options[0].className = "lighter";
// ie bug workaround
var dep_arl_custom_length = 0;
for(var code in dep_arl_custom_arr)
	dep_arl_custom_length++;
if( dep_arl_custom_length > 0 ) {
	for(var code in dep_arl_custom_arr)
	dep_arl_list.options[ dep_arl_list.length ] = new Option(dep_arl_custom_arr[code] + " (" + code + ")", code, false, false);
	dep_arl_list.options[ dep_arl_list.length ] = new Option("", "", false, false);
}
for(var code in dep_arl_arr)
	dep_arl_list.options[ dep_arl_list.length ] = new Option(dep_arl_arr[code] + " (" + code + ")", code, false, false);
if(select_code != false) {
	for(var i=0; i<dep_arl_list.length; i++)
	if(dep_arl_list.options[i].value == select_code) {
		dep_arl_list.options[i].selected = true;
		break;
	}
}
return;
}

function submitForm (formObj) {
if (!formObj)
return false;
var deepLinkParamsArr = new Array();
deepLinkParamsArr["action"] = "encodes_load";
flightType = formObj["param[type]"];
for (var i=0; i<flightType.length; i++)
	if (flightType[i].checked == true)
	var flightTypeValue = flightType[i].value;
	deepLinkParamsArr["param[type]"] = flightTypeValue;

// ###
       clickAndMixType = formObj["param[clickAndMix]"];
       for (var i=0; i<clickAndMixType.length; i++)
           if (clickAndMixType[i].selected == true)
             var clickAndMixValue= clickAndMixType[i].value;
       deepLinkParamsArr["param[clickAndMix]"] = clickAndMixValue;
// ###
	deepLinkParamsArr["param[acc_dep]"] = formObj["param[acc_dep]"].value;
	deepLinkParamsArr["param[acc_arr]"] = formObj["param[acc_arr]"].value;
	deepLinkParamsArr["param[city_dep]"] = formObj["param[city_dep]"].value;
	deepLinkParamsArr["param[city_arr]"] = formObj["param[city_arr]"].value;

	flightNonStop = formObj["param[nonstop]"];
	deepLinkParamsArr["param[outbound_date_str]"] = formObj["param[outbound_date_day]"][formObj["param[outbound_date_day]"].selectedIndex].value + "." + formObj["param[outbound_date_month]"][formObj["param[outbound_date_month]"].selectedIndex].value + "." + formObj["param[outbound_date_year]"][formObj["param[outbound_date_year]"].selectedIndex].value;

	deepLinkParamsArr["param[outbound_dep_datetime]"] = formObj["param[outbound_dep_datetime]"].value;
	deepLinkParamsArr["param[inbound_date_str]"] = formObj["param[inbound_date_day]"][formObj["param[inbound_date_day]"].selectedIndex].value + "." + formObj["param[inbound_date_month]"][formObj["param[inbound_date_month]"].selectedIndex].value + "." + formObj["param[inbound_date_year]"][formObj["param[inbound_date_year]"].selectedIndex].value;
	deepLinkParamsArr["param[inbound_dep_datetime]"] = formObj["param[inbound_dep_datetime]"].value;

	/*
		flightNonStop = formObj["param[nonstop]"];
		for (var i=0; i<flightNonStop.length; i++)
			if (flightNonStop[i].checked == true)
				var flightNonStopValue = flightNonStop[i].value;
	*/

	var flightNonStopValue = "FALSE";
	deepLinkParamsArr["param[nonstop]"] = flightNonStopValue;
	deepLinkParamsArr["param[cabinclass]"] = formObj["param[cabinclass]"][formObj["param[cabinclass]"].selectedIndex].value;

	deepLinkParamsArr["param[dep_arl]"] = formObj["param[dep_arl]"][formObj["param[dep_arl]"].selectedIndex].value;
	deepLinkParamsArr["param[pax_adt]"] = formObj["param[pax_adt]"][formObj["param[pax_adt]"].selectedIndex].value;
	deepLinkParamsArr["param[pax_chd]"] = formObj["param[pax_chd]"][formObj["param[pax_chd]"].selectedIndex].value;
	deepLinkParamsArr["param[pax_inf]"] = formObj["param[pax_inf]"][formObj["param[pax_inf]"].selectedIndex].value;

	var deepLinkParamsStr = "";
	for (var key in deepLinkParamsArr) {
		deepLinkParamsStr += key + "=" + escape(deepLinkParamsArr[key]) + "&";
}
//var ibeUrl = "https://www.fluege-007.de/frontend/static/start.php?deeplink=" + escape(deepLinkParamsStr);
//var ibeUrl = "/travel/index.php?_query=preisvergleich_suche&typ=linien&deeplink=" + escape(deepLinkParamsStr);
var ibeUrl = "http://flug.preisvergleich.de?agent=preisvergleich&portal=preisvergleich.de&deeplink=" + escape(deepLinkParamsStr);
self.location.href = ibeUrl;
return false;
}