// JavaScript Document
var IE = false;
var IE6 = false;
var NS = false;
var browser_version = parseInt(navigator.appVersion);
var browser_type = navigator.appName;
if (browser_type == "Microsoft Internet Explorer" && (browser_version >= 4)) { IE = true; } 
if (browser_type == "Microsoft Internet Explorer" && (browser_version <= 6)) { IE6 = true; } 
else if (browser_type == "Netscape" && (browser_version >= 4) && (browser_version < 5)) { NS = true; }
else if (browser_type == "Netscape" && (browser_version >= 5)) { NS = true; }

function importPopStyle()
{
  var head = document.getElementsByTagName("head")[0];

  var link = document.createElement("link");
  link.rel = "stylesheet";
  link.href = "./css/jsPopup.css";
  link.type = "text/css";
  link.media = "all";

  head.appendChild(link);
}

function closePopup(id) 
{
  Effect.Fade(id, { duration: 0.5 });
  Effect.Fade('popupbg', { duration: 0.5 });
  setTimeout("doclosePopup('"+id+"')", 500);
}

function doclosePopup(id)
{
  deleteLayer(id,false);
  deleteLayer('popupbg',true);
}

function closePopupOnly(id)
{
  Effect.Fade(id, { duration: 0.5 });
  setTimeout("doclosePopupOnly('"+id+"')", 500);
  deleteLayer(id);
}

function doclosePopupOnly(id)
{
  deleteLayer(id);
}

function createPopupFrame(src,W,H,scroll)
{
  if(H == 0)
    H = document.documentElement.clientHeight - 100;
  if(W == 0)
    W = document.documentElement.clientWidth - 100;
  
  importPopStyle();
  
  makeBGLayer('popupbg','popupframe','7','900');
  makeLayer('popupframe',W,H,'10','1000');
  
  height = H - 32 - 10;
  width = W - 20;
  
  var html =  '<div class="popuptop" id="popuptop"><a href="javascript:closePopup(\'popupframe\');" title="Fenster schlie&szlig;en"><b>schlie&szlig;en</b>&nbsp;<img src="img/btn_close.gif" border="0" align="top" style="position:relative; top:0px;" alt="" title="Fenster schlie&szlig;en" /></a></div>'+
              '<div class="popupcontent" id="popupcontent">'+
              '<iframe src="'+src+'" name="puframe" id="puframe" width="'+(width-1)+'" height="'+(height-1)+'" vspace="0" hspace="0" marginwidth="0" marginheight="0" style="overflow:visible; display:block;" allowtransparency="true" frameborder="0" scrolling="'+scroll+'" align="left"></iframe>'+
              '</div>'+
              '<div class="popupbottom" id="popupbottom">&nbsp;</div>';
  
  document.getElementById('popupframe').innerHTML = html;
  document.getElementById('popuptop').style.width = (W - 20)+"px";
  document.getElementById('popuptop').style.height = 25+"px";
  document.getElementById('popupcontent').style.width = (W - 20)+"px";
  document.getElementById('popupcontent').style.height = height+"px";
  document.getElementById('popupbottom').style.width = W+"px";
  document.getElementById('popupbottom').style.height = 10+"px";
}

function createNotification(text, width, height)
{
  makeBGLayer('popupbg','popup','5','60');
  makeLayer('popup',width,height,'10','70');

  importPopStyle();
  
  var html =  '<div class="popuptop" id="popuptop"><a href="javascript:closePopup(\'popup\');" title="Fenster schlie&szlig;en"><b>schlie&szlig;en</b>&nbsp;<img src="img/btn_close.gif" border="0" align="top" style="position:relative; top:0px;" alt="" title="Fenster schlie&szlig;en" /></a></div>'+
              '<div class="popupcontent" id="popupcontent">'+
              text+'<br/><br/>'+
              '<div id="ok" style="width:100%; text-align:center;"></div>'+
              '</div>'+
              '<div class="popupbottom" id="popupbottom">&nbsp;</div>';
  
  document.getElementById('popup').innerHTML = html;
  
  okb=document.createElement('input');
  okb.type = 'image';
  okb.src = './img/btn_ok.gif';
  okb.style.width = 80;
  document.getElementById('ok').appendChild(okb);
  okb.onclick = function() { closePopup('popup'); };
}

function makeBGLayer(id,pid,opacity,zIndex) 
{
  if (!document.createElement) return;
  if (document.getElementById(id)) return;
  
  if(NS)
    document.body.style.overflow = 'hidden';
  if(IE)
  {
    if(!document.documentElement.clientHeight)
      document.body.style.overflow = 'hidden';
    else
      document.documentElement.style.overflow = 'hidden';
  }
  
  if(NS)
  {
    var top = window.pageYOffset+'px';
  }
  if(IE)
  {
    if(!document.documentElement.clientHeight)
      var top = document.body.scrollTop+'px';
    else
      var top = document.documentElement.scrollTop+'px';
  }
  
  d = document.createElement('div');
  d.id = id;
  d.style.display = 'none';
  d.style.left = '0px';
  d.style.top = top;
  d.style.width = '2000px'; // Scroll Fix
  d.style.height = '2000px'; // IE6 Fix
  d.style.backgroundColor = '#000000';
  obj = document.getElementsByClassName('blur');
  i = 0;
  //----------- Website spezifisch ---------
  body = document.getElementsByTagName('body');
  body[0].style.backgroundImage = 'none';
  while(obj[i])
  {
    obj[i].style.filter = 'progid:DXImageTransform.Microsoft.Blur(pixelRadius=2)';
    i++;
  }
  //----------------------------------------
  d.style.position = 'absolute';
  d.style.zIndex = zIndex;
  d.style.opacity = opacity/10;
	d.style.filter = 'alpha(opacity=' + opacity*10 + ')';
	d.onclick = function(){closePopup(pid);}
  document.body.appendChild(d);
  Effect.Appear(d, { duration: 0.5, to: opacity/10 });
}

function makeLayer(id,W,H,opacity,zIndex) 
{
  if (!document.createElement) return;
  if (document.getElementById(id)) return;
  
  if(NS)
  {
    var top = window.pageYOffset+(window.innerHeight/2)-(H/2);
    var left = window.pageXOffset+(window.innerWidth/2)-(W/2);
  }
  if(IE)
  {
    if(!document.documentElement.clientHeight)
    {
      var top = document.body.scrollTop+(document.body.clientHeight/2)-(H/2);
      var left = document.body.scrollLeft+(document.body.clientWidth/2)-(W/2);
    }
    else
    {
      var top = document.documentElement.scrollTop+(document.documentElement.clientHeight/2)-(H/2);
      var left = document.documentElement.scrollLeft+(document.documentElement.clientWidth/2)-(W/2);
    }
  }
  
  var mh = -1*(W/2);
  var mv = -1*(H/2);
  
  W += 'px';
  H += 'px';
  
  left = Math.floor(left)+'px';
  top = Math.floor(top)+'px';
  
  d = document.createElement('div');
  d.id = id;
  d.style.position = 'absolute';
  d.style.zIndex = zIndex;
  d.style.display = 'none';
  d.style.width = W;
  d.style.height = H;
  d.style.margin = '0 0 0 '+mh+'px';
  d.style.left = '50%';
  d.style.top = top;
  /* Verursacht Probleme bei Fade Effekten im IE -----------------
  d.style.opacity = opacity/10;
	d.style.filter = 'alpha(opacity=' + opacity*10 + ')';
	*/
  document.body.appendChild(d);
  Effect.Appear(d, { duration: 0.5, to: opacity/10 });
}

function changePopup(id,newsrc,W,H,scroll)
{
  if(H == 0)
    H = document.documentElement.clientHeight - 100;
  if(W == 0)
    W = document.documentElement.clientWidth - 100;
  
  iframe = document.getElementById('puframe');
  new Effect.Opacity(iframe, { from: 1.0, to: 0, duration: 0.1 });
  morphPopup('popupframe',W,H,'');
  document.getElementById('puframe').src = newsrc;
  new Effect.Opacity(iframe, { from: 0, to: 1.0, duration: 2.0 });
}

function deleteLayer(id,scroll)
{
  if(scroll == true)
  {
    if(NS)
      document.body.style.overflow = 'auto';
    if(IE)
    {
      if(!document.documentElement.clientHeight)
      {
        document.body.style.overflow = 'auto';
      }
      else
      {
        document.documentElement.style.overflow = 'auto';
      }
    }
    
    obj = document.getElementsByClassName('blur');
    i = 0;
    //----------- Website spezifisch ---------
    body = document.getElementsByTagName('body');
    body[0].style.backgroundImage = 'url(./img/bg_menu.gif)';
    while(obj[i])
    {
      obj[i].style.filter = 'none';
      i++;
    }
    //----------------------------------------
  }
  if (!document.createElement) return;
  d = document.getElementById(id);
  if (!d) return;
  document.body.removeChild(d);
}

function morphPopup(id,W,H,style) 
{
  if(NS)
  {
    var top = window.pageYOffset+(window.innerHeight/2)-(H/2);
    var left = window.pageXOffset+(window.innerWidth/2)-(W/2);
  }
  if(IE)
  {
    if(!document.documentElement.clientHeight)
    {
      var top = document.body.scrollTop+(document.body.clientHeight/2)-(H/2);
      var left = document.body.scrollLeft+(document.body.clientWidth/2)-(W/2);
    }
    else
    {
      var top = document.documentElement.scrollTop+(document.documentElement.clientHeight/2)-(H/2);
      var left = document.documentElement.scrollLeft+(document.documentElement.clientWidth/2)-(W/2);
    }
  }
  
  popup = document.getElementById(id);
  ch = getHeightWithoutPadding(popup);
  cw = getWidthWithoutPadding(popup);
  wfac = W/cw;
  hfac = H/ch;
  var mh = -1*(W/2);

  iframe = document.getElementById('puframe');
  nh = getIFrameHeight(iframe)*hfac;
  new Effect.Parallel([
    new Effect.Morph(iframe, {style: 'width:'+(W-20)+'px; height:'+nh+'px;'})
  ]); 
  topb = document.getElementById('popuptop');
  //nh = getHeightWithoutPadding(topb)*hfac;
  new Effect.Parallel([
    new Effect.Morph(topb, {style: 'width:'+(W-20)+'px;'})
    //new Effect.Morph(topb, {style: 'width:'+(W-20)+'px; height:'+nh+'px;'})
  ]); 
  content = document.getElementById('popupcontent');
  nh = getHeightWithoutPadding(content)*hfac;
  new Effect.Parallel([
    new Effect.Morph(content, {style: 'width:'+(W-20)+'px; height:'+nh+'px;'})
  ]);
  bottom = document.getElementById('popupbottom');
  //nh = getHeightWithoutPadding(bottom)*hfac;
  new Effect.Parallel([
    new Effect.Morph(bottom, {style: 'width:'+W+'px;'})
    //new Effect.Morph(bottom, {style: 'width:'+W+'px; height:'+nh+'px;'})
  ]);
  new Effect.Parallel([
    new Effect.Morph(popup, {style: 'width:'+W+'px; height:'+H+'px; top:'+top+'; margin:0 0 0 '+mh+'px'})
  ]);
}

function getHeightWithoutPadding(element) 
{
  if(NS)
    return parseFloat(element.getStyle('height'));
  if(IE)
  {
    str = element.style.height;
    wo = str.split("px");
    n = wo[0];
    return n;
    //return parseFloat(element.style.height);
  }
} 

function getWidthWithoutPadding(element) 
{
  if(NS)
    return parseFloat(element.getStyle('width'));
  if(IE)
    return parseFloat(element.style.width);
} 

function getIFrameHeight(element)
{
  return element.height;
}

function getIFrameWidth(element)
{
  return element.width;
}

function resizeIF(id, fid, minheight) 
{
   if(document.all&&!window.opera) 
   {
     var a = document.popupif;
     a.document.body.scroll = 'no';
   } 
   else 
   {
     var a = document.getElementById(fid);
     a.scrolling = 'no';
   }
   a = document.getElementById(fid);
   a.contentWindow.document.body.style.overflow = 'hidden';
   var b = a.contentWindow.document.getElementById('cont');
   if(a.style.height != eval(b.offsetHeight+35)+'px') 
   {
      if(b.offsetHeight == 0)
        a.style.height = minheight+'px';
      else
        a.style.height = eval(b.offsetHeight+35)+'px';
   }
   var height = a.style.height;
   repostion(id, height);
}



