function setTotals() {
  var warn = "";
  showChosen = 0;
  beds = price = displayedBeds = 0;
  sel = Selects.length;

  for (i=0; i<sel; i++) {
    menu = document.getElementById(Selects[i]);

    menuNum = parseInt(Selects[i].replace(/People/, ''));
    val = parseInt(menu.options[menu.selectedIndex].value);
    displayed = parseInt(menu.options[menu.selectedIndex].text);
    
    beds += val;
    displayedBeds += displayed;
    price += val*Prices[i];

    if(val > 0) {
      document.getElementById('ChosenNum'+menuNum).innerHTML = val;
      document.getElementById('ChosenPrice'+menuNum).innerHTML = "&euro;" + currFormat(val*Prices[i]);
      document.getElementById('Chosen'+menuNum).style.display = rowDisplay;
      showChosen = 1;
    } else {
      document.getElementById('Chosen'+menuNum).style.display = 'none';
    }
  }

  if(showChosen) {
    document.getElementById('ChosenHead').style.display = rowDisplay;
    document.getElementById('BookButton').style.display = rowDisplay;
    document.getElementById('ChosenTotal').style.display = rowDisplay;
  } else {
    document.getElementById('ChosenHead').style.display = 'none';
    document.getElementById('BookButton').style.display = 'none';
    document.getElementById('ChosenTotal').style.display = 'none';
  }

  TotalPrice = document.getElementById('PayNowTotal');
  TotalPrice.innerHTML = "&euro;" + currFormat(price);
}


function currFormat(amount) {
  amount -= 0;
  amount = (amount == Math.floor(amount)) ? amount + '.00' : (  (amount*10 == Math.floor(amount*10)) ? amount + '0' : amount);
  amount = amount.toString();

  bits = amount.split('.');

  return bits[0] + '.' + bits[1].substring(0,2);
}

function isValidDate(dateStr) {
	// Checks for the following valid date formats:
	// MM/DD/YY   MM/DD/YYYY   MM-DD-YY   MM-DD-YYYY
	// Also separates date into month, day, and year variables

	//var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;

	// To require a 4 digit year entry, use this line instead:
	 var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;

	var matchArray = dateStr.match(datePat); // is the format ok?
	if (matchArray == null) {
	alert("Date is not in a valid format.")
	return false;
	}
	month = matchArray[3]; // parse date into variables
	day = matchArray[1];
	year = matchArray[4];
	if (month < 1 || month > 12) { // check month range
	alert("Month must be between 1 and 12.");
	return false;
	}
	if (day < 1 || day > 31) {
	//alert("Day must be between 1 and 31.");
	return false;
	}
	if ((month==4 || month==6 || month==9 || month==11) && day==31) {
	//alert("Month "+month+" doesn't have 31 days!")
	return false
	}
	if (month == 2) { // check for february 29th
	var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
	if (day>29 || (day==29 && !isleap)) {
	alert("February " + year + " doesn't have " + day + " days!");
	return false;
	   }
	}
	return true;  // date is valid
}


