//------------------------------------------------------------------Vérification des messages------------------------------------------------------------------------

function Reponse (form)
  {
  with (form)
    {
     // Vérification du champ message
     if (message.value=="")  { alert ("Votre message ne contient aucune information !"); message.focus(); return false; }
     // Vérification du titre
     if (titre.value=="")  { alert ("Votre titre est vide !"); message.focus(); return false; }
    return true;
    }
  }

//----------------------------------------------------------------Vérification de champ form------------------------------------------------------------------------

function TestIdentite (form)
 {
  with (form)
   {
   if (RegExp("^[A-Za-z0-9_-]{3,}$").exec(login.value)==null) { alert("Votre login est invalide !"); login.focus(); return false; }
   if (RegExp("^[A-Za-z0-9]{3,}$").exec(password.value)==null) { alert("Votre mot de passe est invalide !"); password.focus(); return false; }
   }
 return true;
 }

function TestOubli (form)
 {
  with (form)
   {
   if (RegExp("^[A-Za-z0-9._-]+@[A-Za-z0-9.-]{2,}[.][A-Za-z]{2,4}$").exec(email.value)==null) { alert("Votre e-mail est invalide !"); email.focus(); return false; }
   }
 return true;
 }

function TestInscription (form)
 {
  with (form)
   {
   if (RegExp("^[A-Za-z0-9_-]{3,}$").exec(login.value)==null) { alert("Votre login est invalide !"); login.focus(); return false; }
   if (RegExp("^[A-Za-z0-9]{3,}$").exec(password.value)==null) { alert("Votre mot de passe est invalide !"); password.focus(); return false; }
   if (password.value != password2.value) { alert("Confirmez votre mot de passe !"); password2.focus(); return false; }
   if (RegExp("^[A-Za-z0-9._-]+@[A-Za-z0-9.-]{2,}[.][A-Za-z]{2,4}$").exec(email.value)==null) { alert("Votre e-mail est invalide !"); email.focus(); return false; }
   if (isNaN(age.value) || age.value<5 || age.value>85) { alert("Votre âge est invalide !"); age.focus(); return false; }
   if (RegExp("^[A-Za-z-]{3,}$").exec(prefere.value)==null) { alert("Le sport indiqué est invalide !"); prefere.focus(); return false; }
   if (RegExp("^[A-Za-z-]{3,}$").exec(prefere.value)==null) { alert("Le sport indiqué est invalide !"); prefere.focus(); return false; }
   if (!agreement.checked) { alert("Vous devez accepter les clauses de la charte !"); return false; }
   }
 return true;
 }

function TestModification (form)
 {
  with (form)
   {
   if (RegExp("^[A-Za-z0-9]{3,}$").exec(password.value)==null) { alert("Votre mot de passe est invalide !"); password.focus(); return false; }
   if (password.value != password2.value) { alert("Confirmez votre mot de passe !"); password2.focus(); return false; }
   if (RegExp("^[A-Za-z0-9._-]+@[A-Za-z0-9.-]{2,}[.][A-Za-z]{2,4}$").exec(email.value)==null) { alert("Votre e-mail est invalide !"); email.focus(); return false; }
   if (isNaN(age.value) || age.value<5 || age.value>85) { alert("Votre âge est invalide !"); age.focus(); return false; }
   if (prefere.value.length<4) { alert("Le sport indiqué est invalide !"); prefere.focus(); return false; }
   }
  form.submit();
 }


//--------------------------------------------------------------------Formulaire de recherche------------------------------------------------------------------------

function TestRecherche (form)
  {
  with (form)
    {
     // Vérification du champ message
     if (MotCherche.value.length<3)  { alert ("Votre recherche doit comporter au minimum 3 lettres !"); MotCherche.focus(); return false; }
    return true;
    }
  }


//----------------------------------------------------Ajoute le texte à la position du curseur dans le textarea--------------------------------------------------------

function addText (t, startTag, defaultText, endTag, replace)  //Honteusement pompée sur PHP-ASP.net :)
  {
  if (t.createTextRange)
   {
    t.focus(t.caretPos);
    t.caretPos = document.selection.createRange().duplicate();
    if (t.caretPos.text.length>0)
      {
      var sel = t.caretPos.text;
      var fin = '';
      while(sel.substring(sel.length-1, sel.length)==' ')
        {
        sel = sel.substring(0, sel.length-1)
        fin += ' ';
        }
      if (replace) t.caretPos.text = startTag + sel + endTag + fin;
      else t.caretPos.text = sel + fin + startTag + defaultText + endTag;
      }
    else  t.caretPos.text = startTag + defaultText + endTag;
    }
  else t.value += (startTag + defaultText + endTag);
  }

function addEmoticon(target, image)
  {
  var dotPosition = target.indexOf(".",0);
  var formName = target.substring(0,dotPosition);
  var areaName = target.substring(dotPosition+1,target.length);
  window.opener.document.forms[formName].elements[areaName].value += "[" + image + "]";
  }


//----------------------------------------------------Place les fenêtres ouvrantes au centre de l'écran---------------------------------------------------------------

function CreateCenterWin(page,largeur,hauteur,options)
  {
  var top=(screen.height-hauteur)/2; var left=(screen.width-largeur)/2;
  window.open(page,"","top=" + top + ",left=" + left + ",width=" + largeur + ",height=" + hauteur + "," + options);
  }

function CreateLeftWin(page,largeur,hauteur)
  {
  var top=(screen.height-hauteur)/2;
  window.open(page,"","top=" + top + ",left=10,width=" + largeur + ",height=" + hauteur + ", statusbar=no,scrollbars=no,resizable=no,menubar=no");
  }


//------------------------------------------------------------------Création du menu du forum----------------------------------------------------------------------

var MenuToolBar = new CreerMenuToolBar('#00008f', '#0000c5', 'black', '#0000ff', 'font-family: Sylfaen, Bookman Old Style, Garamond; font-size:13px; color:white;', 16, 16);

// Fonctions internes :

function CreerMenuToolBar(colFond, colClair, colOmbre, colCligno, style, hauteur, largeur)
  {
  this.nb=0; this.colFond=colFond; this.colClair=colClair; this.colOmbre=colOmbre; this.colCligno=colCligno;
  this.hauteur=hauteur; this.largeur=largeur; this.style=style; this.Indice=-1; this.Nbcligno=0; this.Add=AddMenuToolBar; this.Aff=AffMenuToolBar;
  }

function AddMenuToolBar(imgOff, imgOn, libelle, url)
  {
  var link=new Object(); link.imgOff=imgOff; link.imgOn=imgOn; link.libelle=libelle; link.url=url;
  this[this.nb]=link; this.nb++;
  }

function AffMenuToolBar()
  {

  if (document.getElementById || document.all)
    {
    var Z="<TABLE BORDER='0' CELLPADDING='2' CELLSPACING='0'><TR>";
    for (var i=0; i<this.nb; i++)
        {
        Z+="<TD onMouseOver='AffMenuToolBarOver(this," + i + ")' onMouseOut='AffMenuToolBarOut(this," + i + ")' onMouseDown='AffMenuToolBarDown(this," + i + ")' onClick='AffMenuToolBarClic(this," + i + ")' STYLE='border-style: solid; border-width:1px; border-color: " + this.colFond + ";" + this.style + "; cursor: pointer'><IMG NAME='MenuToolBarIMG" + i + "' SRC='" + this[i].imgOff + "' BORDER='0' WIDTH=" + this.largeur + " HEIGHT=" + this.hauteur + " ALIGN='top'>&nbsp;" + this[i].libelle + "</TD>";
        }
        Z+="</TR></TABLE>";
     }

  else
     {
     var Z="| &nbsp;";
     for (var i=0; i<this.nb; i++)
         {
         Z+="<A HREF='" + this[i].url + "' STYLE='" + this.style + "'><IMG NAME='MenuToolBarIMG" + i + "' SRC=\"" + this[i].imgOff + "\" BORDER='0' WIDTH=" + this.largeur + " HEIGHT=" + this.hauteur + " ALIGN='top'>&nbsp;" + this[i].libelle + "</A>&nbsp;|&nbsp;";
         }
      }

  document.write(Z);
}

function AffMenuToolBarOver(obj,ind)
  {
  obj.style.borderTopColor = MenuToolBar.colClair;		  obj.style.borderBottomColor = MenuToolBar.colOmbre;	
  obj.style.borderLeftColor = MenuToolBar.colClair;		  obj.style.borderRightColor = MenuToolBar.colOmbre;
  document.images['MenuToolBarIMG'+ind].src = MenuToolBar[ind].imgOn;
  }

function AffMenuToolBarOut(obj,ind)
  {
  obj.style.borderTopColor = MenuToolBar.colFond;	obj.style.borderBottomColor = MenuToolBar.colFond;
  obj.style.borderLeftColor = MenuToolBar.colFond;	obj.style.borderRightColor = MenuToolBar.colFond;	  document.images['MenuToolBarIMG'+ind].src = MenuToolBar[ind].imgOff;
  }

function AffMenuToolBarDown(obj,ind)
  {
  obj.style.borderTopColor = MenuToolBar.colOmbre;	obj.style.borderBottomColor=MenuToolBar.colClair;    obj.style.borderLeftColor=MenuToolBar.colOmbre;		obj.style.borderRightColor=MenuToolBar.colClair;
  }

function AffMenuToolBarClic(obj,ind)  { MenuToolBar.Indice=ind; MenuToolBar.obj=obj; MenuToolBar.Nbcligno=0; MenuToolBarCligno(); }

function MenuToolBarCligno()
  {
  MenuToolBar.Nbcligno++;
  if (Math.round(MenuToolBar.Nbcligno/2) != MenuToolBar.Nbcligno/2) MenuToolBar.obj.style.backgroundColor = MenuToolBar.colCligno;
  else MenuToolBar.obj.style.backgroundColor=MenuToolBar.colFond;
  if (MenuToolBar.Nbcligno < 8) setTimeout('MenuToolBarCligno()',50-5*MenuToolBar.Nbcligno);
  else { window.location = MenuToolBar[MenuToolBar.Indice].url; }
  }


//-----------------------------------------------------Fonction d'affichage des commentaires-----------------------------------------------------------------------

var Alt = new Object;
var posX=0, posY=0, xOffset=10, yOffset=10;

function Comment(Text)
  {

  Content="<TABLE BORDER=0 CELLSPACING=0 CELLPADDING="+Alt.NbPixel+"><TR BGCOLOR='"+Alt.ColContour+"'><TD><TABLE BORDER=0   CELLSPACING=0 CELLPADDING=2 BGCOLOR='"+Alt.BGColor+"'><TR><TD><SPAN STYLE='font-family: Arial; color:"+Alt.TextColor+"; font-size: 11px; font-weight:bold'>"+Text+"</FONT></TD></TR></TABLE></TD></TR></TABLE>&nbsp;";

  var finalPosX = posX-xOffset;
  if (finalPosX<0) finalPosX=0;

  if (document.layers)
    {
    document.layers["comment"].document.write(Content);
    document.layers["comment"].document.close();
    document.layers["comment"].top=posY+yOffset;
    document.layers["comment"].left = finalPosX;
    document.layers["comment"].visibility="show";
    }

  if (document.all)
    {
    comment.innerHTML = Content;
    document.all["comment"].style.top=posY+yOffset;
    document.all["comment"].style.left=finalPosX;
    document.all["comment"].style.visibility="visible";
    }

  else if (document.getElementById)
    {
    document.getElementById("comment").innerHTML = Content;
    document.getElementById("comment").style.top=posY+yOffset;
    document.getElementById("comment").style.left = finalPosX;
    document.getElementById("comment").style.visibility="visible";
    }

  }


function getMousePos()
  {
  if (document.all) { posX=event.x+document.body.scrollLeft; posY=event.y+document.body.scrollTop; }
  else { posX=e.pageX; posY=e.pageY; }
  }


function HideComment()
  {
  if (document.layers) document.layers["comment"].visibility="hide";
  if (document.all) document.all["comment"].style.visibility="hidden";
  else if (document.getElementById) {document.getElementById("comment").style.visibility="hidden";}
  }


function InitComment()
  {

  Alt.TextColor="White";  Alt.BGColor="#00ccff";  Alt.ColContour="Navy";  Alt.NbPixel=1;

  if (document.layers)
    {
    window.captureEvents(Event.MOUSEMOVE); window.onMouseMove=getMousePos;
    document.write("<LAYER NAME='comment' top=0 left=0 visibility='hide'></LAYER>");
    }

  if (document.all)
   {
   document.write("<DIV ID='comment' STYLE='position:absolute; top:0; left:0; visibility:hidden;'></DIV>");
   document.onmousemove=getMousePos;
   }

  else if (document.getElementById)
   {
   document.onmousemove=getMousePos;
   document.write("<DIV ID='comment' STYLE='position:absolute; top:0; left:0; visibility:hidden;'></DIV>");
   }

 }

InitComment();