/* Check channel Islands and UK
* For Channel Islands and United Kingdom, flowers are posted Monday to Thursday
*/
function CheckCI_UK() {
	// In all the other cases the delivery cost will be £ 0
	alert("For Channel Islands and United Kingdom, flowers are posted Monday to Thursday. The cost for all items to the Channel Islands and United Kingdom include postage. For more information read the note...");
	document.forms["DetailsForm"].elements["costPostage"].value = "£ 0";
	return;
}

/* Check Eire and Europe
** For Eire and Europe, flowers are posted on Monday and Tuesday
*/
function CheckOther(dayName) {
	var isplit1 = dayName.indexOf("Monday");
	var isplit2 = dayName.indexOf("Tuesday");
	var date = new Date();

	var costo = 12 * document.getElementById("DetailsForm").elements["products_Quantity"].value;
	// Manage here Eire and Europe
	if (isplit1 == -1 && isplit2 == -1) {
		alert("Deliveries to Europe & Eire are only posted on Mondays & Tuesdays!!!\n\nPlease select another date.\n\nFor more information please read the note...");
		document.forms["DetailsForm"].elements["ArrivalDate2"].value = "";
		document.forms["DetailsForm"].elements["costPostage"].value = "£ 0";
		return;
	}
	else {
		alert("Deliveries to Europe & Eire are only posted on Mondays & Tuesdays at a cost of £12 per box/bunch. For more information please read the note...");
		document.forms["DetailsForm"].elements["costPostage"].value = "£ " + costo;
	}
}
function DeliveryDateChanged(obj) {
	var countryIndex = document.forms["DetailsForm"].elements["Country"].selectedIndex;
	if (countryIndex == 0) {
		alert("To know the delivery cost, please select the Country..");
		return;
	}

	// Retrieve delivery date:
	var deliveryDate = document.getElementById("dateinput");
	if (deliveryDate != null) {
		deliveryDate = deliveryDate.value;
		var selectedDate = new Date();
		selectedDate.setFullYear(deliveryDate.slice(6, 10), parseInt(deliveryDate.slice(3, 5), 10) - 1, deliveryDate.slice(0, 2))

		var weekday = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
		var dayName = weekday[selectedDate.getDay()];

		// Manage here Channel Islands and UK
		if (countryIndex < 3) {
			CheckCI_UK();
			return;
		}
		else {
			// Manage here Eire and Europe
			CheckOther(dayName);
			return;
		}
	}
}
function CountryChanged(obj) {
	var countryIndex = obj.selectedIndex;
	if (countryIndex == 0) {
		document.forms["DetailsForm"].elements["costPostage"].value = "£ 0";
		return;
	}
	// Retrieve delivery date:
	var deliveryDate = document.getElementById("dateinput");
	if (deliveryDate != null) {
		deliveryDate = deliveryDate.value;
		if (deliveryDate.length < 1) {
			alert("To know the delivery cost, please select the Dispatch Date!!!");
			document.forms["DetailsForm"].elements["costPostage"].value = "£ 0";
			return false;
		}
		var selectedDate = new Date();
		selectedDate.setFullYear(deliveryDate.slice(6, 10), parseInt(deliveryDate.slice(3, 5), 10) - 1, deliveryDate.slice(0, 2))
		var weekday = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
		var dayName = weekday[selectedDate.getDay()] + "";
		dayName = "";
		// Manage here Channel Islands and UK
		if (countryIndex < 3) {
			CheckCI_UK();
			return;
		}
		// Manage here Eire and Europe
		else {
			CheckOther(dayName);
			return;
		}
	}
}

