date=new Date();
date.setMonth(date.getHours()+1);
date.setDate(date.getDate());

function dodate()
{
	var depd =LireCookie("ddd");
	var depm =LireCookie("dmm");
	var depy =LireCookie("dyy");
	var retd =LireCookie("rdd");
	var retm =LireCookie("rmm");
	var rety =LireCookie("ryy");

	var pres =LireCookie("lieu");
	var dest =LireCookie("dest");



if (depd==null || depm==null || depy==null) { 
now = new Date();
d= now.getDate();
m= now.getMonth();

rety=depy= now.getFullYear();
retm=depm=m;
depd=retd=d-1;

EcrireCookie("ddd", depd, date);
EcrireCookie("dmm", depm, date);
EcrireCookie("dyy", depy, date);
EcrireCookie("rdd", retd, date);
EcrireCookie("rmm", retm, date);
EcrireCookie("ryy", rety, date);

}


if (pres==null || dest==null ) 
{ 
pres=0; dest=0;
EcrireCookie("lieu", pres, date);
EcrireCookie("dest", dest, date);
}


	document.inscription.depdd.selectedIndex = depd;
	document.inscription.depmm.selectedIndex = depm;
	document.inscription.depyy.value = depy;
	document.inscription.retdd.selectedIndex = retd;
	document.inscription.retmm.selectedIndex = retm;
	document.inscription.retyy.value = rety;

	document.inscription.pres.value = pres;
	document.inscription.pto.value = dest;
	
verifdate();
}


function pays()
{

pres=document.inscription.pres.value
dest=document.inscription.pto.value
EcrireCookie("lieu", pres, date);
EcrireCookie("dest", dest, date);

}


function verifdate()
{

//alert("debut fct verifdate");
	//Onb compare seulement
now = new Date();
jour=now.getDate();
anne=now.getFullYear()*10000;
mois=((now.getMonth()*100)+1);
now2=jour+mois+anne;

depart2=(document.inscription.depyy.value*10000)+((document.inscription.depmm.value)*100)+(Math.round(document.inscription.depdd.value));
retour2=(document.inscription.retyy.value*10000)+((document.inscription.retmm.value)*100)+(Math.round(document.inscription.retdd.value));

//On regarde si date depart>date retour
if(retour2<depart2){
document.inscription.retdd.selectedIndex = document.inscription.depdd.selectedIndex;
document.inscription.retmm.selectedIndex = document.inscription.depmm.selectedIndex;
document.inscription.retyy.value = document.inscription.depyy.value;
}

//On regarde si date depart< date today
if(depart2<now2){
alert("depart inf a aujourd'hui : impossible");
d= now.getDate();
m=now.getMonth();
y= now.getFullYear();

document.inscription.depdd.selectedIndex = (d-1);
document.inscription.depmm.selectedIndex = m;
document.inscription.depyy.selectedIndex = y;
//alert ("day--jour"+document.inscription.ddd1.value+"mois"+document.inscription.dmm1.value+"anne"+document.inscription.dyy1.value);
}


	depd=document.inscription.depdd.selectedIndex;
	depm=document.inscription.depmm.selectedIndex;
	depy=document.inscription.depyy.value;
	retd=document.inscription.retdd.selectedIndex;
	retm=document.inscription.retmm.selectedIndex;
	rety=document.inscription.retyy.value;


//on inscrit les valeurs dans le cookie
EcrireCookie("ddd", depd, date);
EcrireCookie("dmm", depm, date);
EcrireCookie("dyy", depy, date);
EcrireCookie("rdd", retd, date);
EcrireCookie("rmm", retm, date);
EcrireCookie("ryy", rety, date);

//alert("av fct prix");
prix();
//alert("date actuel"+depart2+"date dep"+Math.round(document.inscription.ddd.value));
}



function prix()
{
//alert("pass");
nbmois=intervalleTemps();
//document.inscription.mois.value=nbmois;
//alert ("nb mois" + nbmois);

document.inscription.mois.value = nbmois;

//alert("nbmois " + nbmois);


if(nbmois >0){
var sto1=0;	
var sto2=0;
var stolug1=0;
var stolug2=0;

if( (document.inscription.pto.value==8||document.inscription.pto.value==97||document.inscription.pto.value==1||document.inscription.pto.value==39||document.inscription.pto.value==19||document.inscription.pto.value==34||document.inscription.pto.value==29||document.inscription.pto.value==28||document.inscription.pto.value==13||document.inscription.pto.value==41||document.inscription.pto.value==45||document.inscription.pto.value==33||document.inscription.pto.value==51||document.inscription.pto.value==61||document.inscription.pto.value==64||document.inscription.pto.value==65||document.inscription.pto.value==88||document.inscription.pto.value==90||document.inscription.pto.value==99||document.inscription.pto.value==126||document.inscription.pto.value==100||document.inscription.pto.value==104||document.inscription.pto.value==113||document.inscription.pto.value==79||document.inscription.pto.value==75||document.inscription.pto.value==103||document.inscription.pto.value==125) 
	&& (document.inscription.pres.value==8||document.inscription.pres.value==97||document.inscription.pres.value==1||document.inscription.pres.value==39||document.inscription.pres.value==19||document.inscription.pres.value==34||document.inscription.pres.value==29||document.inscription.pres.value==28||document.inscription.pres.value==13||document.inscription.pres.value==41||document.inscription.pres.value==45||document.inscription.pres.value==33||document.inscription.pres.value==51||document.inscription.pres.value==61||document.inscription.pres.value==64||document.inscription.pres.value==65||document.inscription.pres.value==88||document.inscription.pres.value==90||document.inscription.pres.value==99||document.inscription.pres.value==126||document.inscription.pres.value==100||document.inscription.pres.value==104||document.inscription.pres.value==113||document.inscription.pres.value==79||document.inscription.pres.value==75||document.inscription.pres.value==103||document.inscription.pres.value==125))
	{ p1=26; p2=29; p3=39;}else{ p1=36; p2=39; p3=49;}

//alert("nbmois " + nbmois);

if (document.inscription.produit.value=="Premium")	{
	if (document.inscription.flight[1].checked){
		verif_rg();
		alert("pass1");
		laps=tmp_bg();
		sto2=(laps*19);
		}
	}


if (document.inscription.produit.value=="Premium+")
	{   
	if (document.inscription.Luggage[1].checked){
		verif_bg();
		laps=tmp_bg();
		stolug1=(laps*18);
	}
	//Rique grave
	if (document.inscription.flight[1].checked){
		verif_rg();
		laps=tmp_rg();
		sto1=(laps*19);
		}
	}


totlug1=(stolug1+sto1); 
totlug2=sto2; //Pour premium

s1=(nbmois*p1);
s2=(nbmois*p2);
s3=(nbmois*p3);

t1=s1;
t2=totlug2+s2;
t3=totlug1+s3;


}else{
t1=0;t2=0;t3=0;
s1=0;s2=0;s3=0;
}



if (document.inscription.produit.value=="Classic")
	{
	document.inscription.stotal.value=s1;
	document.inscription.total.value=t1;
	}

if (document.inscription.produit.value=="Premium")
	{
	document.inscription.stotal.value=s2;
	document.inscription.total.value=t2;
	}

if (document.inscription.produit.value=="Premium+")
	{
	document.inscription.stotal.value=s3;
	document.inscription.total.value=t3;
	}


}


function addx()
{
// remove commas from indivdial fields
// ensure age is digits only
 var line1=line2=line3=line4="";

 if (document.inscription.age2.value < " " && document.inscription.nom2.value > "") {alert ("Il manque l'age de la deuxième personne"); return false;}
 if (document.inscription.age3.value < " " && document.inscription.nom3.value > "") {alert ("Il manque l'age de la troisième personne"); return false;}
 if (document.inscription.age4.value < " " && document.inscription.nom4.value > "") {alert ("Il manque l'age de la quatrième personne"); return false;}
 //alert("passe ok ");
 if (document.inscription.nom1.value != "") {line1 = document.inscription.tit1.value+", "+document.inscription.nom1.value+", "+document.inscription.pre1.value+", "+document.inscription.age1.value;}
 if (document.inscription.nom2.value != "") {line2 = document.inscription.tit2.value+", "+document.inscription.nom2.value+", "+document.inscription.pre2.value+", "+document.inscription.age2.value;}
 if (document.inscription.nom3.value != "") {line3 = document.inscription.tit3.value+", "+document.inscription.nom3.value+", "+document.inscription.pre3.value+", "+document.inscription.age3.value;}
 if (document.inscription.nom4.value != "") {line4 = document.inscription.tit4.value+", "+document.inscription.nom4.value+", "+document.inscription.pre4.value+", "+document.inscription.age4.value;}
 // alert("passe ok ");
 if (line1 > "") {document.inscription.list.value = line1;}
 if (line2 > "") {document.inscription.list.value = document.inscription.list.value +"\n"+line2;}
 if (line3 > "") {document.inscription.list.value = document.inscription.list.value +"\n"+line3;}
 if (line4 > "") {document.inscription.list.value = document.inscription.list.value +"\n"+line4;}

// alert(document.inscription.list.value);
}


function verifdonnes()
{

var msg = "";	
var re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
var t=0;
//alert ("passe");
	//vérification de la periode demandée
if (document.inscription.pres.value == document.inscription.pto.value) {msg = "- Pays destination est iddentique au pays de depart du voyage.";}
//alert ("passe1.0");
if (document.inscription.mois.value < 1){msg = msg + "\n" + "- Votre assurance doit avoir une durée supérieure à 1 mois.";}
//alert ("passe1.1");
if (document.inscription.mois.value > 12){msg = msg + "\n" + "- Votre assurance doit avoir une durée inférieure à 12 mois.";}
//alert ("passe1.2");
if(document.inscription.age1.value > 65 || document.inscription.age2.value > 65 || document.inscription.age3.value > 65 || document.inscription.age4.value > 65){msg = msg + "\n" + "- Les personnes de plus de 65 ans ne sont pas assurés.";}

if(!re.test(document.inscription.email.value)){ msg = msg + "\n" + "- Votre email n'est pas correct.";}
if (document.inscription.add.value == "") {msg = msg + "\n" + "- Adresse manquante.";}
if (document.inscription.ville.value == "") {msg = msg + "\n" + "- Ville manquante.";}
if (document.inscription.pays.value == "") {msg = msg + "\n" + "- Pays manquant.";}
if (document.inscription.zip.value == "") {msg = msg + "\n" + "- Code postal manquant.";}
//if (document.inscription.tel.value == "") {msg = msg + "\n" + "- Telephone manquant.";}


if (document.inscription.mois.value > 12){msg = msg + "\n" + "- Cette assurance en ligne est limitée aux voyages de 12 mois maximum.";}
if (document.inscription.tit1.value == "" || document.inscription.nom1.value == "" || document.inscription.pre1.value == "" || document.inscription.age1.value == "") {msg = msg + "\n" +"- Au moins une personne doit etre inscrites";}
if (document.inscription.connaissance.value == ""){msg = msg + "\n" + "- Vous n'avez pas selectionné comment vous avez connu notre site.";}
if (document.inscription.heart.checked == false) {msg = msg + "\n" + "- Vous n'avez pas coché la case de lecture des conditions générales";}
//alert ("passe2");
var ds=(document.inscription.depyy.value*10000)+((document.inscription.depmm.value-1)*100)+(Math.round(document.inscription.depdd.value));
var dr=(document.inscription.retyy.value*10000)+((document.inscription.retmm.value-1)*100)+(Math.round(document.inscription.retdd.value));
//alert ("passe3");
//var dsrg=(document.inscription.rgdy.value*10000)+((document.inscription.rgdm.value-1)*100)+(Math.round(document.inscription.rgdd.value));
//var drrg=(document.inscription.rgry.value*10000)+((document.inscription.rgrm.value-1)*100)+(Math.round(document.inscription.rgrd.value));
//if (dsrg>=ds && drrg<=dr && drrg>dsrg){t=1;}

//if (document.inscription.optrisk[1].checked && t!=1){msg = msg + "\n" + "- Vos dates d'option risque grave ne sont pas correctes.";}

	if (msg > "") {alert (msg); return false;}
return true;
}

/////////////////////////////////////////////////////////////////////////////////////////

// calcule le nombre de jours entre date1 et une date dont l'année est celle
// de date2 et le mois, le mois précédent celui de date2;
// si mois2 = "janvier", on prend l'année précédente et le mois de "décembre"
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);

}

///////////////////Prix au mois////////////////////////////////////////////////////////////

function intervalleTemps() {

date1 = new Date(document.inscription.depyy.value,(document.inscription.depmm.value),document.inscription.depdd.value,0,0,0,0);
date2 = new Date(document.inscription.retyy.value,(document.inscription.retmm.value),document.inscription.retdd.value,0,0,0,0);
tmois=calcul_int(date1,date2);
return(tmois);
}

function calcul_int( date1, date2) {
  //var date1 = new Date(format1.an, format1.mois, format1.jour);
  //var date2 = new Date(format2.an, format2.mois, format2.jour);
  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++;}
//alert("nb mois dans fct"+tmois);
return(tmois);
} 
///////////////////////////////////////////////////////////////////////////////////////////////
