﻿// JavaScript Document
<!--
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3){
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}}
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_displayStatusMsg(msgStr) { //v1.0
  status=msgStr;
  document.MM_returnValue = true;
}

var lastid = 1;
function addUploadFileField(e) {
	if (!e) e=window.event;
	changed = getEventTarget(e);
	if (changed.id.substring(7) == lastid) {
		var oNewNode = document.createElement("input");
		oNewNode.setAttribute("type","file");
		oNewNode.setAttribute("name","fichier[]");
		oNewNode.setAttribute("size","25");
		oNewNode.onchange = addUploadFileField;
		lastid++;
		oNewNode.id = "filebox" + lastid;
		document.getElementById("articleUpload").appendChild(oNewNode);
	}
}

function getEventTarget(e) {
    if (e.srcElement) return e.srcElement;
    else return e.currentTarget;
}

function ShowAddBox(id) {
	if(id == 'coulpapier') {
		field = document.getElementById('couleurpapier');
		input = document.getElementById(id);
		if(field.options[field.selectedIndex].value == 'Blanc') {
			input.style.display = 'none';
		}
		else {
			input.style.display = 'block';
		}
	}
	
	if(id == 'bichromie') {
		//field = document.getElementById('biounb');
		field = document.getElementById('biounbBI');
		span = document.getElementById('bichromie');
		//if(field.options[field.selectedIndex].value == 'Bichromie') {
		if(field.selected == true) {
			span.style.display = 'block';
		}
		else {
			span.style.display = 'none';
		}
	}
        
    if(id == 'saisieNomClub') {
        field = document.getElementById('rubrique');
        span = document.getElementById('contenu');
        span2 = document.getElementById('4couv');
        boutons = document.getElementById('boutonsarticle');
        boutons2 = document.getElementById('boutons4couv');
        if(field.options[field.selectedIndex].value == '4eme de couv') {
            span.style.display = 'none';
            boutons.style.display = 'none';
            span2.style.display = 'block';
            boutons2.style.display = 'block';
            }
        else {
            span.style.display = 'block';
            boutons.style.display = 'block';
            span2.style.display = 'none';
            boutons2.style.display = 'none';                        
        }
    }

	if(id == 'saisieNomClub') {
		field = document.getElementById('rubrique');
		span = document.getElementById('saisieNomClub');
		if(field.options[field.selectedIndex].value == '4eme de couv' || field.options[field.selectedIndex].value == 'Clubs' || field.options[field.selectedIndex].value == 'Culture') {
			span.style.display = 'block';
		}
		else {
			span.style.display = 'none';
		}
	}
	
	if(id == 'printchoice') {
		p1 = document.getElementById('encre');
                p2 = document.getElementById('couleur?');
		d1 = document.getElementById('printparam');
		ch = document.getElementById('choix');
		tdrv = document.getElementById('rverso');
		upf = document.getElementById('articleUpload');
		if((ch.options[ch.selectedIndex].id == "Oaffiches") || (ch.options[ch.selectedIndex].id == "Oflyers") || (ch.options[ch.selectedIndex].id == "Oelisha") || (ch.options[ch.selectedIndex].id == "Ophotocopies") || (ch.options[ch.selectedIndex].id == "Opapier")) {
			d1.style.display = 'block'; 
			if((ch.options[ch.selectedIndex].id == "Oaffiches") || (ch.options[ch.selectedIndex].id == "Oflyers") || (ch.options[ch.selectedIndex].id == "Oelisha") || (ch.options[ch.selectedIndex].id == "Ophotocopies")) {
                                if(ch.options[ch.selectedIndex].id == "Oelisha") {
                                        p1.style.display = 'none';
                                        p2.style.display = 'block';
                                }
                                else {
        				p1.style.display = 'block';
                                        p2.style.display = 'none';
                                }
				tdrv.style.display = 'block';
				if((ch.options[ch.selectedIndex].id == "Oaffiches") || (ch.options[ch.selectedIndex].id == "Oflyers") || (ch.options[ch.selectedIndex].id == "Oelisha") || (ch.options[ch.selectedIndex].id == "Ophotocopies")) {
					upf.style.display = 'block';
				}
				else {
					upf.style.display = 'none';
				}
			}
			else {
				p1.style.display = 'none';
                                p2.style.display = 'none';
				tdrv.style.display = 'none';
                                upf.style.display = 'none';
			}
		}
		else {
			d1.style.display = 'none';
                        p2.style.display = 'none';
                        upf.style.display = 'none';

		}
	}
}

function verify(page) {
	if(page == 'ecrire') {
		rub = document.getElementById('rubrique');
		title = document.getElementById('titre');
		sign = document.getElementById('signature');
		rq = document.getElementById('remarques');
		ph = document.getElementById('phone');
		content = document.getElementById('contenu');
		ClubName = document.getElementById('nomclub');
		AssoceName = document.getElementById('nomassoce');
		couv = document.getElementById('filebox1');
		if(rub.options[rub.selectedIndex].value == 'Rubrique') {
			alert("Sélectionnez une rubrique");
			rub.focus();
			return false;
		}
		if((title.value == "Titre de l'article") && (rub.options[rub.selectedIndex].value != '4eme de couv')) {
			alert("Entrez le titre de l'article");
			title.focus();
			return false;
		}
		if((sign.value == "signature de l'article, plus ou moins courte") && (rub.options[rub.selectedIndex].value != '4eme de couv')) {
			alert("Signez votre article");
			sign.focus();
			return false;
		}
		if(rq.value == "Si vous avez des envies particuliaires de mise en page ...") {
			rq.value = "";
		}
		if(ph.value == "Pour joindre le Pi c'est 6388") {
			alert("Entrez votre numéro de téléphone");
			ph.focus();
			return false;
		}
		if((ClubName.value == "nom du club...") && (rub.options[rub.selectedIndex].value == '4eme de couv' || rub.options[rub.selectedIndex].value == 'Clubs' || rub.options[rub.selectedIndex].value == 'Culture')) {
			alert("Entrez le nom du club");
			ClubName.focus();
			return false;
		}
		if((rub.options[rub.selectedIndex].value != '4eme de couv' && rub.options[rub.selectedIndex].value != 'Clubs' && rub.options[rub.selectedIndex].value != 'Culture' )){
	                ClubName.value="";
		}
		if((content.value == "Contenu de votre article, sans le titre ni la signature !") && (rub.options[rub.selectedIndex].value != '4eme de couv') ) {
			alert("Vous n'avez pas saisi de contenu pour votre article");
			return false;
		}
		if ( (rub.options[rub.selectedIndex].value == '4eme de couv')  && (couv.value == "")) {
      alert("Vous n'avez pas indiqué d'image");
      return false;
    }
		return true;
	}
	if(page == 'printing') {
		choix = document.getElementById('choix');
		biounb = document.getElementById('biounb');
		coul1 = document.getElementById('couleur1');
		coul2 = document.getElementById('couleur2');
		couleurpapier = document.getElementById('couleurpapier');
		coulpapier = document.getElementById('coulpapier');
		nb = document.getElementById('nombre');
		comment = document.getElementById('commentaires');
		nom = document.getElementById('nom');
		phone = document.getElementById('phone');
		charte = document.getElementById('charte');
		
		if(choix.selectedIndex == 0) {
			alert('Vous devez choisir ce que vous souhaitez imprimer');
			choix.focus();
			return false;
		}
		
		if(choix.selectedIndex !=5) {
			/*if(biounb.selectedIndex == 1 && coul1.selectedIndex == coul2.selectedIndex) {
				alert('Vous devez choisir deux couleurs différentes');
				biounb.focus();
				return false;
			}*/
			if(choix.selectedIndex !=4) {
				if(couleurpapier.selectedIndex == 1 && coulpapier.value == 'Précisez la couleur') {
					alert('Vous devez préciser la couleur du papier que vous souhaitez');
					coulpapier.focus();
					return false;
				}
				if(nb.value == "Quantité de feuilles") {
					alert("Vous n'avez pas donné la quantité souhaitée");
					nb.focus();
					return false;
				}
			}
		}
		
		if(comment.value == "Indiquez ici la date que vous souhaiteriez et autres remarques expliquant vos souhaits") {
			alert("Vous n'avez pas précisé la date souhaitée");
			comment.focus();
			return false;
		}
		if(nom.value == "") {
			alert("Vous n'avez pas saisi votre nom");
			nom.focus();
			return false;
		}
		if(phone.value =="") {
			alert("Vous n'avez pas saisi votre numéro de téléphone");
			phone.focus();
			return false;
		}
		if(charte.checked == false) {
			alert("Vous devez accepter la charte pour continuer");
			charte.focus;
			return false;
		}
		return true;
	}
}

AideBalise = new Array(5);
AideBalise[0]="Aide pour les balises.";
AideBalise[1]="Pour mettre une partie du texte en gras, surlignez le puis cliquez sur ce bouton : il sera encadré par <b> et </b>";
AideBalise[2]="Pour mettre une partie du texte en italique, surlignez le puis cliquez sur ce bouton : il sera encadré par <i> et </i>";
AideBalise[3]="Pour faire un sous-titre, surlignez le texte puis cliquez sur ce bouton : il sera encadré par <h2> et </h2>";
AideBalise[4]="Pour faire apparaître un texte en bleu, surlignez le texte puis cliquez sur ce bouton : il sera encadré par <couleur> et </couleur>";

MessageAide=AideBalise[0];

function ChangeAide(indice)
  {
    MessageAide=AideBalise[indice];
    document.formulaire.Aide.value=MessageAide;
  }


function Insere(repdeb, repfin) {
  var input = document.forms['formulaire'].elements['contenu'];
  input.focus();
  /* pour l'Explorer Internet */
  if(typeof document.selection != 'undefined') {
    /* Insertion du code de formatage */
    var range = document.selection.createRange();
    var insText = range.text;
    range.text = repdeb + insText + repfin;
    /* Ajustement de la position du curseur */
    range = document.selection.createRange();
    if (insText.length == 0) {
      range.move('character', -repfin.length);
    } else {
      range.moveStart('character', repdeb.length + insText.length + repfin.length);
    }
    range.select();
  }
  /* pour navigateurs plus r�cents bas�s sur Gecko*/
  else if(typeof input.selectionStart != 'undefined')
  {
    /* Insertion du code de formatage */
    var start = input.selectionStart;
    var end = input.selectionEnd;
    var insText = input.value.substring(start, end);
    input.value = input.value.substr(0, start) + repdeb + insText + repfin + input.value.substr(end);
    /* Ajustement de la position du curseur */
    var pos;
    if (insText.length == 0) {
      pos = start + repdeb.length;
    } else {
      pos = start + repdeb.length + insText.length + repfin.length;
    }
    input.selectionStart = pos;
    input.selectionEnd = pos;
  }
  /* pour les autres navigateurs */
  else
  {
    /* requ�te de la position d'insertion */
    var pos;
    var re = new RegExp('^[0-9]{0,3}$');
    while(!re.test(pos)) {
      pos = prompt("Insertion à la position (0.." + input.value.length + "):", "0");
    }
    if(pos > input.value.length) {
      pos = input.value.length;
    }
    /* Insertion du code de formatage */
    var insText = prompt("Veuillez entrer le texte à formater:");
    input.value = input.value.substr(0, pos) + repdeb + insText + repfin + input.value.substr(pos);
  }
 }


function remplace(a,b,texte)
 {

    resultat=texte;
    n=resultat.length;
    k=a.length;
    x=resultat.indexOf(a,0);

    while (x != -1) {
        resultat=resultat.substring(0, x)+b+resultat.substring(x+k,n);
        n = n + b.length - a.length;
        x=resultat.indexOf(a, x+b.length);
                }

    return resultat;
 }


function HTMLise(texte)
  {
    resultat=remplace('\n','</p><p id="texte">',texte);
    resultat=remplace('<h2>','</p><h2>',resultat);
    resultat=remplace('\t','&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',resultat);
    resultat=remplace('</h2>','</h2><p id="texte">',resultat);
    resultat=remplace('<couleur>','<font color="#FF0000">',resultat);
    resultat=remplace('</couleur>','</font>',resultat);
    return resultat;
  }

function visualise()
{
document.formulaire.texte.value=HTMLise('<h1>'+document.formulaire.titre.value+'</h1>\n<p id="texte">'+document.formulaire.contenu.value+'\n</p><p id="signature">'+document.formulaire.signature.value+'</p>');
}

function visualisealpha()
{
document.formulaire.texte.value=HTMLise('<p id="texte">'+document.formulaire.contenu.value+'\n</p>');
}

function TransfereValeur(a,b)
{
b.value = a.value;
}

function SetValeurs(formulaire,f,o,r,m,t,a,b,l)
{
formulaire.rubrique.value = f;
formulaire.nomassoce.value = o;
formulaire.nomclub.value = r;
formulaire.titre.value = m;
formulaire.contenu.value = t;
formulaire.remarques.value = a;
formulaire.signature.value = b;
formulaire.phone.value = l;
}
//-->
