// attributs de style pour le smiley
function StyleEmoticon() {
    var att = 'border="0" style="vertical-align:middle"';
    att = (att != '') ? (' ' + att) : '';
    return att;
}

 // création des icones
function ListeEmoticon() {
    var textarea = 'document.frmComment.commentBody';
    var list = TableauGif();
    var att = StyleEmoticon();
    for (var i = 0; i < list.length; i++) {
        window.document.write('<a href="javascript:;" onClick="InsererEmoticon(' + textarea + ', \'' + list[i][0] + '\');"><img src="' + list[i][1] + '"' + att + ' alt="' + list[i][0] + '" /></a>');
    }
}

function InsererEmoticon(obj, tag) {
    var item = '[' + tag + ']';
    if (document.selection) {
        obj.focus();
        sel = document.selection.createRange();
        sel.text = item;
    } else if (obj.selectionStart || obj.selectionStart == '0') {
        var startPos = obj.selectionStart;
        var endPos = obj.selectionEnd;
        obj.value = obj.value.substring(0, startPos) + item + obj.value.substring(endPos, obj.value.length);
    } else {
        obj.value += item;
    }
}

function RemplacerTagEmoticon(ObjetComs) {
    var list = TableauGif();
    var att = StyleEmoticon();
    for (var i = 0; i < list.length; i++) {
        ObjetComs = ObjetComs.split('[' + list[i][0] + ']').join('<img src="' + list[i][1] + '"' + att + ' alt="' + list[i][0] + '" />');
    }

    list = TableauSmiley();
    for (var i = 0; i < list.length; i++) {
        ObjetComs = ObjetComs.split(list[i][0]).join('<img src="' + list[i][1] + '"' + att + '" />');
    }

    return ObjetComs;
}

function SwapCodeEmoticon(namediv,nameclass) {

    var objComArea;
    var classComArea;
    var objComBody = new Array();
    if (namediv != '') {
        objComArea = document.getElementById(namediv);
        if (!objComArea || !objComArea.innerHTML) return;
        classComArea = objComArea.getElementsByTagName("div");
    } else {
        classComArea = document.getElementsByTagName("*");
    }
    for (var i = 0; i < classComArea.length; i++) {
        if (classComArea[i].className == nameclass) objComBody[objComBody.length] = classComArea[i];
    }
    for (var i = 0; i < objComBody.length; i++) {
        objComBody[i].innerHTML = RemplacerTagEmoticon(objComBody[i].innerHTML);
    }
}

// adresses des smileys
function TableauSmiley() {
    var listsml = new Array();    
    listsml[listsml.length] = new Array(":)","http://storage.canalblog.com/86/48/99935/29437566.png");
    listsml[listsml.length] = new Array(";)","http://storage.canalblog.com/22/87/99935/29437484.png");
    listsml[listsml.length] = new Array(":(","http://storage.canalblog.com/07/01/99935/29437543.png");
    listsml[listsml.length] = new Array(":o","http://storage.canalblog.com/25/62/99935/29437572.png");
    listsml[listsml.length] = new Array(":p","http://storage.canalblog.com/66/63/99935/29437580.png");
    listsml[listsml.length] = new Array(":D","http://storage.canalblog.com/44/22/99935/29437520.png");
return listsml;
}

function TableauGif() {
    var list = new Array();    
    list[list.length] = new Array("sourire","http://storage.canalblog.com/86/48/99935/29437566.png");
    list[list.length] = new Array("mort_de_rire","http://storage.canalblog.com/44/22/99935/29437520.png");
    list[list.length] = new Array("pleure_de_rire","http://storage.canalblog.com/66/47/99935/29437551.png");
    list[list.length] = new Array("rigolo","http://storage.canalblog.com/44/41/99935/29437564.png");
    list[list.length] = new Array("lunettes","http://storage.canalblog.com/84/04/99935/29437512.png");
    list[list.length] = new Array("clin_d_oeil","http://storage.canalblog.com/22/87/99935/29437484.png");
    list[list.length] = new Array("tire_la_langue","http://storage.canalblog.com/66/63/99935/29437580.png");
    list[list.length] = new Array("diable","http://storage.canalblog.com/10/30/99935/29437498.png");
    list[list.length] = new Array("mouai","http://storage.canalblog.com/74/71/99935/29437531.png");
    list[list.length] = new Array("bof","http://storage.canalblog.com/38/12/99935/29437468.png");
    list[list.length] = new Array("surprit","http://storage.canalblog.com/25/62/99935/29437572.png");
    list[list.length] = new Array("pas_content","http://storage.canalblog.com/07/01/99935/29437543.png");
    list[list.length] = new Array("triste","http://storage.canalblog.com/89/63/99935/29437590.png");
    list[list.length] = new Array("en_colere","http://storage.canalblog.com/70/68/99935/29437506.png");
return list;
}
