﻿
function writeMailto(c, n, d) {
    var m = n + unescape('%40') + d;
    document.write('<a href="mailto:' + m + '">' + c + '</a>');
}

// 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';
                if (this.chld) {
                    this.chld.className = 'recap visible';
                }
                this.status = 1;
            }
            trobj._close = function() {
                this.className = 'recap_closed';
                this.title = 'Voir le détail de la commande';
                if (this.chld) {
                    this.chld.className = 'recap hidden';
                }
                this.status = 0;
            }
        }
    }
}



// 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() {
            if (this.prt.cur != null) {
                this.prt.cur._hide();
                this.prt.cur = null;
            }
            this.style.visibility = 'visible';
            this.prt.cur = this;
        }
        liobj._hide = function() {
            this.style.visibility = 'hidden';
        }
        lievtcol = liobj.getElementsByTagName("UL")[0].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() {
                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();
}

// 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';
    if (obj.className.indexOf("closed") < 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) ? 'on open' : 'closed');
        repos_haut();
        return false;
    }
}

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";
    }
}

function afficheRecherche(id) {
    for (i = 1; i < 5; i++) {
        bloc = document.getElementById("bloc_themes" + i);
        bloc.className = "off";
    }
    bloc = bloc = document.getElementById("bloc_themes" + id);
    bloc.className = "on";
}

function afficheTabRecherche(id, nbTabs) {
    for (i = 1; i < nbTabs; i++) {
        bloc = document.getElementById("bloc_themes" + i);
        bloc.className = "off";
    }
    bloc = bloc = document.getElementById("bloc_themes" + id);
    bloc.className = "on";
}

function afficheCommande(id) {
    var firstNum = id.toString().substr(0, id.length - 1);
    for (i = 1; i < 4; i++) {
        bloc = document.getElementById("bloc_onglet" + firstNum + i);
        bloc.className = "off";
    }
    bloc = bloc = document.getElementById("bloc_onglet" + id);
    bloc.className = "on";
}

function depliAchat(element) {
    nbre_div = 0;
    bouton = document.getElementById(element);
    if (bouton.className == "on") {
        bouton.className = "";
        while (nbre_div < bouton.getElementsByTagName("div").length) {

            if (bouton.getElementsByTagName("div")[nbre_div].className == "on") {
                bouton.getElementsByTagName("div")[nbre_div].className = "off";
            };

            nbre_div++;
        }
    } else {
        bouton.className = "on";
        bouton.getElementsByTagName("div")[0].className = "on";
    }
    return false;
}
function closeMap() {
    obj = document.getElementById("carte_flash")
    if (obj.className == "flash-off") {
        obj.className = "flash-on";
    } else {
        obj.className = "flash-off";
    }
}
