/* Travel IT to Travel Tainment 24.09.2009 */
// http://reisen.last-minito.de/booking/last-minito/index.php?showresult=1&detail=zielgebiet&engine=pauschal&KID=780500&formular=4&nurflug=&spezial=&agent=LMFB&termin=1254517200&Burl=&ruecktermin=1256331600&kombi=&abflughafen=-1&ktag=3&kmonat=10.2009&erwachsene=25%3B25&ziel=-1&rueckktag=24&rueckkmonat=10.2009&alter1=-1&alter3=-1&region=-1&dauer=-1&alter2=-1&kategorie=-1&shotel=&verpflegung=-1&zimmer=-1&marke=&zimmer2=-1&sportangebot=-1&hbfges=0&hbfanz=0&hbfempf=0

function to_tt() {
	tit_transfer = $("#transfer_to_tit").val();
	if(tit_transfer == undefined || tit_transfer == 'yes') {
	var myDate = new Date; // Generic JS date object
	unixtime_ms = (myDate.getTime()/1000.0);
	default_duration = unixtime_ms +(86400 * 15);

	//$("#protravel_search").attr("action",fourkids);
	/* TT Defaults */
	tt_adults = '25;25';
	tt_alter1 = '-1';
	tt_alter2 = '-1';
	tt_alter3 = '-1';
	tt_alter4 = '-1';
	tt_price  = '-1';
	tt_duration = '-1';
	tt_departure = '-1';
	tt_departure_date = unixtime_ms;
	tt_return_date = default_duration;
	tt_travel_operator = '-1';
	tt_hotel_catering = '-1';
	tt_hotel_room = '-1';
	tt_hotel_star = '-1';
	tt_detail = 'detail=zielgebiet'; // default page region;
	tt_sportmoeglichkeiten = '-1'; // Sports Center
	tt_sportangebot = '-1'; // different sport type
	tt_at_beach = '-1'; // at_beach
	tt_wellness = '-1'; // wellness
	tt_typ = '-1'; // Club
	tt_familie_kinder = '-1'; //kid club

	new_url = tt_url+'KID=780500&&engine=pauschal&formular=4&nurflug=&spezial=&showresult=1&agent='+agent_code;

	/* TiT values */
	tit_adults = $("#adult_passangers").val();
	tit_kid1 = $("#kid1_passanger").val();
	tit_kid2 = $("#kid2_passanger").val();
	tit_kid3 = $("#kid3_passanger").val();
	tit_kid4 = $("#kid4_passanger").val();
	tit_price = $("#maximum_price").val();
	tit_duration = $("#travel_duration").val();
	tit_departure_date = humanToTime($("#outbound_date").val());
	tit_return_date = humanToTime($("#inbound_date").val());

	tit_departure = $("#outbound_departure").val();
	tit_destination = $("#outbound_destination").val();

	tit_travel_operator = $("#travel_operator").val();
	tit_hotel_catering = $("#hotel_catering").val();
	tit_hotel_room = $("#hotel_room").val();
	tit_hotel_star = $("#hotel_star").val();
	/* Ha values */
	tit_at_beach = $("input[name='at_beach']:checked").val();
	tit_animation = $("input[name='animations']:checked").val();
	tit_club = $("input[name='club']:checked").val();
	tit_wellness = $("input[name='welness_facilities']:checked").val();
	tit_kid_club = $("input[name='kid_club']:checked").val();
	tit_sports_center = $("input[name='sports_center']:checked").val();


	/* TT to TiT Conversation */

	/* Destination check */
	if(tit_destination != undefined && tit_destination != '' && dst_tit_to_tt != undefined) {
		if(dst_tit_to_tt[tit_destination] != undefined) {
			tt_destination = parseInt(dst_tit_to_tt[tit_destination]);
			if(tt_destination < 10000) {
				tt_detail = 'detail=hotel&zielgebiets_kenner='+tt_destination;
			} else {
				tt_detail = 'detail=zielgebiet&flugdauer='+tt_destination;
			}
		}
	}
	/* Reponse page */
	new_url = new_url+'&'+tt_detail;

	/* Departure check */
	if(tit_departure != undefined && tit_departure != '' && dep_tit_to_tt != undefined) {
		multidep = tit_departure.indexOf('x');

		if(multidep == '-1') {
			if(dep_tit_to_tt[tit_departure] != undefined) {
				tt_departure = parseInt(dep_tit_to_tt[tit_departure]);
			}
		} else {
			if(tit_departure == 'DUSxDTMxFRAxCGNxFMOxPADxNRN') { // West
				tt_departure = '5002';
			} else if(tit_departure == 'THFxSXFxTXLxDRSxERFxLEJxLBCxRLGxSZW') { // ost
				tt_departure = '5003';
			} else if(tit_departure == 'FDHxMUCxNUExSTR') { // Sud
				tt_departure = '5001';
			} else if(tit_departure == 'BRExHAMxHAJ') { // Nord
				tt_departure = '5000';
			} else {
				departures = tit_departure.split('x');
				for ( var i in departures ) {
					/*
					cdep = departures[i];
					tt_departure = '';
					if(dep_tit_to_tt[cdep] != undefined) {
						tt_departure = tt_departure+';'+parseInt(dep_tit_to_tt[cdep]);
					}*/
					cdep = departures[0];
					tt_departure = parseInt(dep_tit_to_tt[cdep]);
				}
			}
		}
	}
	new_url = new_url+'&abflughafen='+tt_departure;

	/* Adult Passangers */
	switch(tit_adults) {
		case '1': tt_adults = '25'; break;
		case '2': tt_adults = '25;25'; break;
		case '3': tt_adults = '25;25;25'; break;
		case '4': tt_adults = '25;25;25;25'; break;
	}
	new_url = new_url+'&erwachsene='+tt_adults;

	/* Kid Passanger 1 */
	if(tit_kid1 < 18) { tt_alter1 = tit_kid1; }
	new_url = new_url+'&alter1='+tt_alter1;

	/* Kid Passanger 2 */
	if(tit_kid2 < 18) { tt_alter2 = tit_kid2; }
	new_url = new_url+'&alter2='+tt_alter2;

	/* Kid Passanger 3 */
	if(tit_kid3 < 18) { tt_alter3 = tit_kid3; }
	new_url = new_url+'&alter3='+tt_alter3;

	/* Kid Passanger 3 */
	if(tit_kid4 < 18) { tt_alter4 = tit_kid4; }
	new_url = new_url+'&alter4='+tt_alter4;

	/* Max price */
	if(tit_price != undefined && tit_price != '') { tt_price = tit_price; }
	new_url = new_url+'&preis='+tt_price;

	/* Duration ?? */
	if(tit_duration != undefined && tit_duration != '' && tit_duration != '0' && tit_duration != '-') {
		switch(tit_duration) {
			case '0': tt_duration = '-1'; break;
			case '7-7': tt_duration = '6_7'; break;
			case '14-14': tt_duration = '6_14'; break;
			case '9-12': tt_duration = '7'; break;
			case '21-23': tt_duration = '6_21'; break;
			case '2-3': tt_duration = '9'; break;
			case '3-5': tt_duration = '9'; break;
			case '5-7': tt_duration = '10'; break;
			case '8-10': tt_duration = '10'; break;
			case '9-12': tt_duration = '7'; break;
			case '13-15': tt_duration = '3'; break;
			case '16-22': tt_duration = '12'; break;
			case '22-0': tt_duration = '13'; break;
		}
	}
	new_url = new_url+'&dauer='+tt_duration;

	/* Outbound Date */
	new_url = new_url+'&termin='+tit_departure_date;

	/* Inbound Date */
	new_url = new_url+'&ruecktermin='+tit_return_date;

	/* Travel Operator */
	if(tit_travel_operator!= undefined && tit_travel_operator != '') { tt_travel_operator = tit_travel_operator; }
	new_url = new_url+'&marke='+tt_travel_operator;

	/* Hotel Cartering */
	if(tit_hotel_catering != 0) {
		switch(tit_hotel_catering){
			case '2': tt_hotel_catering = 0; break;
			case '3': tt_hotel_catering = 1; break;
			case '1': tt_hotel_catering = 2; break;
			case '4': tt_hotel_catering = 3; break;
			case '6': tt_hotel_catering = 4; break;
		}
	}
	new_url = new_url+'&verpflegung='+tt_hotel_catering;

	/* Hotel Room */
	if(tit_hotel_room != 0) {
		switch(tit_hotel_room){
			case '2': tt_hotel_room = 5; break;
			case '1': tt_hotel_room = 6; break;
			case '5': tt_hotel_room = 0; break;
			case '4':
				tt_hotel_room = -2;
				new_url = new_url+'&zfilter='+2;
			break;
			case '3': tt_hotel_room = 7; break;
			case '6':
				tt_hotel_room = -2;
				new_url = new_url+'&zfilter='+16;
			break;
			case '9': tt_hotel_room = 2; break;
		}
	}
	new_url = new_url+'&zimmer='+tt_hotel_room;

	/* Hotel star */
	if(tit_hotel_star != undefined && tit_hotel_star != 0) {
		switch(tit_hotel_star){
			case '2': tt_hotel_star = 0; break;
			case '3': tt_hotel_star = 1; break;
			case '4': tt_hotel_star = 2; break;
			case '5': tt_hotel_star = 3; break;
		}
	}
	new_url = new_url+'&kategorie='+tt_hotel_star;

	/* At Beach */
	if(tit_at_beach == 'on') { tt_at_beach = 0; }
	new_url = new_url+'&strand='+tt_at_beach;

	/* Sports */
	if(tit_sports_center == 'on') { tt_sportmoeglichkeiten = 0; }
	new_url = new_url+'&sportmoeglichkeiten='+tt_sportmoeglichkeiten+'&sportangebot='+tt_sportangebot;

	/* Wellness */
	if(tit_wellness == 'on') { tt_wellness = 0; }
	new_url = new_url+'&wellness='+tt_wellness;

	/* Club Hotels */
	if(tit_club == 'on') { tt_typ = 0; }
	new_url = new_url+'&typ='+tt_typ;

	/* Kid Club Hotels */
	if(tit_kid_club  == 'on') { tt_familie_kinder = 0; }
	new_url = new_url+'&familie_kinder='+tt_familie_kinder;



	/* Forvard request to Travel Tainment */
	window.location = new_url;
	}
	return false;
}