function sendComment(event, form) {
    if (!event && window.event) event = window.event;
        // Если нажали сочетание ctrl+enter и есть форма отправки комментария, то отправляем запрос
        if (event.ctrlKey && ((event.keyCode == 13) || (event.keyCode == 0xA) || (event.keyCode == 0xD)) && form) {
            form.submit.click();
    }
}

function setB(text) {
    return '[b]'+text+'[/b]';
}

function setI(text) {
    return '[i]'+text+'[/i]';
}

function setU(text) {
    return '[u]'+text+'[/u]';
}

function replaceSelectedText(obj, cbFunc) {
    var only_insert = false;
    if ((arguments.length > 2) && (arguments[2] == true)) {
        only_insert = true;
    }
    if (typeof(obj) == 'string') {
        obj = document.getElementById(obj);
    }
    obj.focus();
 
    if (document.selection) {
        var s = document.selection.createRange(); 
        if (s.text) {
            eval("s.text="+cbFunc+"(s.text);");
            s.select();
            return true;
        }
    } else if (typeof(obj.selectionStart)=="number") {
        if ((obj.selectionStart!=obj.selectionEnd) || only_insert) {
            var start = obj.selectionStart;
            var end = obj.selectionEnd;
            
            eval("var rs = "+cbFunc+"(obj.value.substr(start,end-start));");
            obj.value = obj.value.substr(0,start)+rs+obj.value.substr(end);
            obj.setSelectionRange(end,end);
        } else {
            
        }
        return true;
    }
    
    return false;
}

function insertSelectedText(obj, text) {
    if (typeof(obj) == 'string') {
        obj = document.getElementById(obj);
    }
    obj.focus();
 
    if (document.selection) {
        var s = document.selection.createRange();
        
        s.text = text;
    } else if (typeof(obj.selectionStart)=="number") {
        var start = obj.selectionStart;
        var end = obj.selectionEnd;
        
        //eval("var rs = "+cbFunc+"(obj.value.substr(start,end-start));");
        obj.value = obj.value.substr(0,start)+text+obj.value.substr(end);
        obj.setSelectionRange(end,end);
        return true;
    }
    
    return false;
}

function putSmile(obj, smile) {
    insertSelectedText(obj, '[:'+smile+':]');
}

