var DateCourante=new Date;
var AnEnCours=DateCourante.getYear()
var MoisEnCours=DateCourante.getMonth()
if (MoisEnCours>6)
  {var AnneeLicence=AnEnCours+1;
  }else{
  var AnneeLicence=AnEnCours;}


	
	
	function MM_findObj(n, d) { //v3.0
  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); return x;
}

function Verif(champ,nb,min,max){
 if (nb!=''+nb) Message+='- '+champ+' doit contenir un nombre.\n';
 if (nb<min || max<nb) Message+='- '+champ+' doit contenir un nombre compris entre '+min+' et '+max+'.\n';
}

function CalculeDate(){
  Message=""
  LaAnnee=MM_findObj('Annee');
  LaAnnee=parseFloat(LaAnnee.value);
  Verif("Annee",LaAnnee,1920,AnneeLicence-6)
  LeMois=MM_findObj('Mois');
  LeMois=parseFloat(LeMois.value);
  Verif("Mois",LeMois,1,12)
  LeJour=MM_findObj('Jour');
  LeJour=parseFloat(LeJour.value);
  Verif("Jour",LeJour,1,31)
  if (Message) {alert('Les erreurs suivantes se sont produites :\n'+Message);
   LaDate=""
  }else{
   LaDate=(parseFloat(LaAnnee)*10000)+(parseFloat(LeMois)*100)+parseFloat(LeJour);
   return LaDate;}
}

function TrouveCat(x){
  var DateBase=AnneeLicence*10000+1231
  if (x<=DateBase-600000) {LaCat='Super Vétéran'; LeTarif=1;
  }	else {
  	if (x<=DateBase-500000) {LaCat='Vétéran'; LeTarif=1;
  	} else
  	  {if (x<=DateBase-190000) {LaCat='Senior'; LeTarif=1;
  	  } else {
  	  	if (x<=DateBase-170000) {LaCat='Junior'; LeTarif=2;
  		}else {
  		  if (x<=DateBase-150000) {LaCat='Cadet'; LeTarif=2;
  		  }else{
  		  	if (x<=DateBase-130000) {LaCat='Minime'; LeTarif=2;
  			}else {
  			  if (x<=DateBase-110000) {LaCat='Benjamin';	LeTarif=2;
  			  }else{LaCat='Poussin'; LeTarif=3;
	} } } } } } }
return LaCat; LeTarif;
}

function ChangeEtat(x){
	Etat=MM_findObj('Etat')
	Etat.value=x
}

function AnnonceEtat(){
	Etat=MM_findObj('Etat')
	alert(Etat.value)
}

function TrouveTarif(x){
 LaLicence="?"
	Etat=MM_findObj('Etat')
	if (Etat.value=="H") {VarTarif=2
	}else{VarTarif=x}
 switch(VarTarif)
 {case 1:
 	LaLicence='36 Euros';
   	break
  case 2:
 	LaLicence='18 Euros';
   	break
  case 3:
 	LaLicence='9 Euros';
   	break}
   	return LaLicence;
}

function Affiche(){
  CalculeDate()
  if (LaDate!="") {
     TrouveCat(LaDate)
     TrouveTarif(LeTarif)
     Cat=MM_findObj('Cat')
	 Cat.value=LaCat
     Prix=MM_findObj('Prix')
	 Prix.value=LaLicence}
        }

