// Imprimer
function imprimer(url){
	window.open(url, 'imprimer', 'height=500, width=800, toolbar=yes, menubar=yes, scrollbars=yes, resizable=no, location=no, directories=no, status=no');
}


// Popup
function popup(url, width, height, scroll){
	window.open('http://www.votre-enfant.com/'+url, 'popup', 'height='+height+', width='+width+', toolbar=no, menubar=no, scrollbars='+scroll+', resizable=no, location=no, directories=no, status=no');
}


// Mail
function mail(ou, id){
	popup('mail.php?ou='+ou+'&id='+id, 340, 240, 'no');
}


// Fonctions de mise en page
function format(f, n){
	var ta = document.getElementById('zoneTxt'+n);
	
	if(document.selection){
		var str = document.selection.createRange().text;
		ta.focus();
		var sel = document.selection.createRange();
		sel.text = '['+f+']'+str+'[/'+f+']';
		ta.focus();
	}
	else{
		if(ta.selectionEnd > ta.value.length) ta.selectionEnd = ta.value.length;
		var firstPos = ta.selectionStart;
		var secondPos = ta.selectionEnd+f.length+2;
		var contenuScrollTop = ta.scrollTop;
		
		ta.value=ta.value.slice(0,firstPos)+'['+f+']'+ta.value.slice(firstPos);
		ta.value=ta.value.slice(0,secondPos)+'[/'+f+']'+ta.value.slice(secondPos);
		
		ta.selectionStart = firstPos+f.length+2;
		ta.selectionEnd = secondPos;
		ta.focus();
		ta.scrollTop = contenuScrollTop;
	}
	return;
}

// Insérer un lien
function insLien(boo, url, n){
	if(!url) return false;
	var ta = document.getElementById('zoneTxt'+n);
	
	if(document.selection){
		var str = document.selection.createRange().text;
		ta.focus();
		var sel = document.selection.createRange();
		if(!url) return;
		sel.text = "[a"+boo+"|"+url+"]"+str+"[/a"+boo+"]";
		ta.focus();
	}
	else{
		if(ta.selectionEnd > ta.value.length) ta.selectionEnd = ta.value.length;
		var firstPos = ta.selectionStart;
		var secondPos = ta.selectionEnd+4+boo.length+url.length;
		var contenuScrollTop = ta.scrollTop;
		
		ta.value=ta.value.slice(0,firstPos)+'[a'+boo+'|'+url+']'+ta.value.slice(firstPos);
		ta.value=ta.value.slice(0,secondPos)+'[/a'+boo+']'+ta.value.slice(secondPos);
		
		ta.selectionStart = firstPos+4+boo.length+url.length;
		ta.selectionEnd = secondPos;
		ta.focus();
		ta.scrollTop = contenuScrollTop;
	}
	return;
}


// Insérer une mise à jour
function insMaj(date, maj1, n){
	var ta = document.getElementById('zoneTxt'+n);
	
	if(document.selection){
		var str = document.selection.createRange().text;
		ta.focus();
		var sel = document.selection.createRange();
		if(!maj1) return;
		sel.text = "[maj:"+date+"]"+maj1+"|"+str+"[/maj]";
		ta.focus();
	}
	else{
		if(ta.selectionEnd > ta.value.length) ta.selectionEnd = ta.value.length;
		var firstPos = ta.selectionStart;
		var secondPos = ta.selectionEnd+6+date.length+1+maj1.length;
		var contenuScrollTop = ta.scrollTop;
		
		ta.value=ta.value.slice(0,firstPos)+'[maj:'+date+']'+maj1+'|'+ta.value.slice(firstPos);
		ta.value=ta.value.slice(0,secondPos)+'[/maj]'+ta.value.slice(secondPos);
		
		ta.selectionStart = firstPos+6+date.length;
		ta.selectionEnd = secondPos;
		ta.focus();
		ta.scrollTop = contenuScrollTop;
	}
	return;
}



// Insérer une image
function insImg(url, n){
	if(!url) return false;
	var ta = document.getElementById('zoneTxt'+n);
	if(document.selection){
		ta.focus();
		var sel = document.selection.createRange();
		sel.text = '{'+url+'}';
		ta.focus();
	}
	else{
		var pos = ta.selectionStart;
		var contenuScrollTop = ta.scrollTop;
		
		ta.value=ta.value.slice(0,pos)+'{'+url+'}'+ta.value.slice(pos);
		
		ta.selectionStart = pos+2+url.length;
		ta.selectionEnd = pos+2+url.length;
		ta.focus();
		ta.scrollTop = contenuScrollTop;
	}
	return;
}

// Insérer un média
function insMedia(url, n){
	if(!url) return false;
	insLien('b', url, n);
}


// Choix de l'action dans l'administration
function envoyer(what, value){
	if(!value){
		alert("Vous devez sélectionner quelquechose!");
		return false;
	}
	document.formulaire.choix.value = what;
	document.formulaire.submit();
}
