// JavaScript Document

function validate(form_id,email) 
	{
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   var address = document.forms[form_id].elements[email].value;
   if(reg.test(address) == false) 
   	{
      alert('Adresse mail non valide');
      return false;
   }
}

function setCharCounter (a, b, n) {
var o = document.getElementById(a);
o.charCounterMax
= n;
o.charCounterDisplay = b;
o.onkeyup = charCounterUpdate;
}
function charCounterUpdate () {
var n = this.value.length;
if (n > this.charCounterMax)
{ 
alert("Vous ne pouvez pas dépasser " + this.charCounterMax + " caractères pour cette zone.");
return false;
}
if (this.charCounterDisplay)
{
var o = document.getElementById(this.charCounterDisplay);
if (o.tagName.toLowerCase()=="input") o.value = n;
else o.innerHTML = n;
}
}

function capaciteA(texte)
{
if (texte=="AUTRE")
document.getElementById("capaciteB").style.visibility= 'visible';
else
document.getElementById("capaciteB").style.visibility= 'hidden';
}

function packagingA(texte)
{
if (texte=="AUTRE")
document.getElementById("packagingB").style.visibility= 'visible';
else
document.getElementById("packagingB").style.visibility= 'hidden';
}

function quantiteA(texte)
{
if (texte=="AUTRE")
document.getElementById("quantiteB").style.visibility= 'visible';
else
document.getElementById("quantiteB").style.visibility= 'hidden';
}

function notEmpty(elem, helperMsg){
	if(elem.value.length == 0){
		alert(helperMsg);
		elem.focus();
		return false;
	}
	return true;
}
/***START*** FORMULAIRE CHECK VALUE ***START***/
function formValidator()
{
	/*alert('Test');*/
	var nom = document.getElementById('nom');
	var mail = document.getElementById('mail');
	var telephone = document.getElementById('telephone');
	var quantite = document.getElementById('quantite');
	var quantiteB = document.getElementById('quantiteB');
	var capacite = document.getElementById('capacite');
	var result = document.getElementById('result');
	
	if(isAlphanumeric(nom, "* Un Nom est obligatoire"))
	{
	if(mailValidator(mail, "* Un Email est obligatoire"))
		{
	if(isNumeric(telephone, "* Un Numero de telephone est obligatoire"))
			{
	if(selection(quantite, "* Vous devez choisir une quantité"))
				{
	if(minimum(quantiteB, "* Une quantité est obligatoire. Minimum 100"))
					{						
	if(selection(capacite, "* Vous devez choisir une capacité"))
						{
	if(isAlphanumeric(result, "* Vous devez entrer le code d'identification"))
							{
								return true;
							}
						}
					}
				}	
			}
		}
	}
	return false;
}

function notEmpty(elem, helperMsg)
{
	if(elem.value.length == 0)
	{
		alert(helperMsg);
		elem.focus(); 
		return false;
	}
	return true;
}

function isAlphanumeric(elem, helperMsg)
{
	var alphaExp = /^[0-9a-zA-Zéèùà'"&.#()`_-ê=+û*?;:!,§ç@°{}%µ£¤£&€^¨ ]+$/;
	if(elem.value.match(alphaExp))
	{
		return true;
	}
	else
	{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isNumeric(elem, helperMsg){
	var numericExpression = /^[0-9 ]+$/;
	if(elem.value.match(numericExpression)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function mailValidator(elem, helperMsg)
{
	var mailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(elem.value.match(mailExp))
	{
		return true;
	}
	else
	{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}
function selection(elem, helperMsg)
{
	if(elem.value == "n/c")
	{
		alert(helperMsg);
		elem.focus();
		return false;
	}
	else
	{
		return true;
	}
}
function minimum(elem, helperMsg)
{
	if(elem.value <= 99)
	{
		alert(helperMsg);
		elem.focus();
		return false;
	}
	else
	{
		return true;
	}
}

/***END*** FORMULAIRE CHECK VALUE ***END***/