﻿/*
written by chris wetherell
http://www.massless.org
chris [THE AT SIGN] massless.org
	
warning: it only works for IE4+/Win and Moz1.1+
feel free to take it for your site
if there are any problems, let chris know.
*/


var thisForm;    /* make sure to change the onload handler of the
	 <body> tag to the form you're using!... */

/* YOU CAN ERASE getMozSelection(): 
It's here for debug purposes only */
function getMozSelection(txtarea) {
    var selLength = txtarea.textLength;
    var selStart = txtarea.selectionStart;
    var selEnd = txtarea.selectionEnd;
    if (selEnd == 1 || selEnd == 2) selEnd = selLength;
    return (txtarea.value).substring(selStart, selEnd);
}

function mozWrap(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;
}

function IEWrap(lft, rgt) {
    strSelection = document.selection.createRange().text;
    if (strSelection != "") {
        document.selection.createRange().text = lft + strSelection + rgt;
    }
}

function wrapSelection(txtarea, lft, rgt) {
    if (document.all) { IEWrap(lft, rgt); }
    else if (document.getElementById) { mozWrap(txtarea, lft, rgt); }
}
function wrapSelectionWithLink(txtarea) {
    var my_link = prompt("Enter URL:", "http://");
    if (my_link != null) {
        lft = "<a href=\"" + my_link + "\">";
        rgt = "</a>";
        wrapSelection(txtarea, lft, rgt);
    }
    return;
}

document.onkeypress = function(e) {
    if (document.all) {
        key = event.keyCode; txtarea = thisForm.T;
        if (key == 1) wrapSelectionWithLink(txtarea);
        if (key == 2) wrapSelection(txtarea, '<b>', '</b>');
        if (key == 20) wrapSelection(txtarea, '<i>', '</i>');
    }
    else if (document.getElementById) {
        ctrl = e.ctrlKey; shft = e.shiftKey; chr = e.charCode;
        if (ctrl) if (shft) if (chr == 65) wrapSelectionWithLink(thisForm.T);
        if (ctrl) if (shft) if (chr == 66) wrapSelection(thisForm.T, '<b>', '</b>');
        if (ctrl) if (shft) if (chr == 84) wrapSelection(thisForm.T, '<i>', '</i>');
    }
    return true;
}
/* end chris w. script */



/*
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";
}
/* end meg script */
	