function addDaysToDate(old_date, delta_days){    
	// Date plus plus quelques jours   
	if (old_date!=""&&isDate(old_date)) {
		var split_date = old_date.split('/');    
		// Les mois vont de 0 a 11 donc on enleve 1, cast avec *1   
		var new_date = new Date(split_date[2], split_date[1]*1 - 1, split_date[0]*1 + delta_days);    
		var new_day = new_date.getDate();        
		new_day = ((new_day < 10) ? '0' : '') + new_day; // ajoute un zéro devant pour la forme    
		var new_month = new_date.getMonth() + 1;        
		new_month = ((new_month < 10) ? '0' : '') + new_month; // ajoute un zéro devant pour la forme    
		var new_year = new_date.getYear();        
		new_year = ((new_year < 200) ? 1900 : 0) + new_year; // necessaire car IE et FF retourne pas la meme chose    
		var new_date_text = new_day + '/' + new_month + '/' + new_year;   
		return new_date_text;
	} else {
		return "";
	}
} 

function getCurrentDate() {
	currdate=new Date();
	day=currdate.getDate();
	month=currdate.getMonth()+1;
	year=currdate.getFullYear();
	(day<10)?strday="0" + day:strday=day;
	(month<10)?strmonth="0" + month:strmonth=month;
	return strday+"/"+strmonth+"/"+year;
}

function getFirstMonthDate() {
	currdate=new Date();
	month=currdate.getMonth()+1;
	year=currdate.getFullYear();
	(month<10)?strmonth="0" + month:strmonth=month;
	return "01/"+strmonth+"/"+year;
}

function isDate(d) {
	// Cette fonction permet de vérifier la validité d'une date au format jj/mm/aa ou jj/mm/aaaa
	// Par Romuald
	
	if (d == "") return false;
	
	e = new RegExp("^[0-9]{1,2}\/[0-9]{1,2}\/[0-9]{4}$");
	
	if (!e.test(d)) return false; 

	// On sépare la date en 3 variables pour vérification, parseInt() converti du texte en entier
	j = parseInt(d.split("/")[0], 10); // jour
	m = parseInt(d.split("/")[1], 10); // mois
	a = parseInt(d.split("/")[2], 10); // année

	// Définition du dernier jour de février
	// Année bissextile si annnée divisible par 4 et que ce n'est pas un siècle, ou bien si divisible par 400
	fev=(a%4 == 0 && a%100 !=0 || a%400 == 0)?29:28;

	// Nombre de jours pour chaque mois
	nbJours = new Array(31,fev,31,30,31,30,31,31,30,31,30,31);

	// Enfin, retourne vrai si le jour est bien entre 1 et le bon nombre de jours, idem pour les mois, sinon retourn faux
	return ( m >= 1 && m <=12 && j >= 1 && j <= nbJours[m-1] );
}


function TestWin()
{
  if (MyWin && MyWin.open && !MyWin.closed) MyWin.close();
}

function testWin(objWin)
{
  if (ExistWin(objWin)) objWin.close();
}

function ExistWin(objWin) {
	if (objWin && objWin.open && !objWin.closed) {return true} else {return false}
}

function formatNum(valeur,decimal,separateur) {
// formate un chiffre avec 'decimal' chiffres après la virgule et un separateur
	var val_format;
	if (!isNaN(valeur)) {
		var deci=Math.round( Math.pow(10,decimal)*(Math.abs(valeur)-Math.floor(Math.abs(valeur)))) ; 
		var val=Math.floor(Math.abs(valeur));
		if ((decimal==0)||(deci==Math.pow(10,decimal))) {val=Math.floor(Math.abs(valeur)); deci=0;}
		val_format=val+"";
		var nb=val_format.length;
		for (var i=1;i<4;i++) {
			if (val>=Math.pow(10,(3*i))) {
				val_format=val_format.substring(0,nb-(3*i))+separateur+val_format.substring(nb-(3*i));
			}
		}
		if (decimal>0) {
			var decim=""; 
			for (var j=0;j<(decimal-deci.toString().length);j++) {decim+="0";}
			deci=decim+deci.toString();
			val_format=val_format+"."+deci;
		}
		if (parseFloat(valeur)<0) {val_format="-"+val_format;}
	} else {
		val_format="";
	}
	return val_format;
}

function showWin(cURL, cName, winW, winH, topP, leftP, txtTitle, txtScrollBars) {
	MyWin = null;
	if (!txtScrollBars||txtScrollBars=="") {txtScrollBars="yes";}

  ns4 = (document.layers)? true:false;
  availW = (screen.availWidth-10);
  availH = (screen.availHeight-30);
  if (winW==0) {winW=availW}
  if (winH==0) {winH=availH}
  if (!topP) {topP = (availH-winH)/2;}
  if (!leftP) {leftP = (availW-winW)/2;}

  MyWin=window.open('',cName,'resizable=no,scrollbars=' + txtScrollBars + ',toolbar=no,status=yes,menubar=no,location=no,directories=no,width='+winW+',height='+winH+',top='+topP+',left='+leftP);
  if (ExistWin(MyWin)) {
	  MyWin.location=cURL;
	  if (txtTitle) {MyWin.title=txtTitle;}
	  MyWin.focus();
  } else {
	  alert("Un anti pop-up est activé sur votre navigateur\n\rVeuillez le désactiver pour assurer le fonctionnement optimal de ce site\n\rMerci");
  } 
  return MyWin
}

/* Cette fonction s'utilise sur l'évènement onblur d'un objet texte
	Exemple :
	onblur="javascript:setValFin(this, document.frmMain.Hcdedte_a);"
	i.e. : la valeur du champ courant devient la valeur de l'objet cible
*/
function setValFin(objOri, objDest) {
	if (objDest.value==""&&objOri.value!="") {
		objDest.value=objOri.value;
	}
}

/*Formate une date en jj/mm/yyyy*/
function formatDate(MyDate)
{
	var dTmp, txtDay, txtMonth, txtYear;
	var dGen, iDay, iMonth, iYear;
	if ((MyDate.length>7)&&(MyDate.indexOf("/")!=-1))
	{
		dTmp=MyDate.split("/");
		if ((dTmp.length==3)&&(!isNaN(parseInt(dTmp[0]))&&!isNaN(parseInt(dTmp[1]))&&!isNaN(parseInt(dTmp[2]))))
		{
			txtDay=dTmp[0];
			txtMonth=dTmp[1];
			txtYear=dTmp[2];

			dGen = new Date((parseInt(txtYear)), (parseInt(txtMonth)-1), (parseInt(txtDay)));
			iDay = dGen.getDate();
			iMonth = dGen.getMonth()+1;
			iYear = dGen.getFullYear();
			(iDay<10)?(txtDay="0"+iDay):(txtDay=iDay);
			(iMonth<10)?(txtMonth="0"+iMonth):(txtMonth=iMonth);
			txtYear=iYear;
			tmpStr=(txtDay + "/" + txtMonth + "/" + txtYear);
			return tmpStr;
		}
		else
		{
			return "00/00/0000";
		}
	}
	else
	{
		return "00/00/0000";
	}
}

function browser_check() { 
	var is_major = parseInt(navigator.appVersion);
	this.ver=navigator.appVersion;
	this.agent=navigator.userAgent;
	this.dom=document.getElementById?1:0;
	this.opera=this.agent.indexOf("Opera")>-1;
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera)?1:0;
	this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera)?1:0;
	this.ie4=(document.all && !this.dom && !this.opera)?1:0;
	this.ie=this.ie4||this.ie5||this.ie6;
	this.mac=this.agent.indexOf("Mac")>-1;
	this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0;
	this.ie3 = (this.ver.indexOf("MSIE") && (is_major < 4));
	this.hotjava = (this.agent.toLowerCase().indexOf('hotjava') != -1)? 1:0;
	this.ns4=(document.layers && !this.dom && !this.hotjava)?1:0;
	this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera);
	this.ie=(this.ie5 || this.ie4 || this.ie6 || this.mac)
	this.ns=(this.ns4 || this.ns5 || this.ns6)
	return this
}

var winH2use=0; var winW2use=0;
function getWindowHW() {
	if( typeof( window.innerWidth ) == 'number' ) {
  	winW2use = window.innerWidth;
  	winH2use = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
  	winW2use = parseInt(document.documentElement.clientWidth);
  	winH2use = parseInt(document.documentElement.clientHeight);
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
  	winW2use = parseInt(document.body.clientWidth);
  	winH2use = parseInt(document.body.clientHeight);
  } else {
  	winW2use = -1;
  	winH2use = -1;
  } 
}

function makeMsg(strmsg, strvalue) {
	var msgtemp=strmsg;
	if (msgtemp!="") msgtemp+="\r\n";
	msgtemp+=strvalue;
	return msgtemp;
}

function setPosY(itemname) {
  var contentElement=document.getElementById(itemname);
  contentElement.style.position="relative";
  objWin=new windowSize(); objWin.getSizes();
  contentElement.style.top = ((objWin.height / 2) - (contentElement.offsetHeight / 2)) + objWin.scrolly + 'px';
}

function SorH(iditem) {
	if (document.getElementById(iditem)) {
		currdisplay=document.getElementById(iditem).style.display;
		document.getElementById(iditem).style.display=(currdisplay==""?"none":"");
	}
}

windowSize=function() {
	this.height=0; this.width=0;
	this.scrollx=0; this.scrolly=0;
	
	this.getSizes=function() {
		if (window.innerHeight&&typeof(window.innerHeight) == 'number') {
			this.height = window.innerHeight; this.width = window.innerWidth;
		} else {
			if (document.documentElement && document.documentElement.clientHeight) {
				this.height = document.documentElement.clientHeight; this.width = document.documentElement.clientWidth;
			} else if (document.body && document.body.clientHeight) {
				this.height = document.body.clientHeight; this.width = document.body.clientWidth;
			}
		}
	}
	
	this.getScrolls=function() {
		if (window.innerHeight) {
			this.scrollx = window.pageXOffset; this.scrolly = window.pageYOffset;
		} else {
			if (document.documentElement && document.documentElement.scrollLeft) {
				this.scrollx = document.documentElement.scrollLeft; this.scrolly = document.documentElement.scrollTop;
			} else {
				this.scrollx = document.body.scrollLeft; this.scrolly = document.body.scrollTop;
			}
		}
	}
}

function clearChildNodes(objparent) {
	while (objparent.firstChild) {
		clearChildNodes(objparent.firstChild);
	  objparent.removeChild(objparent.firstChild);
	}
}



