var FavOn	=	new Image();
var FavOff	=	new Image();
FavOn.src	=	IMG+"/forum/fav.png";
FavOff.src	=	IMG+"/forum/fav-fade.png";

var NotOn	=	new Image();
var NotOff	=	new Image();
NotOn.src	=	IMG+"/icones/notification.gif";
NotOff.src	=	IMG+"/icones/notification0.gif";

var NotCOn	=	new Image();
var NotCOff	=	new Image();
NotCOn.src	=	IMG+"/icones/alerte_forum.png";
NotCOff.src	=	IMG+"/icones/no_alerte_forum.png";

var NotAOn	=	new Image();
var NotAOff	=	new Image();
NotAOn.src	=	IMG+"/icones/not_auteur.png";
NotAOff.src	=	IMG+"/icones/no_not_auteur.png";

var imgbas=new Image();
var imgdroite=new Image();
var max_cat=10;

imgbas.src=IMG+"/icones/fleche_bleu_bas.gif";
imgdroite.src=IMG+"/icones/fleche_bleu_droite.gif";

function ChangeEtatCategorie(id)
{
	oldetat=LireCookie("FCAT["+id+"]");
	newetat=oldetat==1 ? 0:1;

	document.images["IMGCAT"+id].src=newetat==1 ? imgdroite.src:imgbas.src;
	for(i=0;i<=max_cat;i++)
	{
		if(!document.getElementById(id+"niveau"+i))break;
		document.getElementById(id+"niveau"+i).style.display=newetat==1 ? "none":(document.all && !window.opera)? "block":"table-row";
	}
	var date=new Date;
	date.setFullYear(date.getFullYear()+1);

	EcrireCookie('FCAT['+id+']', newetat, date, '/','.le-forum-animalier.com')
}

function TableauMasqueLigne(id)
{
	if(document.getElementById(id))
	{
		document.getElementById(id).style.display=document.getElementById(id).style.display=="none" ? ((document.all && !window.opera) ? "block":"table-row"):"none";
	}
}

function add_smi(code)
{
	document.repondre.message.value+=' '+code+' ';
}

function Forum_Citer(id,modeC,reference)
{
	modeC=modeC=="R" ? "R":"Q";

	if(id!="")
	{
		if(!isNaN(id))
		{
			document.repondre.message.value+=(document.repondre.message.value=="" ? "":"\n")+"[CITER]"+modeC+id+"."+reference+"[/CITER]\n";
			document.repondre.message.focus();
		}
	}
}

function RechercheMembre(nom)
{
	erreur="";
	nom=nom.toLowerCase();
	if(nom=="")return;
	if(nom.length<3 || nom.length>12)erreur="L'identifiant doit avoir entre 3 et 12 caractères.\n";
	if(nom.indexOf("\"")!=-1
	|| nom.indexOf("\\")!=-1
	|| nom.indexOf("'")!=-1
	|| nom.indexOf("#")!=-1
	|| nom.indexOf("&")!=-1
	|| nom.indexOf(" ")!=-1
	|| nom.indexOf("/")!=-1
	)erreur+="L'identifiant ne peut avoir de caractère spéciaux.\n";

	if(erreur)
	{
		alert(erreur)
		return;
	}
	else
	{
		window.location.href="/forum/membre/"+nom+".html";
	}
}

function RechercheDate(nom)
{
	erreur="";
	if(!is_date)erreur="Vous devez entrer une date valide au format JJ-MM-AAAA.\n";

	if(erreur)
	{
		alert(erreur)
		return;
	}
	else
	{
		window.location.href="/forum/date/"+nom+".html";
	}
}

function rep(formulaire,modedirect)
{
	if(document.repondre.validation.value=='')
	{
		if(document.repondre.acces_public.value=='1')
		{
			if(document.repondre.votrenom.value=="" || document.repondre.votreemail.value=="")
			{
				alert("Vous devez indiquer votre nom et votre adresse email.")
				return;
			}
			if(!is_mail(document.repondre.votreemail.value))
			{
				alert("Vous devez indiquer une adresse email valide.")
				return;
			}
			if(document.repondre.votrenom.value.indexOf("\"")!=-1 || document.repondre.votrenom.value.indexOf("\\")!=-1 || document.repondre.votrenom.value.indexOf(":")!=-1)
			{
				alert("Vous ne devez pas utiliser les caractères \", : et \\ dans le nom.")
				return;
			}
		}
		if(document.repondre.message.value=='')
		{
			alert("Vous devez inscrire votre reponse.")
			return;
		}
		nbsmil=document.repondre.message.value.split(':')
		nbsmil=nbsmil.length
		if(nbsmil>50)
		{
			alert("Vous avez mis trop de smileys dans le message.")
			return;
		}
		if(document.repondre.message.length>10000)
		{
			document.repondre.message.value=document.repondre.message.value.substr(0,10000);
			alert("Le message est trop long.")
			return;
		}
		document.repondre.validation.value='ok';
		document.repondre.submit();
		if(modedirect==1)
		{
			document.repondre.validation.value='';
			document.repondre.message.value='';
		}
	}
}

/* http://actuel.fr.selfhtml.org/articles/javascript/bbcode/index.htm#exemple */

function insertion(repdeb, repfin, champ) {
  var input = champ;
  input.focus();
  /* pour l'Explorer Internet */
  if(typeof document.selection != 'undefined') {
    /* Insertion du code de formatage */
    var range = document.selection.createRange();
    var insText = range.text;
    range.text = repdeb + insText + repfin;
    /* Ajustement de la position du curseur */
    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();
  }
  /* pour navigateurs plus récents basés sur Gecko*/
  else if(typeof input.selectionStart != 'undefined')
  {
    /* Insertion du code de formatage */
    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);
    /* Ajustement de la position du curseur */
    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;
  }
  /* pour les autres navigateurs */
  else
  {
	alert("Impossible avec ce navigateur.")
  }
}

function Navigation(id)
{
	if(document.navigation && id!="")
	{
		document.navigation.SelectionPage.value=id;
		document.navigation.submit();
	}
}
