//Thanks to everyone who contributed, even if they don't know they did.
//Thanks to all the people at the www.devshed.com forums
//Finally, very special thanks to http://www.xs4all.nl/~ppk/js/intro.html for their nice text selection script (hey, im a newb :))
//which made this script so much better by taking away the prompt boxes, and replacing them with simply
//selecting the text (well in IE anyway). - Short_Rz

//The RED text is the text that you have to change to suit your script


function insertAtCursor(myField, myValue)
{
  //IE support
  if (document.selection)
  {
    myField.focus();
    sel = document.selection.createRange();
    sel.text = myValue;
  }
  //MOZILLA/NETSCAPE support
  else if (myField.selectionStart || myField.selectionStart == '0')
  {
    var startPos = myField.selectionStart;
    var endPos = myField.selectionEnd;
    myField.value = myField.value.substring(0, startPos)
                  + myValue
                  + myField.value.substring(endPos, myField.value.length);
  }
  else
  {
    myField.value += myValue;
  }
}

browser = navigator.appName;
if (browser == "Netscape")
{
function olink()
{
var link = prompt('Podaj adres[url]:','');
if (link != null)
{
var text = prompt('Podaj nazwę odnośnika:','');
if (text != null)
{
insertAtCursor(document.form1.text, '<a target="_blank"  href="http://' + link + '">' + text + "</a>");
}
else
{
return;
}
}
else
{
return;
}
}

function format(format1, format2)
{
  var text = prompt('Enter text to format:','');
  if (text != null)
 {
  insertAtCursor(document.form1.text, format1 + text + format2);
  }
  else
  {
  return;
  }
}

function format2(format1, format2, format3, id)
{
color = document.form1.color.options[document.form1.color.selectedIndex].value;
 var text = prompt('Wpisz tekst do pokolorowania:','');
if (text != null)
 {
if (id == "1")
{
insertAtCursor(document.form1.text, format1 + color + format2 + text + format3);
  }
if (id == "2")
{
insertAtCursor(document.form1.text, format1 + size + format2 + text + format3);
}
}
 else
  {
return;
}
}

function format3(position)
{
var txt = prompt('Please enter text to be aligned', '')
insertAtCursor(document.form1.text, '<div align="' + position + '">' + txt + '</div>')
}
}
else
{
function getSel()
{
if (document.selection) txt = document.selection.createRange().text;
else return;
return txt;
}

function olink()
{
var link = prompt('Podaj adres [url]:','');
if (link != null)
{
getSel();
insertAtCursor(document.form1.text, '<a target="_blank" href="http://' + link + '">' + txt + "</a>");
}
}

function format(format1, format2)
{
getSel();
  insertAtCursor(document.form1.text, format1 + txt + format2);
}

function format2(format1, format2, format3, id)
{
color = document.form1.color.options[document.form1.color.selectedIndex].value;
 var txt = prompt('Wpisz tekst do pokolorowania:','');
if (id == "1")
{
getSel();
insertAtCursor(document.form1.text, format1 + color + format2 + txt + format3);
}
if (id == "2")
{
getSel();
insertAtCursor(document.form1.text, format1 + size + format2 + txt + format3);
}
}

function format3(position)
{
getSel();
insertAtCursor(document.form1.text, '<div align="' + position + '">' + txt + '</div>')
}
}
