// JavaScript Document

//permet d'ouvrir les liens marqués par rel="externe" dans une nouvelle fenêtre, les liens avec le double attribut rel="externe courriel" doivent être saisis avec un href="nom++domaine" évitant les spambots.

function lienExterne(evt) {
	var ceLien = Event.findElement(evt, 'a');
	var destination = ceLien.readAttribute('href');
	var idLien = ceLien.identify();
	Event.stop(evt);
	var testCourriel = /\+{2}/g;
	if (destination.match(testCourriel)) {
		destination = destination.replace(/(\w+)\+{2}(\w+)/, "mailto:$1@$2");
	}
	var nomFenetre = 'fenetre' + nFenetre;
	nFenetre++;
	var optionsFenetre = "width=600, height=400, resizeable=yes, toolbar=yes, scrollbars=yes";
	var nouvelleFenetre = window.open(destination, nomFenetre, optionsFenetre);
}

function activerLiens(evt) {
	$$('a[rel="externe"]').each( function(a) {
		var idLien = 'a' + nLien;
		nLien++;
		a.id = idLien;
		Event.observe($(idLien), 'click', lienExterne);
	});
	$$('a[rel="courriel"]').each( function(a) {
		var destination = a.readAttribute('href');
		var testCourriel = /\+{2}/g;
		if (destination.match(testCourriel)) {
			a.href = destination.replace(/(\w+)\+{2}(\w+)/, "mailto:$1@$2");
		}
	});
}

var nLien = 0;
var nFenetre = 0;
Event.observe(window, 'load', activerLiens);
