var textform='';
function insert(insert, type, el){
  if(type==1){
    if(isIE){
      el.parentNode.parentNode.parentNode.parentNode.getElementsByTagName('textarea')[0].focus();
      document.selection.createRange().text='['+insert+']'+document.selection.createRange().text+'[/'+insert+']';
    }else{
      var text=el.parentNode.parentNode.parentNode.parentNode.getElementsByTagName('textarea')[0];
      el.parentNode.parentNode.parentNode.parentNode.getElementsByTagName('textarea')[0].focus();
      text=text.value.substring(0, text.selectionStart)+'['+insert+']'+text.value.substring(text.selectionStart, text.selectionEnd)+'[/'+insert+']'+text.value.substring(text.selectionEnd, text.value.length);
      el.parentNode.parentNode.parentNode.parentNode.getElementsByTagName('textarea')[0].value=text;
    }
  }else if(type==2){
    if(isIE){
      el.parentNode.parentNode.parentNode.parentNode.getElementsByTagName('textarea')[0].focus();
      document.selection.createRange().text='['+insert+']'+document.selection.createRange().text;
    }else{
      var text=el.parentNode.parentNode.parentNode.parentNode.getElementsByTagName('textarea')[0];
      el.parentNode.parentNode.parentNode.parentNode.getElementsByTagName('textarea')[0].focus();
      text=text.value.substring(0, text.selectionStart)+'['+insert+']'+text.value.substring(text.selectionStart, text.value.length);
      el.parentNode.parentNode.parentNode.parentNode.getElementsByTagName('textarea')[0].value=text;
    }
  }else if(type==3){
    textform=el;
    if(insert=='url'){
      window.open('/text/static/generateurl.html', 'generateurl', 'top=150, left=200, height=125, width=400');
    }else if(insert=='mail'){
      window.open('/text/static/generatemail.html', 'generatemail', 'top=150, left=200, height=125, width=400');
    }else if(insert=='hidden'){
      window.open('/text/static/generatehidden.html', 'generatehidden', 'top=150, left=200, height=125, width=400');
    }else if(insert=='image'){
      window.open('/text/static/addimage.html', 'addimage', 'top=150, left=200, height=100, width=400');
    }else if(insert=='video'){
      window.open('/text/static/addvideo.html', 'addvideo', 'top=150, left=200, height=100, width=400');
    }
  }else if(type==4){
    if(isIE){
      el.parentNode.parentNode.parentNode.parentNode.getElementsByTagName('textarea')[0].focus();
      document.selection.createRange().text=':'+insert+':'+document.selection.createRange().text;
    }else{
      var text=el.parentNode.parentNode.parentNode.parentNode.getElementsByTagName('textarea')[0];
      el.parentNode.parentNode.parentNode.parentNode.getElementsByTagName('textarea')[0].focus();
      text=text.value.substring(0, text.selectionStart)+':'+insert+':'+text.value.substring(text.selectionStart, text.value.length);
      el.parentNode.parentNode.parentNode.parentNode.getElementsByTagName('textarea')[0].value=text;
    }
  }
}
function insertUrl(name, url){
  if(isIE){
    textform.parentNode.parentNode.parentNode.parentNode.getElementsByTagName('textarea')[0].focus();
    document.selection.createRange().text='[url='+url+']'+name+'[/url]'+document.selection.createRange().text;
  }else{
    var text=textform.parentNode.parentNode.parentNode.parentNode.getElementsByTagName('textarea')[0];
    textform.parentNode.parentNode.parentNode.parentNode.getElementsByTagName('textarea')[0].focus();
    text=text.value.substring(0, text.selectionStart)+'[url='+url+']'+name+'[/url]'+text.value.substring(text.selectionStart, text.value.length);
    textform.parentNode.parentNode.parentNode.parentNode.getElementsByTagName('textarea')[0].value=text;
  }
}
function insertMail(name, url){
  if(isIE){
    textform.parentNode.parentNode.parentNode.parentNode.getElementsByTagName('textarea')[0].focus();
    document.selection.createRange().text='[mail='+url+']'+name+'[/mail]'+document.selection.createRange().text;
  }else{
    var text=textform.parentNode.parentNode.parentNode.parentNode.getElementsByTagName('textarea')[0];
    textform.parentNode.parentNode.parentNode.parentNode.getElementsByTagName('textarea')[0].focus();
    text=text.value.substring(0, text.selectionStart)+'[mail='+url+']'+name+'[/mail]'+text.value.substring(text.selectionStart, text.value.length);
    textform.parentNode.parentNode.parentNode.parentNode.getElementsByTagName('textarea')[0].value=text;
  }
}
function insertImage(name, serv){
  if(isIE){
    textform.parentNode.parentNode.parentNode.parentNode.getElementsByTagName('textarea')[0].focus();
    document.selection.createRange().text='[img]'+serv+'[/img]'+document.selection.createRange().text;
  }else{
    var text=textform.parentNode.parentNode.parentNode.parentNode.getElementsByTagName('textarea')[0];
    textform.parentNode.parentNode.parentNode.parentNode.getElementsByTagName('textarea')[0].focus();
    text=text.value.substring(0, text.selectionStart)+'[img]'+serv+'[/img]'+text.value.substring(text.selectionStart, text.value.length);
    textform.parentNode.parentNode.parentNode.parentNode.getElementsByTagName('textarea')[0].value=text;
  }
}
function insertHidden(name, serv){
  if(isIE){
    textform.parentNode.parentNode.parentNode.parentNode.getElementsByTagName('textarea')[0].focus();
    document.selection.createRange().text='[hidden='+name+'|'+serv+']'+document.selection.createRange().text+'[/hidden]';
  }else{
    var text=textform.parentNode.parentNode.parentNode.parentNode.getElementsByTagName('textarea')[0];
    textform.parentNode.parentNode.parentNode.parentNode.getElementsByTagName('textarea')[0].focus();
    text=text.value.substring(0, text.selectionStart)+'[hidden='+name+'|'+serv+']'+text.value.substring(text.selectionStart, text.selectionEnd)+'[/hidden]'+text.value.substring(text.selectionEnd, text.value.length);
    textform.parentNode.parentNode.parentNode.parentNode.getElementsByTagName('textarea')[0].value=text;
  }
}
function insertVideo(url){
  if(isIE){
    textform.parentNode.parentNode.parentNode.parentNode.getElementsByTagName('textarea')[0].focus();
    document.selection.createRange().text='[video='+url+']'+document.selection.createRange().text;
  }else{
    var text=textform.parentNode.parentNode.parentNode.parentNode.getElementsByTagName('textarea')[0];
    textform.parentNode.parentNode.parentNode.parentNode.getElementsByTagName('textarea')[0].focus();
    text=text.value.substring(0, text.selectionStart)+'[video='+url+']'+text.value.substring(text.selectionStart, text.value.length);
    textform.parentNode.parentNode.parentNode.parentNode.getElementsByTagName('textarea')[0].value=text;
  }
}