	// default vars
	var minDays = 2;

	// open_window javascript
	w_openwindow = null;
	function open_window(nurl,windowname,width,height, leftPos, topPos, scrollbars, resizable, newwindow)
	{
		if (typeof leftPos == 'undefined' || leftPos < 0) leftPos = (self.screen.width-width-25)/2;
		if (typeof topPos == 'undefined' || topPos < 0) topPos = (self.screen.height-height-25)/2;
		if (typeof newwindow == 'undefined') newwindow = 0;
		scrollbars = typeof scrollbars == 'undefined' ? 'yes' : 'no';
		resizable = typeof resizable == 'undefined' ? 'yes' : 'no';
		if (newwindow)
		 	window.open(nurl, windowname,'width='+width+',height='+height+',left='+leftPos+',top='+topPos+',directories=no,location=no,menubar=no,scrollbars='+scrollbars+',status=yes,toolbar=no,resizable='+resizable);
		else
			w_openwindow = window.open(nurl, windowname,'width='+width+',height='+height+',left='+leftPos+',top='+topPos+',directories=no,location=no,menubar=no,scrollbars='+scrollbars+',status=yes,toolbar=no,resizable='+resizable);
	}

	function open_window_2(nurl,windowname,width,height, leftPos, topPos, scrollbars, resizable, newwindow)
	{
		if (typeof leftPos == 'undefined' || leftPos < 0) leftPos = (self.screen.width-width-25)/2;
		if (typeof topPos == 'undefined' || topPos < 0) topPos = (self.screen.height-height-25)/2;
		if (typeof newwindow == 'undefined') newwindow = 0;
		scrollbars = typeof scrollbars == 'undefined' ? 'yes' : 'no';
		resizable = typeof resizable == 'undefined' ? 'yes' : 'no';
		if (newwindow)
		 	window.open(nurl+document.forms['reservation'].days.value, windowname,'width='+width+',height='+height+',left='+leftPos+',top='+topPos+',directories=no,location=no,menubar=no,scrollbars='+scrollbars+',status=yes,toolbar=no,resizable='+resizable);
		else
			w_openwindow = window.open(nurl+document.forms['reservation'].days.value, windowname,'width='+width+',height='+height+',left='+leftPos+',top='+topPos+',directories=no,location=no,menubar=no,scrollbars='+scrollbars+',status=yes,toolbar=no,resizable='+resizable);
	}


	// -------------------------------------------------------------------------
	// Check Input
	// -------------------------------------------------------------------------
	function numbersonly (myfield, e, dec) {
		var key;
		var keychar;

		if (window.event) {
		   key = window.event.keyCode;
		}
		else if (e) {
		   key = e.which;
		}
		else {
		   return true;
		}

		keychar = String.fromCharCode(key);

		if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27)) {
		   return true;
		}
		else if ((("0123456789.").indexOf(keychar) > -1)) {
			return true;
		}
		else if (dec && (keychar == ".")) {
			myfield.form.elements[dec].focus();
			return false;
		}
		else {
			return false;
		}
	}
	// <input type='text' name='bla' size='20' onKeyPress="return numbersonly(this, event)">

	function dateWithin(beginDate,endDate,checkDate) {
		var b,e,c;
		b = Date.parse(beginDate);
		e = Date.parse(endDate);
		c = Date.parse(checkDate);
		if((c <= e && c >= b)) {
			return true;
		}
		return false;
	}

	function checkMinimumDays(errMessage){

		var doc, err_Messages;
		doc = document.forms['frmReservation'];

		var strSeparatorArray = new Array("-"," ","/",".");
		strDate = doc.startdate.value;
		endDate = doc.enddate.value;



		// lock specific date christmas
		var lock_start = new Array();
		var lock_end = new Array();

		var show_date_1 = new Array();
		var show_date_2 = new Array();

		// lock dates
		/* ACHTUNG: auch im application.php, dort Änderungen bzw. Ergänzungen vornehmen */
		//lock_start[0] = new Date(2009, 11, 18);
		//lock_end[0] = new Date(2010, 0, 3);

		lock_start[0] = new Date(2010, 0, 9);
		lock_end[0] = new Date(2010, 0, 16);

		lock_start[1] = new Date(2010, 0, 22);
		lock_end[1] = new Date(2010, 0, 24);

		lock_start[2] = new Date(2010, 1, 16);
		lock_end[2] = new Date(2010, 2, 02);
		
		// ***
		lock_start[3] = new Date(2010, 2, 6);
		lock_end[3] = new Date(2010, 2, 7);
		
		lock_start[4] = new Date(2010, 2, 11);
		lock_end[4] = new Date(2010, 2, 14);
		
		lock_start[5] = new Date(2010, 2, 20);
		lock_end[5] = new Date(2010, 2, 21);
		
		lock_start[6] = new Date(2010, 2, 27);
		lock_end[6] = new Date(2010, 2, 28);
		

		// show dates
		//show_date_1[0] = new String ("18.12.2009");
		//show_date_2[0] = new String ("03.01.2010");

		show_date_1[0] = new String ("09.01.2010");
		show_date_2[0] = new String ("16.01.2010");

		show_date_1[1] = new String ("22.01.2010");
		show_date_2[1] = new String ("24.01.2010");

		show_date_1[2] = new String ("16.02.2010");
		show_date_2[2] = new String ("02.03.2010");
		
		
		// März Speerung / Jedes Wochenende
		
		
		show_date_1[3] = new String ("06.03.2010");
		show_date_2[3] = new String ("07.03.2010");

		show_date_1[4] = new String ("11.03.2010");
		show_date_2[4] = new String ("14.03.2010");

		show_date_1[5] = new String ("20.03.2010");
		show_date_2[5] = new String ("21.03.2010");

		show_date_1[6] = new String ("27.03.2010");
		show_date_2[6] = new String ("28.03.2010");
		

		var date_loop = 0;

		for(date_loop = 0; date_loop <= (lock_start.length -1); date_loop++)
		{
			myString = new String(doc.startdate.value);
			splitString = myString.split(".")
			sdate = new Date(splitString[2],splitString[1]-1,splitString[0])

			myString = new String(doc.enddate.value);
			splitString = myString.split(".")
			edate = new Date(splitString[2],splitString[1]-1,splitString[0])

			var lock_msg = 'Zum gewünschten Zeitpunkt (#1 - #2) ist das Direktbuchen nicht möglich.\nBitte kontaktieren Sie uns direkt oder benutzen Sie unser Anfrageformular.';

			if ((sdate >= lock_start[date_loop] && sdate <= lock_end[date_loop]) ||
				(edate >= lock_start[date_loop] && edate <= lock_end[date_loop]))

			{
				myString = new String(lock_msg);
				rExp1 = /#1/gi;
				rExp2 = /#2/gi;
				/*
				newString1 = new String ("17.02.2008")
				newString2 = new String ("02.03.2008")
				*/
				results = myString.replace(rExp1, show_date_1[date_loop])
				results = results.replace(rExp2, show_date_2[date_loop])
				alert(results);
				return false;
			}
		}



		err_Messages = errMessage.split("-");

		if(strDate=='' || endDate=='')
		{
			alert(err_Messages[0]);
			return;
		}
		if(strDate=='dd.mm.yyyy' || endDate=='dd.mm.yyyy')
		{
			alert(err_Messages[3]);
			return;
		}

		var isValid = false;

		for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) {
			if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) {
				strDateArray = strDate.split(strSeparatorArray[intElementNr]);
				if (strDateArray.length != 3) {
					isValid = false;
				}
				else {
					strDay = strDateArray[0];
					strMonth = strDateArray[1];
					strYear = strDateArray[2];
					isValid = true;
				}

			}
			else {
				isValid = false;
			}

			if (endDate.indexOf(strSeparatorArray[intElementNr]) != -1) {
				strDateArray = endDate.split(strSeparatorArray[intElementNr]);
				if (strDateArray.length != 3) {
					isValid = false;
				}
				else {
					endDay = strDateArray[0];
					endMonth = strDateArray[1];
					endYear = strDateArray[2];
					isValid = true;
				}

			}
			else {
				isValid = false;
			}


		}

		if(!isValid) {
			alert(err_Messages[0]);
			return;
		}

		var thisDate = new Date();

		var startDate=new Date(strYear, strMonth-1, strDay); //Month is 0-11 in JavaScript
		var endDate=new Date(endYear, endMonth-1, endDay); //Month is 0-11 in JavaScript

		/* Define Lockdown-date */
		var lockdown = new Array(new Date(2007,11,26), new Date(2008,0,05));

		/* Get all possible dates from start to end */
		var error = 0;

		//alert(new Date(2007,11,26));
		for (i = new Date(strYear, strMonth-1, strDay); i <= endDate; i.setDate(i.getDate()+1)) {
			//alert(new Date(2007,11,26).toUTCString());
			if (i.toUTCString() == new Date(2007,11,26).toUTCString() || i.toUTCString() == new Date(2007,11,27).toUTCString() || i.toUTCString() == new Date(2007,11,28).toUTCString() || i.toUTCString() == new Date(2007,11,29).toUTCString() || i.toUTCString() == new Date(2007,11,30).toUTCString() || i.toUTCString() == new Date(2007,11,31).toUTCString() || i.toUTCString() == new Date(2007,11,32).toUTCString() || i.toUTCString() == new Date(2008,0,1).toUTCString() || i.toUTCString() == new Date(2008,0,2).toUTCString() || i.toUTCString() == new Date(2008,0,3).toUTCString() || i.toUTCString() == new Date(2008,0,4).toUTCString() || i.toUTCString() == new Date(2008,0,5).toUTCString() || i.toUTCString() == new Date(2008,0,6).toUTCString() || i.toUTCString() == new Date(2008,0,7).toUTCString())
				error = 1;
		}

		if ((startDate > lockdown[0] && endDate < lockdown[1]) || error == 1) {
			alert(err_Messages[2]);
			return;
		}


		//Set 1 day in milliseconds
		var one_day=1000*60*60*24;

		var day_diff = Math.ceil((endDate.getTime()-startDate.getTime())/(one_day)+1);
		var day_diff_old = Math.ceil((startDate.getTime()-thisDate.getTime())/(one_day));

		/* if user selects old date in calender*/
		if(day_diff_old<=0){
			alert(err_Messages[1]);
			return;
		}

		var day_diff_old = Math.ceil((endDate.getTime()-thisDate.getTime())/(one_day));

		/* if user selects old date in calender*/
		if(day_diff_old<=0){
			alert(err_Messages[1]);
			return;
		}

		if (parseInt(day_diff) <= minDays) {
			alert(err_Messages[0]);
			return;
		}
		else
			doc.submit();

	}

	/* funtions from directbooking.js from old eden arosa project start*/
	function calculate_beds(beds, extra, adults, kids1, kids2, kids3)
	{
		// total people
		kids = kids1+kids2+kids3;
		people = kids+adults;

		// track bed count (by cost category)
		count_standard = 0;
		count_adults = 0;
		count_kids1 = 0;
		count_kids2 = 0;
		count_kids3 = 0;
		count_singlefee = 0;

		count_rooms = 0;

		// loop while people are not placed
		while (people)
		{
			count_rooms += 1;		// inc rooms
			room_beds = beds;		// reset bed available
			room_extra = extra;		// reset extra available

			// while bed/extra and people are available for this room, loop
			while ( (room_beds+room_extra) > 0 && people > 0)
			{
				// first fill adults in available standard beds
				if (adults && room_beds)
				{
					room_beds--;
					adults--;
					count_standard++;
				}
				// fill remaining standard beds with kids3
				else if (kids3 && room_beds)
				{
					room_beds--;
					kids3--;
					count_standard++;
				}
				// fill remaining standard beds with kids2
				else if (kids2 && room_beds)
				{
					room_beds--;
					kids2--;
					count_standard++;
				}
				// fill remaining standard beds with kids1
				else if (kids1 && room_beds)
				{
					room_beds--;
					kids1--;
					count_standard++;
				}
				// fill extra with kids1
				else if (kids1 && room_extra)
				{
					room_extra -= 0.5;
					kids1--;
					count_kids1++;
				}
				// fill extra with kids2
				else if (kids2 && room_extra)
				{
					room_extra -= 0.5;
					kids2--;
					count_kids2++;
				}
				// fill extra with kids3
				else if (kids3 && room_extra)
				{
					room_extra -= 0.5;
					kids3--;
					count_kids3++;
				}
				// fill extra with adults
				else if (adults && room_extra)
				{
					room_extra -= 1;
					adults--;
					count_adults++;
				}

				// update people count
				kids = kids1+kids2+kids3;
				people = adults+kids;
			}

			// update people count
			kids = kids1+kids2+kids3;
			people = adults+kids;
		}

		// if standard beds are not devisible by available beds, a person is alone in 2 bedroom room
		if (count_standard % beds != 0) count_singlefee++;

		// build return array
		returnVal = new Array();
		returnVal["rooms"] = count_rooms;
		returnVal["standard"] = count_standard;
		returnVal['adults'] = count_adults;
		returnVal['kids1'] = count_kids1;
		returnVal['kids2'] = count_kids2;
		returnVal['kids3'] = count_kids3;
		returnVal['singlefee'] = count_singlefee;

		return returnVal;
	}

	function processDate(datevalue)
	{
		// date regexp
		re_date = /([0-9]{2}).([0-9]{2}).([0-9]{4})/;

		matches = re_date.exec(datevalue);
		if (matches && matches.length == 4)
		{
			if (!validDate(matches[1], matches[2], matches[3]))
				return -1;

			return new Date(matches[3], matches[2]-1, matches[1]);
		}

		return 0;
	}

	function LeapYear(year) {
	    if ((year/4)   != Math.floor(year/4))   return false;
	    if ((year/100) != Math.floor(year/100)) return true;
	    if ((year/400) != Math.floor(year/400)) return false;
	    return true;
	}

	function validDate(day, month, year)
	{
		valid = true;

		if (LeapYear(year))
			var monthMax = new Array(31,31,29,31,30,31,30,31,31,30,31,30,31);
		else
			var monthMax = new Array(31,31,28,31,30,31,30,31,31,30,31,30,31);

		if (monthMax[parseInt(month)] < day) valid = false;
		if (month > 12) valid = false;

		return valid;
	}

	function returnEuroDate(mydate)
	{
		return (mydate.getDate())+"."+(mydate.getMonth()+1)+"."+(mydate.getYear());
	}

	/* funtions from directbooking.js from old eden arosa project end*/