//Requires Mozilla or Phoenix post 8-Jan-03

function getMozSelection() {
  return document.getSelection();
}

// IE only - stores the current cursor position on any textarea activity
  function storeCaret (txtarea) { 
    if (txtarea.createTextRange) { 
      txtarea.caretPos = document.selection.createRange().duplicate();
    } 
  } 

// IE only - wraps selected text with lft and rgt
  function WrapIE(lft, rgt) {
    strSelection = document.selection.createRange().text;
    if (strSelection!="") {
      document.selection.createRange().text = lft + strSelection + rgt;
    }
  }

// Moz only - wraps selected text with lft and rgt
  function wrapMoz(txtarea, lft, rgt) {
    var selLength = txtarea.textLength;
    var selStart = txtarea.selectionStart;
    var selEnd = txtarea.selectionEnd;
    if (selEnd==1 || selEnd==2) selEnd=selLength;
    var s1 = (txtarea.value).substring(0,selStart);
    var s2 = (txtarea.value).substring(selStart, selEnd)
    var s3 = (txtarea.value).substring(selEnd, selLength);
    txtarea.value = s1 + lft + s2 + rgt + s3;
  }
  
// Chooses technique based on browser
  function wrapTag(txtarea, lft, rgt) {
    lft = unescape(lft);
    rgt = unescape(rgt);
    if (document.all) {
      WrapIE(lft, rgt);
    }
    else if (document.getElementById) {
      wrapMoz(txtarea, lft, rgt);
    }
  }

// Get a link via a prompt and wrap selected text
  function wrapWithLink(txtarea) {
    var my_link = prompt("URL:","http://");
    if (my_link != null) {
      lft="<a href=\"" + my_link + "\">";
      rgt="</a>";
      wrapTag(txtarea, lft, rgt);
    }
    return;
  }

// Get a email-addy via a prompt and wrap selected text
  function wrapWithEmail(txtarea) {
    var my_link = prompt("Email:","");
    if (my_link != null) {
      lft="<!-- MAIL2CRYPT " + my_link + ",";
      rgt=",,paranoid -->";
      wrapTag(txtarea, lft, rgt);
    }
    return;
  }

// IE only - Insert text at caret position or at start of selected text
  function insertIE (txtarea, text) {
    if (txtarea.createTextRange && txtarea.caretPos) { 
      var caretPos = txtarea.caretPos; 
      caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text+caretPos.text + ' ' : text+caretPos.text;
    } else {
      txtarea.value = txtarea.value + text; 
    }
    return;
  } 

// Moz only - Insert text at caret position or at start of selected text
  function insertMoz(txtarea , lft) {
    var rgt="";
    wrapTag(txtarea, lft, rgt);
    return;
  }

// Switch function based on browser - Insert text at caret position or at start of selected text
  function insertTag(txtarea , lft) {
    if (document.all) {
      insertIE(txtarea, lft);
    }
    else if (document.getElementById) {
      insertMoz(txtarea, lft);
    }
  }
    
// prompt for image name. Insert image at caret position or at start of selected text
  function insertImage(txtarea) {
    var my_link = prompt("IMG URL:","http://");
    if (my_link != null) {
      lft="<img src=\"" + my_link + "\" />";
      insertTag(txtarea, lft);
    }
    return;
  }

// End Processing code.

/*
  written by meg hourihan
  http://www.megnut.com
  meg@megnut.com
  
  warning: it only works for IE4+/Win and Moz1.1+
  feel free to take it for your site
  but leave this text in place.
  any problems, let meg know.
  */
  
  function mouseover(el) {
    el.className = "raise";
  }
  
  function mouseout(el) {
    el.className = "buttons";
  }
  
  function mousedown(el) {
    el.className = "press";
  }
  
  function mouseup(el) {
    el.className = "raise";
  }

