/**
 * contact_validate.js
 *
 * @author		Jonathan Pitre
 * @description	This script verifies the input for contact information on the www.builditsoftware.com
 *				website. It contains a single method, validate, which returns true if the forms are
 *				correctly filled and false otherwise.
 * @changelog
 * --------------------------------------------------------------------------------------------------
 * Jonathan Pitre		21/06/2011	Final release of script.
 * --------------------------------------------------------------------------------------------------
 */

/*
 * Returns true if the forms are correctly filled and false otherwise.
 */
function validate(){
	var name=document.forms["contactform"]["name"].value;
	var company=document.forms["contactform"]["company"].value;
	var phone=document.forms["contactform"]["phone"].value;
	var email=document.forms["contactform"]["email"].value;
	if (name==null || name=="")
	{
		alert("Please enter your name.");
		return false;
	}
	if (company==null || company=="")
	{
		alert("Please enter your company.");
		return false;
	}
	if (phone==null || phone=="")
	{
		alert("Please enter your phone number.");
		return false;
	}
	if (email==null || email=="")
	{
		alert("Please enter your email address.");
		return false;
	}
	// The following REGEX has been written by Arluison Guillaume and is said to match 99.96% of emails used today.
	var emailFilter = /^[-a-z0-9~!$%^&*_=+}{\'?]+(\.[-a-z0-9~!$%^&*_=+}{\'?]+)*@([a-z0-9_][-a-z0-9_]*(\.[-a-z0-9_]+)*\.(aero|arpa|biz|com|coop|edu|gov|info|int|mil|museum|name|net|org|pro|travel|mobi|[a-z][a-z])|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,5})?$/i;
	if (!emailFilter.test(email)){
		alert("Please provide a valid email address.");
		return false;
	}
	return true;
}

/*
 * Returns true if the forms are correctly filled and false otherwise. Displays the message in french.
 */
function validate_fr(){
	var name=document.forms["contactform"]["name"].value;
	var company=document.forms["contactform"]["company"].value;
	var phone=document.forms["contactform"]["phone"].value;
	var email=document.forms["contactform"]["email"].value;
	if (name==null || name=="")
	{
		alert("Veuillez entrer votre nom.");
		return false;
	}
	if (company==null || company=="")
	{
		alert("Veuillez entrer votre entreprise.");
		return false;
	}
	if (phone==null || phone=="")
	{
		alert("Veuillez entrer votre numéro de téléphone.");
		return false;
	}
	if (email==null || email=="")
	{
		alert("Veuillez entrer votre adresse courriel.");
		return false;
	}
	// The following REGEX has been written by Arluison Guillaume and is said to match 99.96% of emails used today.
	var emailFilter = /^[-a-z0-9~!$%^&*_=+}{\'?]+(\.[-a-z0-9~!$%^&*_=+}{\'?]+)*@([a-z0-9_][-a-z0-9_]*(\.[-a-z0-9_]+)*\.(aero|arpa|biz|com|coop|edu|gov|info|int|mil|museum|name|net|org|pro|travel|mobi|[a-z][a-z])|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,5})?$/i;
	if (!emailFilter.test(email)){
		alert("Veuillez entrer une adresse courriel valide.");
		return false;
	}
	return true;
}
