/*
Fonction de Dreamweaver modifiée pour vérifier la validité des champs dans un formulaire
*/
<!--
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function Format_Tel(NumTel){
  var Tel;
  var i = 0;
  while (i < NumTel.length-1)
    {
    if ((NumTel.charAt(i) == ".")||(NumTel.charAt(i) == ",")||(NumTel.charAt(i) == "/")||(NumTel.charAt(i) == "-")||(NumTel.charAt(i) == " "))
      {
      Tel = NumTel.substring(0,i) + NumTel.substring(i+1,NumTel.length);
          NumTel = Tel; 
      }
      else{
      i++;
      }
    }
  return (NumTel);
}

function nbjours_mois(mois,annee)
{
/* cette fonction envoie le nombre de jours dans 1 mois.
il prend en compte les années bissextiles.
!!! l'année bissextile n'est pas vraiment juste !!!
il arrive tous les 400 ans si je ne me trompes pas qu'une année
divisible par 4 ne soit pas bissextile.. d'ici là on sera plus là :-))*/
  
  if ((mois==1)||(mois==3)||
    (mois==5)||(mois==7)||
    (mois==8)||(mois==10)||
    (mois==12))
  {
  return(31);
  }
  else if ((mois==4)||(mois==6)||
    (mois==9)||(mois==11))
  {
  return(30);
  }
  else if ((mois==2)&&(annee % 4 ==0))
  {
  return(29);
  }
  else
  {
  return(28);
  }

}

function date_valide(x,y,z)
{
/*
pour mes dates j'utilise 3 listes réroulantes (on peut utiliser aussi 3inputbox... il faut juste adapter si nécessaire.)
1 pour les jours, 1 pour les mois et 1 pour les années.
x = jours
y = mois
z = année
-------------------------------
Cette fonction envoie "True" si une date est valide
et dans le cas contraire "False".*/
  if ((x <= 31)&&(nbjours_mois(y,z)==31))
  {
  //return("True");
  return("T");
  }
  else if ((x <= 29)&&(nbjours_mois(y,z)==29))
  {
  return("T");
  }  
  else if ((x<=28)&&(nbjours_mois(y,z)==28))
  {
  return("T");
  }  
  else if ((x<=30)&&(nbjours_mois(y,z)==30))
  {
  return("T");
  }  
  else
  {
  return("F");
  }
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- Le champs '+nm+' doit contenir une adresse email valide.\n';
      } 

		else if ((test.charAt(0) == 'U')||(test.charAt(1) == 'U')) {
			
			if (val.substring(0,7)!='') {	
			test_pt = val.indexOf('.');
			if (val.substring(0,7)!='http://' || test_pt<1) {
            //alert("Pour continuer votre inscription, vous devez accepter le règlement !")
			//document.MM_returnValue = ('');
			errors += '- Le champs '+nm+' doit contenir un lien correct (http://).\n';
												}  
										}
										}
										
		else if (test.charAt(0) == 'T' || test.charAt(1) == 'T') {
			
			var Tel;
			Tel = Format_Tel(val);
			
				if ((Tel.length != 10)||isNaN(Tel)||((Tel.substring(0,2)!='01')&&(Tel.substring(0,2)!='02')&&(Tel.substring(0,2)!='03')&&(Tel.substring(0,2)!='04')&&(Tel.substring(0,2)!='05')&&(Tel.substring(0,2)!='06')&&(Tel.substring(0,2)!='08'))) { errors+='- Le champs '+nm+' doit contenir un numero de téléphone valide\n'; }

										}
										
		else if (test.charAt(0) == 'D' || test.charAt(1) == 'D') {
			
			var j,m,a;
			
			if (val.length != 10) { errors+='- Le champs '+nm+' doit contenir une date valide\n'; }
			else
			if ((isNaN(val.substring(0,2)))||(isNaN(val.substring(3,5)))||(isNaN(val.substring(6,10)))) { errors+='- Le champs '+nm+' doit contenir une date valide\n'; }
			else
			if ((val.substring(2,3)!="/")||(val.substring(5,6)!="/")) { errors+='- Le champs '+nm+' doit contenir une date valide\n'; }
			else
			if (date_valide(val.substring(0,2),val.substring(3,5),val.substring(6,10))=='F') { errors+='- Le champs '+nm+' doit contenir une date valide\n'; }
			}
										
		else if (test.charAt(0) == 'F') {
			
			var Fax;
			Fax = Format_Tel(val);
			
			if (Fax != '') {
				
				if ((Fax.length != 10)||isNaN(Fax)||((Fax.substring(0,2)!='01')&&(Fax.substring(0,2)!='02')&&(Fax.substring(0,2)!='03')&&(Fax.substring(0,2)!='04')&&(Fax.substring(0,2)!='05')&&(Fax.substring(0,2)!='06')&&(Fax.substring(0,2)!='08'))) { errors+='-Le champs '+nm+' doit contenir un numero de fax valide.\n'; }

							}
										 }
		
		else if ((test.charAt(1) == 'C')&&(test.charAt(2) == 'P')) {
			
			if ((val.length != 5)||(isNaN(val))||val=='') { errors+='- Le champs code postal doit contenir un code postal valide (5 chiffres).\n'; }

																	}

	  else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- Le champs '+nm+' est obligatoire.\n'; 
	
			
			}
  } 
  
  
  if (errors) alert('Erreur(s) rencontrée(s) :\n\n'+errors);
  document.MM_returnValue = (errors == '');
}
//-->

<!--
/*
Fonction de fermeture d'un popup et raffraichissement de la fenetre mere
*/
  function refresh(url){
  opener.location.href=url;
  self.close();
  };
//-->

function validbutton1(dd)
{
	window.open("calendrier/calendrier.asp?origine="+dd,"calendrier","width=215,height=170,top=120,left=120");
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
