function checkDestination(l){
  if(document.theForm.country.value == 0
    || document.theForm.city.value == 0){
	if(l==0){
		alert('Wählen Sie bitte ein Reiseziel aus.');
	}else{
		alert('Please choose a destination.');
	}
	return false;
	}else{
    return true;
  }
}
 
 function populateCitySelect( country ) {
  if ( country.length == 0 ) {
    document.theForm.city.length = 1;
    document.theForm.city.options[0] = new Option('Land:');
    document.theForm.city.options[0].value = '';

    return;
  }

    if ( country == 'Holland' ) {
      newcountry = 'Netherlands';
    }
    if ( country == 'Britain' ) {
      newcountry = 'England';
    }
  newOptions = eval(country+'Array');

  document.theForm.city.length = 1;
  document.theForm.city.options[0] = new Option('Hostel/Hotel :');
  document.theForm.city.options[0].value = '';

  document.theForm.city.options[0].selected = true;

  for ( i=0; i<newOptions.length; i++ ) {
    document.theForm.city.length++;
    thisEntry = newOptions[i];
    newOption = new Option( thisEntry[1] );
    newOption.value = thisEntry[0];
    document.theForm.city.options[i+1] = newOption;
  }
}

var EnglandArray = new Array (
  new Array( "lond", "LONDON" ),
  new Array( "sout", " - South Kensington" )
);
// Hier bitte die Adressen eintragen
var GermanyArray = new Array (
  new Array( "berlin", "BERLIN" ),
  new Array( "sene", " - Senefelder Platz" ),
  new Array( "hall", " - Hallesches Ufer" ),
  new Array( "temp", " - Tempelhofer Ufer" ),
  new Array( "mein", " - Meininger Str." ),
  new Array( "colo", "COLOGNE" ),
  new Array( "enge", " - Engelbertstr." ),
  new Array( "muni", "MUNICH" ),
  new Array( "land", " - Landsberger Str." )

);
var AustriaArray = new Array (
  new Array( "vien", "VIENNA" ),
  new Array( "colu", " - Columbusgasse" )
);

var DeutschlandArray = new Array (
  new Array( "berlin", "BERLIN" ),
  new Array( "sene", " - Senefelder Platz" ),
  new Array( "hall", " - Hallesches Ufer" ),
  new Array( "temp", " - Tempelhofer Ufer" ),
  new Array( "mein", " - Meininger Str." ),
  new Array( "colo", "KÖLN" ),
  new Array( "enge", " - Engelbertstr." ),
  new Array( "muni", "MÜNCHEN" ),
  new Array( "land", " - Landsberger Str." )

);
var OesterreichArray = new Array (
  new Array( "vien", "WIEN" ),
  new Array( "colu", " - Columbusgasse" )
);


function makeValidDate() {
  //Ankunft
  year = document.theForm.year_a.options[ document.theForm.year_a.selectedIndex ].value;
  month = document.theForm.month_a.options[ document.theForm.month_a.selectedIndex ].value;
  day = document.theForm.day_a.options[ document.theForm.day_a.selectedIndex ].value;
  
  
  
  maxDay = 31;
  if ( month == 4 || month == 6 || month == 9 || month == 11 ) {
    maxDay = 30;
  } else if ( month == 2 ) {
    if ( year%100 != 0 && year%4 == 0 ) {
      maxDay = 29;
    } else {
      maxDay = 28;
    }
  }
  document.theForm.day_a.selectedIndex = Math.min(day, maxDay)-1;
  
  //Abreise
  year = document.theForm.year_d.options[ document.theForm.year_d.selectedIndex ].value;
  month = document.theForm.month_d.options[ document.theForm.month_d.selectedIndex ].value;
  day = document.theForm.day_d.options[ document.theForm.day_d.selectedIndex ].value;
  maxDay = 31;
  if ( month == 4 || month == 6 || month == 9 || month == 11 ) {
    maxDay = 30;
  } else if ( month == 2 ) {
    if ( year%100 != 0 && year%4 == 0 ) {
      maxDay = 29;
    } else {
      maxDay = 28;
    }
  }
  document.theForm.day_d.selectedIndex = Math.min(day, maxDay)-1;
  
}


var monthLength = new Array(31,28,31,30,31,30,31,31,30,31,30,31);

/*function checkDate(){
  //Anreise
  var day = parseInt(document.theForm.day_a.options[ document.theForm.day_a.selectedIndex ].value);
  var month = parseInt(document.theForm.month_a.options[ document.theForm.month_a.selectedIndex ].value);
  var year = parseInt(document.theForm.year_a.options[ document.theForm.year_a.selectedIndex ].value);

  if (!day || !month || !year)
    return false;

  if (year/4 == parseInt(year/4))
    monthLength[1] = 29;

  if (day > monthLength[month-1])
    return false;

  monthLength[1] = 28;

  var now = new Date();
  now = now.getTime(); //NN3

  var dateToCheck = new Date();
  dateToCheck.setYear(year);
  dateToCheck.setMonth(month-1);
  dateToCheck.setDate(day);
  var checkDate = dateToCheck.getTime();

  var futureDate = (now < checkDate);
  var pastDate_a = (now > checkDate);

  //Abreise
  var day = parseInt(document.theForm.day_d.options[ document.theForm.day_d.selectedIndex ].value);
  var month = parseInt(document.theForm.month_d.options[ document.theForm.month_d.selectedIndex ].value);
  var year = parseInt(document.theForm.year_d.options[ document.theForm.year_d.selectedIndex ].value);

  if (!day || !month || !year)
    return false;

  if (year/4 == parseInt(year/4))
    monthLength[1] = 29;

  if (day > monthLength[month-1])
    return false;

  monthLength[1] = 28;

  var now = new Date();
  now = now.getTime(); //NN3

  var dateToCheck = new Date();
  dateToCheck.setYear(year);
  dateToCheck.setMonth(month-1);
  dateToCheck.setDate(day);
  var checkDate = dateToCheck.getTime();

  var futureDate = (now < checkDate);
  var pastDate_d = (now > checkDate);
  
  if(pastDate_a || pastDate_d)
  {
    alert('Bitte Geben Sie ein Datum nach dem heutigen ein. Vielen Dank.');
  }
  else
  {
    document.theForm.Submit.value=1;
    document.theForm.submit();
  }
  
}*/


 function isBrowserSupp() {
// ****************************************************************
// *    Author: Geraldine Healy         Date:   25/08/1998
// *    Description: Checks if browser is Netscape 2.0 since the options 
// *                            array properties don't work with Netscape 2.0x
// ****************************************************************

    // Get the version of the browser
    version =  parseFloat( navigator.appVersion );

    if ( ( version >= 2.0 ) && ( version < 2.1 ) && ( navigator.appName.indexOf( "Netscape" ) != -1 ) ) {
        return false;
    }
    else {
        return true;
    }                  
}


function isLeapYear(yrStr)
{
// ****************************************************************
// *    Author: Geraldine Healy         Date:   25/08/1998
// *    Description:    Checks if Year selected is a leap year
// ****************************************************************
var leapYear=false;
// every fourth year is a leap year
if ((parseInt(yrStr, 10)%4) == 0)
        {
        leapYear=true;
        }
return leapYear;
}

function getDaysInMonth(mthIdx, YrStr)
// ****************************************************************
// *    Author: Geraldine Healy         Date:   25/08/1998
// *    Description:    Retrieves the number of days in a given month
// ****************************************************************
{
//Default number of days in a month is 31
var maxDays=31
// expect Feb. 
if (mthIdx==2) 
        {
        if (isLeapYear(YrStr))
                {
                maxDays=29;
                }
        else 
                {
                maxDays=28;
                }
        }
// All the rest of the months have 30 days
if (mthIdx==4 || mthIdx==6 || mthIdx==9 || mthIdx==11)
        {
        maxDays=30;
        }
return maxDays;
}


function adjustDate(mthIdx, Dt, Yr) 
// ****************************************************************
// *    Author: Geraldine Healy         Date:   25/08/1998
// *    Description:    Adjusts the format of the Date
// ****************************************************************
{
var value=0;            
var numDays=getDaysInMonth(mthIdx, Yr.options[Yr.options.selectedIndex].value);

if (mthIdx==2) 
        {
        if (Dt.options.selectedIndex < numDays)
                {
                return 0;
                }
        else 
                {
                //check for leap year
                Dt.options.selectedIndex=numDays;
                if (numDays==29)
                        {
                        return 99;
                        }
                else 
                        {
                        return 1;
                        }
                }
        }
if (Dt.options.selectedIndex < numDays)
        {
        value=0;
        }
else 
        {
        if (Dt.options.selectedIndex > numDays)
                {
                Dt.options.selectedIndex;
                value=3;
                }
        else 
                {
                //index is 31 or 30
                value=2;
                }
        }
return value;
}



function parseMonth(mth, inM)
// ****************************************************************
// *    Author: Geraldine Healy         Date:   25/08/1998
// *    Description:    Parses a string and returns a month value
// ****************************************************************
{
var i=1;
var retval =1;
for (i=1;i<=12;i++)
        {
        if (mth == inM.options[i].value)
                {
                retval=i;       
                break;
                }       
        }
        return retval;
}

function parseDay(day, inD)
// ****************************************************************
// *    Author: Geraldine Healy         Date:   25/08/1998
// *    Description:    Parses a string and returns a day value
// ****************************************************************
{
var i=1;
var retval =1;
for (i=1;i<=31;i++)
        {
        if (day == inD.options[i].value)
                {
                retval=i;       
                break;
                }       
        }
return retval;
}

function parseYear(year, inY)
// ****************************************************************
// *    Author: Geraldine Healy         Date:   25/08/1998
// *    Description:    Parses a string and returns a year value
// ****************************************************************
{
var retval=0;
var i=0;
     for (i=0; i<=5; i++)
     {
   
        if (year == inY.options[i].value)
                {
                retval=i;       
                break;
                }       
     }
return retval;
}

//Calendar Section
//calculation functions
function nextMonth(month)
{
if (month==12)
        {
        return 1;
        }
else
        {
        return (month+1);
        }
}


function prevMonth(month) 
{
var prevMonth = (month-1)
if (month==1)
        {
        prevMonth = 12;
        }
return prevMonth
}

function changeYear(direction,month,year)
{
var theYear = year
if (direction=="next")
        {
        if (month == 12)
                {
                theYear = (year+1)
                }
        }
if (direction=="prev")
        {
        if (month == 1)
                {
                theYear = (year-1)
                }
        }
return theYear
}


function createCalendar(month,year,io,dayVal,lang) 
{
if (!isBrowserSupp())
        {
        alert("Your browser is outdated and does not support this feature")
        return;
        }
if (navigator.appVersion.indexOf("Mac",0) != -1) 
        {
        calendarWindow = window.open("","Calendar","width=165,height=200,resizable=yes,scrollbars=no");
        } 
else 
        {
        calendarWindow = window.open("","Calendar","width=165,height=200,resizable=yes,scrollbars=no");
        }
        var mthIdx = month.options.selectedIndex+1
        //var mthVal = month.options[mthIdx].value
		var mthVal = mthIdx
        var yearVal = year.options[year.options.selectedIndex].value
			
        //call the function to populate the window
        generateCalendar(calendarWindow,mthVal,yearVal,io,dayVal,lang)
}


//generates the meat of the calendar
function generateCalendar(target,month,year,io,dayVal,lang)
// ****************************************************************
// *    Author: Geraldine Healy         Date:   25/08/1998
// *    Description:    generates the contents of the calender window
// **************************************************************** 
{
if (!isBrowserSupp())
        {
        return;
        }       
if(lang=="en"){
	var monthName = new Array ("January","February","March","April","May","June","July","August","September","October","November","December")
}else{
	var monthName = new Array ("Januar","Februar","März","April","Mai","Juni","Juli","August","September","Oktober","November","Dezember")
}

//begin table for calendar
target.document.open()
calendar = "<html><head><title>calendar</title></head>"
calendar +="<link rel=\"stylesheet\" href=\"http://www.pfefferbett.de/fileadmin/css/calendar.css\" type=\"text/css\">"
calendar +="<body bgcolor=ffffff link='#000080'>"
calendar +="<table border=0 cellspacing=1 cellpadding=3 width=105 bgcolor=ffffff>"
calendar +="<tr valign=top>"

//The parseInt function parses the string argument as a signed decimal integer. 
var mthIdx = parseInt(month);
var endday = getDaysInMonth(mthIdx, year)

//month header
calendar +="<td colspan=7 align=center class='JSCalendarTitle'>"
var index = (mthIdx-1)
calendar +="<b><span class='BElarge'>" + monthName[index] + " " + year + "</span></b></td></tr>"
calendar +="</tr>"

//writes in the day of the week labels
calendar +="<tr align=center>"

if(lang=="en"){
	calendar +="<td width=15 class='JSCalendarWeek'><span class='BEsmall'>&nbsp;<b>M</b></font></td>"
	calendar +="<td width=15 class='JSCalendarWeek'><span class='BEsmall'>&nbsp;<b>T</b></font></td>"
	calendar +="<td width=15 class='JSCalendarWeek'><span class='BEsmall'>&nbsp;<b>W</b></font></td>"
	calendar +="<td width=15 class='JSCalendarWeek'><span class='BEsmall'>&nbsp;<b>T</b></font></td>"
	calendar +="<td width=15 class='JSCalendarWeek'><span class='BEsmall'>&nbsp;<b>F</b></font></td>"
	calendar +="<td width=15 class='JSCalendarWeekend'><span class='BEsmall'>&nbsp;<b>S</b></font></td>"
	calendar +="<td width=15 class='JSCalendarWeekend'><span class='BEsmall'>&nbsp;<b>S</b></font></td>"
}else{	
	calendar +="<td width=15 class='JSCalendarWeek'><span class='BEsmall'>&nbsp;<b>M</b></font></td>"
	calendar +="<td width=15 class='JSCalendarWeek'><span class='BEsmall'>&nbsp;<b>D</b></font></td>"
	calendar +="<td width=15 class='JSCalendarWeek'><span class='BEsmall'>&nbsp;<b>M</b></font></td>"
	calendar +="<td width=15 class='JSCalendarWeek'><span class='BEsmall'>&nbsp;<b>D</b></font></td>"
	calendar +="<td width=15 class='JSCalendarWeek'><span class='BEsmall'>&nbsp;<b>F</b></font></td>"
	calendar +="<td width=15 class='JSCalendarWeekend'><span class='BEsmall'>&nbsp;<b>S</b></font></td>"
	calendar +="<td width=15 class='JSCalendarWeekend'><span class='BEsmall'>&nbsp;<b>S</b></font></td>"
}
calendar +="</tr>"

wholeDate = month + "/01/" + year
thedate = new Date(wholeDate)
firstDay = thedate.getDay()

selectedmonth = mthIdx;
var today = new Date();
var thisyear = today.getYear() + 1900;
selectedyear = year

var lastDay = (endday + firstDay+1)
if(firstDay==0){
	var lastCalspace = 42
}else{
	var lastCalspace = 43
}


var NoDays = (lastDay - (firstDay + 1))
var TotalDaysFilled = NoDays + firstDay;


if(firstDay==0) {
	firstDay=7;
	var NoDays = (lastDay - ( 1));
	var TotalDaysFilled = NoDays + firstDay;
	
	
	
}

calendar +="<tr>"
for (var i = 1; i <= lastCalspace; i++)
        {
		        if (i <= firstDay && i !=1)
                {
                // 'empty' boxes prior to first day
				

                calendar +="<td class='JSCalendarDays'><img src='images/trans.gif' height=1 width=1></td>"
                }
        if (i > firstDay && i <= TotalDaysFilled)
                {
				if(dayVal=="day_a"){
                	// enter date number
				
                	calendar +="<td align=center class='JSCalendarDays'><a href='JavaScript:self.close();opener.closeCalendar"+io+"("+(i-firstDay) + ");' class='calendar'> "+(i-firstDay)+"</a></td>"
				}else{
                	// enter date number
					
                	calendar +="<td align=center class='JSCalendarDays'><a href='JavaScript:self.close();opener.closeCalendar_d"+io+"("+(i-firstDay) + ");' class='calendar'> "+(i-firstDay)+"</a></td>"
				
				}
				}
		if (i > TotalDaysFilled && i <= lastCalspace) 
				{
				// 'empty' boxes after TotalDaysFilled
				
				calendar +="<td class='JSCalendarDays'><img src='images/trans.gif' height=12 width=1></td>"
				}
        //must start new row after each week
        if(firstDay==0){
			if(i % 7 == 0 &&  i != lastCalspace && i !=1) {
                calendar +="</tr>"
				calendar +="<tr>"
                }
		}else if (i % 7 == 1 &&  i != lastCalspace && i !=1)
                {
                calendar +="</tr>"
				calendar +="<tr>"
                }
        }
calendar +="</tr>"

//prev month - next month controls table
calendar +="<tr><td colspan=7 align=center class='JSCalendarTitle'>"

//next month and previous month buttons
var goPrevMonth = prevMonth(mthIdx)
var goNextMonth = nextMonth(mthIdx)
var nextYear = changeYear("next",parseInt(month),parseInt(year))
var prevYear = changeYear("prev",parseInt(month),parseInt(year))

if(navigator.userAgent.indexOf('MSIE',0) != -1)
        {
		calendar +="<table cellpadding=0 cellspacing=0 border=0 width=100%>"
        calendar +="<tr><td align=left class='JSCalendarTitle'><a href='javascript:opener.generateCalendar(self,"+goPrevMonth+","+prevYear+",\""+io+"\",\""+dayVal+"\",\""+lang+"\")' class='calcontrol'>« Prev</a></td>"
        calendar +="<td align=right class='JSCalendarTitle'><a href='javascript:opener.generateCalendar(self,"+goNextMonth+","+nextYear+",\""+io+"\",\""+dayVal+"\",\""+lang+"\")' class='calcontrol'>Next »</a></td></tr>"
		calendar +="</table>"
		calendar +="</td></tr>"
		calendar +="</table></body></html>"
        target.document.close()
        }
else
        {
		calendar +="<table cellpadding=0 cellspacing=0 border=0 width=100%>"
        calendar +="<fo"+"rm><tr><td align=left class='JSCalendarTitle'><input type='button' value=' < ' onClick='document.clear();opener.generateCalendar(opener.calendarWindow,"+goPrevMonth+","+prevYear+",\""+io+"\",\""+dayVal+"\",\""+lang+"\")'></td>"
        calendar +="<td align=right class='JSCalendarTitle'><input type='button' value=' > '"+"onClick='document.clear();opener.generateCalendar(opener.calendarWindow,"+goNextMonth+","+nextYear+",\""+io+"\",\""+dayVal+"\",\""+lang+"\")'></td></tr></form>"
		calendar +="</table>"
		calendar +="</td></tr>"
        calendar +="</table></body></html>"
        }
target.document.write(calendar);
target.document.close() 
}

function closeCalendar(day) {
        var yrIdx = parseYear(selectedyear,document.theForm.year_a );

        // Decrement index for day and month, because code assumes 
        // that we have an extra defaultvalue at the start.
		
        document.theForm.month_a.options.selectedIndex=selectedmonth-1;
        document.theForm.year_a.options.selectedIndex= yrIdx;
        document.theForm.day_a.options.selectedIndex=parseInt(day)-1;
		
		checkDate('theForm', '', '');
		
}

function closeCalendar_d(day) {
        var yrIdx = parseYear(selectedyear,document.theForm.year_d );
		
        document.theForm.month_d.options.selectedIndex=selectedmonth-1;
        document.theForm.year_d.options.selectedIndex= yrIdx;
        document.theForm.day_d.options.selectedIndex=parseInt(day)-1;		
		
		//checkDate('theForm', '', '');
		checkNights();
}
 
 
 
  var r = document.referrer;
  var ref = '';
  var rand = Math.random();
  if(r.search(window.location.host) == -1) ref = r;
  blah = new Image();
  blah.src='http://www.reservations.bookhostels.com/includes/thing.php?T=V&S=HOSTEL&N=' + window.location.host + '&R=' + r + '&rand=' + rand;
  halb = new Image();
  halb.src="https://secure.webresint.com/writrak.php?T=V&S=HOSTEL&ChosenCity=&UserID=meininger-hostels.de&ServerName=&N=" + window.location.host + '&R=' + ref + '&rand=' + rand ;

  
  
  // ****************************************************************
// *    Abreisedatum an Anreisedatum anpassen  
// **************************************************************** 
		function getDateElementName (formName, whichDate) {
			var elementName = whichDate;
			if (formName == 'bookingForm') {
				elementName = 'searchBookingForm.'+elementName;
			} else if (formName == 'suggestHotel') {
				elementName = 'suggestHotel.'+elementName;
			}

			return elementName;
		}

		function linkToCalendar (formName, selectNameSuffix, dateType) {
		    
		    
		    document.domain= "meininger-hostels.com";

			var startDateDay = document.forms[formName].elements[getDateElementName(formName,'day_a')+selectNameSuffix].value;
			var startDateMonth = document.forms[formName].elements[getDateElementName(formName,'month_a')+selectNameSuffix].value-1;
			var startDateYear = document.forms[formName].elements[getDateElementName(formName,'year_a')+selectNameSuffix].value;
			var endDateDay = document.forms[formName].elements[getDateElementName(formName,'day_d')+selectNameSuffix].value;
			var endDateMonth = document.forms[formName].elements[getDateElementName(formName,'month_d')+selectNameSuffix].value-1;
			var endDateYear = document.forms[formName].elements[getDateElementName(formName,'year_d')+selectNameSuffix].value;
			var nights = document.forms[formName].elements[getDateElementName(formName,'nights')+selectNameSuffix].value;
			

			var urlPrefix;
			if (document.getElementsByTagName('base')[0] != null) {
			    urlPrefix = document.getElementsByTagName('base')[0].href ;
			} else {
			    urlPrefix = "/";
			}
			
			var paramAllowBackwards = "";
			if (formName == 'suggestHotelForm'){				
				paramAllowBackwards = "&allowBackwards=true";
			}
			var link= urlPrefix+"showCalendar.do;jsessionid=5393F4EC81EB02B744243FC2E3F8C462?clientId=ZGVfX0hSUw--&cid=2-3&activity=setCalendar&day_a="+startDateDay+"&month_a="+startDateMonth+"&year_a="+startDateYear+"&day_d="+endDateDay+"&month_d="+endDateMonth+"&year_d="+endDateYear+"&selectNameSuffix="+selectNameSuffix+"&dateType="+dateType+paramAllowBackwards;

			var fenster = windowOpen(link, 'calendar' , 'menubar=no, toorbar=no, width=198, height=275, scrollbars=no, resizable=no');
			fenster.focus();
		}

		function wday (d, m, y) {
			var tage = new Array(
				'So',
				'Mo',
				'Di',
				'Mi',
				'Do',
				'Fr',
				'Sa'
			);

			if (m < 3) {
				m = Number(m) + 12;
				y = Number(y) - 1;
			}

			w = (Number(y) + Math.floor(y / 4) - Math.floor(y / 100) + Math.floor(y / 400) + Math.floor(2.6 * Number(m) + 1.6) + Number(d)) % 7;

			return tage[w];
		}

		function zeit (d, m, y) {
			var datum = new Date(y, m, d);
			return datum.getTime();
		}

		function initWday (form, which, selectNameSuffix) {
			/*with (document.forms[form]) {
				elements[getDateElementName(form,'day'+which)+selectNameSuffix].value = wday(elements[getDateElementName(form,'day'+which)+selectNameSuffix].value, elements[getDateElementName(form,'month'+which)+selectNameSuffix].value, elements[getDateElementName(form,'year'+which)+selectNameSuffix].value);
			}*/
		}

		function numberOfDaysInMonth (year, indexOfMonth) {
			var month = indexOfMonth+1;
			var days;

			if ((month == 1) || (month == 3) || (month == 5) || (month == 7) || (month == 8) || (month == 10) || (month == 12))
					days = 31;
			else if ((month == 4) || (month == 6) || (month == 9) || (month == 11))
					days = 30;
			else if (month == 2) {
					if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0))
							days = 29;
					else
							days = 28;
			}
			return days;
		}

		function checkNights(){
			if(document.theForm.day_a.options.selectedIndex!=null){
				var start = zeit(document.theForm.day_a.options.selectedIndex, document.theForm.month_a.options.selectedIndex, document.theForm.year_a.options.selectedIndex);
				
				var ende = zeit(document.theForm.day_d.options.selectedIndex, document.theForm.month_d.options.selectedIndex, document.theForm.year_d.options.selectedIndex);
			}else{
				var startYearJS = 2007;
				var startDateDay = document.forms['theForm'].elements[getDateElementName('theForm','day_a')].selectedIndex+1;
				var startDateMonth = document.forms['theForm'].elements[getDateElementName('theForm','month_a')].selectedIndex;
				var startDateYear = document.forms['theForm'].elements[getDateElementName('theForm','year_a')].selectedIndex+startYearJS;
	
				var endDateDay = document.forms['theForm'].elements[getDateElementName('theForm','day_d')].selectedIndex+1;
				var endDateMonth = document.forms['theForm'].elements[getDateElementName('theForm','month_d')].selectedIndex;
				var endDateYear = document.forms['theForm'].elements[getDateElementName('theForm','year_d')].selectedIndex+startYearJS;
			
				var start = zeit(startDateDay, startDateMonth , startDateYear);
				
				var ende = zeit(endDateDay, endDateMonth, endDateYear);
			}
			var startDate = new Date(start);
			var endDate = new Date();	
			
			startDate.setTime(start);
			endDate.setTime(ende);
			
			var anzahl = (endDate - startDate)/(60*60*24*1000);
			
			if(document.theForm.nights.options.selectedIndex!=null){
				document.theForm.nights.options.selectedIndex = anzahl-1;
			}else{
				document.forms['theForm'].elements[getDateElementName('theForm','nights')].selectedIndex = anzahl-1;
			}
			
			return anzahl;
		}
		
		function checkDate (formName, selectNameSuffix, dateType) {		
			
			var goBackwardsAllowed = false;
			var startYearJS = 2008;
			
			if (formName == 'suggestHotelForm'){
				goBackwardsAllowed = true;
				startYearJS = startYearJS - 1;
			}
		
			// values of day fields: 1-31, values of month fields: 1-12
			var startDateDay = document.forms[formName].elements[getDateElementName(formName,'day_a')+selectNameSuffix].selectedIndex+1;
			var startDateMonth = document.forms[formName].elements[getDateElementName(formName,'month_a')+selectNameSuffix].selectedIndex;
			var startDateYear = document.forms[formName].elements[getDateElementName(formName,'year_a')+selectNameSuffix].selectedIndex+startYearJS;

			var endDateDay = document.forms[formName].elements[getDateElementName(formName,'day_d')+selectNameSuffix].selectedIndex+1;
			var endDateMonth = document.forms[formName].elements[getDateElementName(formName,'month_d')+selectNameSuffix].selectedIndex;
			var endDateYear = document.forms[formName].elements[getDateElementName(formName,'year_d')+selectNameSuffix].selectedIndex+startYearJS;
			
			var nights = parseInt(document.forms[formName].elements[getDateElementName(formName,'nights')+selectNameSuffix].value);
			
			if(nights==0){
				nights=1;				
			}

			var start = zeit(startDateDay, startDateMonth , startDateYear);
			var ende = zeit(endDateDay, endDateMonth, endDateYear);
		    var startDate = new Date(start);
			var endDate = new Date();
			var heute = new Date(startYearJS, 8, 19);
			
			var startend = zeit(startDateDay+nights-1, startDateMonth , startDateYear);

            if (startDateDay > numberOfDaysInMonth(startDateYear, startDateMonth)) {
				startDateDay = numberOfDaysInMonth(startDateYear, startDateMonth);
			}

			if (endDateDay > numberOfDaysInMonth(endDateYear, endDateMonth)) {
				endDateDay = numberOfDaysInMonth(endDateYear, endDateMonth);
			}    
                
           	if (start < heute) {
                if ((startDateMonth == heute.getUTCMonth()) && (startDateYear == heute.getUTCFullYear())) {
                    if (startDateMonth == 11) {
                        startDateYear = startDateYear+1;
                        startDateMonth = 0;
                    } else{
                        startDateMonth = startDateMonth+1;
                    }
                } else {
                    startDateYear = startDateYear+1;
                }
                start = zeit(startDateDay, startDateMonth, startDateYear);
            } 
            if (start >= ende) {
				if ('end' == dateType.substr(dateType.length-3, 3)) {

					if(goBackwardsAllowed == true){
						if (startDateYear > endDateYear){
							endDateYear = startDateYear;
						}
						if (((startDateYear == endDateYear) && (startDateMonth >= endDateMonth))){
							endDateMonth = startDateMonth;
							endDateDay = startDateDay+nights;
						}else{
							endDateDay = startDateDay+nights;
						}
						ende = zeit(endDateDay, endDateMonth, endDateYear);
					}else if (startDateMonth == endDateMonth) {						
						if (endDateMonth == 11) {
							endDateYear = endDateYear+1;
							endDateMonth = 0;
						} else{
							endDateMonth = endDateMonth+1;
						}
						endDateDay = startDateDay+nights;
						ende = zeit(endDateDay, endDateMonth, endDateYear);
					}
				} else {
					ende = (60*60*24*1000) + startend;
				}
			}
			if(startDateDay+nights!=endDateDay-1){				
					ende = (60*60*24*1000) + startend;
					
			}
			/*endDateDay = startDateDay+nights;
			ende = zeit(endDateDay, endDateMonth, endDateYear);*/
			
		   	startDate.setTime(start);
		   	endDate.setTime(ende);
			/*document.forms[formName].elements[getDateElementName(formName,'day_a')+selectNameSuffix].selectedIndex = startDate.getDate()-1;
			document.forms[formName].elements[getDateElementName(formName,'month_a')+selectNameSuffix].selectedIndex = startDate.getMonth();
			document.forms[formName].elements[getDateElementName(formName,'year_a')+selectNameSuffix].selectedIndex = startDate.getFullYear()-2009;*/
			document.forms[formName].elements[getDateElementName(formName,'day_d')+selectNameSuffix].selectedIndex = endDate.getDate()-1;
			document.forms[formName].elements[getDateElementName(formName,'month_d')+selectNameSuffix].selectedIndex = endDate.getMonth();
			if(endDate.getFullYear()< startDate.getFullYear()){
				document.forms[formName].elements[getDateElementName(formName,'year_d')+selectNameSuffix].selectedIndex = startDate.getFullYear()-startYearJS-1;
			}else{
				document.forms[formName].elements[getDateElementName(formName,'year_d')+selectNameSuffix].selectedIndex = endDate.getFullYear()-startYearJS;
			}

			/*initWday(formName, 'start', selectNameSuffix);
			initWday(formName, 'end', selectNameSuffix);*/

			if (formName == 'suggestHotelForm'){
				calculateDate();
			}

			return true;
		}