function bbcode(bbdebut, bbfin){
	var input = document.form.tb_text;
	input.focus();
	/* pour IE (toujous un cas appart lui )*/
	if(typeof document.selection != 'undefined'){
		var range = document.selection.createRange().duplicate();
		var insText = range.text;
		range.text = bbdebut + insText + bbfin;
		if(insText.length == 0)
			range.move('character', -bbfin);
		else{
			range.moveStart('character', -(insText.length + bbfin.length));
			range.moveEnd('character', -bbfin.length);
			range.select();
		}
	}
	else if(typeof input.selectionStart != 'undefined'){
		var deb_sel = input.value.substring(0, input.selectionStart);
		var end_sel = input.value.substring(input.selectionEnd, input.value.length);
		var sel = input.value.substring(deb_sel.length, input.value.length-end_sel.length);
		input.value = deb_sel + bbdebut + sel + bbfin + end_sel;
		//Ajustement de la position du curseur
		posStart = deb_sel.length + bbdebut.length;
		posEnd = deb_sel.length + bbdebut.length + sel.length;
		if(sel.length != 0)
			input.setSelectionRange(posStart, posEnd);
		else
			input.setSelectionRange(posStart, posStart);
	}
	/* pour les autres navigateurs comme Netscape... */
	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) + bbdebut + insText + bbfin + input.value.substr(pos);
	}
}

function getDate(){
	var text = '';
	 
	var date = new Date();
	 
	var jour_actuel = date.getDay();
	var chaine_jour = Array('Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi');
	var jour_semaine = chaine_jour[jour_actuel];
	 
	/* Fonction ' JOUR ' */
	if ( date.getDate() <= 9 )
		var jour = '0'+date.getDate();
	else
		var jour = date.getDate();
	 
	/* Fonction ' MOIS ' */
	var mois_actuel = date.getMonth();
	var chaine_mois = Array('janvier', 'f&eacute;vrier', 'mars', 'avril', 'mai', 'juin', 'juillet', 'ao&ucirc;t', 'septembre', 'octobre', 'novembre', 'd&eacute;cembre');
	var mois = chaine_mois[mois_actuel];
	 
	/* Fonction ' HEURES ' */
	if ( date.getHours() <= 9 )
		var heure = '0'+date.getHours();
	else
		var heure = date.getHours();
	 
	/* Fonction ' MINUTES ' */
	if ( date.getMinutes() <= 9 )
		var minutes = '0'+date.getMinutes();
	else
		var minutes = date.getMinutes();
	 
	/* Fonction ' SECONDES ' */
	if ( date.getSeconds() <= 9 )
		var secondes = '0'+date.getSeconds();
	else
		var secondes = date.getSeconds();
	 
	// On prépare l'affichage de la date et de l'heure
	text +=  jour_semaine+' '+jour+' '+mois+' '+date.getFullYear();
	text += ' ';
	text +=  heure+':'+minutes;
 
	return text;
}
var domaine = "http://"+document.domain+"/";
var window_variable = "location=no,menubar=no,status=no,toolbar=no,directories=no,scrollbars=yes,width=800,height=700";

function new_article(type){
	window.open(domaine+'engine/editor.php?action=new&type='+type,'Administration',window_variable);
}

function edit_article(id){
	window.open(domaine+'engine/editor.php?action=edit&id='+id,'Administration',window_variable);
}

function copie_article(id){
	window.open(domaine+'engine/editor.php?action=copy&id='+id,'Administration',window_variable);
}

function delete_article(id){
	if(confirm('Voulez vous vraiment supprimer cet article ?'))
		window.open(domaine+'engine/editor.php?action=delete&id='+id,'Administration',window_variable);
}

function edit_menu(){
	window.open(domaine+'engine/admin/admin.php?page=menu','Administration du menu',window_variable);
}

function edit_users(){
	window.open(domaine+'engine/admin/admin.php?page=users','Administration du menu',window_variable);
}

function admin_articles(){
	window.open(domaine+'engine/admin/admin.php?page=articles','Administration du menu',window_variable);
}

function viewAllImage(dir,image){
	window.open(domaine+'engine/view_image.php?page=all&image='+image+'&dir='+dir,'viewImage',window_variable);
}

/*
//Affichage du formulaire d'ajout d'un commentaire
function viewaddcom(id) {
	id = "addcom"+id;
	if(document.getElementById(id).className=='hidden')
		document.getElementById(id).className='visible';
	else
		document.getElementById(id).className='hidden';
}
*/

// Affichage des commentaires
function viewcomment(id) {
	id = "comment"+id;
	if(document.getElementById(id).className=='hidden')
		document.getElementById(id).className='visible';
	else
		document.getElementById(id).className='hidden';
}

//Teste les formulaires de saisie pour les commentaires sur les articles et le livre d'or
function testform(lenom,comment,antispam) {
	if(lenom.value=="") {
		alert("Vous devez inscrire un nom");
		lenom.focus();
	    return false
    }
    if(comment.value=="") {
		alert("Vous devez inscrire un commentaire");
	    comment.focus();
		return false
    }
    if(antispam.value=="") {
		alert("Vous devez inscrire le code antispam");
	    antispam.focus();
		return false
    }
    return true
}


function viewdivimage(element,multi){
	var div = document.getElementById("divimage");
	var image = document.getElementById("maxi_image_article");

	image.setAttribute("src",element.src);
	var left = calculateOffset(element,"offsetLeft");
	var top = calculateOffset(element,"offsetTop");

	if(document.all){//ie
		div.style.top = image.style.top = top;
		div.style.left = image.style.left = left;
		div.style.width = image.style.width = element.width * multi;
		div.style.height = image.style.height = element.height * multi;
		div.style.visibility = image.style.visibility = "visible";
		div.onmouseout = viewdivnoimage;
		div.onclick = "window.open('"+element.parentNode.href+"')";
	}
	else{//firefox
		var width = element.width * multi;
		var height = element.height * multi;
		var style= "top:"+top+"px; left:"+left+"px; width:"+width+"px; height:"+height+"px; visibility:visible;";
		div.setAttribute("style",style);
		image.setAttribute("style",style);
		div.setAttribute("onmouseout","viewdivnoimage();");
		div.setAttribute("onclick","window.open('"+element.parentNode.href+"')");
	}
}

function calculateOffset(r,attr){
	var kb=0;
	while(r){
		kb+=r[attr];
		r=r.offsetParent
	}
	return kb
}

function viewdivnoimage(){
	var div = document.getElementById("divimage");
	var image = document.getElementById("maxi_image_article");
	if(document.all){//ie
		div.style.visibility = image.style.visibility = "hidden";
	}
	else{//firefox
		var style= "visibility:hidden;";
		div.setAttribute("style",style);
		image.setAttribute("style",style);
	}
}

//window.onload = displayPics;

function displayPics()
{
    var photo = document.getElementById('galerie');
	photo.setAttribute("onmouseover",viewimage(photo.src,photo.width,photo.height));
}

/*
	
	
	// On récupère dans une variable tous les liens contenu dans galerie_mini
    var big_photo = document.getElementById('big_pict');
    // Ici c'est l'élément ayant pour id big_pict qui est récupéré, c'est notre photo en taille normale

    var titre_photo = document.getElementById('photo').getElementsByTagName('dt')[0];
    // Et enfin le titre de la photo de taille normale

    // Une boucle parcourant l'ensemble des liens contenu dans galerie_mini
    for (var i = 0; i < liens.length; ++i) {
        // Au clique sur ces liens
        liens[i].onclick = function() {
            big_photo.src = this.href; // On change l'attribut src de l'image en le remplaçant par la valeur du lien
            big_photo.alt = this.title; // On change son titre
            titre_photo.firstChild.nodeValue = this.title; // On change le texte de titre de la photo
            return false; // Et pour finir on inhibe l'action réelle du lien
        };
    }
}
window.onload = displayPics;
// Il ne reste plus qu'à appeler notre fonction au chargement de la page

*/
