function sous_menu(champ)
{
  switch(champ)
   {
	  case "Patro":
			document.getElementById('ss_menu').innerHTML = '<a href="index.php?page=infos">Information</a> | <a href="index.php?page=camp">Le camp</a> | <a href="index.php?page=staff">Les animateurs</a> | <a href="index.php?page=section">Les sections</a> | <a href="index.php?page=histoire">Histoire</a>';
			break;
	  case "Multimedia":
	        document.getElementById('ss_menu').innerHTML = '<a href="index.php?page=photo">Photos</a> | <a href="index.php?page=video">Vidéos</a>';
	        break;
	  case "Communaute":
		    document.getElementById('ss_menu').innerHTML = '<a href="index.php?page=membrePatro">Les membres</a> | <a href="index.php?page=membreEnLigne">Visiteurs connectés</a>';
			break;
	  default: document.getElementById('ss_menu').innerHTML = "";
   }
  
}

function savoirPlusPatro()
{
  document.getElementById('enSavoirPlusPatro').innerHTML ="<p>Le Patro, ce sont près de 20 000 enfants et jeunes qui se retrouvent chaque semaine pour animer ou participer à des activités multiples. Le Patro, ce sont des animatrices et animateurs bénévoles qui s’engagent, prennent des responsabilités et participent à une société plus solidaire. Ils consacrent de nombreuses heures à cette passion et se forment pour offrir une animation de qualité.Le Patro, c’est un lieu d’épanouissement où l’on peut découvrir, grandir et devenir un CRACS: une citoyenne ou un citoyen responsable, actif, critique et solidaire.</p>"

}
function savoirMoinsPatro()
{
   document.getElementById('enSavoirPlusPatro').innerHTML ="";
 }
 
 function surligne(champ, erreur)
{
   if(erreur)
      champ.style.backgroundColor = "rgb(254,82,112)";
   else
      champ.style.backgroundColor = "";
}
 
 function verifPseudo(champ)
 {
   if(champ.value.length<5 || champ.value.length>12)
   {
       surligne(champ, true);
	   return false;
   }
   else
   {
     surligne(champ, false);
	 return true;
   }
 }
 
 function verifMDP(champ)
{
	if(champ.value.length<8 || champ.value.length>12) 
	{
		surligne(champ, true);
		 //document.getElementById('erreur_mot_de_passe').innerHTML = "Le mot de passe doit contenir entre 8 et 12 caractères";
		return false;
	}
	else
	{
	    surligne(champ, false);
		return true;
	}
}
 function verificationConnexion(f)
 {
	var pseudoOk=verifPseudo(f.pseudo);
	var mdpOk= verifMDP(f.motDePasse);
	
	if(pseudoOK==true && mdpOk==true)
	   return true;
	else
	   {
	    alert("Erreur");
	   return false;
	   }
	
 }
 
 function insertTag(startTag, endTag, textareaId, tagType) {
        var field = document.getElementById(textareaId); 
        field.focus();
        
        /* === Partie 1 : on récupère la sélection === */
        if (window.ActiveXObject) {
                var textRange = document.selection.createRange();            
                var currentSelection = textRange.text;
        } else {
                var startSelection   = field.value.substring(0, field.selectionStart);
                var currentSelection = field.value.substring(field.selectionStart, field.selectionEnd);
                var endSelection     = field.value.substring(field.selectionEnd);               
        }
        
        /* === Partie 2 : on analyse le tagType === */
        if (tagType) {
                switch (tagType) {
                        case "lien":
							endTag = "</lien>";
							if (currentSelection) 
							{ // Il y a une sélection
								if (currentSelection.indexOf("http://") == 0 || currentSelection.indexOf("https://") == 0 || currentSelection.indexOf("ftp://") == 0 || currentSelection.indexOf("www.") == 0) 
								{
								// La sélection semble être un lien. On demande alors le libellé
								var label = prompt("Quel est le libellé du lien ?") || "";
								startTag = "<lien url=\"" + currentSelection + "\">";
								currentSelection = label;
								} else 
								{
									// La sélection n'est pas un lien, donc c'est le libelle. On demande alors l'URL
									var URL = prompt("Quelle est l'url ?");
									startTag = "<lien url=\"" + URL + "\">";
								}
							} else 
							{ // Pas de sélection, donc on demande l'URL et le libelle
								var URL = prompt("Quelle est l'url ?") || "";
								var label = prompt("Quel est le libellé du lien ?") || "";
								startTag = "<lien url=\"" + URL + "\">";
								currentSelection = label;                     
        }
break;

                        case "citation":
                                // Si c'est une citation
                        break;
                }
        }
        
        /* === Partie 3 : on insère le tout === */
        if (window.ActiveXObject) {
                textRange.text = startTag + currentSelection + endTag;
                textRange.moveStart("character", -endTag.length - currentSelection.length);
                textRange.moveEnd("character", -endTag.length);
                textRange.select();     
        } else {
                field.value = startSelection + startTag + currentSelection + endTag + endSelection;
                field.focus();
                field.setSelectionRange(startSelection.length + startTag.length, startSelection.length + startTag.length + currentSelection.length);
        }       
}

function preview(textareaId, previewDiv) {
	var field = textareaId.value;
	if (document.getElementById('previsualisation').checked && field) {
		
		var smiliesName = new Array(':magicien:', ':colere:', ':diable:', ':ange:', ':ninja:', '&gt;_&lt;', ':pirate:', ':zorro:', ':honte:', ':soleil:', ':\'\\(', ':waw:', ':\\)', ':D', ';\\)', ':p', ':lol:', ':euh:', ':\\(', ':o', ':colere2:', 'o_O', '\\^\\^', ':\\-°');
		var smiliesUrl  = new Array('magicien.png', 'angry.gif', 'diable.png', 'ange.png', 'ninja.png', 'pinch.png', 'pirate.png', 'zorro.png', 'rouge.png', 'soleil.png', 'pleure.png', 'waw.png', 'smile.png', 'heureux.png', 'clin.png', 'langue.png', 'rire.gif', 'unsure.gif', 'triste.png', 'huh.png', 'mechant.png', 'blink.gif', 'hihi.png', 'siffle.png');
		var smiliesPath = "http://www.siteduzero.com/Templates/images/smilies/";
	
		field = field.replace(/&/g, '&amp;');
		field = field.replace(/</g, '&lt;').replace(/>/g, '&gt;');
		field = field.replace(/\n/g, '<br />').replace(/\t/g, '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;');
		
		field = field.replace(/&lt;gras&gt;([\s\S]*?)&lt;\/gras&gt;/g, '<strong>$1</strong>');
		field = field.replace(/&lt;italique&gt;([\s\S]*?)&lt;\/italique&gt;/g, '<em>$1</em>');
		field = field.replace(/&lt;lien&gt;([\s\S]*?)&lt;\/lien&gt;/g, '<a href="$1">$1</a>');
		field = field.replace(/&lt;lien url="([\s\S]*?)"&gt;([\s\S]*?)&lt;\/lien&gt;/g, '<a href="$1" title="$2">$2</a>');
		field = field.replace(/&lt;image&gt;([\s\S]*?)&lt;\/image&gt;/g, '<img src="$1" alt="Image" />');
		field = field.replace(/&lt;citation nom=\"(.*?)\"&gt;([\s\S]*?)&lt;\/citation&gt;/g, '<br /><span class="citation">Citation : $1</span><div class="citation2">$2</div>');
		field = field.replace(/&lt;citation lien=\"(.*?)\"&gt;([\s\S]*?)&lt;\/citation&gt;/g, '<br /><span class="citation"><a href="$1">Citation</a></span><div class="citation2">$2</div>');
		field = field.replace(/&lt;citation nom=\"(.*?)\" lien=\"(.*?)\"&gt;([\s\S]*?)&lt;\/citation&gt;/g, '<br /><span class="citation"><a href="$2">Citation : $1</a></span><div class="citation2">$3</div>');
		field = field.replace(/&lt;citation lien=\"(.*?)\" nom=\"(.*?)\"&gt;([\s\S]*?)&lt;\/citation&gt;/g, '<br /><span class="citation"><a href="$1">Citation : $2</a></span><div class="citation2">$3</div>');
		field = field.replace(/&lt;citation&gt;([\s\S]*?)&lt;\/citation&gt;/g, '<br /><span class="citation">Citation</span><div class="citation2">$1</div>');
		field = field.replace(/&lt;taille valeur=\"(.*?)\"&gt;([\s\S]*?)&lt;\/taille&gt;/g, '<span class="$1">$2</span>');
		field = field.replace(/&lt;titre valeur=\"(.*?)\"&gt;([\s\S]*?)&lt;\/titre&gt;/g, '<h$1>$2</h$1>');
		
		for (var i=0, c=smiliesName.length; i<c; i++) {
			field = field.replace(new RegExp(" " + smiliesName[i] + " ", "g"), "&nbsp;<img src=\"" + smiliesPath + smiliesUrl[i] + "\" alt=\"" + smiliesUrl[i] + "\" />&nbsp;");
		}
		
		document.getElementById(previewDiv).innerHTML = field;
	}
}