//<script language="javascript">
//-----------------------------------------------------------------------------------------

var bool = true;

function isValid(frm)
//Vérifie les renseignements obligatoires
{
  //window.alert(frm.CodePostal.value.length);
  var iLongueur = frm.CodePostal.value.length;
  var sChaine = frm.CodePostal.value;
  var iPos = 0;
  var bOK = true;
  if ((iLongueur!=2) && (iLongueur!=5))
  {
    window.alert("La saisie du code postal est obligatoire sous la forme XX ou XXXXX");
    frm.CodePostal.focus();
	frm.CodePostal.select();
    return false;
  }
  
  while ((iPos<iLongueur) && (bOK))
  {
	bOK = ( (sChaine.charAt(iPos)<=9) && (sChaine.charAt(iPos)>=0));
	iPos++;
  }
  if (!(bOK))
  {
	window.alert("Le code postal ne doit comporter que des chiffres.");
    frm.CodePostal.focus();
	frm.CodePostal.select();
    return false;
  }
  
}

function checkCPNumber(txtCheck)
//vérifie les champs tel ou fax
{
	if ((bool) && (txtCheck.value.length>0))
	{
	  // On parcours la chaîne de texte du champ tel ou fax
	  for (i=0; i < txtCheck.value.length;i++)
	  {
	    // Si la chaîne comporte des caractères différents d'espace ou d'un chiffre
	    if (isNaN(txtCheck.value.charAt(i)))
	    {
	      // On l'indique à l'utilisateur
	        window.alert("Seuls les chiffres sont admis.");
	        bool = false;
	        txtCheck.focus();
	        txtCheck.select();
	      return false;
	    }
	  }
	} 
} 


function verif(email) 
{ // Email valide ?
	var arobase = email.indexOf("@");
	var point = email.lastIndexOf(".");
	if((arobase < 3)||(point + 2 > email.length) ||(point < arobase+3)) 
		return false;
	else
		return true;
 }
 
function test(nom,mail) 
{ // Vérifie le formulaire
	if (nom.value=="") 
	{ 
		alert('Nom requis !');
		nom.focus();
		return false;
	}
	if (!verif(mail.value)) 
	{ 
		alert('Email invalide !');
		mail.focus();
		return false ;
	}
	return true // envoie les champs
 }
 
 function ConfirmSuppVin(idVin,sRef) {
	var sMessage = "Voulez vous supprimer le vin ayant pour référence\n '" + sRef + "'?";
	
	var bRes = confirm(sMessage);
	
	if (bRes)
	{ // Clic sur OK
		window.location.href = 'vins.php?supp=Ok&idVin=' + idVin + '&';
	   //document.form.submit();
	}
	else
	{
		window.location.href = 'vins.php';
	}
}

//--------------------------------------------------------------------------------------
//</script>