
		
/* Affichage du plus d'infos */
function plusInfos(article) {
	if (document.getElementById(article).style.display=="block") {
		document.getElementById(article).style.display="none";
	}else{
		document.getElementById(article).style.display="block";
	}
	win=article;
	return;
}

/* Recherche des mots passés en paramètre */
function getParams() {
	var idx = document.URL.indexOf('?');
	var params = new Array();
	if (idx != -1) {
		var pairs = document.URL.substring(idx+1, document.URL.length).split('&');
		for (var i=0; i<pairs.length; i++) {
			nameVal = pairs[i].split('=');
			params[nameVal[0]] = nameVal[1];
		}
	}
	return params;
}

params = getParams();

/* Eclatement des mots passés  en paramètre */
function splitwords(words) {
	//words = words.replace('e', '[eéèêë]');
	//words = words.replace('a', '[aàâ]');
	//words = words.replace('i', '[iïî]');
	//words = words.replace('u', '[uù]');
	//words = words.replace('c', '[cç]');
		
	arrayOfTerms = new Array(0);
		
	reQuoted = /"([^"]+)"/g; // version simple interdisant les apostrophes échappées
	arrayOfQuoted = words.match(reQuoted)
	if (arrayOfQuoted) {
		for (i=0; i< arrayOfQuoted.length; ++i) {
			arrayOfTerms.push(arrayOfQuoted[i].substr(1,arrayOfQuoted[i].length-2));
			// On transforme les termes contenant des ? ou des *
			arrayOfTerms[i] = arrayOfTerms[i].replace(/\?/g, "\\w?");
			arrayOfTerms[i] = arrayOfTerms[i].replace(/\*/g, "\\w*");
		}
		words = words.replace(reQuoted, "");
	}
	reSpace = /[^\s]+/g; // Séparation des mots par des espaces
	arrayOfWords = words.match(reSpace);
	if (arrayOfWords) {
		reJoker = /[?*]/;
		reNotJoker = /[^?*]/;
		// On transforme les termes contenant des ? ou des *
		for (i=0; i< arrayOfWords.length; ++i) {
			term = arrayOfWords[i];
			if (term.match(reJoker)) {
				if (term.match(reNotJoker)) {
					term = term.replace(/\?/g, "\\w?");
					term = term.replace(/\*/g, "\\w*");
				}
				else {
					// Le terme ne contient que des joker, on le supprime
					break;
				}
			}
			else {
				term += "\\w?";
			}
			term = "\\b" + term + "\\b";
			arrayOfTerms.push(term);
		}
	}
	return arrayOfTerms;
}

/* Recherche et mise en surbrillance des mots */
function wordhighlight(aSourceObject, aWords){
	//alert(params['jump']);
	aWords = decodeURI(aWords)
	HTML = document.getElementById(aSourceObject).innerHTML;
	if (HTML.length > 64*1024) {
		return;
	}
	//Extract HTML Tags
	regexp=/<[^<>]*>/ig;
	vHTMLArray = HTML.match(regexp);
	//Replace HTML tags
	vStrippedHTML = HTML.replace(regexp,"$!$");
	// Prepare Array of highlightings
	highlight = new Array;
	for (i = 1; i <= 6; ++i) {
		highlight.push('highlight' + i);
	}
	//Replace search words
	arrayOfTerms = splitwords(aWords);
	for (i=0; i < arrayOfTerms.length; ++i) {
		nbLight = (i % highlight.length);
		regexp= new RegExp ("(" + arrayOfTerms[i] + ")", "gi");
		vStrippedHTML = vStrippedHTML.replace(regexp,'%!' + nbLight + '%$1%!%');
	}
	for (light = 0; light < highlight.length; ++light ) {
		searchedStr = "%!" + light + "%";
		for(i=0;vStrippedHTML.indexOf(searchedStr) > -1;i++){
			//vStrippedHTML = vStrippedHTML.replace(searchedStr,'<span style="background-color:yellow;" class="' + highlight[light % highlight.length] + '">');
			vStrippedHTML = vStrippedHTML.replace(searchedStr,'<span class="surbrillance">');
		}
	}
	for(i=0;vStrippedHTML.indexOf("%!%") > -1;i++){
		vStrippedHTML = vStrippedHTML.replace("%!%",'</span>');
	}
	//Reinsert HTML
	for(i=0;vStrippedHTML.indexOf("$!$") > -1;i++){
		vStrippedHTML = vStrippedHTML.replace("$!$", vHTMLArray[i]);
	}
	//Display Result
	document.getElementById(aSourceObject).innerHTML = vStrippedHTML;
}

/* Au démarrage de la page sur body onload */
function startHighlight() {
	if(document.getElementById(params['objet'])) {
		if (!params['do']) {
			wordhighlight(params['objet'], params['texte']);
			}
	}
	location.href= '#' + params['jump'];
}

/* Plier et déplier la zone de recherche */
var action ='deplier';
function plier_deplier() {
	var dbRes = [[]];
	var dbEl = document.body.getElementsByTagName('div');
	for (e = 0; e < dbEl.length; e++) {
		if (dbEl[[e]].className == 'plusInfos') {
			if (action == 'deplier') {
				dbEl[[e]].style.display="block";
			}
			if (action == 'plier') {
				dbEl[[e]].style.display="none";
			}
		}
	}
	if (action == 'deplier') {
		action = 'plier';
	}else{
		action = 'deplier';
	}
}

/* Ouvre une image dans une nouvelle fenêtre */
function ouvre_image(image){
	var theWindow = "";
	if (image == '') return;
	image = image.toLowerCase();
	theWindow=open("","Image", "menubar=0, location=no, status=no, scrollbars=yes, resizable=yes, width=1053, height=800");
	theWindow.document.write("<html><head><title>Archives du Morbihan</title></head><body bgcolor='#000000' color='#FFFFFF'>");
	theWindow.document.write('<div align="center"><a style="color:#FFFFFF;" href="javascript: self.close()">- Fermer -</a></div>');
	if (image.indexOf(".pdf") != -1){
		theWindow.document.write("<object  type='application/pdf' data='" + image + "' style='margin-top: 20px;border: 2px solid #8b0000; width:1024; height:768;'>");
		theWindow.document.write("<param  name='src' value='" + image + "' /></object>");
	}else{
		theWindow.document.write("<div style='text-align: center;margin-top:auto; margin-bottom:auto:'><img src='" + image + "'></div>");
	}
	theWindow.document.write('<div align="center"><a style="color:#FFFFFF;" href="javascript: self.close()">- Fermer -</a></div>');
	theWindow.document.write("</body>\n</html>");
	theWindow.focus();
	return;
}

/* Plier et déplier le plan de classement */
old = '';
function deplierPlan(lien){
	//alert(old);
	if (document.getElementById(lien).style.display=="none" && old != lien){
		document.getElementById(lien).style.display="block";
		old=lien;
		return;
	}
	if (document.getElementById(lien).style.display=="block"){
		document.getElementById(lien).style.display="none";
		old='';
		return;
	}
}

/* Fonction d'affichage du média */
var mediaSelect = '';
function getMedia(type, id, path, viewer){
var rendu = '';
if (document.getElementById(mediaSelect)) {
	document.getElementById(mediaSelect).innerHTML = '<img border="0" src="../tools/HP.png"/>';
}
switch (type)
{
case 'mp3' :
	rendu = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="200" height="20" id="dewplayer" align="middle">';
	rendu = rendu + '<param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="' + viewer + '?mp3=' + path ;
	rendu = rendu + '&autostart=1&showtime=1&bgcolor=FFFFFF" /><param name="quality" value="high" />';
	rendu = rendu + '<param name="bgcolor" value="FFFFFF" /><embed src="' + viewer + '?mp3=' + path;
	rendu = rendu + '&autostart=1&showtime=1&bgcolor=FFFFFF" quality="high" bgcolor="FFFFFF" width="200" height="20" name="dewplayer"  align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed></object>';
	break;
}
document.getElementById(id).innerHTML = rendu;
mediaSelect = id;
}				
					
	