// Copyright: drumedar Internet-Entwicklungs-GmbH
// eMail:     info@drumedar.de
// Web:       www.drumedar.de


//---------------------------------------------------------------------------
// erzeugen_objekt_variation
//---------------------------------------------------------------------------

function erzeugen_objekt_variation (id_shop, id_objekt, flag_masstabelle) {

    var anzeige_var0 = '';
    var anzeige_var1 = '';
    var anzeige_var2 = '';
    var anzeige_var3 = '';
    var anzeige_var4 = '';

    var variations_kombination = '';

    if (document.forms['PRODUKT'].VARIATION_0.type != "hidden") {
        variations_kombination = variations_kombination + document.forms['PRODUKT'].VARIATION_0.options[document.forms['PRODUKT'].VARIATION_0.selectedIndex].value + "\|";
        if (id_shop == '02_D') {
            if (flag_masstabelle == 1) {
                anzeige_var0 = "<a style=\"font-weight:bold;\" href=\"javascript:var masstabelle_" + id_shop + " = open ('http://www.proidee.de?S=masstabelle', 'masstabelle_" + id_shop + "', 'width=650,height=800,resizable=no,scrollbars=yes,status=no,menubar=no,location=no,toolbar=no,directories=no');\">FC-Größe:</a> ";
            }
            else {
                anzeige_var0 = "Größe: ";
            }
        }
        else if (id_shop == '02_A') {
            if (flag_masstabelle == 1) {
                anzeige_var0 = "<a style=\"font-weight:bold;\" href=\"javascript:var masstabelle_" + id_shop + " = open ('http://www.proidee.at?S=masstabelle', 'masstabelle_" + id_shop + "', 'width=650,height=800,resizable=no,scrollbars=yes,status=no,menubar=no,location=no,toolbar=no,directories=no');\">FC-Größe:</a> ";
            }
            else {
                anzeige_var0 = "Größe: ";
            }
        }
        else if (id_shop == '02_CH') {
            if (flag_masstabelle == 1) {
                anzeige_var0 = "<a style=\"font-weight:bold;\" href=\"javascript:var masstabelle_" + id_shop + " = open ('http://www.proidee.ch?S=masstabelle', 'masstabelle_" + id_shop + "', 'width=650,height=800,resizable=no,scrollbars=yes,status=no,menubar=no,location=no,toolbar=no,directories=no');\">FC-Größe:</a> ";
            }
            else {
                anzeige_var0 = "Größe: ";
            }
        }
        else if (id_shop == '02_GB') {
            if (flag_masstabelle == 1) {
                anzeige_var0 = "<a style=\"font-weight:bold;\" href=\"javascript:var masstabelle_" + id_shop + " = open ('http://www.proidee.co.uk?S=masstabelle', 'masstabelle_" + id_shop + "', 'width=650,height=800,resizable=no,scrollbars=yes,status=no,menubar=no,location=no,toolbar=no,directories=no');\">FC Size:</a> ";
            }
            else {
                anzeige_var0 = "Size: ";
            }
        }
        else if (id_shop == '02_F') {
            anzeige_var0 = "";
        }
        else if (id_shop == '02_NL') {
            if (flag_masstabelle == 1) {
                anzeige_var0 = "<a style=\"font-weight:bold;\" href=\"javascript:var masstabelle_" + id_shop + " = open ('http://www.proidee.nl?S=masstabelle', 'masstabelle_" + id_shop + "', 'width=650,height=800,resizable=no,scrollbars=yes,status=no,menubar=no,location=no,toolbar=no,directories=no');\">FC Maat:</a> ";
            }
            else {
                anzeige_var0 = "Maat: ";
            }
        }
        else if (id_shop == '01_D') {
            anzeige_var0 = "Größe: ";
        }
        anzeige_var0 += document.forms['PRODUKT'].VARIATION_0.options[document.forms['PRODUKT'].VARIATION_0.selectedIndex].text;
    }
    else {
        variations_kombination = variations_kombination + document.forms['PRODUKT'].VARIATION_0.value + "\|";
        anzeige_var0 = '';
    }


    if (document.forms['PRODUKT'].VARIATION_1.type != "hidden") {
        variations_kombination = variations_kombination + document.forms['PRODUKT'].VARIATION_1.options[document.forms['PRODUKT'].VARIATION_1.selectedIndex].value + "\|";
        if (id_shop == '02_GB') {
            anzeige_var1 = "Colour: ";
        }
        else if (id_shop == '02_F') {
            anzeige_var1 = "Coleur: ";
        }
        else if (id_shop == '02_NL') {
            anzeige_var1 = "Kleur: ";
        }
        else {
            anzeige_var1 = "Farbe: ";
        }
        anzeige_var1 += document.forms['PRODUKT'].VARIATION_1.options[document.forms['PRODUKT'].VARIATION_1.selectedIndex].text;
    }
    else {
        variations_kombination = variations_kombination + document.forms['PRODUKT'].VARIATION_1.value + "\|";
        anzeige_var1 = '';
    }


    if (document.forms['PRODUKT'].VARIATION_2.type != "hidden" ) {
        variations_kombination = variations_kombination + document.forms['PRODUKT'].VARIATION_2.options[document.forms['PRODUKT'].VARIATION_2.selectedIndex].value + "\|";
        anzeige_var2 = document.forms['PRODUKT'].VARIATION_2.options[document.forms['PRODUKT'].VARIATION_2.selectedIndex].text;
    }
    else {
        variations_kombination = variations_kombination + document.forms['PRODUKT'].VARIATION_2.value + "\|";
        anzeige_var2 = '';
    }


    if (document.forms['PRODUKT'].VARIATION_3.type != "hidden" ) {
        variations_kombination = variations_kombination + document.forms['PRODUKT'].VARIATION_3.options[document.forms['PRODUKT'].VARIATION_3.selectedIndex].value + "\|";
        anzeige_var3 = document.forms['PRODUKT'].VARIATION_3.options[document.forms['PRODUKT'].VARIATION_3.selectedIndex].text;
    }
    else {
        variations_kombination = variations_kombination + document.forms['PRODUKT'].VARIATION_3.value + "\|";
        anzeige_var3 = '';
    }


    if (document.forms['PRODUKT'].VARIATION_4.type != "hidden" ) {
        variations_kombination = variations_kombination + document.forms['PRODUKT'].VARIATION_4.options[document.forms['PRODUKT'].VARIATION_4.selectedIndex].value;
        anzeige_var4 = document.forms['PRODUKT'].VARIATION_4.options[document.forms['PRODUKT'].VARIATION_4.selectedIndex].text;
    }
    else {
        variations_kombination = variations_kombination + document.forms['PRODUKT'].VARIATION_4.value;
        anzeige_var4 = '';
    }


    var anzahl_elemente = variationen.length;
    var zaehler = 0;
    var gefunden = false;
    var produktpreis = '';
    var produktpreis_alt = '';
    var warnung = '';
    var html_id_produkt = '';
    var html_liefertext = '';
    var html_vrg = '';
    var html_grundpreis = '';

    if (preis_alt_prefix != '') {

        while (zaehler < (anzahl_elemente / 7)) {
            if (variationen[zaehler * 7 + 1] == variations_kombination) {
                produktpreis = variationen[zaehler * 7 + 2];
                produktpreis_alt = variationen[zaehler * 7 + 3];
                if (produktpreis_alt != '') {
                    produktpreis_alt = preis_alt_prefix + ' ' + produktpreis_alt;
                }
                var position_id_produkt = variationen[zaehler * 7].lastIndexOf('_') + 1;
                var id_produkt = variationen[zaehler * 7].substring(position_id_produkt, position_id_produkt + 6);

                html_id_produkt = '<br/><span class="tabpr_wk_artnr">';
                if (id_shop == '02_GB') {
                    html_id_produkt += 'Item No.: ';
                }
                else if (id_shop == '02_F') {
                    html_id_produkt += 'Réf.: ';
                }
                else if (id_shop == '02_NL') {
                    html_id_produkt += 'Best.-Nr.: ';
                }
                else {
                    html_id_produkt += 'Best.-Nr.: ';
                }
                html_id_produkt += id_produkt;

                html_liefertext = '<br />' + variationen[zaehler * 7 + 4] + '</span>';
                html_vrg = variationen[zaehler * 7 + 5];
                html_grundpreis = variationen[zaehler * 7 + 6];

                document.forms['PRODUKT'].ID_PRODUKT.value = variationen[zaehler * 7];
                gefunden = true;
                break;
            }
            zaehler++;
        }
    }

    else {

        while (zaehler < (anzahl_elemente / 6)) {
            if (variationen[zaehler * 6 + 1] == variations_kombination) {
                produktpreis = variationen[zaehler * 6 + 2];
                var position_id_produkt = variationen[zaehler * 6].lastIndexOf('_') + 1;
                var id_produkt = variationen[zaehler * 6].substring(position_id_produkt, position_id_produkt + 6);

                html_id_produkt = '<br/><span class="tabpr_wk_artnr">';
                if (id_shop == '02_GB') {
                    html_id_produkt += 'Item No.: ';
                }
                else if (id_shop == '02_F') {
                    html_id_produkt += 'Réf.: ';
                }
                else if (id_shop == '02_NL') {
                    html_id_produkt += 'Best.-Nr.: ';
                }
                else {
                    html_id_produkt += 'Best.-Nr.: ';
                }
                html_id_produkt += id_produkt;

                html_liefertext = '<br />' + variationen[zaehler * 6 + 3] + '</span>';
                html_vrg = variationen[zaehler * 6 + 4];
                html_grundpreis = variationen[zaehler * 6 + 5];

                document.forms['PRODUKT'].ID_PRODUKT.value = variationen[zaehler * 6];
                gefunden = true;
                break;
            }
            zaehler++;
        }
    }

    if (gefunden == false) {
        if (id_shop == '02_GB') {
            warnung = '<span class="tabpr_wk_fehler">This product variation is no longer available</span><br/>';
        }
        else if (id_shop == '02_F') {
            warnung = '<span class="tabpr_wk_fehler">Cette variante de l\'article n\'est malheureusement plus disponible</span><br/>';
        }
        else if (id_shop == '02_NL') {
            warnung = '<span class="tabpr_wk_fehler">Deze uitvoering van het artikel is helaas niet meer leverbaar</span><br/>';
        }
        else {
            warnung = '<span class="tabpr_wk_fehler">Diese Artikelvariation ist leider nicht mehr lieferbar</span><br/>';
        }
        produktpreis = '';
        document.forms['PRODUKT'].ID_PRODUKT.value = '';
    }

    var komma = '';

    if (anzeige_var2 != '') {
        anzeige_var2 = komma + anzeige_var2;
        komma = ', ';
    }
    if (anzeige_var3 != '') {
        anzeige_var3 = komma + anzeige_var3;
        komma = ', ';
    }
    if (anzeige_var4 != '') {
        anzeige_var4 = komma + anzeige_var4;
        komma = ', ';
    }
    if (anzeige_var0 != '') {
        anzeige_var0 = komma + anzeige_var0;
        komma = ', ';
    }
    if (anzeige_var1 != '') {
        anzeige_var1 = komma + anzeige_var1;
        komma = ', ';
    }

    var inhalt =
        '<table style="width:100%;border-collapse:collapse;border-spacing:0px;padding:0;table-layout:fixed;"><tr><td class="tabpr_wk_variation">' +
        warnung +
        anzeige_var2 +
        anzeige_var3 +
        anzeige_var4 +
        anzeige_var0 +
        anzeige_var1 +
        html_id_produkt +
        html_liefertext +
        '</td></tr><tr><td class="tabpr_wk_preis">' + produktpreis + '</td></tr><tr><td style="text-align:right;">' + html_vrg + '</td></tr><tr><td style="text-align:right;">' + html_grundpreis + '</td></tr><tr><td class="tabpr_wk_artnr" style="text-align:right; font-weight:bold;">' + produktpreis_alt + '</td></tr></table>';

    fuellen_objekt (id_objekt, inhalt);
}


//---------------------------------------------------------------------------
// fuellen_objekt
//---------------------------------------------------------------------------

function fuellen_objekt (id_objekt, inhalt) {

    if (document.getElementById) {
        document.getElementById (id_objekt).innerHTML = inhalt;
    }
    else if (document.all) {
        document.all[id_objekt].innerHTML = inhalt;
    }
    else if (document.layers) {
        with (document.layers[id_objekt].document) {
            open ();
            write (inhalt);
            close ();
        }
    }
}


//---------------------------------------------------------------------------
// positionieren_objekt
//---------------------------------------------------------------------------

function positionieren_objekt (id_objekt) {

    if (document.getElementById) {
        var zeiger_anker = document.getElementById ('DIV_' + id_objekt);

        with (document.getElementById (id_objekt).style) {
            left = holen_objekt_x_koordinate (zeiger_anker) + 'px';
            top = holen_objekt_y_koordinate (zeiger_anker) + 'px';
            visibility = 'visible';
        }
    }
    else if (document.all) {
        var zeiger_anker = document.all['ANKER_' + id_objekt];

        with (document.all[id_objekt].style) {
            posLeft = holen_objekt_x_koordinate (zeiger_anker);
            posTop = holen_objekt_y_koordinate (zeiger_anker);
            visibility = 'visible';
        }
    }
    else if (document.layers) {
        var zeiger_anker = document.anchors['ANKER_' + id_objekt];

        with (document[id_objekt]) {
            pageX = zeiger_anker.x;
            pageY = zeiger_anker.y;
            visibility = 'show';
        }
    }
}


//---------------------------------------------------------------------------
// zeigen_objekt
//---------------------------------------------------------------------------

function zeigen_objekt (id_objekt) {

    if (document.getElementById) {
        with (document.getElementById (id_objekt).style) {
            visibility = 'visible';
        }
    }
    else if (document.all) {
        with (document.all[id_objekt].style) {
            visibility = 'visible';
        }
    }
    else if (document.layers) {
        with (document[id_objekt]) {
            visibility = 'show';
        }
    }
}


//---------------------------------------------------------------------------
// verstecken_objekt
//---------------------------------------------------------------------------

function verstecken_objekt (id_objekt) {

    if (document.getElementById) {
        with (document.getElementById (id_objekt).style) {
            visibility = 'hidden';
        }
    }
    else if (document.all) {
        with (document.all[id_objekt].style) {
            visibility = 'hidden';
        }
    }
    else if (document.layers) {
        with (document[id_objekt]) {
            visibility = 'hidden';
        }
    }
}


//---------------------------------------------------------------------------
// holen_objekt_x_koordinate
//---------------------------------------------------------------------------

function holen_objekt_x_koordinate (zeiger_objekt) {

    if (zeiger_objekt.offsetParent) {
        return (zeiger_objekt.offsetLeft + holen_objekt_x_koordinate (zeiger_objekt.offsetParent));
    }
    else {
        return (zeiger_objekt.offsetLeft);
    }
}


//---------------------------------------------------------------------------
// holen_objekt_y_koordinate
//---------------------------------------------------------------------------

function holen_objekt_y_koordinate (zeiger_objekt) {

    if (zeiger_objekt.offsetParent) {
        return (zeiger_objekt.offsetTop + holen_objekt_y_koordinate (zeiger_objekt.offsetParent));
    }
    else {
        return (zeiger_objekt.offsetTop);
    }
}

//---------------------------------------------------------------------------
// laden_menue
//---------------------------------------------------------------------------

function laden_menue () {
    fuellen_objekt ("nav", menue_inhalt);
}


//---------------------------------------------------------------------------
// super_zoom
//---------------------------------------------------------------------------

var ausschnitt_groesse = 546;
var bild_groesse = 1300;
var navigator_groesse = 86;

var x0 = 12;
var y0 = 37;

var navigator_x0 = 662 + Math.round(navigator_groesse / 2);
var navigator_y0 = 250 + Math.round(navigator_groesse / 2);

var verschiebungs_faktor = (bild_groesse - ausschnitt_groesse) / navigator_groesse;

var anfangs_rand = Math.round((bild_groesse - ausschnitt_groesse) / 2);

//---------------------------------------------------------------------------
// super_zoom_an
//---------------------------------------------------------------------------

function super_zoom_an (e) {
    document.getElementById("sz_navigator").onmousemove=bewegen_bild;
}

//---------------------------------------------------------------------------
// super_zoom_aus
//---------------------------------------------------------------------------

function super_zoom_aus (e) {
    document.getElementById("sz_navigator").onmousemove=null;
}

//---------------------------------------------------------------------------
// bewegen_bild
//---------------------------------------------------------------------------

function bewegen_bild (e) {
    if (document.attachEvent) {
        x=event.clientX;
        y=event.clientY;
    } else {
        x = parseInt(e.pageX);
        y = parseInt(e.pageY);
    }

    versatz_x = Math.round((x - navigator_x0) * verschiebungs_faktor );
    versatz_y = Math.round((y - navigator_y0) * verschiebungs_faktor);

    //document.PRODUKT.WERTE.value = "vX:" + versatz_x + " [" + (x - navigator_x0) + "] vY:" + versatz_y + " [" + (y - navigator_y0) + "] RAND:" + anfangs_rand + ' Faktor' + verschiebungs_faktor;

    ausschnitt_oben = anfangs_rand + versatz_y;
    ausschnitt_rechts = bild_groesse - anfangs_rand + versatz_x;
    ausschnitt_unten = bild_groesse - anfangs_rand + versatz_y;
    ausschnitt_links = anfangs_rand + versatz_x;
    ausschnitt = 'rect(' + ausschnitt_oben + 'px ' + ausschnitt_rechts + 'px ' + ausschnitt_unten + 'px ' + ausschnitt_links + 'px)';

    document.getElementById("sz_bild").style.left = (-anfangs_rand + x0 - versatz_x) + 'px';
    document.getElementById("sz_bild").style.top = (-anfangs_rand + y0 - versatz_y) + 'px';
    document.getElementById("sz_bild").style.clip=ausschnitt;
}

