	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());
	}

