//smileys internes
function TableauSmiley() {
    var listsml = new Array();    
    listsml[listsml.length] = new Array(":)","http://storage.canalblog.com/27/81/68197/10073370.gif");
    listsml[listsml.length] = new Array(":-)","http://storage.canalblog.com/27/81/68197/10073370.gif");
    listsml[listsml.length] = new Array(":(","http://storage.canalblog.com/71/18/68197/10073312.gif");
    listsml[listsml.length] = new Array(":-(","http://storage.canalblog.com/71/18/68197/10073312.gif");
    listsml[listsml.length] = new Array(":s","http://storage.canalblog.com/53/76/68197/10073186.gif");
    listsml[listsml.length] = new Array(":D","http://storage.canalblog.com/51/49/68197/10073229.gif");
    listsml[listsml.length] = new Array(":-D","http://storage.canalblog.com/51/49/68197/10073229.gif");
    listsml[listsml.length] = new Array(";)","http://storage.canalblog.com/97/31/68197/10073422.gif");
    listsml[listsml.length] = new Array(";-)","http://storage.canalblog.com/97/31/68197/10073422.gif");
    listsml[listsml.length] = new Array(":-/ ","http://storage.canalblog.com/22/51/68197/10073079.gif");
    listsml[listsml.length] = new Array(":/ ","http://storage.canalblog.com/22/51/68197/10073079.gif");
 return listsml;
}

//attributs de style pour le smiley
function StyleEmoticon() {
    var att = 'border="0" style="vertical-align:middle; padding:0px 5px 5px 0px "';
    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);
    }
}
