  function pickupCP()
   { 
	if (isNaN(document.all["CP"].value))
      { alert("Vous devez entrer que des chiffres");
        document.all["CP"].value = '';
        return };
     if  ( (document.all["CP"].value >= 10 ) )
       {
	  tmpVal = document.all["CP"].value
	  strDeb = tmpVal.substr(0,2);
	  if ( (strDeb == 20 ) || (strDeb == 97) || (strDeb == 98) )
	   {
	     alert("Département interdit");
	     document.all["CP"].value = '';
             return false;
           }
       }
   
     if ( document.all["CP"].value >= 1000 )
       {
	    self.frames("CPVille").location.href = document.location.protocol + '//' + document.location.host + '/SollyAzar/DogCat/getVille.asp?CP=' + document.all('CP').value
       }
  return
 }



/***********************************************/
function isNumerique(strRef,strIn)
{
	if (isNaN(document.all(strRef).value))
	{	alert('Saisissez une valeur numérique');document.all(strRef).value=''; document.all(strRef).focus(); return false;}

//	isNaN(document.all(strRef).value))?alert('saisissez une valeur numérique');document.all(strRef).value=''; document.all(strRef).focus(); return false:alert("c bien un numérique!");


}


/***********************************************/
function set_Date_Naissance(strIn,strRef)
{	var res;

	if ( strIn.length == 0 ) { return true };

	if (ControlDate('DATE_NAISSANCE', document.formChienChat, 'jjmmaa'))
	{	//alert("ddn= " + document.formChienChat.DATE_NAISSANCE.value);
		var age= parseFloat(getAge(document.formChienChat.DATE_NAISSANCE.value,strRef));
		//alert("age= " + age);
				if ( age < parseFloat('0.03'))
				{	alert("Souscription impossible\n Animal trop jeune.");
					document.formChienChat.TRANCHE_AGE.value="0";
					document.formChienChat.DATE_NAISSANCE.value="jjmmaa";
					document.formChienChat.DATE_NAISSANCE.focus();
					return false;
				}
				else
				  if (age < parseFloat(7)) 
					{	// alert("Animal entre 3 mois et 6 ans...");
						document.formChienChat.TRANCHE_AGE.value="1";
					} 
					else 
					{ 
						if(document.formChienChat.ANIMAL.value=="CHIEN")
	             B=8.0;
	          else
	             B=11.0;
						if (age < parseFloat(B)) 
						{	// alert("Animal entre 6 et 9 ans...");
							document.formChienChat.TRANCHE_AGE.value="2";
						}
					else
						{	alert("Souscription immpossible\n Animal trop agé.");
							document.formChienChat.TRANCHE_AGE.value="3";
							document.formChienChat.DATE_NAISSANCE.value="jjmmaa";
							document.formChienChat.DATE_NAISSANCE.focus();
							return false;
						}
					}
//			}
		}
  else
		{	document.formChienChat[strRef].focus();
			return false;
		}
		return true;
}

/***********************************************/
function format_JJMMAA(strIn,strRef)
{
// strIn doit être au format JJMMAA

   var ind1,mm,aaaa,CurYear,CurMonth,CurDate,CurNb;
     
   if ( strIn.length == 0 ) { return true };

   CurDate = new Date();
   CurYear = CurDate.getYear();
   CurMonth = CurDate.getMonth()+1;
   CurDay = CurDate.getDay();

   if ( strIn.indexOf('/') == -1 ) 
   {
		if (strIn.length == 6)
	    {
			jj=strIn.substr(0,2);
			mm=strIn.substr(2,2);
			aaaa=strIn.substr(4,9999);
			CurNb = new Number(aaaa)
			if ( (aaaa < 100) && (aaaa >= 20 ) ) { CurNb  += 1900 }
			if ( (aaaa < 21) && (aaaa >= 0 ) ) {  CurNb  += 2000 }
			aaaa=CurNb ;
			strIn = jj + '/' + mm + '/' + aaaa; 
		}
	}

	else 
	{	if (strIn.length == 10) //format entré= jj/mm/aaaa
			{       
// 					return true;
			}

		else
			{
				if (strIn.length == 8) //format entré= jj/mm/aa
				{
				    jj=strIn.substr(0,2);
					mm=strIn.substr(3,2);
					aaaa=strIn.substr(6,9999);
//					alert("		strIn =" + jj + '/' + mm + '/' + aaaa); 
					CurNb = new Number(aaaa)
					if ( (aaaa < 100) && (aaaa >= 20 ) ) { CurNb  += 1900 }
					if ( (aaaa < 21) && (aaaa >= 0 ) ) {  CurNb  += 2000 }
					aaaa=CurNb ;
					strIn = jj + '/' + mm + '/' + aaaa; 
				}
	
			else
				{
					alert("Veuillez rentrer une date sous un format correct (JJMMAA)");
					document.all[strRef].value = '';
					document.all[strRef].focus();
					return false;
				}
  			}
	}

	document.formChienChat[strRef].value = strIn;
	return strIn;
}


/***********************************************/
 function isLeapYear (Year) 
{ 
	if (((Year % 4)==0) && ((Year % 100)!=0) || ((Year % 400)==0)) 
	{ return (true);} 
	else 
	{ return (false)}
}

/***********************************************/
function validate_JJMMAAAA(strIn,strRef)
{
// La date doit être au format JJ/MM/AAAA
   var xDate,CurDate,CurMonth,CurYear,intDumm,Jour,Mois,An,strWork;
   var mValues = "312831303130313130313031";
   var lastDate = 0;
   xDate = new Date();
   CurDate = xDate.getDate();
   CurMonth = xDate.getMonth()+1;
   CurYear = xDate.getYear()
   strWork = strIn

   if (( strIn.length == 0 ) || (document.formChienChat[strRef].value== ''))
	{ alert("Veuillez saisir une date"); 
	document.formChienChat(strRef).focus();
	return false };

   intDumm = strWork.indexOf('/');
   if ( intDumm == -1 )
   {
      alert("Veuillez rentrer une date sous la forme jj/mm/aaaa");
      return (false);
   }
   Jour = strWork.substr(0,intDumm);
   strWork = strWork.substr(intDumm+1,9999);
   intDumm = strWork.indexOf('/');
   if  ( intDumm == -1 )
   {
      alert("Veuillez rentrer une date sous la forme jj/mm/aaaa");
      return (false);
   }
   Mois = strWork.substr(0,intDumm);
   An = strWork.substr(intDumm+1,999)
   if ( (isNaN(Jour)) || (isNaN(Mois)) || ( isNaN(An)) )
   {
      alert("Veuillez rentrer une date cohérente: jj/mm/aaaa");
      return false;
   }
   if ( ((Jour > 31 )||(Jour < 1)) || ((Mois > 12)||(Mois < 1)) )
   {
      alert("Veuillez rentrer une date cohérente : jj/mm/aaaa");
      return false;
   }

   if ( (An > CurYear) || ( (An == CurYear)&&(Mois > CurMonth) ) || ( (An == CurYear)&&(Mois == CurMonth)&&(Jour > CurDate) ) )
   {
      alert("La date ne peut pas etre postérieure");
      return false;
   }
	
	// Check la validité de la future date 
   if (Mois == 2)
   {
     if (isLeapYear(An)) 
	 {
	    lastDate = 29
     }
     else
	 {
        lastDate = 28
     }
   } 
   else 
   {
      lastDate = mValues.substring((Mois-1)*2, (Mois-1)*2+2)
   }

   if ( (Jour > lastDate) )
   {
      alert("Date incohérente avec le calendrier");
      return false
   }
   return true;
}


/***********************************************/
function getAge(dateString,strRef)
{
	// Fonction qui calcule l'age en fonction de la date de naissance JJ/MM/AAAA


    var now = new Date();

	// Correctif pour Netscape
//    var yearNow = now.getYear();
//	if (yearNow < 2000)
//		yearNow+=1900;
//
//    var monthNow = now.getMonth();
//    var dateNow = now.getDate();
 var yearNow = parseInt(document.formChienChat.anneeC.value,10);
 var monthNow = parseInt(document.formChienChat.moisC.value,10);
 var dateNow = parseInt(document.formChienChat.jourC.value,10);
 var today = new Date(yearNow,monthNow,dateNow);


	var dob = new Date(dateString.substring(6,10),
                            dateString.substring(3,5)-1,
                            dateString.substring(0,2));

	
	var yearDob = dob.getFullYear(); //ne pas utiliser getYear qui renvoie année au format AA
    var monthDob = dob.getMonth()+1;
    var dateDob = dob.getDate();

	yearAge = yearNow - yearDob;

//	alert("yearDob= " + yearDob); 
//	alert("monthDob= " + monthDob);

    if (monthNow >= monthDob)
        var monthAge = monthNow - monthDob;
    else {
        yearAge--;
        var monthAge = 12 + monthNow -monthDob;
    }

    if (dateNow >= dateDob)
        var dateAge = dateNow - dateDob;
    else {
        monthAge--;
        var dateAge = 31 + dateNow - dateDob;

        if (monthAge < 0) {
            monthAge = 11;
            yearAge--; 
        }
    }
//	alert("yearDob= " + yearDob); 
//	alert("monthAge= " + monthAge);

	if (monthAge < 10) monthAge = "0" + monthAge;
	var age=yearAge.toString();
//	alert("monthAge= " + monthAge);
	document.formChienChat["AGE"].value = yearAge + "," + monthAge; //.substring(2,4);
    return yearAge + "." + monthAge;
}




/***********************************************/
function Checkdate(strIn,strRef)
 {
   var ind1,mm,aaaa,CurYear,CurMonth,CurDate,CurNb;
   if ( strIn.length == 0 ) { return true };
   CurDate = new Date();
   CurYear = CurDate.getYear();
   CurMonth = CurDate.getMonth()+1;

//	alert("JE SUIS DANS CHECKDATE");

   ind1 = strIn.indexOf('/');
   if ( ind1 == -1 ) 
   {
      if ( (strIn.length == 3) || (strIn.length == 5))
      {
         strIn = strIn.substr(0,1) + '/' + strIn.substr(1,9999); 
	  }
      else
	  {
	     if( (strIn.length == 4) || (strIn.length == 6))
		 {
		    strIn = strIn.substr(0,2) + '/' + strIn.substr(2,9999) 
         }
		 else
         {
            alert("Veuillez rentrer une date sous un format correct (MMAA)");
            document.all[strRef].value = '';
            return false;
         }
         document.all[strRef].value = strIn;
      }
   }
   ind1 = strIn.indexOf('/');
   mm = strIn.substr(0,ind1);
   if ( isNaN(mm) )
     {
        alert("Veuillez rentrer une date sous un format correct (MMAA)");
        document.all[strRef].value = '';
        return false;
     }
   if ( (mm > 12) || (mm < 1) )
     {
        alert("Veuillez rentrer une date sous un format correct (MMAA)");
        document.all[strRef].value = '';
        return false;
     }
   aaaa = strIn.substr(ind1+1,9999);
   CurNb = new Number(aaaa)
   if ( isNaN(aaaa) ) 
     {
        alert("Veuillez rentrer une date sous un format correct (MMAA)");
        document.all[strRef].value = '';
        return false;
     }


   if ( (aaaa > CurYear) || (aaaa < 1925) )
     {
        alert("Limite invalide, controler la date");
        document.all[strRef].value = '';
        return false;
     }
   if ( (aaaa == CurYear) && (mm > CurMonth) )
     {
        alert("Limite invalide, controler la date");
        document.all[strRef].value = '';
        return false;
     }
   if ( (mm < 10) && (mm.substr(0,1) != '0') )
        { document.all[strRef].value = '0' + mm +'/' + aaaa }
     else { document.all[strRef].value = mm + '/' + aaaa }
   return true;
 }



/***********************************************/
function validate_DATE_NAISSANCE(strIn,strRef)
{
   var ind1,mm,aaaa,CurYear,CurMonth,CurDate;

   if ( Checkdate(strIn,strRef) )
   {
      strIn=document.all[strRef].value;
      CurDate = new Date();
      CurYear = CurDate.getYear();
      CurMonth = CurDate.getMonth()+1;
      ind1 = strIn.indexOf('/');
      mm = Number(strIn.substr(0,ind1));
      aaaa = Number(strIn.substr(ind1+1,9999));
/*	  alert('aaaa=' + aaaa + '    mm=' + mm + '     CurYear=' + CurYear + '    CurMonth=' + CurMonth + '  	resmm=' + (mm+12*aaaa) + '    cur=' + (CurYear*12+CurMonth));*/
      if ( CurYear*12+CurMonth >= mm+12*(aaaa+13))
      {
         alert("Animal trop agé, tarification impossible");
         document.all[strRef].value = '';
         return false;
      };
      if ( CurYear*12+CurMonth < mm+12*aaaa )
      {
         alert("Limite invalide, contrôler la date");
         document.all[strRef].value = '';
         return false;
      };
	  document.formChienChat.AGE.value= getAge(strIn);
	  return true;
   };
   return false;
}



/***********************************************/
function validSubmit()
{
  
  with(document.formChienChat){
	if (DATE_NAISSANCE.value == '' )
   {
      alert("Veuillez renseigner le champ DATE de NAISSANCE de l'ANIMAL");
	  DATE_NAISSANCE.focus();
	  return 
   }
   else
   {
   		//if( !ControlDate('DATE_NAISSANCE', document.formChienChat, 'jj/mm/aaaa'))
      if( !set_Date_Naissance(DATE_NAISSANCE.value,'DATE_NAISSANCE'))
         return 
   }


   if (!(TATOUE[0].checked) && !(TATOUE[1].checked ))
   {
      alert("Veuillez indiquer si l animal est tatoué");
	  TATOUE[0].focus();
      return ;
   }


   if (TATOUE[1].checked)
   {
      alert("Seuls les animaux tatoués peuvent être assurés");
            return
   }


   if (!(PEDIGREE[0].checked) && !(PEDIGREE[1].checked ))
   {
      alert("Veuillez indiquer si l animal a un pédigrée");
	  PEDIGREE[0].focus();
            return
   }
   
   if (!(ATTAQUE[0].checked) && !(ATTAQUE[1].checked ) && (ANIMAL.value=='CHIEN'))
   {
      alert("Veuillez indiquer si il s'agit d'un chien de 1ère catégorie.");
	  ATTAQUE[0].focus();
      return
   }


   if (ATTAQUE[0].checked)
   {
      alert("Tarification impossible \n Animal de 1ère catégorie.");
            return
   }
   
   if (!(CHIRURGIE[0].checked) && !(CHIRURGIE[1].checked ))
   {
    alert("Veuillez indiquer si l animal a subi une intervention chirurgicale au cours des 6 derniers mois.");
	  CHIRURGIE[0].select();
	  CHIRURGIE[0].focus();
    return;
   }


   if (!(MALADE[0].checked) && !(MALADE[1].checked ))
   {
      alert("Veuillez indiquer si l animal est Malade");
	  MALADE[0].select();
	  MALADE[0].focus();
            return
   }

//   if ((MALADE[0].checked) && (MALADIE.value == ""))
//   {
//	  alert("Veuillez renseigner la MALADIE");
//	  MALADIE.select();
//	  MALADIE.focus();
//	        return
//   }

   if (!(SUIVI[0].checked) && !(SUIVI[1].checked ))
   {
      alert("Veuillez indiquer si l animal est suivi médicalement");
	  SUIVI[0].focus();
            return
   }

//   if ((SUIVI[0].checked) && (TRAITEMENT.value==""))
//   {
//      alert("Veuillez renseigner le TRAITEMENT SUIVI");
//	  SUIVI[0].focus();
//            return
//   }


   submit();
//   return true;
}}






//////////////////////////////////////////////////////////////////////////////
// onLoad()
function onLoad()
 {
	MM_preloadImages('/SuperAssureur/images/pucenoir.gif','/SuperAssureur/images/puce.gif');
	init_DATE_EFFET();
}


//////////////////////////////////////////////////////////////////////////////
// Fonctions Images 
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) { //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 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 validate_TCV(strIn,strRef)
 {
   if ( strIn > 30 || strIn < 0 )
    {
      alert("Le coeff varie entre 0 et 30");
      document.formChienChat[strRef].value = '';
      return  false;
    }
 return true;
}

///////////////////////////////////////////////////////////////////////////
// CheckdateJJMMAA, adaptation de Checkdate pour le format JJMMAA en utilisant verifDate
// ".select()" en commentaires suite à bug gestion des evenements de Netscape

function CheckdateJJMMAA(strIn,strRef)
 {
 	var ind1,jj, mm, aaaa, CurNb,strDate;
 
 	if ( strIn.length == 0 || strIn == "jjmmaa")
 		return true;
 	if ( (strIn.length != 6 && strIn.length != 8 && strIn.length != 10))
     {
     	alert("1.Veuillez entrer une date correcte (JJMMAA)"); //xxx
     	document.formChienChat[strRef].value='jjmmaa';
		document.formChienChat[strRef].focus();		
     	return false;
     }
 	ind1 = strIn.indexOf('/');
   	if ( ind1 == -1 ) 
    {
    	strIn = strIn.substr(0,2) + '/' + strIn.substr(2,2) + '/' + strIn.substr(4,9999);
    }
	jj = strIn.substr(0,2);
	mm = strIn.substr(3,2);
	aaaa = strIn.substr(6,9999);
	CurNb = new Number(aaaa)
	if ( (aaaa < 100) && (aaaa >= 20 ) ) { CurNb += 1900 }
	if ( (aaaa < 21) && (aaaa >= 0 ) ) {  CurNb += 2000 }
	aaaa = CurNb;

	alert('Coucou');

	strDate= jj+"/"+mm+"/"+aaaa;
 	var res=verifDate(strDate,"JJ/MM/AAAA");
	if (res=="0")
	{
		alert("Veuillez entrer une date correcte (JJMMAA)");
		document.formChienChat[strRef].value='jjmmaa';
		document.formChienChat[strRef].focus();
		return false;
	}
	else
		document.formChienChat[strRef].value=res;
	
	if ( (aaaa < 1925) )
	 {
	    alert("Limite invalide, controler la date");
		document.formChienChat[strRef].value='jjmmaa';
		// document.formChienChat[strRef].select();
	    return false;
	 }	
	return true;
 }


/////////////////////////////////////////////////////////////////////////// 
// Fonction pour les Dates

//--- verifDate: fonction, verifie la validite d'une date selon son format ---
// cette version de la fonction a été modifiée pour afficher moins de msg
function verifDate(maDate, monFormat)
{
	var monJour, monMois, monAnnee;
	var dateC, jourC, moisC, anneeC;
	var temp;
	var res=true;
	var jourAnnee= new Array(31,28,31,30,31,30,31,31,30,31,30,31);

	//--- Recuperation de la date courrante ---
	dateC = new Date();
	anneeC = dateC.getYear();
	//--- Correctif pour netscape ---
	if (anneeC < 2000)
		anneeC+=1900;
	moisC = dateC.getMonth()+1;
	jourC = dateC.getDate();
	
	//--- Verification suivant le format demande ---
	switch (monFormat)
	{
		case "MMAA":
			if (isNaN(parseInt(maDate, 10))||(maDate.length!=4))
			{
				// alert("Veuillez entrer une date sous un format correct ("+monFormat+")");
				res=false;
			}
			else
			{
				//--- Recuperation des informations sur la date ---
				monAnnee=parseInt(maDate, 10)%100;
				monMois=(parseInt(maDate, 10)-monAnnee)/100;
				
				//--- Passage l'annee au format AAAA (regle fixee par ctrlauto.js) ---
				if (monAnnee>20)
					monAnnee+=1900;
				else
					monAnnee+=2000;
				
				//--- Rejet des dates incorrects ---
				if ((monMois<1)||(monMois>12))
				{
					// alert("Veuillez entrer une date sous un format correct ("+monFormat+")");
					res=false;
				}
				else
					if ((monAnnee > anneeC)||((monAnnee==anneeC)&&(monMois>moisC)))
					{
						alert("Limite invalide, controler la date");
						res=false;
					}
			}
			break;
		case "JJ/MM/AAAA":
			temp = maDate.split("/");
			if (temp.length!=3)
			{
				// alert("Veuillez entrer une date sous un format correct ("+monFormat+")");
				res=false;
			}
			else
			{
				monJour=temp[0];
				monMois=temp[1];
				monAnnee=temp[2];
				if ((monJour.length!=2)||(monMois.length!=2)||(monAnnee.length!=4)||isNaN(parseInt(monJour,10))||isNaN(parseInt(monMois,10))||isNaN(parseInt(monAnnee,10)))
				{
					// alert("Veuillez entrer une date sous un format correct ("+monFormat+")");
					res=false;
				}
				else
				{
					//--- Rejet des dates incorrects ---
					if ((monMois<1)||(monMois>12))
					{
						// alert("Veuillez entrer une date sous un format correct ("+monFormat+")");
						res=false;
					}
					else
					{
/*						if ((monAnnee > anneeC)||((monAnnee==anneeC)&&(monMois>moisC)))
						{
							alert("Limite invalide, controler la date");
							res=false;
						}
						else
						{
*/							
						if (isLeapYear(monAnnee))
							jourAnnee[2]+=1;
						if ( (monJour<1) || (monJour>jourAnnee[monMois-1]) )
						{
							alert("Limite invalide, controler la date");
							res=false;
						}
/*						else
						{
							if ((monAnnee > anneeC) || ((monAnnee==anneeC)&&(monMois>moisC)) || ((monAnnee==anneeC)&&(monMois==moisC)&&(monJour>jourC)))
							{
								alert("Limite invalide, controler la date");
								res=false;
							}
						}
										
						} end Else monAnnee
*/						
					}
				}
			}
			break;
		default :
			res=false;
			break;
	}
	//--- Renvoi du resultat ---
	if (res)
	{
		switch (monFormat)
		{
			case "MMAA":
				temp=""+monMois;
				if (temp.length==1)
					temp="0"+monMois;
				temp+="/"+monAnnee;
				return temp;
				break;
			case "JJ/MM/AAAA":
				temp=""+monJour;
				if (temp.length==1)
					monJour="0"+monJour;
				temp=""+monMois;
				if (temp.length==1)
					monMois="0"+monMois;
				temp=monJour+"/"+monMois+"/"+monAnnee;
				return temp;
				break;
			default:
				break;
		}
	}
	else
		return "0";
}

function ChercheRaces(Codeinter)
{
 if(document.formChienChat.ANIMAL.options.selectedIndex==0)
    openWindow('vehiculeWindow','/pages/TarificationSouscription/RechercheRaces/frameRechercheRaces.htm',700,300,20,20);
 else
    alert("Concerne uniquement les chiens");
}