﻿/*
$(document).ready(function(){
$("#c_04").datepicker({
showOn: "both", 
buttonImage: "img/picto_calendrier.gif", 
buttonImageOnly: true 
});
$("#c_05").datepicker({ 
showOn: "both", 
buttonImage: "img/picto_calendrier.gif", 
buttonImageOnly: true 
});
$("#dp_03").datepicker({ 
showOn: "both", 
buttonImage: "img/picto_calendrier.gif", 
buttonImageOnly: true 
});
$("#dp_04").datepicker({ 
showOn: "both", 
buttonImage: "img/picto_calendrier.gif", 
buttonImageOnly: true 
});
$("#date_consult").datepicker({ 
showOn: "both", 
buttonImage: "img/picto_calendrier.gif", 
buttonImageOnly: true 
});
	
	
// Flash Cartes
// Remplacement de l'image aperçu par le flash
$("#mcarte").empty();
$("#mcarte").flash({
src: 'pays/flash/miniMap.swf',
width: 148,
height: 82,
wmode: 'transparent'
});
		
$(".region .europe").empty();
$(".region .europe").flash({
src: 'region/flash/miniMapFrance.swf',
width: 135,
height: 135,
wmode: 'transparent'
});
		
$("#flashbanneralt").remove();
$(".layout0").addClass("withflash");
		
		
// Erreurs
$(".oblig").blur(function() {
if($(this).hasClass("erreur_chps") == true) {return;}
$(this).addClass("erreur_chps");
var H = '<span class="erreur_live"><img src="img/picto-cross.gif" alt="" />&nbsp;Vous n&rsquo;avez pas rempli ce champ correctement. &uarr;</span>';
$(H).insertAfter($(this));
var H = '<span class="ok_live"><img src="img/picto-tick.gif" alt="Champ correctement rempli" /></span>';
$(H).insertAfter($(this));
});



});
*/


// voir toute la collection
function init_voir(oid) {
 if (document.getElementById(oid) == null)
  return false;
 obj = document.getElementById(oid);
 if (obj.className.indexOf("open") < 0)
  obj.className = 'voir closed';
 aevt = obj.getElementsByTagName("A")[0];
 aevt.prt = obj;
 aevt.onclick = function() {
  this.blur();
  this.prt.className = ((this.prt.className.indexOf("open") < 0) ? 'voir open' : 'voir closed');
  repos_haut();
  return false;
 }
}

// IE6 - repositionnement haut de page avec les contenus dynamiques
function repos_haut() {
 if (typeof document.body.style.maxHeight != "undefined") // detection IE6 uniquement
  return false;
 if (document.getElementById('haut_fin'))
  document.getElementById('haut_fin').className = 'haut h_fin';
}

// ajouter adresse
function init_ajout_adresse(oid) {
 if (document.getElementById(oid) == null)
  return false;
 obj = document.getElementById(oid);
 if (obj.className.indexOf("open") < 0)
  obj.className = 'closed';
 aevt = obj.getElementsByTagName("A")[0];
 aevt.prt = obj;
 aevt.onclick = function() {
  this.blur();
  this.prt.className = ((this.prt.className.indexOf("open") < 0) ? 'open' : 'closed');
  repos_haut();
  return false;
 }
}

// affichage formulaire societe
function form_societe(oid, v) {
 if (document.getElementById(oid) == null)
  return false;
 obj = document.getElementById(oid);
 if (v)
  obj.style.display = 'block';
 else
  obj.style.display = 'none';
 return false;
}

// recap commandes
function init_recap_commande(oid) {
 commobj = document.getElementById(oid);
 trcol = commobj.getElementsByTagName("TBODY")[0].getElementsByTagName("TR");
 for (i = 0; i < trcol.length; i++) {
  trobj = trcol[i];
  if (trobj.className == 'recap')
   trobj.className = 'recap hidden';
  else {
   if (trobj.className != 'recap_event')
    continue;
   trobj.className = 'recap_closed';
   trobj.title = 'Voir le détail de la commande';
   trobj.chld = trcol[i + 1];
   trobj.status = 0;
   trobj.onmouseover = function() {
    if (this.className == 'recap_open')
     return false;
    this.className = 'recap_over';
   }
   trobj.onmouseout = function() {
    if (this.className == 'recap_open')
     return false;
    this.className = 'recap_out';
   }
   trobj.onclick = function() {
    if (this.status)
     this._close();
    else
     this._open();
   }
   trobj._open = function() {
    this.className = 'recap_open';
    this.title = 'Masquer le détail de la commande';
    this.chld.className = 'recap visible';
    this.status = 1;
   }
   trobj._close = function() {
    this.className = 'recap_closed';
    this.title = 'Voir le détail de la commande';
    this.chld.className = 'recap hidden';
    this.status = 0;
   }
  }
 }
}

// Bloc recherche
var treeobj = null;
function init_treeview() {
 treeobj = document.getElementById("rech_tree");
 treecol = treeobj.getElementsByTagName("UL");
 treeobj.collected = new Array();
 treeobj.critlist = new Array();
 treeobj.treeinit = new Array();
 treeobj.crit_build = function() {
  for (i = 0; i < this.collected.length; i++) {
   for (j = 0; j < this.collected[i].length; j++) {
    liobj = this.collected[i][j].cloneNode(true);
    this.critlist[i].appendChild(liobj);
   }
  }
 }
 ind = -1;
 critind = 0;
 for (i = 0; i < treecol.length; i++) {
  ulobj = treecol[i];
  if (ulobj.parentNode.className == 'crit') {
   treeobj.critlist[critind++] = ulobj;
   ulobj.removeChild(ulobj.getElementsByTagName("LI")[0]);
   continue;
  }
  if (ulobj.parentNode.className != 'tree')
   continue;
  ind++;

  treeobj.collected[ind] = new Array();
  treeobj.treeinit[ind] = new Array();

  treeobj.cleancol = function(colind) {
   if (arguments.length == 2)
    maxind = 1;
   else
    maxind = this.collected[colind].length;
   for (i = 0; i < maxind; i++) {
    if (this.collected[colind][i] == null)
     continue;
    rmchld = this.collected[colind][i];
    this.collected[colind][i] = null;
    if (rmchld.tagName != 'LI')
     rmchld = rmchld.parentNode;
    rmchld.parentNode.removeChild(rmchld);
   }
  }

  acol = ulobj.getElementsByTagName("A");
  for (j = 0; j < acol.length; j++) {
   aobj = acol[j];
   aobj.ind = j;
   aobj.prt = treeobj;
   aobj.colind = ind;
   aobj.prt.collected[ind][j] = null;
   aobj.prt.treeinit[ind][j] = aobj;
   if (aobj.parentNode.getElementsByTagName("UL").length > 0) { // masquer - afficher sous-menu
    aobj.onclick = function() {
     this.blur();
     this.parentNode.className = (this.parentNode.className == 'open') ? 'closed' : 'open';
     return false;
    }
   }
   else {
    aobj.crit_add = function() { // ajouter  - supprimer element
     if (this.prt.collected[this.colind][this.ind] != null)
      return false;
     clonobj = this.parentNode;
     if (clonobj.tagName != "LI") { // premier element
      this.prt.cleancol(this.colind);
      clonobj = clonobj.parentNode;
     }
     else {
      this.prt.cleancol(this.colind, 0);
     }
     this.prt.collected[this.colind][this.ind] = clonobj;
     liobj = clonobj.cloneNode(true);
     this.prt.critlist[this.colind].appendChild(liobj);
     clonaobj = liobj.getElementsByTagName("A")[0];
     clonaobj.ind = this.ind;
     this.prt.collected[this.colind][this.ind] = liobj;
     clonaobj.uptag = liobj;
     clonaobj.prt = this;
     clonaobj.title = "Supprimer ce critère";
     clonaobj.onclick = clonaobj.remove = function() {
      this.uptag.parentNode.removeChild(this.uptag);
      this.prt.prt.collected[this.prt.colind][this.prt.ind] = null;
      return false;
     }
     return false;
    }

    aobj.onclick = function() {
     this.blur();
     return this.crit_add();
    }
   }
  }
 }

 // initialisation
 for (i = 0; i < arguments.length; i++) {
  for (j = 0; j < arguments[i].length; j++) {
   if (treeobj.treeinit[i][arguments[i][j]].crit_add)
    treeobj.treeinit[i][arguments[i][j]].crit_add();
  }
 }
}

// bloc onglets
function init_onglets(oid) {
  
 obj = document.getElementById(oid);
 obj.cur = null;
 licol = obj.getElementsByTagName("LI");
 obj.licol = new Array();
 mxH = 0;
 for (i = 0; i < licol.length; i++) {
  liobj = licol[i];
  if (liobj.parentNode != obj)
   continue;
  obj.licol[obj.licol.length] = liobj;
  liobj.prt = obj;
  liobj.className = 'onglet_cont';
  liobj._show = function() {
  $("#onglets1 input:radio").hide();
  $(this).find("table").show();
  $(this).find("input:radio").show();
   if (this.prt.cur != null) {
    this.prt.cur._hide();
    this.prt.cur = null;

   }
   // this.style.display = 'block';
   this.style.visibility = 'visible';
   this.style.backgroundColor = "white";
   this.prt.cur = this;
  }
  liobj._hide = function() {
   // this.style.display = 'none';
   this.style.visibility = 'hidden';

  }
  lievtcol = liobj.getElementsByTagName("UL")[1].getElementsByTagName("LI");
  for (j = 0; j < lievtcol.length; j++) {
   lievt = lievtcol[j];
   if (lievt.getElementsByTagName("A").length == 0)
    continue;
   aevt = lievt.getElementsByTagName("A")[0];
   aevt.mprt = obj;
   aevt.ind = j;
   aevt.onclick = function() {

    $("[id$=MemoTabHiddenField]").val(this.ind);
    this.blur();
    this.mprt.licol[this.ind]._show();
    return false;
   }

  }

  mxH = Math.max(mxH, parseInt(liobj.offsetHeight));
 }
 obj.style.height = mxH + 'px';
 licol[0]._show();

 //lievtcol = licol.liobj.getElementsByTagName("UL")[0].getElementsByTagName("LI")[1].getElementsByTagName("A").Click();
}

// affiche l'onglet dont l'index est passé en paramètre
function show_onglet(oid, index) {
 obj = document.getElementById(oid);
 licol = obj.getElementsByTagName("LI");
 var liobj = licol[index - 1];
 //var lievtcol = liobj.getElementsByTagName("UL")[0].getElementsByTagName("LI");
 //alert(index);
 //$("#" + oid + " A").trigger("click");
 $("#" + oid + " A:eq(" + (index - 1) + ")").trigger("click");
 $("#onglets1 table").hide();

 //$("#" + oid + " A:first").trigger("click");
 //alert(index);
}
// plier-deplier topic
function init_toggleTopic() {
 i = 1;
 titres = document.getElementById("topics").getElementsByTagName("P");
 while (o = document.getElementById("topic" + i)) {
  o.className = 'closed';
  o.ind = i;
  o.lien = titres[i - 1].firstChild;
  i++;
  o.lien.prt = o;
  o.lien.onclick = function() {
   if (this.className == "close") {
    this.className = "open";
    this.prt.className = "closed";
   }
   else {
    this.className = "close";
    this.prt.className = "opened";
   }
   return false;
  }
 }
}

// plier-deplier topic
function open_toggleTopics() {
 i = 1;
 while (o = document.getElementById("topic" + (i++))) {
  o.lien.className = "close";
  o.lien.prt.className = "opened";
 }
 return false;
}
/* apparition champs */
function champs(element1, element2, bt) {
 if (document.getElementById(bt).checked == true) {
  document.getElementById(element1).firstChild.nextSibling.style.display = "block";
  document.getElementById(element2).firstChild.style.display = "block";
 } else {
  document.getElementById(element1).firstChild.nextSibling.style.display = "none";
  document.getElementById(element2).firstChild.style.display = "none";
 }
}


// Flash Map
function openMap() {
 // Insertion de la popin
 $("body").append('<div id="popin"> </div>');

 // Blocage du scroll
 if ($.browser.msie == true) {
  e = document.getElementsByTagName("html")[0].scrollTop;
  $(".conteneur").css("margin-top", -e);
 }
 $("body").css("overflow", "hidden");
 $("html").css("height", '100%');
 $("body").css("height", '100%');

 // Masquage des select
 $("select").css("visibility", "hidden");

 // Insertion de la carte dans la popin
 if ((arguments.length > 0) && (arguments[0] == 2)) {
  $("#popin").flash({
   src: 'region/flash/carte.swf',
   width: "100%",
   height: "100%",
   wmode: 'transparent',
   flashvars: {
    xmlPath: 'region/flash/xml/mapFrance.xml',
    mapFrancePath: 'region/flash/map_france.swf'
   }
  });
 }
 else {
  $("#popin").flash({
   src: 'pays/flash/carte.swf',
   width: "100%",
   height: "100%",
   wmode: 'transparent',
   flashvars: {
    xmlPath: 'pays/flash/xml/worldmap.xml',
    mapCountriesPath: 'pays/flash/map_world.swf',
    mapZonesPath: 'pays/flash/map_world_zones.swf'
   }
  });
 }

 $("#popin").fadeIn();
}


function openMapFrance() {
 openMap(2);
 /*	// Insertion de la popin
 $("body").append('<div id="popin"> </div>');
	
 // Blocage du scroll
 if($.browser.msie == true) {
 e = document.getElementsByTagName("html")[0].scrollTop;
 $(".conteneur").css("margin-top", -e );
 }
 $("body").css("overflow", "hidden");
 $("html").css("height", '100%');
 $("body").css("height", '100%');

 // Masquage des select
 $("select").css("visibility", "hidden");
	
 // Insertion de la carte dans la popin
 $("#popin").flash({
 src: 'region/flash/carte.swf',
 width: "100%",
 height: "100%",
 wmode: 'transparent',
 flashvars: {
 xmlPath: 'region/flash/xml/mapFrance.xml',
 mapFrancePath: 'region/flash/map_france.swf'
 }
 });
 $("#popin").fadeIn();*/
}


function closeMap() {

 // Suppression de la popin
 $("#popin").fadeOut("fast", function() {
  $(this).remove();
  // Affichage des select
  $("select").css("visibility", "visible");
 });

 // Init du scroll
 $("body").css("overflow", "visible");
 $("html").css("height", 'auto');
 $("body").css("height", 'auto');
}

function closeMapFrance() {
 closeMap();
}


function date() {
 document.getElementById("date").innerHTML = document.getElementById("date_consult").value;
}

/* acces dynamique */
function init_acces() {
 if (arguments[0] != -1) {
  document.getElementById('acces').className = 'acces acceshide';
  window.setTimeout("init_acces(-1," + arguments[0] + ")", 100);
  return;
 }
 o = document.getElementById('acces');
 o.curitm = null;
 o.dv = o.getElementsByTagName("DIV")[0];
 o.getElementsByTagName("UL")[0].className = 'accesdyn';
 ini_ind = arguments[1];
 itms = o.getElementsByTagName("LABEL");
 selitms = o.getElementsByTagName("SELECT");
 for (i = 0; i < itms.length; i++) {
  it = itms[i];
  it.ind = i;
  it.prt = o;
  it.sel = selitms[i];
  it.txt = it.getElementsByTagName("SPAN")[0].innerHTML;
  it.innerHTML = '<a href="#">' + it.txt + '</a>';
  it.getElementsByTagName("A")[0].onclick = function() {
   this.parentNode._switch(1);
  }

  it._switch = function(v) {
   if (v == 1) {
    if (this.prt.curitm != null)
     this.prt.curitm._switch(0);
    this.sel.style.display = 'block';
    this.innerHTML = '<span>' + this.txt + '</span>';
    this.prt.dv.className = 'acces' + this.ind;
    if (this.ind != 1) {
     this.prt.dv.innerHTML = '<a href="javascript:openMap(' + this.ind + ')" title="Clicquez pour afficher la carte"><br/></a>';
     this.prt.dv.getElementsByTagName("A")[0].style.width = this.prt.dv.offsetWidth + 'px';
     this.prt.dv.getElementsByTagName("A")[0].style.height = this.prt.dv.offsetHeight + 'px';
    }
    else {
     this.prt.dv.innerHTML = '<span><br/></span>';
    }
    this.prt.curitm = this;
   }
   else {
    this.innerHTML = '<a href="#">' + this.txt + '</a>';
    this.getElementsByTagName("A")[0].onclick = function() {
     this.parentNode._switch(1);
    }
    this.sel.style.display = 'none';
   }
   return false;
  }
 }

 itms[ini_ind]._switch(1);
}

// deplier home page
function init_on(oid) {
 if (document.getElementById(oid) == null)
  return false;
 obj = document.getElementById(oid);
 if (obj.className.indexOf("open") < 0)
  obj.className = 'on open';
 aevt = obj.getElementsByTagName("A")[0];
 aevt.prt = obj;
 aevt.onclick = function() {
  this.blur();
  this.prt.className = ((this.prt.className.indexOf("open") < 0) ? 'on open' : 'closed');
  repos_haut();
  return false;
 }
}

// gestion onglet page espace
function gestion_onglet_espace(onglet) {
 for (i = 1; i < 4; i++) {
  document.getElementById("onglet" + i).className = "onglet";
  document.getElementById("contenu" + i).className = "contenu-off";
 }
 document.getElementById("onglet" + onglet).className = "onglet-on";
 document.getElementById("contenu" + onglet).className = "bloc_contenu_onglet contenu-on";
}

function gestion_ss_contenu(id) {
 obj = document.getElementById("num_contenu" + id);
 if (obj.className == "num_contenu-off") {
  obj.className = "num_contenu-on";
 } else {
  obj.className = "num_contenu-off";
 }
}
function afficheMenu(param, etat) {
 i = 0;
 element = document.getElementById("filiere");
 if (etat == "on") {
  document.getElementById("filiere_bt").src = "Image.axd?path=img/h_fd_menu_filiere-on.png";
  element.className = "filiere on";
  while (element.getElementsByTagName("li")[i] != undefined) {
   element.getElementsByTagName("li")[i].onmouseover = function() {
    this.className = "on";
   }
   element.getElementsByTagName("li")[i].onmouseout = function() {
    this.className = "off";
   }
   i++;
  }

 } else {
 document.getElementById("filiere_bt").src = "Image.axd?path=img/h_fd_menu_filiere.png";
  element.className = "filiere off";
 }
}