
	var strOptionList = '<option value="0">0</option><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option>10</option>';

	function use_two_cards() {
		var elmHiddenElements = elmsByClass('hide_multiple_card');
		for (i = 0; i < elmHiddenElements.length; i++) {
			elmHiddenElements[i].style.display = 'block';
		}
		document.getElementById('turn_on_multiple_cards').style.display = 'none';
	}
	
	function show_content_block(blockid) {
		for (var i = 1; i <= 10; i++) {
			if (document.getElementById('content_block_' + i)) {
				document.getElementById('content_block_' + i).style.display = 'none';
			}
			if (document.getElementById('content_tab_' + i)) {
				var thisClass = ' ' + document.getElementById('content_tab_' + i).className + ' ';
				document.getElementById('content_tab_' + i).className = thisClass.replace(/ on /g, ' ');
			}
		}
		if (document.getElementById('content_block_' + blockid)) {
			document.getElementById('content_block_' + blockid).style.display = 'block';
		}
		if (document.getElementById('content_tab_' + blockid)) {
			document.getElementById('content_tab_' + blockid).className += ' on';
		}
	}

	function update_card_values(card_element, total_cost) {
		var card1 = document.getElementById('first_card_payment');
		var card2 = document.getElementById('second_card_payment');
		if (card_element == 'first_card_payment') {
			if (card1.value > total_cost) {
				card1.value = total_cost;
			}
			card2.value = (total_cost - card1.value).toFixed(2);
		} else {
			if (card2.value > total_cost) {
				card2.value = total_cost;
			}
			card1.value = (total_cost - card2.value).toFixed(2);
		}
	}

	function updatePeopleSelector() {
		var arrInputs = elmsByClass('room_booking_inputs');
		var strReference;
		var strTempReference;
		if (arrInputs.length > 0) {
			var totalRoomCount = 0;
			for (i = 0; i < arrInputs.length; i++) {
				totalRoomCount += parseFloat(arrInputs[i].options[(arrInputs[i].selectedIndex)].value);
			}
			if (totalRoomCount > 0) {
				var arrRows = elmsByClass('people_row');
				var arrRowIds = [];
				var arrTempRowIds = [];
				for (i = 0; i < arrRows.length; i++) {
					arrRowIds[arrRowIds.length] = arrRows[i].id;
				}
				// arrRowIds now lists all rows that already exist
				for (i = 0; i < arrInputs.length; i++) {
					intRoomId = arrInputs[i].name.replace(/[^0-9]/ig, '');
					strReference = document.getElementById('people_row_reference_' + i).innerHTML;
					for (j = 1; j <= arrInputs[i].value; j++) {
						strRowId = 'people_row_' + intRoomId + '_' + j;
						// If row already present, skip
						if (document.getElementById(strRowId)) {
						} else {
							strTempReference = strReference;
							if (arrInputs[i].value > 1) {
								strTempReference += ' ' + j;
							}
							strTempReference = '<span id="age_row_reference_' + intRoomId + '_' + j + '">' + strTempReference + '</span>';
							addRow('booking_form_people',  strRowId, strTempReference);
						}
						// Remove this row id from rowids
						arrTempRowIds = [];
						for (k = 0; k < arrRowIds.length; k++) {
							if (arrRowIds[k] != strRowId) {
								arrTempRowIds[arrTempRowIds.length] = arrRowIds[k];
							}
						}
						arrRowIds = arrTempRowIds;
					}
				}
				// Whatever we have in arrRowIds should now be deleted
				for (i = 0; i < arrRowIds.length; i++) {
					var el = document.getElementById(arrRowIds[i]);
					el.parentNode.removeChild(el);
				}
				document.getElementById('people_div').style.display = 'block';
			} else {
				document.getElementById('people_div').style.display = 'none';
			}
		} else {
			document.getElementById('people_div').style.display = 'none';
		}
	}

	function addRow(strTableId, strRowId, strReference) {
		var tbody = document.getElementById(strTableId).getElementsByTagName("tbody")[0];
		var row = document.createElement("tr");
		row.className = 'people_row';
		row.id = strRowId;
		var th1 = document.createElement("th");
		th1.innerHTML = strReference;
		strRowId = strRowId.replace(/people_row_/ig, '');
		var td1 = document.createElement("td");
		td1.innerHTML = '<select id="book_adults_' + strRowId + '" name="book_adults_' + strRowId + '">' + strOptionList + '</select>';
		var td2 = document.createElement("td");
		td2.innerHTML = '<select onChange="updateAgesSection();" class="child_booking_inputs" id="book_children_' + strRowId + '" name="book_children_' + strRowId + '">' + strOptionList + '</select>';
		row.appendChild(th1);
		row.appendChild(td1);
		row.appendChild(td2);
		tbody.appendChild(row);
	}

	function updateAgesSection() {
		var strReferenceRowId;
		var arrInputs = elmsByClass('child_booking_inputs');
		if (arrInputs.length > 0) {
			var total = 0;
			for (i = 0; i < arrInputs.length; i++) {
				total += parseFloat(arrInputs[i].options[(arrInputs[i].selectedIndex)].value);
			}
			if (total > 0) {
				var arrRows = elmsByClass('age_row');
				var arrRowIds = [];
				var arrTempRowIds = [];
				for (i = 0; i < arrRows.length; i++) {
					arrRowIds[arrRowIds.length] = arrRows[i].id;
				}
				// arrRowIds now lists all rows that already exist
				for (i = 0; i < arrInputs.length; i++) {
					strReferenceRowId = arrInputs[i].name.replace(/book_children_/ig, 'age_row_reference_');
					strReference = document.getElementById(strReferenceRowId).innerHTML;
					for (j = 1; j <= arrInputs[i].value; j++) {
						strRowId = arrInputs[i].name + '_' + j;
						strRowId = strRowId.replace(/book_children_/ig, 'age_row_');
						// If row already present, skip
						if (document.getElementById(strRowId)) {
						} else {
							strTempReference = strReference;
							strTempReference += ' <span style="font-weight: normal;"> - child ' + j + '</span>';
							addAgeRow('booking_form_age',  strRowId, strTempReference);
						}
						// Remove this row id from rowids
						arrTempRowIds = [];
						for (k = 0; k < arrRowIds.length; k++) {
							if (arrRowIds[k] != strRowId) {
								arrTempRowIds[arrTempRowIds.length] = arrRowIds[k];
							}
						}
						arrRowIds = arrTempRowIds;
					}
				}
				// Whatever we have in arrRowIds should now be deleted
				for (i = 0; i < arrRowIds.length; i++) {
					var el = document.getElementById(arrRowIds[i]);
					el.parentNode.removeChild(el);
				}
				document.getElementById('ages_div').style.display = 'block';
			} else {
				document.getElementById('ages_div').style.display = 'none';
			}
		} else {
			document.getElementById('ages_div').style.display = 'none';
		}
	}

	function addAgeRow(strTableId, strRowId, strReference) {
		var tbody = document.getElementById(strTableId).getElementsByTagName("tbody")[0];
		var row = document.createElement("tr");
		row.className = 'age_row';
		row.id = strRowId;
		var th1 = document.createElement("th");
		th1.innerHTML = strReference;
		strRowId = strRowId.replace(/age_row_/ig, '');
		var td1 = document.createElement("td");
		td1.innerHTML = '<input id="child_age_' + strRowId + '" name="child_age_' + strRowId + '" type="text" size="3"> years';
		row.appendChild(th1);
		row.appendChild(td1);
		tbody.appendChild(row);
	}

	function toggleRoomSelection() {
		if (document.getElementById('room_selection_rooms').checked == true) {
			document.getElementById('room_selection').style.display = 'block';
		} else {
			document.getElementById('room_selection').style.display = 'none';
		}
	}