/* ****************** AJAX FONCTION ***************************** */



function GetLastTopic(Forum)
{
  try {
    var xmlHttp = getNewXMLHTTP();
    var Fichier="/Forums/ajax_lasttopic.php?IdForum="+Forum;
    document.getElementById("LastTopicParticipate").innerHTML=GetInfo(xmlHttp,Fichier);
  } catch(e) {
    alert("Désolé votre navigateur ne supporte pas cette technologie, veuillez contacter le webmaster");
  }
}

/***************** Recherche *****************/

function MsgErreur(Ligne1,Ligne2) {
	if (Ligne2==null) {
	 Ligne2="";}
	var nb=Math.max(Ligne1.length,Ligne2.length);
	var msg="Erreur !";
	var space="";
	for (var i=0;i<=(nb-msg.length)/2+1;i++)	{space+=" "}
	alert(space+" "+msg+"\n"+Ligne1+"\n"+Ligne2);
}

var nb=0;

function GoForumSearch(f) 
{
  var ok=1;
  if (nb>0) {MsgErreur('Recherche en cours. Merci de patienter...'); ok=0;}
  if ((ok==1)&&(f.motclefs.value=='')) {ok=0; MsgErreur('Saisissez un mot clé'); f.motclefs.focus();}
  if (ok==1) {
    nb++;
    f.submit()
  }
}

function AddUrl(f) {
  TAinsert(f,"[A]","[/A]");
}

function AddBold(f) {
  TAinsert(f,"[B]","[/B]");
}

function countInstances(f,open,closed) {
  var opening = f.body.value.split(open);
  var closing = f.body.value.split(closed);
  return opening.length + closing.length - 2;
}

function TAinsert(f,text1,text2) {
  var ta = f.body;
  if (document.selection) {
    var str = document.selection.createRange().text;
    ta.focus();
    var sel = document.selection.createRange();
    if (text2!="") {
      if (str=="") {
        var instances = countInstances(f,text1,text2);
        if (instances%2 != 0) sel.text = sel.text + text2;
        else sel.text = sel.text + text1;
      } else sel.text = text1 + sel.text + text2;
    } else sel.text = sel.text + text1;
  } else if (ta.selectionStart || ta.selectionStart == 0) {
  if (ta.selectionEnd > ta.value.length) ta.selectionEnd = ta.value.length;
    var firstPos = ta.selectionStart;
    var secondPos = ta.selectionEnd+text1.length;
    var contenuScrollTop = ta.scrollTop;

    ta.value=ta.value.slice(0,firstPos)+text1+ta.value.slice(firstPos);
    ta.value=ta.value.slice(0,secondPos)+text2+ta.value.slice(secondPos);

    ta.selectionStart = firstPos+text1.length;
    ta.selectionEnd = secondPos;
    ta.focus();
    ta.scrollTop = contenuScrollTop;
  } else { // Opera
      var sel = document.hop.contenu;
      var instances = countInstances(text1,text2);
      if (instances%2 != 0 && text2 != "") sel.value = sel.value + text2;
      else sel.value = sel.value + text1;
  }
}



function AddSmiley(f,smiley) {
  TAinsert(f,' '+smiley+' ',"");
}

function CheckPost(f) {
	var ok=1
	if ((ok==1)&&(f.subject.value=="")) {MsgErreur("Le sujet du message est obligatoire !"); f.subject.focus(); ok=0;}
	if ((ok==1)&&(f.body.value=="")) {MsgErreur("Le corps du message est obligatoire !"); f.body.focus(); ok=0;}
	if (ok==1) {f.submit();}
}

function CheckReponse(f) {
	var ok=1
	if ((ok==1)&&(f.body.value=="")) {MsgErreur("Le corps du message est obligatoire !"); f.body.focus(); ok=0;}
	if (ok==1) {f.submit();}
}

