/*	Copyright (C) 2007  Thomas Guillem <thomas.guillem@gmail.com>
 * 
 *  Copyright 2004-2006
 * - Maxime Pettazoni
 * - Pierre Mauduit
 * - Laurent Colnat
 * - Julien Etelain < julien at pmad dot net >
 * 
 *	This file is part of my web site. 
 *
 *	My web site is free software: you can redistribute it and/or modify
 *	it under the terms of the GNU General Public License as published by
 *	the Free Software Foundation, either version 3 of the License, or
 *	(at your option) any later version.
 *
 *	My web site is distributed in the hope that it will be useful,
 *	but WITHOUT ANY WARRANTY; without even the implied warranty of
 *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *	GNU General Public License for more details.
 *
 *	You should have received a copy of the GNU General Public License
 *	along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/*Fonction qui fait switcher entre display:none et display une balise html ayant l'id ID*/
function toggle (id) {
	var style = document.getElementById(id).style;
	style.display = (style.display == "none") ? "" : "none";

	}
/*Fonction qui affiche dans un div vide un formulaire de confirmation de suppression de fichier*/
function conf_sup_file(dir,file){
	var chaine="<p><strong>Supprimer "+file+" ?</strong></p>";
	chaine+="<form method='post' action='/files/?p=files&dir="+dir+"'>";
	chaine+="<input type='hidden' name='sup' value='"+file+"'/>";
	chaine+="<input type='submit' name='oui' value='Oui'/>";
	chaine+="<input type='submit' value='Non'/></form><br />";
	document.getElementById('javascript_zone').innerHTML =chaine;
}
/*Fonction qui affiche dans un div vide le code bbcode d'un fichier*/
function display_bbcode(dir,file){
	if (file==0) {
		document.getElementById('javascript_zone').innerHTML ="";
	} else {
		var chaine="<a href='javascript:display_bbcode(0,0)'><img src='/theme/boutons/retour.png' alt='retour' /></a>";
		chaine+="<div class='quote'>[[/upload/"+dir+file+"|Nom du lien]]</div>";
		document.getElementById('javascript_zone').innerHTML =chaine;
	}
}
function insert_smiley(txtarea,smiley)
{
	txtarea.value=txtarea.value+" "+smiley+" ";
}
/*Fonction javascript qui vient de http://ae.utbm.fr/js/site.js */
/*Insertion de bbcode*/
function insert_bbcode(txtarea, lft, rgt, sample_text) 
{
  sample_text = typeof(sample_text) != 'undefined' ? sample_text : 'votre texte'; /* pas de passage d'arguments par dÃƒÂ©faut en JS alors on fait autrement */

  if (lft == '[[' && rgt == ']]') /* balises d'URL */
    {
      var _url = prompt("Entrez l'URL:","http://");

      if (_url != "" && _url != "http://") {
	lft='[[' + _url + '|';
	rgt=']]';
	insert_bbcode(txtarea, lft, rgt);
      }
      else
	insert_bbcode(txtarea, lft, " "+rgt); /* vieux truandage pour passer outre le test */

      return;
    }
  else if (lft == '<size=|' && rgt == '>') /* balises d'URL */
    {
      var _size = prompt("Taille du texte (en px):","12");

	lft='<size=' + _size + 'px|';
	rgt='>';
	insert_bbcode(txtarea, lft, rgt);
      return;
    }
  else if (lft == '<color=|' && rgt == '>') /* balises d'URL */
    {
      var _color = prompt("Couleur du texte :","red");

	lft='<color=' + _color + '|';
	rgt='>';
	insert_bbcode(txtarea, lft, rgt);
      return;
    }
  else if (document.all) /* IE */
    {
		txtarea.value=txtarea.value +" "+ lft + sample_text + rgt + " ";
    }
  else if (document.getElementById) /* Firefox... */
    {		
      var _length = txtarea.textLength;
      var _start = txtarea.selectionStart;
      var _end = txtarea.selectionEnd;
      if (_end==1 || _end==2) 
	_end = _length;
      var s1 = (txtarea.value).substring(0,_start);
      var s2 = (txtarea.value).substring(_start, _end)
      var s3 = (txtarea.value).substring(_end, _length);
     
      if(s2 == "")
        s2 = sample_text;   

      txtarea.value = s1 + lft + s2 + rgt + s3;

    }
}
