function onLoad()
{
  // jQuery.noConflict();

// alert("VERSION="+document.myform["VERSION"].value);

  if(document.myform["ASSURES"].selectedIndex<=1)
    {
    document.getElementById('LIBELCONJOINT').style.color="#C0C0C0";// Grisé
    document.getElementById('LIBELANS').style.color="#C0C0C0";
    document.getElementById('REGIME2').disabled=true;
    document.getElementById('AGE2').disabled=true;
    document.getElementById('DNAIS2').disabled=true;
    }
  else
    {
    document.getElementById('LIBELCONJOINT').style.color="#B82195"; // Violet couleur santé
    document.getElementById('LIBELANS').style.color="#000000";
    document.getElementById('REGIME2').disabled=false;
    document.getElementById('AGE2').disabled=false;
    document.getElementById('DNAIS2').disabled=false;
    }

  if(document.myform["REGIME1"].selectedIndex!=2 && document.myform["REGIME2"].selectedIndex!=2)
    {

    document.getElementById('TR_MADELIN').style.display='none';
    document.getElementById('TR_DEBEXER').style.display='none';
    document.getElementById('TR_FINEXER').style.display='none';

    document.getElementById('LIBELMADELIN').style.color="#C0C0C0";// Grisé
    document.getElementById('LIBELOUI').style.color="#C0C0C0";// Grisé
    document.getElementById('LIBELNON').style.color="#C0C0C0";// Grisé
    document.getElementById('LIBELDEXER').style.color="#C0C0C0";
    document.getElementById('LIBELFEXER').style.color="#C0C0C0";

    document.getElementById('DEBUTEXER').disabled=true;
    document.getElementById('FINEXER').disabled=true;

    }
  else
    {

    document.getElementById('TR_MADELIN').style.display='block';
    document.getElementById('TR_DEBEXER').style.display='block';
    document.getElementById('TR_FINEXER').style.display='block';

    document.getElementById('LIBELMADELIN').style.color="#000000";
    document.getElementById('LIBELOUI').style.color="#000000";
    document.getElementById('LIBELNON').style.color="#000000";
    document.getElementById('LIBELDEXER').style.color="#000000";
    document.getElementById('LIBELFEXER').style.color="#000000";

    document.getElementById('DEBUTEXER').disabled=false;
    document.getElementById('FINEXER').disabled=false;
    }

/*
  if(document.myform["QUESTION6"][0].checked)
    document.getElementById('LES6QUESTIONS').style.display='block';
  else
    document.getElementById('LES6QUESTIONS').style.display='block';
*/

  // Suppression du Questionnaire comportement à partir de la version V7
  if(parseInt(document.myform["VERSION"].value,10)<=6)
    {
    	
    if(document.myform["QUESTION6"][0].checked)
      AjustQuestion6('ON');
    else
  	  {
      Nav = navigator.appName;
      Ver = navigator.appVersion;
      Ver = Ver.substr(Ver.indexOf(';')+2,6);
      Ver=parseInt(Ver.substr(5,1),10);

      // Suppression du Questionnaire comportement à partir de la version V7
      if(Nav=="Microsoft Internet Explorer" && Ver>=1)
        {
        AjustQuestion6('ON');
        document.myform["QUESTION6"][0].checked=true;
        }
      else
        AjustQuestion6('OFF');
      }
    
/*   
    Ajustscorereduc();
*/

    }
  else
    AjustQuestion6('OFF');
      
}

function verifForm()
{
	 Agemin=18;
	 Agemax=65;
	 
   if(document.myform["ASSURES"].selectedIndex==0)
      {
      alert("Veuillez choisir les personnes à garantir");
      document.myform["ASSURES"].focus();
      return false;
      }
   if(document.myform["AGE1"].value=="")
      {
      alert("Veuillez indiquer votre âge");
      document.myform["AGE1"].select();
      return false;
      }
   if(parseInt(document.myform["AGE1"].value,10)==0)
      {
      alert("Veuillez indiquer votre âge");
      document.myform["AGE1"].select();
      return false;
      }
   if(parseInt(document.myform["AGE1"].value,10)<Agemin)
      {
      alert("Age minimum autorisé : "+Agemin+" ans");
      document.myform["AGE1"].select();
      return false;
      }
   if(parseInt(document.myform["AGE1"].value,10)>Agemax)
      {
      alert("Age minimum autorisé : "+Agemax+" ans");
      document.myform["AGE1"].select();
      return false;
      }

   if(document.myform["REGIME1"].selectedIndex==0)
      {
      alert("Veuillez indiquer votre régime d'affiliation");
      document.myform["REGIME1"].focus();
      return false;
      }

   if(document.myform["ASSURES"].selectedIndex==2)
      {
      if(document.myform["AGE2"].value=="")
         {
         alert("Veuillez indiquer l'âge du conjoint");
         document.myform["AGE2"].select();
         return false;
         }
      if(parseInt(document.myform["AGE2"].value,10)==0)
         {
         alert("Veuillez indiquer l'âge du conjoint");
         document.myform["AGE2"].select();
         return false;
         }
      if(parseInt(document.myform["AGE2"].value,10)<Agemin)
         {
         alert("Age minimum du conjoint : "+Agemin+" ans");
         document.myform["AGE2"].select();
         return false;
         }
      if(parseInt(document.myform["AGE2"].value,10)>Agemax)
         {
         alert("Age maximum du conjoint : "+Agemax+" ans");
         document.myform["AGE2"].select();
         return false;
         }
      if(document.myform["REGIME2"].selectedIndex==0)
         {
         alert("Veuillez indiquer le régime d'affiliation du conjoint");
         document.myform["REGIME2"].focus();
         return false;
         }
      }

   if(document.myform["DPT"].selectedIndex==0)
      {
      alert("Veuillez indiquer votre département d'habitation");
      document.myform["DPT"].focus();
      return false;
      }

   if(document.myform["NBENFANTS"].selectedIndex==0)
      {
      alert("Veuillez indiquer le nombre d'enfants à charge à assurer");
      document.myform["NBENFANTS"].focus();
      return false;
      }
      
   return true;
}

function AjustConjoint()
{
  if(document.myform["ASSURES"].selectedIndex>0)
    {
    if(document.myform["ASSURES"].selectedIndex==1)
      {
      document.getElementById('LIBELCONJOINT').style.color="#C0C0C0";
      document.getElementById('LIBELANS').style.color="#C0C0C0";
      document.myform["DNAIS2"].value="jj/mm/aaaa";
      document.myform["AGE2"].value="";
      document.myform["REGIME2"].selectedIndex=0;
      document.myform["DNAIS2"].disabled=true;
      document.myform["AGE2"].disabled=true;
      document.myform["REGIME2"].disabled=true;
      }
    else
      {
      document.getElementById('LIBELCONJOINT').style.color="#B82195";
      document.getElementById('LIBELANS').style.color="#000000";
      document.myform["DNAIS2"].disabled=false;
      document.myform["AGE2"].disabled=false;
      document.myform["REGIME2"].disabled=false;
      }
    
      
    }
    
  else
  	{
    document.getElementById('LIBELCONJOINT').style.color="#C0C0C0";
    document.getElementById('LIBELANS').style.color="#C0C0C0";
    document.myform["DNAIS2"].value="jj/mm/aaaa";
    document.myform["AGE2"].value="";
    document.myform["REGIME2"].selectedIndex=0;
    document.myform["DNAIS2"].disabled=true;
    document.myform["AGE2"].disabled=true;
    document.myform["REGIME2"].disabled=true;
  	}

  AjustLibelTNS();
   
}

function AjustLibelTNS()
{
  if(document.myform["REGIME1"].selectedIndex==2 || (document.myform["ASSURES"].selectedIndex==2 && document.myform["REGIME2"].selectedIndex==2))
    {

    document.getElementById('TR_MADELIN').style.display='block';
    document.getElementById('TR_DEBEXER').style.display='block';
    document.getElementById('TR_FINEXER').style.display='block';

//    document.getElementById('LIBEL_TNS').style.display='block';

    document.getElementById('LIBEL_TNS').innerHTML="<br>En tant que Travailleur Non Salarié, vous bénéficiez d'une réduction de 10% du tarif d'assurance.";
    document.getElementById('LIBELMADELIN').style.color="#000000";
    document.getElementById('LIBELOUI').style.color="#000000";
    document.getElementById('LIBELNON').style.color="#000000";

//    document.getElementById('LIBELDEXER').style.color="#000000";
//    document.getElementById('LIBELFEXER').style.color="#000000";

//    document.getElementById('DEBUTEXER').disabled=false;
//    document.getElementById('FINEXER').disabled=false;

    }
  else
  	{

    document.getElementById('TR_MADELIN').style.display='none';
    document.getElementById('TR_DEBEXER').style.display='none';
    document.getElementById('TR_FINEXER').style.display='none';

//    document.getElementById('LIBEL_TNS').style.display='none';

    document.getElementById('LIBEL_TNS').innerHTML="<br>&nbsp;";
  
    document.getElementById('LIBELMADELIN').style.color="#C0C0C0";// Grisé
    document.getElementById('LIBELOUI').style.color="#C0C0C0";// Grisé
    document.getElementById('LIBELNON').style.color="#C0C0C0";// Grisé
    document.getElementById('LIBELDEXER').style.color="#C0C0C0";// Grisé
    document.getElementById('LIBELFEXER').style.color="#C0C0C0";// Grisé

    document.myform["MADELIN"][1].checked=true;
    document.myform["DEBUTEXER"].value="0101";
    document.myform["FINEXER"].value  ="3112";

    document.getElementById('DEBUTEXER').disabled=true;
    document.getElementById('FINEXER').disabled=true;

    }
}

function AjustDebFin(f)
{
  if(f=="ON")
    {
    if(document.myform["REGIME1"].selectedIndex==2 || document.myform["REGIME2"].selectedIndex==2)
      {
      document.getElementById('LIBELDEXER').style.color="#000000";
      document.getElementById('LIBELFEXER').style.color="#000000";
      document.getElementById('DEBUTEXER').disabled=false;
      document.getElementById('FINEXER').disabled=false;
      }
    else
    	document.myform["MADELIN"][1].checked=true;
    }
  else
  	{
    document.getElementById('LIBELDEXER').style.color="#C0C0C0";// Grisé
    document.getElementById('LIBELFEXER').style.color="#C0C0C0";// Grisé
    document.myform["DEBUTEXER"].value="0101";
    document.myform["FINEXER"].value  ="3112";
    document.getElementById('DEBUTEXER').disabled=true;
    document.getElementById('FINEXER').disabled=true;
    }
}

function AjustQuestion6(f)
{
  if(f=="ON")
    {
    document.getElementById('LES6QUESTIONS').style.display='block';
    }
  else
  	{
    document.getElementById('LES6QUESTIONS').style.display='none';
    document.myform['SCORE1'].value=0;
    document.myform['SCORE2'].value=0;
    document.myform['SCORE3'].value=0;
    document.myform['SCORE4'].value=0;
    document.myform['SCORE5'].value=0;
    document.myform['SCORE6'].value=0;
    }
}

function Ajustscorereduc()
{
/*	
  score=0;
  for(i=1;i<=6;i++)
     score=score+parseInt(document.myform['SCORE'+i].value,10);
  if(score<=20)
     if(document.myform["QUESTION6"][0].checked)
       document.getElementById('SCOREREDUC').innerHTML="* Votre profil comportement ne vous permet de bénéficier d'aucune réduction.";
     else
       document.getElementById('SCOREREDUC').innerHTML="* Vous n'avez pas complété votre profil comportement, vous ne bénéficiez d'aucune réduction.";
  else if(score<=30)
     document.getElementById('SCOREREDUC').innerHTML="* Votre profil comportement vous permet de bénéficier d'une réduction de tarif de 3 %.";
  else if(score<=40)
     document.getElementById('SCOREREDUC').innerHTML="* Votre profil comportement vous permet de bénéficier d'une réduction de tarif de 6 %.";
  else if(score<=50)
     document.getElementById('SCOREREDUC').innerHTML="* Votre profil comportement vous permet de bénéficier d'une réduction de tarif de 9 %.";
  else if(score<=60)
     document.getElementById('SCOREREDUC').innerHTML="* Votre profil comportement vous permet de bénéficier d'une réduction de tarif de 12 %.";
  else
     document.getElementById('SCOREREDUC').innerHTML="* Vous n'avez pas complété votre profil comportement, vous ne bénéficiez d'aucune réduction.";
*/     
}

function validate_DATE_NAIS(strIn,strRef,n)
{
   var xDate,CurDate,CurMonth,CurYear,intDumm,Jour,Mois,An,strWork;
   var mValues = "312831303130313130313031";
   var lastDate = 0;
   var Bage1,Bage2;

   strEffet=document.myform["DATE_EFFET"].value;

   if(document.myform[strRef].value=="jjmmaa")
      return false;

   if(strIn.length>0)
   {
      if(n<=2)
         {
         Bage1=18;
         Bage2=80;

         }
      else
         {
         Bage1=0;
         Bage2=26;
         }
   if (ControlDate(strRef, document.myform, 'jj/mm/aaaa'))
      {
         strIn=document.myform[strRef].value ;
         ret = getAge2(strIn,strEffet);
         
         AA = ret.substr(0,ret.indexOf(';'))
         MM = ret.substr(ret.indexOf(';')+1,999)

         if(AA>=Bage1 && AA<=Bage2)
         {
            
            switch(n)
              {
              case 1:
                     document.myform["AGE1"].value=AA;
                     break;
              case 2:
                     document.myform["AGE2"].value=AA;
                     break;
              }
/*         	
            if(Madelin=="OUI")
            {

               switch(n)
               {
               case 1:
                      {
                      document.myform["REGIME1"].options[2].selected = true;
                      break;
                      };
               case 2:
                      {
                      document.myform["REGIME2"].options[2].selected = true;
                      break;
                      };
               case 3:
                      {
                      document.myform["REGIME3"].options[2].selected = true;
                      break;
                      };
               case 4:
                      {
                      document.myform["REGIME4"].options[2].selected = true;
                      break;
                      };
               case 5:
                      {
                      document.myform["REGIME5"].options[2].selected = true;
                      break;
                      };
               case 6:
                      {
                      document.myform["REGIME6"].options[2].selected = true;
                      break;
                      };
               case 7:
                      {
                      document.myform["REGIME7"].options[2].selected = true;
                      break;
                      };
               case 8:
                      {
                      document.myform["REGIME8"].options[2].selected = true;
                      break;
                      };
               case 9:
                      {
                      document.myform["REGIME9"].options[2].selected = true;
                      break;
                      };
               case 10:
                      {
                      document.myform["REGIME10"].options[2].selected = true;
                      break;
                      };
               }
            }
*/            
         return true;
         }
      else
         {
         if(n<=2)
            {
                                alert("L'âge de l'adulte "+n+" doit être compris entre "+Bage1+" et "+Bage2+" ans");
                                  document.myform[strRef].value = "jj/mm/aaaa";
                                document.myform[strRef].select();
                                document.myform[strRef].focus();
                                return false;
            }
         else
            {
                                n=n-2;
                                alert("L'âge de l'enfant "+n+" doit être compris entre "+1+" et "+Bage2+" ans");
                                  document.myform[strRef].value = "jj/mm/aaaa";
                                document.myform[strRef].select();
                                document.myform[strRef].focus();

            }
         }
      }

   }
   else
   {
/*alert("Taille DNAIS=0");*/
   }
   return true;
}

function getAge2(strIn,strEffet)
{
   var ind1,jj,mm,aaaa,CurDay,CurMonth,CurYear,CurDate,strAge,intTmp;
   var mmInt, CurmonthInt, jjInt, CurDayInt;
   
   CurDay = strEffet.substr(0,2);
   if ( CurDay.substr(0,1) == '0' )
      { 
      CurDay = CurDay.substr(1,999) 
      };

   CurMonth = strEffet.substr(3,2);
   if ( CurMonth.substr(0,1) == '0' )
      { 
      CurMonth = CurMonth.substr(1,999) 
      };
   CurYear = strEffet.substr(6,9999);

   ind1 = 3;

   jj = strIn.substr(0,2);
   if ( jj.substr(0,1) == '0' )
      { 
      jj = jj.substr(1,999) 
    };

   mm = strIn.substr(3,2);
   if ( mm.substr(0,1) == '0' )
      { 
      mm = mm.substr(1,999) 
      };
   aaaa = strIn.substr(6,9999);

   mmInt=parseInt(mm,10);
   CurMonthInt=parseInt(CurMonth,10);

   if (mmInt == CurMonthInt) 
      {
      intTmp = parseInt(CurYear,10) - parseInt(aaaa,10);

   jjInt=parseInt(jj,10);
   CurDayInt=parseInt(CurDay,10);
      
      if(CurDayInt<jjInt)
         {
         strAge = intTmp-1;
         strAge = strAge + ";11";
         }
      else
         strAge = intTmp + ";0";
      return strAge
      };
   if (mmInt < CurMonthInt)
      {
      intTmp = parseInt(CurYear,10) - parseInt(aaaa,10);
      strAge = intTmp;
      intTmp = parseInt(CurMonth,10) - parseInt(mm,10);
      strAge = strAge + ";" + intTmp;
      return strAge
      }  
   if (mmInt > CurMonthInt)
      {
      intTmp = eval(parseInt(CurYear,10) - parseInt(aaaa,10));
      intTmp = eval(intTmp - 1);
      strAge = intTmp;
      intTmp =  (parseInt(mm,10) - parseInt(CurMonth,10))
      intTmp = eval(parseInt('12',10) - intTmp);
      strAge = strAge + ";" + intTmp;
      return strAge
      }
}

//--- isLeapYear: verifie si l'annee est bisextile ---
function isLeapYear(Year)
{ 
	if (((Year % 4)==0) && ((Year % 100)!=0) || ((Year % 400)==0))
		return true;
	else 
		return false;
}

function IsJour(jour){
		vjour=parseInt(jour, 10);
		if (!isNaN(vjour)){if (vjour>0 && vjour<=31)return true;}
		return false;
		}
	
function IsMois(mois){
		vmois=parseInt(mois, 10);
		if (!isNaN(vmois)){if (vmois>0 && vmois<=12)return true;}
		return false;
		}
		
function convertAnnee(an){
	van=parseInt(an, 10);
	if (!isNaN(van)){
		if(van <=99)if (van>10)
				van+=1900;
				else
				van+=2000;
	}else van=-1;
	return van;
}		
		
//--- verifDate: fonction, verifie la validite d'une date selon son format ---
function ControlDate(monChamp, monFormul, monFormat, dateEffet, dateMin, dateMax)
{
	var DateC,maDate,fmat,d1,d2,d3,res,val
	var jourAnnee= new Array(31,28,31,30,31,30,31,31,30,31,30,31);
	monChamp=eval("document."+monFormul.name+"."+monChamp);
	maDate=monChamp.value;

	//--- Recuperation de la date courante ---
	if(window.DateActuelle==null){
	// --- A remplacer par la ligne du dessus
	dateC = new Date();
	anneeC = dateC.getYear();
	//--- Correctif pour netscape ---
	if (anneeC < 2000)
		anneeC+=1900;
	moisC = dateC.getMonth()+1;
	jourC = dateC.getDate(); 
	if (jourC<10)jourC="0"+jourC;
	if (moisC<10)moisC="0"+moisC;
	DateC=jourC+"/"+moisC+"/"+anneeC;
	// --- 
	}
	else
	{DateC = DateActuelle();}
	
	tDateC = DateC.split("/");
	res=true;
	msg="";	
	
	if (maDate==monFormat) return false;
	if (maDate==""){monChamp.value=monFormat;return false;}
	if ((monFormat=="jjmm")||(monFormat=="JJMM")||(monFormat=="jj/mm")||(monFormat=="JJ/MM")) fmat="jjmm";
	if ((monFormat=="MMAA")||(monFormat=="mmaa")||(monFormat=="mm/aa")||(monFormat=="MM/AA")||(monFormat=="mmaaaa")||(monFormat=="MMAAAA")||(monFormat=="mm/aaaa")||(monFormat=="MM/AAAA")) fmat="mmaa";
	if ((monFormat=="JJMMAA")||(monFormat=="jjmmaa")||(monFormat=="JJ/MM/AA")||(monFormat=="jj/mm/aa")||(monFormat=="JJMMAAAA")||(monFormat=="jjmmaaaa")||(monFormat=="JJ/MM/AAAA")||(monFormat=="jj/mm/aaaa")) fmat="jjmmaa";


	// décomposition de la date
	switch (maDate.length){
	case 4: d1=maDate.substr(0,2);d2=maDate.substr(2,2);
	break;
	case 6: if (fmat=="mmaa"){d1=maDate.substr(0,2);d2=maDate.substr(2,4);if(parseInt(d2.substr(0,2),10)<13){d1=d2.substr(0,2);d2=d2.substr(2,2);}}else{d1=maDate.substr(0,2);d2=maDate.substr(2,2);d3=maDate.substr(4,2);}
	break;
	case 3:
	case 5: dt= maDate.split("/");d1=dt[0];d2=dt[1];
	break;
	case 7: if (fmat=="jjmmaa"){dt= maDate.split("/");d1=dt[0];d2=dt[1];d3=dt[2];}else{dt= maDate.split("/");d1=dt[0];d2=dt[1];}
	break;
	case 8: if (maDate.indexOf('/')>1){dt=maDate.split("/");d1=dt[0];d2=dt[1];d3=dt[2];}else{d1=maDate.substr(0,2);d2=maDate.substr(2,2);d3=maDate.substr(4,4);}
	break;
	case 9 :
	case 10:dt= maDate.split("/");d1=dt[0];d2=dt[1];d3=dt[2];
	break;
	default :
	break;
	}
	
	// controle des éléments composant la date
	switch (fmat)
	{  
		case "jjmm": res=IsJour(d1)&&IsMois(d2);
		break;
		case "mmaa": 
		if(d3){res=IsJour(d1)&&IsMois(d2);d3=convertAnnee(d3);if(d3<0)res=false;}
		else{res=IsMois(d1);d2=convertAnnee(d2);if(d2<0)res=false;}
		break;
		case "jjmmaa":res=IsJour(d1)&&IsMois(d2);d3=convertAnnee(d3);if(d3<0)res=false;
		break;
		default :res=false;
		break;
	}
	if (!res) {msg="Veuillez entrer une date sous un format correct ("+monFormat+")";}
	
	d1=parseInt(d1,10);
	d2=parseInt(d2,10);
	d3=parseInt(d3,10);

	// controle de validite
	if (res) {
	switch (fmat)
	{  
		case "jjmm": 
				jourAnnee[1]+=1;
				if (d1>jourAnnee[d2-1]) res=false;
		break;

		case "jjmmaa": 
				if (isLeapYear(d3))jourAnnee[1]+=1;
				if (d1>jourAnnee[d2-1]) res=false;
		break;

	}
	if (!res) {msg="Limite invalide, controler la date";}
	}
	if (res) {
	// formatage
	switch (fmat)
		{
			case "jjmm":
			if (d1<10)d1="0"+d1;
			if (d2<10)d2="0"+d2;
			val= d1+"/"+d2;
			break;
			
			case "mmaa":
			if (d1<10)d1="0"+d1;
			val= d1+"/"+d2;
			break;
			
			case "jjmmaa":
			if (d1<10)d1="0"+d1;
			if (d2<10)d2="0"+d2;
			val=d1+"/"+d2+"/"+d3;
			break;

		}

	// controles spécifiques
		FAvt=(monFormul.name.indexOf("Avenant")>=0);
		if (dateEffet!=1)
		{
			if (CompareDate(val, DateC)>0)
			{
				msg="Limite invalide, controler la date";
				res=false;
			}
		}
		else 
		{	temp = 0;
			if (dateMin) temp = dateMin.split("/");
			if (temp.length!=3)
			{
				if (CompareDate(val, DateC)<0)
				{
					msg="La date ne peut pas être antérieure à celle d'aujourd'hui";
					res=false;
				} 
			}
			else
			{
				if (CompareDate(val, dateMin)<0)
				{
					if(FAvt)msg=("Date d'effet au "+val+" impossible par internet.\n\nDate d'effet possible entre le "+dateMin+" et le  "+dateMax+" \n\nPour enregistrer votre avenant en dehors de cette période, \nVeuillez nous adresser votre demande par courrier.");
					else msg="La date ne peut pas être antérieure à "+dateMin;
					res=false;
				}
				}
				if (dateMax){
				temp = dateMax.split("/");
				if (temp.length==3)
				{
					if (CompareDate(val, dateMax)>0)
					{
						if(FAvt)msg=("Date d'effet au "+val+" impossible par internet.\n\nDate d'effet possible entre le "+dateMin+" et le  "+dateMax+" \n\nPour enregistrer votre avenant en dehors de cette période, \nVeuillez nous adresser votre demande par courrier.");
						else msg="La date ne peut pas être supérieure à "+dateMax;
						res=false;
					}
				}
				}else {
					TotMoisC= parseInt(tDateC[2],10)*12+parseInt(tDateC[1],10)+2;
					switch (fmat)
				{						
					case "mmaa":
					
					TotMois=d2*12+parseInt(d1,10);
					if  (TotMois > TotMoisC )
					{
					   msg="La date saisie ne peut être postérieure de plus de 2 mois à la date d'aujourd'hui.";
					   res=false;
					}break;
					case "jjmmaa":
					TotMois=d3*12+parseInt(d2,10);
					if  (TotMois > TotMoisC || (TotMoisC == TotMois && d1 > tDateC[0]))
					{
					   msg="La date saisie ne peut être postérieure de plus de 2 mois à la date d'aujourd'hui.";
					   res=false;
					}break;
				}
			}
		}

	}
	if (!res)
	{
		if (msg!="") alert(msg);
		monChamp.value=monFormat;
		monChamp.select();
		monChamp.focus();
		
	}
	else
	monChamp.value=val;
	
	return (res);
}


function Retour(){
	window.history.go(-1)
}

function CtrlSurDate(myObj)
{//Controle de la date pour paiement par cheque 
	var date1,date2,temp1,temp2,a1,a2,m1,m2,j1,j2,ecart;
	//date courante 
	dateeffet=myObj.form.DATE_EFFET
	date1 = new Date();
	j1 = date1.getDate();
	m1 = date1.getMonth();
	a1 = date1.getFullYear();
	
	if ( dateeffet.value == '' || dateeffet.value == 'jj/mm/aaaa' )
	{
		myObj.checked = false;
		alert( "Saisissez votre date d'effet");
		dateeffet.focus();
        return;
	}
	else
	 if (myObj.value!="CB")
	{
		strdate2 = dateeffet.value;
		 
		temp2 = strdate2.split('/'); 
		j2 = parseInt(temp2[0],10);
		m2 = parseInt(temp2[1],10) - 1;
		a2 = parseInt(temp2[2],10);
	
		date2 = new Date() ;
		date2.setUTCFullYear(a2,m2,j2);
	
		ecart = (date2.valueOf() - date1.valueOf())/86400000;
	
		//alert( "j2" + j2 + "m2" + m2 + "a2" + a2);
		//alert(ecart);
		if ( ecart < 15 )
		{
			myObj.checked = false;
			dateeffet.focus();
			alert("La date d'effet choisie est inférieure à 15 jours. Veuillez choisir une date superieure ou choisissez CB");
		}
	}
}

///////////////////////////
// Sous-routines de calcul
function FormatDateMA(Mois, Annee)
{
   var result;
   
   if(Mois<10)
     result="0" + Mois+"/"+Annee;
   else   
     result=""+Mois+"/"+Annee;
   return result;
}

function AddDateMA(strIn1, strIn2)
{
   var ind1,mm1,aa1,mm2,aa2;
   ind1 = strIn1.indexOf('/');
   mm1 = strIn1.substr(0,ind1);
   aa1 = strIn1.substr(ind1+1,9999);
   ind1 = strIn2.indexOf('/');
   mm2 = strIn2.substr(0,ind1);
   aa2 = strIn2.substr(ind1+1,9999);
   mm1=parseInt(mm1, 10)+parseInt(mm2,10);
   aa1=parseInt(aa1,10)+parseInt(aa2,10)+Math.floor((mm1-1)/12);
   mm1-=Math.floor((mm1-1)/12)*12;
   return FormatDateMA(mm1, aa1);
}
 
function DiffDateMA(strIn1,strIn2)
{
   var ind1,mm1,aa1,mm2,aa2;
   ind1 = strIn1.indexOf('/');
   mm1 = strIn1.substr(0,ind1);
   aa1 = strIn1.substr(ind1+1,9999);
   ind1 = strIn2.indexOf('/');
   mm2 = strIn2.substr(0,ind1);
   aa2 = strIn2.substr(ind1+1,9999);
   mm1=parseInt(mm1, 10)-parseInt(mm2,10);
   aa1=parseInt(aa1,10)-parseInt(aa2,10)+Math.floor((mm1-1)/12);
   mm1-=Math.floor((mm1-1)/12)*12;
   return FormatDateMA(mm1, aa1);
}

function CompareDateMA(strIn1, strIn2)
{
	return CompareDate(strIn1, strIn2);
}

function CompareDate(strIn1, strIn2)
{
   var ind1,mm1,aa1,mm2,aa2;
   td1 = strIn1.split('/');
   td2 = strIn2.split('/');
   l1=td1.length;
   l2=td2.length;
   if (l1==3)jj1 = td1[0];else jj1 = 0;
   mm1 = td1[l1-2];
   aa1 = td1[l1-1];
   if (l2==3)jj2 = td2[0];else jj2 = 0;
   mm2 = td2[l2-2];
   aa2 = td2[l2-1];
   if ( (aa1-aa2) > 0 ) { return 1 };
   if ( (aa1-aa2) < 0 ) { return -1 };
   if ( (mm1-mm2) > 0 ) { return 1 };
   if ( (mm1-mm2) < 0 ) { return -1 };
   if ( (jj1-jj2) > 0 ) { return 1 };
   if ( (jj1-jj2) < 0 ) { return -1 };
   return 0;
}


function GetCurDateMA()
{
  var CurDate;
	
	if(window.DateActuelle==null){
	// --- A remplacer par la ligne du dessus
	CurDate = new Date();
	An = CurDate.getFullYear();
	//--- Correctif pour netscape ---
	if (An < 2000)
		An+=1900;
	mois = CurDate.getMonth()+1;
	if (mois<10)mois="0"+mois;

	}
	else
	{CurDate = DateActuelle();
		tDateC = CurDate.split("/");
		An=tDateC[2];
		mois=tDateC[1];
	}
  return (mois+"/"+An);
}

function DifMois(myDate1,myDate2)
{
	var temp1,temp2, res;
	var monMois1, monAnnee1;
	var monMois2, monAnnee2;

	//--- Recuperation des informations sur la date de naissance ---
	temp1 = myDate1.split('/');
	if (temp1.length==3){
	monMois1 = parseInt(temp1[1],10);
	monAnnee1 = parseInt(temp1[2],10);
	}else{
	monMois1 = parseInt(temp1[0],10);
	monAnnee1 = parseInt(temp1[1],10);
	}
	temp2 = myDate2.split('/');
	if (temp2.length==3){
	monMois2 = parseInt(temp2[1],10);
	monAnnee2 = parseInt(temp2[2],10);
	}else{
	monMois2 = parseInt(temp2[0],10);
	monAnnee2 = parseInt(temp2[1],10);
	}
	if (monMois1==monMois2)
		res = (monAnnee1-monAnnee2)*12;
	else
		if (monMois2 < monMois1)
			res = (monAnnee1-monAnnee2)*12+(monMois1-monMois2);
		else
			res = (monAnnee1-monAnnee2-1)*12+(12-monMois2+monMois1);
	return res;
}

/* Date au format jj/mm/aaaa */
function AddDateJJ(DateIn, JJ)
{
   var ind,jj,mm,aaaa;
	 var jourAnnee= new Array(31,28,31,30,31,30,31,31,30,31,30,31);
   
   jj = parseInt(DateIn.substr(0,2),10);
   mm = parseInt(DateIn.substr(3,2),10);
   aaaa = parseInt(DateIn.substr(6,4),10);

   for(i=0;i<JJ;i++)
      {
      if(isLeapYear(aaaa))
         jourAnnee[1]=29;
      else
         jourAnnee[1]=28;
      jj+=1;
      if(jj>jourAnnee[mm-1])
         {
         jj=1;
         mm+=1;
         if(mm>12)
            {
            mm=1;
            aaaa+=1;
            }
         }
      }
   
   DateOut=Padding(jj,2,"0")+"/"+Padding(mm,2,"0")+"/"+Padding(aaaa,4,"0")
   return DateOut;
}

function Padding(v,n,c)
{
	 sv=String(v);
	 res="";
   for(i=0;i<n-sv.length;i++)
      res=res+c;
   res=res+sv;
   return(res);
}	

//-->
