﻿function ChangeInfosReference(idDdlColoris, idDdlTaille) {
    var coloris = GetSelectedValue(idDdlColoris)
    ChangeTaille(coloris, idDdlTaille);
    ChangeAllValues(idDdlColoris, idDdlTaille, true);
    AfficherImageColoris(coloris);
}

function GetSelectedValue(controlId) {
    var control = document.getElementById(controlId);
    var value;
    try {
        value = control.options[control.selectedIndex].value;
    }
    catch (Error) {
        value = control.value;
    }
    return value;
}

function ChangeTaille(coloris, idDdlTaille) {
    var oldTaille;
    var taille;
    var oldIndex = -1;
    var selection = -1;
    if (coloris == '0') {
        taille = taillesDefaut.split(/;/);
    }
    else {
        taille = colorSize[coloris].split(/;/);
    }
    var ddlTaille = document.getElementById(idDdlTaille);

    // On récupère l'ancienne taille
    if (ddlTaille.length > 0) {
        oldTaille = ddlTaille.options[ddlTaille.selectedIndex].text;
    }
    if (ddlTaille.tagName.toLowerCase() == "select") {
        if (ddlTaille.options.length > taille.length)
            ddlTaille.options.length = 0;
        for (i = 0; i < taille.length; i++) {
            ddlTaille.options[i] = document.createElement("option");
            ddlTaille.options[i].value = taille[i].split(/!/)[0];
            ddlTaille.options[i].text = taille[i].split(/!/)[1];
            if (ddlTaille.options[i].text.lastIndexOf(" _ ") != -1)
                ddlTaille.options[i].text = ddlTaille.options[i].text.split(/_/)[0];
                
            if (ddlTaille.options[i].text == oldTaille) {
                oldIndex = i;
            }

            if (taille[i].split(/!/)[1].lastIndexOf(" - ") != -1) {
                try {
                    ddlTaille.options[i].attributes["class"].value = "memo_taille_epuisee";
                }
                catch (Error) {
                    ddlTaille.options[i].setAttribute('class', 'memo_taille_epuisee', '');
                }
            }
            else if (taille[i].split(/!/)[1].lastIndexOf(" _ ") != -1) {
                try {
                    ddlTaille.options[i].attributes["class"].value = "memo_taille_differe";
                }
                catch (Error) {
                    ddlTaille.options[i].setAttribute('class', 'memo_taille_differe', '');
                }
            }
            else {
                try {
                    ddlTaille.options[i].attributes["class"].value = "memo_taille_defaut";
                }
                catch (Error) {
                    ddlTaille.options[i].setAttribute('class', 'memo_taille_defaut', '');
                }
            }
        }

        if (indexTaille) {
            ddlTaille.selectedIndex = indexTaille;
        }
        else {
            if (oldIndex != -1) {
                ddlTaille.selectedIndex = oldIndex;
            }
            else {
                if (selection != -1) {
                    ddlTaille.selectedIndex = selection;
                }
                else {
                    ddlTaille.selectedIndex = 0;
                }
            }
        }
    }
    else {
        ddlTaille.value = taille[0].split(/!/)[0];
        if (taille[0].split(/!/).length > 1) {
            document.getElementById(idDdlTaille + '_Label').innerHTML = taille[0].split(/!/)[1];
        }
        else {
            document.getElementById(idDdlTaille + '_Label').innerHTML = "";
        }

        if (taille[0].split(/!/).length > 1 && taille[0].split(/!/)[1].lastIndexOf(" _ ") != -1) {
            if (taille[0].split(/!/)[1].split(/_/)[1].length <= 3) {
                document.getElementById(idDdlTaille + '_Label').innerHTML = taille[0].split(/!/)[1].split(/_/)[0];
            }
        }
    }
}

function ChangeAllValues(idDdlColoris, idDdlTaille, initialisation) {
    var reference = GetSelectedValue(idDdlTaille);
    var coloris = GetSelectedValue(idDdlColoris)
    if (reference == '0') {
        SetDefaultValues(coloris, reference);
    }
    else {
        var infos = infosRef[reference];
        var listeId = infos.split(/;/);

        if (initialisation) {
            var control = document.getElementById(idDdlTaille);
            if (control.options) {
                if (control.options[0].innerHTML.lastIndexOf("-") != -1) {
                    for (var i = 0; i < control.options.length; i++) {
                        if (control.options[i].innerHTML.lastIndexOf("-") == -1) {
                            infos = infosRef[control.options[i].value];
                            listeId = infos.split(/;/);
                            control.value = control.options[i].value;
                            break;
                        }
                    }
                }
            }
        }

        ChangePrix(listeId[0]);
        ChangeDispo(listeId[1]);
        ChangeToolTipTitre(listeId[2], reference);
        ChangeTxdmq(listeId[3]);
        if (finarefActif) {
            var finarefInfos = finarefInfosDeReference[listeId[4]];
            ChangeFinaref(finarefInfos);
        }
        else {
            ChangeFinarefVide();
        }
    }
}

function ChangePrix(idPrix) {
    var prix = prixDeReference[idPrix];
    var divPrix = document.getElementById('divPrix');
    divPrix.innerHTML = prix;
}

function ChangeDispo(idDispo) {
    var dispo = dispoDeReference[idDispo];
    var divDispo = document.getElementById('divDispo');
    divDispo.innerHTML = dispo;
}

function ChangeTxdmq(idTxdmq) {
    var txdmq = txdmqDeReference[idTxdmq];
    var divTxdmq = document.getElementById('divTxdmq');
    divTxdmq.innerHTML = txdmq;
}

function ChangeToolTipTitre(idCoddoc, reference) {
    var coddoc = coddocDeReference[idCoddoc];
    var titre = document.getElementById("memo_produit_fiche_produit_titre");
    titre.attributes["title"].value = coddoc + " - " + reference;
}

function ChangeFinaref(finarefInfos) {

    var divFinarefLibelle = document.getElementById('memo_produit_fiche_produit_multifractionnement_libelle_1');
    var divFinaref = document.getElementById('memo_produit_fiche_produit_multifractionnement');

    if (libelleFinaref == '') {
        divFinarefLibelle.style.display = "none";
        divFinaref.style.display = "none";
    }
    else {
        divFinaref.style.display = "block";
        divFinarefLibelle.style.display = "block";
        divFinarefLibelle.innerHTML = libelleFinaref;
    }

    var finaref = finarefInfos.split(/;/);

    var divFinarefMention = document.getElementById("memo_produit_fiche_produit_multifractionnement_mention");
    divFinarefMention.innerHTML = finarefMentionDeReference[finaref[0]];
    divFinarefMention.style.display = "none";

    var spanMtmens = document.getElementById("mtmens");
    spanMtmens.innerHTML = finaref[1];

    var spanNbfract = document.getElementById("nbfract");
    spanNbfract.innerHTML = finaref[2];

    var spanMtfrais = document.getElementById("mtfrais");
    spanMtfrais.innerHTML = finaref[3];

    var spanTaeg = document.getElementById("taeg");
    spanTaeg.innerHTML = finaref[4];
}

function ChangeFinarefVide() {

    var divFinaref = document.getElementById('memo_produit_fiche_produit_multifractionnement_2');
    var divFinarefLibelle = document.getElementById('memo_produit_fiche_produit_multifractionnement_libelle_2');

    if (libelleHorsFinaref == '') {
        divFinaref.style.display = "none";
    }
    else {
        divFinaref.style.display = "block";
        divFinarefLibelle.style.display = "block";
        divFinarefLibelle.innerHTML = libelleHorsFinaref;
    }

    var divFinarefMention = document.getElementById("memo_produit_fiche_produit_multifractionnement_mention");
    divFinarefMention.style.display = "none";
}

function SetDefaultValues(coloris, reference) {
    var divPrix = document.getElementById('divPrix');
    divPrix.innerHTML = prixDefaut;

    var divDispo = document.getElementById('divDispo');
    if (coloris != '0') {
        divDispo.innerHTML = dispoDefaut;
    }
    else {
        divDispo.innerHTML = '';
    }

    var divTxdmq = document.getElementById('divTxdmq');
    divTxdmq.innerHTML = TxdmqDefaut;

    var titre = document.getElementById("memo_produit_fiche_produit_titre");
    titre.attributes["title"].value = coddocDefaut + " - " + reference;

    if (finarefActif) {
        var finarefInfos = finarefDefaut;
        ChangeFinaref(finarefInfos);
    }
    else {
        ChangeFinarefVide();
    }
}

function AfficherImageColoris(codeColoris) {
    var url = arrImagesColoris[codeColoris];
    ChargeImage(url);
}

function ChargeImage(url) {
    var imgVisuel = document.getElementById("memo_produit_fiche_image_visuel");
    imgVisuel.src = url;
}

function SetEVar15(onglet) {
    var s = s_gi(omnitureSiteKey);
    s.linkTrackVars = 'eVar15,events';
    s.linkTrackEvents = 'event19';
    s.eVar15 = onglet;
    s.events = 'event19';
    s.tl(this, 'o', onglet);

}

function display(name, isender, onglet) {
    for (i = 1; i <= 4; i++) {
        if (document.getElementById(name + i) != null) {
            document.getElementById(name + i).style.display = "none";
        }
        if (document.getElementById(onglet + i) != null) {
            document.getElementById(onglet + i).attributes["class"].value = "memo_produit_fiche_onglet_inactif";
        }
    }
    var div = document.getElementById(name + isender);
    if (div != null) {
        div.style.display = div.style.display == "none" ? "block" : "none";
    }
    div = document.getElementById(onglet + isender);
    if (div != null) {
        div.attributes["class"].value = "memo_produit_fiche_onglet_actif";
    }
}

function mouseOverFicheProduit() {
    var div = document.getElementById('memo_produit_fiche_dispo');
    div.style.display = 'block';
    div.style.zIndex = '10000000';
}

function mouseOutFicheProduit() {
    var div = document.getElementById('memo_produit_fiche_dispo');
    div.style.display = 'none';
}



var WindowGuideTaille;
function PopupGuideTaille(pageUrl, popW, popH) {

    var w = 800, h = 600;

    w = screen.availWidth;
    h = screen.availHeight;


    if (popW > w) { popW = w }
    if (popH > h) { popH = h }

    var leftPos = (w - popW) / 2, topPos = (h - popH) / 2;

    WindowGuideTaille = window.open(pageUrl, 'popup', 'width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos + ',scrollbars=yes');


}

var WindowCatalogueInteractif;
function PopupCatalogueInteractif(pageUrl, popW, popH) {

    var w = 800, h = 600;


    w = screen.availWidth;
    h = screen.availHeight;


    if (popW > w) { popW = w }
    if (popH > h) { popH = h }

    var leftPos = (w - popW) / 2, topPos = (h - popH) / 2;

    WindowCatalogueInteractif = window.open(pageUrl, 'popup', 'width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos);


}

var WindowDetailPopup;
function PopupDetailPopup(pageUrl, popW, popH) {

    var w = 800, h = 600;


    w = screen.availWidth;
    h = screen.availHeight;


    if (popW > w) { popW = w }
    if (popH > h) { popH = h }

    var leftPos = (w - popW) / 2, topPos = (h - popH) / 2;

    WindowDetailPopup = window.open(pageUrl, 'popup', 'width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos);


}

var WindowAchatSecurise;
function PopupAchatSecurise(pageUrl, popW, popH) {

    var w = 800, h = 600;


    w = screen.availWidth;
    h = screen.availHeight;


    if (popW > w) { popW = w }
    if (popH > h) { popH = h }

    var leftPos = (w - popW) / 2, topPos = (h - popH) / 2;

    WindowAchatSecurise = window.open('popup' + pageUrl, 'popup', 'width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos + ',scrollbars=yes');


}

function mouseOverFinaref() {
    var divLibelle = document.getElementById("memo_produit_fiche_produit_multifractionnement_libelle_1");
    if (divLibelle.innerHTML != '') {
        var divMention = document.getElementById("memo_produit_fiche_produit_multifractionnement_mention");
        divMention.style.display = "block";
    }
}

function mouseOutFinaref() {
    var divLibelle = document.getElementById("memo_produit_fiche_produit_multifractionnement_libelle_1");
    if (divLibelle.innerHTML != '') {
        var divMention = document.getElementById("memo_produit_fiche_produit_multifractionnement_mention");
        divMention.style.display = "none";
    }
}

function verifChoixAjoutPanier(messageErreur) {
    return verifChoixAjoutPanier(messageErreur, messageErreur);
}

function verifChoixAjoutPanier(messageErreurColoris, messageErreurTaille) {
    var ddlColoris = document.getElementById("ctl00_cphZoneActive_memo_produit_fiche_select_selecteur_coloris");
    if (ddlColoris == null) ddlColoris = document.getElementById("memo_produit_fiche_select_selecteur_coloris");
    if (ddlColoris != null && ddlColoris.selectedIndex == 0) {
        alert(messageErreurColoris);
        return false;
    }
    var ddlTaille = document.getElementById("ctl00_cphZoneActive_memo_produit_fiche_select_selecteur_taille");
    if (ddlTaille == null) ddlTaille = document.getElementById("memo_produit_fiche_select_selecteur_taille");
    if (ddlTaille != null && ( ddlTaille.value == "0" || (ddlTaille.options && ddlTaille.options[ddlTaille.selectedIndex].className == 'memo_taille_epuisee'))) {
        alert(messageErreurTaille);
        return false;
    }
    return true;
}




// debut tests altima

function ChangeDispoPersonnalisee(idDispo) {
    var dispo = dispoDeReference[idDispo];
    var divDispo = document.getElementById('divDispo');
    divDispo.innerHTML = '<br>' + dispo;
}

function SetDefaultValuesPersonnalisee(coloris, reference) {
    var divPrix = document.getElementById('divPrixAltima');
    divPrix.innerHTML = prixDefaut + TxdmqDefaut;

    var divDispo = document.getElementById('divDispo');
    if (coloris != '0') {
        divDispo.innerHTML = '<br>' + dispoDefaut;
    }
    else {
        divDispo.innerHTML = '';
    }

    var titre = document.getElementById("memo_produit_fiche_produit_titre");
    titre.attributes["title"].value = coddocDefaut + " - " + reference;

    if (finarefActif) {
        var finarefInfos = finarefDefaut;
        ChangeFinarefPersonnalisee(finarefInfos);
    }
    else {
        ChangeFinarefVidePersonnalisee();
    }
}

function ChangeInfosReferencePersonnalisee(idDdlColoris, idDdlTaille) {
    var coloris = GetSelectedValue(idDdlColoris)
    ChangeTaille(coloris, idDdlTaille);
    ChangeAllValuesPersonnalisee(idDdlColoris, idDdlTaille, true);
    AfficherImageColorisPersonnalisee(coloris);
}

function ChangeAllValuesPersonnalisee(idDdlColoris, idDdlTaille, initialisation) {
    var reference = GetSelectedValue(idDdlTaille);
    var coloris = GetSelectedValue(idDdlColoris)
    if (reference == '0') {
        SetDefaultValuesPersonnalisee(coloris, reference);
    }
    else {
        var infos = infosRef[reference];
        var listeId = infos.split(/;/);

        if (initialisation) {
            var control = document.getElementById(idDdlTaille);
            if (control.options) {
                if (control.options[0].innerHTML.lastIndexOf("-") != -1) {
                    for (var i = 0; i < control.options.length; i++) {
                        if (control.options[i].innerHTML.lastIndexOf("-") == -1) {
                            infos = infosRef[control.options[i].value];
                            listeId = infos.split(/;/);
                            control.value = control.options[i].value;
                            break;
                        }
                    }
                }
            }
        }

        ChangePrixPersonnalisee(listeId[0], listeId[3]);
        ChangeDispoPersonnalisee(listeId[1]);
        ChangeToolTipTitre(listeId[2], reference);

        if (finarefActif) {
            var finarefInfos = finarefInfosDeReference[listeId[4]];
            ChangeFinarefPersonnalisee(finarefInfos);
        }
        else {
            ChangeFinarefVidePersonnalisee();
        }
    }
}

function ChangePrixPersonnalisee(idPrix, idTxdmq) {
    var prix = prixDeReference[idPrix];
    var divPrix = document.getElementById('divPrixAltima');
    var txdmq = txdmqDeReference[idTxdmq];

    divPrix.innerHTML = prix + txdmq;
}

function ChangeFinarefVidePersonnalisee() {

    var divFinaref = document.getElementById('memo_produit_fiche_produit_multifractionnement_altima0');
    var divFinarefLibelle = document.getElementById('memo_produit_fiche_produit_multifractionnement_libelle_2');

    if (libelleHorsFinaref == '') {
        divFinaref.style.display = "none";
    }
    else {
        divFinaref.style.display = "block";
        divFinarefLibelle.style.display = "block";
        divFinarefLibelle.innerHTML = libelleHorsFinaref;
    }

    var divFinarefMention = document.getElementById("memo_produit_fiche_produit_multifractionnement_mention");
    divFinarefMention.style.display = "none";
}

function ChangeFinarefPersonnalisee(finarefInfos) {

    var divFinaref = document.getElementById('memo_produit_fiche_produit_multifractionnement_altima1');
    var divFinarefLibelle = document.getElementById('memo_produit_fiche_produit_multifractionnement_libelle_1');

    if (libelleFinaref == '') {
        divFinarefLibelle.style.display = "none";
        divFinaref.style.display = "none";
    }
    else {
        divFinaref.style.display = "block";
        divFinarefLibelle.style.display = "block";
        divFinarefLibelle.innerHTML = libelleFinaref;
    }

    var finaref = finarefInfos.split(/;/);

    var divFinarefMention = document.getElementById("memo_produit_fiche_produit_multifractionnement_mention");
    divFinarefMention.innerHTML = finarefMentionDeReference[finaref[0]];
    divFinarefMention.style.display = "none";

    var spanMtmens = document.getElementById("mtmens");
    spanMtmens.innerHTML = finaref[1];

    var spanNbfract = document.getElementById("nbfract");
    spanNbfract.innerHTML = finaref[2];

    var spanMtfrais = document.getElementById("mtfrais");
    spanMtfrais.innerHTML = finaref[3];

    var spanTaeg = document.getElementById("taeg");
    spanTaeg.innerHTML = finaref[4];
}

function AfficherImageColorisPersonnalisee(codeColoris) {
    var url = arrImagesColoris[codeColoris];
    ChargeImagePersonnalisee(url);
}

function ChargeImagePersonnalisee(url) {
    var imgVisuel = document.getElementById("memo_produit_fiche_image_visuel");
    if (imgVisuel != undefined) 
    {
        imgVisuel.src = url;
    }
}
// fin tests altima