// JavaScript Document


function emoticon(motif,formulaire)
{
	document.getElementById(formulaire).value += '[' + motif + ']';
	document.getElementById(formulaire).focus();
}

function ajout_bbcode(bbcode,formulaire)
{
	if(bbcode == 'lien')
	{
		document.getElementById(formulaire).value += '[url=LIEN]TEXTE[/url]';
	}
	
	else if(bbcode == 'citation')
	{
		document.getElementById(formulaire).value += '[quote=PERSONNE_CITEE]CITATION[/quote]';
	}
}

function liste_bbcodes()
{
	document.getElementById('bouton_bbcodes').style.display = 'none';
	document.getElementById('liste_bbcodes').style.display = 'block';
}

function liste_smileys()
{
	document.getElementById('bouton_smileys').style.display = 'none';
	document.getElementById('liste_smileys').style.display = 'block';
}




// SCRIPT TOUT FAIT !


function insertTag(startTag, endTag, textareaId, tagType) {
        var field = document.getElementById(textareaId); 
        field.focus();
        
        if (window.ActiveXObject) { // C'est IE
                var textRange = document.selection.createRange();            
                var currentSelection = textRange.text;
                
                textRange.text = startTag + currentSelection + endTag;
                textRange.moveStart("character", -endTag.length - currentSelection.length);
                textRange.moveEnd("character", -endTag.length);
                textRange.select();     
        } else { // Ce n'est pas IE
                var startSelection   = field.value.substring(0, field.selectionStart);
                var currentSelection = field.value.substring(field.selectionStart, field.selectionEnd);
                var endSelection     = field.value.substring(field.selectionEnd);
                
                field.value = startSelection + startTag + currentSelection + endTag + endSelection;
                field.focus();
                field.setSelectionRange(startSelection.length + startTag.length, startSelection.length + startTag.length + currentSelection.length);
        }       
}


