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((document.selection)) 
   { 
      document.forms[0].msg.focus(); 
      document.forms[0].document.selection.createRange().text = "[b]"+document.forms[0].document.selection.createRange().text+"[/b]";
   }
   else if(document.forms[0].elements['msg'].selectionStart != undefined)
   { 
      var element = document.forms[0].elements['msg']; 
      var str = element.value; 
      var start = element.selectionStart; 
      var length = element.selectionEnd - element.selectionStart;
      element.value = str.substr(0, start) + "[b]" + str.substr(start, length) + "[/b]" + str.substr(start + length); 
   } 
   else document.form.msg.value += "[b]"+"[/b]";
}
   

function xoopsCodeItalic(id)
{
   if((document.selection)) 
   { 
      document.forms[0].msg.focus(); 
      document.forms[0].document.selection.createRange().text = "[i]"+document.forms[0].document.selection.createRange().text+"[/i]";
   }
   else if(document.forms[0].elements['msg'].selectionStart != undefined)
   { 
      var element = document.forms[0].elements['msg']; 
      var str = element.value; 
      var start = element.selectionStart; 
      var length = element.selectionEnd - element.selectionStart;
      element.value = str.substr(0, start) + "[i]" + str.substr(start, length) + "[/i]" + str.substr(start + length); 
   } 
   else document.form.msg.value += "[i]"+"[/i]";
}

function xoopsCodeUnderline(id)
{
   if((document.selection)) 
   { 
      document.forms[0].msg.focus(); 
      document.forms[0].document.selection.createRange().text = "[u]"+document.forms[0].document.selection.createRange().text+"[/u]";
   }
   else if(document.forms[0].elements['msg'].selectionStart != undefined)
   { 
      var element = document.forms[0].elements['msg']; 
      var str = element.value; 
      var start = element.selectionStart; 
      var length = element.selectionEnd - element.selectionStart;
      element.value = str.substr(0, start) + "[u]" + str.substr(start, length) + "[/u]" + str.substr(start + length); 
   } 
   else document.form.msg.value += "[u]"+"[/u]";
}

function xoopsCodeRight(id)
{
   if((document.selection)) 
   { 
      document.forms[0].msg.focus(); 
      document.forms[0].document.selection.createRange().text = "[p right]"+document.forms[0].document.selection.createRange().text+"[/p]";
   }
   else if(document.forms[0].elements['msg'].selectionStart != undefined)
   { 
      var element = document.forms[0].elements['msg']; 
      var str = element.value; 
      var start = element.selectionStart; 
      var length = element.selectionEnd - element.selectionStart;
      element.value = str.substr(0, start) + "[p right]" + str.substr(start, length) + "[/p]" + str.substr(start + length); 
   } 
   else document.form.msg.value += "[p right]"+"[/p]";
}

function xoopsCodeCenter(id)
{
   if((document.selection)) 
   { 
      document.forms[0].msg.focus(); 
      document.forms[0].document.selection.createRange().text = "[p center]"+document.forms[0].document.selection.createRange().text+"[/p]";
   }
   else if(document.forms[0].elements['msg'].selectionStart != undefined)
   { 
      var element = document.forms[0].elements['msg']; 
      var str = element.value; 
      var start = element.selectionStart; 
      var length = element.selectionEnd - element.selectionStart;
      element.value = str.substr(0, start) + "[p center]" + str.substr(start, length) + "[/p]" + str.substr(start + length); 
   } 
   else document.form.msg.value += "[p center]"+"[/p]";
}

function xoopsCodeLeft(id)
{
   if((document.selection)) 
   { 
      document.forms[0].msg.focus(); 
      document.forms[0].document.selection.createRange().text = "[p left]"+document.forms[0].document.selection.createRange().text+"[/p]";
   }
   else if(document.forms[0].elements['msg'].selectionStart != undefined)
   { 
      var element = document.forms[0].elements['msg']; 
      var str = element.value; 
      var start = element.selectionStart; 
      var length = element.selectionEnd - element.selectionStart;
      element.value = str.substr(0, start) + "[p left]" + str.substr(start, length) + "[/p]" + str.substr(start + length); 
   } 
   else document.form.msg.value += "[p left]"+"[/p]";
}

function xoopsCodeJustify(id)
{
   if((document.selection)) 
   { 
      document.forms[0].msg.focus(); 
      document.forms[0].document.selection.createRange().text = "[p justify]"+document.forms[0].document.selection.createRange().text+"[/p]";
   }
   else if(document.forms[0].elements['msg'].selectionStart != undefined)
   { 
      var element = document.forms[0].elements['msg']; 
      var str = element.value; 
      var start = element.selectionStart; 
      var length = element.selectionEnd - element.selectionStart;
      element.value = str.substr(0, start) + "[p justify]" + str.substr(start, length) + "[/p]" + str.substr(start + length); 
   } 
   else document.form.msg.value += "[p class=justify]"+"[/p]";
}

function xoopsCodeStrike(id)
{
   if((document.selection)) 
   { 
      document.forms[0].msg.focus(); 
      document.forms[0].document.selection.createRange().text = "[s]"+document.forms[0].document.selection.createRange().text+"[/s]";
   }
   else if(document.forms[0].elements['msg'].selectionStart != undefined)
   { 
      var element = document.forms[0].elements['msg']; 
      var str = element.value; 
      var start = element.selectionStart; 
      var length = element.selectionEnd - element.selectionStart;
      element.value = str.substr(0, start) + "[s]" + str.substr(start, length) + "[/s]" + str.substr(start + length); 
   } 
   else document.form.msg.value += "[s]"+"[/s]";
}

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

   if((document.selection)) 
   { 
      document.forms[0].msg.focus(); 
      document.forms[0].document.selection.createRange().text = "[font size=" + sizeDomValue + "#]"+document.forms[0].document.selection.createRange().text+"[/font]";
   }
   else if(document.forms[0].elements['msg'].selectionStart != undefined)
   { 
      var element = document.forms[0].elements['msg']; 
      var str = element.value; 
      var start = element.selectionStart; 
      var length = element.selectionEnd - element.selectionStart;
      element.value = str.substr(0, start) + "[font size=" + sizeDomValue + "#]" + str.substr(start, length) + "[/font]" + str.substr(start + length); 
   } 
   else document.form.msg.value += "[font size=" + sizeDomValue + "#]"+"[/font]";
}

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

   if((document.selection)) 
   { 
      document.forms[0].msg.focus(); 
      document.forms[0].document.selection.createRange().text = "[font face=" + fontDomValue + "#]"+document.forms[0].document.selection.createRange().text+"[/font]";
   }
   else if(document.forms[0].elements['msg'].selectionStart != undefined)
   { 
      var element = document.forms[0].elements['msg']; 
      var str = element.value; 
      var start = element.selectionStart; 
      var length = element.selectionEnd - element.selectionStart;
      element.value = str.substr(0, start) + "[font face=" + fontDomValue + "#]" + str.substr(start, length) + "[/font]" + str.substr(start + length); 
   } 
   else document.form.msg.value += "[font face=" + fontDomValue + "#]"+"[/font]";
}

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

   if((document.selection)) 
   { 
      document.forms[0].msg.focus(); 
      document.forms[0].document.selection.createRange().text = "[font color=" + colorDomValue + "#]"+document.forms[0].document.selection.createRange().text+"[/font]";
   }
   else if(document.forms[0].elements['msg'].selectionStart != undefined)
   { 
      var element = document.forms[0].elements['msg']; 
      var str = element.value; 
      var start = element.selectionStart; 
      var length = element.selectionEnd - element.selectionStart;
      element.value = str.substr(0, start) + "[font color=" + colorDomValue + "#]" + str.substr(start, length) + "[/font]" + str.substr(start + length); 
   } 
   else document.form.msg.value += "[font color=" + colorDomValue + "#]"+"[/font]";
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


