function basculer(fen, nb_fen) {
   for (i = 0; i < nb_fen; i++) {
	  id_cible = "fen" + i;      
	  cible = document.getElementById(id_cible);
	 // id_fl_cible = "fen-fl" + i;  
	 // fl_cible = document.getElementById(id_fl_cible);
	  if (i == fen) {
		 if (cible.style.display == "none"){
			cible.style.display="";
			//fl_cible.src="utilities/img/fl-fen.gif";
		 } else {
			cible.style.display="none";
			//fl_cible.src="utilities/img/fl-sq.gif";
		 }
	  } else if (cible.style.display == ""){
		 cible.style.display = "";
		// fl_cible.src="utilities/img/fl-sq.gif";
	  } else if (cible.style.display == ""){
		 cible.style.display = "";
		// fl_cible.src="utilities/img/fl-sq.gif";
	  } else if (cible.style.display == "none"){
		 cible.style.display = "none";
		// fl_cible.src="utilities/img/fl-sq.gif";
	  }
   }  
}
function basculer2(fen, nb_fen) {
   for (i = 0; i < nb_fen; i++) {
	  id_cible = "fen" + i;      
	  cible = document.getElementById(id_cible);
	  if (i == fen) {
		 if (cible.style.display == "none"){
			//cible.style.display="";
		 } else {
			cible.style.display="none";
		 }
	  } else if (cible.style.display == ""){
		 cible.style.display = "";
	  } else if (cible.style.display == "none"){
		 cible.style.display = "none";
	  }
   }  
}
function detectBoulet(){
var N=navigator.appName; var V=navigator.appVersion;
var version="?"; var nom=N; var os="?"; var langue="?";
	if (N=="Microsoft Internet Explorer") {
		langue=navigator.systemLanguage
		version=V.substring(V.indexOf("MSIE",0)+5,V.indexOf(";",V.indexOf("MSIE",0)));
		
		if (V.indexOf("Win",0)>0) {

			if ( V.indexOf(";",V.indexOf("Win",0)) > 0 ) {
				os=V.substring(V.indexOf("Win",0),V.indexOf(";",V.indexOf("Win",0)));
			} else {
				os=V.substring(V.indexOf("Win",0),V.indexOf(")",V.indexOf("Win",0)));
			}
		}
		if (V.indexOf("Mac",0)>0) {
			os="Macintosh";
			version=V.substring(V.indexOf("MSIE",0)+5,V.indexOf("?",V.indexOf("MSIE",0)));
		}
		if (version<5.5){javascript:alert('vous utiliser un navigateur internet explorer version '+version+', pour un affichage optimal merci de mettre à jour votre navigateur, ou alors utiliser FireFox...');};
	}
}
//
function PopupImage(img) {
	titre="ZoOm";
	w=open("",'image','width=200,height=200,toolbar=no,scrollbars=no,resizable=no');
	w.document.write("<\HTML><\HEAD><\TITLE>"+titre+"<\/TITLE><\/HEAD>");
	w.document.write("<\SCRIPT language=javascript>function checksize() { if (document.images[0].complete) { window.resizeTo(document.images[0].width+30,document.images[0].height+50); window.focus();} else { setTimeout('checksize()',250) } }</"+"SCRIPT>");
	w.document.write("<\BODY bgcolor='#000' background='images/fondpopup.gif' style='background-repeat: no-repeat' onload='checksize()' leftMargin=0 topMargin=0 marginwidth=0 marginheight=0>");
	w.document.write("<\TABLE width='100%' border='0' cellspacing='0' cellpadding='0' height='100%'><\TR />");
	w.document.write("<\TD valign='middle' align='center'><\IMG src='"+img+"' border=0 />");
	w.document.write("<\/TD><\/TR><\/TABLE>");
	w.document.write("<\/BODY><\/HTML>");
	w.document.close();
}
function PopupDebug(debug) {
	w=open("",'debug','width=1200,height=600,toolbar=no,scrollbars=yes,resizable=yes');
	w.document.write("<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'><html xmlns='http://www.w3.org/1999/xhtml' xml:lang='fr' lang='fr'>");
	w.document.write("<head><title>Console de Débugage</title>");
	w.document.write("<style><!--");
	w.document.write(".debug{margin:0px;padding:15px;border:solid 0px red;width:97%;}.debug .vert{color:#099c3e;}.debug .bleu{color:#2a57fb;}.debug .decale{float:left;width:100%;padding-left:25px;}.attention{color:#EF3E00;}");
	w.document.write(" body {margin:0;padding:0;font-size:11px;font-family:Verdana,Arial,Helvetica,sans-serif;}");
	w.document.write("--></style></head>");
	w.document.write("<body>");
	w.document.write(""+debug+"");
	w.document.write("</body></html>");
	w.document.close();
}
	
function PopupCentre(url,nom,largeur,hauteur,options){
	var haut=(screen.height-hauteur)/2;
	var Gauche=(screen.width-largeur)/2;
	calendrier = window.open(url,nom,"top="+haut+",left="+Gauche+",width="+largeur+",height="+hauteur+","+options);
}

function openprint(url,nom) {
	var haut=(screen.height-hauteur)/2;
	var Gauche=(screen.width-largeur)/2;
	print = window.open(url,nom,"top="+haut+",left="+Gauche+",width='595',height='841',toolbar='no',scrollbars='no',resizable='no'");
}

function isValidEmail(str) {
  var atSym = str.lastIndexOf("@");
  if (atSym < 1) { return false; } // no local-part
  if (atSym == str.length - 1) { return false; } // no domain
  if (atSym > 64) { return false; } // there may only be 64 octets in the local-part
  if (str.length - atSym > 255) { return false; } // there may only be 255 octets in the domain
  // Is the domain plausible?
  var lastDot = str.lastIndexOf(".");
  // Check if it is a dot-atom such as example.com
  if (lastDot > atSym + 1 && lastDot < str.length - 1) {return true; }
  //  Check if could be a domain-literal.
  if (str.charAt(atSym + 1) == '[' &&  str.charAt(str.length - 1) == ']') { return true;}
  return false;
}

function valide() {
	var message = "";
	var nom = document.getElementById("nom");
	if (nom.value == "") {
		message += "Vous devez saisir votre nom. \n";
		//nom.style.backgroundColor='#c4e1ff';
	}
	var mail = document.getElementById("mail");
	if (mail.value != "") {
		var str = mail.value;
		if (isValidEmail(str) == false){
			message += "Votre mail " + (isValidEmail(str) ? "" : "'" + str + "' ne semble pas valide. \n") + "";
			//mail.style.backgroundColor='#c4e1ff';
			}else{
				message += "";
				}
	}else{
		message += "Vous devez saisir votre mail \n";
		//mail.style.backgroundColor='#c4e1ff';
		}
		
	if (message != ""){
		alert ("Attention \n"+message);
		return false;
		}
}
function valideRecherche() {
	var message = "";
	var nom = document.getElementById("nomRecherche");
	if (nom.value == "" || nom.value == "Rechercher...") {
		message += "Vous devez saisir une recherche. \n";
		nom.style.backgroundColor='#FFE0AF';
	}
	if (message != ""){
		alert ("Attention \n"+message);
		return false;
	}
}
function valide_en() {
	var message = "";
	var nom = document.getElementById("nom");
	if (nom.value == "") {
		message += "You have to write your name. \n";
		nom.style.backgroundColor='#c4e1ff';
	}
	var mail = document.getElementById("mail");
	if (mail.value != "") {
		var str = mail.value;
		if (isValidEmail(str) == false){
			message += "Your email " + (isValidEmail(str) ? "" : "'" + str + "' is invalid. \n") + "";
			mail.style.backgroundColor='#c4e1ff';
			}else{
				message += "";
				}
	}else{
		message += "You have to write your email. \n";
		mail.style.backgroundColor='#c4e1ff';
	}
	if (message != ""){
		alert ("Warning \n"+message);
		return false;
	}
}

function valideCata() {
	var message = "";
	if (document.formulairecatalogue.nom.value == "") {
		message += "Vous devez saisir votre nom. \n";
		document.formulairecatalogue.nom.style.backgroundColor='#F9DDC5';
	}
	if (document.formulairecatalogue.mail.value != "") {
		var str = document.formulairecatalogue.mail.value;
		if (isValidEmail(str) == false){
			message += "Votre mail " + (isValidEmail(str) ? "" : "'" + str + "' ne semble pas valide. \n") + "";
			document.formulairecatalogue.mail.style.backgroundColor='#F9DDC5';
			}else{
				message += "";
				}
	}else{
		message += "Vous devez saisir votre mail \n";
		document.formulairecatalogue.mail.style.backgroundColor='#F9DDC5';
		}
		
	if (message != ""){
		alert ("Attention \n"+message);
		return false;
		}
}
function valideCommentaires() {
	var message = "";
	if (document.getElementById('ajoutComment').nomInternaute.value == "") {
		message += "Vous devez saisir votre nom. \n";
		document.getElementById('ajoutComment').nomInternaute.style.backgroundColor='#F9DDC5';
	}
	if (document.getElementById('ajoutComment').messageInternaute.value == "") {
		message += "Vous devez saisir un commentaires. \n";
		document.getElementById('ajoutComment').messageInternaute.style.backgroundColor='#F9DDC5';
	}
	if (document.getElementById('ajoutComment').mailInternaute.value != "") {
		var str = document.getElementById('ajoutComment').mailInternaute.value;
		if (isValidEmail(str) == false){
			message += "Votre mail " + (isValidEmail(str) ? "" : "'" + str + "' ne semble pas valide. \n") + "";
			document.getElementById('ajoutComment').mailInternaute.style.backgroundColor='#F9DDC5';
		}
	}else{
		message += "Vous devez saisir votre mail \n";
		document.getElementById('ajoutComment').mailInternaute.style.backgroundColor='#F9DDC5';
		}
		
	if (message != ""){
		alert ("Attention \n"+message);
		return false;
	}

}

function redirection(url, cat, id){
	if (cat == 0){
		//var newUrl = url.substr(0,url.length);
		location.href = url+".html"; 
	}else if (cat == "desc" || cat == "asc"){
		location.href = url+""+cat+".html";
	}else{
		location.href = url+""+cat+".html";}
}
function redirection2(url, cat, id){
	if (cat == 0){
		//var newUrl = url.substr(0,url.length-1);
		location.href = url+".html"; 
	}else if (cat == "desc" || cat == "asc"){
		location.href = url+"-"+cat+".html";
	}else{
		location.href = url+""+cat+".html";}
}
function redirectionArticle(url, id){
	location.href = url+"-"+id+".html";
}

function Check_all(container_id,state,img, img2){
	var checkboxes = document.getElementById(container_id).getElementsByTagName('input');
	for (var ia=0;ia<checkboxes.length;ia++){
		if(checkboxes[ia].type == 'checkbox'){
			checkboxes[ia].checked = state;
		}
	}
	var Obj = document.getElementById(img);
	var Obj2 = document.getElementById(img2);
	if (state == false){
		Obj.style.display = "none"; 
		Obj2.style.display ="block";
	}else{
		Obj2.style.display = "none"; 
		Obj.style.display ="block";
	}
	return true;
}

function rend_none(img2){
	fl_cible2 = document.getElementById(img2);
	if (fl_cible2.style.display == "block"){
		fl_cible2.style.display = "none";
	}
	return true;
}

function add_favoris()
{
   var title = document.title;
   var page = location.href;

   if ( navigator.appName != 'Microsoft Internet Explorer' ){
	  window.sidebar.addPanel(title,page,1); 
   } 
   else 
   {
	  window.external.AddFavorite(page,title);
   }
}

function request(url,cadre) {
	var XHR = null;

	if(window.XMLHttpRequest) // Firefox
	XHR = new XMLHttpRequest();
	else if(window.ActiveXObject) // Internet Explorer
	XHR = new ActiveXObject("Microsoft.XMLHTTP");
	else { // XMLHttpRequest non supporté par le navigateur
	alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
	return;
	}
	// envoie de la requête, methode GET et de l'url
	XHR.open("GET",url, true);

	// on guette les changements d'état de l'objet
	XHR.onreadystatechange = function attente() {
		// l'état est à 4, requête reçu !
		if(XHR.readyState == 4)     {
			// ecriture de la réponse
			document.getElementById(cadre).innerHTML = XHR.responseText;
	   }
	}
	XHR.send(null); // le travail est terminé
	return;
}

/**
 * renvoie true si le mail est bon
 */
function testEMail(adresse){
  var maReg = new RegExp ( "^[a-zA-Z0-9]+(?:[\\.]?[a-zA-Z0-9_-]+)*@(?:[a-zA-Z0-9][a-zA-Z0-9-]*\\.)*[a-zA-Z0-9][a-zA-Z0-9-]*\\.[a-zA-Z]{2,5}$", "gi" ) ;
  if (adresse.search( maReg ) == -1 ){
    return (false);
  } else {
    return (true);
  }
}
