//FONCTION POUR AGRANDIR UNE IMAGE
	function agrandir_photo(chemin,photo){
		window.open(chemin+photo)	
	}


//POUR AFFICHER UNE GRANDE IMAGE SOUS FORME D'UNE POPUS
function PopupImage(img) { 
	w=open("",'image','weigth=toolbar=no,scrollbars=no,resizable=no, width=320, height=272, left=300, top=200'); 
	w.document.write("<HTML><BODY topmargin='0px' bottommargin='0px'   leftmargin='0px' rightmargin='0px' onblur=\"window.close();\"><object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0' width=320 height=272><param name=movie value='animations/diaporama.swf'><param name=quality value=high><embed src='animations/diaporama.swf' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width=320 height=272></embed></object>"); 		
	w.document.write("</BODY></HTML>"); 
	w.document.close(); 
} 
function mailtoo(email){    
	chaine_mail = "mailto:"+email+"?subject=" + document.title;      
	chaine_mail += "&body="; 
	chaine_mail += ""; location.href = chaine_mail;     
} 
function mailtooo(email,titre){
	chaine_mail = "mailto:"+email+"?subject=" + titre;      
	chaine_mail += "&body="; 
	chaine_mail += ""; location.href = chaine_mail;     
} 
function changeImages(name,image) {
	document.images[name].src=image
}

var ancien="";

function getHTTPObject() {
	var xmlhttp;
	if (navigator.appName=="Microsoft Internet Explorer")
		var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 
		//il faut remplacer "Microsoft.XMLHTTP" par "Msxml2.XMLHTTP.5.0" pour eviter l'erreur system : 1072896748 
		//pour les actentuées : test réussi est validé		
	else 	
		var xmlhttp = new XMLHttpRequest();  

  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
      } catch (e) {
      	xmlhttp = false;
      }
    }
  return xmlhttp;
}
var http = getHTTPObject();

var marked_row = new Array;
function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
    var theCells = null;

    // 1. Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }

    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }
    // 3.2 ... with other browsers
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    } // end 3

    // 3.3 ... Opera changes colors set via HTML to rgb(r,g,b) format so fix it
    if (currentColor.indexOf("rgb") >= 0)
    {
        var rgbStr = currentColor.slice(currentColor.indexOf('(') + 1,
                                     currentColor.indexOf(')'));
        var rgbValues = rgbStr.split(",");
        currentColor = "#";
        var hexChars = "0123456789ABCDEF";
        for (var i = 0; i < 3; i++)
        {
            var v = rgbValues[i].valueOf();
            currentColor += hexChars.charAt(v/16) + hexChars.charAt(v%16);
        }
    }

    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == ''
        || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor              = thePointerColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
            // Garvin: deactivated onclick marking of the checkbox because it's also executed
            // when an action (like edit/delete) on a single item is performed. Then the checkbox
            // would get deactived, even though we need it activated. Maybe there is a way
            // to detect if the row was clicked, and not an item therein...
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = true;
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
             && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
        if (theAction == 'out') {
            newColor              = theDefaultColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = true;
        }
    }
    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
            newColor              = (thePointerColor != '')
                                  ? thePointerColor
                                  : theDefaultColor;
            marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
                                  ? true
                                  : null;
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = false;
        }
    } // end 4

    // 5. Sets the new color...
    if (newColor) {
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            } // end for
        }
        // 5.2 ... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    } // end 5

    return true;
} // end of the 'setPointer()' function



function setCheckboxColumn(theCheckbox){
    if (document.getElementById(theCheckbox)) {
        document.getElementById(theCheckbox).checked = (document.getElementById(theCheckbox).checked ? false : true);
        if (document.getElementById(theCheckbox + 'r')) {
            document.getElementById(theCheckbox + 'r').checked = document.getElementById(theCheckbox).checked;
        }
    } else {
        if (document.getElementById(theCheckbox + 'r')) {
            document.getElementById(theCheckbox + 'r').checked = (document.getElementById(theCheckbox +'r').checked ? false : true);
            if (document.getElementById(theCheckbox)) {
                document.getElementById(theCheckbox).checked = document.getElementById(theCheckbox + 'r').checked;
            }
        }
    }
}


function isExtsAllowed(path) {
	var lastDot = path.lastIndexOf("."); //index of last dot, the extension will follow this dot
	if(lastDot != 1) { //if we found a dot, that means we have an extension
		var fileExts = path.substring(lastDot + 1, path.length).toLowerCase();
		//loop through array of allowed extensions and check if this one is allowed
		for(var i = 0; i < allowedExts.length; i++) {
			//alert (fileExts);
			if(fileExts == allowedExts[i]) //if the extension is in the list of allowed
				return true;
		}
	}
	
	return false;
}


function messages(champs,libelle){
	if (document.getElementById(champs).value==""){
		document.getElementById('id_validation').style.visibility='visible'
		document.getElementById('id_validation').innerHTML="Le champs "+libelle+" ne doit pas être une chaine vide "
		document.getElementById(champs).focus()
		return false
	}else{
		document.getElementById('id_validation').style.visibility='hidden'
		return true
	}
}



function adad(champs,libelle){
	if (isNaN(document.getElementById(champs).value)){
		document.getElementById('id_validation').style.visibility='visible'
		document.getElementById('id_validation').innerHTML="Le champs "+libelle+" n'est pas une valuer numérique !"
		document.getElementById(champs).focus()
		return false
	}else{
		document.getElementById('id_validation').style.visibility='hidden'
		return true
	}
}

function checkdate(champs,libelle){
	if(!isDate(document.getElementById(champs).value)  ) {
		document.getElementById('id_validation').style.visibility='visible'
		document.getElementById('id_validation').innerHTML="Le format de la "+libelle+" n'est pas valide (ex: 31-02-2007) !"
		document.getElementById(champs).focus()
		return false
	}else{
		document.getElementById('id_validation').style.visibility='hidden'
		return true
	}
}

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 == "") // si la variable est vide on retourne faux
		return false;
	
	e = new RegExp("^[0-9]{1,2}\-[0-9]{1,2}\-([0-9]{2}|[0-9]{4})$");
	
	if (!e.test(d)) // On teste l'expression régulière pour valider la forme de la date
		return false; // Si pas bon, retourne faux

	// 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

	// Si l'année n'est composée que de 2 chiffres on complète automatiquement
	if (a < 1000) {
		if (a < 89)	a+=2000; // Si a < 89 alors on ajoute 2000 sinon on ajoute 1900
		else a+=1900;
	}

	// 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
	if (a%4 == 0 && a%100 !=0 || a%400 == 0) fev = 29;
	else fev = 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 visibilite(thingId){
	var targetElement;
	targetElement = document.getElementById(thingId) ;
	if (ancien!=""){
		document.getElementById(ancien).style.display = "none"
		document.getElementById(ancien).style.visibility = "hidden"
	}
	if (targetElement.style.display == "none"){
		targetElement.style.display = "" ;
		targetElement.style.visibility = "visible" ;
	} else {
		targetElement.style.display = "none" ;
		targetElement.style.visibility = "hidden" ;
	}
	ancien=thingId

}

var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

function checkmail(champs,libelle){
	if ( !filter.test(document.getElementById(champs).value) ){
		document.getElementById('id_validation').style.visibility='visible'
		document.getElementById('id_validation').innerHTML="L'adresse email du champ "+libelle+" n'est pas valide "
		document.getElementById(champs).focus()
		return false
	}else{
		document.getElementById('id_validation').style.visibility='hidden'
		return true
	}
}


function comparerdates(date1,date2){
	// Compare 2 dates au format jj/mm/aaaa
	// Renvoye 0 si égalité, 1 si la première est supérieure, sinon 2
	var date1 = dato(date1,"-");// Ne pas oublier d'utiliser cette fonction
	// pour convertir en date anglaise, sinon le 05/07/2003 sera compris "7 mai 2003" par JavaScript
	var date2 = dato(date2,"-");

	date1 = Date.parse(date1);
	date2 = Date.parse(date2);

	//if (date1 == date2) { return true;}
	if (date1 > date2){
		document.getElementById('id_validation').style.visibility='visible'
		document.getElementById('id_validation').innerHTML="La date début doit être inférieure ou égal (<=) à la date fin"
		return false
	}else{
		document.getElementById('id_validation').style.visibility='hidden'
		return true
	}

}
function dato(date,sep){
	var elem = date.split(sep); 
	jour = elem[0]; 
	mois = elem[1]; 
	annee = elem[2]; 
	return annee+"/"+mois+"/"+jour
}

function dateact(date1,date2){
	// Compare 2 dates au format jj/mm/aaaa
	// Renvoye 0 si égalité, 1 si la première est supérieure, sinon 2
	var date1 = dato(date1,"-");// Ne pas oublier d'utiliser cette fonction
	// pour convertir en date anglaise, sinon le 05/07/2003 sera compris "7 mai 2003" par JavaScript
	var date2 = dato(date2,"-");

	date1 = Date.parse(date1);
	date2 = Date.parse(date2);

	//if (date1 == date2) { return true;}
	if (date1 > date2){
		document.getElementById('id_validation').style.visibility='visible'
		document.getElementById('id_validation').innerHTML="La date début doit être supérieure ou égal (<=) a la date d'ajourd'hui"
		return false
	}else{
		document.getElementById('id_validation').style.visibility='hidden'
		return true
	}

}

function DateSystem (){
		d= new Date();
		d.setDate(d.getDate());
		strDay = (d.getDate()<10?"0":"")+d.getDate();
		month = d.getMonth()+1;
		strMonth = (month<10?"0":"")+month;
		strDate = ""+strDay+"-"+strMonth+"-"+d.getFullYear();	
		return strDate;
}


function longchaine(champs,libelle,longeur){	
	if (document.getElementById(champs).value.length<=longeur){
		document.getElementById('id_validation').style.visibility='visible'
		document.getElementById('id_validation').innerHTML="Le champs "+libelle+" doit avoir au moins "+longeur+" caractères"
		document.getElementById(champs).focus()
		return false
	}else{
		document.getElementById('id_validation').style.visibility='hidden'
		return true
	}
}
