function calcDayOfWeek(WhichDD) {
	if (WhichDD=="P") {
		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);
	}else{
		var day = parseInt(document.carSearchFormBean.dropDate.options[document.carSearchFormBean.dropDate.selectedIndex].value,10);
		var monthVal = new String(document.carSearchFormBean.dropMonth.options[document.carSearchFormBean.dropMonth.selectedIndex].value);
	}
	var month = parseInt(monthVal.slice(4),10);
	var year = parseInt(monthVal.slice(0,4),10);
	selectedDate = new Date(year,month-1,day,0,0,0,0);
	if (selectedDate.getDate()!=day) {
		WhichDD=="P"?document.carSearchFormBean.pickDate.selectedIndex=day-selectedDate.getDate()-1:document.carSearchFormBean.dropDate.selectedIndex=day-selectedDate.getDate()-1;
		selectedDate.setDate(day-selectedDate.getDate());
		selectedDate.setMonth(selectedDate.getMonth()-1);
	}
}
rightnow = new Date();
function month(i,name) {
	var thisyear = rightnow.getFullYear();
	var nextyear = thisyear + 1;
	var a =	"";
    (i<rightnow.getMonth()) ? a+=nextyear : a+=thisyear;
	(i<9) ? a += "0"+(i+1) : a +=(i+1);
	var b = name+ ", ";
	(i<rightnow.getMonth()) ? b +=nextyear : b +=thisyear;
	this.name = b;
	this.value = a;
}
var months = new Array(new month(0,"Januar"), new month(1,"Februar"),new month(2,"März"),new month(3,"April"),new month(4,"Mai"), new month(5,"Juni"), new month(6,"Juli"), new month(7,"August"), new month(8,"September"), new month(9,"Oktober"), new month(10,"November"), new month(11,"Dezember"));
function init(){
for(i=0;i<12;i++) document.carSearchFormBean.pickMonth[i] = new Option (months[i].name,months[i].value);
    for(j=0;j<12;j++) document.carSearchFormBean.dropMonth[j] = new Option (months[j].name,months[j].value);
    for(d=0;d<31;d++) document.carSearchFormBean.dropDate[d] = new Option(d+1,((d<10)?"0"+(d+1):d+1));
    for(d=0;d<31;d++) 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;
		document.carSearchFormBean.pickMonth.selectedIndex = sevendays.getMonth();
		then = new Date(sevendays.getTime()+(604800000))
		document.carSearchFormBean.dropDate.selectedIndex = then.getDate()-1;
		document.carSearchFormBean.dropMonth.selectedIndex = then.getMonth();
	}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;
	}
}
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)) {
    		alert('Bitte geben Sie ein gültiges Rückflugdatum an');
    		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;
			}
			return true;
        }
    }else{
		  alert("Bitte geben Sie das Alter des Fahrers an.");
          return false;
    }
}
