function myCode(mydebut, myfin)
{
	var input = window.document.formulaire.message;
	input.focus();
	if(typeof document.selection != 'undefined')
	{
		var range = document.selection.createRange();
		var insText = range.text;
		range.text = mydebut + insText + myfin;
		range = document.selection.createRange();
		if (insText.length == 0)
		{
			range.move('character', -myfin.length);
		}
		else
		{
			range.moveStart('character', mydebut.length + insText.length + myfin.length);
		}
		range.select();
	}
	else if(typeof input.selectionStart != 'undefined')
	{
		var start = input.selectionStart;
		var end = input.selectionEnd;
		if (mydebut=='[lien]') { lien=prompt('Adresse du lien :',''); mydebut='[lien='+lien+']'}
		var insText = input.value.substring(start, end);
		input.value = input.value.substr(0, start) + mydebut + insText + myfin + input.value.substr(end);
		var pos;
		if (insText.length == 0)
		{
			pos = start + mydebut.length;
		}
		else
		{
			pos = start + mydebut.length + insText.length + myfin.length;
		}
		input.selectionStart = pos;
		input.selectionEnd = pos;
	}
	else
	{
		var pos;
		var re = new RegExp('^[0-9]{0,3}$');
		while(!re.test(pos))
		{
			pos = prompt("insertion (0.." + input.value.length + "):", "0");
		}
		if(pos > input.value.length)
		{
			pos = input.value.length;
		}
		var insText = prompt("Veuillez taper le texte");
		input.value = input.value.substr(0, pos) + mydebut + insText + myfin + input.value.substr(pos);
	}
}

function plusChap() {
	document.formulaire.nouveau.value=parseInt(document.formulaire.nouveau.value)+1;
	var val = document.formulaire.nouveau.value;
	var text = '';
	for (var i=1;i<val;i++) {
		text+='<label>Chapitre '+i+' : </label><input type="text" name="chap'+i+'" id="chap'+i+'" value="'+document.getElementById('chap'+i).value+'" /><br />';
	}
	text+='<label>Chapitre '+val+' : </label><input type="text" name="chap'+val+'" id="chap'+val+'" /><br />'
	window.document.getElementById('chapitre').innerHTML = text;
}

function supprChap() {
	var val = document.formulaire.nouveau.value;
	if (val>1) {
		document.formulaire.nouveau.value=parseInt(document.formulaire.nouveau.value)-1;
		var text = '';
		for (var i=1;i<val;i++) {
			text+='<label>Chapitre '+i+' : </label><input type="text" name="chap'+i+'" id="chap'+i+'" value="'+document.getElementById('chap'+i).value+'" /><br />';
		}
	}
	else {
		alert('Il faut au moins un chapitre');
		var text = '<label>Chapitre 1 : </label><input type="text" name="chap1" id="chap1" /><br />';
	}
	window.document.getElementById('chapitre').innerHTML = text;
}

function editAddChap() {
	document.formulaire.nbChap.value=parseInt(document.formulaire.nbChap.value)+1;
	var val = document.formulaire.nbChap.value;
	var text = window.document.getElementById('chapitre').innerHTML;
	text+='<label>Chapitre '+val+' : </label><input type="text" name="chap'+val+'" id="chap'+val+'" /><br /><br />'
	window.document.getElementById('chapitre').innerHTML = text;
	
	window.document.getElementById('ajouterChap').innerHTML = '  (pour éditer ou supprimer, éditez le grand tutoriel)';
}