function confirmAction (question, uri) {
    if (confirm (question)) {
        document.location=uri;
    }
    return false;
}

function GetSel()
{
  document.forms[1].body.focus();
  if (document.getSelection) txt = document.getSelection();
  else if (document.selection) txt = document.selection.createRange().text;
    else return;
}

function AddTag(tag)
{
  GetSel();

  if (tag == "IMG") {
    img_url = prompt("Please enter the Image URL", "http://");
    img_border = prompt("Please enter the Image Border-Size", "0");

    if (img_url && img_border) {
      tag_img = "<IMG SRC=" + img_url + " border=" + img_border + ">";
      if ( txt ) {
        document.selection.createRange().text = tag_img;
      }
      else {
        insertAtCaret(document.forms[0].body, tag_img);
      }
    }
  }
  else if (tag == "URL") {
    if ( txt ) {
      link_url = prompt("Please enter the Link URL", "http://");
      link_name = prompt("Please enter the Link Name", txt);
      if (link_url && link_name) {
        tag_url = "<A HREF=" + link_url + ">" + link_name + "</A>";
        document.selection.createRange().text = tag_url;
      }
    }
    else {
      link_url = prompt("Please enter the Link URL", "http://");
      link_name = prompt("Please enter the Link Title", "Link");
      if (link_url && link_name) {
        tag_url = "<A HREF=" + link_url + ">" + link_name + "</A>";
        insertAtCaret(document.forms[0].body, tag_url);
      }
    }
  }
  else if (tag == "URL_EXT") {
    if ( txt ) {
      link_url = prompt("Please enter the Link URL", "http://");
      link_name = prompt("Please enter the Link Name", txt);
      if (link_url && link_name) {
        tag_url = "<A HREF=" + link_url + " target=new>" + link_name + "</A>";
        document.selection.createRange().text = tag_url;
      }
    }
    else {
      link_url = prompt("Please enter the Link URL", "http://");
      link_name = prompt("Please enter the Link Title", "Link");
      if (link_url && link_name) {
        tag_url = "<A HREF=" + link_url + ">" + link_name + "</A>";
        insertAtCaret(document.forms[0].body, tag_url);
      }
    }
  }
  else {
    tag1 = "<" + tag + ">";
    tag2 = "</" + tag + ">";
    if ( txt ) {
      document.selection.createRange().text = tag1 + txt + tag2;
    }
    else {
      alert ("You must highlight a Text in the Textarea");
    }
  }
}

function storeCaret (textEl) {
  if (textEl.createTextRange)
      textEl.caretPos = document.selection.createRange().duplicate();
}

function insertAtCaret (textEl, text) {
     var caretPos = textEl.caretPos;
    caretPos.text =
  caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
}


function popupLogin() {

  // the size of the popup window
  var width = 800;
  var height = 600;

  // the x,y position of the popup window
  // NOTE: this formula will auto-center the popup on the screen
  var y = (screen.height - height) / 2;
  var x = (screen.width - width) / 2;

  var url = "http://forum.vo-racing.de/vo_chat.php";
  var options = "width=" + width + ",height=" + height + ",top=" + y + ",left=" + x + ",resizable";

  // open the chat window as a popup, instead of embedded in webpage
  window.open( url, "chat", options );
}