function xoopsGetElementById(id)
{
   if(document.getElementById(id))
   {
      return document.getElementById(id);
   } 
   else if (document.all[id])
   {
      return document.all[id];
   } 
   else if (document.layers && document.layers[id])
   {
      return (document.layers[id]);
   } 
   else
   {
      return false;
   }
}

function justReturn()
{
   return;
}

function setElementColor(id, color)
{
   xoopsGetElementById(id).style.color = "#" + color;
}

function setElementFont(id, font)
{
   xoopsGetElementById(id).style.fontFamily = font;
}

function setElementSize(id, size)
{
   xoopsGetElementById(id).style.fontSize = size;
}

function changeDisplay(id)
{
   var elestyle = xoopsGetElementById(id).style;

   if(elestyle.display == "")
   {
      elestyle.display = "none";
   } 
   else
   {
      elestyle.display = "block";
   }
}

function toggleDisplay(id)
{
   var elestyle = xoopsGetElementById(id).style;

   if (elestyle.display == "block" || elestyle.display == "")
   {
      elestyle.display = 'none';
   } 
   else
   {
      elestyle.display = "block";
   }
}

function setVisible(id)
{
   xoopsGetElementById(id).style.visibility = "visible";
}

function setHidden(id)
{
   xoopsGetElementById(id).style.visibility = "hidden";
}

function makeBold(id)
{
   var eleStyle = xoopsGetElementById(id).style;

   if (eleStyle.fontWeight != "bold")
   {
      eleStyle.fontWeight = "bold";
   }
   else
   {
      eleStyle.fontWeight = "normal";
   }
}

function makeItalic(id)
{
   var eleStyle = xoopsGetElementById(id).style;

   if (eleStyle.fontStyle != "italic")
   {
       eleStyle.fontStyle = "italic";
   } 
   else
   {
       eleStyle.fontStyle = "normal";
   }
}

function makeUnderline(id)
{
   var eleStyle = xoopsGetElementById(id).style;

   if(eleStyle.textDecoration != "underline")
   {
      eleStyle.textDecoration = "underline";
   } 
   else
   {
      eleStyle.textDecoration = "none";
   }
}

function appendSelectOption(selectMenuId, optionName, optionValue)
{
   var selectMenu = xoopsGetElementById(selectMenuId);
   var newoption = new Option(optionName, optionValue);

   selectMenu.options[selectMenu.length] = newoption;
   selectMenu.options[selectMenu.length].selected = true;
}

function disableElement(target)
{
   var targetDom = xoopsGetElementById(target);

   if(targetDom.disabled != true)
   {
      targetDom.disabled = true;
   } 
   else
   {
      targetDom.disabled = false;
   }
}

var clientPC = navigator.userAgent.toLowerCase();
var clientVer = parseInt(navigator.appVersion);
var is_ie = ((clientPC.indexOf("msie") != -1) && (clientPC.indexOf("opera") == -1));
var is_win = ((clientPC.indexOf("win")!=-1) || (clientPC.indexOf("16bit") != -1));

function xoopsCodeBold(id)
{
   if((clientVer >= 4) && is_ie && is_win)
   {
      var text = document.selection.createRange().text;
      var dom = xoopsGetElementById(id);

      if( text != null && text != "" )
      {
         var sel = document.selection.createRange();
         sel.text = "[b]" + text + "[/b]";
      } 
      else
      {
         alert("Вы должны выделить текст");
      }
   } 
   else
   {
      var text = prompt("Введите текст, который вы хотите добавить", "");
      var dom = xoopsGetElementById(id);

      if ( text != null && text != "" )
      {
          var result = "[b]" + text + "[/b]";
          dom.focus();
          dom.value += result;
      }
   }
}

function xoopsCodeItalic(id)
{
   if((clientVer >= 4) && is_ie && is_win)
   {
      var text = document.selection.createRange().text;
      var dom = xoopsGetElementById(id);

      if( text != null && text != "" )
      {
         var sel = document.selection.createRange();
         sel.text = "[i]" + text + "[/i]";
      } 
      else
      {
         alert("Вы должны выделить текст");
      }
   } 
   else 
   {
      var text = prompt("Введите текст, который вы хотите добавить", "");
      var dom = xoopsGetElementById(id);

      if( text != null && text != "" )
      {
         var result = "[i]" + text + "[/i]";
         dom.focus();
         dom.value += result;
      }
   }
}

function xoopsCodeUnderline(id)
{
   if((clientVer >= 4) && is_ie && is_win)
   {
      var text = document.selection.createRange().text;
      var dom = xoopsGetElementById(id);

      if( text != null && text != "" )
      {
         var sel = document.selection.createRange();
         sel.text = "[u]" + text + "[/u]";
      } 
      else
      {
         alert("Вы должны выделить текст");
      }
   } 
   else
   {
      var text = prompt("Введите текст, который вы хотите добавить", "");
      var dom = xoopsGetElementById(id);

      if( text != null && text != "" )
      {
         var result = "[u]" + text + "[/u]";
         dom.focus();
         dom.value += result;
      }
   }
}

function xoopsCodeRight(id)
{
   if((clientVer >= 4) && is_ie && is_win)
   {
      var text = document.selection.createRange().text;
      var dom  = xoopsGetElementById(id);

      if( text != null && text != "" )
      {
         var sel = document.selection.createRange();
         sel.text = "[p right]" + text + "[/p]";
      } 
      else
      {
         alert("Вы должны выделить текст");
      }
   } 
   else
   {
      var text = prompt("Введите текст, который вы хотите добавить", "");
      var dom  = xoopsGetElementById(id);

      if( text != null && text != "" )
      {
         var result = "[p right]" + text + "[/p]";
         dom.focus();
         dom.value += result;
      }
   }
}

function xoopsCodeCenter(id)
{
   if((clientVer >= 4) && is_ie && is_win)
   {
      var text = document.selection.createRange().text;
      var dom  = xoopsGetElementById(id);

      if( text != null && text != "" )
      {
         var sel = document.selection.createRange();
         sel.text = "[p center]" + text + "[/p]";
      } 
      else
      {
         alert("Вы должны выделить текст");
      }
   } 
   else
   {
      var text = prompt("Введите текст, который вы хотите добавить", "");
      var dom  = xoopsGetElementById(id);

      if( text != null && text != "" )
      {
         var result = "[p center]" + text + "[/p]";
         dom.focus();
         dom.value += result;
      }
   }
}

function xoopsCodeLeft(id)
{
   if((clientVer >= 4) && is_ie && is_win)
   {
      var text = document.selection.createRange().text;
      var dom  = xoopsGetElementById(id);

      if( text != null && text != "" )
      {
         var sel = document.selection.createRange();
         sel.text = "[p left]" + text + "[/p]";
      } 
      else
      {
         alert("Вы должны выделить текст");
      }
   } 
   else
   {
      var text = prompt("Введите текст, который вы хотите добавить", "");
      var dom  = xoopsGetElementById(id);

      if( text != null && text != "" )
      {
         var result = "[p left]" + text + "[/p]";
         dom.focus();
         dom.value += result;
      }
   }
}

function xoopsCodeJustify(id)
{
   if((clientVer >= 4) && is_ie && is_win)
   {
       var text = document.selection.createRange().text;
       var dom  = xoopsGetElementById(id);

       if( text != null && text != "" )
       {
          var sel = document.selection.createRange();
          sel.text = "[p justify]" + text + "[/p]";
       } 
       else
       {
          alert("Вы должны выделить текст");
       }
    } 
    else
    {
       var text = prompt("Введите текст, который вы хотите добавить", "");
       var dom  = xoopsGetElementById(id);

       if( text != null && text != "" )
       {
          var result = "[p justify]" + text + "[/p]";
          dom.focus();
          dom.value += result;
       }
    }
}

function xoopsCodeStrike(id)
{
   if((clientVer >= 4) && is_ie && is_win)
   {
      var text = document.selection.createRange().text;
      var dom = xoopsGetElementById(id);

      if( text != null && text != "" )
      {
         var sel = document.selection.createRange();
         sel.text = "[s]" + text + "[/s]";

      } 
      else
      {
         alert("Вы должны выделить текст");
      }
   } 
   else
   {
      var text = prompt("Введите текст, который вы хотите добавить", "");
      var dom = xoopsGetElementById(id);

      if( text != null && text != "" )
      {
         var result = "[s]" + text + "[/s]";
         dom.focus();
         dom.value += result;
      }
   }
}

function xoopsCodeSize(id)
{

   var sizeDom = xoopsGetElementById(id + "Size");
   var sizeDomValue = sizeDom.options[sizeDom.options.selectedIndex].value;

   if ((clientVer >= 4) && is_ie && is_win)
   {
       var text = document.selection.createRange().text;
       var dom = xoopsGetElementById(id);

       if( text != null && text != "" )
       {
          if(sizeDomValue == "SIZE") sizeDomValue=3;
   
          var sel = document.selection.createRange();
          sel.text = "[font size=" + sizeDomValue + "#]" + text + "[/font]";
          dom.focus();
       } 
       else
       {
          alert("Вы должны выделить текст");
       }
   } 
   else
   {
       var text = prompt("Введите текст, который появится в виде кода.", "");
       var dom = xoopsGetElementById(id);

       if( text != null && text != "" )
       {
          if(sizeDomValue == "SIZE") sizeDomValue=3;

          var result = "[font size=" + sizeDomValue + "#]" + text + "[/font]";
          dom.focus();
          dom.value += result;
       }
   }
}

function xoopsCodeFont(id)
{
   var fontDom = xoopsGetElementById(id + "Font");
   var fontDomValue = fontDom.options[fontDom.options.selectedIndex].value;

   if((clientVer >= 4) && is_ie && is_win)
   {
      var text = document.selection.createRange().text;
      var dom = xoopsGetElementById(id);

      if( text != null && text != "" )
      {
         var sel = document.selection.createRange();
         sel.text = "[font face=" + fontDomValue + "#]" + text + "[/font]";
         dom.focus();
      }
      else
      {
         alert("Вы должны выделить текст");
      }
   } 
   else
   {
      var text = prompt("Введите текст, который появится в виде кода.", "");
      var dom = xoopsGetElementById(id);

      if( text != null && text != "" )
      {
         var result = "[font font=" + fontDomValue + "#]" + text + "[/font]";
         dom.focus();
         dom.value += result;
      }
   }
}

function xoopsCodeColor(id)
{
   var colorDom = xoopsGetElementById(id + "Color");
   var colorDomValue = colorDom.options[colorDom.options.selectedIndex].value;

   if((clientVer >= 4) && is_ie && is_win)
   {
      var text = document.selection.createRange().text;
      var dom = xoopsGetElementById(id);

      if( text != null && text != "" )
      {
         var sel = document.selection.createRange();
         sel.text = "[font color=" + colorDomValue + "#]" + text + "[/font]";
         dom.focus();
      } 
      else
      {
         alert("Вы должны выделить текст");
      }
   } 
   else
   {
      var text = prompt("Введите текст, который появится в виде кода.", "");
      var dom = xoopsGetElementById(id);

      if( text != null && text != "" )
      {
          var result = "[font color=" + colorDomValue + "#]" + text + "[/font]";
          dom.focus();
          dom.value += result;
      }
   }
}

function xoopsCodebiggrin_smile(id)
{
   var dom = xoopsGetElementById(id);
   dom.value +=  "[:))]";
}

function xoopsCodeconfused_smile(id)
{
   var dom = xoopsGetElementById(id);
   dom.value +=  "[:~]";
   
}

function xoopsCodecool_smile(id)
{
   var dom = xoopsGetElementById(id);
   dom.value +=  "[:)]";
}

function xoopsCodemad_smile(id)
{
   var dom = xoopsGetElementById(id);
   dom.value +=  "[:(|]";
}

function xoopsCodeeek_smile(id)
{
   var dom = xoopsGetElementById(id);
   dom.value +=  "[:|]";
}

function xoopsCodefrown_smile(id)
{
   var dom = xoopsGetElementById(id);
   dom.value +=  "[:(]";
}

function xoopsCodesmile_smile(id)
{
   var dom = xoopsGetElementById(id);
   dom.value +=  "[:|)]";
}

function xoopsCodewink_smile(id)
{
   var dom = xoopsGetElementById(id);
   dom.value +=  "[:/]";
}

function xoopsCodejazz_smile(id)
{
   var dom = xoopsGetElementById(id);
   dom.value +=  "[:()]";
}
