// JavaScript Document
var mnn=new Array(31,28,31,30,31,30,31,31,30,31,30,31);
var mnl=new Array(31,29,31,30,31,30,31,31,30,31,30,31);
var anBiss = 366;
var anNorm = 365;

function verifDate(){
	var deb = document.getElementById('datedebut').value;
	var fin = document.getElementById('datefin').value;
	debut = deb.split('/');
	farany = fin.split('/');
	if(parseFloat(debut[2]) > parseFloat(farany[2])){
		correct = false;
	}else{
		if(parseFloat(debut[1]) <= parseFloat(farany[1])){
			correct = true;
		}else{
			if(parseFloat(debut[0]) > parseFloat(farany[0])){
				correct = false;
			}else{
				correct = true;
			}
		}
	}
	if(correct){
		anDeb = parseFloat(debut[2]);
		anFin = parseFloat(farany[2]);
		nbAn = (bissextil(anFin) - bissextil(anDeb));
		moiDeb = parseFloat(debut[1]);
		moiFin = parseFloat(farany[1]);
		nbM = calculMois(moiDeb, moiFin, anDeb, anFin)
		jDeb = parseFloat(debut[0]);
		jFin = parseFloat(farany[0]);
		nbJ = (nbM - jDeb) + parseFloat(jFin);
		nbr = nbJ;
		document.getElementById('nbr').value = nbr;
	}else{
		alert('votre date est fausse...\nVeuillez rectifier');
		document.getElementById('datedebut').value = 'dd/mm/yy';
		document.getElementById('datefin').value = 'dd/mm/yy';
		document.getElementById('nbr').value = '000';
	}
}

function bissextil(annee){
	return ((annee%4)==0)?anBiss:anNorm;
}

function moiBis(annee, mois){
	mois--;
	tabMois = ((annee%4)==0)?mnl:mnn;
	return tabMois[mois];
}

function calculMois(debutMois, finMois, debutAn, finAn){
	difMois = (((finAn - debutAn) * 12) - debutMois) + finMois;
	var compte = 0;
	var isa = debutMois;
	for (n=debutMois;n<(debutMois + difMois);n++) {
		if(isa == 12){
			isa = 0;
		}
		compte = compte + moiBis(debutAn, (isa+1));
		//alert('inc = ' + isa + '\n nbJour/Mois = ' + moiBis(debutAn, (isa + 1)) + '\n compte = ' + compte);
		isa++;
	}
	return compte;
}
