var ANNEE_REFERENCE = 2008;
var QUARTSHEURES_PAR_JOUR = 96;
var JOURS_PAR_ANNEE = 365;
var JOURS_PAR_ANNEEBI = 366;
var QUARTSHEURES_PAR_ANNEE = 35040;
var QUARTSHEURES_PAR_ANNEEBI = 35136;

function GetQuantieme(date)
{
	var mois = date.getMonth()+1;
	var jour = date.getDate();
	q = 0;
	for (m=1; m<mois; m++) q += GetNbJoursMois(m,date.getFullYear());
	q += jour;
	quantieme = parseInt(q);
	return quantieme;
}
function IsBissextile(annee)
{
	if ((annee%4==0) && ((annee%100!=0) || (annee%400==0))) return true;
	else return false;
}
function GetNbJoursMois(mois,annee)
{
		if (mois==1||mois==3||mois==5||mois==7||mois==8||mois==10||mois==12) return(31);
		else if (mois==2)
		{
			if (IsBissextile(annee)) return(29);
			else return(28);
		}
		else return(30);
}
function GetNbJoursCourant() // Nombre de jours relatif à l'annee de référence
{
	Now = new Date();
	var nbj = GetNbJours(Now);
	return nbj;
}
function GetQuartHeureCourant() // Quart d'heure courant relatif à l'annee de référence
{
	Now = new Date();
	var nbqh = GetNbQuartsHeures(Now);
	nbqh += (Now.getHours() * 4);
	nbqh += parseInt((Now.getMinutes() / 15));
	return nbqh;
}
function GetNbJours(date) // Nombre de jours depuis l'annee de référence jusqu'à aujourd'hui inclus
{
	var nbj = 0;
	annee = parseInt(date.getFullYear());
	for (a=0; a<(annee-ANNEE_REFERENCE); a++)
	{
		if (IsBissextile(ANNEE_REFERENCE+a)) nbj += JOURS_PAR_ANNEEBI;
		else nbj += JOURS_PAR_ANNEE;
	}
	nbj += (GetQuantieme(date))
	return nbj;
}
function GetNbQuartsHeures(date) // Nb de quarts d'heures depuis l'annee de référence jusqu'au début de ce jour
{
	var nbqh = 0;
	annee = parseInt(date.getFullYear());
	for (a=0; a<(annee-ANNEE_REFERENCE); a++)
	{
		if (IsBissextile(ANNEE_REFERENCE+a)) nbqh += QUARTSHEURES_PAR_ANNEEBI;
		else nbqh += QUARTSHEURES_PAR_ANNEE;
	}
	nbqh += (GetQuantieme(date)-1) * QUARTSHEURES_PAR_JOUR;
	return nbqh;
}
function GetQHAnnee(nbquartsheures) // Annee du jour en fonction du nb de quarts d'heures depuis l'annee de référence
{
	stopit=false;
	annee = ANNEE_REFERENCE;
	for (a=0; a<100 && !stopit; a++)
	{
		if (IsBissextile(ANNEE_REFERENCE+a))
		{
			if (nbquartsheures < QUARTSHEURES_PAR_ANNEEBI)
			{
				annee+=a;
				stopit=true;
			}
			else nbquartsheures -= QUARTSHEURES_PAR_ANNEEBI;
		}
		else
		{
			if (nbquartsheures < QUARTSHEURES_PAR_ANNEE)
			{
				annee+=a;
				stopit=true;
			}
			else nbquartsheures -= QUARTSHEURES_PAR_ANNEE;
		}
	}
	ladate = String(annee);
	return ladate;
}
function GetQHMois(nbquartsheures) // Mois du jour en fonction du nb de quarts d'heures depuis l'annee de référence
{
	stopit=false;
	annee = ANNEE_REFERENCE;
	for (a=0; a<100 && !stopit; a++)
	{
		if (IsBissextile(ANNEE_REFERENCE+a))
		{
			if (nbquartsheures < QUARTSHEURES_PAR_ANNEEBI)
			{
				annee+=a;
				stopit=true;
			}
			else nbquartsheures -= QUARTSHEURES_PAR_ANNEEBI;
		}
		else
		{
			if (nbquartsheures < QUARTSHEURES_PAR_ANNEE)
			{
				annee+=a;
				stopit=true;
			}
			else nbquartsheures -= QUARTSHEURES_PAR_ANNEE;
		}
	}
	stopit=false;
	mois=1;
	for (m=1; m<=12 && !stopit; m++)
	{
		nbqhmois = QUARTSHEURES_PAR_JOUR * GetNbJoursMois(m,annee);
		if (nbquartsheures < nbqhmois)
		{
			mois=m;
			stopit=true;
		}
		else nbquartsheures -= nbqhmois;
	}
	ladate = ((mois<10)?"0"+String(mois):String(mois));
	return ladate;
}
function GetQHJour(nbquartsheures) // Date du jour en fonction du nb de quarts d'heures depuis l'annee de référence
{
	stopit=false;
	annee = ANNEE_REFERENCE;
	for (a=0; a<100 && !stopit; a++)
	{
		if (IsBissextile(ANNEE_REFERENCE+a))
		{
			if (nbquartsheures < QUARTSHEURES_PAR_ANNEEBI)
			{
				annee+=a;
				stopit=true;
			}
			else nbquartsheures -= QUARTSHEURES_PAR_ANNEEBI;
		}
		else
		{
			if (nbquartsheures < QUARTSHEURES_PAR_ANNEE)
			{
				annee+=a;
				stopit=true;
			}
			else nbquartsheures -= QUARTSHEURES_PAR_ANNEE;
		}
	}
	stopit=false;
	mois=1;
	for (m=1; m<=12 && !stopit; m++)
	{
		nbqhmois = QUARTSHEURES_PAR_JOUR * GetNbJoursMois(m,annee);
		if (nbquartsheures < nbqhmois)
		{
			mois=m;
			stopit=true;
		}
		else nbquartsheures -= nbqhmois;
	}
	stopit=false;
	jour=1;
	for (j=1; j<=31 && !stopit; j++)
	{
		if (nbquartsheures < QUARTSHEURES_PAR_JOUR)
		{
			jour=j;
			stopit=true;
		}
		else nbquartsheures -= QUARTSHEURES_PAR_JOUR;
	}
	ladate = ((jour<10)?"0"+String(jour):String(jour));
	return ladate;
}
function GetJDate(nbjours) // Date complete du jour en fonction du nb de jours depuis l'annee de référence
{
	stopit=false;
	annee = ANNEE_REFERENCE;
	for (a=0; a<100 && !stopit; a++)
	{
		if (IsBissextile(ANNEE_REFERENCE+a))
		{
			if (nbjours < JOURS_PAR_ANNEEBI)
			{
				annee+=a;
				stopit=true;
			}
			else nbjours -= JOURS_PAR_ANNEEBI;
		}
		else
		{
			if (nbjours < JOURS_PAR_ANNEE)
			{
				annee+=a;
				stopit=true;
			}
			else nbjours -= JOURS_PAR_ANNEE;
		}
	}
	stopit=false;
	mois=1;
	for (m=1; m<=12 && !stopit; m++)
	{
		nbjmois = GetNbJoursMois(m,annee);
		if (nbjours < nbjmois)
		{
			mois=m;
			stopit=true;
		}
		else nbjours -= nbjmois;
	}
	jour=nbjours;
	ladate = ((jour<10)?"0"+String(jour):String(jour))+"/"+((mois<10)?"0"+String(mois):String(mois))+"/"+String(annee);
	return ladate;
}
function GetQHDate(nbquartsheures) // Date complete du jour en fonction du nb de quarts d'heures depuis l'annee de référence
{
	stopit=false;
	annee = ANNEE_REFERENCE;
	for (a=0; a<100 && !stopit; a++)
	{
		if (IsBissextile(ANNEE_REFERENCE+a))
		{
			if (nbquartsheures < QUARTSHEURES_PAR_ANNEEBI)
			{
				annee+=a;
				stopit=true;
			}
			else nbquartsheures -= QUARTSHEURES_PAR_ANNEEBI;
		}
		else
		{
			if (nbquartsheures < QUARTSHEURES_PAR_ANNEE)
			{
				annee+=a;
				stopit=true;
			}
			else nbquartsheures -= QUARTSHEURES_PAR_ANNEE;
		}
	}
	stopit=false;
	mois=1;
	for (m=1; m<=12 && !stopit; m++)
	{
		nbqhmois = QUARTSHEURES_PAR_JOUR * GetNbJoursMois(m,annee);
		if (nbquartsheures < nbqhmois)
		{
			mois=m;
			stopit=true;
		}
		else nbquartsheures -= nbqhmois;
	}
	stopit=false;
	jour=1;
	for (j=1; j<=31 && !stopit; j++)
	{
		if (nbquartsheures < QUARTSHEURES_PAR_JOUR)
		{
			jour=j;
			stopit=true;
		}
		else nbquartsheures -= QUARTSHEURES_PAR_JOUR;
	}
	ladate = ((jour<10)?"0"+String(jour):String(jour))+"/"+((mois<10)?"0"+String(mois):String(mois))+"/"+String(annee);
	return ladate;
}
function GetQHHeure(nbquartsheures)
{
	stopit=false;
	annee = ANNEE_REFERENCE;
	for (a=0; a<100 && !stopit; a++)
	{
		if (IsBissextile(ANNEE_REFERENCE+a))
		{
			if (nbquartsheures < QUARTSHEURES_PAR_ANNEEBI)
			{
				annee+=a;
				stopit=true;
			}
			else nbquartsheures -= QUARTSHEURES_PAR_ANNEEBI;
		}
		else
		{
			if (nbquartsheures < QUARTSHEURES_PAR_ANNEE)
			{
				annee+=a;
				stopit=true;
			}
			else nbquartsheures -= QUARTSHEURES_PAR_ANNEE;
		}
	}
	stopit=false;
	mois=1;
	for (m=1; m<=12 && !stopit; m++)
	{
		nbqhmois = QUARTSHEURES_PAR_JOUR * GetNbJoursMois(m,annee);
		if (nbquartsheures < nbqhmois)
		{
			mois=m;
			stopit=true;
		}
		else nbquartsheures -= nbqhmois;
	}
	stopit=false;
	jour=1;
	for (j=1; j<=31 && !stopit; j++)
	{
		if (nbquartsheures < QUARTSHEURES_PAR_JOUR)
		{
			jour=j;
			stopit=true;
		}
		else nbquartsheures -= QUARTSHEURES_PAR_JOUR;
	}
	h = parseInt(nbquartsheures/4);
	m = (nbquartsheures%4) * 15;
	return ((h<10)?"0"+String(h):String(h)) + "h" + ((m<10)?"0"+String(m):String(m));
}
