function validate_email(field)
{
	with (field)
	{
		apos=value.indexOf("@");
		dotpos=value.lastIndexOf(".");
		return (apos > 0 && dotpos - apos > 1);
	}
}

function validate_postalCode(field)
{
	with(field) return (value == '' || value.search(/(^[0-9]{5})-([0-9]{4}$)/) >= 0 || value.search(/^[a-zA-Z][0-9][a-zA-Z](\s?)[0-9][a-zA-Z][0-9]$/) >= 0 || value.search(/(^[0-9]{5})/) >= 0);
}

function valide_champs(field)
{
	with(field) return (value != null && value != "");
}

function validate_form(thisform)
{
	var errmsg = '';
	try
	{
		var current_lang = (document.getElementById('current_lang') ? document.getElementById('current_lang').value : 'fra');
		with (thisform)
		{
			if(!valide_champs(nom))
			{
				if(!errmsg) nom.focus();
				errmsg += (current_lang == "fra" ? "Le nom est obligatoire!\n" : "The name is required!\n");
			}
			if(!valide_champs(entreprise))
			{
				if(!errmsg) entreprise.focus();
				errmsg += (current_lang == "fra" ? "L'entreprise est obligatoire!\n" : "The company is required!\n");
			}

			if(!validate_postalCode(postalCode))
			{
				if(!errmsg) postalCode.focus();
				errmsg += (current_lang == "fra" ? "Le code postal est invalide!\n" : "The postal code is not valid!\n");
			}
			if(!valide_champs(stateProvince))
			{
				if(!errmsg) stateProvince.focus();
				errmsg += (current_lang == "fra" ? "L'état/La province est obligatoire!\n" : "The State/Province is required!\n");
			}
			if(!valide_champs(country))
			{
				if(!errmsg) country.focus();
				errmsg += (current_lang == "fra" ? "Le pays est obligatoire!\n" : "The country is required!\n");
			}

			if (!valide_champs(email))
			{
				if(!errmsg) email.focus();
				errmsg += (current_lang == "fra" ? "Le courriel est obligatoire!\n" : "The Email is required!\n");
			}
			else if (!validate_email(email))
			{
				if(!errmsg) email.focus();
				errmsg += (current_lang == "fra" ? "Le courriel est invalide!\n" : "The Email is not valid!\n");
			}

			if(!valide_champs(referal))
			{
				if(!errmsg) referal.focus();
				errmsg += (current_lang == "fra" ? "Le champ entendu parlé est obligatoire!\n" : "The referal field is required!\n");
				referal.style.backgroundColor='red';
			}

		}
	}
	catch(ex)
	{
		errmsg = (current_lang == "fra" ? "Une erreur est survenue :\n\n" : "An error occured : \n\n") + ex.message;
	}
	if(errmsg) alert(errmsg);
	return errmsg == '';
}
