var popUpWin=0;

function popUpWindow(URLStr, left, top, width, height) {
  if (popUpWin) {
    if (!popUpWin.closed) {
      popUpWin.close();
    }
  }
  popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

function blindToggle(element_id, _duration) {
  // Set a default duration of 1/4 second if none specified.
  if (null == _duration) { _duration = 0.25; }
  var el = $(element_id);
  try {
    if (el) {
      if (el.visible()) {
        el.blindUp({duration: _duration});
      } else {
        el.blindDown({duration: _duration});
      }
    }
  } catch (e) {
  }
}

function EditorBoxFocus() {
  document.form1.body.focus();
}

function CreateLinkPlain() {
  var str = prompt("Enter link location","http:\/\/");
  if (str) {
    var str1 = prompt("Enter link title:", "");
    if (str1) {
      str = "<a href=\"" + str + "\">" + str1 + "</a>";
      SetValueAndFocus('body', str);
//      prompt("Copy the HTML below and paste into your journal.", str);
    } else {
      EditorBoxFocus();
    }
  }
  return false;
}

function CreateImagePlain() {
  var str = prompt("Enter image location","http:\/\/");
  if ((str!=null) && (str!="http://")) {
    if (str) {
      var size = prompt("Enter the maximum width:", "200");
    }
    str = "<img src=\"" + str + "\"" + " width=\"" + size + "\">";
    SetValueAndFocus('body', str);
//    prompt("Copy the HTML below and paste into your journal.", str);
  } else {
    EditorBoxFocus();
  }
  return false;
}

function SetValueAndFocus(id, str) {
  try {
    el = $(id);
    if (el != null) {
      el.value = el.value + str;
      el.focus();
    } else {
      alert("boo: Unable to find element with id: " + id);
    }
  } catch (e) {
    alert("poopie: " + e);
  }
}

function CopyToClipboard() {
  CopiedTxt = document.selection.createRange();
  CopiedTxt.execCommand("Copy");
}

function PasteFromClipboard() { 
  document.Form1.txtArea.focus();
  PastedText = document.Form1.txtArea.createTextRange();
  PastedText.execCommand("Paste");
} 

function PasteToElementId(id) {
  var el = $(id);
  if (el != null) {
    el.focus();
    theText = el.createTextRange();
    theText.execCommand("Paste");
  }
}
