//**************************************
//
// Name: Apply BBCode to Textarea
// Description:This script will insert s
//     ome bbcode where the selection is locate
//     d in a textarea form field. There is als
//     o an additional function for link bbcode
//     with prompt feature.
// By: Matt DeKok
//
//This code is copyrighted and has// limited warranties.Please see http://
//     www.Planet-Source-Code.com/vb/scripts/Sh
//     owCode.asp?txtCodeId=6058&lngWId=2//for details.//**************************************
//


    function addtag(tag) {
      var txt = document.getElementById('content');


          if(document.selection) {
            txt.focus();
            sel = document.selection.createRange();
            sel.text = '[' + tag + ']' + sel.text + '[/' + tag + ']';
          } else if(txt.selectionStart || txt.selectionStart == '0') {
            txt.value = (txt.value).substring(0, txt.selectionStart) + "["+tag+"]" + (txt.value).substring(txt.selectionStart, txt.selectionEnd) + "[/"+tag+"]" + (txt.value).substring(txt.selectionEnd, txt.textLength);


              } else {
                txt.value = '[' + tag + '][/' + tag + ']';
              }
              return;
        }


            function addurltag() {
              var txt = document.getElementById('content');
              var link = prompt("Type the address:", "http://");


                  if(link.length == 0 || link == "http://") {
                    return;


                      } else {
                        var link = "=" + link;
                        var text;
                        var sel2 = "";


                            if(document.selection) {
                              txt.focus();
                              sel = document.selection.createRange();
                              sel2 = sel.text;


                                } else if(txt.selectionStart || txt.selectionStart == '0') {
                                  sel2 = (txt.value).substring(txt.selectionStart, txt.selectionEnd);
                                }


                                    if(sel2.length > 0) {
                                      text = sel2;


                                        } else {
                                          text = prompt("Enter the link text:", "");
                                        }
                                      }


                                          if(document.selection) {
                                            txt.focus();
                                            sel = document.selection.createRange();
                                            sel.text = "[url" + link + "]" + text + "[/url]";


                                              } else {
                                                txt.value = (txt.value).substring(0, txt.selectionStart) + "[url" + link + "]" + text + "[/url]" + (txt.value).substring(txt.selectionEnd, txt.textLength);
                                              }
                                              return;
                                        }
