﻿function MailTo($email, $nom) {
  $email = $email.replace("*", "@");
  if (typeof ($nom) != "string")
    $nom = $email;
  document.write("<a href=\"mailto:" + $email + "\">" + $nom + "</a>");
}

// Affiche ou masque une rubrique
function ouvrirFermerMenu($id) {
  var $rubrique = $("menuRubrique" + $id);
  var $fx = new Fx.Slide($rubrique);
  if ($rubrique.style.display == "none") {
    $fx.hide();
    $rubrique.style.display = "block";
  }
  $fx.toggle();
}

function developperArticle($id) {
  $("blocArticle" + $id).load("sys.articles.ajax.asp?ACTION=DETAILLER_ARTICLE&ID=" + $id);
}

function resumerArticle($id) {
  $("blocArticle" + $id).load("sys.articles.ajax.asp?ACTION=RESUME_ARTICLE&ID=" + $id);
}

function afficherSousArticle($idPere, $idFils) {
  $("blocSousArticle" + $idPere).load("sys.articles.ajax.asp?ACTION=AFFICHER_ARTICLE&ID=" + $idFils);
  $("blocSousArticle" + $idPere).style.display = "block";
}

// Gestion des tables HTML
var TABLE = new Hash().extend({

  oldClassName: "",

  over: function($tr) {
    this.oldClassName = $tr.className;
    $tr.className = "over";
  },

  out: function($tr) {
    $tr.className = this.oldClassName;
    this.oldClassName = "";
  },

  click: function($event, $url) {
    var $tagName = ($event.srcElement ? $event.srcElement : $event.target).tagName;
    if ($tagName != "INPUT" && $tagName != "IMG" && $tagName != "A")
      window.location = $url;
  }

});

// Popup en web 2.0
var POPUP = new Hash({

  fondNoir: null,
  closeBtn: null,

  open: function($id) {
    this.fondNoir = new Element("div", { "class": "fondNoir" });
    document.body.appendChild(this.fondNoir);
    var $popup = $($id);
    $popup.unpin();
    $popup.position({ position: "center" });
    $popup.style.display = "block";
    $popup.fade("hide");
    $popup.fade("in");
    this.closeBtn = new Element("img", { src: "images/close.png", style: "z-index:9999", "class": "bouton" });
    document.body.appendChild(this.closeBtn);
    this.closeBtn.position({ relativeTo: $($id), position: "upperRight", offset: { x: -25, y: 7} });
    this.closeBtn.addEvent("click", this.close.bind(this, $id));
    $popup.pin();
    this.closeBtn.pin();
  },

  close: function($id) {
    $($id).fade("out");
    if (this.fondNoir)
      document.body.removeChild(this.fondNoir);
    if (this.closeBtn)
      document.body.removeChild(this.closeBtn);
    this.fondNoir = null;
    this.closeBtn = null;
  }

});