// =========================================================
// ==                                                     ==
// ==                                                     ==
// ==                                                     ==
// =========================================================
// ==                                                     ==
// == CODE SOURCE VERSION : 0.0.1                         ==
// == CODE DEVELOPPER     : LERICQUE Jean-Yves            ==
// ==                                                     ==
// =========================================================

// =========================================================
// =========================================================
// =========================================================

// FONCTION D'AJOUT DANS LE TEXTAREA.
function insertion(repdeb, repfin) {
	var input = document.forms['frmutilisateur'].elements['valub'];
	input.focus();
	if(typeof document.selection != 'undefined') {
		var range = document.selection.createRange();
		var insText = range.text;
		range.text = repdeb + insText + repfin;
		range = document.selection.createRange();
		if (insText.length == 0) {
			range.move('character', -repfin.length);
		} else {
			range.moveStart('character', repdeb.length + insText.length + repfin.length);
		}
		range.select();
	} else if(typeof input.selectionStart != 'undefined') {
		var start = input.selectionStart;
		var end = input.selectionEnd;
		var insText = input.value.substring(start, end);
		input.value = input.value.substr(0, start) + repdeb + insText + repfin + input.value.substr(end);
		var pos;
		if (insText.length == 0) {
			pos = start + repdeb.length;
		} else {
			pos = start + repdeb.length + insText.length + repfin.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 à la position (0.." + input.value.length + "):", "0");
	} if(pos > input.value.length) {
		pos = input.value.length;
	}
		var insText = prompt("Veuillez entrer le texte à formater:");
		input.value = input.value.substr(0, pos) + repdeb + insText + repfin + input.value.substr(pos);
	}
}

// =========================================================
// =========================================================
// =========================================================

// ROUTINE D'AJOUT DES DIVERS SMILEYS.
	function addsmile(texta_,textb_) {
		insertion(texta_,textb_)
	}
	function addaddress() {
		var text1 = window.prompt("INDIQUEZ L'URL DU SITE","http://");
		var text2 = window.prompt("INDIQUEZ LE MOT CLEF","");
		if (text1!=null && text1!="") {
			if (text2==null) {
				text2 = '';
			}
			insertion("[url="+text1+"]"+text2,"[/url]")
		}
	}
	function viewer(text_) {
		if (document.getElementById('valub').value!='') {
			document.frmutilisateur.action="php/page_koakw2.php";
			document.frmutilisateur.target = "MyWindow";
			window.open("","MyWindow","height=600, width=800,scrollbars=yes,left=0,top=0,titlebar=no,toolbar=no,personalbar=no,menubar=no"); 
			document.frmutilisateur.submit();
			document.frmutilisateur.target = "";
			document.frmutilisateur.action = text_;
		}else{
			alert("VEUILLEZ ECRIRE UN MESSAGE AVANT LA PREVISUALISATION, MERCI");
		}
	}
	function champsok(){
		if (document.frmutilisateur.valua.value.length == 0 || document.frmutilisateur.valub.value.length == 0){
			alert("VEUILLEZ ECRIRE UN MESSAGE AVANT LA VALIDATION, MERCI");
			return false;
		}else{
			return true;
        	}
	}
