



//id  est l'id de l'element TABLE, TBODY, THEAD ou TFOOT à trier.
//col est l'indice de la colonne à trier, 0 = premiere colonne, 1 = 2e colonne, etc.
//rev est utilisé pour trier ou non le tableau dans l'ordre décroissant

function sortTable(id, col, rev) {

  var tblEl = document.getElementById(id);
  if (tblEl.reverseSort == null) {
    tblEl.reverseSort = new Array();
    tblEl.lastColumn = 1;
  }

  if (tblEl.reverseSort[col] == null)
    tblEl.reverseSort[col] = rev;

  if (col == tblEl.lastColumn)
    tblEl.reverseSort[col] = !tblEl.reverseSort[col];

  tblEl.lastColumn = col;

  var oldDsply = tblEl.style.display;
  tblEl.style.display = "none";

  var tmpEl;
  var i, j;
  var minVal, minIdx;
  var testVal;
  var cmp;

  for (i = 1; i < tblEl.rows.length - 1; i++) {

    minIdx = i;
    minVal = getTextValue(tblEl.rows[i].cells[col]);

    for (j = i + 1; j < tblEl.rows.length; j++) {
      testVal = getTextValue(tblEl.rows[j].cells[col]);
      cmp = compareValues(minVal, testVal);
      if (tblEl.reverseSort[col])
        cmp = -cmp;
      if (cmp == 0 && col != 1)
        cmp = compareValues(getTextValue(tblEl.rows[minIdx].cells[1]),
                            getTextValue(tblEl.rows[j].cells[1]));
      if (cmp > 0) {
        minIdx = j;
        minVal = testVal;
      }
    }

      
    if (minIdx > i) {
      var tmpRow = tblEl.rows[minIdx].innerHTML;
      var tmpRowIn = tblEl.insertRow(i);
      for(z = 0;z < tblEl.rows[minIdx+1].cells.length; z++){
      var tmpCell = tmpRowIn.insertCell(z);
      tmpCell.innerHTML = tblEl.rows[minIdx+1].cells[z].innerHTML;
      }
      
      tblEl.deleteRow(minIdx+1);
      
      
    }
  }
  tblEl.style.display = oldDsply;

  return false;
}

if (document.ELEMENT_NODE == null) {
  document.ELEMENT_NODE = 1;
  document.TEXT_NODE = 3;
}

function getTextValue(el) {

  var i;
  var s;

  s = "";
  for (i = 0; i < el.childNodes.length; i++)
    if (el.childNodes[i].nodeType == document.TEXT_NODE)
      s += el.childNodes[i].nodeValue;
    else if (el.childNodes[i].nodeType == document.ELEMENT_NODE &&
             el.childNodes[i].tagName == "BR")
      s += " ";
    else
      s += getTextValue(el.childNodes[i]);

  return normalizeString(s);
}

function compareValues(v1, v2) {

  var f1, f2;

  f1 = parseFloat(v1);
  f2 = parseFloat(v2);
  if (!isNaN(f1) && !isNaN(f2)) {
    v1 = f1;
    v2 = f2;
  }

  
  if (v1 == v2)
    return 0;
  if (v1 > v2)
    return 1
  return -1;
}

var whtSpEnds = new RegExp("^\\s*|\\s*$", "g");
var whtSpMult = new RegExp("\\s\\s+", "g");

function normalizeString(s) {

  s = s.replace(whtSpMult, " ");  
  s = s.replace(whtSpEnds, "");   

  return s;
}






//La date au format jj//mm//AAAA est elle plus récente que la date2
function compareDates(date1,date2){
var tab1 = date1.split('/');
var tab2 = date2.split('/');
if (tab1[2]==tab2[2]) {
	if (tab1[1]==tab2[1]){
		return (tab1[0]>tab2[0]);
	}
	else return (tab1[1]>tab2[1]);
}
else return (tab1[2]>tab2[2]);
}



function formatImmat(immat){
var sep= "[ \\-]";
var exp1 = "(^[0-9]{3}(("+sep+"?[a-zA-Z])|([0-9]"+sep+"?))[a-zA-Z]{2}"+sep+"?[0-9][a-zA-Z]$)";//999 XXX 9X;9999 XX 9X
var exp2 = "(^[0-9][0-9][0-9]?[0-9]?"+sep+"?[a-zA-Z]{2}"+sep+"?[0-9]{2}$)";//9999 XX 99;999 XX 99;99 XX 99
var exp3 = "(^[0-9][0-9][0-9]?"+sep+"?[a-zA-Z]{3}"+sep+"?[0-9]{2}$)";//999 XXX 99;99 XXX 99
var pattern = exp1+"|"+exp2+"|"+exp3;
var reg = new RegExp(pattern);
if (!immat.match(reg)) immat="";
return immat;
}



function sortTable(col, tableToSort)
{
var iCurCell = col + tableToSort.cols;
var totalRows = tableToSort.rows.length;
var bSort = 0;
var colArray = new Array();
var oldIndex = new Array();
var indexArray = new Array();
var bArray = new Array();
var newRow;
var newCell;
var i;
var c;
var j;
// ** POPULATE THE ARRAY colArray WITH CONTENTS OF THE COLUMN SELECTED
for (i=1; i < tableToSort.rows.length; i++)
colArray[i - 1] = setDataType(tableToSort.cells(iCurCell).innerText);
iCurCell = iCurCell + tableToSort.cols;
// ** COPY ARRAY FOR COMPARISON AFTER SORT
for (i=0; i < colArray.length; i++)
bArray[i] = colArray[i];
// ** 
}
//Bibliothèque de fonctions Commune IE & FireFox

//Retourne le Browser
function GetBrowserName() {
	var b=navigator.appName;
	window.alert(b);
	if (b.indexOf('Netscape')!=-1) this.b="ns";
	else if ((b=="Opera") || (navigator.userAgent.indexOf("Opera")>0)) this.b = "opera";
	else if (b=="Microsoft Internet Explorer") this.b="ie";
	if (!b) alert('Unidentified browser.\nThis browser is not supported,');
	var c= this.version=navigator.appVersion;
	window.alert(c);
	this.v=parseInt(this.version);
	this.ns=(this.b=="ns" && this.v>=4);
	this.ns4=(this.b=="ns" && this.v==4);
	this.ns6=(this.b=="ns" && this.v==5);
	this.ie=(this.b=="ie" && this.v>=4);
	this.ie4=(this.version.indexOf('MSIE 4')>0);
	this.ie5=(this.version.indexOf('MSIE 5')>0);
	this.ie55=(this.version.indexOf('MSIE 5.5')>0);
	this.ie6=(this.version.indexOf('MSIE 6.0')>0);
	this.opera=(this.b=="opera");
	this.dom=(document.createElement && document.appendChild && document.getElementsByTagName)?true:false;
	this.def=(this.ie||this.dom); // most used browsers, for faster if loops
	var ua=navigator.userAgent.toLowerCase();
	//window.alert(ua);
	if (ua.indexOf("win")>-1) this.platform="win32";
	else if (ua.indexOf("Mac")>-1) this.platform="mac";
	else this.platform="other";
	this.highbrowser=(this.ie5||this.ie55||this.ie6||this.ns6);
	this.lowbrowser=!(this.highbrowser);	
	if ((navigator.userAgent.toLowerCase().indexOf('libwww')!=-1)||(navigator.userAgent.toLowerCase().indexOf('spider')!=-1)||(navigator.userAgent.toLowerCase().indexOf('netcraft')!=-1)||(navigator.userAgent.toLowerCase().indexOf('lycos')!=-1)||(navigator.userAgent.toLowerCase().indexOf('fast')!=-1)||(navigator.userAgent.toLowerCase().indexOf('crawl')!=-1)||(navigator.userAgent.toLowerCase().indexOf('inktomi')!=-1)||(navigator.userAgent.toLowerCase().indexOf('jeeve')!=-1)||(navigator.userAgent.toLowerCase().indexOf('pompos')!=-1)||(navigator.userAgent.toLowerCase().indexOf('bot')!=-1)||(navigator.userAgent.toLowerCase().indexOf('echo')!=-1)||(navigator.userAgent.toLowerCase().indexOf('scooter')!=-1)||(navigator.userAgent.toLowerCase().indexOf('internetseer')!=-1)||(navigator.userAgent.toLowerCase().indexOf('ia_archiver')!=-1)||(navigator.userAgent.toLowerCase().indexOf('ng/')!=-1)||(navigator.userAgent.toLowerCase().indexOf('almaden')!=-1)||(navigator.userAgent.toLowerCase().indexOf('slurp')!=-1)||(navigator.userAgent.toLowerCase().indexOf('mercator')!=-1)||(navigator.userAgent.toLowerCase().indexOf('appie')!=-1)||(navigator.userAgent.toLowerCase().indexOf('xenu')!=-1)||(navigator.userAgent.toLowerCase().indexOf('scrub')!=-1)||(navigator.userAgent.toLowerCase().indexOf('robo')!=-1)||(navigator.userAgent.toLowerCase().indexOf('relevare')!=-1)) this.robot=true;
}

//Affichage en plein ecran
function FullScreen()
{
	window.moveTo(0,0);
	if (document.all){
		window.resizeTo(screen.availWidth,screen.availHeight);
	}
	else if (document.layers) {
		if (window.outerHeight<screen.availHeight||window.outerWidth<screen.availWidth)	{
			window.outerHeight = screen.availHeight;
			window.outerWidth = screen.availWidth;
		}
	}
}		

// Fonction de masquage des span d'erreur avec re affichage des select
function CacheSpanErr(DivSpan)
{
	document.getElementById(DivSpan).style.display="none";
	var aSelect=document.getElementsByTagName('select');
	for (i=0;i<aSelect.length;i++)
	{
		aSelect[i].style.display="block";
	}  
}

// Fonction d'affichage d'un Span ou Div d'erreur avec masquage des select
function MontreSpan(DivSpan)
{
	document.getElementById('DivSpan').style.display="block";
	var aSelect=document.getElementsByTagName('select');
	for (i=0;i<aSelect.length;i++)
	{
		aSelect[i].style.display="none";
	}  
}


//Fonction commune Affichage/Masquage d'un Bloc ou d'une Div ou Span
function AfficheCacheObj(Obj, Affiche) 
{
 	var hidden = document.layers ? 'hide' : 'hidden';
	var visible = document.layers ? 'show' : 'visible';
 	//var divStyle = (document.layers) ? document.layers[divID] : document.all ?
 	//document.all[divID].style : document.getElementById(divID).style;
 	if (Affiche) 
 	{
		Obj.style.visibility = visible;
 	}  
	else
 	{
	 	Obj.style.visibility = hidden;
 	}
}

//Fonction Commune d'ouverture de Fenêtres
function OpenWindow(theURL,winName,features, myWidth, myHeight, isCenter) 
{
	if (window.winName!= null) window.winName.close();
	var myLeft = (screen.width-myWidth)/2;
	var myTop = (screen.height-myHeight)/2;
	features+=(features!='')?',':'';
	if (features != 'scrollbars=0,') features+=',scrollbars=1';
	features+=',left='+myLeft+',top='+myTop;
	mywindow = window.open(theURL,winName,features+((features!='')?',':'')+'width='+myWidth+',height='+myHeight);
	
}

//CONTENU DU FICHIER date.js

function JJMMAAAA(strdate){
		var jour, mois, annee;
		var chaine;
		var i, len;
	
		// teste si la chaine existe
		len	= strdate.length;
		if (len==0) { return ""; }

		//positionnement sur le premier chiffre
		i = 0;
		while (((strdate.charAt(i)<'0')||(strdate.charAt(i)>'9'))&&(++i<len)) {}
		if (i==len) { return ""; }

		// extraction du jour
		chaine = "";
		jour	= 0;
		while ((strdate.charAt(i)>='0')&&(strdate.charAt(i)<='9'))
		{
			chaine += strdate.charAt(i);
			jour = jour*10 + eval(strdate.charAt(i),10);
			i++;
			if (i>=len) break;
		}
						
		if ((jour>31)||(jour==0))
		{
			if ((chaine.length==6)||(chaine.length==8))
			{
				//forme jjmmaa ou jjmmaaaa
				jour  = eval(chaine.charAt(0),10)*10+eval(chaine.charAt(1),10);
				mois  = eval(chaine.charAt(2),10)*10+eval(chaine.charAt(3),10);
				annee = eval(chaine.charAt(4),10)*10+eval(chaine.charAt(5),10);
				if (chaine.length==8)
				{
					annee = annee*100 + eval(chaine.charAt(6),10)*10+eval(chaine.charAt(7),10);
				}
				if ((jour>31)||(jour==0)||(mois>12)||(mois==0)) { return ""; }	
			}
			else { return ""; }
		}
		else
		{
					
			//positionnement sur le deuxieme chiffre
			while (((strdate.charAt(i)<'1')||(strdate.charAt(i)>'9'))&&(++i<len)) {}
			if (i==len) { return ""; }

			// extraction du mois
			mois = 0;
			while ((strdate.charAt(i)>='0')&&(strdate.charAt(i)<='9'))
			{
				mois = mois*10 + eval(strdate.charAt(i),10);
				i++;
				if (i>=len) break;
			}
			if ((mois>12)||(mois==0)) { return "";  }
		
			//positionnement sur le troisieme chiffre
			while (((strdate.charAt(i)<'0')||(strdate.charAt(i)>'9'))&&(++i<len)) {}
			if (i==len) { return ""; }
			
			// extraction de l'année
			annee	= 0;
			while ((strdate.charAt(i)>='0')&&(strdate.charAt(i)<='9'))
			{
				annee = annee*10 + eval(strdate.charAt(i),10);
				i++;
				if (i>=len) break;
			}
		}
			
		// fenêtrage
		if (annee<15)
		{
			annee += 2000;
		}
		if (annee<100)
		{
			annee += 1900;
		}			
		
		var jourbis, moisbis;
		jourbis = "" + eval(jour);
		moisbis = "" + eval(mois);
		
		if ( jourbis.length<2 )
		{
			jourbis = "0" + eval(jour);
		}
		
		if ( moisbis.length<2 )
		{
			moisbis = "0" + eval(mois);
		}
		
		return	"" + jourbis + "/" + moisbis + "/" + annee;
	}	
	
	function MMAAAA(strdate){
		var mois, annee;
		var chaine;
		var i, len;
	
		// teste si la chaine existe
		len	= strdate.length;
		if (len==0) { return ""; }

		//positionnement sur le premier chiffre
		i = 0;
		while (((strdate.charAt(i)<'0')||(strdate.charAt(i)>'9'))&&(++i<len)) {}
		if (i==len) { return ""; }

		// extraction du mois
		chaine	= "";
		mois	= 0;
		while ((strdate.charAt(i)>='0')&&(strdate.charAt(i)<='9'))
		{
			chaine += strdate.charAt(i);
			mois = mois*10 + eval(strdate.charAt(i),10);
			i++;
			if (i>=len) break;
		}
						
		if ((mois>12)||(mois==0))
		{
			if ((chaine.length==4)||(chaine.length==6))
			{
				//forme mmaa ou mmaaaa
				mois  = eval(chaine.charAt(0),10)*10+eval(chaine.charAt(1),10);
				annee = eval(chaine.charAt(2),10)*10+eval(chaine.charAt(3),10);
				if (chaine.length==6)
				{
					annee = annee*100 + eval(chaine.charAt(4),10)*10+eval(chaine.charAt(5),10);
				}
				if ((mois>12)||(mois==0)) { return ""; }	
			}
			else { return ""; }
		}
		else
		{
					
			//positionnement sur le deuxieme chiffre
			while (((strdate.charAt(i)<'0')||(strdate.charAt(i)>'9'))&&(++i<len)) {}
			if (i==len) { return ""; }
			
			// extraction de l'année
			annee	= 0;
			while ((strdate.charAt(i)>='0')&&(strdate.charAt(i)<='9'))
			{
				annee = annee*10 + eval(strdate.charAt(i),10);
				i++;
				if (i>=len) break;
			}
		}
			
		// fenêtrage
		if (annee<15)
		{
			annee += 2000;
		}
		if (annee<100)
		{
			annee += 1900;
		}	
		mois+="";	
		if (mois.length <2) mois ="0"+mois;
		return	"" + mois + "/" + annee;
	}	
	
	function AAAA(strdate){
		var annee;
		var i, len;
	
		// teste si la chaine existe
		len	= strdate.length;
		if (len==0) { return ""; }

		//positionnement sur le premier chiffre
		i = 0;
		while (((strdate.charAt(i)<'0')||(strdate.charAt(i)>'9'))&&(++i<len)) {}
		if (i==len) { return ""; }

		// extraction de l'année
		annee	= 0;
		while ((strdate.charAt(i)>='0')&&(strdate.charAt(i)<='9'))
		{
			annee = annee*10 + eval(strdate.charAt(i),10);
			i++;
			if (i>=len) break;
		}
									
		// fenêtrage
		if (annee<15)
		{
			annee += 2000;
		}
		if (annee<100)
		{
			annee += 1900;
		}			

		return	"" + annee;
	}	
	
//CONTENU DU FICHIER dhtml.js

function MM_findObj(n, d) { //v4.01 
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function ShowBlock(btn,blk){ // FG V1.2 Affiche le bloc 'blk' et modifie le bouton 'btn' 
if (btn!="" && blk!="") 
	{
	obj = MM_findObj(btn);
	obj.innerHTML = "<a href=\"javascript:HideBlock('" + btn + "','" + blk + "');\" class=\"BOUTONENSAVOIRPLUS\">&nbsp;>&nbsp;<b>Cacher</b>&nbsp;<&nbsp;</a>";
	obj2 = MM_findObj(blk);
	obj2.style.display = "block";
	}
else 
	{
	obj = MM_findObj(blk);
	obj.style.display = "block";
	}	
}

function HideBlock(btn,blk){ // FG V1.2 Masque le bloc 'blk' et modifie le bouton 'btn' 
if (btn!="" && blk!="") 
	{
	obj = MM_findObj(btn);
	obj.innerHTML="<a href=\"javascript:ShowBlock('" + btn + "','" + blk + "');\" class=\"BOUTONENSAVOIRPLUS\">&nbsp;>&nbsp;<b>En savoir plus</b>&nbsp;<&nbsp;</a>";
	obj2 = MM_findObj(blk);
	obj2.style.display = "none";
	}
else 
	{
	obj = MM_findObj(blk);
	obj.style.display = "none";
	}	
}

function ShowBlockArchives(btn,blk){ // FG V1.2 Affiche le bloc 'blk' et modifie le bouton 'btn' 
if (btn!="" && blk!="") 
	{
	obj = MM_findObj(btn);
	obj.innerHTML = "&nbsp;>&nbsp;<a href=\"javascript:HideBlockArchives('" + btn + "','" + blk + "');\"><b>Cacher les archives</b></a>&nbsp;<&nbsp;";
	obj2 = MM_findObj(blk);
	obj2.style.display = "block";
	}
else 
	{
	obj = MM_findObj(blk);
	obj.style.display = "block";
	}	
}

function HideBlockArchives(btn,blk){ // FG V1.2 Masque le bloc 'blk' et modifie le bouton 'btn' 
if (btn!="" && blk!="") 
	{
	obj = MM_findObj(btn);
	obj.innerHTML="&nbsp;>&nbsp;<a href=\"javascript:ShowBlockArchives('" + btn + "','" + blk + "');\"><b>Voir les archives</b></a>&nbsp;<&nbsp;";
	obj2 = MM_findObj(blk);
	obj2.style.display = "none";
	}
else 
	{
	obj = MM_findObj(blk);
	obj.style.display = "none";
	}	
}
	
function ChangeImage(img,newsrc) { // FG V1.0 
	i = MM_findObj(img);
	i.src = newsrc;
}

function ShowDiv(blk) {
	obj = MM_findObj(blk);
	obj.style.display = "block";
}

function HideDiv(blk) {
	obj = MM_findObj(blk);
	obj.style.display = "none";
}

function fnForm_number(oInput, iMaxLength) {
	if ((! oInput) || (! oInput.value)) return;
	
	var sValue = oInput.value;
	var iDiff  = iMaxLength - sValue.length;
	
	for (var i = 0; i < iDiff; i++) {
		sValue = "0" + sValue;
	}
	
	oInput.value = sValue;
}

function emailCheck (emailStr) {

	var emailPat=/^(.+)@(.+)$/
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	var validChars="\[^\\s" + specialChars + "\]"
	var quotedUser="(\"[^\"]*\")"
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	var atom=validChars + '+'
	var word="(" + atom + "|" + quotedUser + ")"
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
	var matchArray=emailStr.match(emailPat)
	if (matchArray==null) {
		alert("Cette adresse e-mail est incorrecte (vérifiez les '@' et les '.')")
		return false
	}
	var user=matchArray[1]
	var domain=matchArray[2]

	if (user.match(userPat)==null) {
	    alert("Le nom avant saisi avant le '@' est incorrect.")
	    return false
	}

	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) {
		  for (var i=1;i<=4;i++) {
		    if (IPArray[i]>255) {
		        alert("L'adresse IP saisie après le '@' est incorrecte.")
			return false
		    }
	    }
	    return true
	}

	var domainArray=domain.match(domainPat)
	if (domainArray==null) {
		alert("Le nom de domaine saisi après le '@' est incorrect.")
	    return false
	}

	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if (domArr[domArr.length-1].length<2 || 
	    domArr[domArr.length-1].length>3) {
	   alert("L'adresse e-mail doit être terminée par un groupe de 2 ou 3 lettres.")
	   return false
	}

	if (len<2) {
	   var errStr="Le nom de domaine est incomplet."
	   alert(errStr)
	   return false
	}
return true; 
}

function reloadetape(){
	top.etape.location.reload();
}

/*
* This function will not return until (at least)
* the specified number of milliseconds have passed.
* It uses a modal dialog.
*/
function pause(numberMillis) 
{
	var dialogScript = 
		'window.setTimeout(' +
		' function () { window.close(); }, ' + numberMillis + ');';
	// For IE5.
	if ((navigator.appName=='Microsoft Internet Explorer'))
	{
		//On récupére le numéro de la version.
		version=navigator.appVersion.substring(navigator.appVersion.indexOf("MSIE",0)+5,navigator.appVersion.indexOf(";",navigator.appVersion.indexOf("MSIE",0)));
		if(version>=5)
		{
			window.showModalDialog(
			'javascript:document.writeln(' +
			'"<script>' + dialogScript + '<' + '/script>")');
		}
	}
	else
	{
		// For Opera
		if (navigator.appName=='Opera')
		{
			//On récupére le numéro de la version.
			version=navigator.appVersion.substring(navigator.appVersion,navigator.appVersion.indexOf("(",0));
			window.showModalDialog(
			'javascript:document.writeln(' +
			'"<script>' + dialogScript + '<' + '/script>")');
		}
		else
		{
			// For NN6, but it requires a trusted script.
			if (navigator.appName=='Netscape')
			{
				//On récupére le numéro de la version.
				version=(navigator.appVersion.substring(0,navigator.appVersion.indexOf("(",0)));
				if(version>=6)
				{
					openDialog(
					'javascript:document.writeln(' +
					'"<script>' + dialogScript + '<' + '/script>"',
					'pauseDialog', 'modal=1,width=10,height=10');
				}
			}
		}
	}
}



