// Affiche un objet "<div>"
function afficheDiv(document, divName){
		divElement=document.getElementById(divName); 
		divElement.style.visibility='visible'; 
		/*
	if(document.all) {
		// IE.
		with (document){
			divName.style.visibility="visible";
		}
	} else if(document.layers) {
		// Netspace 4
		with (document){
			divName.visibility="visible";
		}
	} else {
		// Mozilla
		divName.style.visibility="visible";
	} 
	*/
	return false;
}

// Cache un objet "<div>"
function cacheDiv(document, divName){
		divElement=document.getElementById(divName);
		divElement.style.visibility='hidden'; 
		
		/*
	if(document.all) {
		// IE.
		with (document){
			divName.style.visibility="hidden";
		}
	} else if(document.layers) {
		// Netspace 4
		with (document){
			divName.visibility="hidden";
		}
	} else {
		// Mozilla
		divName.style.visibility="hidden";
	} 
	*/
	return false;
}

//Centre la div horizontalement sur l'ecran
function centreDiv(document, divName){
	//récupère la largeur de l'écran
	var largeurEcran = document.body.clientWidth;
 	var hauteurEcran = document.body.clientHeight;
	if(!document.all){
		largeurEcran = screen.width;
		hauteurEcran = screen.height;
	}
		
	//Récupère la largeur de la div
	var largeurDiv = divName.style.width;
	if (largeurDiv.substring(largeurDiv.length-2,largeurDiv.length)=="px"){
		largeurDiv = largeurDiv.substring(0,largeurDiv.length-2);
	}	
	largeurDiv = getNumber(largeurDiv);
	
	//Centre la div
	divName.style.left = (largeurEcran - largeurDiv)/2;
	
}

	function handleHideableDiv1(divId, linkId) { 
		divElement=document.getElementById(divId); 		
		
		if (divElement.style.display=='none'){ 
			divElement.style.display='block'; 
			linkId.firstChild.nodeValue=toShowText;
 		} else { 
			divElement.style.display='none'; 
			linkId.firstChild.nodeValue=toHideText;
		} 
	} 

	/**
	*Affiche la div si elle est cachée (et inversement) à partir d'un lien dont le texte change suivant que l'état de la DIV
	*/
	function handleHideableDivWithLink(divId, linkId, toShowText, toHideText) { 
		divElement=document.getElementById(divId); 		
		
		if (divElement.style.display=='none'){ 
			divElement.style.display='block'; 
			linkId.firstChild.nodeValue=toShowText;
 		} else { 
			divElement.style.display='none'; 
			linkId.firstChild.nodeValue=toHideText;
		} 
	}

//Permet de cacher une DIV ou tout autre object gérant la propriété display
	function switchDisplayState(objectId) { 
		objectElement=document.getElementById(objectId); 		
		
		if (objectElement.style.display=='none'){ 
			objectElement.style.display='block'; 
 		} else { 
			objectElement.style.display='none'; 
		} 
	} 
	
	function showDiv(divId) { 
		divElement=document.getElementById(divId); 			
		divElement.style.display='block'; 
	}  
	
	function hideDiv(divId) { 
		divElement=document.getElementById(divId); 			
		divElement.style.display='none'; 
	} 
	
	

//Permet de cacher une DIV de type SPAN à l'aide d'un lien détaché
	function handleHideableSpan1(spanId, linkId) { 
		panelElement=document.getElementById(spanId); 		
		
		if (panelElement.style.display=='none'){ 
			panelElement.style.display='block'; 
 		} else { 
			panelElement.style.display='none'; 
		} 
	} 
	
//handleHideableSpan1 + texte à afficher lorsque la div est cachée et texte à afficher lorsque la div est montrée												
	function handleHideableSpan2(spanId, linkId, toShowText, toHideText) { 
		panelElement=document.getElementById(spanId); 		
		
		if (panelElement.style.display=='none'){ 
			panelElement.style.display='block'; 
			linkId.firstChild.nodeValue=toHideText;
 		} else { 
			panelElement.style.display='none'; 
			linkId.firstChild.nodeValue=toShowText;
		} 
	}		


function getSpanText(spanId) {

	return trim(document.getElementById(spanId).innerHTML);

}

		
function setSpanText(spanId, newText) {

	document.getElementById(spanId).innerHTML = newText;

}

		
function changeSpanText(spanId, newText) {

	setSpanText(spanId, newText);

}
					
function setSpanStyle(spanId, newStyle) {

	document.getElementById(spanId).className = newStyle;

}
			

function changeImage(imageId, imagePath){
	objectImage = document.getElementById(imageId);
	objectImage.src = imagePath;
}

function refreshFormWithReqCode(form, reqCode){
	form.elements['reqCode'].value=reqCode; 
	form.submit();
	return false;
}


function refreshForm(form){
	form.submit();
	return false;
}

function submitForm(form){
	form.submit();
	return false;
}

function submitFormWithNewURL(form, newURL){
	form.action=newURL;
	form.submit();
	return false;
}

function submitFormWithReqCode(form, reqCode){
	form.elements['reqCode'].value=reqCode; 
	form.submit();
	return false;
}

function confirmAnnulation(){
	
	return window.confirm("Vous allez annuler votre saisie en cours.\nAucun élément ne sera sauvegardé.\n\nEtes-vous sûr?");
	
}

/*
* ===================================================================================================
* Fonctions permettant de "gérer" l'interdiction du copier/coller. (testé sous IE, Firefox et Safari)
* ===================================================================================================
* Utilisation :
*   1/ Appeler la fonction 'initDisablePasteFunction' sous l'element '<input>'
* 	2/ Appeler la fonction 'disablePasteFunction'  dans l'attribut 'onKeyUp' de l'element '<input>'
*
* 		EXEMPLE complet : 	
*			<input type="text" name="confirmationMailExpediteur" size="40" onKeyUp="disablePasteFunction(document.forms['contactForm'].elements['confirmationMailExpediteur']);" />
* 		 	<script language="javascript">
*	 			//Initialisation de la variable pour la fonction 'disablePasteFunction'
*				initDisablePasteFunction(document.forms['contactForm'].elements['confirmationMailExpediteur'].value);
*	   		</script>
*/

var oldText = ""; 

function initDisablePasteFunction(formElement) {
	oldText = formElement.value;
}

function disablePasteFunction(formElement) {	
	
	var text = formElement.value;
	
	if (text.length > (oldText.length+4)){ //si plus de 4 caractères ont été ajouté, alors c'est forcément un copier/coller (sinon cela peut etre une frappe rapide)
		if (text.length>4){ //pour afficher l'alerte qu'une fois (car apparemment le fait de rechanger la valeur, via le javascript ci-dessous, rappelle al fonction)
			alert('Copier/Coller désactivé sur ce champs.');
		}
		formElement.value = oldText;
	} else {
		oldText = text;
	}
}



function checkFieldSearchNumeroAdherent(form, isMandatory){

	var message = "";
	
	//On trim le champs
	if (!isNull(form.searchNumeroAdherent.value)){
		form.searchNumeroAdherent.value = trim(form.searchNumeroAdherent.value);
	}		

	
	//Si le numéro adhérent est obligatoire et qu'il n'est pas rempli, on ne va pas plus loin	
	if (isMandatory && isNull(form.searchNumeroAdherent.value)){
		message += "Le champ ' N° Adhérent ' est obligatoire.\n";
		window.alert(message);
		return false;		
	}
		

	//Vérifie la saisie du numéro d'adhérent
	if (!checkPositiveIntegerNumber(form.searchNumeroAdherent.value)){
		message += "Le champs ' N° Adhérent ' doit être un nombre (Ne pas saisir la clé).\n";
		window.alert(message);
		return false;
	}
	
	return true;
} 

function checkFieldSearchIdCptble(form, isMandatory){

	var message = "";
	
	//On trim le champs
	if (!isNull(form.searchIdCptble.value)){
		form.searchIdCptble.value = trim(form.searchIdCptble.value);
	}		

	
	//Si l'ID comptable est obligatoire et qu'il n'est pas rempli, on ne va pas plus loin	
	if (isMandatory && isNull(form.searchIdCptble.value)){
		message += "Le champ ' N° Comptable ' est obligatoire.\n";
		window.alert(message);
		return false;		
	}
		

	//Vérifie la saisie de l'ID comptable
	if (!checkPositiveIntegerNumber(form.searchIdCptble.value)){
		message += "Le champs ' N° Comptable ' doit être un nombre.\n";
		window.alert(message);
		return false;
	}
	
	return true;
} 



function checkFieldSearchNumeroDossier(form, isMandatory){

	var message = "";
	
	//On trim le champs
	if (!isNull(form.searchNumeroDossier.value)){
		form.searchNumeroDossier.value = trim(form.searchNumeroDossier.value);
	}		

	
	//Si le numéro dossier est obligatoire et qu'il n'est pas rempli, on ne va pas plus loin	
	if (isMandatory && isNull(form.searchNumeroDossier.value)){
		message += "Le champ ' N° Dossier ' est obligatoire.\n";
		window.alert(message);
		return false;		
	}
		

	//Vérifie la saisie du numéro de dossier
	if (!checkPositiveIntegerNumber(form.searchNumeroDossier.value)){
		message += "Le champs ' N° Dossier ' doit être un nombre.\n";
		window.alert(message);
		return false;
	}
	
	return true;
} 

function checkFieldSearchIdSalarie(form, isMandatory){

	var message = "";
	
	//On trim le champs
	if (!isNull(form.searchIdSalarie.value)){
		form.searchIdSalarie.value = trim(form.searchIdSalarie.value);
	}		

	
	//Si l'ID salarie est obligatoire et qu'il n'est pas rempli, on ne va pas plus loin	
	if (isMandatory && isNull(form.searchIdSalarie.value)){
		message += "Le champ ' N° Salarié ' est obligatoire.\n";
		window.alert(message);
		return false;		
	}
		

	//Vérifie la saisie de l'ID comptable
	if (!checkPositiveIntegerNumber(form.searchIdSalarie.value)){
		message += "Le champs ' N° Salarié ' doit être un nombre.\n";
		window.alert(message);
		return false;
	}
	
	return true;
} 

function checkDecimalNumber(inputValue){
	if (isNull(inputValue)){
		inputValue='';
		return true;
	}
	
	//On utilise pas la fonction NaN(..) car elle bug lorsqu'on saisi des nombres comme "8s7" ou "9c"
	for (var i=0; i<inputValue.length; i++) {
		var car = inputValue.substring(i,i+1);
		
		if (car<"0" || car>"9"){		
			if (car=="," || car=="."){			
				//Si ce n'est pas un nombre, on a le droit d'avoir un caractère point ou virgule car cela peux etre un décimal
				if (car==","){
					if (inputValue.indexOf(",",0)!=inputValue.lastIndexOf(",",inputValue.length)){
						//il y a plusieurs virgules
						return false;
					} else if (inputValue.indexOf(".",0)!=-1){ //On a qu'une virgule, on vérifie qu'il n'y ait pas un point en plus
						return false;					
					}
				}
				if (car=="."){
					if (inputValue.indexOf(".",0)!=inputValue.lastIndexOf(".",inputValue.length)){
						//il y a plusieurs points
						return false;
					} else if (inputValue.indexOf(",",0)!=-1){//On a qu'un point, on vérifie qu'il n'y ait pas une virgule en plus						
						return false;					
					}
				}
			} else {
				return false;
			}
		}
	}
	
	return true;
}

function checkPositiveDecimalNumber(inputValue){
	if (isNull(inputValue)){
		inputValue='';
		return true;
	}
	
	if (checkDecimalNumber(inputValue)){
		if (parseInt(inputValue)>=0){
			return true;
		}
	}
	
	return false;	
}

function checkStrictlyPositiveDecimalNumber(inputValue){
	if (isNull(inputValue)){
		inputValue='';
		return false;
	}
	
	if (checkDecimalNumber(inputValue)){
		if (parseInt(inputValue)>0){
			return true;
		}
	}
	
	return false;
}


function checkNumberRange(formInput, minValue, maxValue){
	var nombre = getNumber(formInput.value);
	
	if (nombre<=minValue){ //On test l'égalité car la fonction getNumber() renvoi 0 pour les incohérences
		formInput.value=minValue;
	} else if (nombre>maxValue){
		formInput.value=maxValue;
	}
}

function checkDecimalRange(formInput, minValue, maxValue){
	var nombre = getDecimalNumber(formInput.value);
	
	if (nombre<=minValue){ //On test l'égalité car la fonction getNumber() renvoi 0 pour les incohérences
		formInput.value=minValue;
	} else if (nombre>maxValue){
		formInput.value=maxValue;
	}
}

function getNumber(inputValue){

	if (isNull(inputValue)){
		inputValue='';
		return 0;
	}
	
	//On utilise pas la fonction NaN(..) car elle bug lorsqu'on saisi des nombres comme "8s7" ou "9c"
	for (var i=0; i<inputValue.length; i++) {
		var car = inputValue.substring(i,i+1);
		if (car<"0" || car>"9"){
			return 0;
		}
	}
	return new Number(inputValue);
	
}

function getDecimalNumber(inputValue){

	if (isNull(inputValue)){
		inputValue='';
		return 0;
	}
	
	//On remplace les ',' par des '.'
	var virgulePosition = inputValue.indexOf(",",0);
	if (virgulePosition!=-1){
		if (virgulePosition!=inputValue.lastIndexOf(",",inputValue.length)){
			//il y a plusieurs virgules
			return 0;
		} else { //On a qu'une virgule, on la remplace par un point
			inputValue = eval(inputValue.substring(0,virgulePosition)+"."+inputValue.substring(virgulePosition+1,inputValue.length));	
		}
	}

	//On utilise pas la fonction NaN(..) car elle bug lorsqu'on saisi des nombres comme "8s7" ou "9c"
	if (!checkDecimalNumber(inputValue)){
		return 0;
	}
	
	return new Number(inputValue);
	
}

function checkIntegerNumber(inputValue){
	if (isNull(inputValue)){
		inputValue='';
		return true;
	}
	
	//On utilise pas la fonction NaN(..) car elle bug lorsqu'on saisi des nombres comme "8s7" ou "9c"
	for (var i=0; i<inputValue.length; i++) {
		var car = inputValue.substring(i,i+1);
		if (car<"0" || car>"9"){
			return false;
		}
	}
	
	return true;
}


function checkPositiveIntegerNumber(inputValue){
	if (isNull(inputValue)){
		inputValue='';
		return true;
	}
	
	if (checkIntegerNumber(inputValue)){
		if (parseInt(inputValue)>=0){
			return true;
		}
	}
	
	return false;	
}


function checkStrictlyPositiveIntegerNumber(inputValue){
	if (isNull(inputValue)){
		inputValue='';
		return false;
	}
	
	if (checkIntegerNumber(inputValue)){
		if (parseInt(inputValue)>0){
			return true;
		}
	}
	
	return false;	
}



function checkLetterField(inputValue){
	if (isNull(inputValue)){
		inputValue='';
		return true;
	}

	for (var i=0; i< inputValue.length; i++){
	    var car = inputValue.substring(i,i+1);
	    if (car>="0" && car<="9"){
	      return false;
	    }
    }
    return true;
}



function checkNumeroSecuriteSocialeField(inputValue){
	if (isNull(inputValue)){
		inputValue='';
		return true;
	}

	for (var i=0; i<inputValue.length; i++){
		var num = inputValue.substring(i,i+1);
		if ((num<"0" || num>"9") && (num.toLowerCase()!=".") && (num.toLowerCase()!=" ") && (num.toLowerCase()!="A") && (num.toLowerCase()!="B") ){ //A et B car 2A, 2B peuvent etre présent
			return false;
	    }
	}
	return true;
}



function checkNumeroTelephone(inputValue){
	if (isNull(inputValue)){
		inputValue='';
		return true;
	}

	var compteChiffresLus = 0;
	for (var i=0; i<inputValue.length; i++){
		var num = inputValue.substring(i,i+1);
		if ((num<"0" || num>"9") && (num.toLowerCase()!=".") && (num.toLowerCase()!=" ") ){
			return false;
	    } else { // caractères autorisés
	    	if ( num>="0" && num<="9" ) { //on a lu un chiffre
	    		compteChiffresLus++;
	    	}
	    }
	}
	
	if (compteChiffresLus!=10){
		return false;
	}
	
	return true;
}

/**
 * Test si le mois et l'année de la date de naissance passé en paeramètrre est conforme au numero de secu qui fait foir (également passé en paramètre)
 * @param dateNaissanceValue
 * @param numeroSsValue
 * @return -3=Année et mois incorrects, -2=Mois incorrect, -1=Année incorrecte, 1=OK   
 */
function checkDateNaissanceAgainstNumeroSS(dateNaissanceValue, numSSValue){
	//Extraction de l'année et du mois de naissance du N°SS pour controle de cohérence avec la date de naissance choisie
	var sexeSS =  numSSValue.substring(0,1);
	var anneeSS = numSSValue.substring(1,3);
	var moisSS = numSSValue.substring(3,5);
	var paysSS = numSSValue.substring(5,7);
	
	//Extraction de l'année et du mois de naissance de la saisie de la date de naissance	
	var anneeNaissanceSaisi = dateNaissanceValue.substring(8);
	var moisNaissanceSaisi = dateNaissanceValue.substring(3,5);
	
	//On ne verifie que pour le numéro de sécu principaux
	if ( sexeSS=="1" || sexeSS=="2" || sexeSS=="3" ){
		
		//Si le salarié n'est pas né à l'étranger : vérification du mois de naissance
		if ( paysSS != "99" ){
			if ( moisSS != moisNaissanceSaisi ){
				
				//vérification de l'année de naissance
				if ( anneeSS != anneeNaissanceSaisi ){	
					return -3; //Année et mois incorrects
				} else { 
					return -2; //Mois incorrect
				}
			}
		}
		
		//vérification de l'année de naissance
		if ( anneeSS != anneeNaissanceSaisi ){			
			return -1; //Année incorrecte
		}
	}
	
	return 1; //OK
}

function checkEmail(inputValue){

	if (isNull(inputValue)){
		inputValue='';
		return true;
	}

	//checks that there is one '@' and only one and checks also if the character '.' is present
	var firstAtPosition = inputValue.indexOf('@',0);
	var dotPosition = inputValue.indexOf('.',0);
	var spacePosition = inputValue.indexOf(' ',0);

	
	//If a space is present do not continue :
	if ( spacePosition!=-1 ){
		return false;
	}
	
	//If the character '@' or '.' are not present, display the error message
	if (firstAtPosition==-1 || dotPosition==-1){
		return false;
	}
	else{
		var secondAtPosition = inputValue.indexOf('@',firstAtPosition+1);

		//If the character '@' is present more than once, display the error message
		if(secondAtPosition!=-1){
			return false;
		}

		//else checks the length of the adress and the position of the characters '@' and '.' (and checks if there is the character '.' in the string after the '@'
		else{
			if( inputValue.length<5 || inputValue.charAt(0)=='@' || inputValue.charAt(0)=='.' || 
				inputValue.charAt(inputValue.length-1)=='@' || inputValue.charAt(inputValue.length-1)=='.' || 
				inputValue.charAt(firstAtPosition-1)=='.' || inputValue.charAt(firstAtPosition+1)=='.' || 
				inputValue.indexOf('.', firstAtPosition+1)==-1){
        			return false;
    			}
		}
	}

	return true;
}

/**
*Retourne un objet Date à partir de la date passée en paramètre avec le format DD/MM/YYYY
*/
function getDateFromDateString(dateString){
	var day = dateString.substring(0,2);
	var month = dateString.substring(3,5);
	var year = dateString.substring(6,10);

	return new Date(year, month-1, day); 
}


function isContainsApostrophize (inputName, inputValue){
	
 	if ( !(inputValue.indexOf('\'',0)==-1)){
	        return true;
	}
	return false;
}


function isContainsSpace (inputName, inputValue){
	
 	if ( !(inputValue.indexOf(' ',0)==-1))
	{
	        return true;
	}
	return false;
}

function isEmpty (inputValue) {
	inputValue = trim(inputValue);
    if ( (inputValue=="") || (inputValue == null) || (inputValue.length < 1) ){
		return true;
	}
	return false;
}


function isNull (inputValue) {
	return isEmpty(inputValue);
}

function trim(TRIM_VALUE){
	if(TRIM_VALUE.length < 1){
		return "";
	}
	TRIM_VALUE = rtrim(TRIM_VALUE);
	TRIM_VALUE = ltrim(TRIM_VALUE);

	if(TRIM_VALUE==""){
		return "";
	} else{
    	return TRIM_VALUE;
    }
}


function rtrim(VALUE){
	var w_space = String.fromCharCode(32);
	var v_length = VALUE.length;
	var strTemp = "";

	if(v_length < 0){
		return "";
	}
	var iTemp = v_length -1;

	while(iTemp > -1){
		if(VALUE.charAt(iTemp) != w_space){
			strTemp = VALUE.substring(0,iTemp +1);
			break;
		}
		iTemp = iTemp-1;
	}
	return strTemp;
}


function ltrim(VALUE){
	var w_space = String.fromCharCode(32);


	if(v_length < 1){
		return "";
	}
	var v_length = VALUE.length;
	var strTemp = "";
	var iTemp = 0;


	while(iTemp < v_length){
		if(VALUE.charAt(iTemp) != w_space){
			strTemp = VALUE.substring(iTemp,v_length);
			break;
		}
		iTemp = iTemp + 1;
	}
	return strTemp;
}

/**
 * @name isSirenValid
 *
 * @param Le code SIREN dont on veut vérifier la validité.
 *
 * @return Un booléen qui vaut 'true' si le code SIREN passé en paramètre est valide, false sinon.
 */
 function isSirenValid(siren) {
 	var isSirenvalid;
 	
 	if ( (siren.length != 9) || (isNaN(siren)) ){
		isSirenvalid = false;
	} else {
		// Donc le SIREN est un numérique à 9 chiffres
		var somme = 0;
		var tmp;
		
		for (var cpt = 0; cpt<siren.length; cpt++) {
			if ((cpt % 2) == 1) { // Les positions paires : 2ème, 4ème, 6ème et 8ème chiffre
				tmp = siren.charAt(cpt) * 2; // On le multiplie par 2
				if (tmp > 9){
					tmp -= 9; // Si le résultat est supérieur à 9, on lui soustrait 9
				}
			} else{
				tmp = siren.charAt(cpt);
			}
			somme += parseInt(tmp);
	 	}
		
		if ((somme % 10) == 0){
			isSirenvalid = true; // Si la somme est un multiple de 10 alors le SIREN est valide
		} else {
			isSirenvalid = false;
		}
	}
	
	return isSirenvalid;
 }

/**
 * @name isSiretValid
 *
 * @param Le code SIRET dont on veut vérifier la validité.
 *
 * @return Un booléen qui vaut 'true' si le code SIRET passé en paramètre est valide, false sinon.
 */
 function isSiretValid(siret) {
 	var isSiretvalid;
 	
	if ( (siret.length != 14) || (isNaN(siret)) ) {
		isSiretvalid = false;
	} else {
		// Donc le SIRET est un numérique à 14 chiffres
		// Les 9 premiers chiffres sont ceux du SIREN (ou RCS), les 4 suivants
		// correspondent au numéro d'établissement
		// et enfin le dernier chiffre est une clef de LUHN.
		var somme = 0;
		var tmp;
		
		for (var cpt = 0; cpt<siret.length; cpt++) {
			if ((cpt % 2) == 0) { // Les positions impaires : 1er, 3è, 5è, etc...
				tmp = siret.charAt(cpt) * 2; // On le multiplie par 2
				if (tmp > 9){					
					tmp -= 9; // Si le résultat est supérieur à 9, on lui soustrait 9
				}
			} else {
				tmp = siret.charAt(cpt);
			}
			somme += parseInt(tmp);
		}

		if ((somme % 10) == 0){
			isSiretvalid = true; // Si la somme est un multiple de 10 alors le SIRET est valide
		} else {
			isSiretvalid = false;
		}		
	}
	
	return isSiretvalid;
 } 


function nombreMoisEntreDeuxDates(startDate, endDate) {
	var nombreMois = 0;

	var startDateTemp = new Date(startDate.getYear(), startDate.getMonth(), startDate.getDate());
	var endDateTemp = new Date(endDate.getYear(), endDate.getMonth(), endDate.getDate());

	endDateTemp.setDate(endDateTemp.getDate()+1);//Si le jour+1 pointe sur le mois suivant, cela est géré par Javascript
	startDateTemp.setMonth(startDateTemp.getMonth()+1);//Si le mois+1 est égal à 13, cela est géré par Javascript
	
	while (startDateTemp<=endDateTemp){
		nombreMois++;
		startDateTemp.setMonth(startDateTemp.getMonth()+1);
	}

   	return nombreMois;
}

//diffDays = Math.floor((endDate - startDate) / 86400000); ne larche pas sur des années différentes
function nombreJoursEntreDeuxDates(startDate, endDate) {
	var nombreJours = 0;
	
	var startDateTemp = new Date(startDate.getYear(), startDate.getMonth(), startDate.getDate());
	var endDateTemp = new Date(endDate.getYear(), endDate.getMonth(), endDate.getDate());

	while (startDateTemp<=endDateTemp){
		nombreJours++;
		startDateTemp.setDate(startDateTemp.getDate()+1);//Si le jour+1 pointe sur le mois suivant, cela est géré par Javascript
 	}

   	return nombreJours;
}

//Week-end exclus
function nombreJoursTravailEntreDeuxDates(startDate, endDate) {
	
	var startDateTemp = new Date(startDate.getYear(), startDate.getMonth(), startDate.getDate());
	var endDateTemp = new Date(endDate.getYear(), endDate.getMonth(), endDate.getDate());

	var nombreJours = nombreJoursEntreDeuxDates(startDateTemp, endDateTemp);
	var nombreSemaines = Math.floor(nombreJours / 7);

   	var ajustement = 0;	 
	if (endDateTemp.getDay()>startDateTemp.getDay() && endDateTemp.getDay()!=6){
		ajustement = endDateTemp.getDay() - startDateTemp.getDay();
	}

  	return eval((nombreSemaines * 5) + ajustement);
}

//On suppose que la date entrée a été validée auparavant
//au format dd/mm/yyyy
function getDateFromString(strDate){	  
	day = strDate.substring(0,2);
	month = strDate.substring(3,5);
	year = strDate.substring(6,10);
	d = new Date();
	d.setDate(day);
	d.setMonth(month-1);
	d.setFullYear(year); 
	return d;  
}

 
/*	Permet de comparer 2 dates entre elles (heures exclues)
 *  Retourne : 0 si date_1=date_2; 1 si date_1>date_2;  -1 si date_1<date_2
 */
function compareDates(date_1, date_2){
	
	//On ne veut comparer que les jours et non les heures, donc on va les mettre à égalité pour ne pas que la différence se fasse dessus :
	  diff = date_1.getTime()-date_2.getTime(); // getTime renvoi la date exprimée en millisecondes
	  
	  if ( Math.abs(diff)<1000000 ){ //Si la différence entre les 2 dates est inférieure à 1 000 secondes (env. 16mn). La différence n'est pas significative puisqu'on compare des dates indépendamment des heures
		  return 0;
	  } 
	
	  
	  return diff/Math.abs(diff);
}

//Retourne true si la date est celle d'un jour férié
function isJourFerie(dateToTest){
//Source : http://www.joursferies.fr/ & http://www.calendrier-365.fr/
//Note : En France, les jours fériés sont légalement définis par le code du travail, article L3133-1 


	var joursFeriesArray = [//2010
	                   getDateFromString("01/01/2010"), //Jour de l'an 
	                   getDateFromString("05/04/2010"), //Lundi de Paques
	                   getDateFromString("01/05/2010"), //Fête du Travail
	                   getDateFromString("08/05/2010"), //8 Mai 1945
	                   getDateFromString("13/05/2010"), //Jeudi de l'Ascension
	                   getDateFromString("24/05/2010"), //Lundi de Pentecôte
	                   getDateFromString("14/07/2010"), //Fête Nationale
	                   getDateFromString("15/08/2010"), //Assomption
	                   getDateFromString("01/11/2010"), //La Toussaint
	                   getDateFromString("11/11/2010"), //Armistice
	                   getDateFromString("25/12/2010"), //Noël
	                   //2011
	                   getDateFromString("01/01/2011"), //Jour de l'an  
	                   getDateFromString("25/04/2011"), //Lundi de Paques
	                   getDateFromString("01/05/2011"), //Fête du Travail
	                   getDateFromString("08/05/2011"), //8 Mai 1945
	                   getDateFromString("02/06/2011"), //Jeudi de l'Ascension
	                   getDateFromString("13/06/2011"), //Lundi de Pentecôte
	                   getDateFromString("14/07/2011"), //Fête Nationale
	                   getDateFromString("15/08/2011"), //Assomption
	                   getDateFromString("01/11/2011"), //La Toussaint
	                   getDateFromString("11/11/2011"), //Armistice
	                   getDateFromString("25/12/2011"), //Noël
	                   //2012
	                   getDateFromString("01/01/2012"), //Jour de l'an  
	                   getDateFromString("09/04/2012"), //Lundi de Paques
	                   getDateFromString("01/05/2012"), //Fête du Travail
	                   getDateFromString("08/05/2012"), //8 Mai 1945
	                   getDateFromString("17/05/2012"), //Jeudi de l'Ascension
	                   getDateFromString("28/05/2012"), //Lundi de Pentecôte
	                   getDateFromString("14/07/2012"), //Fête Nationale
	                   getDateFromString("15/08/2012"), //Assomption
	                   getDateFromString("01/11/2012"), //La Toussaint
	                   getDateFromString("11/11/2012"), //Armistice
	                   getDateFromString("25/12/2012"), //Noël        
	                   //2013
	                   getDateFromString("01/01/2013"), //Jour de l'an  
	                   getDateFromString("01/04/2013"), //Lundi de Paques
	                   getDateFromString("01/05/2013"), //Fête du Travail
	                   getDateFromString("08/05/2013"), //8 Mai 1945
	                   getDateFromString("09/05/2013"), //Jeudi de l'Ascension
	                   getDateFromString("20/05/2013"), //Lundi de Pentecôte
	                   getDateFromString("14/07/2013"), //Fête Nationale
	                   getDateFromString("15/08/2013"), //Assomption
	                   getDateFromString("01/11/2013"), //La Toussaint
	                   getDateFromString("11/11/2013"), //Armistice
	                   getDateFromString("25/12/2013"), //Noël       
	                   //2014
	                   getDateFromString("01/01/2014"), //Jour de l'an  
	                   getDateFromString("21/04/2014"), //Lundi de Paques
	                   getDateFromString("01/05/2014"), //Fête du Travail
	                   getDateFromString("08/05/2014"), //8 Mai 1945
	                   getDateFromString("29/05/2014"), //Jeudi de l'Ascension
	                   getDateFromString("09/06/2014"), //Lundi de Pentecôte
	                   getDateFromString("14/07/2014"), //Fête Nationale
	                   getDateFromString("15/08/2014"), //Assomption
	                   getDateFromString("01/11/2014"), //La Toussaint
	                   getDateFromString("11/11/2014"), //Armistice
	                   getDateFromString("25/12/2014"), //Noël      
	                   //2015
	                   getDateFromString("01/01/2015"), //Jour de l'an  
	                   getDateFromString("06/04/2015"), //Lundi de Paques
	                   getDateFromString("01/05/2015"), //Fête du Travail
	                   getDateFromString("08/05/2015"), //8 Mai 1945
	                   getDateFromString("14/05/2015"), //Jeudi de l'Ascension
	                   getDateFromString("25/05/2015"), //Lundi de Pentecôte
	                   getDateFromString("14/07/2015"), //Fête Nationale
	                   getDateFromString("15/08/2015"), //Assomption
	                   getDateFromString("01/11/2015"), //La Toussaint
	                   getDateFromString("11/11/2015"), //Armistice
	                   getDateFromString("25/12/2015"), //Noël        
	                   //2016
	                   getDateFromString("01/01/2016"), //Jour de l'an  
	                   getDateFromString("28/03/2016"), //Lundi de Paques
	                   getDateFromString("01/05/2016"), //Fête du Travail
	                   getDateFromString("05/05/2016"), //8 Mai 1945
	                   getDateFromString("08/05/2016"), //Jeudi de l'Ascension
	                   getDateFromString("16/05/2016"), //Lundi de Pentecôte
	                   getDateFromString("14/07/2016"), //Fête Nationale
	                   getDateFromString("15/08/2016"), //Assomption
	                   getDateFromString("01/11/2016"), //La Toussaint
	                   getDateFromString("11/11/2016"), //Armistice
	                   getDateFromString("25/12/2016"), //Noël      
	                   //2017
	                   getDateFromString("01/01/2017"), //Jour de l'an  
	                   getDateFromString("17/04/2017"), //Lundi de Paques
	                   getDateFromString("01/05/2017"), //Fête du Travail
	                   getDateFromString("08/05/2017"), //8 Mai 1945
	                   getDateFromString("25/05/2017"), //Jeudi de l'Ascension
	                   getDateFromString("05/06/2017"), //Lundi de Pentecôte
	                   getDateFromString("14/07/2017"), //Fête Nationale
	                   getDateFromString("15/08/2017"), //Assomption
	                   getDateFromString("01/11/2017"), //La Toussaint
	                   getDateFromString("11/11/2017"), //Armistice
	                   getDateFromString("25/12/2017"), //Noël      
	                   //2018
	                   getDateFromString("01/01/2018"), //Jour de l'an  
	                   getDateFromString("02/04/2018"), //Lundi de Paques
	                   getDateFromString("01/05/2018"), //Fête du Travail
	                   getDateFromString("08/05/2018"), //8 Mai 1945
	                   getDateFromString("10/05/2018"), //Jeudi de l'Ascension
	                   getDateFromString("21/05/2018"), //Lundi de Pentecôte
	                   getDateFromString("14/07/2018"), //Fête Nationale
	                   getDateFromString("15/08/2018"), //Assomption
	                   getDateFromString("01/11/2018"), //La Toussaint
	                   getDateFromString("11/11/2018"), //Armistice
	                   getDateFromString("25/12/2018"), //Noël      
	                   //2019
	                   getDateFromString("01/01/2019"), //Jour de l'an  
	                   getDateFromString("22/04/2019"), //Lundi de Paques
	                   getDateFromString("01/05/2019"), //Fête du Travail
	                   getDateFromString("08/05/2019"), //8 Mai 1945
	                   getDateFromString("30/05/2019"), //Jeudi de l'Ascension
	                   getDateFromString("10/06/2019"), //Lundi de Pentecôte
	                   getDateFromString("14/07/2019"), //Fête Nationale
	                   getDateFromString("15/08/2019"), //Assomption
	                   getDateFromString("01/11/2019"), //La Toussaint
	                   getDateFromString("11/11/2019"), //Armistice
	                   getDateFromString("25/12/2019"), //Noël         
	                   //2020
	                   getDateFromString("01/01/2020"), //Jour de l'an  
	                   getDateFromString("13/04/2020"), //Lundi de Paques
	                   getDateFromString("01/05/2020"), //Fête du Travail
	                   getDateFromString("08/05/2020"), //8 Mai 1945
	                   getDateFromString("21/05/2020"), //Jeudi de l'Ascension
	                   getDateFromString("01/06/2020"), //Lundi de Pentecôte
	                   getDateFromString("14/07/2020"), //Fête Nationale
	                   getDateFromString("15/08/2020"), //Assomption
	                   getDateFromString("01/11/2020"), //La Toussaint
	                   getDateFromString("11/11/2020"), //Armistice
	                   getDateFromString("25/12/2020") //Noël       
	                   ];
	
	
	for (var i=0; i < joursFeriesArray.length; i++){
		
		if ( compareDates(dateToTest,joursFeriesArray[i])==0 ){
			//la date passé en paramètre est fériée!
			return true;
		}
	
	}
	return false;
	

}

function addDays(uneDate, nbJours)
{
 return new Date(uneDate.getTime() + (1000 * 60 * 60 * 24 * nbJours));
}

function getDateFinConge(dateDepartConge, nbJoursConges){
		
	while ( nbJoursConges>0 ){	
				
		//Si la date est un dimanche ou un jour férié : Ne décompte pas de jour de congé
		if ( dateDepartConge.getDay()==0 || isJourFerie(dateDepartConge) ){
			dateDepartConge = addDays(dateDepartConge,1); // se positionne sur le jour suivant	
			continue;
		}			
		
		//Sinon c'est bien un jour de congé : on le comptabilise
		dateDepartConge = addDays(dateDepartConge,1);	 // se positionne sur le jour suivant	
		nbJoursConges--;
		
	}
	
	//on est sur le jour calendaire suivant le fin du conge : on se repostionne sur le jour calendaire de fin du congé
	dateDepartConge = addDays(dateDepartConge,-1);
	
	return dateDepartConge;
	
}

function getDateRepriseTravail(dateDepartConge, nbJoursConges){
	
	//date retour = date fin conges + 1 jour	
	var dateRepriseTravail = getDateFinConge(dateDepartConge, nbJoursConges);	
	dateRepriseTravail = addDays(dateRepriseTravail,1); 
	
	//Si la date est un dimanche ou un jour férié : on va au jour suivant
	while ( dateRepriseTravail.getDay()==0 || isJourFerie(dateRepriseTravail) ){
		dateRepriseTravail = addDays(dateRepriseTravail,1);
	}
	
	return dateRepriseTravail;
	
}


