/***********************************************************************
 *   Fichier : Scripts.js                                              *
 *   Script pour les outils                                            *
 ***********************************************************************/

/***********************************************************************
 * Suuprime les espaces en début de chaîne                             *
 *---------------------------------------------------------------------*
 * pSource : Chaîne d'origine                                          *
 ***********************************************************************/

function mvTrim(pSource)
{
var i, wTarget, wLength, wCar, wSpace;

wTarget = "";
wLength = pSource.length;
wSpace = true;
for (i = 0 ; i < wLength ; i++)
  {
  wCar = pSource.substr(i, 1);
  if (wCar == " " && wSpace)
    wCar = "";
    else
      wSpace = false;
  wTarget += wCar;
  }
return wTarget;
}

/***********************************************************************
 * Change les "+" en "•", etc...                                       *
 *---------------------------------------------------------------------*
 * pSource : Chaîne d'origine                                          *
 ***********************************************************************/

function mvChangePlus(pSource)
{
var i, wString, wLength, wCar;

wString = "";
wLength = pSource.length;
for (i = 0 ; i < wLength ; i++)
  {
  wCar = pSource.substr(i, 1);
  if (wCar == "+")
    wCar = "`p";
    else if (wCar == "&")
      wCar = "`é";
      else if (wCar == "\n")
        wCar = "`n";
        else if (wCar == "\r")
          wCar = "";
          else if (wCar == "'")
            wCar = "''";
  wString += wCar;
  }
return wString;
}

/***********************************************************************
 * Envoi de mail                                                       *
 ***********************************************************************/

function mvSend()
{
var wDestinataire, wMessage, wString;

wDestinataire = "";
wDestinataire += ((document.FrmMail.ChkWebmaster.checked) ? "1" : "0");
wDestinataire += ((document.FrmMail.ChkPresident.checked) ? "1" : "0");
wDestinataire += ((document.FrmMail.ChkTresorier.checked) ? "1" : "0");
wDestinataire += ((document.FrmMail.ChkSecretaire.checked) ? "1" : "0");
wDestinataire += ((document.FrmMail.ChkMecanicien.checked) ? "1" : "0");
if (wDestinataire == "00000")
  {
  alert("Vous n'avez pas mentionné le(s) destinataire(s) !");
  return;
  }
wMessage = mvTrim(document.FrmMail.TxtMessage.value);
if (wMessage == "")
  {
  alert("Vous n'avez pas écrit votre message !");
  return;
  }
wString  = "SendMail.php?destinataire=" + wDestinataire;
wString += "&objet=" + mvChangePlus(document.FrmMail.TxtObject.value);
wString += "&message=" + mvChangePlus(wMessage);
wString += "&mail=" + document.FrmMail.TxtMail.value;
document.location.replace(wString);
}

/***********************************************************************
 * Ecrire dans le livre d'or                                           *
 ***********************************************************************/

function mvWriteBook()
{
var wString, wText, wLength, wCar, i;

if (document.FrmBookWrite.TxtName.value == "")
  {
  alert("Vous n'avez pas renseigné votre nom !");
  return;
  }
if (document.FrmBookWrite.TxtText.value == "")
  {
  alert("Vous n'avez pas écrit de message !");
  return;
  }
if (document.FrmBookWrite.TxtUrl.value == "http://")
  document.FrmBookWrite.TxtUrl.value = "";
wString = document.FrmBookWrite.TxtText.value;
wLength = wString.length;
wText = "";
for (i = 0 ; i < wLength ; i++)
  {
  wCar = wString.substr(i, 1);
  if (wCar == "\r")
    continue;
  if (wCar == "\n")
    {
    wText += "<br>";
    continue;
    }
  wText += wCar;
  }
wString  = "BookWritePost.php?name=" + document.FrmBookWrite.TxtName.value;
wString += "&mail=" + document.FrmBookWrite.TxtMail.value;
wString += "&ville=" + document.FrmBookWrite.TxtVille.value;
wString += "&pays=" + document.FrmBookWrite.TxtPays.value;
wString += "&url=" + document.FrmBookWrite.TxtUrl.value;
wString += "&note=" + document.FrmBookWrite.CboNote.value;
wString += "&visiteur=" + document.FrmBookWrite.CboVisiteur.value;
wString += "&text=" + wText;
document.location.replace(wString);
}
