//Для textarea
//Если класс tags, то добавляются кнопки тегов форматирования
objs=document.getElementsByTagName("TEXTAREA");
if(objs)
{
  for(i=0; i<objs.length;i++)
  {
    container=objs[i].parentNode;

    if(isClass(objs[i],"tags"))
    {
      tags=document.createElement("div");
      tags.style.width=objs[i].style.width;
      container.insertBefore(tags,objs[i]);
      //ссылка
      head=document.createElement("a");
      head.className="ajax";
      head.href="javascript:";
      head.onclick=function() {switchDisplay(this.nextSibling,"block")};
      head.innerHTML="Теги форматирования";
      tags.appendChild(head);
      //блок кнопок
      tagsButtons=document.createElement("div");
      tagsButtons.style.display="none";
      tags.appendChild(tagsButtons);
      //кнопка H1
      B=document.createElement("button"); B.setAttribute("type","button"); B.className="ajax";
      B.innerHTML="Заголовок 1";
      B.onclick=function(){ textarea=getChildByType(this.parentNode.parentNode.parentNode,"textarea"); replaceSelectedText(textarea,function(str){return "[h1]"+str+"[/h1]"})};
      tagsButtons.appendChild(B);
      //кнопка H2
      B=document.createElement("button"); B.setAttribute("type","button"); B.className="ajax";
      B.innerHTML="Заголовок 2";
      B.onclick=function(){ textarea=getChildByType(this.parentNode.parentNode.parentNode,"textarea"); replaceSelectedText(textarea,function(str){return "[h2]"+str+"[/h2]"})};
      tagsButtons.appendChild(B);
      //кнопка H3
      B=document.createElement("button"); B.setAttribute("type","button"); B.className="ajax";
      B.innerHTML="Заголовок 3";
      B.onclick=function(){ textarea=getChildByType(this.parentNode.parentNode.parentNode,"textarea"); replaceSelectedText(textarea,function(str){return "[h3]"+str+"[/h3]"})};
      tagsButtons.appendChild(B);
      //кнопка P
      B=document.createElement("button"); B.setAttribute("type","button"); B.className="ajax";
      B.innerHTML="Новый абзац";
      B.onclick=function(){ textarea=getChildByType(this.parentNode.parentNode.parentNode,"textarea"); replaceSelectedText(textarea,function(str){return str+"[p]"})};
      tagsButtons.appendChild(B);
      //кнопка Bold
      B=document.createElement("button"); B.setAttribute("type","button"); B.className="ajax";
      B.innerHTML="<b>Жирный</b>";
      B.onclick=function(){ textarea=getChildByType(this.parentNode.parentNode.parentNode,"textarea"); replaceSelectedText(textarea,function(str){return "[b]"+str+"[/b]"})};
      tagsButtons.appendChild(B);
      //кнопка Italic
      B=document.createElement("button"); B.setAttribute("type","button"); B.className="ajax";
      B.innerHTML="<i>Курсив</i>";
      B.onclick=function(){ textarea=getChildByType(this.parentNode.parentNode.parentNode,"textarea"); replaceSelectedText(textarea,function(str){return "[i]"+str+"[/i]"})};
      tagsButtons.appendChild(B);
      //кнопка Underline
      B=document.createElement("button"); B.setAttribute("type","button"); B.className="ajax";
      B.innerHTML="<u>Подчеркнуть</u>";
      B.onclick=function(){ textarea=getChildByType(this.parentNode.parentNode.parentNode,"textarea"); replaceSelectedText(textarea,function(str){return "[u]"+str+"[/u]"})};
      tagsButtons.appendChild(B);
      //кнопка Strike
      B=document.createElement("button"); B.setAttribute("type","button"); B.className="ajax";
      B.innerHTML="<s>Зачеркнуть</s>";
      B.onclick=function(){ textarea=getChildByType(this.parentNode.parentNode.parentNode,"textarea"); replaceSelectedText(textarea,function(str){return "[s]"+str+"[/s]"})};
      tagsButtons.appendChild(B);
      //кнопка Url
      B=document.createElement("button"); B.setAttribute("type","button"); B.className="ajax";
      B.innerHTML="Ссылка";
      B.onclick=function(){ textarea=getChildByType(this.parentNode.parentNode.parentNode,"textarea"); url=prompt("Введите адрес ссылки"); replaceSelectedText(textarea,function(str){return "[url="+url+"]"+str+"[/url]"})};
      tagsButtons.appendChild(B);
      //кнопка Email
      B=document.createElement("button"); B.setAttribute("type","button"); B.className="ajax";
      B.innerHTML="Email";
      B.onclick=function(){ textarea=getChildByType(this.parentNode.parentNode.parentNode,"textarea"); email=prompt("Введите email"); replaceSelectedText(textarea,function(str){return "[email="+email+"]"+str+"[/email]"})};
      tagsButtons.appendChild(B);
      //кнопка Color
      B=document.createElement("button"); B.setAttribute("type","button"); B.className="ajax";
      B.innerHTML="Цвет";
      B.onclick=function(){ textarea=getChildByType(this.parentNode.parentNode.parentNode,"textarea"); color=prompt("Введите цвет в формате #RRGGBB"); replaceSelectedText(textarea,function(str){return "[color="+color+"]"+str+"[/color]"})};
      tagsButtons.appendChild(B);
      //кнопка IMG
      B=document.createElement("button"); B.setAttribute("type","button"); B.className="ajax";
      B.innerHTML="Картинка";
      B.onclick=function(){ textarea=getChildByType(this.parentNode.parentNode.parentNode,"textarea"); img=prompt("Введите имя картинки"); if(confirm("Картинка внутри текста?")) replaceSelectedText(textarea,function(str){return str+"[img="+img+"]"}); else { if(confirm("Картинка слева от текста?")) replaceSelectedText(textarea,function(str){return str+"[img="+img+",l]"}); else replaceSelectedText(textarea,function(str){return str+"[img="+img+",r]"}); } };
      tagsButtons.appendChild(B);
      //кнопка HR
      B=document.createElement("button"); B.setAttribute("type","button"); B.className="ajax";
      B.innerHTML="Линия";
      B.onclick=function(){ textarea=getChildByType(this.parentNode.parentNode.parentNode,"textarea"); replaceSelectedText(textarea,function(str){return str+"[hr]"})};
      tagsButtons.appendChild(B);
      //кнопка HTML
      B=document.createElement("button"); B.setAttribute("type","button"); B.className="ajax";
      B.innerHTML="HTML";
      B.onclick=function(){ textarea=getChildByType(this.parentNode.parentNode.parentNode,"textarea"); replaceSelectedText(textarea,function(str){return "[html]"+str+"[/html]"})};
      tagsButtons.appendChild(B);
    }
    
    /*upDown=document.createElement("div");
    upDown.title="Изменить размер ввода поля";
    upDown.className="up-down";
    upDown.name=i;
    upDown.onmousedown=function()
    {
      obj=this.previousSibling;
      document.onmousemove=function(ev){resize_textarea(obj,ev);return false}
      document.onmouseup=function(){document.onmousemove=null;document.onmouseup=null}
      return false;
    }
    container.appendChild(upDown);*/
  }
}

/*function resize_textarea(obj,e)
{
  alert(e.clientY);
  e=(e)?e:(window.event)?event:null,ws=getScrollY();
  var h=e.clientY-getposOffset(obj,'top')-5;//ws;
  if(h>50)obj.style.height=h+'px';
  
  function getScrollY()
  {
    var scrOfY = 0;
    if( typeof( window.pageYOffset ) == 'number' ) {
      //Netscape compliant
      scrOfY = window.pageYOffset;
    } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
      //DOM compliant
      scrOfY = document.body.scrollTop;
    } else if( document.documentElement &&
	( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
      //IE6 standards compliant mode
      scrOfY = document.documentElement.scrollTop;
    }
    return scrOfY;
  }
  function getposOffset(overlay, offsettype)
  {
    var totaloffset=overlay.offsetTop
    var parentEl=overlay.offsetParent
    while (parentEl!=null)
    {
      totaloffset=totaloffset+parentEl.offsetTop
      parentEl=parentEl.offsetParent
    }
    return totaloffset;
  }
}*/

