var win;
function fenetreListeVotes(lien) {
  if (win != null) {win.close();}
  win=window.open(lien,"Votes","height=450,width=350,left=250,top=150,resizable=no,scrollbars=yes");
}

var win;
    function fenetre_article(lien) {
      if (win != null) {win.close();}
      win=window.open(lien,"Article","height=700,width=900,left=50,top=50,resizable=no,scrollbars=yes");
    }

function aide_bbcodes(nom_bouton) {
  var texte_retour = '';

  if (nom_bouton == 'gras')
    texte_retour = texte_retour + 'Texte gras: [b]texte[/b]';
  else if (nom_bouton == 'italique')
    texte_retour = texte_retour + 'Texte italique: [i]texte[/i]';
  else if (nom_bouton == 'souligne')
    texte_retour = texte_retour + 'Texte souligné: [u]texte[/u]';
  else if (nom_bouton == 'lien')
    texte_retour = texte_retour + 'Insérer un lien: [url]http://url/[/url] ou [url=http://url/]Nom[/url]';
  else if (nom_bouton == 'email')
    texte_retour = texte_retour + 'Insérer un email: [email]adressemail[/email] ou [email=adressemail]Nom[/email]';
  else if (nom_bouton == 'image')
    texte_retour = texte_retour + 'Insérer une image: [img]http://image_url/[/img]';

  document.getElementById("texte_aide_bouton").innerHTML = texte_retour;
}

function storeCaret(selec,nom_form)
{
  var isMozilla = (navigator.userAgent.toLowerCase().indexOf('gecko')!=-1) ? true : false;
  var regexp = new RegExp("[\r]","gi");

  if (isMozilla)
  {
  // Si on est sur Mozilla

    oField = document.forms[nom_form].elements['texte'];

    objectValue = oField.value;

    deb = oField.selectionStart;
    fin = oField.selectionEnd;

    objectValueDeb = objectValue.substring( 0 , oField.selectionStart );
    objectValueFin = objectValue.substring( oField.selectionEnd , oField.textLength );
    objectSelected = objectValue.substring( oField.selectionStart ,oField.selectionEnd );

  //	alert("Debut:'"+objectValueDeb+"' ("+deb+")\nFin:'"+objectValueFin+"' ("+fin+")\n\nSelectionné:'"+objectSelected+"'("+(fin-deb)+")");

    oField.value = objectValueDeb + "[" + selec + "]" + objectSelected + "[/" + selec + "]" + objectValueFin;
    oField.selectionStart = strlen(objectValueDeb);
    oField.selectionEnd = strlen(objectValueDeb + "[" + selec + "]" + objectSelected + "[/" + selec + "]");
    oField.focus();
    oField.setSelectionRange(
            objectValueDeb.length + selec.length + 2,
            objectValueDeb.length + selec.length + 2);
  }
  else
  {
  // Si on est sur IE

    oField = document.forms[nom_form].elements['texte'];
    var str = document.selection.createRange().text;

    if (str.length>0)
    {
    // Si on a selectionné du texte
            var sel = document.selection.createRange();
            sel.text = "[" + selec + "]" + str + "[/" + selec + "]";
            sel.collapse();
            sel.select();
    }
    else
    {
            oField.focus(oField.caretPos);
    //	alert(oField.caretPos+"\n"+oField.value.length+"\n")
            oField.focus(oField.value.length);
            oField.caretPos = document.selection.createRange().duplicate();

            var bidon = "%~%";
            var orig = oField.value;
            oField.caretPos.text = bidon;
            var i = oField.value.search(bidon);
            oField.value = orig.substr(0,i) + "[" + selec + "][/" + selec + "]" + orig.substr(i, oField.value.length);
            var r = 0;
            for(n = 0; n < i; n++)
            {if(regexp.test(oField.value.substr(n,2)) == true){r++;}};
            pos = i + 2 + selec.length - r;
            //placer(document.forms[nom_form].elements['texte'], pos);
            var r = oField.createTextRange();
            r.moveStart('character', pos);
            r.collapse();
            r.select();

    }
  }
}