// JavaScript Document

/***********************************************
 * Declaration et affectation des variables
 * globales
 ***********************************************/

var nbCom = 1;
var nbPay = 1;
var i = 1;


/************************************************
 * but : enregistrer les variables maDate, nbCom
 * et nbPay dans les champs cachés du formulaire,
 * pour pouvoir les reutiliser avec le script ASP
 * (je n'ai pas trouvé d'autre méthode)
 ************************************************/

function validerForm() 
{
  var maDate;
  var dateJour = new Date();

// "sauvegarde" de la date

  maDate = dateJour.getDate() + '-';
  maDate += dateJour.getMonth() + 1 + '-'; // +1 parce que les mois commencent à 0 à Javascript-Land
  maDate += dateJour.getYear();
  
//  document.garantie.champDate.value = maDate;
  
// "sauvegarde" des variables nbCom et nbPay
  document.garantie.nbCom.value = nbCom;
  document.garantie.nbPay.value = nbPay;
  
// verification : est-ce que les variables ont les bonnes valeurs
//  window.alert(maDate + ' - ' + nbCom + ' - ' + nbPay);

// Verification : est-ce que les champs nomLabo, adresse,
// codePostal, téléphone, et signataire sont bien remplis ?


if ((document.garantie.nom.value != "") && (document.garantie.prenom.value != "") && (document.garantie.adresse1.value != "") && (document.garantie.codepostal.value != "") && (document.garantie.ville.value != "") && (document.garantie.tel.value != "")) 
   {
	

	if ((document.garantie.civilite[0].checked == false) && (document.garantie.civilite[1].checked == false) && (document.garantie.civilite[2].checked == false))
		{
		window.alert("Veuillez choisir une civilité"); 
		return;
		}
	
	if (document.garantie.datenaissance.value != "")
		{
		var exp=new RegExp("[0-9]{2}[\\/\\-/][0-9]{2}[\\/\\-/][0-9]{4}", "i");
		if ( exp.test(document.garantie.datenaissance.value) ) {}
		else {alert("Date de naissance incorrecte");
		return; }
		}
						
	if (document.garantie.codepostal.value == "")
		{
		window.alert("Veuillez indiquer votre code postal"); 
		return;
		}
	else
		{	
		var exp=new RegExp("[0-9]{5}", "i");
		if ( exp.test(document.garantie.codepostal.value) ) {}
		else {alert("Code postal incorrecte");
		return; }
		}				

	if (document.garantie.tel.value == "")
		{
		window.alert("Veuillez indiquer votre téléphone"); 
		return;
		}
	else
		{	
		var exp=new RegExp("[0-9]", "i");
		if ( exp.test(document.garantie.tel.value) ) {}
		else {alert("Numéro de téléphone incorrecte");
		return; }
		}				

	if (document.garantie.portable.value == "")
		{
		}
	else
		{	
		var exp=new RegExp("[0-9]", "i");
		if ( exp.test(document.garantie.portable.value) ) {}
		else {alert("Numéro de téléphone portable incorrecte");
		return; }
		}				

	if (document.garantie.email.value != "")
		{
		var lemot = "@"
		var exp=new RegExp("^[a-zA-Z0-9\-_]+[a-zA-Z0-9\.\-_]*@[a-zA-Z0-9\-_]+\.[a-zA-Z\.\-_]{1,}[a-zA-Z\-_]+","g");
		if ( exp.test(document.garantie.email.value) ) {}
		else {alert("Adresse Email incorrecte");
		return; }
		}

	if (document.garantie.dateachat.value == "")
		{
		window.alert("Vous n'avez pas rempli la date d'achat du lecteur"); 
		return;
		}
	else
		{	
		var exp=new RegExp("[0-9]{2}[\\/\\-/][0-9]{2}[\\/\\-/][0-9]{4}", "i");
		if ( exp.test(document.garantie.dateachat.value) ) {}
		else {alert("Date d'achat incorrecte");
		return; }
		}				
	
	if (document.garantie.numeroserie.value == "") 
		{
		window.alert("Veuillez saisir le numéro de série du lecteur"); 
		return;
		}
	if (document.garantie.numeroserie.value.length < 2) 
		{
		window.alert("Numéro de série du lecteur incorrecte"); 
		return;
		}
	
	if (document.garantie.numeroserie1.value == "") 
		{
		window.alert("Veuillez saisir le numéro de série du lecteur"); 
		return;
		}
	if (document.garantie.numeroserie1.value.length < 2) 
		{
		window.alert("Numéro de série du lecteur incorrecte"); 
		return;
		}
				
	if ((document.garantie.unitemesure[0].checked == false) && (document.garantie.unitemesure[1].checked == false))
		{
		window.alert("Vous n'avez pas selectionné d'unité de mesure"); 
		return;
		}


	{
	document.garantie.submit();
	}
							
	}
else
   {
    // si certains champs sont vides, on annule et on prévient
    window.alert ("Veuillez remplir les champs Civilité, Nom, Prénom, adresse, code postal, ville et téléphone");
   return;
   }

}

