﻿
var max_chars = 1000;
var el_msg = document.getElementById("txtMessaggio");

function _controllaLunghezza() 
{
    if (max_chars != 0) r = "\nIl massimo numero di caratteri e\' " + max_chars + "."; else r = "";
    alert("Il tuo messaggio contiene " + el_msg.value.length + " caratteri." + r);
}

function _aggiungiEmoticon(icona) 
{
    if (document.selection) {
        // IE
        el_msg.focus();
        sel      = document.selection.createRange();
        sel.text = icona;
    }
    else if (el_msg.selectionStart || el_msg.selectionStart == '0') {
        // FF
        var startPos = el_msg.selectionStart;
        var endPos   = el_msg.selectionEnd;
        el_msg.value = el_msg.value.substring(0, startPos) + icona + el_msg.value.substring(endPos, el_msg.value.length);
        el_msg.focus();
    } else {
        // altri
        el_msg.value += icona;
    }
}
