// js validation

function Trim(sString)
{
	return sString.replace(/^\s+/g, '').replace(/\s+$/g, '');
}

function validateform(frm, sFields)
{
	// csv list of values to check
	fieldlist = sFields.split(",");
	for(element=0; element<fieldlist.length; element++)
	{
		doc = eval('frm.' + fieldlist[element]);
		if(Trim(doc.value) == "")
		{
			if (doc.alt)
				alert(doc.alt); 
			else
				alert('You must enter a value for ' + fieldlist[element]); 
			doc.focus();
			return false;
		}
	}
	return true;
}

function isEmail(sEmail)
{
	//Check that there is an @ symbol in there and that it is not the first character
	if (sEmail.indexOf ('@', 0) < 1)
	{
		alert("Please ensure you have entered a valid email address");
		return false;
	}
	else
	{
		//Now check that there is a . after the @ symbol and that there are characters between the @ and the .
		if (sEmail.indexOf ('.', sEmail.indexOf ('@', 0)) < (sEmail.indexOf ('@', 0) + 3))
		{
			alert("Please ensure you have entered a valid email address.");
			return false;
		}
		
		//Now check to ensure that the . is not the last character entered into the string.
		if (sEmail.lastIndexOf(".") == (sEmail.length - 1))
		{
			alert("Please make sure you have entered a valid email address.");
			return false;
		}
	}
	return true;
}

function validatereservation(frm)
{
	var lstRequired = 'firstname,lastname,EmailAddress,tel,arrivalday,arrivalmonth,departureday,departuremonth';
	if (validateform(frm, lstRequired) && isEmail(frm.EmailAddress.value))
	{
		return true;
	}
	return false;
}