function yearOptions() {
         var i=0;
         var datum = new Date();
	var jahr = datum.getFullYear();
	while (i<6){
         	document.write("<option value="+jahr+">"+jahr+"</option>");
                 i++;
                 jahr++;
         }
}

function yearOptions1() {
         var i=0;
         var datum = new Date();
	var jahr = datum.getFullYear();
         var month = datum.getMonth() + 1;
         var tag = datum.getDate();
	while (i<6){
         	if(month==12 && tag==31){
                    document.write("<option value="+(jahr+1)+">"+(jahr+1)+"</option>");
                 }
                 else{
         		document.write("<option value="+jahr+">"+jahr+"</option>");
                 }
                 i++;
                 jahr++;
         }
}

function dayOptions() {
         var i=1;
         var datum = new Date();
         var tag = datum.getDate();
	while (i<32){
                 if(i==tag){
                      document.write("<option value="+i+" selected>"+i+"</option>");
                 }
                 else{
                 	document.write("<option value="+i+">"+i+"</option>");
                 }
                 i++;
         }
}

function dayOptions1() {
         var i=1;
         var datum = new Date();
         var month = datum.getMonth() + 1;
         var tag = datum.getDate();
	while (i<32){
                 if((month==1||month==3||month==5||month==7||month==8||month==10||month==12)&&tag==31&&i==1){
                      document.write("<option value="+i+" selected>"+i+"</option>");
                 }
                 else if((month==2||month==4||month==6||month==9||month==11)&&tag==30&&i==1){
                      document.write("<option value="+i+" selected>"+i+"</option>");
                 }
                 else if((month==1||month==3||month==5||month==7||month==8||month==10||month==12)&&tag!=31&&i==(tag+1)){
                      document.write("<option value="+i+" selected>"+i+"</option>");
                 }
                 else if((month==2||month==4||month==6||month==9||month==11)&&tag!=30&&i==(tag+1)){
                      document.write("<option value="+i+" selected>"+i+"</option>");
                 }
                 else{
                 	document.write("<option value="+i+">"+i+"</option>");
                 }
                 i++;
         }
}

function monthOptions() {
         var i=1;
         var monatsname = new Array("Januar", "Februar", "M&auml;rz", "April", "Mai", "Juni", "Juli",
                          "August", "September", "Oktober", "November", "Dezember");
         var datum = new Date();
         var month = datum.getMonth() + 1;
	while (i<13){
                 if(i==month){
                 	document.write('<option value="'+i+'/" selected>'+monatsname[i-1]+'</option>');
                 }
                 else{
                     	document.write('<option value="'+i+'/">'+monatsname[i-1]+'</option>');
                 }
                 i++;
         }
}

function monthOptions1() {
         var i=1;
         var monatsname = new Array("Januar", "Februar", "M&auml;rz", "April", "Mai", "Juni", "Juli",
                          "August", "September", "Oktober", "November", "Dezember");
         var datum = new Date();
         var month = datum.getMonth() + 1;
         var tag = datum.getDate();
	while (i<13){
                 if((month==12)&&tag==31&&i==1){
                      document.write('<option value="'+i+'/" selected>'+monatsname[i-1]+'</option>');
                 }
                 else if((month==1||month==3||month==5||month==7||month==8||month==10||month==12)&&tag==31&&i==(month+1)){
                      document.write('<option value="'+i+'/" selected>'+monatsname[i-1]+'</option>');
                 }
                 else if((month==2||month==4||month==6||month==9||month==11)&&tag==30&&i==(month+1)){
                      document.write('<option value="'+i+'/" selected>'+monatsname[i-1]+'</option>');
                 }
                 else if((month==1||month==3||month==5||month==7||month==8||month==10||month==12)&&tag!=31&&i==month){
                      document.write('<option value="'+i+'/" selected>'+monatsname[i-1]+'</option>');
                 }
                 else if((month==2||month==4||month==6||month==9||month==11)&&tag!=30&&i==month){
                      document.write('<option value="'+i+'/" selected>'+monatsname[i-1]+'</option>');
                 }
                 else{
                     	document.write('<option value="'+i+'/">'+monatsname[i-1]+'</option>');
                 }
                 i++;
         }
}

function monthOptions2() {
         var i=1;
         var monatsname = new Array("January", "February", "March", "April", "May", "June", "July",
                          "August", "September", "October", "November", "December");
         var datum = new Date();
         var month = datum.getMonth() + 1;
	while (i<13){
                 if(i==month){
                 	document.write('<option value="'+i+'/" selected>'+monatsname[i-1]+'</option>');
                 }
                 else{
                     	document.write('<option value="'+i+'/">'+monatsname[i-1]+'</option>');
                 }
                 i++;
         }
}

function monthOptions3() {
         var i=1;
         var monatsname = new Array("January", "February", "March", "April", "May", "June", "July",
                          "August", "September", "October", "November", "December");
         var datum = new Date();
         var month = datum.getMonth() + 1;
         var tag = datum.getDate();
	while (i<13){
                 if((month==12)&&tag==31&&i==1){
                      document.write('<option value="'+i+'/" selected>'+monatsname[i-1]+'</option>');
                 }
                 else if((month==1||month==3||month==5||month==7||month==8||month==10||month==12)&&tag==31&&i==(month+1)){
                      document.write('<option value="'+i+'/" selected>'+monatsname[i-1]+'</option>');
                 }
                 else if((month==2||month==4||month==6||month==9||month==11)&&tag==30&&i==(month+1)){
                      document.write('<option value="'+i+'/" selected>'+monatsname[i-1]+'</option>');
                 }
                 else if((month==1||month==3||month==5||month==7||month==8||month==10||month==12)&&tag!=31&&i==month){
                      document.write('<option value="'+i+'/" selected>'+monatsname[i-1]+'</option>');
                 }
                 else if((month==2||month==4||month==6||month==9||month==11)&&tag!=30&&i==month){
                      document.write('<option value="'+i+'/" selected>'+monatsname[i-1]+'</option>');
                 }
                 else{
                     	document.write('<option value="'+i+'/">'+monatsname[i-1]+'</option>');
                 }
                 i++;
         }
}

function chkFormular() {
	error=0;
         if(document.quickbuchung.departureYear.selectedIndex<document.quickbuchung.arrivalYear.selectedIndex)
         {
         	error++;
         }
         else if(document.quickbuchung.departureYear.selectedIndex=document.quickbuchung.arrivalYear.selectedIndex)
         {
                 if(document.quickbuchung.departureMonth.selectedIndex<document.quickbuchung.arrivalMonth.selectedIndex)
         	{
         		error++;
         	}
                 else if(document.quickbuchung.departureMonth.selectedIndex=document.quickbuchung.arrivalMonth.selectedIndex)
                 {
                       if(document.quickbuchung.departureDate.selectedIndex<document.quickbuchung.arrivalDate.selectedIndex)
         		{
         			error++;
         		}
                 }
         }

         if (error == 0)
         {
         adults=document.quickbuchung.adults.value;
         childs=document.quickbuchung.childs.value;
         arrival=document.quickbuchung.arrivalDate.value+'/'+document.quickbuchung.arrivalMonth.value+document.quickbuchung.arrivalYear.value;
         departure=document.quickbuchung.departureDate.value+'/'+document.quickbuchung.departureMonth.value+document.quickbuchung.departureYear.value;

         document.quickbuchung.action='https://reservations.synxis.com/LBE/rez.aspx?hotel=12435&Chain=5154&Dest=mandala&locale=de-DE&src=mandalahotel&arrive='+arrival+'&depart='+departure+'&Adult='+adults+'&Child='+childs+'&step=2';
         document.quickbuchung.submit();
         }
         else
         {
         	alert("Ihr Abreisedatum liegt zeitlich vor dem Ankunftsdatum. Bitte überprüfen Sie Ihre Angaben.");
         }
}

function chkFormularSuites() {
	error=0;
         if(document.quickbuchung.departureYear.selectedIndex<document.quickbuchung.arrivalYear.selectedIndex)
         {
         	error++;
         }
         else if(document.quickbuchung.departureYear.selectedIndex=document.quickbuchung.arrivalYear.selectedIndex)
         {
                 if(document.quickbuchung.departureMonth.selectedIndex<document.quickbuchung.arrivalMonth.selectedIndex)
         	{
         		error++;
         	}
                 else if(document.quickbuchung.departureMonth.selectedIndex=document.quickbuchung.arrivalMonth.selectedIndex)
                 {
                       if(document.quickbuchung.departureDate.selectedIndex<document.quickbuchung.arrivalDate.selectedIndex)
         		{
         			error++;
         		}
                 }
         }

         if (error == 0)
         {
         adults=document.quickbuchung.adults.value;
         childs=document.quickbuchung.childs.value;
         arrival=document.quickbuchung.arrivalDate.value+'/'+document.quickbuchung.arrivalMonth.value+document.quickbuchung.arrivalYear.value;
         departure=document.quickbuchung.departureDate.value+'/'+document.quickbuchung.departureMonth.value+document.quickbuchung.departureYear.value;

         document.quickbuchung.action='https://reservations.synxis.com/LBE/rez.aspx?hotel=12434&Chain=5154&Dest=mandala&locale=de-DE&src=mandalasuites&arrive='+arrival+'&depart='+departure+'&Adult='+adults+'&Child='+childs+'&step=2';
         document.quickbuchung.submit();
         }
         else
         {
         	alert("Your departure is before your arrival. Please check your entries.");
         }
}

function chkFormularEn() {
	error=0;
         if(document.quickbuchung.departureYear.selectedIndex<document.quickbuchung.arrivalYear.selectedIndex)
         {
         	error++;
         }
         else if(document.quickbuchung.departureYear.selectedIndex=document.quickbuchung.arrivalYear.selectedIndex)
         {
                 if(document.quickbuchung.departureMonth.selectedIndex<document.quickbuchung.arrivalMonth.selectedIndex)
         	{
         		error++;
         	}
                 else if(document.quickbuchung.departureMonth.selectedIndex=document.quickbuchung.arrivalMonth.selectedIndex)
                 {
                       if(document.quickbuchung.departureDate.selectedIndex<document.quickbuchung.arrivalDate.selectedIndex)
         		{
         			error++;
         		}
                 }
         }

         if (error == 0)
         {
         adults=document.quickbuchung.adults.value;
         childs=document.quickbuchung.childs.value;
         arrival=document.quickbuchung.arrivalMonth.value+document.quickbuchung.arrivalDate.value+'/'+document.quickbuchung.arrivalYear.value;
         departure=document.quickbuchung.departureMonth.value+document.quickbuchung.departureDate.value+'/'+document.quickbuchung.departureYear.value;

         document.quickbuchung.action='https://reservations.synxis.com/LBE/rez.aspx?hotel=12435&Chain=5154&Dest=mandala&locale=en-US&src=mandalahotel&arrive='+arrival+'&depart='+departure+'&Adult='+adults+'&Child='+childs+'&step=2';
         document.quickbuchung.submit();
         }
         else
         {
         	alert("Your departure is before your arrival. Please check your entries.");
         }
}

function chkFormularSuitesEn() {
	error=0;
         if(document.quickbuchung.departureYear.selectedIndex<document.quickbuchung.arrivalYear.selectedIndex)
         {
         	error++;
         }
         else if(document.quickbuchung.departureYear.selectedIndex=document.quickbuchung.arrivalYear.selectedIndex)
         {
                 if(document.quickbuchung.departureMonth.selectedIndex<document.quickbuchung.arrivalMonth.selectedIndex)
         	{
         		error++;
         	}
                 else if(document.quickbuchung.departureMonth.selectedIndex=document.quickbuchung.arrivalMonth.selectedIndex)
                 {
                       if(document.quickbuchung.departureDate.selectedIndex<document.quickbuchung.arrivalDate.selectedIndex)
         		{
         			error++;
         		}
                 }
         }

         if (error == 0)
         {
         adults=document.quickbuchung.adults.value;
         childs=document.quickbuchung.childs.value;
         arrival=document.quickbuchung.arrivalMonth.value+document.quickbuchung.arrivalDate.value+'/'+document.quickbuchung.arrivalYear.value;
         departure=document.quickbuchung.departureMonth.value+document.quickbuchung.departureDate.value+'/'+document.quickbuchung.departureYear.value;

         document.quickbuchung.action='https://reservations.synxis.com/LBE/rez.aspx?hotel=12434&Chain=5154&Dest=mandala&locale=en-US&src=mandalasuites&arrive='+arrival+'&depart='+departure+'&Adult='+adults+'&Child='+childs+'&step=2';
         document.quickbuchung.submit();
         }
         else
         {
         	alert("Ihr Abreisedatum liegt zeitlich vor dem Ankunftsdatum. Bitte überprüfen Sie Ihre Angaben.");
         }
}

function selectDay() {
         if (document.quickbuchung.arrivalDate.selectedIndex != 30)
         {
    		document.quickbuchung.departureDate.selectedIndex = document.quickbuchung.arrivalDate.selectedIndex+1;
                 document.quickbuchung.departureMonth.selectedIndex = document.quickbuchung.arrivalMonth.selectedIndex;
                 document.quickbuchung.departureYear.selectedIndex = document.quickbuchung.arrivalYear.selectedIndex;
         }
         else
         {
         	document.quickbuchung.departureDate.selectedIndex = 0;
                 if (document.quickbuchung.arrivalMonth.selectedIndex != 11){
                 document.quickbuchung.departureMonth.selectedIndex = document.quickbuchung.arrivalMonth.selectedIndex+1;
                 }
                 else {document.quickbuchung.departureMonth.selectedIndex=0;}
         }
}

function selectMonth() {
         if (document.quickbuchung.arrivalMonth.selectedIndex != 11 && document.quickbuchung.arrivalDate.selectedIndex == 30)
         {
    		document.quickbuchung.departureMonth.selectedIndex = document.quickbuchung.arrivalMonth.selectedIndex+1;
                 document.quickbuchung.departureYear.selectedIndex = document.quickbuchung.arrivalYear.selectedIndex;
         }
         else if ((document.quickbuchung.arrivalMonth.selectedIndex != 11 || document.quickbuchung.arrivalMonth.selectedIndex == 11) && document.quickbuchung.arrivalDate.selectedIndex != 30)
         {
    		document.quickbuchung.departureMonth.selectedIndex = document.quickbuchung.arrivalMonth.selectedIndex;
                 document.quickbuchung.departureYear.selectedIndex = document.quickbuchung.arrivalYear.selectedIndex;
         }
         else if (document.quickbuchung.arrivalMonth.selectedIndex == 11 && document.quickbuchung.arrivalDate.selectedIndex == 30)
         {
         	document.quickbuchung.departureMonth.selectedIndex = 0;
                 if (document.quickbuchung.departureYear.options[document.quickbuchung.arrivalYear.selectedIndex+1])
	         {
	                 document.quickbuchung.departureYear.selectedIndex = document.quickbuchung.arrivalYear.selectedIndex+1;
	         }
         }
}

function selectYear() {
         if(document.quickbuchung.arrivalDate.selectedIndex == 30 && document.quickbuchung.arrivalMonth.selectedIndex == 11)
	{
	         if (document.quickbuchung.departureYear.options[document.quickbuchung.arrivalYear.selectedIndex+1])
	         {
	                 document.quickbuchung.departureYear.selectedIndex = document.quickbuchung.arrivalYear.selectedIndex+1;
	         }
         }
         else {
         	document.quickbuchung.departureYear.selectedIndex = document.quickbuchung.arrivalYear.selectedIndex;
         }
}

function selectDayBooking() {
         
		 var option=document.anfrage.aMY.selectedIndex;
		 var aMY=document.anfrage.aMY.options[option].value;//selected option of arrival month and year
		 var my = aMY.split('-'); // selected Month and Year are saved in array my[]
		 var nextMonth = (++my[0])+'-'+my[1]; // Option for next month of the same year
		 var nextYear = '1-'+(++my[1]); // if it's december, january of the next year 
		 
		 //find out, if selected year is a leap year
		 jahr = --my[1];
		 //SJahr = Jahr%4;
		 //SHJahr = Jahr%100;
		 //S4Jahr = Jahr%400;
		 //STag = ((S4Jahr == "0") ? (1) : ((SHJahr == "0") ? (0) : ((SJahr == "0") ? (1) : (0))));
		 STag = ((jahr % 4 == 0 && jahr % 100 != 0)  || jahr % 400 == 0);
		 		 
		 if(my[0]==5||my[0]==7||my[0]==10||my[0]==12){
		 	var dayCount=29;
		 }
		 else if (my[0]==3&&STag!=1){//feb without leap day
		 	var dayCount=27;
		 }
		 else if (my[0]==3&&STag==1){//feb with leap day
		 	var dayCount=28;
		 }
		 else{
		 	var dayCount=30;
		 }
		 
		 if(document.anfrage.aD.selectedIndex > dayCount)
		 {
		 	alert("Dieser Monat hat nicht so viele Tage.\nWir haben das Datum auf den letzten Tag des Monats abgeändert.")
			document.anfrage.aD.selectedIndex=dayCount;
		 }
		 if (document.anfrage.aD.selectedIndex < dayCount) // if it's not the last day of month
         {
    		document.anfrage.dD.selectedIndex = document.anfrage.aD.selectedIndex+1; //Day +1
            for(var i=0; i<document.anfrage.dMY.length; ++i){ //search and select the same month and year as in arrival date
					 if(document.anfrage.dMY.options[i].value==aMY){
						document.anfrage.dMY.options[i].selected=true; 
					 }
			}
         }
         else if(document.anfrage.aD.selectedIndex == dayCount)//if it's the 31st
         {
			document.anfrage.dD.selectedIndex = 0; //day is the 1st
			if (my[0]!=13){//if it's not december
				for(var i=0; i<document.anfrage.dMY.length; ++i){//select the next month of the same year
					 if(document.anfrage.dMY.options[i].value==nextMonth){
						document.anfrage.dMY.options[i].selected=true; 
					 }
				}
			}
			else{//if it's december
				for(var i=0; i<document.anfrage.dMY.length; ++i){//select january of the next year
					 if(document.anfrage.dMY.options[i].value==nextYear){
						document.anfrage.dMY.options[i].selected=true; 
					 }
				}
			}
         }
}