
var popupDiv    = null,
    popupShadow = null;

window.openPopup = function( url, name, param ){
  if ( ! popupDiv ){
    var topDiv  = document.createElement( 'div' ),
        iframe  = document.createElement( 'iframe' ),
        close   = document.createElement( 'span' ),
        body    = document.getElementsByTagName('body')[0],
        parArr  = param.split( ',' ),
        i;
    popupDiv    = document.createElement( 'div' );
    popupShadow = document.createElement( 'div' );

    popupDiv.className    = 'popup';
    popupShadow.className = 'popupShadow';
    topDiv.className      = 'pop';
    iframe.className      = 'pop';

    topDiv.innerHTML    = 'Schließen';
    addEvent( topDiv, 'click', window.closePopup, false );

    for ( var i = 0; i < parArr.length; i++ ){
      var arr = parArr[i].split( "=" ),
          key   = arr[0].toLowerCase(), 
          value = arr[1];

      if ( key == 'height' ){
        popupDiv.style.height    = value + "px";
        popupShadow.style.height = value + "px";
        iframe.style.height      = ( value - 15 ) + "px";
      } else if ( key == 'width' ){
        popupDiv.style.width     = value + "px";
        popupShadow.style.width  = value + "px";
        iframe.style.width       = value + "px";
      } else if ( key == 'top' ){
        popupDiv.style.top       = value + "px";
        popupShadow.style.top    = value + "px";
        iframe.style.top         = value + "px";
      } else if ( key == 'left' ){
        popupDiv.style.left      = value + "px";
        popupShadow.style.left   = value + "px";
        iframe.style.left        = value + "px";
      } else if ( key == 'scrollbar' ){
        if ( value == 'yes' || value == 'on' ){
          iframe.style.overflowX = "auto";
          iframe.style.overflowY = "auto";
        } else if ( value == 'vert' ){
          iframe.style.overflowX = "hidden";
          iframe.style.overflowY = "auto";
        } else if ( value == 'hor' ){
          iframe.style.overflowX = "auto";
          iframe.style.overflowY = "hidden";
        } else if ( value == 'no' || value == 'off' ){
          iframe.style.overflowX = "hidden";
          iframe.style.overflowY = "hidden";
        }
      }
    }
    

    popupDiv.appendChild( topDiv );
    popupDiv.appendChild( iframe );

    iframe.src = url;

    body.appendChild( popupDiv );
    body.appendChild( popupShadow );
  }
  return false;
}

window.closePopup = function() {
  var body  = document.getElementsByTagName('body')[0];
  body.removeChild( popupDiv );
  body.removeChild( popupShadow );
  popupDiv    = null;
  popupShadow = null;
}

function addEvent(obj, eventType, func, useCaption) {
  if (obj.addEventListener) {
    obj.addEventListener(eventType, func, useCaption);
    return true;
  } else if (obj.attachEvent) {
    var retVal = obj.attachEvent("on"+eventType, func);
    return retVal;
  } else {
    return false;
  }
}

