function instag(id,tag,param1,param2) {
  switch (tag) {
  case "b":
  case "u":
  case "i":
  case "sup":
  case "sub":
    instext(id,"["+tag+"]","[/"+tag+"]");
    break;
  case "color":
    instext(id,"["+tag+"="+param1+"]","[/"+tag+"]");
    break;
  case "size":
    instext(id,"["+tag+"=100%]","[/"+tag+"]");
    break;
  case "url":
  case "email":
    instext(id,"["+tag+"=","]");
    break;
  case "h":
    instext(id,"\r\n["+tag+param1+"]","");
    break;
  case "left":
  case "center":
  case "right":
  case "list":
  case "list=1":
  case "table":
    instext(id,"\r\n["+tag+"]\r\n","");
    break;
  case "img":
    instext(id,"[img="+param1+" right]","");
    break;
  case "file":
    instext(id,"[url=/files/"+param1+" "+param2+"]","");
    break;
  }
}

function instext(id,tag1,tag2) {
  str=document.getElementById(id);
  if (navigator.userAgent.indexOf('Opera')==-1) {
    str.focus();
  }
  if (document.selection) {
    // IE, Opera
    document.selection.createRange().text=tag1+document.selection.createRange().text+tag2;
  } else {
    // Mozilla
    var str1=str.value.substr(0,str.selectionStart);
    var str2=str.value.substr(str.selectionStart,str.selectionEnd-str.selectionStart);
    var str3=str.value.substr(str.selectionEnd,str.value.length);
    cursor=str.selectionEnd+tag1.length+tag2.length;
    str.value=str1+tag1+str2+tag2+str3;
    str.selectionStart=str.selectionEnd=cursor;
  }
}

function showhide(div) {
  if (document.getElementById(div).style.display=="block")
    document.getElementById(div).style.display="none";
  else
    document.getElementById(div).style.display="block";
}

function ico2on(obj) {
  obj.style.border='1px solid #7a7f9c';
  obj.style.background='#d5eaff';
}
function ico2off(obj) {
  obj.style.border='1px solid #eeeeee';
  obj.style.background='none';
}

