//
function confirmBooking(intPropertyId, selectedPropertyName, strClient, dtStartNight, dtEndNight) {
	//alert("Running confirmBooking()...");
	//alert("intPropertyId: " + intPropertyId + "\nselectedPropertyName: " + selectedPropertyName + "\nstrClient: " + strClient + "\ndtStartNight: " + dtStartNight + "\ndtEndNight: " + dtEndNight);
	
	myErrors = "";
	// check that intPropertyId is an integer
	if (!isInteger(intPropertyId)) {
		myErrors = myErrors + "\nProperty must be an integer.";
	}
	// check that strClient is not blank
	if (isBlank(strClient)) {
		myErrors = myErrors + "\nBooker must not be blank.";
	}	

	// check that dtStartNight is a valid date
	if (!isDate(dtStartNight, "dd MMM yyyy")) {
		myErrors = myErrors + "\nStart Night must be in valid format, eg 31 March 2005.";
	}
	
	// check that dtEndNight is a valid date
	if (!isDate(dtEndNight, "dd MMM yyyy")) {
		myErrors = myErrors + "\nEnd Night must be in valid format, eg 31 March 2005.";
	}
	if (myErrors != "") {
		alert("The following errors occurred:\n\n" + myErrors);
		return false;
	}
	else {
		good2go = confirm("Please confirm the details...\n\nProperty: " + selectedPropertyName + " (Property Id " + intPropertyId + ")" + "\nBooked by: " + strClient + "\nFirst night: " + dtStartNight + "\nFinal night: " + dtEndNight);
		if (good2go) {
			return true;
		}
		else {
			return false;
		}
	}
}

// toggle display of sub menu
function toggleInfo(targetId) {
	if (document.getElementById) {
		target = document.getElementById(targetId);
		if (target.style.display == "none") {
			target.style.display = "";
		}
		else {
			target.style.display = "none";
		}
	}
}

// add to favourites list
function addToFavourites(intPropertyId) {
	//alert("Adding PropertyId: " + intPropertyId + " to 'My Favourites'.");
	
	if (favouriteExists(intPropertyId)) {
		alert("PropertyId: " + intPropertyId + " is already in 'My Favourites'!");
	}
	else {
		good2go = confirm("Add PropertyId: " + intPropertyId + " to 'My Favourites'.");
		if (good2go) {
			strFaves = readCookie("floridaysFaves");
			if (strFaves == "") {
				writeCookie("floridaysFaves", intPropertyId, 24*7);
			}
			else {
				writeCookie("floridaysFaves", strFaves + "," + intPropertyId, 24*7);
			}
		}
	}
}

function removeFavourite(intPropertyId) {
	if (favouriteExists(intPropertyId)) {
		arrFaves = strFaves.split(",");
		for (var i = 0; i <arrFaves.length; i++) {
			if (arrFaves[i] == intPropertyId) {
				arrFaves.splice(i,1)
				writeCookie("floridaysFaves", arrFaves.join(), 24*7);
				window.location.reload();
			}
		}		
	}
	else {
		alert("PropertyId: " + intPropertyId + " is not in 'My Favourites'!");
	}
}

function favouriteExists(intPropertyId) {
	strFaves = readCookie("floridaysFaves");
	if (strFaves == "") {
		return false;
	}
	arrFaves = strFaves.split(",");
	for (var i = 0; i <arrFaves.length; i++) {
		if (arrFaves[i] == intPropertyId) {
			return true;
		}
	}
	// if we get to here, we haven't found it
	return false;
}

function clearFavourites() {
	writeCookie("floridaysFaves", "", -1);
	window.location.reload();
}