// Vérifie la validité du champ par rapport à la regexp et sion :
//		- affiche le message d'erreur
//		- passe le focus au champ
//		- retourne false
function checkfield(champ,regexp,message) {
	var reg = new RegExp(regexp)
	if(reg.exec(champ.value)==null) {
		alert(message)
		champ.focus()
		return false
	}
	return true
}

// Ajoute le texte à la position du curseur
// dans le textearea. Merci Iubito ;)
function addtext(t,startTag,defaultText,endTag,replace) {
	if(t.createTextRange) {
		t.focus(t.caretPos);
		t.caretPos = document.selection.createRange().duplicate();
		if(t.caretPos.text.length>0) {
			//gère les espace de fin de sélection. Un double-click sélectionne le mot
			//+ un espace qu'on ne souhaite pas forcément...
			var sel = t.caretPos.text;
			var fin = '';
			while(sel.substring(sel.length-1, sel.length)==' ') {
				sel = sel.substring(0, sel.length-1)
				fin += ' ';
			}
			if(replace) t.caretPos.text = startTag + sel + endTag + fin;
			else t.caretPos.text = sel + fin + startTag + defaultText + endTag;
		} else {
			t.caretPos.text = startTag+defaultText+endTag;
		}
	}
	else t.value += startTag+defaultText+endTag;
}

