// ###################################################################
// Copyright 2004 by mattmarr.com


var ie= ((document.all)&&(!document.layers)) ? true : false;
var ns= ((document.layers)&&(!document.getElementById)) ? true : false;
var moz= ((document.getElementById)&&(!document.all)) ? true : false;
var lastopen = "";

function dropdown(wdiv){

    var merk = "m_" + wdiv;
    var emlid = document.getElementById(wdiv);
    var merkid = document.getElementById(merk);

    // ################################################
    // Schliesse altes Fenster wenn eins offen ist
    if (lastopen) {
        if(lastopen != wdiv) {
            document.getElementById(lastopen).style.visibility="hidden";
        }
    }

    var statdiv = emlid.style.visibility;
    var pLeft   = emlid.offsetLeft;
    var pWidth  = emlid.offsetWidth;
    var pTop    = emlid.offsetTop;
    var mWidth  = merkid.offsetWidth;
    var mHeight = merkid.offsetHeight;
    var mLeft   = merkid.offsetLeft;
    var mTop    = merkid.offsetTop;
    var BWidth  = document.body.clientWidth;

    // ################################################
    // Menü position neuberechnen
    var neuXTop = mTop + mHeight;
    var merkRight = mLeft + pWidth;
    if (merkRight >= BWidth) {
        //alert("mLeft: " + mLeft + "\nmerkRight: " + merkRight + "\npWidth: " + pWidth + "\nBWidth: " + BWidth);
        var mLeft = (mLeft + mWidth) - pWidth;
    }
    // ################################################
    // Menu neu positionieren
    emlid.style.left=mLeft;
    emlid.style.top=neuXTop;

    // ################################################
    // Öffne neues Menu bei Klick
    if(ie) {
        if (statdiv == "visible") {
            emlid.style.visibility="hidden";
        } else {
            //document.all[wdiv].style.visibility="visible";
            emlid.style.visibility="visible";
        }
    }
    if(ns) {
        if (statdiv == "show") {
            emlid.style.visibility="hidden";
        } else {
            document.layers[wdiv].visibility="show";
        }
    }
    if(moz) {
        if (statdiv == "visible") {
            emlid.style.visibility="hidden";
        } else {
            emlid.style.visibility="visible";
        }
    }
    if (lastopen) {
        if(lastopen != wdiv) {
            document.getElementById(lastopen).style.left=1;
            document.getElementById(lastopen).style.top=1;
        }
    }
    lastopen = wdiv;
}

