/*************************************************
 * Auteur :         Rémi Chéno <remi@cheno.org>
 * Nom du fichier : commun/fenetre.js
 * Date création :  01/03/2003
 * Mise à jour :    19/06/2003
 * Contenu :        JavaScript
 *************************************************/
 
 /*
  * Ouverture d'une fenêtre - renvoie une handle sur la fenêtre
  */
 
function ouvrirFenetre(url, nom) {
	var nouvelleFenetre = window.open(url, nom, "resizable=yes, toolbar=no, menubar=no, scrollbars=yes, width=500, height=250");
	return nouvelleFenetre;
}

/*
 * Ouverture d'une fenêtre d'aide, avec le texte d'aide pour les tags HTLM de base
 */

function aide() {
	fenetre = ouvrirFenetre("", "fenetreAide");

// Entête XHTML

	fenetre.document.writeln("<?xml version=\"1.0\" encoding=\"iso-8859-1\" ?>");
	fenetre.document.writeln("<!DOCTYPE html ");
	fenetre.document.writeln("PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"");
	fenetre.document.writeln("\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\" >");
	fenetre.document.writeln("<html xmlns=\"http://www.w3.org/1999/xhtml\" >\n<head>");
	fenetre.document.writeln("<title>Aide-mémoire</title>");
	fenetre.document.writeln("<link type=\"text/css\" href=\"../commun/styles.css\" title=\"Mes styles\" rel=\"stylesheet\" />");
	fenetre.document.writeln("<meta content=\"text/html; charset=iso-8859-1\" />");
	fenetre.document.writeln("<body style=\"background : none;\">");

// Le texte de l'aide

	fenetre.document.writeln("<p class=\"erreur\">pour les <b>caractères gras</b>, écrire <b>&lt;b&gt;le texte&lt;/b&gt;</b><br />");
	fenetre.document.writeln("pour les <em>caractères italiques</em>, écrire <b>&lt;em&gt;</b><em>le texte</em><b>&lt;/em&gt;</b><br />");
	fenetre.document.writeln("pour aller à la ligne, utilisez <b>&lt;br /&gt;</b><br />");
	fenetre.document.writeln("pour une espace insécable, utilisez <b>&amp;nbsp;</b> (avec le «&nbsp;<b>;</b>&nbsp;»&nbsp;!)<br />");
	fenetre.document.writeln("évitez les guillemets anglais <b>\"</b> (ou <b>&amp;quote;</b>)<br />");
	fenetre.document.writeln("utilisez plutôt les guillemets français<br />");
	fenetre.document.writeln("<b>«</b> (ou <b>&amp;laquo;</b>) et <b>»</b> (ou <b>&amp;raquo;</b>)<br />");
	fenetre.document.writeln("enfin pour écrire le signe <b>&amp;</b> lui-même, il faut écrire <b>&amp;amp;</b>");
	fenetre.document.writeln("</p>");
	fenetre.document.writeln("<p><a href=\"#\" onclick=\"window.close();\">Fermer</a></p>");
	fenetre.document.writeln("</body>");
        fenetre.document.writeln("</html>");
}

/*
 * Ouverture d'une fenêtre pour afficher le texte mis en forme
 */

function visualiser(message) {
	fenetre = ouvrirFenetre("", "fenetreVisu");

// Entête XHTML

	fenetre.document.writeln("<?xml version=\"1.0\" encoding=\"iso-8859-1\" ?>");
	fenetre.document.writeln("<!DOCTYPE html ");
	fenetre.document.writeln("PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"");
	fenetre.document.writeln("\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\" >");
	fenetre.document.writeln("<html xmlns=\"http://www.w3.org/1999/xhtml\" >\n<head>");
	fenetre.document.writeln("<title>Visualisation</title>");
	fenetre.document.writeln("<link type=\"text/css\" href=\"../commun/styles.css\" title=\"Mes styles\" rel=\"stylesheet\" />");
	fenetre.document.writeln("<meta content=\"text/html; charset=iso-8859-1\" />");
	fenetre.document.writeln("<body style=\"background : none;\">");

// Le texte

	fenetre.document.writeln("<p class=\"noindent\"><em>Votre texte mis en forme&nbsp;:</em></p>");
	fenetre.document.writeln("<p class=\"noindent\">");
	fenetre.document.writeln(message);
	fenetre.document.writeln("</p>");
	fenetre.document.writeln("<p><a href=\"#\" onclick=\"window.close();\">Fermer</a></p>");
	fenetre.document.writeln("</body>");
        fenetre.document.writeln("</html>");
}

/*
 * Bascule de l'affichage/non-affichage de l'élément 'texte' sous l'élément 'titre' (+ ou -)
 */

function basculeAffichage(titre,texte) {
	if (eval("document.getElementById('"+texte+"').style.display!='block'")) {
		eval("document.getElementById('"+texte+"').style.display='block';");
                eval("document.getElementById('"+texte+"').style.visibility='visible';");
                eval("document.getElementById('"+titre+"').title='Cliquer pour refermer';");
                eval("document.getElementById('"+titre+"').style.border='2px inset';");
                eval("document.getElementById('"+titre+"').innerText='-';");
	} else {
		eval("document.getElementById('"+texte+"').style.display='none';");
                eval("document.getElementById('"+texte+"').style.visibility='hidden';");
                eval("document.getElementById('"+titre+"').title='Cliquer pour ouvrir';");
                eval("document.getElementById('"+titre+"').style.border='2px outset';");
                eval("document.getElementById('"+titre+"').innerText='+';");
	};
}

/*
 * Affichage de l'aide pour la PGRM
 */
 
function aidePGMR() {
	fenetre = ouvrirFenetre("", "fenetreAide");

// Entête XHTML

	fenetre.document.writeln("<?xml version=\"1.0\" encoding=\"iso-8859-1\" ?>");
	fenetre.document.writeln("<!DOCTYPE html ");
	fenetre.document.writeln("PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"");
	fenetre.document.writeln("\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\" >");
	fenetre.document.writeln("<html xmlns=\"http://www.w3.org/1999/xhtml\" >\n<head>");
	fenetre.document.writeln("<title>Aide-mémoire</title>");
	fenetre.document.writeln("<link type=\"text/css\" href=\"../commun/styles.css\" title=\"Mes styles\" rel=\"stylesheet\" />");
	fenetre.document.writeln("<meta content=\"text/html; charset=iso-8859-1\" />");
	fenetre.document.writeln("<body style=\"background : none;\">");

// Le texte de l'aide

	fenetre.document.writeln("<p class=\"erreur\">pour les <span style=\"font-variant: small-caps\">petites capitales</span>, écrire <b>{</b>le texte entre accolades<b>}</b><br />");
	fenetre.document.writeln("pour les <em>caractères italiques</em>, écrire <b>~</b>le texte entre tildes<b>~</b><br />");
	fenetre.document.writeln("mettez les <b>notes de bas de page</b>, sans leur numérotation,<br /><b>[[</b>entre crochets doubles<b>]]</b><br />");
	fenetre.document.writeln("pour écrire en latin <b>&aelig;</b>, écrivez <b>&amp;aelig;</b>&nbsp;; pour <b>&oelig;</b>, écrivez <b>&amp;oelig;</b><br />");
	fenetre.document.writeln("pour une espace insécable, utilisez <b>&amp;nbsp;</b> (avec le «&nbsp;<b>;</b>&nbsp;»&nbsp;!)<br />");
	fenetre.document.writeln("évitez les guillemets anglais <b>\"</b> (ou <b>&amp;quote;</b>)<br />");
	fenetre.document.writeln("utilisez plutôt les guillemets français<br />");
	fenetre.document.writeln("<b>«</b> (ou <b>&amp;laquo;</b>) et <b>»</b> (ou <b>&amp;raquo;</b>)<br />");
	fenetre.document.writeln("enfin pour écrire le signe <b>&amp;</b> lui-même, il faut écrire <b>&amp;amp;</b>");
	fenetre.document.writeln("</p>");
	fenetre.document.writeln("<p><a href=\"#\" onclick=\"window.close();\">Fermer</a></p>");
	fenetre.document.writeln("</body>");
        fenetre.document.writeln("</html>");

}

/*
 * Transfert du contenu de la version 2002 à l'identique vers la version 1975 pour la PGMR
 */
 
function transfert(langue) {
	eval("document.getElementById('"+langue+"75').innerText = document.getElementById('"+langue+"02').innerText;");
}
 
/*
 * Visualisation du rendu d'une saisie de la PGMR
 */
  
function extraireTexte(paragraphe) {
 
	var modele = /(.*)\[\[(.+)]](.*)/;
	var i = 0;
	var istring = new String("");
	var temp = paragraphe;
	
	while (modele.test(temp)) {
		i++;
		temp = temp.replace(modele, "$1 - $3");
	};
	
	while (modele.test(paragraphe)) {
		istring = i;
		paragraphe = paragraphe.replace(modele, "$1 (" + istring + ") $3");
		i--;
	};

	modele = /(.*)\{(.+)}(.*)/;
	while (modele.test(paragraphe)) {
		paragraphe = paragraphe.replace(modele, "$1<span style=\"font-variant : small-caps\">$2</span>$3");
	};

	modele = /(.*)~(.+)~(.*)/;
	while (modele.test(paragraphe)) {
		paragraphe = paragraphe.replace(modele, "$1<em>$2</em>$3");
	};

	return paragraphe; 
}

function extraireNote(paragraphe) {

	var modele = /(.*)\[\[(.+)]](.*)/;
	var i = 0;
	var temp = paragraphe;
	var istring = new String("");

	while (modele.test(temp)) {
		i++;
		temp = temp.replace(modele, "$1 - $3");
	};

	var reponse = "";
	
	while (modele.test(paragraphe)) {
		istring = i;
		if (reponse != "") {
			reponse = "<br />" + reponse;
		};
		reponse = "(" + istring + ")&nbsp;" + paragraphe.replace(modele, "$2") + reponse;
		paragraphe = paragraphe.replace(modele, "$1 - $3");
		i--;
	};
	
	return extraireTexte(reponse);
}
 
function visualiserPGMR(zone) {
	
	message = new String ("");
 	
  	eval("message = document.getElementById('"+zone+"').innerText;");
  	fenetre = ouvrirFenetre("", "fenetreVisu");

// Entête XHTML

	fenetre.document.writeln("<?xml version=\"1.0\" encoding=\"iso-8859-1\" ?>");
	fenetre.document.writeln("<!DOCTYPE html ");
	fenetre.document.writeln("PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"");
	fenetre.document.writeln("\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\" >");
	fenetre.document.writeln("<html xmlns=\"http://www.w3.org/1999/xhtml\" >\n<head>");
	fenetre.document.writeln("<title>Visualisation</title>");
	fenetre.document.writeln("<link type=\"text/css\" href=\"../commun/styles.css\" title=\"Mes styles\" rel=\"stylesheet\" />");
	fenetre.document.writeln("<meta content=\"text/html; charset=iso-8859-1\" />");
	fenetre.document.writeln("<body style=\"background : none;\">");

// Le texte

	fenetre.document.writeln("<p class=\"noindent\"><em>Votre texte mis en forme&nbsp;:</em></p>");
	fenetre.document.writeln("<p class=\"noindent\">");
	
	message = extraireTexte(message) + "</p><hr /><p class=\"noindent\">" + extraireNote(message);
	
	fenetre.document.writeln(message);
	fenetre.document.writeln("</p>");
	fenetre.document.writeln("<p><a href=\"#\" onclick=\"window.close();\">Fermer</a></p>");
	fenetre.document.writeln("</body>");
        fenetre.document.writeln("</html>");
	
  }