date=new Date;
date.setHours(date.getHours()+1);


function dodate()
{
var voyd =LireCookie("vdd");
var voym =LireCookie("vmm");
var voyy =LireCookie("vyy");
var depd =LireCookie("ddd");
var depm =LireCookie("dmm");
var depy =LireCookie("dyy");
var retd =LireCookie("rdd");
var retm =LireCookie("rmm");
var rety =LireCookie("ryy");

if (depd==null || retd==null || voyd==null) { 

	now = new Date();
	var m = now.getMonth();
	var d = now.getDate();
	var ann= now.getFullYear();

retd=depd=voyd=d-1;
voym=depm=retm=m;
voyy=depy=rety=ann;

}

	document.formgrp.voymm.selectedIndex = voym;
	document.formgrp.depmm.selectedIndex = depm;
	document.formgrp.retmm.selectedIndex = retm;
	document.formgrp.voydd.selectedIndex = voyd;
	document.formgrp.depdd.selectedIndex = depd;
	document.formgrp.retdd.selectedIndex = retd;
	document.formgrp.voyyy.value = voyy;
	document.formgrp.depyy.value = depy;
	document.formgrp.retyy.value = rety;
alert("Pour les residents permanents aux Etats-Unis : AVI International n'ayant pas de licence commerciale aux Etats-Unis, vous ne pouvez pas souscrire d'assurance depuis ce site. Veuillez nous en excuser. US permanent residents, please note that AVI International not being licensed to write business in the USA you cannot subscribe insurance on this web site. Sorry, we hope to be able to provide you soon with an alternative.");
	intervalleTemps();
}

 function verif()
{
	now = new Date();
jour=now.getDate();
anne=now.getFullYear()*10000;
mois=now.getMonth()*100;
no=mois+jour+anne;

dep=(document.formgrp.depyy.value*10000)+((document.formgrp.depmm.value-1)*100)+(Math.round(document.formgrp.depdd.value));
ret=(document.formgrp.retyy.value*10000)+((document.formgrp.retmm.value-1)*100)+(Math.round(document.formgrp.retdd.value));
//+(Math.round(document.inscription.ddd.value))

if(dep<no){
alert("Votre date de depart ne peut pas être inférieure à la date d'aujourd'hui");
document.formgrp.depmm.selectedIndex = now.getMonth();
document.formgrp.depdd.selectedIndex = jour-1;
document.formgrp.depyy.value = now.getFullYear();
}
if(ret<dep){
document.formgrp.retdd.selectedIndex = document.formgrp.depdd.value-1;
document.formgrp.retmm.selectedIndex = document.formgrp.depmm.value-1;
document.formgrp.retyy.value = document.formgrp.depyy.value;
}
}


////les durees voyage///////////////////////////////////////////////


function diffJours(date1, date2) {
  if (date2.getMonth() == 0)
     var temp = new Date(date2.getFullYear() - 1, 11, date1.getDate());
  else
     var temp = new Date(date2.getFullYear(), date2.getMonth() - 1, date1.getDate());
  return Math.floor((date2.getTime() - temp.getTime()) / 1000 / 60 / 60 / 24);
}




function nbsemaines(depart,retour)
{

	//difference = retour.getTime()-depart.getTime();
	//nbjour = Math.floor(difference/(1000*60*60*24))+1;
	//nbsem = Math.floor(nbjour/7);
	//if((nbjour%7)>=3){nbsem+=1;}




//Set 1 day in milliseconds
var one_day=1000*60*60*24

var nbjour=(retour.getTime()-depart.getTime())/(one_day)+1;

//var nbjour=Math.floor((retour.getTime()-depart.getTime())/(one_day))+1;
var nbsem= Math.floor(nbjour/7);

//nbsem=Math.floor((((retour.getTime()-depart.getTime())/(1000*60*60*24))+1)/7);

if((nbjour%7)>1){nbsem+=1;}

//alert(nbjour + " - " + nbsem);
return nbsem;

}

function nbmois(date1, date2)
{
	 var jours = 0;
  var mois = 0;
  var ans = date2.getFullYear() - date1.getFullYear();
 
  // cas 01, 02 & 03 : mois2 = mois1
  if (date1.getMonth() == date2.getMonth()) {
     // cas 02 : jour1 < jour2 (date1 = 15/4/1985, date2 = 22/4/2000) 
     if (date1.getDate() < date2.getDate())
        jours = date2.getDate() - date1.getDate();
     // cas 03 : jour1 > jour2 (date1 = 22/4/1985, date2 = 15/4/2000) 
     else if (date1.getDate() > date2.getDate()) {
        ans--;
        mois = 11;
        jours = diffJours(date1, date2);
     }
     // cas 01 : jour1 = jour2 (date1 = 15/4/1985, date2 = 15/4/2000) 
     // on laisse comme ça
          else {}
  }

  // cas 11 & 12 : mois1 < mois2
  else if (date1.getMonth() < date2.getMonth()) {
     mois = date2.getMonth() - date1.getMonth();
     // cas 11 : jour1 <= jour2 (exemple 15/04/1985 au 22/08/2000)
     if (date1.getDate() <= date2.getDate())
        jours = date2.getDate() - date1.getDate();
     // cas 12 : jour1 > jour2 (exemple 22/04/1985 au 15/08/2000)
     else {
        mois--;
        jours = diffJours(date1, date2);
     }
  }
  // cas 21 & 22 : mois1 > mois2
  else {
     ans--;
     mois = 12 + date2.getMonth() - date1.getMonth();
     // cas 21 : jour1 <= jour2 (exemple 15/08/1985 au 22/04/2000)
     if (date1.getDate() <= date2.getDate())
        jours = date2.getDate() - date1.getDate();
     // cas 22 : jour1 > jour2 (exemple 22/08/1985 au 15/04/2000)
     else {
        mois--;
        jours = diffJours(date1, date2);
     }
  }
var tmois=0;
tmois = 12*ans+mois;
if (jours>=1) {tmois++;}
return tmois;
	
}


function intervalleTemps()
{
verif();

voyy=document.formgrp.voyyy.value;
voym=document.formgrp.voymm.value-1;
voyd=document.formgrp.voydd.value-1;
depy=document.formgrp.depyy.value;
depm=document.formgrp.depmm.value-1;
depd=document.formgrp.depdd.value-1;
rety=document.formgrp.retyy.value;
retm=document.formgrp.retmm.value-1;
retd=document.formgrp.retdd.value-1;
EcrireCookie("vdd", voyd, date);
EcrireCookie("vmm", voym, date);
EcrireCookie("vyy", voyy, date);
EcrireCookie("ddd", depd, date);
EcrireCookie("dmm", depm, date);
EcrireCookie("dyy", depy, date);
EcrireCookie("rdd", retd, date);
EcrireCookie("rmm", retm, date);
EcrireCookie("ryy", rety, date);

date1 = new Date(document.formgrp.depyy.value,(document.formgrp.depmm.value-1),document.formgrp.depdd.value,0,0,0,0);
date2 = new Date(document.formgrp.retyy.value,(document.formgrp.retmm.value-1),document.formgrp.retdd.value,0,0,0,0);

 
nbsem = nbsemaines(date1, date2);
tmois= nbmois(date1, date2);

//if (nbsem<8){document.formgrp.mois.value="0";}else{document.formgrp.mois.value=tmois;	}
document.formgrp.sem.value=nbsem;
document.formgrp.mois.value=tmois;
} 
////Fin les durees voyage///////////////////////////////////////////////


