
var smiles = new Array();
smiles['03'] = '[:)]';
smiles['05'] = '[:D]';
smiles['07'] = '[;)]';
smiles['09'] = '[:O]';

smiles['13'] = '[8)]';
smiles['15'] = '[>:F]';
smiles['17'] = '[Q]';
smiles['19'] = '[<:|]';

smiles['21'] = '[:(]';
smiles['58'] = '[:~(]';
smiles['33'] = '[:|]';
smiles['36'] = '[>:C]';

smiles['41'] = '[:/]';
smiles['59'] = '[0:)]';
smiles['56'] = '[L]';
smiles['57'] = '[Ł]';

function smile(code){
	var textarea = document.forms.newcomment.comment;
	var pos = js_getCursorPosition(textarea);
	var smile = smiles[code];
	var value = textarea.value;
	textarea.value = value.substring(0, pos.start)+smile+value.substring(pos.end, value.length);
}

function js_CursorPos(start, end) {
    this.start = start;
    this.end = end;
}

function js_getCursorPosition(textArea) {
    var start = 0;
    var end = 0;
    if (document.selection) { // IE.
        textArea.focus();
        var sel1 = document.selection.createRange();
        var sel2 = sel1.duplicate();
        sel2.moveToElementText(textArea);
        var selText = sel1.text;
        sel1.text = "01";
        var index = sel2.text.indexOf("01");
        start = js_countTextAreaChars((index == -1) ? sel2.text : sel2.text.substring(0, index));
        end = js_countTextAreaChars(selText) + start;
        sel1.moveStart('character', -2);
        sel1.text = selText;
    } else if (textArea.selectionStart || (textArea.selectionStart == "0")) { // Mozilla/Netscape.
        start = textArea.selectionStart;
        end = textArea.selectionEnd;
    }
    return new js_CursorPos(start, end);
}

function js_countTextAreaChars(text) {
    var n = 0;
    for (var i = 0; i < text.length; i++) {
      //  if (/* text.charAt(i) != '\r'  &&*/ text.charAt(i) != '\n') {
            n++;
     //   }
    }
    return n;
}
