// function to validate the contact form on the contact page

function validateContactForm(contactForm){
	
	rePhone = /^\+?(\d|\s){9,18}$/
	reEmpty = /^(\s|\S){3,1000}$/
	reEmail = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,6})+$/
	reIllegal = /[\(\)\<\>\,\;\:\\\/\"\[\]]/
	
	if (!reEmpty.test(contactForm.clientname.value)){
		alert("Please enter your full name");
		contactForm.clientname.focus();
		return false;
	}
	
	if (!rePhone.test(contactForm.tel.value)){
		alert("Please enter your full telephone number, including your country code (if not a Spanish number).  For example 971 111 111 or +44 7000 111 111");
		contactForm.tel.focus();
		return false;
	}
	
	if (!reEmail.test(contactForm.email.value)){
		alert("Please enter a valid email address.  E.g. xxx@xxxx.xxx");
		contactForm.email.focus();
		return false;
	}
	
	if (reIllegal.test(contactForm.email.value)){
		alert("Please enter a valid email address.  E.g. xxx@xxxx.xxx");
		contactForm.email.focus();
		return false;
	}
	
	if (!reEmpty.test(contactForm.question.value)){
		alert("Please enter your question or comments");
		contactForm.question.focus();
		return false;
	}
}

// function to validate the order form on the index.php page and proddetail.php page

function validateOrderForm(orderForm){
	
	if(orderForm.colour.value=="null"){
		alert("Please select a colour before placing an item in the shopping basket")
		orderForm.colour.focus();
		return false;
	}
	
	if(orderForm.size.value=="null"){
		alert("Please select a size before placing an item in the shopping basket")
		orderForm.size.focus();
		return false;
	}
	
	if(orderForm.qty.value=="null"){
		alert("Please select a quantity before placing an item in the shopping basket")
		orderForm.qty.focus();
		return false;
	}
}

// function to validate the customer details when making a purchase

function validatePurchaseForm(purchaseForm){
	
	rePhone = /^\+?(\d|\s){9,18}$/
	reEmpty = /^(\s|\S){3,1000}$/
	reEmail = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,6})+$/
	reIllegal = /[\(\)\<\>\,\;\:\\\/\"\[\]]/
	
	if (!reEmpty.test(purchaseForm.clientname.value)){
		alert("Please enter your full name");
		purchaseForm.clientname.focus();
		return false;
	}

	if (!reEmpty.test(purchaseForm.address1.value)){
		alert("Please complete at least 1 line of your street address");
		purchaseForm.address1.focus();
		return false;
	}
	
	if (!reEmpty.test(purchaseForm.town.value)){
		alert("Please enter your town or city");
		purchaseForm.town.focus();
		return false;
	}
	
	if (!reEmpty.test(purchaseForm.postcode.value)){
		alert("Please enter your postal code");
		purchaseForm.postcode.focus();
		return false;
	}
	
	if (!reEmpty.test(purchaseForm.county.value)){
		alert("Please enter your county");
		purchaseForm.county.focus();
		return false;
	}
	
	if (!reEmail.test(purchaseForm.correo.value)){
		alert("Please enter a valid email address.  E.g. xxx@xxxx.xxx");
		purchaseForm.correo.focus();
		return false;
	}
	
	if (reIllegal.test(purchaseForm.correo.value)){
		alert("Please enter a valid email address.  E.g. xxx@xxxx.xxx");
		purchaseForm.correo.focus();
		return false;
	}
	
		if (!rePhone.test(purchaseForm.tel.value)){
		alert("Please enter your full telephone number, including your country code (if not a Spanish number).  For example 971 111 111 or +44 7000 111 111");
		purchaseForm.tel.focus();
		return false;
	}
}

// function to validate the customer details when completing the pre-Paypal form

function validatePaypalForm(paypalForm){
	
	rePhone = /^\+?(\d|\s){9,18}$/
	reEmpty = /^(\s|\S){3,1000}$/
	reEmail = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,6})+$/
	reIllegal = /[\(\)\<\>\,\;\:\\\/\"\[\]]/
	
	if (!reEmpty.test(paypalForm.firstname.value)){
		alert("Please enter your first name");
		paypalForm.firstname.focus();
		return false;
	}

	if (!reEmpty.test(paypalForm.surname.value)){
		alert("Please enter your surname");
		paypalForm.surname.focus();
		return false;
	}
	
	if (!reEmpty.test(paypalForm.address1.value)){
		alert("Please complete at least 1 line of your street address");
		paypalForm.address1.focus();
		return false;
	}
	
	if (!reEmpty.test(paypalForm.town.value)){
		alert("Please enter your town or city");
		paypalForm.town.focus();
		return false;
	}
	
	if (!reEmpty.test(paypalForm.postcode.value)){
		alert("Please enter your postal code");
		paypalForm.postcode.focus();
		return false;
	}
}