/*
 *  Emoticonos.js   v0.1
 *
 *  Permite usar emoticonos en los comentarios del CMS Bitacorae.
 *
 *  Sistema: Bitacoras.com  -  http://www.bitacoras.com/
 *  Por    : Smartbrain     -  http://incontinenciamental.bitacoras.com/
 */

function convierte() {
  /* Obtenemos el contenido del textarea */
  var texto = document.form_comentar.texto.value;

  /*
   *  Con esto evitas que te cuelen imágenes en los comentarios,
   *  solo aparecerán las de los emoticonos. En determinadas situaciones
   *  el "replace" se comerá parte del texto, así que mejor no
   *  intentar añadir imágenes.
   */
  texto = texto.replace(/<\s*img.*>/ig,'');

  /* Convierte los emoticones */
  texto = texto.replace(/::1::/g,'<img src="/emoticonos/1.png" />');
  texto = texto.replace(/::2::/g,'<img src="/emoticonos/2.png" />');
  texto = texto.replace(/::3::/g,'<img src="/emoticonos/3.png" />');
  texto = texto.replace(/::4::/g,'<img src="/emoticonos/4.png" />');
  texto = texto.replace(/::5::/g,'<img src="/emoticonos/5.png" />');
  texto = texto.replace(/::6::/g,'<img src="/emoticonos/6.png" />');
  texto = texto.replace(/::7::/g,'<img src="/emoticonos/7.png" />');
  texto = texto.replace(/::8::/g,'<img src="/emoticonos/8.png" />');
  texto = texto.replace(/::9::/g,'<img src="/emoticonos/9.png" />');
  texto = texto.replace(/::10::/g,'<img src="/emoticonos/10.png" />');
  texto = texto.replace(/::11::/g,'<img src="/emoticonos/11.png" />');
  texto = texto.replace(/::12::/g,'<img src="/emoticonos/12.png" />');
  texto = texto.replace(/::13::/g,'<img src="/emoticonos/13.png" />');
  texto = texto.replace(/::14::/g,'<img src="/emoticonos/14.png" />');
  texto = texto.replace(/::15::/g,'<img src="/emoticonos/15.png" />');
  texto = texto.replace(/::16::/g,'<img src="/emoticonos/16.png" />');
  texto = texto.replace(/::17::/g,'<img src="/emoticonos/17.png" />');
  texto = texto.replace(/::18::/g,'<img src="/emoticonos/18.png" />');
  texto = texto.replace(/::19::/g,'<img src="/emoticonos/19.png" />');
  texto = texto.replace(/::20::/g,'<img src="/emoticonos/20.png" />');
  texto = texto.replace(/::21::/g,'<img src="/emoticonos/21.png" />');
  texto = texto.replace(/::22::/g,'<img src="/emoticonos/22.png" />');
  texto = texto.replace(/::23::/g,'<img src="/emoticonos/23.png" />');
  texto = texto.replace(/::24::/g,'<img src="/emoticonos/24.png" />');
  texto = texto.replace(/::25::/g,'<img src="/emoticonos/25.png" />');
  texto = texto.replace(/::26::/g,'<img src="/emoticonos/26.png" />');
  texto = texto.replace(/::27::/g,'<img src="/emoticonos/27.png" />');
  texto = texto.replace(/::28::/g,'<img src="/emoticonos/28.png" />');
  texto = texto.replace(/::29::/g,'<img src="/emoticonos/29.png" />');
  texto = texto.replace(/::30::/g,'<img src="/emoticonos/30.png" />');
  texto = texto.replace(/::31::/g,'<img src="/emoticonos/31.png" />');
  texto = texto.replace(/::32::/g,'<img src="/emoticonos/32.gif" />');
  texto = texto.replace(/::33::/g,'<img src="/emoticonos/33.png" />');
  texto = texto.replace(/::34::/g,'<img src="/emoticonos/34.png" />');
  texto = texto.replace(/::35::/g,'<img src="/emoticonos/35.png" />');
  texto = texto.replace(/::36::/g,'<img src="/emoticonos/36.png" />');
  texto = texto.replace(/::37::/g,'<img src="/emoticonos/37.gif" />');
  texto = texto.replace(/::38::/g,'<img src="/emoticonos/38.gif" />');
  texto = texto.replace(/::39::/g,'<img src="/emoticonos/39.gif" />');
  texto = texto.replace(/::40::/g,'<img src="/emoticonos/40.gif" />');
  texto = texto.replace(/::41::/g,'<img src="/emoticonos/41.bmp" />');
  texto = texto.replace(/::42::/g,'<img src="/emoticonos/42.gif" />');
  texto = texto.replace(/::43::/g,'<img src="/emoticonos/43.gif" />');
  texto = texto.replace(/::44::/g,'<img src="/emoticonos/44.gif" />');
  texto = texto.replace(/::45::/g,'<img src="/emoticonos/45.png" />');
  texto = texto.replace(/::46::/g,'<img src="/emoticonos/46.gif" />');
  texto = texto.replace(/::47::/g,'<img src="/emoticonos/47.gif" />');
  texto = texto.replace(/::48::/g,'<img src="/emoticonos/48.gif" />');
  texto = texto.replace(/::49::/g,'<img src="/emoticonos/49.gif" />');
  texto = texto.replace(/::50::/g,'<img src="/emoticonos/50.gif" />');
  texto = texto.replace(/::51::/g,'<img src="/emoticonos/51.gif" />');
  texto = texto.replace(/::52::/g,'<img src="/emoticonos/52.gif" />');
  texto = texto.replace(/::53::/g,'<img src="/emoticonos/53.gif" />');
  texto = texto.replace(/::54::/g,'<img src="/emoticonos/54.gif" />');
  texto = texto.replace(/::55::/g,'<img src="/emoticonos/55.gif" />');

  /* 
Se reescribe con los reemplazos efectuados */
  document.form_comentar.texto.value = texto;
}

function emoticono(emo) {
  /* Escribe el código del emoticono y devuelve el foco al textarea */
  document.form_comentar.texto.value += emo;
  document.form_comentar.texto.focus();
}
