/* Fonctions JavaScript pour site 4xpepper
	Sources:	JavaScript - MicroApplication
				Site de Erik Bosrup (www.bosrup.com/web/overlib)
*/	
function appelIndex()
{
	var fenetre = window.open("", "introitus");
	fenetre.location = "/introitus.php";
	fenetre.focus();
}

var qcm = ["A", "B", "C", "D", "E"];
var clqTailleDft = 250;
var idLien = 0;

//Détection du navigateur
var ns4 = (document.layers)? true:false;
var ns6 = (document.getElementById)? true:false;
var ie4 = (document.all)? true:false;
if (ie4)
	{
	if ((navigator.userAgent.indexOf('MSIE 5') > 0) || (navigator.userAgent.indexOf('MSIE 6') > 0))
		{ie5 = true;}
	if (ns6) ns6 = false;
	}
else ie5 = false;	

	
// Affichage du calque avec son contenu à l'emplacement de la souris 
function affSolution(e, solution, contenu)
{
	//window.alert ("ie4=" + ie4 + "  ie5= " + ie5 + "   ns4 = " + ns4 + "   n6 = " + ns6);
	//Détermination de l'objet-calque utile (dont les propriétés seront utilisées) selon le navigateur
	if (ns4) clqSol = document.layers["solution"];
	if (ie4) clqSol = document.all["solution"].style;
	if (ns6) clqSol = window.document.getElementById("solution");
	
	//Fabrication du code HTML correspondant à la réponse
	clrFond = (solution == "vrai")? "#DDFFDD":"#FFF0F0";
	clrBord = (solution == "vrai")? "#00FF00":"#FF0000";
	html = "<TABLE WIDTH=100% BORDERCOLOR=\"" + clrBord + "\" BGCOLOR=\"" + clrFond + "\"";
	html += " BORDER=1 CELLPADING=5 CELLSPACING=1><TR><TD CLASS=\"qst\" VALIGN='MIDDLE'><P>" + contenu + "</P>";
	html += "<P ALIGN=\"RIGHT\"><A HREF=\"Javascript:void(0);\" onMouseDown=\"effSolution()\">fermer<A></P></TD></TR></TABLE>";

	//Détermination de la position où doit apparaître le calque solution
	if ((ns4) || (ns6))
		{xSouris = e.pageX; ySouris = e.pageY;}
	if (ie4)
		{xSouris = event.x; ySouris = event.y;}
	if (ie5)
	{
		xSouris = event.x + document.body.scrollLeft;
		ySouris = event.y + document.body.scrollTop;
	}
	winOffset = (ie4) ? document.body.scrollLeft : window.pageXOffset;
	scrollOffset = (ie4)? document.body.scrollTop : window.pageYOffset;

	posX = (xSouris + clqTailleDft > winOffset) ? xSouris : winOffset - clqTailleDft;
	posY = ySouris;

	//Repositionnement
	if ((ns4) || (ie4))
		{clqSol.left = posX; clqSol.top = posY;}
	else if (ns6)
		{clqSol.style.left = posX + "px"; clqSol.style.top = posY + "px";}
		
	//Mise à jour du contenu du calque
	if (ns4)
	{
		with (document.layers["solution"].document)
		{
			write(html);
			close();
		}		
	}
	else if (ie4)
		{document.all["solution"].innerHTML = html}
	else if (ns6)
	{
		range = document.createRange();
		range.setStartBefore(clqSol);
		domFrag = range.createContextualFragment(html);
		while (clqSol.hasChildNodes())
			{clqSol.removeChild(clqSol.lastChild)}
		clqSol.appendChild(domFrag);	
	}
	
	//Affichage du calque
	if (ns4) clqSol.visibility ="show";
	else if (ie4) clqSol.visibility = "visible";
	else if (ns6) clqSol.style.visibility = "visible";
}


// Cachage du calque
function effSolution()
{
	if (ns4) clqSol.visibility ="hide";
	else if (ie4) clqSol.visibility = "hidden";
	else if (ns6) clqSol.style.visibility = "hidden";
}

function poserQuestion(question, solution, reps, rems)
{
	html = "<TABLE WIDTH=100% BORDER=1 CELLSPACING=0 CELLPADING=2 BORDERCOLOR=\"#FF8000\" ><TR><TD>";
	html +="<TABLE WIDTH=100% BORDER=0 CELLSPACING=0 CELLPADING=0";
	html += "<TR><TD WIDTH=25 VALIGN=\"top\"><IMG SRC=\"/design/ico/question.gif\" WIDTH=21 HEIGHT=21></TD>\n";
	html += "<TD CLASS=\"qst\" >" + question + "</TD></TR>\n";
	html += "</TR><TR><TD></TD><TD CLASS=\"qst\" ALIGN=center>";
	document.write (html);
	i = 0;
	html = "";
	while (i < reps.length)
	{
		vrai = (i == solution)? "vrai":"faux";
		if (i != 0) html += " - ";
		html += qcm[i] + ". <A HREF=\"Javascript:void(0);\" onMouseDown=\"affSolution(event, '" + vrai + "', '" + rems[i] + "')\">";
		html += reps[i] + "<A>";
		i++;
	}
	html += "</TD></TR></TABLE></TD></TR></TABLE>"
	document.write (html);
}

function test(chaine)
{
	document.write(chaine);
	exprg = new RegExp("'");
	chaine = chaine.replace(exprg, "\\\'");
	document.write(chaine);
}		
		
