function insert(textAreaId, insertText) 
{
	text = document.getElementById(textAreaId);
	selstart = text.selectionStart;
	
	text.value = text.value.slice(0, selstart) + insertText +
			text.value.slice(text.selectionEnd);
	text.selectionStart = selstart + insertText.length;
	text.selectionEnd = text.selectionStart;
    text.focus();
}


function append(textAreaId, insertText) 
{
	text = document.getElementById(textAreaId);
	text.value = text.value + insertText;
}

function add_remove_tag(tags, tag)
{
    var tt = tags.split(" ");
    var remove = false;
    tags = "";
    for (i in tt)
    {
        if (tt[i] != "")
        {
            if (tt[i] == tag)
                remove = true;
            else
                tags += tt[i] + " ";
        }
    }
    return tags + (remove ? "" : tag)
}

function resize_textarea(textAreaId, rows) 
{
    var text = document.getElementById(textAreaId);
	if (!text || text.rows == undefined) 
        return;
    text.rows = rows;
}

function get_select_value(selectId)
{
    var select = document.getElementById(selectId);
	return select.options[select.selectedIndex].value;
}

function append_tag(textAreaId, tag) 
{
	text = document.getElementById(textAreaId);
	text.value = add_remove_tag(text.value, tag)
}

function ie_switch_wrap(textAreaId)
{
    area = document.getElementById(textAreaId);
    if (area.wrap == "off")
        area.wrap = "soft";
    else
        area.wrap = "off";
}

function submit_listener(e)
{
    if (!document.getElementById) 
        return;
    
    if (window.event) 
        e = window.event;
    
    if ((e.keyCode == 13 || e.keyCode == 10) && e.ctrlKey) 
    {
        var target = e.target || e.srcElement;
        
        if (target && target.form)
            target.form.submit.click();
            
        if (event.stopPropagation) 
            event.stopPropagation();
    }
}

if (document.addEventListener)
    document.addEventListener('keyup', submit_listener, false);
else if (document.attachEvent)
    document.attachEvent('onkeydown', submit_listener);
