$(document).ready(function() {
	if (typeof(geo_entity) != 'undefined') {
		if ((geo_entity != '') && (geo_entity != 'continent')) {
			toggleDisplay('package');
			$('.tx-oposidemps-pi1 select#BE_AIR_NUM_OF_CHILDREN').setValue('package');
		}
	}
	
	// MPS Initialization only when Search is on site
	if ( $("#OpodoQuickSearch").length > 0 ) {
		init_mietwagen();
		init();
		initFlights();
		init_hotel();
	}
});




// ###########################################################################################################################
// Setting for complete MPS  #################################################################################################
// ###########################################################################################################################
var Maximum 	= 10;
var rightnow 	= new Date();
var mDays 		= new Array(31,28,31,30,31,30,31,31,30,31,30,31)	
var monthDays 	= new Array(31,28,31,30,31,30,31,31,30,31,30,31);
var monthLengths= new Array(31,28,31,30,31,30,31,31,30,31,30,31);
var days 		= new Array("So","Mo","Di","Mi","Do","Fr","Sa");
var months 		= new Array(new month(0,"Jan"), new month(1,"Feb"),new month(2,"Mär"),new month(3,"Apr"),new month(4,"Mai"), new month(5,"Jun"), new month(6,"Jul"), new month(7,"Aug"), new month(8,"Sep"), new month(9,"Okt"), new month(10,"Nov"), new month(11,"Dez"));

// URLAUBSREISE
var dest_abflug = new Array(["-1","beliebig"],["1000","Nord"],["1001","Süd"],["1002","West"],["1003","Ost"],["0","Altenburg-Nob."],["1","Amsterdam (NL)"],["2","Augsburg"],["3","Basel-Mulhouse (CH)"],["4","Berlin-Schönef."],["5","Berlin-Tegel"],["6","Berlin-Tempelh."],["7","Bern-Belp (CH)"],["8","Bremen"],["9","Brüssel (B)"],["10","Dortmund"],["11","Dresden"],["12","Düsseldorf"],["13","Enschede (NL)"],["14","Erfurt"],["15","Frankfurt"],["16","Frankfurt-Hahn"],["17","Friedrichshafen"],["18","Genf (CH)"],["19","Graz (A)"],["20","Hamburg"],["21","Hannover"],["22","Hof-Plauen"],["23","Innsbruck (A)"],["24","Karlsruhe"],["25","Kassel"],["26","Kiel"],["27","Klagenfurt (A)"],["28","Köln-Bonn"],["29","Leipzig-Halle"],["30","Linz (A)"],["31","Lübeck"],["32","Lüttich (B)"],["33","Luxemburg"],["34","Maastricht (NL)"],["35","Mönchengladb."],["36","München"],["37","Münster-Osnab."],	["38","Nürnberg"],["39","Paderborn"],["40","Rostock"],["41","Saarbrücken"],["42","Salzburg (A)"],["43","Schwerin"],["44","Strasbourg (F)"],["45","Stuttgart"],["46","Wien (A)"],["47","Zürich (CH)"],["48","Zweibrücken"]);
var dest_ziel 	= new Array(["-1","beliebig"],["0","Nahstrecke"],["1","Mittelstrecke"],["2","Fernstrecke"],["3","Mittelmeer (Ges.)"],["4","Spanien-Portugal"],["5","Griechenland"],["5","T&uuml;rkei-Zypern"],["6","Kanarische Inseln"],["7","Mallorca-Menorca"],["7","Ibiza"],["8","Karibik-Mexico"],["8","Dominikanische Rep."],["9","&Auml;gypten-Israel-VAE"],["10","Asien-Thailand"],["10","Malediven"],["11","Afrika-Mauritius"],["11","Seychellen"],["12","Tunesien-Marokko"],["13","Kroatien-Bulgarien"],["14","Bes. Tauchregionen"]);
var child1 		= new Array(["-1","---"],["1","<2 Jahre"],["2","2 Jahre"],["3","3 Jahre"],["4","4 Jahre"],["5","5 Jahre"],["6","6 Jahre"],["7","7 Jahre"],["8","8 Jahre"],["9","9 Jahre"],["10","10 Jahre"],["11","11 Jahre"],["12","12 Jahre"],["13","13 Jahre"],["14","14 Jahre"],["15","15 Jahre"],["16","16 Jahre"]);

// Flight V2 Autocomplete Setup
var ajaxBox_offsetX = 0;
var ajaxBox_offsetY = 0;
var minimumLettersBeforeLookup = 1; // Minimum number of letters before lookup airport/city names
var allowLevenshteinDistance = 2; // allow use of Levenshtein distance for correcting typos, set the maximum allowed distance, or 0 to disable
var submitform = false;


function month(i,name) {
	rightnow = new Date();
	var thisyear = rightnow.getFullYear();
	var nextyear = thisyear + 1;
	var a = "<option value=\"";
	(i<rightnow.getMonth()) ? a +=nextyear : a +=thisyear;
	(i<9) ? a += "0"+(i+1) : a +=(i+1);
	a += "\">"+name+" 0";
	(i<rightnow.getMonth()) ? a +=(nextyear-2000) : a +=(thisyear-2000);
	a += "</option>\n";
	this.option = a;
}




// Toggle for products through selectbox
function toggleDisplay(tg) {
	if (document.getElementById('OpodoQuickFlightSearch') === null) return;

	switch(tg) {
	case 'flights':
		document.getElementById('OpodoQuickFlightSearch').style.display = 'block';
		document.getElementById('OpodoQuickHotelSearch').style.display = 'none';
		document.getElementById('OpodoQuickCarSearch').style.display = 'none';
		document.getElementById('OpodoQuickPackageSearch').style.display = 'none';
		document.getElementById('OpodoQuickSearch').className = 'searchFlug';
		break
	case 'hotel':
		document.getElementById('OpodoQuickFlightSearch').style.display = 'none';
		document.getElementById('OpodoQuickHotelSearch').style.display = 'block';
		document.getElementById('OpodoQuickCarSearch').style.display = 'none';
		document.getElementById('OpodoQuickPackageSearch').style.display = 'none';
		document.getElementById('OpodoQuickSearch').className = 'searchHotel';
		break
	case 'cars':
		document.getElementById('OpodoQuickFlightSearch').style.display = 'none';
		document.getElementById('OpodoQuickHotelSearch').style.display = 'none';
		document.getElementById('OpodoQuickCarSearch').style.display = 'block';
		document.getElementById('OpodoQuickPackageSearch').style.display = 'none';
		document.getElementById('OpodoQuickSearch').className = 'searchCar';
		break
	case 'package':
		document.getElementById('OpodoQuickFlightSearch').style.display = 'none';
		document.getElementById('OpodoQuickHotelSearch').style.display = 'none';
		document.getElementById('OpodoQuickCarSearch').style.display = 'none';
		document.getElementById('OpodoQuickPackageSearch').style.display = 'block';
		document.getElementById('OpodoQuickSearch').className = 'searchPackage';
		break
	}
}



// ###########################################################################################################################
// FLUGSUCHE   ###############################################################################################################
// ###########################################################################################################################
function setOptions(chosen) {
	frm = document.flightSearch;
	var selbox = frm.NUM_OF_CHD;
		selbox.options.length = 0;
	var selbox2 = frm.NUM_OF_INFS;
		selbox2.options.length = 0;
	var box1 = frm.NUM_OF_ADTS.options[frm.NUM_OF_ADTS.selectedIndex].value;
	for(q=0;q<=box1;q++){
		 selbox2.options[selbox2.options.length] = new Option(q,q);
	}
	for(i=0;i <Maximum ; i++){
		if (chosen == i) {
			selbox.options[selbox.options.length] = new Option(0,0);
			for(z=1;z <(Maximum-i) ; z++){
			  selbox.options[selbox.options.length] = new Option(z,z);
			}
		}
	}
}
																		
function validReturnDate(formName, elementArray) {
		firstDay = eval('document.' + formName + '.' + elementArray[0] + ".options[" + 'document.' + formName + '.' + elementArray[0] + '.selectedIndex].value');
		firstMonth = eval('document.' + formName + '.' + elementArray[1] + ".options[" + 'document.'	+ formName + '.' + elementArray[1] + '.selectedIndex].value');
		firstYear = firstMonth.substr(0,4);
		secondDay = eval('document.' + formName + '.' + elementArray[2] + ".options[" + 'document.'	+ formName + '.' + elementArray[2] + '.selectedIndex].value');
		secondMonth = eval('document.' + formName + '.' + elementArray[3] + ".options[" + 'document.'	+ formName + '.' + elementArray[3] + '.selectedIndex].value');
		secondYear = secondMonth.substr(0,4);
		if ((validMonthDay(firstDay, firstMonth, firstYear))&& (validMonthDay(secondDay, secondMonth, secondYear))){
			outboundDate = createDate(firstDay, firstMonth);
			returnDate = createDate(secondDay, secondMonth);
			return ((outboundDate.valueOf() <= returnDate.valueOf()) && (outboundDate.valueOf() > rightnow.valueOf()) ) ? true : false;
		} else {
			return false;
		}	
}

function isLeapYear(year) {
	return (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0));
}

function validMonthDay(dayVal, monthVal, yearVal){
	var error = 0;
	if ((monthVal.substr(4,2) == 4)||(monthVal.substr(4,2) == 6)||(monthVal.substr(4,2) == 9)||(monthVal.substr(4,2) == 11)){
		if (dayVal>30) error = 1;
	} else if (monthVal.substr(4,2) == 2) {
		if (isLeapYear(yearVal)){ 
			if (dayVal>29) error = 1;
		} else {
			if (dayVal>28) error = 1;
		}
	} else {
		if (dayVal>31) error = 1;
	}
	return (error == 1) ? false : true;	
}

function createDate(day, monthYear) {
	dayVal = day;
	monthYearVal = monthYear;
	x = dayVal.substr(0,1);
	(x == "0") ? day = parseInt(dayVal.substr(1,1)) : day = parseInt(dayVal.substr(0,2));
	
	y = monthYearVal.substr(4,1);
	(y == "0") ? month = parseInt(monthYearVal.substr(5,1)) : month = parseInt(monthYearVal.substr(4,2));
	
	year = parseInt(monthYearVal.substr(0,4));
	if (year < 1900) year = year + 1900;
	newDate = new Date(year, month-1, day);
	return newDate;
}


function isLeapYear(year) {
	return ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0);
}

function isNull(val){
	return(val==null);
}

function changeDate(objMonth, objDate, adoptMonth, adoptDate, difference) {
	maxDays = monthLengths[(rightnow.getMonth() + objMonth.selectedIndex) % 12];
	if ( (objMonth.selectedIndex == 1) && (isLeapYear(objMonth.value.substring(0, 4))) ) maxDays="29";

	var oldSelect = objDate.selectedIndex;
	if (oldSelect > maxDays-1) oldSelect = maxDays-1;
	
	objDate.length = 0;
	for (d=0;d<maxDays;d++) {
	    objDate[d] = new Option((d+1),(((d+1)<10)?"0"+(d+1):d+1));
	}

	objDate.selectedIndex = oldSelect;

	if (difference > 0 || difference == undefined)	{
	    var priMonth = objMonth;
	    var priDate = objDate;
	    var secMonth = adoptMonth;
	    var secDate = adoptDate;
	} else {
	    var secMonth = objMonth;
	    var secDate = objDate;
	    var priMonth = adoptMonth;
	    var priDate = adoptDate;
	}
		
	if (secMonth != undefined)	{
	    if (priMonth.value > secMonth.value) {
			secMonth.selectedIndex = priMonth.selectedIndex;
	    }
	    if (priMonth.value == secMonth.value && priDate.value > secDate.value)  {
	        secDate.selectedIndex = priDate.selectedIndex;		
	    }
	}	

}


// flights /////////////////////////////////////////////////////////////////////////////////////////
function flightSearchSubmit(buttonValue){

		if (submitform == false) return false;
		
		
//		document.flightSearch.whereTo.value = buttonValue;
//		document.flightSearch.BE_QUICK_SEARCH_FLAG.value = true;
		
		var datesArray= new Array('departureDay', 'departureMonth', 'returnDay', 'returnMonth');
		var formName = 'flightSearch';
		firstDay = eval('document.' + formName + '.' + datesArray[0] + ".options[" + 'document.' + formName + '.' + datesArray[0] + '.selectedIndex].value');
		firstMonth = eval('document.' + formName + '.' + datesArray[1] + ".options[" + 'document.' + formName + '.' + datesArray[1] + '.selectedIndex].value');
		firstYear=firstMonth.substr(0,4);
		secondDay = eval('document.' + formName + '.' + datesArray[2] + ".options[" + 'document.' + formName + '.' + datesArray[2] + '.selectedIndex].value');
		secondMonth = eval('document.' + formName + '.' + datesArray[3] + ".options[" + 'document.'	+ formName + '.' + datesArray[3] + '.selectedIndex].value');
		secondYear=secondMonth.substr(0,4);
		
		if((document.flightSearch.departureAirport.value.length > 0 && document.flightSearch.arrivalAirport.value.length > 0)) {
			if(!validMonthDay(firstDay, firstMonth, firstYear)) {

				alert("Please enter a valid departure date");
				return false;
			} else { 
				if(!validMonthDay(secondDay, secondMonth, secondYear)){
					alert("Please enter valid return and departure dates");
					return false;
				} else { 
					if (validReturnDate(formName, datesArray)){
						return true;
					} else {
						alert("Please enter valid return and departure dates");
						return false;
					}
				}
			}
		} else {
			alert("Please enter a valid Departure and Arrival City");
			document.getElementById("cityDepart").style.color="#FF3300";
			document.getElementById("cityArrive").style.color="#FF3300";
			return false;
		}
}

// set week day
function calcDay(frm,nm,nm2,day){
	dateVal = document.forms[frm].elements[nm].options[document.forms[frm].elements[nm].selectedIndex].value;
	monthVal = document.forms[frm].elements[nm2].options[document.forms[frm].elements[nm2].selectedIndex].value;
	var isLeapYear = (((monthVal.substr(0,4) % 4 == 0) && (monthVal.substr(0,4) % 100 != 0)) || (monthVal.substr(0,4) % 400 == 0));
	mDays[1] = (isLeapYear)?29:28;
		if(dateVal > mDays[monthVal.substr(4,2)-1]){
			setDDValue(document.forms[frm].elements[nm],mDays[monthVal.substr(4,2)-1]);
			dateVal = document.forms[frm].elements[nm].options[document.forms[frm].elements[nm].selectedIndex].value;}
		newDate = new Date(Date.UTC(monthVal.substr(0,4),parseInt(monthVal.substr(4,2)-1),dateVal));
		document.forms[frm].elements[day].value = days[newDate.getDay()];
}

function initFlights() {
	tomorrow = new Date(rightnow.getTime()+(86400000));
	document.flightSearch.departureDay.selectedIndex = tomorrow.getDate()-1;
	then = new Date(tomorrow.getTime()+(604800000))
	document.flightSearch.returnDay.selectedIndex = then.getDate()-1;
	document.flightSearch.returnMonth.selectedIndex = (then.getMonth() - tomorrow.getMonth()) % 12;
	var oldDepartIndex = document.flightSearch.departureDay.selectedIndex;
	document.flightSearch.departureDay.selectedIndex = oldDepartIndex;
	var oldReturnIndex = document.flightSearch.returnDay.selectedIndex;
	document.flightSearch.returnDay.selectedIndex = oldReturnIndex;
	if(tomorrow.getDate()-1 == 0){
	document.flightSearch.departureMonth.selectedIndex = (then.getMonth()+1 - tomorrow.getMonth())
	document.flightSearch.returnMonth.selectedIndex = (then.getMonth()+1 - tomorrow.getMonth())
	}
}


function flightPrepSubmit()
{
    if (document.getElementById('departureAirport_hidden').value == '' && document.getElementById('departureAirport').value.length == 3) document.getElementById('departureAirport_hidden').value = document.getElementById('departureAirport').value;
    if (document.getElementById('arrivalAirport_hidden').value == '' && document.getElementById('arrivalAirport').value.length == 3) document.getElementById('arrivalAirport_hidden').value = document.getElementById('arrivalAirport').value;
    submitform = true;
    document.flightSearch.submit();
}
					    
function dateChangeTrigger(){
}

// set preferred Airlines
function fillSelect(field, codeArray, nameArray,selectedValue){
	var selectedIndex = -1;
	for (var i = 0; i < codeArray.length; i++){
	if (selectedValue == codeArray[i])
		selectedIndex = field.length;
	field[field.length] = new Option(nameArray[i], codeArray[i]);
	}
	if (selectedIndex != -1)
	field.selectedIndex = selectedIndex;
}


// ###########################################################################################################################
// HOTELSUCHE  ###############################################################################################################
// ###########################################################################################################################

function hotelSubmit() {
	var f1 = document.hotel;
	var f2 = document.hotelOutput;
	monthYear = f1.checkInDateB.options[f1.checkInDateB.selectedIndex].value;
	dayVal = f1.checkInDateA.options[f1.checkInDateA.selectedIndex].value;
	monthVal= monthYear.substr(4,2);
	yearVal = monthYear.substring(0,4);
	
	numAdlts = f1.numOfAdults.options[f1.numOfAdults.selectedIndex].value;
	numRo = f1.numberOfRooms.options[f1.numberOfRooms.selectedIndex].value;
				
	secMonthYear = f1.depDateB.options[f1.depDateB.selectedIndex].value;
	secDayVal = f1.depDateA.options[f1.depDateA.selectedIndex].value;
	secMonthVal = secMonthYear.substr(4,2);
	secYearVal = secMonthYear.substring(0,4);
	
	var date = new Date(yearVal, monthVal-1, dayVal);
	var secdate = new Date(secYearVal, secMonthVal-1, secDayVal);
	var theDate = date.getDate();
	var theSecDate = secdate.getDate();
	var aCity = f2.destinationName.value;
	
	if (aCity==0) {
		alert("Bitte geben Sie den Zielort ein.");		
		document.hotelOutput.destinationName.focus()
		return false;
	}
	if (!((rightnow.valueOf() < (date.valueOf()+(86400000))) && (date.valueOf() <= secdate.valueOf()))) {
		alert("Bitte geben Sie ein gültiges Datum ein");
		return false;
	} else {
		f2.checkInDate.value = monthYear + dayVal;
		f2.checkOutDate.value = secMonthYear + secDayVal;
		f2.numOfAdults.value = numAdlts;
		f2.numberOfRooms.value = numRo;
		f2.submit();
		return false;
	}
}
	
function init_hotel() {
	var f1 = document.hotel;
	tomorrow = new Date(rightnow.getTime());
	for(d=0;d<31;d++) f1.checkInDateA[d] = new Option(d+1,((d<10)?"0"+(d+1):d+1));
	for(d=0;d<31;d++) f1.depDateA[d] = new Option(d+1,((d<10)?"0"+(d+1):d+1));
	f1.checkInDateA.selectedIndex = tomorrow.getDate()-1;
	index = tomorrow.getMonth()-rightnow.getMonth();
	if (index < 1) index = 0;
	f1.checkInDateB.selectedIndex = tomorrow.getMonth()-rightnow.getMonth();	
	then = new Date(tomorrow.getTime()+(86400000));
	f1.depDateA.selectedIndex = then.getDate()-1;
	index = then.getMonth()-rightnow.getMonth();
	if (index < 1) index = 0;
	f1.depDateB.selectedIndex = index;
}

// ###########################################################################################################################
// MIETWAGENSUCHE ############################################################################################################
// ###########################################################################################################################

function init_mietwagen(){

    for(d=0;d<31;d++) {
    	document.carSearchFormBean.dropDate[d] = new Option(d+1,((d<10)?"0"+(d+1):d+1));
    	document.carSearchFormBean.pickDate[d] = new Option(d+1,((d<10)?"0"+(d+1):d+1));
    }

	
	if(document.carSearchFormBean.pickUpDateForm.value=="") {
		sevendays = new Date(rightnow.getTime()+(604800000));
		document.carSearchFormBean.pickDate.selectedIndex = sevendays.getDate()-1;
		then = new Date(sevendays.getTime()+(604800000));
		document.carSearchFormBean.dropDate.selectedIndex = then.getDate()-1;
		var datum = monthLengths[sevendays.getMonth()] -7;
		
		index = sevendays.getMonth() - rightnow.getMonth();
		if (index < 1) index = 0;
		document.carSearchFormBean.pickMonth.selectedIndex = index;
		
		index = then.getMonth() - rightnow.getMonth();
		if (index < 1) index = 1;
		document.carSearchFormBean.dropMonth.selectedIndex = index;
		
		/*
		if(rightnow.getDate() > datum ) { 
			document.carSearchFormBean.pickMonth.selectedIndex = document.carSearchFormBean.pickMonth.selectedIndex+1; }
		if(sevendays.getDate() > datum || rightnow.getMonth() < sevendays.getMonth()) { 
			document.carSearchFormBean.dropMonth.selectedIndex = document.carSearchFormBean.dropMonth.selectedIndex+1; }
		*/
	} else {
		var pickup	= document.carSearchFormBean.pickUpDateForm.value;
		var drop	= document.carSearchFormBean.dropOffDateForm.value;
		var pmonth	= parseInt(pickup.slice(4,6),10);
		var pday	= parseInt(pickup.slice(6,8),10);
		var ptime	= parseInt(pickup.slice(8,10),10);
		document.carSearchFormBean.pickMonth.selectedIndex	= pmonth-1;
		document.carSearchFormBean.pickDate.selectedIndex	= pday-1;
		document.carSearchFormBean.pickHour.selectedIndex	= ptime;
		var dmonth	= parseInt(drop.slice(4,6),10);
		var dday	= parseInt(drop.slice(6,8),10);
		var dtime	= parseInt(drop.slice(8,10),10);
		document.carSearchFormBean.dropMonth.selectedIndex	= dmonth-1;
		document.carSearchFormBean.dropDate.selectedIndex	= dday-1;
		document.carSearchFormBean.dropHour.selectedIndex	= dtime;
	}

	//changeDate(document.carSearchFormBean.pickMonth, document.carSearchFormBean.pickDate);
	//changeDate(document.carSearchFormBean.dropMonth, document.carSearchFormBean.dropDate);
}
function setPickLoc() {
	document.carSearchFormBean.destination1.value = document.carSearchFormBean.searchString.value;
}
function setDropLoc() {
	document.carSearchFormBean.destination2.value = document.carSearchFormBean.searchStringDrop.value;
}
function submitCheck() {
    if (document.carSearchFormBean.age.selectedIndex!=0) {
    	var day 		= parseInt(document.carSearchFormBean.pickDate.options[document.carSearchFormBean.pickDate.selectedIndex].value,10);
    	var monthVal 	= new String(document.carSearchFormBean.pickMonth.options[document.carSearchFormBean.pickMonth.selectedIndex].value);
    	var month 		= parseInt(monthVal.slice(4),10);
    	var year 		= parseInt(monthVal.slice(0,4),10);
    	var pickupDate 	= new Date(year,month-1,day,12,0,0,0);
    	day 			= parseInt(document.carSearchFormBean.dropDate.options[document.carSearchFormBean.dropDate.selectedIndex].value,10);
    	monthVal 		= new String(document.carSearchFormBean.dropMonth.options[document.carSearchFormBean.dropMonth.selectedIndex].value);
    	month 			= parseInt(monthVal.slice(4),10);
    	year 			= parseInt(monthVal.slice(0,4),10);

		var dropoffDate = new Date(year,month-1,day,12,0,0,0);
    	if (pickupDate>dropoffDate || pickupDate<rightnow) {
			if (pickupDate>dropoffDate) {
    			alert("Bitte geben Sie ein gültiges Rückgabedatum an");
				document.getElementById("returnDate").style.color="#FF3300";
    		}
			if (pickupDate<rightnow) {
	    		alert("Bitte Ihr Übernahmedatum prüfen");
	    		document.getElementById("outboundDate").style.color="#FF3300";
	    	}
    		return false;
		} else {
			document.carSearchFormBean.pickUpDateForm.value=""+pickupDate.getFullYear()+
			(((pickupDate.getMonth()+1)<10)?"0"+(pickupDate.getMonth()+1):(pickupDate.getMonth()+1))+
				((pickupDate.getDate()<10)?"0"+pickupDate.getDate():pickupDate.getDate())+
				((pickupDate.getHours()<10)?"0"+pickupDate.getHours():pickupDate.getHours())
				+((pickupDate.getMinutes()<10)?"0"+pickupDate.getMinutes():pickupDate.getMinutes());
			document.carSearchFormBean.dropOffDateForm.value=""+dropoffDate.getFullYear()+
			(((dropoffDate.getMonth()+1)<10)?"0"+(dropoffDate.getMonth()+1):(dropoffDate.getMonth()+1))+
				((dropoffDate.getDate()<10)?"0"+dropoffDate.getDate():dropoffDate.getDate())+
				((dropoffDate.getHours()<10)?"0"+dropoffDate.getHours():dropoffDate.getHours())+
				((dropoffDate.getMinutes()<10)?"0"+dropoffDate.getMinutes():dropoffDate.getMinutes());

			if (document.carSearchFormBean.destination2.value=="") {
				document.carSearchFormBean.destination2.value = document.carSearchFormBean.destination1.value;
			}
			document.carSearchFormBean.destination1.value=escape(document.carSearchFormBean.destination1.value);
			document.carSearchFormBean.destination2.value=escape(document.carSearchFormBean.destination2.value);
			return true;
        }
    }
}



function isLeapYear(year) {
	return ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0);
}

/*
function changeDate(objMonth, objDate) {
	maxDays = monthLengths[(rightnow.getMonth() + objMonth.selectedIndex) % 12];
	if ( (objMonth.selectedIndex == 1) && (isLeapYear(objMonth.value.substring(0, 4))) ) maxDays="29";

	var oldSelect = objDate.selectedIndex;
	if (oldSelect > maxDays-1) oldSelect = maxDays-1;

	objDate.length = 0;
	for (d=0;d<maxDays;d++) objDate[d] = new Option(d+1,((d<10)?"0"+(d+1):d+1));

	objDate.selectedIndex = oldSelect;
}
*/

function validateAge() {
	var valid = (document.carSearchFormBean.age.selectedIndex != 0);
	if (valid == false) {
		alert("Bitte geben Sie das Alter des Fahrers an.");
		document.carSearchFormBean.age.focus()
	}
	return valid;
}

function validatePickup() {
	var valid = (document.carSearchFormBean.destination1.value != "");
	if (valid == false) {
		alert("Bitte geben Sie eine Anmietstation ein.");
		document.carSearchFormBean.searchString.focus()
		//document.getElementById("searchString").style.color="#FF3300";
	}
	return valid;
}

function validateForm() {
	/*document.getElementById("age").style.color="#000000";
	document.getElementById("driverAge").style.color="#000000";
	document.getElementById("pickupDest").style.color="#000000";
	document.getElementById("returnDate").style.color="#000000";
    document.getElementById("outboundDate").style.color="#000000";*/
	return ( validateAge() ) && ( validatePickup() ) && ( submitCheck() );
}

// ###########################################################################################################################
// URLAUBSREISE  #############################################################################################################
// ###########################################################################################################################
	
function last_searchSubmit() {
	d = document.last_search2;
	d2 = document.last_search;
	
	var monthVal,dayVal,yearVal;
	var secMonthVal,secDayVal,secYearVal;
	monthYear	= d.D_Month.options[d.D_Month.selectedIndex].value;
	monthVal	= monthYear.substr(4,2);
	yearVal 	= monthYear.substring(0,4);
	dayVal 		= d.D_Day.options[d.D_Day.selectedIndex].value;
	secMonthYear= d.R_Month.options[d.R_Month.selectedIndex].value;
	secMonthVal	= secMonthYear.substr(4,2);
	secYearVal 	= secMonthYear.substring(0,4);
	secDayVal 	= d.R_Day.options[d.R_Day.selectedIndex].value;
	abf 		= d.abf.options[d.abf.selectedIndex].value;
	topregion	= d.topregion.options[d.topregion.selectedIndex].value;
	var date 	= new Date(yearVal, monthVal-1, dayVal);
	var secdate = new Date(secYearVal, secMonthVal-1, secDayVal);
	var theDate = date.getDate();
	var theSecDate = secdate.getDate();

	if ((rightnow > date)&&(rightnow > secdate)) {
		alert("Bitte geben Sie ein gültiges Abflug/Rückflug Datum ein");
		return false;
	}
	if (!((rightnow.valueOf() < date.valueOf()) && (date.valueOf() < secdate.valueOf()))) { 
		alert("Bitte geben Sie ein gültiges Abflug/Rückflug Datum ein");
		return false;
	} else {
		d2.termin.value = dayVal +'.'+ monthVal +'.' + yearVal;
		d2.ruecktermin.value = secDayVal +'.'+ secMonthVal +'.' + secYearVal;
		d2.abflughafen.value = abf;
		if(topregion == "") {		
			fenster = window.open (	"http://www.lastminute.opodo.de/booking/opodo/index.php?showresult=1&detail=zielgebiet&engine=&KID=634000&formular=4" +
									"&termin=" + dayVal +'.'+ monthVal +'.' + yearVal +
									"&ruecktermin=" + secDayVal +'.'+ secMonthVal +'.' + secYearVal +
									"&abflughafen=" + abf + 
									"&dauer=-1&erwachsene=25;25", 
									"OpodoTT");
			return false;			
		} else {
			d2.topRegion.value = topregion;			
			d2.detail.value 	= 'hotel';	
			return true;		
			d.submit();
		}

	}
}
	
function init() {
	tomorrow = new Date(rightnow.getTime()+(86400000));
	document.last_search2.D_Day.selectedIndex = tomorrow.getDate()-1;
	document.last_search2.D_Month.selectedIndex = 1;
	
	then = new Date(tomorrow.getTime()+(3542400000))
	document.last_search2.R_Day.selectedIndex = then.getDate()-1;
	document.last_search2.R_Month.selectedIndex = 2;
}
