
function clearQuotes(theForm) {
	for (i=0;i<theForm.elements.length;i++) {
		if (theForm.elements[i].value) {
			theForm.elements[i].value = theForm.elements[i].value.replace(/'/gi,"`");
		}
	}
}

function checkEmail(theEmail) {
	if (theEmail.indexOf('.')==-1) return false;
	if (theEmail.indexOf('@')==-1) return false;
	if (theEmail.length<6) return false;
	return true;
}

function checkCompetition() {
	theForm=document.CompetitionForm;
	clearQuotes(theForm);
	
	if (theForm.fname.value.length<1) {alert("Please enter your first name.");return false;}
	if (theForm.lname.value.length<1) {alert("Please enter your last name.");return false;}
	if (theForm.email.value.length<1) {alert("Please enter your email address.");return false;}
	if (checkEmail(theForm.email.value)==false) {alert("The email address you have entered does not seem to be valid.");return false;}

	return true;
}

function checkSubscription() {
	theForm=document.SubscriptionForm;
	clearQuotes(theForm);
	
	if (theForm.fname.value.length<1) {alert("Please enter your first name.");return false;}
	if (theForm.lname.value.length<1) {alert("Please enter your last name.");return false;}
	if (theForm.email.value.length<1) {alert("Please enter your email address.");return false;}
	if (checkEmail(theForm.email.value)==false) {alert("The email address you have entered does not seem to be valid.");return false;}

	return true;
}

function checkEnquiry() {
	theForm=document.EnquiryForm;
	clearQuotes(theForm);
	
	if (theForm.fname.value.length<1) {alert("Please enter your first name.");return false;}
	if (theForm.lname.value.length<1) {alert("Please enter your last name.");return false;}
	if (theForm.email.value.length<1) {alert("Please enter your email address.");return false;}
	if (checkEmail(theForm.email.value)==false) {alert("The email address you have entered does not seem to be valid.");return false;}

	if (theForm.subject.value.length<1) {alert("Please enter a subject for your enquiry.");return false;}
	if (theForm.message.value.length<1) {alert("Please enter a message.");return false;}

	return true;
}

function checkMember()
{
	theForm = document.MemberForm;

	clearQuotes(theForm);
	
	if (theForm.fname.value.length<1) {alert("Please enter your first name.");return false;}
	if (theForm.lname.value.length<1) {alert("Please enter your last name.");return false;}
	if (theForm.email.value.length<1) {alert("Please enter your email address.");return false;}
	if (checkEmail(theForm.email.value)==false) {alert("The email address you have entered does not seem to be valid.");return false;}
	
	if (theForm.phone1.value.length<1) {alert("Please enter a phone number.");return false;}

	var phone = theForm.phone1.value + '';

	phone = phone.replace(/[^0-9]*/gi, "");

	theForm.password.value = phone;

	return true;
}

function checkJoinNow(f)
{
	with(f)
	{
		if (checkEmail(email.value) == false)
		{
			alert("The email address you have entered does not seem to be valid.");
			return false;
		}
	}
	
}
function checkLoginForm(f)
{
	theForm = document.LoginForm;

	clearQuotes(theForm);
	
	if (theForm.fname.value.length<1) {alert("Please enter your first name.");return false;}
	if (theForm.lname.value.length<1) {alert("Please enter your last name.");return false;}
	if (theForm.phone1.value.length<1) {alert("Please enter a phone number.");return false;}
	if (theForm.email.value.length<1) {alert("Please enter your email address.");return false;}
	if (checkEmail(theForm.email.value)==false) {alert("The email address you have entered does not seem to be valid.");return false;}

	var phone = theForm.phone1.value + '';

	phone = phone.replace(/[^0-9]*/gi, "");
	
	theForm.password.value = phone;

}
/* ***** BOOKING FORM ***** */
function lastServiceDate() {
	var lsDay 	= document.getElementById('fdDate').options[document.getElementById('fdDate').selectedIndex].value;
	var lsMonth	= document.getElementById('fdMonth').options[document.getElementById('fdMonth').selectedIndex].text;
	var lsYear 	= document.getElementById('fdYear').options[document.getElementById('fdYear').selectedIndex].value;

	var theDate = lsMonth+" "+lsDay+" "+lsYear;
	document.getElementById('iData02').value = theDate;
}
function prefServiceDate() {
	var psDay 	= document.getElementById('fpDate').options[document.getElementById('fpDate').selectedIndex].value;
	var psMonth	= document.getElementById('fpMonth').options[document.getElementById('fpMonth').selectedIndex].text;

	var theDate = psMonth+" "+psDay;
	document.getElementById('iData05').value = theDate;
}

function checkService() {
	theForm=document.ServiceForm;
	clearQuotes(theForm);
	
	if (theForm.data00.value.length<1) {alert("Please enter the make and model of your coffee machine.");return false;}
	if (theForm.data07.value.length<1) {alert("Please enter the reason for the service.");return false;}

	lastServiceDate();
	prefServiceDate();

	return true;
}