// 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("Debe introducir du nombre y apellido");
		contactForm.clientname.focus();
		return false;
	}
	
	if (!rePhone.test(contactForm.tel.value)){
		alert("Debe introducir su número de teléfono entero, incluso el código de país (si no es de España).  Por ejemplo 971 111 111 or +44 7000 111 111");
		contactForm.tel.focus();
		return false;
	}
	
	if (!reEmail.test(contactForm.email.value)){
		alert("Debe introducir una dirección de correo electrónico válido.  Por ej. xxx@xxxx.xxx");
		contactForm.email.focus();
		return false;
	}
	
	if (reIllegal.test(contactForm.email.value)){
		alert("Debe introducir una dirección de correo electrónico válido.  Por ej. xxx@xxxx.xxx");
		contactForm.email.focus();
		return false;
	}
	
	if (!reEmpty.test(contactForm.question.value)){
		alert("Debe introducir su pregunta o comentario");
		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("Debe seleccionar un color antes de colocar un artículo en la cesta de compras")
		orderForm.colour.focus();
		return false;
	}
	
	if(orderForm.size.value=="null"){
		alert("Debe seleccionar una talla antes de colocar un artículo en la cesta de compras")
		orderForm.size.focus();
		return false;
	}
	
	if(orderForm.qty.value=="null"){
		alert("Debe seleccionar una cantidad antes de colocar un artículo en la cesta de compras")
		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("Debe introducir su nombre y apellido");
		purchaseForm.clientname.focus();
		return false;
	}
	
	if (!reEmpty.test(purchaseForm.address1.value)){
		alert("Debe introducir su dirección");
		purchaseForm.address1.focus();
		return false;
	}
	
	if (!reEmpty.test(purchaseForm.town.value)){
		alert("Debe introducir su ciudad o población");
		purchaseForm.town.focus();
		return false;
	}
	
	if (!reEmpty.test(purchaseForm.postcode.value)){
		alert("Debe introducir su código postal");
		purchaseForm.postcode.focus();
		return false;
	}
	
	if (!reEmpty.test(purchaseForm.county.value)){
		alert("Debe introducir su provincia");
		purchaseForm.county.focus();
		return false;
	}
	
	if (!reEmail.test(purchaseForm.correo.value)){
		alert("Debe introducir una dirección de correo electrónico válido.  Por ej. xxx@xxxx.xxx");
		purchaseForm.correo.focus();
		return false;
	}
	
	if (reIllegal.test(purchaseForm.correo.value)){
		alert("Debe introducir una dirección de correo electrónico válido.  Por ej. xxx@xxxx.xxx");
		purchaseForm.correo.focus();
		return false;
	}
	
		if (!rePhone.test(purchaseForm.tel.value)){
		alert("Debe introducir su número de teléfono entero, incluso el código de país (si no es de España).  Por ejemplo 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("Debe introducir su nombre");
		paypalForm.firstname.focus();
		return false;
	}

	if (!reEmpty.test(paypalForm.surname.value)){
		alert("Debe introducir su apellido");
		paypalForm.surname.focus();
		return false;
	}
	
	if (!reEmpty.test(paypalForm.address1.value)){
		alert("Debe introducir su dirección");
		paypalForm.address1.focus();
		return false;
	}
	
	if (!reEmpty.test(paypalForm.town.value)){
		alert("Debe introducir su ciudad o población");
		paypalForm.town.focus();
		return false;
	}
	
	if (!reEmpty.test(paypalForm.postcode.value)){
		alert("Debe introducir su código postal");
		paypalForm.postcode.focus();
		return false;
	}
}