//Package JavaScript author Loredana Zonnino

// Copyright (C) 2007 www.loredanaebook.it

// verifica che i campi obbligatori del form contengano dei valori

function validatevalues(theForm){
	if ((theForm.expm.value == "") || (theForm.expy.value == "")) {
		alert("Please select a value for the Credit card \"Expiration date\" field.");
		theForm.expm.focus();
		return (false);
	}
	if (theForm.ccNumber.value == "") {
		alert("Please enter a value for the \"Credit Card no.\" field.");
		theForm.ccNumber.focus();
		return (false);
	}
	if (theForm.Country.value == "") {
		alert("Please select your Country.");
		theForm.Country.focus();
		return (false);
	}
	if (theForm.Email.value == "") {
		alert("Please enter your E-mail address to enable us to contact you.");
		theForm.Email.focus();
		return (false);
	}
	if (theForm.ArrivalDate.value == "") {
		alert("Please enter a value for the \"Arrival Date\" field.");
		theForm.ArrivalDate.focus();
		return (false);
	}
	if (theForm.ArrivalTime.value == "") {
		alert("Please select a value for the \"Time of Arrival\" field.");
		theForm.ArrivalTime.focus();
		return (false);
	}
	if (theForm.DepartureDate.value == "") {
		alert("Please enter a value for the \"Departure Date\" field.");
		theForm.DepartureDate.focus();
		return (false);
	}
	if (theForm.TandC.checked == false) {
		alert("Please tick the box to confirm you have read and understood the Terms & Conditions applied.");
		theForm.TandC.focus();
		return (false);
	}
	else {
		return (true);
	}
}


// controlla che il campo contenga solo valori numerici

function onlynumbers(ccno) {
	if (isNaN(ccno)) {
		alert("Please enter a valid credit card number.");
		document.form1.ccNumber.focus();
		document.form1.ccNumber.value = "";
		return (false);
	}
	if ((ccno.indexOf(' ') >=0) || (ccno.indexOf('.') >=0)) {
		alert ("Please enter a valid credit card number.");
		document.form1.ccNumber.focus();
		document.form1.ccNumber.value = "";
		return (false);
	}
	if (ccno.length < 13) {
		alert ("Please enter a valid credit card number.");
		document.form1.ccNumber.focus();
		document.form1.ccNumber.value = "";
		return (false);
	}
}


// controlla che il campo email contenga un indirizzo valido

function checkemail(email) {
	if(email.length > 0) {
		if (email.indexOf(' ') >= 0) {
			alert("Please enter a valid email address without spaces in.");
			document.form1.Email.focus();
			document.form1.Email.value = "";
			return (false);
		}
		if ((email.indexOf('@') == -1) || (email.indexOf('.') == -1)) {
			alert("Please enter a valid email address.");
			document.form1.Email.focus();
			document.form1.Email.value = "";
			return (false);
		}
			if (email.indexOf('%') >= 0) {
			alert("Please enter a valid email address.");
			document.form1.Email.focus();
			document.form1.Email.value = "";
			return (false);
		}
	return (true);
	}
}


// cambia le tariffe durante alcuni periodi dell'anno
// e verifica che il valore della data inserita non sia anteriore alla data corrente

function checkindate(thisField) {

var normalprice = new Array("Single Room (Basic) £45.00","Single Room (Ensuite) £55.00","Double/Twin Room (Basic) £55.00","Double/Twin Room (Ensuite) £65.00","Triple Room (Basic) £75.00","Triple Room (Ensuite) £85.00","Quad Room (Ensuite) £120.00");
//"Quad Room (Basic) £120.00"

var specialprice = new Array("Single Room (Basic) £35.00","Single Room (Ensuite) £45.00","Double/Twin Room (Basic) £45.00","Double/Twin Room (Ensuite) £55.00","Triple Room (Basic) £65.00","Triple Room (Ensuite) £75.00","Quad Room (Ensuite) £100.00");
//"Quad Room (Basic) £100.00"

var selectlist = document.form1.RoomType;
//var tarifsarray = eval(newtarifs);
var newdate = new Date();
var currentyear = newdate.getFullYear();
var nextyear = currentyear +1;

	if ((thisField.value >= currentyear+"-04-01" && thisField.value <= currentyear+"-09-15") || (thisField.value >= nextyear+"-04-01" && thisField.value <= nextyear+"-09-15")) {
		//alert(" "+document.form1.RoomType.options(1).value);
		for(loop = 0; loop < selectlist.options.length; loop++) {
			selectlist.options[loop].text = normalprice[loop];
			selectlist.options[loop].value = normalprice[loop];
		}
	}
	else {
		for(loop = 0; loop < selectlist.options.length; loop++) {
			selectlist.options[loop].text = specialprice[loop];
			selectlist.options[loop].value = specialprice[loop];
		}
	}

var todayDate = document.form1.CurrentDate;
	if(thisField.value <= todayDate.value) {
		alert("Please enter a value greater than the current date.");
		thisField.focus();
		thisField.value="";
		return (false);
	}

var checkout = document.form1.DepartureDate;
	if(thisField.value >= checkout.value) {
		checkout.value="";
		return (false);
	}
}


// verifica che il valore della data di partenza sia una data posteriore 
// a quello della data di arrivo

function postarrival(thisCheckout) {
var checkin = document.form1.ArrivalDate;
	if(thisCheckout.value <= checkin.value) {
		alert("Please enter a value greater than the arrival date.");
		thisCheckout.focus();
		thisCheckout.value="";
		return (false);
	}
}


