function updateQSForm(choice){

jQuery('#conQSTravelTypeLabel2, #conQSTravelTypeLabel3').hide();

    choice = parseFloat(choice); // browsers handle it different, let it be a number
    switch (choice) {
        case 1: // nur club
            var elemShow = new Array('conQSClubOnlySelectCell','conQSDurationCell2', 'conQSDurationLabel', 'conQSDepartureClubAndGeoGroupCell', 'conQSOccupationAndChildCell', 'conQSStartdateNormalLabel', 'conQSClubSelect', 'conQSGeoGroupSelect', 'conQSDepartureSelfTravelCell', 'conQSAdvancedSearchLnk');
            var elemHide = new Array('conQSGeoGroupSelectPT','conQSGeoGroupSelectCell','conQSDurationCell','conQSClubSelectCell','conQSDepartureAirportCell', 'conQSDepartureAirportSelectCell', 'conQSDepartureAirport3lcCell', 'conQSDestination3lcCell', 'conQSStartdateFlightLabel', 'conQSRentalcarSelectCell', 'conQSStartdateRentalcarLabel');
            //toggleDestination('conQSClubSelectCell'); // start with club selection
            break;
        default: // package
            var elemShow = new Array('conQSGeoGroupSelectPT','conQSClubSelectCell','conQSDurationCell', 'conQSDurationLabel', 'conQSDepartureAirportCell', 'conQSDepartureAirportSelectCell', 'conQSDepartureClubAndGeoGroupCell', 'conQSOccupationAndChildCell', 'conQSStartdateNormalLabel', 'conQSClubSelect', 'conQSAdvancedSearchLnk');
            var elemHide = new Array('conQSGeoGroupSelect','conQSGeoGroupSelectCell','conQSDurationCell2','conQSClubOnlySelectCell','conQSDepartureAirport3lcCell', 'conQSDestination3lcCell', 'conQSStartdateFlightLabel', 'conQSDepartureSelfTravelCell', 'conQSRentalcarSelectCell', 'conQSStartdateRentalcarLabel');
            //toggleDestination('conQSClubSelectCell'); // start with club selection 
            break;
    }
    for (i = 0; i < elemHide.length; i++) {
		if (document.getElementById(elemHide[i]) != null) {
			document.getElementById(elemHide[i]).style.display = 'none';
		}
    }
    for (i = 0; i < elemShow.length; i++) {
		if (document.getElementById(elemShow[i]) != null) {
			document.getElementById(elemShow[i]).style.display = 'block';
		}
    }
	if (document.getElementById('conQSClubRadio') != null) {
		document.getElementById('conQSClubRadio').checked = true;
	}
}

function startQSearch(adv){
	var traveltype = getTravelType('conQSTravelType');

	var club = document.getElementById('conQSClubSelect').value;
	if (traveltype == 0) {
		var duration = document.getElementById('conQSDuration').value;
		//console.log(duration);
		var airports = document.getElementById('conQSDeparture').value;
	}
	if (traveltype == 1) {
		var duration = document.getElementById('conQSDuration2').value;
	}
	
	var GeoGroup = document.getElementById('conQSGeoGroupSelectPT').value;
	var startairport3LC = document.getElementById('conQSOrigin3lc').value;
	var destination3LC = document.getElementById('conQSDestination3lc').value;
	var rentalcarCountry = document.getElementById('conQSRentalcarSelect').value;
	
	// check if country club is selected
	var clubExcept = QSclubsExceptions.join('_');
	var countryExcept = countriesExceptions.join('_');
	var eCE = extraClubExceptions.join('_');
	var eCoE = extraCountryExceptions.join('_');
	if(traveltype == 0){
		if(document.getElementById('conQSClubRadio').checked && clubExcept.indexOf(club)!=-1 && eCE.indexOf(club)==-1) {
			QSerr = true;
			QSerrTxt = 'F&uuml;r diesen Club w&auml;hlen Sie bitte die Buchungsart "<a href=\"javascript:updateQSForm(1);hideErrCell()\" style=\"color:#f00\">Nur Club</a>".';
		} else if(countryExcept.indexOf(GeoGroup)!=-1 && eCoE.indexOf(GeoGroup)==-1) {
			QSerr = true;
			QSerrTxt = 'F&uuml;r dieses Reiseland w&auml;hlen Sie bitte die Buchungsart "<a href=\"javascript:updateQSForm(1);hideErrCell()\" style=\"color:#f00\">Nur Club</a>".';
		}
	}
	// check flight data
	if(traveltype == 2){
		if(!adv){
			if(startairport3LC == '' || startairport3LC == 'Abflughafen eingeben'){
				setErrorColor('conQSOrigin3lc');
				QSerr = true;
			} else {
				startairport3LC = '&Abflughafen=' + startairport3LC; 
				resetErrorColor('conQSOrigin3lc');
				QSerr = false;
			}
			if(destination3LC == '' || destination3LC == 'Zielflughafen eingeben'){
				setErrorColor('conQSDestination3lc');
				QSerr = true;
			} else {
				destination3LC = '&Zielflughafen=' + destination3LC; 
				resetErrorColor('conQSDestination3lc');
				if(!QSerr) {QSerr = false}
			}
		} else {
			if(startairport3LC == 'Abflughafen eingeben'){
				startairport3LC = ''
			} else {
				startairport3LC = '&Abflughafen=' + startairport3LC;
			}
			if(destination3LC == 'Zielflughafen eingeben'){
				destination3LC = ''
			} else {
				destination3LC = '&Zielflughafen=' + destination3LC;
			}
			if(!QSerr) {QSerr = false}
		}
	}
	
	var startdate ='';
	var returndate = '';
	if(traveltype == 2 || traveltype == 3){
		startdate = document.getElementById('conQSStartdateInput').value;
		returndate = document.getElementById('conQSEnddateInput').value;
	}else {
		startdate = transformDate(document.getElementById('conQSStartdateInput').value);
		returndate = transformDate(document.getElementById('conQSEnddateInput').value);
	}
	//var organizer = (traveltype == 0 && eCE.indexOf(club)!=-1)?'778':'1'; // package and extraClub => organizer 778, otherwise 1
	//var destination = (document.getElementById('conQSClubRadio').checked)?((!adv)?((club!='-1')?'&bookingcodes='+organizer+','+club+',RO':''):''):'&destination='+GeoGroup;
	var destination = (!document.getElementById('conQSClubRadio').checked)?'&destination='+GeoGroup:'';
	
	var hotelname = '';
	if(typeof hn[club] != 'undefined'){
		hotelname = hn[club];
		if(!document.getElementById('conQSGeoGroupRadio').checked){destination += '&hotelname='+hotelname + '&organizer=0';}
	}
	var occupancy = parseFloat(document.getElementById('conQSOccupation').value);
	var child1 = document.getElementById('child1').value;
	var child2 = document.getElementById('child2').value;
	var child3 = document.getElementById('child3').value;
	var sumPassengers = occupancy+((child1>0)?1:0)+((child2>0)?1:0)+((child3>0)?1:0);
	var nintynine = '';
	
	var iff = -1;
	if(traveltype == 0){
		iff = $('#conQSClubSelectCell select:eq(0)').val();
	}else if(traveltype == 1){
		iff = $('#conQSClubOnlySelectCell select:eq(0)').val();
	}
	
	var adult = document.getElementById('conQSOccupation').value;
	
	var timestampStart = getTimestampFromDate(document.getElementById('conQSStartdateInput').value);
	var timestampEnd = getTimestampFromDate(document.getElementById('conQSEnddateInput').value);
	
	var startDate = document.getElementById('conQSStartdateInput').value;
	var endDate = document.getElementById('conQSEnddateInput').value;
	
	var region = document.getElementById('conQSGeoGroupSelectPT').value != '' ? document.getElementById('conQSGeoGroupSelectPT').value : document.getElementById('conQSGeoGroupSelect').value;

	var airport = document.getElementById('conQSDeparture').value;
	
	for(i=0;i<occupancy;i++){nintynine += '99'+((i<occupancy-1)?';':'')}
	if(traveltype!=2){
		occupancy = nintynine+((child1>0)?';'+child1:'')+((child2>0)?';'+child2:'')+((child3>0)?';'+child3:'');
	} else {
		occupancy = (document.getElementById('conQSOccupation').selectedIndex) + 1;
		children = '';
		if(child1 != -1){
			children += child1;
		}
		if(child2 != -1){
			if(child1 != -1){
				children += ',';
			}
			children += child2;
		}
		if(child3 != -1){
			if(child1 != -1 || child2 != -1){
				children += ',';
			}
			children += child3;
		}						
		occupancy += (child1 != -1 || child2 != -1 || child3 != -1) ? '&ChildAge=' + children : '';
	}
	
	var url = '';
	var tturl = 'http://www3.vidado.com/booking/robinson_ch/';
	//package
	if(traveltype==0){
		//url += '?package'+ destination + '&startdate=' + startdate + '&returndate=' + returndate + '&duration=' + duration + '&airports=' + airports + '&occupancy=' + occupancy + ((!adv)?'&page=result':'&page=advancedSearch');
		url = '';
		var detail = 'termine';
		if (document.getElementById('conQSClubRadio').checked){
			if (iff == '-1'){
				detail = 'zielgebiet';
			}
			if(adv){
				detail = "";
			}
			
			tturl += 'index.php?showresult=1&detail=' + detail + '&engine=&KID=792900&formular=4' +
			'&termin=' + startDate + '&ruecktermin=' + endDate + '&dauer=' + duration +
			'&IFF=' + iff + '&erwachsene=' + adult + '&alter1=' + child1 + '&alter2=' + child2 + '&alter3=' + child3 + '&abflughafen=' + airport;
			
			if(adv){
				tturl += '&personen='+document.getElementById('conQSOccupation').value;
				if(child1){
					tturl += ';' + child1;
				}
				if(child2){
					tturl += ';' + child2;
				}
				if(child3){
					tturl += ';' + child3;
				}								
			}			
		} else {
			detail = 'zielgebiet';
			if(adv){
				detail = "";				
			}			
			tturl += 'index.php?showresult=1&detail=' + detail + '&engine=&KID=792900&formular=4' +
			'&termin=' + startDate + '&ruecktermin=' + endDate + '&dauer=' + duration +
			'&udfregionen=' + region + '&erwachsene=' + adult + '&alter1=' + child1 + '&alter2=' + child2 + '&alter3=' + child3 + '&abflughafen=' + airport;

			if(adv){
				tturl += '&personen='+document.getElementById('conQSOccupation').value;
				if(child1){
					tturl += ';' + child1;
				}
				if(child2){
					tturl += ';' + child2;
				}
				if(child3){
					tturl += ';' + child3;
				}								
			}			
		}
	}
	
	// club
	if(traveltype==1){
		url += '?selftravel'+ destination + '&startdate=' + startdate + '&returndate=' + returndate + '&duration=' + duration + '&occupancy=' + occupancy + ((!adv)?'&page=result':'&page=advancedSearch');
		url = '';
		var detail = 'termine';
		if (document.getElementById('conQSClubRadio').checked) {
			if (iff == '-1'){
				detail = 'zielgebiet';
			}
			if(adv){
				detail = "";
			}
			tturl += 'erde/index.php?showresult=1&detail=' + detail + '&engine=erde&KID=792900&formular=4' +
			'&termin=' + startDate + '&ruecktermin=' + endDate + '&dauer=' + duration +
			'&IFF=' + iff + '&erwachsene=' + adult + '&alter1=' + child1 + '&alter2=' + child2 + '&alter3=' + child3;
			
			if(adv){
				tturl += '&personen='+document.getElementById('conQSOccupation').value;
				if(child1){
					tturl += ';' + child1;
				}
				if(child2){
					tturl += ';' + child2;
				}
				if(child3){
					tturl += ';' + child3;
				}								
			}			
		} else {
			detail = 'zielgebiet';
			if(adv){
				detail = "";
			}
			tturl += 'erde/index.php?showresult=1&selftravel&detail=' + detail + '&engine=erde&KID=792900&formular=4' + '&termin=' + startDate + '&ruecktermin=' + endDate + '&dauer=' + duration + '&erwachsene=' + adult + '&alter1=' + child1 + '&alter2=' + child2 + '&alter3=' + child3 + '&abflughafen=' + airport + '&udfregionen=' + region;
			if(adv){
				tturl += '&personen='+document.getElementById('conQSOccupation').value;
				if(child1){
					tturl += ';' + child1;
				}
				if(child2){
					tturl += ';' + child2;
				}
				if(child3){
					tturl += ';' + child3;
				}								
			}			
		}



	}
	
	// flight
	if(traveltype==2){
		url += "?Flug"+destination3LC+ startairport3LC +"&Abflugdatum="+ startdate +"&Rueckflugdatum="+ returndate+ "&AnzahlReisende="+ occupancy + ((!adv)?'&Startseite=Angebotsliste':'&action=advancedSearch');
	}
	
	// mietwagen
	if(traveltype==3){
		url += "?Mietwagen&Land="+rentalcarCountry +"&Anmietung="+ startdate +"&Abgabe="+ returndate + ((!adv)?'&Startseite=List':'&page=advancedSearch');
	}
	if(!QSerr){
		hideErrCell();
		
		if (url == ''){
			location.href = tturl;
		} else {
			location.href = url;
		}
		//alert(url);
	} else {
		if(traveltype==0){
		 showErrCell(QSerrTxt);
		}
	}
}

jQuery(document).ready(function() {


	jQuery('a','#contentContainer').each(function() {
		if(jQuery(this).attr('href')) {	
			jQuery(this).attr('href', jQuery(this).attr('href').replace(
				'http://ww2.robinson.com/booking/robinson/erde/index.php', 
				'http://ww2.robinson.ch/booking/robinson_ch/erde/index.php'
			));
			jQuery(this).attr('href', jQuery(this).attr('href').replace(
				'793000', 
				'792900'
			));
		}
	});

	jQuery('a','#contentContainer').each(function() {
		if(jQuery(this).attr('href')) {	
			jQuery(this).attr('href', jQuery(this).attr('href').replace(
				'http://ww2.robinson.com/booking/robinson/index.php', 
				'http://ww2.robinson.ch/booking/robinson_ch/index.php'
			));
			jQuery(this).attr('href', jQuery(this).attr('href').replace(
				'793000', 
				'792900'
			));
		}
	});	


	jQuery('.tx-tuisearch-pi1 form[action="http://ww2.robinson.com/booking/robinson/index.php"]').attr('action', 'http://ww2.robinson.ch/booking/robinson_ch/index.php?KID=792900&formular=4&personen=25;25');
	
	jQuery('.tx-tuisearch-pi1 input[name="KID"]').attr('value', '792900');
	
	jQuery('img[src=fileadmin/rob/pics/buttons/tuev-robinson_homepage.png]').remove();
});
